1 // SPDX-License-Identifier: GPL-2.0+
7 #include <linux/libfdt.h>
8 #include <fdt_support.h>
11 #include <asm/processor.h>
12 #include <asm/arch-fsl-layerscape/fsl_icid.h>
15 static void set_icid(struct icid_id_table *tbl, int size)
19 for (i = 0; i < size; i++)
20 out_be32((u32 *)(tbl[i].reg_addr), tbl[i].reg);
23 #ifdef CONFIG_SYS_DPAA_FMAN
24 void set_fman_icids(struct fman_icid_id_table *tbl, int size)
27 ccsr_fman_t *fm = (void *)CONFIG_SYS_FSL_FM1_ADDR;
29 for (i = 0; i < size; i++) {
30 out_be32(&fm->fm_bmi_common.fmbm_ppid[tbl[i].port_id - 1],
38 /* setup general icid offsets */
39 set_icid(icid_tbl, icid_tbl_sz);
41 #ifdef CONFIG_SYS_DPAA_FMAN
42 set_fman_icids(fman_icid_tbl, fman_icid_tbl_sz);
46 int fdt_set_iommu_prop(void *blob, int off, int smmu_ph, u32 *ids, int num_ids)
52 * Note: The "iommus" property definition mentions Stream IDs while
53 * this code handles ICIDs. The current implementation assumes that
54 * ICIDs and Stream IDs are equal.
56 for (i = 0; i < num_ids; i++) {
57 prop[i * 2] = cpu_to_fdt32(smmu_ph);
58 prop[i * 2 + 1] = cpu_to_fdt32(ids[i]);
60 ret = fdt_setprop(blob, off, "iommus",
61 prop, sizeof(u32) * num_ids * 2);
63 printf("WARNING unable to set iommus: %s\n", fdt_strerror(ret));
70 int fdt_fixup_icid_tbl(void *blob, int smmu_ph,
71 struct icid_id_table *tbl, int size)
75 for (i = 0; i < size; i++) {
79 off = fdt_node_offset_by_compat_reg(blob,
83 err = fdt_set_iommu_prop(blob, off, smmu_ph,
88 printf("WARNING could not find node %s: %s.\n",
89 tbl[i].compat, fdt_strerror(off));
96 #ifdef CONFIG_SYS_DPAA_FMAN
97 int get_fman_port_icid(int port_id, struct fman_icid_id_table *tbl,
102 for (i = 0; i < size; i++) {
103 if (tbl[i].port_id == port_id)
110 void fdt_fixup_fman_port_icid_by_compat(void *blob, int smmu_ph,
116 noff = fdt_node_offset_by_compatible(blob, -1, compat);
118 prop = fdt_getprop(blob, noff, "cell-index", &len);
120 printf("WARNING missing cell-index for fman port\n");
124 printf("WARNING bad cell-index size for fman port\n");
128 icid = get_fman_port_icid(fdt32_to_cpu(*prop),
129 fman_icid_tbl, fman_icid_tbl_sz);
131 printf("WARNING unknown ICID for fman port %d\n",
136 fdt_set_iommu_prop(blob, noff, smmu_ph, (u32 *)&icid, 1);
138 noff = fdt_node_offset_by_compatible(blob, noff, compat);
142 void fdt_fixup_fman_icids(void *blob, int smmu_ph)
144 static const char * const compats[] = {
145 "fsl,fman-v3-port-oh",
146 "fsl,fman-v3-port-rx",
147 "fsl,fman-v3-port-tx",
151 for (i = 0; i < ARRAY_SIZE(compats); i++)
152 fdt_fixup_fman_port_icid_by_compat(blob, smmu_ph, compats[i]);
156 int fdt_get_smmu_phandle(void *blob)
160 noff = fdt_node_offset_by_compatible(blob, -1, "arm,mmu-500");
162 printf("WARNING failed to get smmu node: %s\n",
167 smmu_ph = fdt_get_phandle(blob, noff);
169 smmu_ph = fdt_create_phandle(blob, noff);
171 printf("WARNING failed to get smmu phandle\n");
179 void fdt_fixup_icid(void *blob)
183 smmu_ph = fdt_get_smmu_phandle(blob);
187 fdt_fixup_icid_tbl(blob, smmu_ph, icid_tbl, icid_tbl_sz);
189 #ifdef CONFIG_SYS_DPAA_FMAN
190 fdt_fixup_fman_icids(blob, smmu_ph);