Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Ahmed Mansour | aa270b4 | 2017-12-15 16:01:00 -0500 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2008-2011 Freescale Semiconductor, Inc. |
| 4 | * Copyright 2017 NXP |
Ahmed Mansour | aa270b4 | 2017-12-15 16:01:00 -0500 | [diff] [blame] | 5 | */ |
| 6 | |
Tom Rini | dec7ea0 | 2024-05-20 13:35:03 -0600 | [diff] [blame] | 7 | #include <config.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 8 | #include <log.h> |
Masahiro Yamada | 75f82d0 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 9 | #include <linux/libfdt.h> |
Ahmed Mansour | aa270b4 | 2017-12-15 16:01:00 -0500 | [diff] [blame] | 10 | #include <fdt_support.h> |
| 11 | |
| 12 | #include <asm/processor.h> |
| 13 | #include <asm/io.h> |
| 14 | #ifdef CONFIG_PPC |
| 15 | #include <asm/fsl_portals.h> |
| 16 | #include <asm/fsl_liodn.h> |
Laurentiu Tudor | 1238f74 | 2018-08-09 15:19:47 +0300 | [diff] [blame] | 17 | #else |
| 18 | #include <asm/arch-fsl-layerscape/fsl_portals.h> |
| 19 | #include <asm/arch-fsl-layerscape/fsl_icid.h> |
Ahmed Mansour | aa270b4 | 2017-12-15 16:01:00 -0500 | [diff] [blame] | 20 | #endif |
| 21 | #include <fsl_qbman.h> |
| 22 | |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 23 | #define MAX_BPORTALS (CFG_SYS_BMAN_CINH_SIZE / CFG_SYS_BMAN_SP_CINH_SIZE) |
| 24 | #define MAX_QPORTALS (CFG_SYS_QMAN_CINH_SIZE / CFG_SYS_QMAN_SP_CINH_SIZE) |
Ahmed Mansour | aa270b4 | 2017-12-15 16:01:00 -0500 | [diff] [blame] | 25 | void setup_qbman_portals(void) |
| 26 | { |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 27 | void __iomem *bpaddr = (void *)CFG_SYS_BMAN_CINH_BASE + |
| 28 | CFG_SYS_BMAN_SWP_ISDR_REG; |
| 29 | void __iomem *qpaddr = (void *)CFG_SYS_QMAN_CINH_BASE + |
| 30 | CFG_SYS_QMAN_SWP_ISDR_REG; |
Tom Rini | 376b88a | 2022-10-28 20:27:13 -0400 | [diff] [blame] | 31 | struct ccsr_qman *qman = (void *)CFG_SYS_FSL_QMAN_ADDR; |
Ahmed Mansour | aa270b4 | 2017-12-15 16:01:00 -0500 | [diff] [blame] | 32 | |
| 33 | /* Set the Qman initiator BAR to match the LAW (for DQRR stashing) */ |
| 34 | #ifdef CONFIG_PHYS_64BIT |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 35 | out_be32(&qman->qcsp_bare, (u32)(CFG_SYS_QMAN_MEM_PHYS >> 32)); |
Ahmed Mansour | aa270b4 | 2017-12-15 16:01:00 -0500 | [diff] [blame] | 36 | #endif |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 37 | out_be32(&qman->qcsp_bar, (u32)CFG_SYS_QMAN_MEM_PHYS); |
Ahmed Mansour | aa270b4 | 2017-12-15 16:01:00 -0500 | [diff] [blame] | 38 | #ifdef CONFIG_FSL_CORENET |
| 39 | int i; |
| 40 | |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 41 | for (i = 0; i < CFG_SYS_QMAN_NUM_PORTALS; i++) { |
Ahmed Mansour | aa270b4 | 2017-12-15 16:01:00 -0500 | [diff] [blame] | 42 | u8 sdest = qp_info[i].sdest; |
| 43 | u16 fliodn = qp_info[i].fliodn; |
| 44 | u16 dliodn = qp_info[i].dliodn; |
| 45 | u16 liodn_off = qp_info[i].liodn_offset; |
| 46 | |
| 47 | out_be32(&qman->qcsp[i].qcsp_lio_cfg, (liodn_off << 16) | |
| 48 | dliodn); |
| 49 | /* set frame liodn */ |
| 50 | out_be32(&qman->qcsp[i].qcsp_io_cfg, (sdest << 16) | fliodn); |
| 51 | } |
Laurentiu Tudor | 1238f74 | 2018-08-09 15:19:47 +0300 | [diff] [blame] | 52 | #else |
Laurentiu Tudor | 810eb76 | 2018-08-27 17:34:00 +0300 | [diff] [blame] | 53 | #if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) |
Laurentiu Tudor | 1238f74 | 2018-08-09 15:19:47 +0300 | [diff] [blame] | 54 | int i; |
| 55 | |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 56 | for (i = 0; i < CFG_SYS_QMAN_NUM_PORTALS; i++) { |
Laurentiu Tudor | 1238f74 | 2018-08-09 15:19:47 +0300 | [diff] [blame] | 57 | u8 sdest = qp_info[i].sdest; |
| 58 | u16 ficid = qp_info[i].ficid; |
| 59 | u16 dicid = qp_info[i].dicid; |
| 60 | u16 icid = qp_info[i].icid; |
| 61 | |
| 62 | out_be32(&qman->qcsp[i].qcsp_lio_cfg, (icid << 16) | |
| 63 | dicid); |
| 64 | /* set frame icid */ |
| 65 | out_be32(&qman->qcsp[i].qcsp_io_cfg, (sdest << 16) | ficid); |
| 66 | } |
Ahmed Mansour | aa270b4 | 2017-12-15 16:01:00 -0500 | [diff] [blame] | 67 | #endif |
Laurentiu Tudor | 1238f74 | 2018-08-09 15:19:47 +0300 | [diff] [blame] | 68 | #endif |
Ahmed Mansour | aa270b4 | 2017-12-15 16:01:00 -0500 | [diff] [blame] | 69 | |
| 70 | /* Change default state of BMan ISDR portals to all 1s */ |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 71 | inhibit_portals(bpaddr, CFG_SYS_BMAN_NUM_PORTALS, MAX_BPORTALS, |
| 72 | CFG_SYS_BMAN_SP_CINH_SIZE); |
| 73 | inhibit_portals(qpaddr, CFG_SYS_QMAN_NUM_PORTALS, MAX_QPORTALS, |
| 74 | CFG_SYS_QMAN_SP_CINH_SIZE); |
Ahmed Mansour | aa270b4 | 2017-12-15 16:01:00 -0500 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | void inhibit_portals(void __iomem *addr, int max_portals, |
| 78 | int arch_max_portals, int portal_cinh_size) |
| 79 | { |
| 80 | u32 val; |
| 81 | int i; |
| 82 | |
| 83 | /* arch_max_portals is the maximum based on memory size. This includes |
| 84 | * the reserved memory in the SoC. max_portals the number of physical |
| 85 | * portals in the SoC |
| 86 | */ |
| 87 | if (max_portals > arch_max_portals) { |
| 88 | printf("ERROR: portal config error\n"); |
| 89 | max_portals = arch_max_portals; |
| 90 | } |
| 91 | |
| 92 | for (i = 0; i < max_portals; i++) { |
| 93 | out_be32(addr, -1); |
| 94 | val = in_be32(addr); |
| 95 | if (!val) { |
| 96 | printf("ERROR: Stopped after %d portals\n", i); |
| 97 | return; |
| 98 | } |
| 99 | addr += portal_cinh_size; |
| 100 | } |
| 101 | debug("Cleared %d portals\n", i); |
| 102 | } |
| 103 | |
| 104 | #ifdef CONFIG_PPC |
| 105 | static int fdt_qportal(void *blob, int off, int id, char *name, |
| 106 | enum fsl_dpaa_dev dev, int create) |
| 107 | { |
| 108 | int childoff, dev_off, ret = 0; |
Marek BehĂșn | a4273f5 | 2021-11-26 14:57:06 +0100 | [diff] [blame] | 109 | unsigned int dev_handle; |
Ahmed Mansour | aa270b4 | 2017-12-15 16:01:00 -0500 | [diff] [blame] | 110 | #ifdef CONFIG_FSL_CORENET |
| 111 | int num; |
| 112 | u32 liodns[2]; |
| 113 | #endif |
| 114 | |
| 115 | childoff = fdt_subnode_offset(blob, off, name); |
| 116 | if (create) { |
| 117 | char handle[64], *p; |
| 118 | |
| 119 | strncpy(handle, name, sizeof(handle)); |
| 120 | p = strchr(handle, '@'); |
| 121 | if (!strncmp(name, "fman", 4)) { |
| 122 | *p = *(p + 1); |
| 123 | p++; |
| 124 | } |
| 125 | *p = '\0'; |
| 126 | |
| 127 | dev_off = fdt_path_offset(blob, handle); |
| 128 | /* skip this node if alias is not found */ |
| 129 | if (dev_off == -FDT_ERR_BADPATH) |
| 130 | return 0; |
| 131 | if (dev_off < 0) |
| 132 | return dev_off; |
| 133 | |
| 134 | if (childoff <= 0) |
| 135 | childoff = fdt_add_subnode(blob, off, name); |
| 136 | |
| 137 | /* need to update the dev_off after adding a subnode */ |
| 138 | dev_off = fdt_path_offset(blob, handle); |
| 139 | if (dev_off < 0) |
| 140 | return dev_off; |
| 141 | |
| 142 | if (childoff > 0) { |
| 143 | dev_handle = fdt_get_phandle(blob, dev_off); |
| 144 | if (dev_handle <= 0) { |
Marek BehĂșn | a4273f5 | 2021-11-26 14:57:06 +0100 | [diff] [blame] | 145 | dev_handle = fdt_create_phandle(blob, dev_off); |
| 146 | if (!dev_handle) |
| 147 | return -FDT_ERR_NOPHANDLES; |
Ahmed Mansour | aa270b4 | 2017-12-15 16:01:00 -0500 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | ret = fdt_setprop(blob, childoff, "dev-handle", |
| 151 | &dev_handle, sizeof(dev_handle)); |
| 152 | if (ret < 0) |
| 153 | return ret; |
| 154 | |
| 155 | #ifdef CONFIG_FSL_CORENET |
| 156 | num = get_dpaa_liodn(dev, &liodns[0], id); |
| 157 | ret = fdt_setprop(blob, childoff, "fsl,liodn", |
| 158 | &liodns[0], sizeof(u32) * num); |
| 159 | if (!strncmp(name, "pme", 3)) { |
| 160 | u32 pme_rev1, pme_rev2; |
| 161 | ccsr_pme_t *pme_regs = |
Tom Rini | 376b88a | 2022-10-28 20:27:13 -0400 | [diff] [blame] | 162 | (void *)CFG_SYS_FSL_CORENET_PME_ADDR; |
Ahmed Mansour | aa270b4 | 2017-12-15 16:01:00 -0500 | [diff] [blame] | 163 | |
| 164 | pme_rev1 = in_be32(&pme_regs->pm_ip_rev_1); |
| 165 | pme_rev2 = in_be32(&pme_regs->pm_ip_rev_2); |
| 166 | ret = fdt_setprop(blob, childoff, |
| 167 | "fsl,pme-rev1", &pme_rev1, |
| 168 | sizeof(u32)); |
| 169 | if (ret < 0) |
| 170 | return ret; |
| 171 | ret = fdt_setprop(blob, childoff, |
| 172 | "fsl,pme-rev2", &pme_rev2, |
| 173 | sizeof(u32)); |
| 174 | } |
| 175 | #endif |
| 176 | } else { |
| 177 | return childoff; |
| 178 | } |
| 179 | } else { |
| 180 | if (childoff > 0) |
| 181 | ret = fdt_del_node(blob, childoff); |
| 182 | } |
| 183 | |
| 184 | return ret; |
| 185 | } |
| 186 | #endif /* CONFIG_PPC */ |
| 187 | |
| 188 | void fdt_fixup_qportals(void *blob) |
| 189 | { |
| 190 | int off, err; |
| 191 | unsigned int maj, min; |
| 192 | unsigned int ip_cfg; |
Tom Rini | 376b88a | 2022-10-28 20:27:13 -0400 | [diff] [blame] | 193 | struct ccsr_qman *qman = (void *)CFG_SYS_FSL_QMAN_ADDR; |
Ahmed Mansour | aa270b4 | 2017-12-15 16:01:00 -0500 | [diff] [blame] | 194 | u32 rev_1 = in_be32(&qman->ip_rev_1); |
| 195 | u32 rev_2 = in_be32(&qman->ip_rev_2); |
| 196 | char compat[64]; |
| 197 | int compat_len; |
| 198 | |
Laurentiu Tudor | 810eb76 | 2018-08-27 17:34:00 +0300 | [diff] [blame] | 199 | #if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) |
Laurentiu Tudor | 1238f74 | 2018-08-09 15:19:47 +0300 | [diff] [blame] | 200 | int smmu_ph = fdt_get_smmu_phandle(blob); |
| 201 | #endif |
| 202 | |
Ahmed Mansour | aa270b4 | 2017-12-15 16:01:00 -0500 | [diff] [blame] | 203 | maj = (rev_1 >> 8) & 0xff; |
| 204 | min = rev_1 & 0xff; |
| 205 | ip_cfg = rev_2 & 0xff; |
| 206 | |
| 207 | compat_len = sprintf(compat, "fsl,qman-portal-%u.%u.%u", |
| 208 | maj, min, ip_cfg) + 1; |
| 209 | compat_len += sprintf(compat + compat_len, "fsl,qman-portal") + 1; |
| 210 | |
Marek BehĂșn | 5d6b448 | 2022-01-20 01:04:42 +0100 | [diff] [blame] | 211 | fdt_for_each_node_by_compatible(off, blob, -1, "fsl,qman-portal") { |
Laurentiu Tudor | 810eb76 | 2018-08-27 17:34:00 +0300 | [diff] [blame] | 212 | #if defined(CONFIG_PPC) || defined(CONFIG_ARCH_LS1043A) || \ |
| 213 | defined(CONFIG_ARCH_LS1046A) |
Ahmed Mansour | aa270b4 | 2017-12-15 16:01:00 -0500 | [diff] [blame] | 214 | #ifdef CONFIG_FSL_CORENET |
| 215 | u32 liodns[2]; |
| 216 | #endif |
| 217 | const int *ci = fdt_getprop(blob, off, "cell-index", &err); |
| 218 | int i; |
| 219 | |
| 220 | if (!ci) |
| 221 | goto err; |
| 222 | |
Laurentiu Tudor | 1238f74 | 2018-08-09 15:19:47 +0300 | [diff] [blame] | 223 | i = fdt32_to_cpu(*ci); |
| 224 | #if defined(CONFIG_SYS_DPAA_FMAN) && defined(CONFIG_PPC) |
Ahmed Mansour | aa270b4 | 2017-12-15 16:01:00 -0500 | [diff] [blame] | 225 | int j; |
| 226 | #endif |
| 227 | |
Laurentiu Tudor | 810eb76 | 2018-08-27 17:34:00 +0300 | [diff] [blame] | 228 | #endif /* CONFIG_PPC || CONFIG_ARCH_LS1043A || CONFIG_ARCH_LS1046A */ |
Ahmed Mansour | aa270b4 | 2017-12-15 16:01:00 -0500 | [diff] [blame] | 229 | err = fdt_setprop(blob, off, "compatible", compat, compat_len); |
| 230 | if (err < 0) |
| 231 | goto err; |
| 232 | #ifdef CONFIG_PPC |
| 233 | #ifdef CONFIG_FSL_CORENET |
| 234 | liodns[0] = qp_info[i].dliodn; |
| 235 | liodns[1] = qp_info[i].fliodn; |
| 236 | err = fdt_setprop(blob, off, "fsl,liodn", |
| 237 | &liodns, sizeof(u32) * 2); |
| 238 | if (err < 0) |
| 239 | goto err; |
| 240 | #endif |
| 241 | |
| 242 | i++; |
| 243 | |
| 244 | err = fdt_qportal(blob, off, i, "crypto@0", FSL_HW_PORTAL_SEC, |
| 245 | IS_E_PROCESSOR(get_svr())); |
| 246 | if (err < 0) |
| 247 | goto err; |
| 248 | |
| 249 | #ifdef CONFIG_FSL_CORENET |
| 250 | #ifdef CONFIG_SYS_DPAA_PME |
| 251 | err = fdt_qportal(blob, off, i, "pme@0", FSL_HW_PORTAL_PME, 1); |
| 252 | if (err < 0) |
| 253 | goto err; |
| 254 | #else |
| 255 | fdt_qportal(blob, off, i, "pme@0", FSL_HW_PORTAL_PME, 0); |
| 256 | #endif |
| 257 | #endif |
| 258 | |
| 259 | #ifdef CONFIG_SYS_DPAA_FMAN |
Tom Rini | 0a2bac7 | 2022-11-16 13:10:29 -0500 | [diff] [blame] | 260 | for (j = 0; j < CFG_SYS_NUM_FMAN; j++) { |
Ahmed Mansour | aa270b4 | 2017-12-15 16:01:00 -0500 | [diff] [blame] | 261 | char name[] = "fman@0"; |
| 262 | |
| 263 | name[sizeof(name) - 2] = '0' + j; |
| 264 | err = fdt_qportal(blob, off, i, name, |
| 265 | FSL_HW_PORTAL_FMAN1 + j, 1); |
| 266 | if (err < 0) |
| 267 | goto err; |
| 268 | } |
| 269 | #endif |
| 270 | #ifdef CONFIG_SYS_DPAA_RMAN |
| 271 | err = fdt_qportal(blob, off, i, "rman@0", |
| 272 | FSL_HW_PORTAL_RMAN, 1); |
| 273 | if (err < 0) |
| 274 | goto err; |
| 275 | #endif |
Laurentiu Tudor | 1238f74 | 2018-08-09 15:19:47 +0300 | [diff] [blame] | 276 | #else |
Laurentiu Tudor | 810eb76 | 2018-08-27 17:34:00 +0300 | [diff] [blame] | 277 | #if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) |
Laurentiu Tudor | 1238f74 | 2018-08-09 15:19:47 +0300 | [diff] [blame] | 278 | if (smmu_ph >= 0) { |
| 279 | u32 icids[3]; |
| 280 | |
| 281 | icids[0] = qp_info[i].icid; |
| 282 | icids[1] = qp_info[i].dicid; |
| 283 | icids[2] = qp_info[i].ficid; |
| 284 | |
| 285 | fdt_set_iommu_prop(blob, off, smmu_ph, icids, 3); |
| 286 | } |
| 287 | #endif |
Ahmed Mansour | aa270b4 | 2017-12-15 16:01:00 -0500 | [diff] [blame] | 288 | #endif /* CONFIG_PPC */ |
| 289 | |
| 290 | err: |
| 291 | if (err < 0) { |
| 292 | printf("ERROR: unable to create props for %s: %s\n", |
| 293 | fdt_get_name(blob, off, NULL), |
| 294 | fdt_strerror(err)); |
| 295 | return; |
| 296 | } |
Ahmed Mansour | aa270b4 | 2017-12-15 16:01:00 -0500 | [diff] [blame] | 297 | } |
| 298 | } |
| 299 | |
| 300 | void fdt_fixup_bportals(void *blob) |
| 301 | { |
| 302 | int off, err; |
| 303 | unsigned int maj, min; |
| 304 | unsigned int ip_cfg; |
Tom Rini | 376b88a | 2022-10-28 20:27:13 -0400 | [diff] [blame] | 305 | struct ccsr_bman *bman = (void *)CFG_SYS_FSL_BMAN_ADDR; |
Ahmed Mansour | aa270b4 | 2017-12-15 16:01:00 -0500 | [diff] [blame] | 306 | u32 rev_1 = in_be32(&bman->ip_rev_1); |
| 307 | u32 rev_2 = in_be32(&bman->ip_rev_2); |
| 308 | char compat[64]; |
| 309 | int compat_len; |
| 310 | |
| 311 | maj = (rev_1 >> 8) & 0xff; |
| 312 | min = rev_1 & 0xff; |
| 313 | |
| 314 | ip_cfg = rev_2 & 0xff; |
| 315 | |
| 316 | compat_len = sprintf(compat, "fsl,bman-portal-%u.%u.%u", |
| 317 | maj, min, ip_cfg) + 1; |
| 318 | compat_len += sprintf(compat + compat_len, "fsl,bman-portal") + 1; |
| 319 | |
| 320 | off = fdt_node_offset_by_compatible(blob, -1, "fsl,bman-portal"); |
| 321 | while (off != -FDT_ERR_NOTFOUND) { |
| 322 | err = fdt_setprop(blob, off, "compatible", compat, compat_len); |
| 323 | if (err < 0) { |
| 324 | printf("ERROR: unable to create props for %s: %s\n", |
| 325 | fdt_get_name(blob, off, NULL), |
| 326 | fdt_strerror(err)); |
| 327 | return; |
| 328 | } |
| 329 | |
| 330 | off = fdt_node_offset_by_compatible(blob, off, |
| 331 | "fsl,bman-portal"); |
| 332 | } |
| 333 | } |