Kumar Gala | db977ab | 2009-09-10 03:02:13 -0500 | [diff] [blame] | 1 | /* |
Haiying Wang | 24995d8 | 2011-01-20 22:26:31 +0000 | [diff] [blame] | 2 | * Copyright 2008-2011 Freescale Semiconductor, Inc. |
Kumar Gala | db977ab | 2009-09-10 03:02:13 -0500 | [diff] [blame] | 3 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 4 | * SPDX-License-Identifier: GPL-2.0+ |
Kumar Gala | db977ab | 2009-09-10 03:02:13 -0500 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <libfdt.h> |
| 9 | #include <fdt_support.h> |
| 10 | |
| 11 | #include <asm/processor.h> |
| 12 | #include <asm/io.h> |
| 13 | |
| 14 | #include <asm/fsl_portals.h> |
| 15 | #include <asm/fsl_liodn.h> |
| 16 | |
Kumar Gala | db977ab | 2009-09-10 03:02:13 -0500 | [diff] [blame] | 17 | void setup_portals(void) |
| 18 | { |
Jeffrey Ladouceur | 3c1bfc0 | 2013-01-25 10:38:53 +0000 | [diff] [blame] | 19 | ccsr_qman_t *qman = (void *)CONFIG_SYS_FSL_QMAN_ADDR; |
Haiying Wang | 24995d8 | 2011-01-20 22:26:31 +0000 | [diff] [blame] | 20 | #ifdef CONFIG_FSL_CORENET |
Kumar Gala | db977ab | 2009-09-10 03:02:13 -0500 | [diff] [blame] | 21 | int i; |
| 22 | |
Kumar Gala | db977ab | 2009-09-10 03:02:13 -0500 | [diff] [blame] | 23 | for (i = 0; i < CONFIG_SYS_QMAN_NUM_PORTALS; i++) { |
| 24 | u8 sdest = qp_info[i].sdest; |
| 25 | u16 fliodn = qp_info[i].fliodn; |
| 26 | u16 dliodn = qp_info[i].dliodn; |
| 27 | u16 liodn_off = qp_info[i].liodn_offset; |
| 28 | |
| 29 | out_be32(&qman->qcsp[i].qcsp_lio_cfg, (liodn_off << 16) | |
| 30 | dliodn); |
| 31 | /* set frame liodn */ |
| 32 | out_be32(&qman->qcsp[i].qcsp_io_cfg, (sdest << 16) | fliodn); |
| 33 | } |
Haiying Wang | 24995d8 | 2011-01-20 22:26:31 +0000 | [diff] [blame] | 34 | #endif |
| 35 | |
| 36 | /* Set the Qman initiator BAR to match the LAW (for DQRR stashing) */ |
| 37 | #ifdef CONFIG_PHYS_64BIT |
| 38 | out_be32(&qman->qcsp_bare, (u32)(CONFIG_SYS_QMAN_MEM_PHYS >> 32)); |
| 39 | #endif |
| 40 | out_be32(&qman->qcsp_bar, (u32)CONFIG_SYS_QMAN_MEM_PHYS); |
Kumar Gala | db977ab | 2009-09-10 03:02:13 -0500 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | /* Update portal containter to match LAW setup of portal in phy map */ |
| 44 | void fdt_portal(void *blob, const char *compat, const char *container, |
| 45 | u64 addr, u32 size) |
| 46 | { |
| 47 | int off; |
| 48 | |
| 49 | off = fdt_node_offset_by_compatible(blob, -1, compat); |
| 50 | if (off < 0) |
| 51 | return ; |
| 52 | |
| 53 | off = fdt_parent_offset(blob, off); |
| 54 | /* if non-zero assume we have a container */ |
| 55 | if (off > 0) { |
| 56 | char buf[60]; |
| 57 | const char *p, *name; |
| 58 | u32 *range; |
| 59 | int len; |
| 60 | |
| 61 | /* fixup ranges */ |
| 62 | range = fdt_getprop_w(blob, off, "ranges", &len); |
| 63 | if (range == NULL) { |
| 64 | printf("ERROR: container for %s has no ranges", compat); |
| 65 | return ; |
| 66 | } |
| 67 | |
| 68 | range[0] = 0; |
| 69 | if (len == 16) { |
| 70 | range[1] = addr >> 32; |
| 71 | range[2] = addr & 0xffffffff; |
| 72 | range[3] = size; |
| 73 | } else { |
| 74 | range[1] = addr & 0xffffffff; |
| 75 | range[2] = size; |
| 76 | } |
| 77 | fdt_setprop_inplace(blob, off, "ranges", range, len); |
| 78 | |
| 79 | /* fixup the name */ |
| 80 | name = fdt_get_name(blob, off, &len); |
| 81 | p = memchr(name, '@', len); |
| 82 | |
| 83 | if (p) |
| 84 | len = p - name; |
| 85 | |
| 86 | /* if we are given a container name check it |
| 87 | * against what we found, if it doesnt match exit out */ |
| 88 | if (container && (memcmp(container, name, len))) { |
| 89 | printf("WARNING: container names didn't match %s %s\n", |
| 90 | container, name); |
| 91 | return ; |
| 92 | } |
| 93 | |
| 94 | memcpy(&buf, name, len); |
| 95 | len += sprintf(&buf[len], "@%llx", addr); |
| 96 | fdt_set_name(blob, off, buf); |
| 97 | return ; |
| 98 | } |
| 99 | |
| 100 | printf("ERROR: %s isn't in a container. Not supported\n", compat); |
| 101 | } |
| 102 | |
| 103 | static int fdt_qportal(void *blob, int off, int id, char *name, |
| 104 | enum fsl_dpaa_dev dev, int create) |
| 105 | { |
Haiying Wang | 24995d8 | 2011-01-20 22:26:31 +0000 | [diff] [blame] | 106 | int childoff, dev_off, ret = 0; |
Kumar Gala | db977ab | 2009-09-10 03:02:13 -0500 | [diff] [blame] | 107 | uint32_t dev_handle; |
Haiying Wang | 24995d8 | 2011-01-20 22:26:31 +0000 | [diff] [blame] | 108 | #ifdef CONFIG_FSL_CORENET |
| 109 | int num; |
Kumar Gala | db977ab | 2009-09-10 03:02:13 -0500 | [diff] [blame] | 110 | u32 liodns[2]; |
Haiying Wang | 24995d8 | 2011-01-20 22:26:31 +0000 | [diff] [blame] | 111 | #endif |
Kumar Gala | db977ab | 2009-09-10 03:02:13 -0500 | [diff] [blame] | 112 | |
| 113 | childoff = fdt_subnode_offset(blob, off, name); |
| 114 | if (create) { |
York Sun | e1d5a27 | 2013-03-25 07:33:21 +0000 | [diff] [blame] | 115 | char handle[64], *p; |
| 116 | |
| 117 | strncpy(handle, name, sizeof(handle)); |
| 118 | p = strchr(handle, '@'); |
| 119 | if (!strncmp(name, "fman", 4)) { |
| 120 | *p = *(p + 1); |
| 121 | p++; |
| 122 | } |
| 123 | *p = '\0'; |
| 124 | |
| 125 | dev_off = fdt_path_offset(blob, handle); |
| 126 | /* skip this node if alias is not found */ |
| 127 | if (dev_off == -FDT_ERR_BADPATH) |
| 128 | return 0; |
| 129 | if (dev_off < 0) |
| 130 | return dev_off; |
| 131 | |
Kumar Gala | db977ab | 2009-09-10 03:02:13 -0500 | [diff] [blame] | 132 | if (childoff <= 0) |
| 133 | childoff = fdt_add_subnode(blob, off, name); |
| 134 | |
York Sun | e1d5a27 | 2013-03-25 07:33:21 +0000 | [diff] [blame] | 135 | /* need to update the dev_off after adding a subnode */ |
| 136 | dev_off = fdt_path_offset(blob, handle); |
| 137 | if (dev_off < 0) |
| 138 | return dev_off; |
| 139 | |
Kumar Gala | db977ab | 2009-09-10 03:02:13 -0500 | [diff] [blame] | 140 | if (childoff > 0) { |
Kumar Gala | db977ab | 2009-09-10 03:02:13 -0500 | [diff] [blame] | 141 | dev_handle = fdt_get_phandle(blob, dev_off); |
| 142 | if (dev_handle <= 0) { |
| 143 | dev_handle = fdt_alloc_phandle(blob); |
Kumar Gala | f117c0f | 2011-08-01 00:23:23 -0500 | [diff] [blame] | 144 | ret = fdt_set_phandle(blob, dev_off, |
Timur Tabi | e4e7e42 | 2011-05-10 15:28:14 -0500 | [diff] [blame] | 145 | dev_handle); |
| 146 | if (ret < 0) |
| 147 | return ret; |
Kumar Gala | db977ab | 2009-09-10 03:02:13 -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 | |
Haiying Wang | 24995d8 | 2011-01-20 22:26:31 +0000 | [diff] [blame] | 155 | #ifdef CONFIG_FSL_CORENET |
Kumar Gala | db977ab | 2009-09-10 03:02:13 -0500 | [diff] [blame] | 156 | num = get_dpaa_liodn(dev, &liodns[0], id); |
| 157 | ret = fdt_setprop(blob, childoff, "fsl,liodn", |
| 158 | &liodns[0], sizeof(u32) * num); |
Jeffrey Ladouceur | 3c1bfc0 | 2013-01-25 10:38:53 +0000 | [diff] [blame] | 159 | if (!strncmp(name, "pme", 3)) { |
| 160 | u32 pme_rev1, pme_rev2; |
| 161 | ccsr_pme_t *pme_regs = |
| 162 | (void *)CONFIG_SYS_FSL_CORENET_PME_ADDR; |
| 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, sizeof(u32)); |
| 168 | if (ret < 0) |
| 169 | return ret; |
| 170 | ret = fdt_setprop(blob, childoff, |
| 171 | "fsl,pme-rev2", &pme_rev2, sizeof(u32)); |
| 172 | } |
Haiying Wang | 24995d8 | 2011-01-20 22:26:31 +0000 | [diff] [blame] | 173 | #endif |
Kumar Gala | db977ab | 2009-09-10 03:02:13 -0500 | [diff] [blame] | 174 | } else { |
| 175 | return childoff; |
| 176 | } |
| 177 | } else { |
| 178 | if (childoff > 0) |
| 179 | ret = fdt_del_node(blob, childoff); |
| 180 | } |
| 181 | |
| 182 | return ret; |
| 183 | } |
| 184 | |
| 185 | void fdt_fixup_qportals(void *blob) |
| 186 | { |
| 187 | int off, err; |
| 188 | unsigned int maj, min; |
Haiying Wang | b0e8115 | 2012-10-11 07:13:38 +0000 | [diff] [blame] | 189 | unsigned int ip_cfg; |
Jeffrey Ladouceur | 3c1bfc0 | 2013-01-25 10:38:53 +0000 | [diff] [blame] | 190 | ccsr_qman_t *qman = (void *)CONFIG_SYS_FSL_QMAN_ADDR; |
Kumar Gala | db977ab | 2009-09-10 03:02:13 -0500 | [diff] [blame] | 191 | u32 rev_1 = in_be32(&qman->ip_rev_1); |
Haiying Wang | b0e8115 | 2012-10-11 07:13:38 +0000 | [diff] [blame] | 192 | u32 rev_2 = in_be32(&qman->ip_rev_2); |
Kumar Gala | db977ab | 2009-09-10 03:02:13 -0500 | [diff] [blame] | 193 | char compat[64]; |
| 194 | int compat_len; |
| 195 | |
| 196 | maj = (rev_1 >> 8) & 0xff; |
| 197 | min = rev_1 & 0xff; |
Haiying Wang | b0e8115 | 2012-10-11 07:13:38 +0000 | [diff] [blame] | 198 | ip_cfg = rev_2 & 0xff; |
Kumar Gala | db977ab | 2009-09-10 03:02:13 -0500 | [diff] [blame] | 199 | |
Haiying Wang | b0e8115 | 2012-10-11 07:13:38 +0000 | [diff] [blame] | 200 | compat_len = sprintf(compat, "fsl,qman-portal-%u.%u.%u", |
| 201 | maj, min, ip_cfg) + 1; |
Kumar Gala | db977ab | 2009-09-10 03:02:13 -0500 | [diff] [blame] | 202 | compat_len += sprintf(compat + compat_len, "fsl,qman-portal") + 1; |
| 203 | |
| 204 | off = fdt_node_offset_by_compatible(blob, -1, "fsl,qman-portal"); |
| 205 | while (off != -FDT_ERR_NOTFOUND) { |
Haiying Wang | 24995d8 | 2011-01-20 22:26:31 +0000 | [diff] [blame] | 206 | #ifdef CONFIG_FSL_CORENET |
Kumar Gala | db977ab | 2009-09-10 03:02:13 -0500 | [diff] [blame] | 207 | u32 liodns[2]; |
Haiying Wang | 24995d8 | 2011-01-20 22:26:31 +0000 | [diff] [blame] | 208 | #endif |
Kumar Gala | db977ab | 2009-09-10 03:02:13 -0500 | [diff] [blame] | 209 | const int *ci = fdt_getprop(blob, off, "cell-index", NULL); |
Kumar Gala | e2d0f25 | 2011-07-31 12:55:39 -0500 | [diff] [blame] | 210 | int i = *ci; |
| 211 | #ifdef CONFIG_SYS_DPAA_FMAN |
| 212 | int j; |
| 213 | #endif |
Kumar Gala | db977ab | 2009-09-10 03:02:13 -0500 | [diff] [blame] | 214 | |
| 215 | err = fdt_setprop(blob, off, "compatible", compat, compat_len); |
| 216 | if (err < 0) |
| 217 | goto err; |
| 218 | |
Haiying Wang | 24995d8 | 2011-01-20 22:26:31 +0000 | [diff] [blame] | 219 | #ifdef CONFIG_FSL_CORENET |
Kumar Gala | db977ab | 2009-09-10 03:02:13 -0500 | [diff] [blame] | 220 | liodns[0] = qp_info[i].dliodn; |
| 221 | liodns[1] = qp_info[i].fliodn; |
| 222 | |
| 223 | err = fdt_setprop(blob, off, "fsl,liodn", |
| 224 | &liodns, sizeof(u32) * 2); |
| 225 | if (err < 0) |
| 226 | goto err; |
Haiying Wang | 24995d8 | 2011-01-20 22:26:31 +0000 | [diff] [blame] | 227 | #endif |
Kumar Gala | db977ab | 2009-09-10 03:02:13 -0500 | [diff] [blame] | 228 | |
| 229 | i++; |
| 230 | |
| 231 | err = fdt_qportal(blob, off, i, "crypto@0", FSL_HW_PORTAL_SEC, |
| 232 | IS_E_PROCESSOR(get_svr())); |
| 233 | if (err < 0) |
| 234 | goto err; |
| 235 | |
Haiying Wang | 24995d8 | 2011-01-20 22:26:31 +0000 | [diff] [blame] | 236 | #ifdef CONFIG_FSL_CORENET |
Kumar Gala | db977ab | 2009-09-10 03:02:13 -0500 | [diff] [blame] | 237 | #ifdef CONFIG_SYS_DPAA_PME |
| 238 | err = fdt_qportal(blob, off, i, "pme@0", FSL_HW_PORTAL_PME, 1); |
| 239 | if (err < 0) |
| 240 | goto err; |
| 241 | #else |
| 242 | fdt_qportal(blob, off, i, "pme@0", FSL_HW_PORTAL_PME, 0); |
| 243 | #endif |
Haiying Wang | 24995d8 | 2011-01-20 22:26:31 +0000 | [diff] [blame] | 244 | #endif |
| 245 | |
Kumar Gala | db977ab | 2009-09-10 03:02:13 -0500 | [diff] [blame] | 246 | #ifdef CONFIG_SYS_DPAA_FMAN |
| 247 | for (j = 0; j < CONFIG_SYS_NUM_FMAN; j++) { |
| 248 | char name[] = "fman@0"; |
| 249 | |
| 250 | name[sizeof(name) - 2] = '0' + j; |
| 251 | err = fdt_qportal(blob, off, i, name, |
| 252 | FSL_HW_PORTAL_FMAN1 + j, 1); |
| 253 | if (err < 0) |
| 254 | goto err; |
| 255 | } |
| 256 | #endif |
Kumar Gala | 4d28db8 | 2011-10-14 13:28:52 -0500 | [diff] [blame] | 257 | #ifdef CONFIG_SYS_DPAA_RMAN |
| 258 | err = fdt_qportal(blob, off, i, "rman@0", |
| 259 | FSL_HW_PORTAL_RMAN, 1); |
| 260 | if (err < 0) |
| 261 | goto err; |
| 262 | #endif |
Kumar Gala | db977ab | 2009-09-10 03:02:13 -0500 | [diff] [blame] | 263 | |
| 264 | err: |
| 265 | if (err < 0) { |
| 266 | printf("ERROR: unable to create props for %s: %s\n", |
| 267 | fdt_get_name(blob, off, NULL), fdt_strerror(err)); |
| 268 | return; |
| 269 | } |
| 270 | |
| 271 | off = fdt_node_offset_by_compatible(blob, off, "fsl,qman-portal"); |
| 272 | } |
| 273 | } |
Haiying Wang | 2a0ffb8 | 2011-03-01 09:30:07 -0500 | [diff] [blame] | 274 | |
| 275 | void fdt_fixup_bportals(void *blob) |
| 276 | { |
| 277 | int off, err; |
| 278 | unsigned int maj, min; |
Haiying Wang | b0e8115 | 2012-10-11 07:13:38 +0000 | [diff] [blame] | 279 | unsigned int ip_cfg; |
Jeffrey Ladouceur | 3c1bfc0 | 2013-01-25 10:38:53 +0000 | [diff] [blame] | 280 | ccsr_bman_t *bman = (void *)CONFIG_SYS_FSL_BMAN_ADDR; |
Haiying Wang | 2a0ffb8 | 2011-03-01 09:30:07 -0500 | [diff] [blame] | 281 | u32 rev_1 = in_be32(&bman->ip_rev_1); |
Haiying Wang | b0e8115 | 2012-10-11 07:13:38 +0000 | [diff] [blame] | 282 | u32 rev_2 = in_be32(&bman->ip_rev_2); |
Haiying Wang | 2a0ffb8 | 2011-03-01 09:30:07 -0500 | [diff] [blame] | 283 | char compat[64]; |
| 284 | int compat_len; |
| 285 | |
| 286 | maj = (rev_1 >> 8) & 0xff; |
| 287 | min = rev_1 & 0xff; |
| 288 | |
Haiying Wang | b0e8115 | 2012-10-11 07:13:38 +0000 | [diff] [blame] | 289 | ip_cfg = rev_2 & 0xff; |
| 290 | |
| 291 | compat_len = sprintf(compat, "fsl,bman-portal-%u.%u.%u", |
| 292 | maj, min, ip_cfg) + 1; |
Haiying Wang | 2a0ffb8 | 2011-03-01 09:30:07 -0500 | [diff] [blame] | 293 | compat_len += sprintf(compat + compat_len, "fsl,bman-portal") + 1; |
| 294 | |
| 295 | off = fdt_node_offset_by_compatible(blob, -1, "fsl,bman-portal"); |
| 296 | while (off != -FDT_ERR_NOTFOUND) { |
| 297 | err = fdt_setprop(blob, off, "compatible", compat, compat_len); |
| 298 | if (err < 0) { |
| 299 | printf("ERROR: unable to create props for %s: %s\n", |
| 300 | fdt_get_name(blob, off, NULL), |
| 301 | fdt_strerror(err)); |
| 302 | return; |
| 303 | } |
| 304 | |
| 305 | off = fdt_node_offset_by_compatible(blob, off, "fsl,bman-portal"); |
| 306 | } |
| 307 | |
| 308 | } |