Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 2 | /* |
Yogesh Gaur | 1a0c4ae | 2018-05-09 10:52:17 +0530 | [diff] [blame] | 3 | * Copyright 2014 Freescale Semiconductor, Inc. |
Prabhakar Kushwaha | 145e4cd | 2018-08-27 12:58:52 +0530 | [diff] [blame] | 4 | * Copyright 2017-2018 NXP |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 5 | */ |
Stuart Yoder | a2bdb77 | 2015-07-02 11:29:03 +0530 | [diff] [blame] | 6 | #include <common.h> |
Simon Glass | adaaa48 | 2019-11-14 12:57:43 -0700 | [diff] [blame] | 7 | #include <command.h> |
Simon Glass | 6333448 | 2019-11-14 12:57:39 -0700 | [diff] [blame] | 8 | #include <cpu_func.h> |
Simon Glass | 0af6e2d | 2019-08-01 09:46:52 -0600 | [diff] [blame] | 9 | #include <env.h> |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 10 | #include <errno.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 11 | #include <malloc.h> |
Masahiro Yamada | 78eeb91 | 2016-01-24 23:27:48 +0900 | [diff] [blame] | 12 | #include <linux/bug.h> |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 13 | #include <asm/io.h> |
Masahiro Yamada | 75f82d0 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 14 | #include <linux/libfdt.h> |
Bogdan Purcareata | bea8abd | 2017-01-11 15:58:36 +0000 | [diff] [blame] | 15 | #include <net.h> |
Stuart Yoder | a2bdb77 | 2015-07-02 11:29:03 +0530 | [diff] [blame] | 16 | #include <fdt_support.h> |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 17 | #include <fsl-mc/fsl_mc.h> |
| 18 | #include <fsl-mc/fsl_mc_sys.h> |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 19 | #include <fsl-mc/fsl_mc_private.h> |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 20 | #include <fsl-mc/fsl_dpmng.h> |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 21 | #include <fsl-mc/fsl_dprc.h> |
| 22 | #include <fsl-mc/fsl_dpio.h> |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 23 | #include <fsl-mc/fsl_dpni.h> |
Florinel Iordache | ae6d852 | 2019-11-19 10:28:17 +0000 | [diff] [blame] | 24 | #include <fsl-mc/fsl_dpsparser.h> |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 25 | #include <fsl-mc/fsl_qbman_portal.h> |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 26 | #include <fsl-mc/ldpaa_wriop.h> |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 27 | |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 28 | #define MC_RAM_BASE_ADDR_ALIGNMENT (512UL * 1024 * 1024) |
| 29 | #define MC_RAM_BASE_ADDR_ALIGNMENT_MASK (~(MC_RAM_BASE_ADDR_ALIGNMENT - 1)) |
| 30 | #define MC_RAM_SIZE_ALIGNMENT (256UL * 1024 * 1024) |
| 31 | |
| 32 | #define MC_MEM_SIZE_ENV_VAR "mcmemsize" |
| 33 | #define MC_BOOT_TIMEOUT_ENV_VAR "mcboottimeout" |
Bogdan Purcareata | 08bc014 | 2017-05-24 16:40:21 +0000 | [diff] [blame] | 34 | #define MC_BOOT_ENV_VAR "mcinitcmd" |
Meenakshi Aggarwal | 67f195c | 2019-02-27 14:41:02 +0530 | [diff] [blame] | 35 | #define MC_DRAM_BLOCK_DEFAULT_SIZE (512UL * 1024 * 1024) |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 36 | |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 37 | DECLARE_GLOBAL_DATA_PTR; |
Prabhakar Kushwaha | 145e4cd | 2018-08-27 12:58:52 +0530 | [diff] [blame] | 38 | static int mc_memset_resv_ram; |
Florinel Iordache | ae6d852 | 2019-11-19 10:28:17 +0000 | [diff] [blame] | 39 | static struct mc_version mc_ver_info; |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 40 | static int mc_boot_status = -1; |
| 41 | static int mc_dpl_applied = -1; |
| 42 | #ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET |
| 43 | static int mc_aiop_applied = -1; |
| 44 | #endif |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 45 | struct fsl_mc_io *root_mc_io = NULL; |
| 46 | struct fsl_mc_io *dflt_mc_io = NULL; /* child container */ |
| 47 | uint16_t root_dprc_handle = 0; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 48 | uint16_t dflt_dprc_handle = 0; |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 49 | int child_dprc_id; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 50 | struct fsl_dpbp_obj *dflt_dpbp = NULL; |
| 51 | struct fsl_dpio_obj *dflt_dpio = NULL; |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 52 | struct fsl_dpni_obj *dflt_dpni = NULL; |
Alexander Graf | 2ebeb44 | 2016-11-17 01:02:57 +0100 | [diff] [blame] | 53 | static u64 mc_lazy_dpl_addr; |
Florinel Iordache | ae6d852 | 2019-11-19 10:28:17 +0000 | [diff] [blame] | 54 | static u32 dpsparser_obj_id; |
| 55 | static u16 dpsparser_handle; |
| 56 | static char *mc_err_msg_apply_spb[] = MC_ERROR_MSG_APPLY_SPB; |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 57 | |
| 58 | #ifdef DEBUG |
| 59 | void dump_ram_words(const char *title, void *addr) |
| 60 | { |
| 61 | int i; |
| 62 | uint32_t *words = addr; |
| 63 | |
| 64 | printf("Dumping beginning of %s (%p):\n", title, addr); |
| 65 | for (i = 0; i < 16; i++) |
| 66 | printf("%#x ", words[i]); |
| 67 | |
| 68 | printf("\n"); |
| 69 | } |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 70 | |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 71 | void dump_mc_ccsr_regs(struct mc_ccsr_registers __iomem *mc_ccsr_regs) |
| 72 | { |
| 73 | printf("MC CCSR registers:\n" |
| 74 | "reg_gcr1 %#x\n" |
| 75 | "reg_gsr %#x\n" |
| 76 | "reg_sicbalr %#x\n" |
| 77 | "reg_sicbahr %#x\n" |
| 78 | "reg_sicapr %#x\n" |
| 79 | "reg_mcfbalr %#x\n" |
| 80 | "reg_mcfbahr %#x\n" |
| 81 | "reg_mcfapr %#x\n" |
| 82 | "reg_psr %#x\n", |
| 83 | mc_ccsr_regs->reg_gcr1, |
| 84 | mc_ccsr_regs->reg_gsr, |
| 85 | mc_ccsr_regs->reg_sicbalr, |
| 86 | mc_ccsr_regs->reg_sicbahr, |
| 87 | mc_ccsr_regs->reg_sicapr, |
| 88 | mc_ccsr_regs->reg_mcfbalr, |
| 89 | mc_ccsr_regs->reg_mcfbahr, |
| 90 | mc_ccsr_regs->reg_mcfapr, |
| 91 | mc_ccsr_regs->reg_psr); |
| 92 | } |
| 93 | #else |
| 94 | |
| 95 | #define dump_ram_words(title, addr) |
| 96 | #define dump_mc_ccsr_regs(mc_ccsr_regs) |
| 97 | |
| 98 | #endif /* DEBUG */ |
| 99 | |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 100 | /** |
| 101 | * Copying MC firmware or DPL image to DDR |
| 102 | */ |
| 103 | static int mc_copy_image(const char *title, |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 104 | u64 image_addr, u32 image_size, u64 mc_ram_addr) |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 105 | { |
| 106 | debug("%s copied to address %p\n", title, (void *)mc_ram_addr); |
| 107 | memcpy((void *)mc_ram_addr, (void *)image_addr, image_size); |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 108 | flush_dcache_range(mc_ram_addr, mc_ram_addr + image_size); |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 109 | return 0; |
| 110 | } |
| 111 | |
Florinel Iordache | ae6d852 | 2019-11-19 10:28:17 +0000 | [diff] [blame] | 112 | #ifndef CONFIG_SYS_LS_MC_FW_IN_DDR |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 113 | /** |
| 114 | * MC firmware FIT image parser checks if the image is in FIT |
| 115 | * format, verifies integrity of the image and calculates |
| 116 | * raw image address and size values. |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 117 | * Returns 0 on success and a negative errno on error. |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 118 | * task fail. |
| 119 | **/ |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 120 | int parse_mc_firmware_fit_image(u64 mc_fw_addr, |
| 121 | const void **raw_image_addr, |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 122 | size_t *raw_image_size) |
| 123 | { |
| 124 | int format; |
| 125 | void *fit_hdr; |
| 126 | int node_offset; |
| 127 | const void *data; |
| 128 | size_t size; |
| 129 | const char *uname = "firmware"; |
| 130 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 131 | fit_hdr = (void *)mc_fw_addr; |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 132 | |
| 133 | /* Check if Image is in FIT format */ |
| 134 | format = genimg_get_format(fit_hdr); |
| 135 | |
| 136 | if (format != IMAGE_FORMAT_FIT) { |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 137 | printf("fsl-mc: ERR: Bad firmware image (not a FIT image)\n"); |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 138 | return -EINVAL; |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | if (!fit_check_format(fit_hdr)) { |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 142 | printf("fsl-mc: ERR: Bad firmware image (bad FIT header)\n"); |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 143 | return -EINVAL; |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | node_offset = fit_image_get_node(fit_hdr, uname); |
| 147 | |
| 148 | if (node_offset < 0) { |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 149 | printf("fsl-mc: ERR: Bad firmware image (missing subimage)\n"); |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 150 | return -ENOENT; |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | /* Verify MC firmware image */ |
| 154 | if (!(fit_image_verify(fit_hdr, node_offset))) { |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 155 | printf("fsl-mc: ERR: Bad firmware image (bad CRC)\n"); |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 156 | return -EINVAL; |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | /* Get address and size of raw image */ |
| 160 | fit_image_get_data(fit_hdr, node_offset, &data, &size); |
| 161 | |
| 162 | *raw_image_addr = data; |
| 163 | *raw_image_size = size; |
| 164 | |
| 165 | return 0; |
| 166 | } |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 167 | #endif |
| 168 | |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 169 | #define MC_DT_INCREASE_SIZE 64 |
| 170 | |
| 171 | enum mc_fixup_type { |
| 172 | MC_FIXUP_DPL, |
| 173 | MC_FIXUP_DPC |
| 174 | }; |
| 175 | |
| 176 | static int mc_fixup_mac_addr(void *blob, int nodeoffset, |
Ioana Ciornei | 25f7cf7 | 2020-03-18 16:47:38 +0200 | [diff] [blame] | 177 | #ifdef CONFIG_DM_ETH |
| 178 | const char *propname, struct udevice *eth_dev, |
| 179 | #else |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 180 | const char *propname, struct eth_device *eth_dev, |
Ioana Ciornei | 25f7cf7 | 2020-03-18 16:47:38 +0200 | [diff] [blame] | 181 | #endif |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 182 | enum mc_fixup_type type) |
Bogdan Purcareata | bea8abd | 2017-01-11 15:58:36 +0000 | [diff] [blame] | 183 | { |
Ioana Ciornei | 25f7cf7 | 2020-03-18 16:47:38 +0200 | [diff] [blame] | 184 | #ifdef CONFIG_DM_ETH |
| 185 | struct eth_pdata *plat = dev_get_platdata(eth_dev); |
| 186 | unsigned char *enetaddr = plat->enetaddr; |
| 187 | int eth_index = eth_dev->seq; |
| 188 | #else |
| 189 | unsigned char *enetaddr = eth_dev->enetaddr; |
| 190 | int eth_index = eth_dev->index; |
| 191 | #endif |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 192 | int err = 0, len = 0, size, i; |
| 193 | unsigned char env_enetaddr[ARP_HLEN]; |
| 194 | unsigned int enetaddr_32[ARP_HLEN]; |
| 195 | void *val = NULL; |
| 196 | |
| 197 | switch (type) { |
| 198 | case MC_FIXUP_DPL: |
Ioana Ciornei | 25f7cf7 | 2020-03-18 16:47:38 +0200 | [diff] [blame] | 199 | /* DPL likes its addresses on 32 * ARP_HLEN bits */ |
| 200 | for (i = 0; i < ARP_HLEN; i++) |
| 201 | enetaddr_32[i] = cpu_to_fdt32(enetaddr[i]); |
| 202 | val = enetaddr_32; |
| 203 | len = sizeof(enetaddr_32); |
| 204 | break; |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 205 | case MC_FIXUP_DPC: |
Ioana Ciornei | 25f7cf7 | 2020-03-18 16:47:38 +0200 | [diff] [blame] | 206 | val = enetaddr; |
| 207 | len = ARP_HLEN; |
| 208 | break; |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | /* MAC address property present */ |
| 212 | if (fdt_get_property(blob, nodeoffset, propname, NULL)) { |
| 213 | /* u-boot MAC addr randomly assigned - leave the present one */ |
Ioana Ciornei | 25f7cf7 | 2020-03-18 16:47:38 +0200 | [diff] [blame] | 214 | if (!eth_env_get_enetaddr_by_index("eth", eth_index, |
Simon Glass | 399a9ce | 2017-08-03 12:22:14 -0600 | [diff] [blame] | 215 | env_enetaddr)) |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 216 | return err; |
| 217 | } else { |
| 218 | size = MC_DT_INCREASE_SIZE + strlen(propname) + len; |
| 219 | /* make room for mac address property */ |
| 220 | err = fdt_increase_size(blob, size); |
| 221 | if (err) { |
| 222 | printf("fdt_increase_size: err=%s\n", |
| 223 | fdt_strerror(err)); |
| 224 | return err; |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | err = fdt_setprop(blob, nodeoffset, propname, val, len); |
| 229 | if (err) { |
| 230 | printf("fdt_setprop: err=%s\n", fdt_strerror(err)); |
| 231 | return err; |
| 232 | } |
| 233 | |
| 234 | return err; |
| 235 | } |
| 236 | |
| 237 | #define is_dpni(s) (s != NULL ? !strncmp(s, "dpni@", 5) : 0) |
| 238 | |
| 239 | const char *dpl_get_connection_endpoint(void *blob, char *endpoint) |
| 240 | { |
| 241 | int connoffset = fdt_path_offset(blob, "/connections"), off; |
| 242 | const char *s1, *s2; |
| 243 | |
| 244 | for (off = fdt_first_subnode(blob, connoffset); |
| 245 | off >= 0; |
| 246 | off = fdt_next_subnode(blob, off)) { |
| 247 | s1 = fdt_stringlist_get(blob, off, "endpoint1", 0, NULL); |
| 248 | s2 = fdt_stringlist_get(blob, off, "endpoint2", 0, NULL); |
| 249 | |
| 250 | if (!s1 || !s2) |
| 251 | continue; |
| 252 | |
| 253 | if (strcmp(endpoint, s1) == 0) |
| 254 | return s2; |
| 255 | |
| 256 | if (strcmp(endpoint, s2) == 0) |
| 257 | return s1; |
| 258 | } |
| 259 | |
| 260 | return NULL; |
| 261 | } |
| 262 | |
| 263 | static int mc_fixup_dpl_mac_addr(void *blob, int dpmac_id, |
Ioana Ciornei | 25f7cf7 | 2020-03-18 16:47:38 +0200 | [diff] [blame] | 264 | #ifdef CONFIG_DM_ETH |
| 265 | struct udevice *eth_dev) |
| 266 | #else |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 267 | struct eth_device *eth_dev) |
Ioana Ciornei | 25f7cf7 | 2020-03-18 16:47:38 +0200 | [diff] [blame] | 268 | #endif |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 269 | { |
| 270 | int objoff = fdt_path_offset(blob, "/objects"); |
| 271 | int dpmacoff = -1, dpnioff = -1; |
| 272 | const char *endpoint; |
| 273 | char mac_name[10]; |
| 274 | int err; |
| 275 | |
| 276 | sprintf(mac_name, "dpmac@%d", dpmac_id); |
| 277 | dpmacoff = fdt_subnode_offset(blob, objoff, mac_name); |
| 278 | if (dpmacoff < 0) |
| 279 | /* dpmac not defined in DPL, so skip it. */ |
| 280 | return 0; |
| 281 | |
| 282 | err = mc_fixup_mac_addr(blob, dpmacoff, "mac_addr", eth_dev, |
| 283 | MC_FIXUP_DPL); |
| 284 | if (err) { |
| 285 | printf("Error fixing up dpmac mac_addr in DPL\n"); |
| 286 | return err; |
| 287 | } |
| 288 | |
| 289 | /* now we need to figure out if there is any |
| 290 | * DPNI connected to this MAC, so we walk the |
| 291 | * connection list |
| 292 | */ |
| 293 | endpoint = dpl_get_connection_endpoint(blob, mac_name); |
| 294 | if (!is_dpni(endpoint)) |
| 295 | return 0; |
| 296 | |
| 297 | /* let's see if we can fixup the DPNI as well */ |
| 298 | dpnioff = fdt_subnode_offset(blob, objoff, endpoint); |
| 299 | if (dpnioff < 0) |
| 300 | /* DPNI not defined in DPL in the objects area */ |
| 301 | return 0; |
| 302 | |
| 303 | return mc_fixup_mac_addr(blob, dpnioff, "mac_addr", eth_dev, |
| 304 | MC_FIXUP_DPL); |
| 305 | } |
| 306 | |
Meenakshi Aggarwal | d67ae48 | 2019-05-23 15:13:43 +0530 | [diff] [blame] | 307 | void fdt_fixup_mc_ddr(u64 *base, u64 *size) |
| 308 | { |
| 309 | u64 mc_size = mc_get_dram_block_size(); |
| 310 | |
| 311 | if (mc_size < MC_DRAM_BLOCK_DEFAULT_SIZE) { |
| 312 | *base = mc_get_dram_addr() + mc_size; |
| 313 | *size = MC_DRAM_BLOCK_DEFAULT_SIZE - mc_size; |
| 314 | } |
| 315 | } |
| 316 | |
Nipun Gupta | d691264 | 2018-08-20 16:01:14 +0530 | [diff] [blame] | 317 | void fdt_fsl_mc_fixup_iommu_map_entry(void *blob) |
| 318 | { |
| 319 | u32 *prop; |
| 320 | u32 iommu_map[4]; |
| 321 | int offset; |
| 322 | int lenp; |
| 323 | |
| 324 | /* find fsl-mc node */ |
| 325 | offset = fdt_path_offset(blob, "/soc/fsl-mc"); |
| 326 | if (offset < 0) |
| 327 | offset = fdt_path_offset(blob, "/fsl-mc"); |
| 328 | if (offset < 0) { |
| 329 | printf("%s: fsl-mc: ERR: fsl-mc node not found in DT, err %d\n", |
| 330 | __func__, offset); |
| 331 | return; |
| 332 | } |
| 333 | |
| 334 | prop = fdt_getprop_w(blob, offset, "iommu-map", &lenp); |
| 335 | if (!prop) { |
| 336 | debug("%s: fsl-mc: ERR: missing iommu-map in fsl-mc bus node\n", |
| 337 | __func__); |
| 338 | return; |
| 339 | } |
| 340 | |
| 341 | iommu_map[0] = cpu_to_fdt32(FSL_DPAA2_STREAM_ID_START); |
| 342 | iommu_map[1] = *++prop; |
| 343 | iommu_map[2] = cpu_to_fdt32(FSL_DPAA2_STREAM_ID_START); |
| 344 | iommu_map[3] = cpu_to_fdt32(FSL_DPAA2_STREAM_ID_END - |
| 345 | FSL_DPAA2_STREAM_ID_START + 1); |
| 346 | |
| 347 | fdt_setprop_inplace(blob, offset, "iommu-map", |
| 348 | iommu_map, sizeof(iommu_map)); |
| 349 | } |
| 350 | |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 351 | static int mc_fixup_dpc_mac_addr(void *blob, int dpmac_id, |
Ioana Ciornei | 25f7cf7 | 2020-03-18 16:47:38 +0200 | [diff] [blame] | 352 | #ifdef CONFIG_DM_ETH |
| 353 | struct udevice *eth_dev) |
| 354 | #else |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 355 | struct eth_device *eth_dev) |
Ioana Ciornei | 25f7cf7 | 2020-03-18 16:47:38 +0200 | [diff] [blame] | 356 | #endif |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 357 | { |
| 358 | int nodeoffset = fdt_path_offset(blob, "/board_info/ports"), noff; |
| 359 | int err = 0; |
Bogdan Purcareata | bea8abd | 2017-01-11 15:58:36 +0000 | [diff] [blame] | 360 | char mac_name[10]; |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 361 | const char link_type_mode[] = "MAC_LINK_TYPE_FIXED"; |
Bogdan Purcareata | bea8abd | 2017-01-11 15:58:36 +0000 | [diff] [blame] | 362 | |
| 363 | sprintf(mac_name, "mac@%d", dpmac_id); |
| 364 | |
| 365 | /* node not found - create it */ |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 366 | noff = fdt_subnode_offset(blob, nodeoffset, (const char *)mac_name); |
| 367 | if (noff < 0) { |
Bogdan Purcareata | bea8abd | 2017-01-11 15:58:36 +0000 | [diff] [blame] | 368 | err = fdt_increase_size(blob, 200); |
| 369 | if (err) { |
| 370 | printf("fdt_increase_size: err=%s\n", |
| 371 | fdt_strerror(err)); |
| 372 | return err; |
| 373 | } |
| 374 | |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 375 | noff = fdt_add_subnode(blob, nodeoffset, mac_name); |
| 376 | if (noff < 0) { |
| 377 | printf("fdt_add_subnode: err=%s\n", |
| 378 | fdt_strerror(err)); |
| 379 | return err; |
| 380 | } |
Bogdan Purcareata | bea8abd | 2017-01-11 15:58:36 +0000 | [diff] [blame] | 381 | |
| 382 | /* add default property of fixed link */ |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 383 | err = fdt_appendprop_string(blob, noff, |
Bogdan Purcareata | bea8abd | 2017-01-11 15:58:36 +0000 | [diff] [blame] | 384 | "link_type", link_type_mode); |
| 385 | if (err) { |
| 386 | printf("fdt_appendprop_string: err=%s\n", |
| 387 | fdt_strerror(err)); |
| 388 | return err; |
| 389 | } |
| 390 | } |
| 391 | |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 392 | return mc_fixup_mac_addr(blob, noff, "port_mac_address", eth_dev, |
| 393 | MC_FIXUP_DPC); |
| 394 | } |
Bogdan Purcareata | bea8abd | 2017-01-11 15:58:36 +0000 | [diff] [blame] | 395 | |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 396 | static int mc_fixup_mac_addrs(void *blob, enum mc_fixup_type type) |
| 397 | { |
| 398 | int i, err = 0, ret = 0; |
Ioana Ciornei | 25f7cf7 | 2020-03-18 16:47:38 +0200 | [diff] [blame] | 399 | #ifdef CONFIG_DM_ETH |
| 400 | #define ETH_NAME_LEN 20 |
| 401 | struct udevice *eth_dev; |
| 402 | #else |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 403 | struct eth_device *eth_dev; |
Ioana Ciornei | 25f7cf7 | 2020-03-18 16:47:38 +0200 | [diff] [blame] | 404 | #endif |
| 405 | char ethname[ETH_NAME_LEN]; |
Bogdan Purcareata | bea8abd | 2017-01-11 15:58:36 +0000 | [diff] [blame] | 406 | |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 407 | for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++) { |
| 408 | /* port not enabled */ |
Pankaj Bansal | 7987ab7 | 2018-10-10 14:08:33 +0530 | [diff] [blame] | 409 | if (wriop_is_enabled_dpmac(i) != 1) |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 410 | continue; |
Bogdan Purcareata | bea8abd | 2017-01-11 15:58:36 +0000 | [diff] [blame] | 411 | |
Pankaj Bansal | 8a92170 | 2018-08-02 16:31:28 +0530 | [diff] [blame] | 412 | snprintf(ethname, ETH_NAME_LEN, "DPMAC%d@%s", i, |
| 413 | phy_interface_strings[wriop_get_enet_if(i)]); |
Bogdan Purcareata | bea8abd | 2017-01-11 15:58:36 +0000 | [diff] [blame] | 414 | |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 415 | eth_dev = eth_get_dev_by_name(ethname); |
| 416 | if (eth_dev == NULL) |
| 417 | continue; |
| 418 | |
| 419 | switch (type) { |
| 420 | case MC_FIXUP_DPL: |
| 421 | err = mc_fixup_dpl_mac_addr(blob, i, eth_dev); |
| 422 | break; |
| 423 | case MC_FIXUP_DPC: |
| 424 | err = mc_fixup_dpc_mac_addr(blob, i, eth_dev); |
| 425 | break; |
| 426 | default: |
| 427 | break; |
| 428 | } |
| 429 | |
| 430 | if (err) |
| 431 | printf("fsl-mc: ERROR fixing mac address for %s\n", |
| 432 | ethname); |
| 433 | ret |= err; |
Bogdan Purcareata | bea8abd | 2017-01-11 15:58:36 +0000 | [diff] [blame] | 434 | } |
| 435 | |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 436 | return ret; |
Bogdan Purcareata | bea8abd | 2017-01-11 15:58:36 +0000 | [diff] [blame] | 437 | } |
| 438 | |
Stuart Yoder | a2bdb77 | 2015-07-02 11:29:03 +0530 | [diff] [blame] | 439 | static int mc_fixup_dpc(u64 dpc_addr) |
| 440 | { |
| 441 | void *blob = (void *)dpc_addr; |
Bogdan Purcareata | bea8abd | 2017-01-11 15:58:36 +0000 | [diff] [blame] | 442 | int nodeoffset, err = 0; |
Stuart Yoder | a2bdb77 | 2015-07-02 11:29:03 +0530 | [diff] [blame] | 443 | |
| 444 | /* delete any existing ICID pools */ |
| 445 | nodeoffset = fdt_path_offset(blob, "/resources/icid_pools"); |
| 446 | if (fdt_del_node(blob, nodeoffset) < 0) |
| 447 | printf("\nfsl-mc: WARNING: could not delete ICID pool\n"); |
| 448 | |
| 449 | /* add a new pool */ |
| 450 | nodeoffset = fdt_path_offset(blob, "/resources"); |
| 451 | if (nodeoffset < 0) { |
| 452 | printf("\nfsl-mc: ERROR: DPC is missing /resources\n"); |
| 453 | return -EINVAL; |
| 454 | } |
| 455 | nodeoffset = fdt_add_subnode(blob, nodeoffset, "icid_pools"); |
| 456 | nodeoffset = fdt_add_subnode(blob, nodeoffset, "icid_pool@0"); |
| 457 | do_fixup_by_path_u32(blob, "/resources/icid_pools/icid_pool@0", |
| 458 | "base_icid", FSL_DPAA2_STREAM_ID_START, 1); |
| 459 | do_fixup_by_path_u32(blob, "/resources/icid_pools/icid_pool@0", |
| 460 | "num", |
| 461 | FSL_DPAA2_STREAM_ID_END - |
| 462 | FSL_DPAA2_STREAM_ID_START + 1, 1); |
| 463 | |
Bogdan Purcareata | bea8abd | 2017-01-11 15:58:36 +0000 | [diff] [blame] | 464 | /* fixup MAC addresses for dpmac ports */ |
| 465 | nodeoffset = fdt_path_offset(blob, "/board_info/ports"); |
| 466 | if (nodeoffset < 0) |
Ioana Ciocoi Radulescu | d7697f4 | 2019-02-26 15:50:07 +0000 | [diff] [blame] | 467 | goto out; |
Bogdan Purcareata | bea8abd | 2017-01-11 15:58:36 +0000 | [diff] [blame] | 468 | |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 469 | err = mc_fixup_mac_addrs(blob, MC_FIXUP_DPC); |
Ioana Ciocoi Radulescu | d7697f4 | 2019-02-26 15:50:07 +0000 | [diff] [blame] | 470 | |
| 471 | out: |
Stuart Yoder | a2bdb77 | 2015-07-02 11:29:03 +0530 | [diff] [blame] | 472 | flush_dcache_range(dpc_addr, dpc_addr + fdt_totalsize(blob)); |
| 473 | |
Bogdan Purcareata | bea8abd | 2017-01-11 15:58:36 +0000 | [diff] [blame] | 474 | return err; |
Stuart Yoder | a2bdb77 | 2015-07-02 11:29:03 +0530 | [diff] [blame] | 475 | } |
| 476 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 477 | static int load_mc_dpc(u64 mc_ram_addr, size_t mc_ram_size, u64 mc_dpc_addr) |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 478 | { |
| 479 | u64 mc_dpc_offset; |
| 480 | #ifndef CONFIG_SYS_LS_MC_DPC_IN_DDR |
| 481 | int error; |
| 482 | void *dpc_fdt_hdr; |
| 483 | int dpc_size; |
| 484 | #endif |
| 485 | |
| 486 | #ifdef CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET |
| 487 | BUILD_BUG_ON((CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET & 0x3) != 0 || |
| 488 | CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET > 0xffffffff); |
| 489 | |
| 490 | mc_dpc_offset = CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET; |
| 491 | #else |
| 492 | #error "CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET not defined" |
| 493 | #endif |
| 494 | |
| 495 | /* |
| 496 | * Load the MC DPC blob in the MC private DRAM block: |
| 497 | */ |
| 498 | #ifdef CONFIG_SYS_LS_MC_DPC_IN_DDR |
| 499 | printf("MC DPC is preloaded to %#llx\n", mc_ram_addr + mc_dpc_offset); |
| 500 | #else |
| 501 | /* |
| 502 | * Get address and size of the DPC blob stored in flash: |
| 503 | */ |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 504 | dpc_fdt_hdr = (void *)mc_dpc_addr; |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 505 | |
| 506 | error = fdt_check_header(dpc_fdt_hdr); |
| 507 | if (error != 0) { |
| 508 | /* |
| 509 | * Don't return with error here, since the MC firmware can |
| 510 | * still boot without a DPC |
| 511 | */ |
J. German Rivera | 75d7ace | 2015-07-02 11:28:56 +0530 | [diff] [blame] | 512 | printf("\nfsl-mc: WARNING: No DPC image found"); |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 513 | return 0; |
| 514 | } |
| 515 | |
| 516 | dpc_size = fdt_totalsize(dpc_fdt_hdr); |
| 517 | if (dpc_size > CONFIG_SYS_LS_MC_DPC_MAX_LENGTH) { |
J. German Rivera | 75d7ace | 2015-07-02 11:28:56 +0530 | [diff] [blame] | 518 | printf("\nfsl-mc: ERROR: Bad DPC image (too large: %d)\n", |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 519 | dpc_size); |
| 520 | return -EINVAL; |
| 521 | } |
| 522 | |
| 523 | mc_copy_image("MC DPC blob", |
| 524 | (u64)dpc_fdt_hdr, dpc_size, mc_ram_addr + mc_dpc_offset); |
| 525 | #endif /* not defined CONFIG_SYS_LS_MC_DPC_IN_DDR */ |
| 526 | |
Stuart Yoder | a2bdb77 | 2015-07-02 11:29:03 +0530 | [diff] [blame] | 527 | if (mc_fixup_dpc(mc_ram_addr + mc_dpc_offset)) |
| 528 | return -EINVAL; |
| 529 | |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 530 | dump_ram_words("DPC", (void *)(mc_ram_addr + mc_dpc_offset)); |
| 531 | return 0; |
| 532 | } |
| 533 | |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 534 | |
| 535 | static int mc_fixup_dpl(u64 dpl_addr) |
| 536 | { |
| 537 | void *blob = (void *)dpl_addr; |
| 538 | u32 ver = fdt_getprop_u32_default(blob, "/", "dpl-version", 0); |
| 539 | int err = 0; |
| 540 | |
| 541 | /* The DPL fixup for mac addresses is only relevant |
| 542 | * for old-style DPLs |
| 543 | */ |
| 544 | if (ver >= 10) |
| 545 | return 0; |
| 546 | |
| 547 | err = mc_fixup_mac_addrs(blob, MC_FIXUP_DPL); |
| 548 | flush_dcache_range(dpl_addr, dpl_addr + fdt_totalsize(blob)); |
| 549 | |
| 550 | return err; |
| 551 | } |
| 552 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 553 | static int load_mc_dpl(u64 mc_ram_addr, size_t mc_ram_size, u64 mc_dpl_addr) |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 554 | { |
| 555 | u64 mc_dpl_offset; |
| 556 | #ifndef CONFIG_SYS_LS_MC_DPL_IN_DDR |
| 557 | int error; |
| 558 | void *dpl_fdt_hdr; |
| 559 | int dpl_size; |
| 560 | #endif |
| 561 | |
| 562 | #ifdef CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET |
| 563 | BUILD_BUG_ON((CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET & 0x3) != 0 || |
| 564 | CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET > 0xffffffff); |
| 565 | |
| 566 | mc_dpl_offset = CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET; |
| 567 | #else |
| 568 | #error "CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET not defined" |
| 569 | #endif |
| 570 | |
| 571 | /* |
| 572 | * Load the MC DPL blob in the MC private DRAM block: |
| 573 | */ |
| 574 | #ifdef CONFIG_SYS_LS_MC_DPL_IN_DDR |
| 575 | printf("MC DPL is preloaded to %#llx\n", mc_ram_addr + mc_dpl_offset); |
| 576 | #else |
| 577 | /* |
| 578 | * Get address and size of the DPL blob stored in flash: |
| 579 | */ |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 580 | dpl_fdt_hdr = (void *)mc_dpl_addr; |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 581 | |
| 582 | error = fdt_check_header(dpl_fdt_hdr); |
| 583 | if (error != 0) { |
J. German Rivera | 75d7ace | 2015-07-02 11:28:56 +0530 | [diff] [blame] | 584 | printf("\nfsl-mc: ERROR: Bad DPL image (bad header)\n"); |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 585 | return error; |
| 586 | } |
| 587 | |
| 588 | dpl_size = fdt_totalsize(dpl_fdt_hdr); |
| 589 | if (dpl_size > CONFIG_SYS_LS_MC_DPL_MAX_LENGTH) { |
J. German Rivera | 75d7ace | 2015-07-02 11:28:56 +0530 | [diff] [blame] | 590 | printf("\nfsl-mc: ERROR: Bad DPL image (too large: %d)\n", |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 591 | dpl_size); |
| 592 | return -EINVAL; |
| 593 | } |
| 594 | |
| 595 | mc_copy_image("MC DPL blob", |
| 596 | (u64)dpl_fdt_hdr, dpl_size, mc_ram_addr + mc_dpl_offset); |
| 597 | #endif /* not defined CONFIG_SYS_LS_MC_DPL_IN_DDR */ |
| 598 | |
Bogdan Purcareata | 7266914 | 2017-05-24 16:40:22 +0000 | [diff] [blame] | 599 | if (mc_fixup_dpl(mc_ram_addr + mc_dpl_offset)) |
| 600 | return -EINVAL; |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 601 | dump_ram_words("DPL", (void *)(mc_ram_addr + mc_dpl_offset)); |
| 602 | return 0; |
| 603 | } |
| 604 | |
| 605 | /** |
| 606 | * Return the MC boot timeout value in milliseconds |
| 607 | */ |
| 608 | static unsigned long get_mc_boot_timeout_ms(void) |
| 609 | { |
| 610 | unsigned long timeout_ms = CONFIG_SYS_LS_MC_BOOT_TIMEOUT_MS; |
| 611 | |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 612 | char *timeout_ms_env_var = env_get(MC_BOOT_TIMEOUT_ENV_VAR); |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 613 | |
| 614 | if (timeout_ms_env_var) { |
| 615 | timeout_ms = simple_strtoul(timeout_ms_env_var, NULL, 10); |
| 616 | if (timeout_ms == 0) { |
| 617 | printf("fsl-mc: WARNING: Invalid value for \'" |
| 618 | MC_BOOT_TIMEOUT_ENV_VAR |
| 619 | "\' environment variable: %lu\n", |
| 620 | timeout_ms); |
| 621 | |
| 622 | timeout_ms = CONFIG_SYS_LS_MC_BOOT_TIMEOUT_MS; |
| 623 | } |
| 624 | } |
| 625 | |
| 626 | return timeout_ms; |
| 627 | } |
| 628 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 629 | #ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET |
York Sun | cbe8e1c | 2016-04-04 11:41:26 -0700 | [diff] [blame] | 630 | |
| 631 | __weak bool soc_has_aiop(void) |
| 632 | { |
| 633 | return false; |
| 634 | } |
| 635 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 636 | static int load_mc_aiop_img(u64 aiop_fw_addr) |
J. German Rivera | c3b505f | 2015-07-02 11:28:58 +0530 | [diff] [blame] | 637 | { |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 638 | u64 mc_ram_addr = mc_get_dram_addr(); |
| 639 | #ifndef CONFIG_SYS_LS_MC_DPC_IN_DDR |
J. German Rivera | c3b505f | 2015-07-02 11:28:58 +0530 | [diff] [blame] | 640 | void *aiop_img; |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 641 | #endif |
J. German Rivera | c3b505f | 2015-07-02 11:28:58 +0530 | [diff] [blame] | 642 | |
York Sun | cbe8e1c | 2016-04-04 11:41:26 -0700 | [diff] [blame] | 643 | /* Check if AIOP is available */ |
| 644 | if (!soc_has_aiop()) |
| 645 | return -ENODEV; |
J. German Rivera | c3b505f | 2015-07-02 11:28:58 +0530 | [diff] [blame] | 646 | /* |
| 647 | * Load the MC AIOP image in the MC private DRAM block: |
| 648 | */ |
| 649 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 650 | #ifdef CONFIG_SYS_LS_MC_DPC_IN_DDR |
| 651 | printf("MC AIOP is preloaded to %#llx\n", mc_ram_addr + |
| 652 | CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET); |
| 653 | #else |
| 654 | aiop_img = (void *)aiop_fw_addr; |
J. German Rivera | c3b505f | 2015-07-02 11:28:58 +0530 | [diff] [blame] | 655 | mc_copy_image("MC AIOP image", |
| 656 | (u64)aiop_img, CONFIG_SYS_LS_MC_AIOP_IMG_MAX_LENGTH, |
| 657 | mc_ram_addr + CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET); |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 658 | #endif |
| 659 | mc_aiop_applied = 0; |
J. German Rivera | c3b505f | 2015-07-02 11:28:58 +0530 | [diff] [blame] | 660 | |
| 661 | return 0; |
| 662 | } |
| 663 | #endif |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 664 | |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 665 | static int wait_for_mc(bool booting_mc, u32 *final_reg_gsr) |
| 666 | { |
| 667 | u32 reg_gsr; |
| 668 | u32 mc_fw_boot_status; |
| 669 | unsigned long timeout_ms = get_mc_boot_timeout_ms(); |
| 670 | struct mc_ccsr_registers __iomem *mc_ccsr_regs = MC_CCSR_BASE_ADDR; |
| 671 | |
| 672 | dmb(); |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 673 | assert(timeout_ms > 0); |
| 674 | for (;;) { |
| 675 | udelay(1000); /* throttle polling */ |
| 676 | reg_gsr = in_le32(&mc_ccsr_regs->reg_gsr); |
| 677 | mc_fw_boot_status = (reg_gsr & GSR_FS_MASK); |
| 678 | if (mc_fw_boot_status & 0x1) |
| 679 | break; |
| 680 | |
| 681 | timeout_ms--; |
| 682 | if (timeout_ms == 0) |
| 683 | break; |
| 684 | } |
| 685 | |
| 686 | if (timeout_ms == 0) { |
J. German Rivera | 75d7ace | 2015-07-02 11:28:56 +0530 | [diff] [blame] | 687 | printf("ERROR: timeout\n"); |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 688 | |
| 689 | /* TODO: Get an error status from an MC CCSR register */ |
| 690 | return -ETIMEDOUT; |
| 691 | } |
| 692 | |
| 693 | if (mc_fw_boot_status != 0x1) { |
| 694 | /* |
| 695 | * TODO: Identify critical errors from the GSR register's FS |
| 696 | * field and for those errors, set error to -ENODEV or other |
| 697 | * appropriate errno, so that the status property is set to |
| 698 | * failure in the fsl,dprc device tree node. |
| 699 | */ |
J. German Rivera | 75d7ace | 2015-07-02 11:28:56 +0530 | [diff] [blame] | 700 | printf("WARNING: Firmware returned an error (GSR: %#x)\n", |
| 701 | reg_gsr); |
| 702 | } else { |
| 703 | printf("SUCCESS\n"); |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 704 | } |
| 705 | |
J. German Rivera | 75d7ace | 2015-07-02 11:28:56 +0530 | [diff] [blame] | 706 | |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 707 | *final_reg_gsr = reg_gsr; |
| 708 | return 0; |
| 709 | } |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 710 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 711 | int mc_init(u64 mc_fw_addr, u64 mc_dpc_addr) |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 712 | { |
| 713 | int error = 0; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 714 | int portal_id = 0; |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 715 | struct mc_ccsr_registers __iomem *mc_ccsr_regs = MC_CCSR_BASE_ADDR; |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 716 | u64 mc_ram_addr = mc_get_dram_addr(); |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 717 | u32 reg_gsr; |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 718 | u32 reg_mcfbalr; |
| 719 | #ifndef CONFIG_SYS_LS_MC_FW_IN_DDR |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 720 | const void *raw_image_addr; |
| 721 | size_t raw_image_size = 0; |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 722 | #endif |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 723 | u8 mc_ram_num_256mb_blocks; |
| 724 | size_t mc_ram_size = mc_get_dram_block_size(); |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 725 | |
York Sun | c55d731 | 2017-03-06 09:02:29 -0800 | [diff] [blame] | 726 | mc_ram_num_256mb_blocks = mc_ram_size / MC_RAM_SIZE_ALIGNMENT; |
Meenakshi Aggarwal | 67f195c | 2019-02-27 14:41:02 +0530 | [diff] [blame] | 727 | |
| 728 | if (mc_ram_num_256mb_blocks >= 0xff) { |
York Sun | c55d731 | 2017-03-06 09:02:29 -0800 | [diff] [blame] | 729 | error = -EINVAL; |
| 730 | printf("fsl-mc: ERROR: invalid MC private RAM size (%lu)\n", |
| 731 | mc_ram_size); |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 732 | goto out; |
York Sun | c55d731 | 2017-03-06 09:02:29 -0800 | [diff] [blame] | 733 | } |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 734 | |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 735 | /* |
Meenakshi Aggarwal | 67f195c | 2019-02-27 14:41:02 +0530 | [diff] [blame] | 736 | * To support 128 MB DDR Size for MC |
| 737 | */ |
| 738 | if (mc_ram_num_256mb_blocks == 0) |
| 739 | mc_ram_num_256mb_blocks = 0xFF; |
| 740 | |
| 741 | /* |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 742 | * Management Complex cores should be held at reset out of POR. |
Bin Meng | 7557405 | 2016-02-05 19:30:11 -0800 | [diff] [blame] | 743 | * U-Boot should be the first software to touch MC. To be safe, |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 744 | * we reset all cores again by setting GCR1 to 0. It doesn't do |
| 745 | * anything if they are held at reset. After we setup the firmware |
| 746 | * we kick off MC by deasserting the reset bit for core 0, and |
| 747 | * deasserting the reset bits for Command Portal Managers. |
| 748 | * The stop bits are not touched here. They are used to stop the |
| 749 | * cores when they are active. Setting stop bits doesn't stop the |
| 750 | * cores from fetching instructions when they are released from |
| 751 | * reset. |
| 752 | */ |
| 753 | out_le32(&mc_ccsr_regs->reg_gcr1, 0); |
| 754 | dmb(); |
| 755 | |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 756 | #ifdef CONFIG_SYS_LS_MC_FW_IN_DDR |
| 757 | printf("MC firmware is preloaded to %#llx\n", mc_ram_addr); |
| 758 | #else |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 759 | error = parse_mc_firmware_fit_image(mc_fw_addr, &raw_image_addr, |
| 760 | &raw_image_size); |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 761 | if (error != 0) |
| 762 | goto out; |
| 763 | /* |
| 764 | * Load the MC FW at the beginning of the MC private DRAM block: |
| 765 | */ |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 766 | mc_copy_image("MC Firmware", |
| 767 | (u64)raw_image_addr, raw_image_size, mc_ram_addr); |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 768 | #endif |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 769 | dump_ram_words("firmware", (void *)mc_ram_addr); |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 770 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 771 | error = load_mc_dpc(mc_ram_addr, mc_ram_size, mc_dpc_addr); |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 772 | if (error != 0) |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 773 | goto out; |
J. German Rivera | c3b505f | 2015-07-02 11:28:58 +0530 | [diff] [blame] | 774 | |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 775 | debug("mc_ccsr_regs %p\n", mc_ccsr_regs); |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 776 | dump_mc_ccsr_regs(mc_ccsr_regs); |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 777 | |
| 778 | /* |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 779 | * Tell MC what is the address range of the DRAM block assigned to it: |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 780 | */ |
Meenakshi Aggarwal | 67f195c | 2019-02-27 14:41:02 +0530 | [diff] [blame] | 781 | if (mc_ram_num_256mb_blocks < 0xFF) { |
| 782 | reg_mcfbalr = (u32)mc_ram_addr | |
| 783 | (mc_ram_num_256mb_blocks - 1); |
| 784 | } else { |
| 785 | reg_mcfbalr = (u32)mc_ram_addr | |
| 786 | (mc_ram_num_256mb_blocks); |
| 787 | } |
| 788 | |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 789 | out_le32(&mc_ccsr_regs->reg_mcfbalr, reg_mcfbalr); |
| 790 | out_le32(&mc_ccsr_regs->reg_mcfbahr, |
York Sun | c55d731 | 2017-03-06 09:02:29 -0800 | [diff] [blame] | 791 | (u32)(mc_ram_addr >> 32)); |
Stuart Yoder | d197035 | 2015-07-02 11:29:02 +0530 | [diff] [blame] | 792 | out_le32(&mc_ccsr_regs->reg_mcfapr, FSL_BYPASS_AMQ); |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 793 | |
| 794 | /* |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 795 | * Tell the MC that we want delayed DPL deployment. |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 796 | */ |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 797 | out_le32(&mc_ccsr_regs->reg_gsr, 0xDD00); |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 798 | |
J. German Rivera | 75d7ace | 2015-07-02 11:28:56 +0530 | [diff] [blame] | 799 | printf("\nfsl-mc: Booting Management Complex ... "); |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 800 | |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 801 | /* |
| 802 | * Deassert reset and release MC core 0 to run |
| 803 | */ |
| 804 | out_le32(&mc_ccsr_regs->reg_gcr1, GCR1_P1_DE_RST | GCR1_M_ALL_DE_RST); |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 805 | error = wait_for_mc(true, ®_gsr); |
| 806 | if (error != 0) |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 807 | goto out; |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 808 | |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 809 | /* |
| 810 | * TODO: need to obtain the portal_id for the root container from the |
| 811 | * DPL |
| 812 | */ |
| 813 | portal_id = 0; |
| 814 | |
| 815 | /* |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 816 | * Initialize the global default MC portal |
| 817 | * And check that the MC firmware is responding portal commands: |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 818 | */ |
Prabhakar Kushwaha | 790c1a4 | 2017-10-11 08:51:18 +0530 | [diff] [blame] | 819 | root_mc_io = (struct fsl_mc_io *)calloc(sizeof(struct fsl_mc_io), 1); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 820 | if (!root_mc_io) { |
Prabhakar Kushwaha | 790c1a4 | 2017-10-11 08:51:18 +0530 | [diff] [blame] | 821 | printf(" No memory: calloc() failed\n"); |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 822 | return -ENOMEM; |
| 823 | } |
| 824 | |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 825 | root_mc_io->mmio_regs = SOC_MC_PORTAL_ADDR(portal_id); |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 826 | debug("Checking access to MC portal of root DPRC container (portal_id %d, portal physical addr %p)\n", |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 827 | portal_id, root_mc_io->mmio_regs); |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 828 | |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 829 | error = mc_get_version(root_mc_io, MC_CMD_NO_FLAGS, &mc_ver_info); |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 830 | if (error != 0) { |
| 831 | printf("fsl-mc: ERROR: Firmware version check failed (error: %d)\n", |
| 832 | error); |
| 833 | goto out; |
| 834 | } |
| 835 | |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 836 | printf("fsl-mc: Management Complex booted (version: %d.%d.%d, boot status: %#x)\n", |
| 837 | mc_ver_info.major, mc_ver_info.minor, mc_ver_info.revision, |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 838 | reg_gsr & GSR_FS_MASK); |
| 839 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 840 | out: |
| 841 | if (error != 0) |
| 842 | mc_boot_status = error; |
| 843 | else |
| 844 | mc_boot_status = 0; |
| 845 | |
| 846 | return error; |
| 847 | } |
| 848 | |
| 849 | int mc_apply_dpl(u64 mc_dpl_addr) |
| 850 | { |
| 851 | struct mc_ccsr_registers __iomem *mc_ccsr_regs = MC_CCSR_BASE_ADDR; |
| 852 | int error = 0; |
| 853 | u32 reg_gsr; |
| 854 | u64 mc_ram_addr = mc_get_dram_addr(); |
| 855 | size_t mc_ram_size = mc_get_dram_block_size(); |
| 856 | |
Alexander Graf | 2ebeb44 | 2016-11-17 01:02:57 +0100 | [diff] [blame] | 857 | if (!mc_dpl_addr) |
| 858 | return -1; |
| 859 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 860 | error = load_mc_dpl(mc_ram_addr, mc_ram_size, mc_dpl_addr); |
| 861 | if (error != 0) |
| 862 | return error; |
| 863 | |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 864 | /* |
| 865 | * Tell the MC to deploy the DPL: |
| 866 | */ |
| 867 | out_le32(&mc_ccsr_regs->reg_gsr, 0x0); |
J. German Rivera | 75d7ace | 2015-07-02 11:28:56 +0530 | [diff] [blame] | 868 | printf("fsl-mc: Deploying data path layout ... "); |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 869 | error = wait_for_mc(false, ®_gsr); |
J. German Rivera | 75d7ace | 2015-07-02 11:28:56 +0530 | [diff] [blame] | 870 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 871 | if (!error) |
| 872 | mc_dpl_applied = 0; |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 873 | |
| 874 | return error; |
| 875 | } |
| 876 | |
| 877 | int get_mc_boot_status(void) |
| 878 | { |
| 879 | return mc_boot_status; |
| 880 | } |
| 881 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 882 | #ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET |
| 883 | int get_aiop_apply_status(void) |
| 884 | { |
| 885 | return mc_aiop_applied; |
| 886 | } |
| 887 | #endif |
| 888 | |
| 889 | int get_dpl_apply_status(void) |
| 890 | { |
| 891 | return mc_dpl_applied; |
| 892 | } |
| 893 | |
Mian Yousaf Kaukab | 9712465 | 2018-12-18 14:01:17 +0100 | [diff] [blame] | 894 | int is_lazy_dpl_addr_valid(void) |
| 895 | { |
| 896 | return !!mc_lazy_dpl_addr; |
| 897 | } |
| 898 | |
Priyanka Jain | e0e0be5 | 2017-08-24 16:42:43 +0530 | [diff] [blame] | 899 | /* |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 900 | * Return the MC address of private DRAM block. |
Priyanka Jain | e0e0be5 | 2017-08-24 16:42:43 +0530 | [diff] [blame] | 901 | * As per MC design document, MC initial base address |
| 902 | * should be least significant 512MB address of MC private |
| 903 | * memory, i.e. address should point to end address masked |
| 904 | * with 512MB offset in private DRAM block. |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 905 | */ |
| 906 | u64 mc_get_dram_addr(void) |
| 907 | { |
Priyanka Jain | e0e0be5 | 2017-08-24 16:42:43 +0530 | [diff] [blame] | 908 | size_t mc_ram_size = mc_get_dram_block_size(); |
| 909 | |
Prabhakar Kushwaha | 145e4cd | 2018-08-27 12:58:52 +0530 | [diff] [blame] | 910 | if (!mc_memset_resv_ram || (get_mc_boot_status() < 0)) { |
| 911 | mc_memset_resv_ram = 1; |
| 912 | memset((void *)gd->arch.resv_ram, 0, mc_ram_size); |
| 913 | } |
| 914 | |
Priyanka Jain | e0e0be5 | 2017-08-24 16:42:43 +0530 | [diff] [blame] | 915 | return (gd->arch.resv_ram + mc_ram_size - 1) & |
| 916 | MC_RAM_BASE_ADDR_ALIGNMENT_MASK; |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 917 | } |
| 918 | |
| 919 | /** |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 920 | * Return the actual size of the MC private DRAM block. |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 921 | */ |
| 922 | unsigned long mc_get_dram_block_size(void) |
| 923 | { |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 924 | unsigned long dram_block_size = CONFIG_SYS_LS_MC_DRAM_BLOCK_MIN_SIZE; |
| 925 | |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 926 | char *dram_block_size_env_var = env_get(MC_MEM_SIZE_ENV_VAR); |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 927 | |
| 928 | if (dram_block_size_env_var) { |
| 929 | dram_block_size = simple_strtoul(dram_block_size_env_var, NULL, |
Prabhakar Kushwaha | b166d6a | 2017-11-09 14:45:41 +0530 | [diff] [blame] | 930 | 16); |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 931 | |
| 932 | if (dram_block_size < CONFIG_SYS_LS_MC_DRAM_BLOCK_MIN_SIZE) { |
| 933 | printf("fsl-mc: WARNING: Invalid value for \'" |
| 934 | MC_MEM_SIZE_ENV_VAR |
| 935 | "\' environment variable: %lu\n", |
| 936 | dram_block_size); |
| 937 | |
Meenakshi Aggarwal | 67f195c | 2019-02-27 14:41:02 +0530 | [diff] [blame] | 938 | dram_block_size = MC_DRAM_BLOCK_DEFAULT_SIZE; |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 939 | } |
| 940 | } |
| 941 | |
| 942 | return dram_block_size; |
J. German Rivera | 8ff14b7 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 943 | } |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 944 | |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 945 | int fsl_mc_ldpaa_init(bd_t *bis) |
| 946 | { |
Prabhakar Kushwaha | 52d2e2c | 2015-11-04 12:26:00 +0530 | [diff] [blame] | 947 | int i; |
| 948 | |
| 949 | for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++) |
Pankaj Bansal | 7987ab7 | 2018-10-10 14:08:33 +0530 | [diff] [blame] | 950 | if (wriop_is_enabled_dpmac(i) == 1) |
Prabhakar Kushwaha | 52d2e2c | 2015-11-04 12:26:00 +0530 | [diff] [blame] | 951 | ldpaa_eth_init(i, wriop_get_enet_if(i)); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 952 | return 0; |
| 953 | } |
| 954 | |
Prabhakar Kushwaha | 0a4156c | 2015-12-24 15:32:37 +0530 | [diff] [blame] | 955 | static int dprc_version_check(struct fsl_mc_io *mc_io, uint16_t handle) |
| 956 | { |
Prabhakar Kushwaha | 0a4156c | 2015-12-24 15:32:37 +0530 | [diff] [blame] | 957 | int error; |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 958 | uint16_t major_ver, minor_ver; |
Prabhakar Kushwaha | 0a4156c | 2015-12-24 15:32:37 +0530 | [diff] [blame] | 959 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 960 | error = dprc_get_api_version(mc_io, 0, |
| 961 | &major_ver, |
| 962 | &minor_ver); |
| 963 | if (error < 0) { |
| 964 | printf("dprc_get_api_version() failed: %d\n", error); |
| 965 | return error; |
Prabhakar Kushwaha | 0a4156c | 2015-12-24 15:32:37 +0530 | [diff] [blame] | 966 | } |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 967 | |
| 968 | if (major_ver < DPRC_VER_MAJOR || (major_ver == DPRC_VER_MAJOR && |
| 969 | minor_ver < DPRC_VER_MINOR)) { |
| 970 | printf("DPRC version mismatch found %u.%u,", |
| 971 | major_ver, minor_ver); |
| 972 | printf("supported version is %u.%u\n", |
| 973 | DPRC_VER_MAJOR, DPRC_VER_MINOR); |
| 974 | } |
| 975 | |
Prabhakar Kushwaha | 0a4156c | 2015-12-24 15:32:37 +0530 | [diff] [blame] | 976 | return error; |
| 977 | } |
| 978 | |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 979 | static int dpio_init(void) |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 980 | { |
| 981 | struct qbman_swp_desc p_des; |
| 982 | struct dpio_attr attr; |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 983 | struct dpio_cfg dpio_cfg; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 984 | int err = 0; |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 985 | uint16_t major_ver, minor_ver; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 986 | |
Prabhakar Kushwaha | 790c1a4 | 2017-10-11 08:51:18 +0530 | [diff] [blame] | 987 | dflt_dpio = (struct fsl_dpio_obj *)calloc( |
| 988 | sizeof(struct fsl_dpio_obj), 1); |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 989 | if (!dflt_dpio) { |
Prabhakar Kushwaha | 790c1a4 | 2017-10-11 08:51:18 +0530 | [diff] [blame] | 990 | printf("No memory: calloc() failed\n"); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 991 | err = -ENOMEM; |
Prabhakar Kushwaha | 790c1a4 | 2017-10-11 08:51:18 +0530 | [diff] [blame] | 992 | goto err_calloc; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 993 | } |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 994 | dpio_cfg.channel_mode = DPIO_LOCAL_CHANNEL; |
| 995 | dpio_cfg.num_priorities = 8; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 996 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 997 | err = dpio_create(dflt_mc_io, |
| 998 | dflt_dprc_handle, |
| 999 | MC_CMD_NO_FLAGS, |
| 1000 | &dpio_cfg, |
| 1001 | &dflt_dpio->dpio_id); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1002 | if (err < 0) { |
| 1003 | printf("dpio_create() failed: %d\n", err); |
| 1004 | err = -ENODEV; |
| 1005 | goto err_create; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1006 | } |
| 1007 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1008 | err = dpio_get_api_version(dflt_mc_io, 0, |
| 1009 | &major_ver, |
| 1010 | &minor_ver); |
| 1011 | if (err < 0) { |
| 1012 | printf("dpio_get_api_version() failed: %d\n", err); |
| 1013 | goto err_get_api_ver; |
| 1014 | } |
| 1015 | |
| 1016 | if (major_ver < DPIO_VER_MAJOR || (major_ver == DPIO_VER_MAJOR && |
| 1017 | minor_ver < DPIO_VER_MINOR)) { |
| 1018 | printf("DPRC version mismatch found %u.%u,", |
| 1019 | major_ver, |
| 1020 | minor_ver); |
| 1021 | } |
| 1022 | |
| 1023 | err = dpio_open(dflt_mc_io, |
| 1024 | MC_CMD_NO_FLAGS, |
| 1025 | dflt_dpio->dpio_id, |
| 1026 | &dflt_dpio->dpio_handle); |
| 1027 | if (err) { |
| 1028 | printf("dpio_open() failed\n"); |
| 1029 | goto err_open; |
| 1030 | } |
| 1031 | |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1032 | memset(&attr, 0, sizeof(struct dpio_attr)); |
Prabhakar Kushwaha | 9564df6 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 1033 | err = dpio_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS, |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1034 | dflt_dpio->dpio_handle, &attr); |
| 1035 | if (err < 0) { |
| 1036 | printf("dpio_get_attributes() failed: %d\n", err); |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1037 | goto err_get_attr; |
| 1038 | } |
| 1039 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1040 | if (dflt_dpio->dpio_id != attr.id) { |
| 1041 | printf("dnpi object id and attribute id are not same\n"); |
| 1042 | goto err_attr_not_same; |
Prabhakar Kushwaha | 0a4156c | 2015-12-24 15:32:37 +0530 | [diff] [blame] | 1043 | } |
| 1044 | |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1045 | #ifdef DEBUG |
| 1046 | printf("Init: DPIO id=0x%d\n", dflt_dpio->dpio_id); |
| 1047 | #endif |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1048 | err = dpio_enable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle); |
| 1049 | if (err < 0) { |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1050 | printf("dpio_enable() failed %d\n", err); |
| 1051 | goto err_get_enable; |
| 1052 | } |
Prabhakar Kushwaha | fd5d127 | 2015-07-02 11:28:59 +0530 | [diff] [blame] | 1053 | debug("ce_offset=0x%llx, ci_offset=0x%llx, portalid=%d, prios=%d\n", |
| 1054 | attr.qbman_portal_ce_offset, |
| 1055 | attr.qbman_portal_ci_offset, |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1056 | attr.qbman_portal_id, |
| 1057 | attr.num_priorities); |
| 1058 | |
Prabhakar Kushwaha | fd5d127 | 2015-07-02 11:28:59 +0530 | [diff] [blame] | 1059 | p_des.cena_bar = (void *)(SOC_QBMAN_PORTALS_BASE_ADDR |
| 1060 | + attr.qbman_portal_ce_offset); |
| 1061 | p_des.cinh_bar = (void *)(SOC_QBMAN_PORTALS_BASE_ADDR |
| 1062 | + attr.qbman_portal_ci_offset); |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1063 | |
| 1064 | dflt_dpio->sw_portal = qbman_swp_init(&p_des); |
| 1065 | if (dflt_dpio->sw_portal == NULL) { |
| 1066 | printf("qbman_swp_init() failed\n"); |
| 1067 | goto err_get_swp_init; |
| 1068 | } |
| 1069 | return 0; |
| 1070 | |
| 1071 | err_get_swp_init: |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1072 | dpio_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle); |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1073 | err_get_enable: |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1074 | err_get_attr: |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1075 | err_attr_not_same: |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1076 | dpio_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle); |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1077 | err_open: |
| 1078 | err_get_api_ver: |
| 1079 | dpio_destroy(dflt_mc_io, |
| 1080 | dflt_dprc_handle, |
| 1081 | MC_CMD_NO_FLAGS, |
| 1082 | dflt_dpio->dpio_id); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1083 | err_create: |
Prabhakar Kushwaha | c6018bd | 2016-03-18 16:15:29 +0530 | [diff] [blame] | 1084 | free(dflt_dpio); |
Prabhakar Kushwaha | 790c1a4 | 2017-10-11 08:51:18 +0530 | [diff] [blame] | 1085 | err_calloc: |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1086 | return err; |
| 1087 | } |
| 1088 | |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1089 | static int dpio_exit(void) |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1090 | { |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1091 | int err; |
| 1092 | |
| 1093 | err = dpio_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle); |
| 1094 | if (err < 0) { |
| 1095 | printf("dpio_disable() failed: %d\n", err); |
| 1096 | goto err; |
| 1097 | } |
| 1098 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1099 | dpio_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle); |
| 1100 | if (err < 0) { |
| 1101 | printf("dpio_close() failed: %d\n", err); |
| 1102 | goto err; |
| 1103 | } |
| 1104 | |
| 1105 | err = dpio_destroy(dflt_mc_io, |
| 1106 | dflt_dprc_handle, |
| 1107 | MC_CMD_NO_FLAGS, |
| 1108 | dflt_dpio->dpio_id); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1109 | if (err < 0) { |
| 1110 | printf("dpio_destroy() failed: %d\n", err); |
| 1111 | goto err; |
| 1112 | } |
| 1113 | |
| 1114 | #ifdef DEBUG |
| 1115 | printf("Exit: DPIO id=0x%d\n", dflt_dpio->dpio_id); |
| 1116 | #endif |
| 1117 | |
| 1118 | if (dflt_dpio) |
| 1119 | free(dflt_dpio); |
| 1120 | |
| 1121 | return 0; |
| 1122 | err: |
| 1123 | return err; |
| 1124 | } |
| 1125 | |
| 1126 | static int dprc_init(void) |
| 1127 | { |
| 1128 | int err, child_portal_id, container_id; |
| 1129 | struct dprc_cfg cfg; |
| 1130 | uint64_t mc_portal_offset; |
| 1131 | |
| 1132 | /* Open root container */ |
| 1133 | err = dprc_get_container_id(root_mc_io, MC_CMD_NO_FLAGS, &container_id); |
| 1134 | if (err < 0) { |
| 1135 | printf("dprc_get_container_id(): Root failed: %d\n", err); |
| 1136 | goto err_root_container_id; |
| 1137 | } |
| 1138 | |
| 1139 | #ifdef DEBUG |
| 1140 | printf("Root container id = %d\n", container_id); |
| 1141 | #endif |
| 1142 | err = dprc_open(root_mc_io, MC_CMD_NO_FLAGS, container_id, |
| 1143 | &root_dprc_handle); |
| 1144 | if (err < 0) { |
| 1145 | printf("dprc_open(): Root Container failed: %d\n", err); |
| 1146 | goto err_root_open; |
| 1147 | } |
| 1148 | |
| 1149 | if (!root_dprc_handle) { |
| 1150 | printf("dprc_open(): Root Container Handle is not valid\n"); |
| 1151 | goto err_root_open; |
| 1152 | } |
| 1153 | |
Prabhakar Kushwaha | 0a4156c | 2015-12-24 15:32:37 +0530 | [diff] [blame] | 1154 | err = dprc_version_check(root_mc_io, root_dprc_handle); |
| 1155 | if (err < 0) { |
| 1156 | printf("dprc_version_check() failed: %d\n", err); |
| 1157 | goto err_root_open; |
| 1158 | } |
| 1159 | |
Prabhakar Kushwaha | 901a88e | 2016-01-20 12:04:19 +0530 | [diff] [blame] | 1160 | memset(&cfg, 0, sizeof(struct dprc_cfg)); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1161 | cfg.options = DPRC_CFG_OPT_TOPOLOGY_CHANGES_ALLOWED | |
| 1162 | DPRC_CFG_OPT_OBJ_CREATE_ALLOWED | |
| 1163 | DPRC_CFG_OPT_ALLOC_ALLOWED; |
| 1164 | cfg.icid = DPRC_GET_ICID_FROM_POOL; |
Prabhakar Kushwaha | 7fd59d9 | 2015-12-24 15:33:49 +0530 | [diff] [blame] | 1165 | cfg.portal_id = DPRC_GET_PORTAL_ID_FROM_POOL; |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1166 | err = dprc_create_container(root_mc_io, MC_CMD_NO_FLAGS, |
| 1167 | root_dprc_handle, |
| 1168 | &cfg, |
| 1169 | &child_dprc_id, |
| 1170 | &mc_portal_offset); |
| 1171 | if (err < 0) { |
| 1172 | printf("dprc_create_container() failed: %d\n", err); |
| 1173 | goto err_create; |
| 1174 | } |
| 1175 | |
Prabhakar Kushwaha | 790c1a4 | 2017-10-11 08:51:18 +0530 | [diff] [blame] | 1176 | dflt_mc_io = (struct fsl_mc_io *)calloc(sizeof(struct fsl_mc_io), 1); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1177 | if (!dflt_mc_io) { |
| 1178 | err = -ENOMEM; |
Prabhakar Kushwaha | 790c1a4 | 2017-10-11 08:51:18 +0530 | [diff] [blame] | 1179 | printf(" No memory: calloc() failed\n"); |
| 1180 | goto err_calloc; |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1181 | } |
| 1182 | |
| 1183 | child_portal_id = MC_PORTAL_OFFSET_TO_PORTAL_ID(mc_portal_offset); |
| 1184 | dflt_mc_io->mmio_regs = SOC_MC_PORTAL_ADDR(child_portal_id); |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1185 | |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1186 | #ifdef DEBUG |
| 1187 | printf("MC portal of child DPRC container: %d, physical addr %p)\n", |
| 1188 | child_dprc_id, dflt_mc_io->mmio_regs); |
| 1189 | #endif |
| 1190 | |
| 1191 | err = dprc_open(dflt_mc_io, MC_CMD_NO_FLAGS, child_dprc_id, |
| 1192 | &dflt_dprc_handle); |
| 1193 | if (err < 0) { |
| 1194 | printf("dprc_open(): Child container failed: %d\n", err); |
| 1195 | goto err_child_open; |
| 1196 | } |
| 1197 | |
| 1198 | if (!dflt_dprc_handle) { |
| 1199 | printf("dprc_open(): Child container Handle is not valid\n"); |
| 1200 | goto err_child_open; |
| 1201 | } |
| 1202 | |
| 1203 | return 0; |
| 1204 | err_child_open: |
| 1205 | free(dflt_mc_io); |
Prabhakar Kushwaha | 790c1a4 | 2017-10-11 08:51:18 +0530 | [diff] [blame] | 1206 | err_calloc: |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1207 | dprc_destroy_container(root_mc_io, MC_CMD_NO_FLAGS, |
| 1208 | root_dprc_handle, child_dprc_id); |
| 1209 | err_create: |
| 1210 | dprc_close(root_mc_io, MC_CMD_NO_FLAGS, root_dprc_handle); |
| 1211 | err_root_open: |
| 1212 | err_root_container_id: |
| 1213 | return err; |
| 1214 | } |
| 1215 | |
| 1216 | static int dprc_exit(void) |
| 1217 | { |
| 1218 | int err; |
| 1219 | |
| 1220 | err = dprc_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dprc_handle); |
| 1221 | if (err < 0) { |
| 1222 | printf("dprc_close(): Child failed: %d\n", err); |
| 1223 | goto err; |
| 1224 | } |
| 1225 | |
| 1226 | err = dprc_destroy_container(root_mc_io, MC_CMD_NO_FLAGS, |
| 1227 | root_dprc_handle, child_dprc_id); |
| 1228 | if (err < 0) { |
| 1229 | printf("dprc_destroy_container() failed: %d\n", err); |
| 1230 | goto err; |
| 1231 | } |
| 1232 | |
| 1233 | err = dprc_close(root_mc_io, MC_CMD_NO_FLAGS, root_dprc_handle); |
| 1234 | if (err < 0) { |
| 1235 | printf("dprc_close(): Root failed: %d\n", err); |
| 1236 | goto err; |
| 1237 | } |
| 1238 | |
| 1239 | if (dflt_mc_io) |
| 1240 | free(dflt_mc_io); |
| 1241 | |
| 1242 | if (root_mc_io) |
| 1243 | free(root_mc_io); |
| 1244 | |
| 1245 | return 0; |
| 1246 | |
| 1247 | err: |
| 1248 | return err; |
| 1249 | } |
| 1250 | |
| 1251 | static int dpbp_init(void) |
| 1252 | { |
| 1253 | int err; |
| 1254 | struct dpbp_attr dpbp_attr; |
| 1255 | struct dpbp_cfg dpbp_cfg; |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1256 | uint16_t major_ver, minor_ver; |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1257 | |
Prabhakar Kushwaha | 790c1a4 | 2017-10-11 08:51:18 +0530 | [diff] [blame] | 1258 | dflt_dpbp = (struct fsl_dpbp_obj *)calloc( |
| 1259 | sizeof(struct fsl_dpbp_obj), 1); |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1260 | if (!dflt_dpbp) { |
Prabhakar Kushwaha | 790c1a4 | 2017-10-11 08:51:18 +0530 | [diff] [blame] | 1261 | printf("No memory: calloc() failed\n"); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1262 | err = -ENOMEM; |
Prabhakar Kushwaha | 790c1a4 | 2017-10-11 08:51:18 +0530 | [diff] [blame] | 1263 | goto err_calloc; |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1264 | } |
| 1265 | |
| 1266 | dpbp_cfg.options = 512; |
| 1267 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1268 | err = dpbp_create(dflt_mc_io, |
| 1269 | dflt_dprc_handle, |
| 1270 | MC_CMD_NO_FLAGS, |
| 1271 | &dpbp_cfg, |
| 1272 | &dflt_dpbp->dpbp_id); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1273 | |
| 1274 | if (err < 0) { |
| 1275 | err = -ENODEV; |
| 1276 | printf("dpbp_create() failed: %d\n", err); |
| 1277 | goto err_create; |
| 1278 | } |
| 1279 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1280 | err = dpbp_get_api_version(dflt_mc_io, 0, |
| 1281 | &major_ver, |
| 1282 | &minor_ver); |
| 1283 | if (err < 0) { |
| 1284 | printf("dpbp_get_api_version() failed: %d\n", err); |
| 1285 | goto err_get_api_ver; |
| 1286 | } |
| 1287 | |
| 1288 | if (major_ver < DPBP_VER_MAJOR || (major_ver == DPBP_VER_MAJOR && |
| 1289 | minor_ver < DPBP_VER_MINOR)) { |
| 1290 | printf("DPBP version mismatch found %u.%u,", |
| 1291 | major_ver, minor_ver); |
| 1292 | printf("supported version is %u.%u\n", |
| 1293 | DPBP_VER_MAJOR, DPBP_VER_MINOR); |
| 1294 | } |
| 1295 | |
| 1296 | err = dpbp_open(dflt_mc_io, |
| 1297 | MC_CMD_NO_FLAGS, |
| 1298 | dflt_dpbp->dpbp_id, |
| 1299 | &dflt_dpbp->dpbp_handle); |
| 1300 | if (err) { |
| 1301 | printf("dpbp_open() failed\n"); |
| 1302 | goto err_open; |
| 1303 | } |
| 1304 | |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1305 | memset(&dpbp_attr, 0, sizeof(struct dpbp_attr)); |
| 1306 | err = dpbp_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS, |
| 1307 | dflt_dpbp->dpbp_handle, |
| 1308 | &dpbp_attr); |
| 1309 | if (err < 0) { |
| 1310 | printf("dpbp_get_attributes() failed: %d\n", err); |
| 1311 | goto err_get_attr; |
| 1312 | } |
| 1313 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1314 | if (dflt_dpbp->dpbp_id != dpbp_attr.id) { |
| 1315 | printf("dpbp object id and attribute id are not same\n"); |
| 1316 | goto err_attr_not_same; |
Prabhakar Kushwaha | 0a4156c | 2015-12-24 15:32:37 +0530 | [diff] [blame] | 1317 | } |
| 1318 | |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1319 | #ifdef DEBUG |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1320 | printf("Init: DPBP id=0x%x\n", dflt_dpbp->dpbp_attr.id); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1321 | #endif |
| 1322 | |
| 1323 | err = dpbp_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle); |
| 1324 | if (err < 0) { |
| 1325 | printf("dpbp_close() failed: %d\n", err); |
| 1326 | goto err_close; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1327 | } |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1328 | |
| 1329 | return 0; |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1330 | |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1331 | err_get_attr: |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1332 | err_attr_not_same: |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1333 | dpbp_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle); |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1334 | dpbp_destroy(dflt_mc_io, |
| 1335 | dflt_dprc_handle, |
| 1336 | MC_CMD_NO_FLAGS, |
| 1337 | dflt_dpbp->dpbp_id); |
| 1338 | err_get_api_ver: |
| 1339 | err_close: |
| 1340 | err_open: |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1341 | err_create: |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1342 | free(dflt_dpbp); |
Prabhakar Kushwaha | 790c1a4 | 2017-10-11 08:51:18 +0530 | [diff] [blame] | 1343 | err_calloc: |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1344 | return err; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1345 | } |
| 1346 | |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1347 | static int dpbp_exit(void) |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1348 | { |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1349 | int err; |
| 1350 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1351 | err = dpbp_destroy(dflt_mc_io, dflt_dprc_handle, MC_CMD_NO_FLAGS, |
| 1352 | dflt_dpbp->dpbp_id); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1353 | if (err < 0) { |
| 1354 | printf("dpbp_destroy() failed: %d\n", err); |
| 1355 | goto err; |
| 1356 | } |
| 1357 | |
| 1358 | #ifdef DEBUG |
| 1359 | printf("Exit: DPBP id=0x%d\n", dflt_dpbp->dpbp_attr.id); |
| 1360 | #endif |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1361 | |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1362 | if (dflt_dpbp) |
| 1363 | free(dflt_dpbp); |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1364 | return 0; |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1365 | |
| 1366 | err: |
| 1367 | return err; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1368 | } |
| 1369 | |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1370 | static int dpni_init(void) |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1371 | { |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1372 | int err; |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1373 | uint8_t cfg_buf[256] = {0}; |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1374 | struct dpni_cfg dpni_cfg; |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1375 | uint16_t major_ver, minor_ver; |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1376 | |
Prabhakar Kushwaha | 790c1a4 | 2017-10-11 08:51:18 +0530 | [diff] [blame] | 1377 | dflt_dpni = (struct fsl_dpni_obj *)calloc( |
| 1378 | sizeof(struct fsl_dpni_obj), 1); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1379 | if (!dflt_dpni) { |
Prabhakar Kushwaha | 790c1a4 | 2017-10-11 08:51:18 +0530 | [diff] [blame] | 1380 | printf("No memory: calloc() failed\n"); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1381 | err = -ENOMEM; |
Prabhakar Kushwaha | 790c1a4 | 2017-10-11 08:51:18 +0530 | [diff] [blame] | 1382 | goto err_calloc; |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1383 | } |
| 1384 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1385 | memset(&dpni_cfg, 0, sizeof(dpni_cfg)); |
| 1386 | err = dpni_prepare_cfg(&dpni_cfg, &cfg_buf[0]); |
Prabhakar Kushwaha | e26e285 | 2015-12-24 15:33:01 +0530 | [diff] [blame] | 1387 | if (err < 0) { |
| 1388 | err = -ENODEV; |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1389 | printf("dpni_prepare_cfg() failed: %d\n", err); |
| 1390 | goto err_prepare_cfg; |
Prabhakar Kushwaha | e26e285 | 2015-12-24 15:33:01 +0530 | [diff] [blame] | 1391 | } |
| 1392 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1393 | err = dpni_create(dflt_mc_io, |
| 1394 | dflt_dprc_handle, |
| 1395 | MC_CMD_NO_FLAGS, |
| 1396 | &dpni_cfg, |
| 1397 | &dflt_dpni->dpni_id); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1398 | if (err < 0) { |
| 1399 | err = -ENODEV; |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1400 | printf("dpni create() failed: %d\n", err); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1401 | goto err_create; |
| 1402 | } |
| 1403 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1404 | err = dpni_get_api_version(dflt_mc_io, 0, |
| 1405 | &major_ver, |
| 1406 | &minor_ver); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1407 | if (err < 0) { |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1408 | printf("dpni_get_api_version() failed: %d\n", err); |
| 1409 | goto err_get_version; |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1410 | } |
| 1411 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1412 | if (major_ver < DPNI_VER_MAJOR || (major_ver == DPNI_VER_MAJOR && |
| 1413 | minor_ver < DPNI_VER_MINOR)) { |
Prabhakar Kushwaha | 0a4156c | 2015-12-24 15:32:37 +0530 | [diff] [blame] | 1414 | printf("DPNI version mismatch found %u.%u,", |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1415 | major_ver, minor_ver); |
Prabhakar Kushwaha | 0a4156c | 2015-12-24 15:32:37 +0530 | [diff] [blame] | 1416 | printf("supported version is %u.%u\n", |
| 1417 | DPNI_VER_MAJOR, DPNI_VER_MINOR); |
| 1418 | } |
| 1419 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1420 | err = dpni_open(dflt_mc_io, |
| 1421 | MC_CMD_NO_FLAGS, |
| 1422 | dflt_dpni->dpni_id, |
| 1423 | &dflt_dpni->dpni_handle); |
| 1424 | if (err) { |
| 1425 | printf("dpni_open() failed\n"); |
| 1426 | goto err_open; |
| 1427 | } |
| 1428 | |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1429 | #ifdef DEBUG |
| 1430 | printf("Init: DPNI id=0x%d\n", dflt_dpni->dpni_id); |
| 1431 | #endif |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1432 | err = dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle); |
| 1433 | if (err < 0) { |
| 1434 | printf("dpni_close() failed: %d\n", err); |
| 1435 | goto err_close; |
| 1436 | } |
| 1437 | |
| 1438 | return 0; |
| 1439 | |
| 1440 | err_close: |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1441 | dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle); |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1442 | err_open: |
| 1443 | err_get_version: |
| 1444 | dpni_destroy(dflt_mc_io, |
| 1445 | dflt_dprc_handle, |
| 1446 | MC_CMD_NO_FLAGS, |
| 1447 | dflt_dpni->dpni_id); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1448 | err_create: |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1449 | err_prepare_cfg: |
Prabhakar Kushwaha | e26e285 | 2015-12-24 15:33:01 +0530 | [diff] [blame] | 1450 | free(dflt_dpni); |
Prabhakar Kushwaha | 790c1a4 | 2017-10-11 08:51:18 +0530 | [diff] [blame] | 1451 | err_calloc: |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1452 | return err; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1453 | } |
| 1454 | |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1455 | static int dpni_exit(void) |
| 1456 | { |
| 1457 | int err; |
| 1458 | |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1459 | err = dpni_destroy(dflt_mc_io, dflt_dprc_handle, MC_CMD_NO_FLAGS, |
| 1460 | dflt_dpni->dpni_id); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1461 | if (err < 0) { |
| 1462 | printf("dpni_destroy() failed: %d\n", err); |
| 1463 | goto err; |
| 1464 | } |
| 1465 | |
| 1466 | #ifdef DEBUG |
| 1467 | printf("Exit: DPNI id=0x%d\n", dflt_dpni->dpni_id); |
| 1468 | #endif |
| 1469 | |
| 1470 | if (dflt_dpni) |
| 1471 | free(dflt_dpni); |
| 1472 | return 0; |
| 1473 | |
| 1474 | err: |
| 1475 | return err; |
| 1476 | } |
Florinel Iordache | ae6d852 | 2019-11-19 10:28:17 +0000 | [diff] [blame] | 1477 | |
| 1478 | static bool is_dpsparser_supported(void) |
| 1479 | { |
| 1480 | /* dpsparser support was first introduced in MC version: 10.12.0 */ |
| 1481 | if (mc_ver_info.major < 10) |
| 1482 | return false; |
| 1483 | if (mc_ver_info.major == 10) |
| 1484 | return (mc_ver_info.minor >= 12); |
| 1485 | return true; |
| 1486 | } |
| 1487 | |
| 1488 | static int dpsparser_version_check(struct fsl_mc_io *mc_io) |
| 1489 | { |
| 1490 | int error; |
| 1491 | u16 major_ver, minor_ver; |
| 1492 | |
| 1493 | if (!is_dpsparser_supported()) |
| 1494 | return 0; |
| 1495 | |
| 1496 | error = dpsparser_get_api_version(mc_io, 0, |
| 1497 | &major_ver, |
| 1498 | &minor_ver); |
| 1499 | if (error < 0) { |
| 1500 | printf("dpsparser_get_api_version() failed: %d\n", error); |
| 1501 | return error; |
| 1502 | } |
| 1503 | |
| 1504 | if (major_ver < DPSPARSER_VER_MAJOR || (major_ver == |
| 1505 | DPSPARSER_VER_MAJOR && minor_ver < DPSPARSER_VER_MINOR)) { |
| 1506 | printf("DPSPARSER version mismatch found %u.%u,", |
| 1507 | major_ver, minor_ver); |
| 1508 | printf("supported version is %u.%u\n", |
| 1509 | DPSPARSER_VER_MAJOR, DPSPARSER_VER_MINOR); |
| 1510 | } |
| 1511 | |
| 1512 | return error; |
| 1513 | } |
| 1514 | |
| 1515 | static int dpsparser_init(void) |
| 1516 | { |
| 1517 | int err = 0; |
| 1518 | |
| 1519 | if (!is_dpsparser_supported()) |
| 1520 | return 0; |
| 1521 | |
| 1522 | err = dpsparser_create(dflt_mc_io, |
| 1523 | dflt_dprc_handle, |
| 1524 | MC_CMD_NO_FLAGS, |
| 1525 | &dpsparser_obj_id); |
| 1526 | if (err) |
| 1527 | printf("dpsparser_create() failed\n"); |
| 1528 | |
| 1529 | err = dpsparser_version_check(dflt_mc_io); |
| 1530 | if (err < 0) { |
| 1531 | printf("dpsparser_version_check() failed: %d\n", err); |
| 1532 | goto err_version_check; |
| 1533 | } |
| 1534 | |
| 1535 | err = dpsparser_open(dflt_mc_io, |
| 1536 | MC_CMD_NO_FLAGS, |
| 1537 | &dpsparser_handle); |
| 1538 | if (err < 0) { |
| 1539 | printf("dpsparser_open() failed: %d\n", err); |
| 1540 | goto err_open; |
| 1541 | } |
| 1542 | |
| 1543 | return err; |
| 1544 | |
| 1545 | err_open: |
| 1546 | err_version_check: |
| 1547 | dpsparser_destroy(dflt_mc_io, |
| 1548 | dflt_dprc_handle, |
| 1549 | MC_CMD_NO_FLAGS, dpsparser_obj_id); |
| 1550 | |
| 1551 | return err; |
| 1552 | } |
| 1553 | |
| 1554 | #ifdef DPSPARSER_DESTROY |
| 1555 | /* TODO: refactoring needed in the future to allow DPSPARSER object destroy |
| 1556 | * Workaround: DO NOT destroy DPSPARSER object because it needs to be available |
| 1557 | * on Apply DPL |
| 1558 | */ |
| 1559 | static int dpsparser_exit(void) |
| 1560 | { |
| 1561 | int err; |
| 1562 | |
| 1563 | if (!is_dpsparser_supported()) |
| 1564 | return 0; |
| 1565 | |
| 1566 | dpsparser_close(dflt_mc_io, MC_CMD_NO_FLAGS, dpsparser_handle); |
| 1567 | if (err < 0) { |
| 1568 | printf("dpsparser_close() failed: %d\n", err); |
| 1569 | goto err; |
| 1570 | } |
| 1571 | |
| 1572 | err = dpsparser_destroy(dflt_mc_io, dflt_dprc_handle, |
| 1573 | MC_CMD_NO_FLAGS, dpsparser_obj_id); |
| 1574 | if (err < 0) { |
| 1575 | printf("dpsparser_destroy() failed: %d\n", err); |
| 1576 | goto err; |
| 1577 | } |
| 1578 | return 0; |
| 1579 | |
| 1580 | err: |
| 1581 | return err; |
| 1582 | } |
| 1583 | #endif |
| 1584 | |
| 1585 | int mc_apply_spb(u64 mc_spb_addr) |
| 1586 | { |
| 1587 | int err = 0; |
| 1588 | u16 error, err_arr_size; |
| 1589 | u64 mc_spb_offset; |
| 1590 | u32 spb_size; |
| 1591 | struct sp_blob_header *sp_blob; |
| 1592 | u64 mc_ram_addr = mc_get_dram_addr(); |
| 1593 | |
| 1594 | if (!is_dpsparser_supported()) |
| 1595 | return 0; |
| 1596 | |
| 1597 | if (!mc_spb_addr) { |
| 1598 | printf("fsl-mc: Invalid Blob address\n"); |
| 1599 | return -1; |
| 1600 | } |
| 1601 | |
| 1602 | #ifdef CONFIG_MC_DRAM_SPB_OFFSET |
| 1603 | mc_spb_offset = CONFIG_MC_DRAM_SPB_OFFSET; |
| 1604 | #else |
| 1605 | #error "CONFIG_MC_DRAM_SPB_OFFSET not defined" |
| 1606 | #endif |
| 1607 | |
| 1608 | // Read blob header and get size of SPB blob |
| 1609 | sp_blob = (struct sp_blob_header *)mc_spb_addr; |
| 1610 | spb_size = le32_to_cpu(sp_blob->length); |
| 1611 | if (spb_size > CONFIG_MC_SPB_MAX_SIZE) { |
| 1612 | printf("\nfsl-mc: ERROR: Bad SPB image (too large: %d)\n", |
| 1613 | spb_size); |
| 1614 | return -EINVAL; |
| 1615 | } |
| 1616 | |
| 1617 | mc_copy_image("MC SP Blob", mc_spb_addr, spb_size, |
| 1618 | mc_ram_addr + mc_spb_offset); |
| 1619 | |
| 1620 | //Invoke MC command to apply SPB blob |
| 1621 | printf("fsl-mc: Applying soft parser blob... "); |
| 1622 | err = dpsparser_apply_spb(dflt_mc_io, MC_CMD_NO_FLAGS, dpsparser_handle, |
| 1623 | mc_spb_offset, &error); |
| 1624 | if (err) |
| 1625 | return err; |
| 1626 | |
| 1627 | if (error == 0) { |
| 1628 | printf("SUCCESS\n"); |
| 1629 | } else { |
| 1630 | printf("FAILED with error code = %d:\n", error); |
| 1631 | err_arr_size = (u16)ARRAY_SIZE(mc_err_msg_apply_spb); |
| 1632 | |
| 1633 | if (error > 0 && error < err_arr_size) |
| 1634 | printf(mc_err_msg_apply_spb[error]); |
| 1635 | else |
| 1636 | printf(MC_ERROR_MSG_SPB_UNKNOWN); |
| 1637 | } |
| 1638 | |
| 1639 | return err; |
| 1640 | } |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1641 | |
| 1642 | static int mc_init_object(void) |
| 1643 | { |
| 1644 | int err = 0; |
| 1645 | |
| 1646 | err = dprc_init(); |
| 1647 | if (err < 0) { |
| 1648 | printf("dprc_init() failed: %d\n", err); |
| 1649 | goto err; |
| 1650 | } |
| 1651 | |
| 1652 | err = dpbp_init(); |
| 1653 | if (err < 0) { |
| 1654 | printf("dpbp_init() failed: %d\n", err); |
| 1655 | goto err; |
| 1656 | } |
| 1657 | |
| 1658 | err = dpio_init(); |
| 1659 | if (err < 0) { |
| 1660 | printf("dpio_init() failed: %d\n", err); |
| 1661 | goto err; |
| 1662 | } |
| 1663 | |
| 1664 | err = dpni_init(); |
| 1665 | if (err < 0) { |
| 1666 | printf("dpni_init() failed: %d\n", err); |
| 1667 | goto err; |
| 1668 | } |
| 1669 | |
Florinel Iordache | ae6d852 | 2019-11-19 10:28:17 +0000 | [diff] [blame] | 1670 | err = dpsparser_init(); |
| 1671 | if (err < 0) { |
| 1672 | printf("dpsparser_init() failed: %d\n", err); |
| 1673 | goto err; |
| 1674 | } |
| 1675 | |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1676 | return 0; |
| 1677 | err: |
| 1678 | return err; |
| 1679 | } |
| 1680 | |
| 1681 | int fsl_mc_ldpaa_exit(bd_t *bd) |
| 1682 | { |
| 1683 | int err = 0; |
Yogesh Gaur | 4a81bbe | 2017-04-27 10:14:16 +0530 | [diff] [blame] | 1684 | bool is_dpl_apply_status = false; |
Santan Kumar | 0a6e5ba | 2017-06-29 11:19:34 +0530 | [diff] [blame] | 1685 | bool mc_boot_status = false; |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1686 | |
Alexander Graf | 2ebeb44 | 2016-11-17 01:02:57 +0100 | [diff] [blame] | 1687 | if (bd && mc_lazy_dpl_addr && !fsl_mc_ldpaa_exit(NULL)) { |
Yogesh Gaur | 8dadfb4 | 2018-01-16 10:08:24 +0530 | [diff] [blame] | 1688 | err = mc_apply_dpl(mc_lazy_dpl_addr); |
| 1689 | if (!err) |
| 1690 | fdt_fixup_board_enet(working_fdt); |
Alexander Graf | 2ebeb44 | 2016-11-17 01:02:57 +0100 | [diff] [blame] | 1691 | mc_lazy_dpl_addr = 0; |
| 1692 | } |
| 1693 | |
Santan Kumar | 0a6e5ba | 2017-06-29 11:19:34 +0530 | [diff] [blame] | 1694 | if (!get_mc_boot_status()) |
| 1695 | mc_boot_status = true; |
| 1696 | |
Prabhakar Kushwaha | 878d3ec | 2016-03-21 14:19:39 +0530 | [diff] [blame] | 1697 | /* MC is not loaded intentionally, So return success. */ |
Santan Kumar | 0a6e5ba | 2017-06-29 11:19:34 +0530 | [diff] [blame] | 1698 | if (bd && !mc_boot_status) |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1699 | return 0; |
| 1700 | |
Yogesh Gaur | 4a81bbe | 2017-04-27 10:14:16 +0530 | [diff] [blame] | 1701 | /* If DPL is deployed, set is_dpl_apply_status as TRUE. */ |
| 1702 | if (!get_dpl_apply_status()) |
| 1703 | is_dpl_apply_status = true; |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1704 | |
Yogesh Gaur | 4a81bbe | 2017-04-27 10:14:16 +0530 | [diff] [blame] | 1705 | /* |
| 1706 | * For case MC is loaded but DPL is not deployed, return success and |
| 1707 | * print message on console. Else FDT fix-up code execution hanged. |
| 1708 | */ |
Santan Kumar | 0a6e5ba | 2017-06-29 11:19:34 +0530 | [diff] [blame] | 1709 | if (bd && mc_boot_status && !is_dpl_apply_status) { |
Yogesh Gaur | 4a81bbe | 2017-04-27 10:14:16 +0530 | [diff] [blame] | 1710 | printf("fsl-mc: DPL not deployed, DPAA2 ethernet not work\n"); |
Yogesh Gaur | 82709e5 | 2017-11-28 10:11:14 +0530 | [diff] [blame] | 1711 | goto mc_obj_cleanup; |
Yogesh Gaur | 4a81bbe | 2017-04-27 10:14:16 +0530 | [diff] [blame] | 1712 | } |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1713 | |
Santan Kumar | 0a6e5ba | 2017-06-29 11:19:34 +0530 | [diff] [blame] | 1714 | if (bd && mc_boot_status && is_dpl_apply_status) |
| 1715 | return 0; |
| 1716 | |
Yogesh Gaur | 82709e5 | 2017-11-28 10:11:14 +0530 | [diff] [blame] | 1717 | mc_obj_cleanup: |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1718 | err = dpbp_exit(); |
| 1719 | if (err < 0) { |
Prabhakar Kushwaha | 88ba4d6 | 2016-01-20 12:04:37 +0530 | [diff] [blame] | 1720 | printf("dpbp_exit() failed: %d\n", err); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1721 | goto err; |
| 1722 | } |
| 1723 | |
| 1724 | err = dpio_exit(); |
| 1725 | if (err < 0) { |
| 1726 | printf("dpio_exit() failed: %d\n", err); |
| 1727 | goto err; |
| 1728 | } |
| 1729 | |
| 1730 | err = dpni_exit(); |
| 1731 | if (err < 0) { |
| 1732 | printf("dpni_exit() failed: %d\n", err); |
| 1733 | goto err; |
| 1734 | } |
| 1735 | |
| 1736 | err = dprc_exit(); |
| 1737 | if (err < 0) { |
| 1738 | printf("dprc_exit() failed: %d\n", err); |
| 1739 | goto err; |
| 1740 | } |
| 1741 | |
| 1742 | return 0; |
| 1743 | err: |
| 1744 | return err; |
| 1745 | } |
| 1746 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1747 | static int do_fsl_mc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1748 | { |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1749 | int err = 0; |
| 1750 | if (argc < 3) |
| 1751 | goto usage; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1752 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1753 | switch (argv[1][0]) { |
| 1754 | case 's': { |
| 1755 | char sub_cmd; |
Prabhakar Kushwaha | 122bcfd | 2015-11-09 16:42:07 +0530 | [diff] [blame] | 1756 | u64 mc_fw_addr, mc_dpc_addr; |
| 1757 | #ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET |
| 1758 | u64 aiop_fw_addr; |
| 1759 | #endif |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1760 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1761 | sub_cmd = argv[2][0]; |
Yogesh Gaur | 318c32f | 2017-11-15 11:59:31 +0530 | [diff] [blame] | 1762 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1763 | switch (sub_cmd) { |
| 1764 | case 'm': |
| 1765 | if (argc < 5) |
| 1766 | goto usage; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1767 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1768 | if (get_mc_boot_status() == 0) { |
| 1769 | printf("fsl-mc: MC is already booted"); |
| 1770 | printf("\n"); |
| 1771 | return err; |
| 1772 | } |
| 1773 | mc_fw_addr = simple_strtoull(argv[3], NULL, 16); |
| 1774 | mc_dpc_addr = simple_strtoull(argv[4], NULL, |
| 1775 | 16); |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1776 | |
| 1777 | if (!mc_init(mc_fw_addr, mc_dpc_addr)) |
| 1778 | err = mc_init_object(); |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1779 | break; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1780 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1781 | #ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET |
| 1782 | case 'a': |
| 1783 | if (argc < 4) |
| 1784 | goto usage; |
| 1785 | if (get_aiop_apply_status() == 0) { |
| 1786 | printf("fsl-mc: AIOP FW is already"); |
| 1787 | printf(" applied\n"); |
| 1788 | return err; |
| 1789 | } |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1790 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1791 | aiop_fw_addr = simple_strtoull(argv[3], NULL, |
| 1792 | 16); |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1793 | |
York Sun | cbe8e1c | 2016-04-04 11:41:26 -0700 | [diff] [blame] | 1794 | /* if SoC doesn't have AIOP, err = -ENODEV */ |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1795 | err = load_mc_aiop_img(aiop_fw_addr); |
| 1796 | if (!err) |
| 1797 | printf("fsl-mc: AIOP FW applied\n"); |
| 1798 | break; |
| 1799 | #endif |
| 1800 | default: |
| 1801 | printf("Invalid option: %s\n", argv[2]); |
| 1802 | goto usage; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1803 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1804 | break; |
| 1805 | } |
| 1806 | } |
Florinel Iordache | ae6d852 | 2019-11-19 10:28:17 +0000 | [diff] [blame] | 1807 | break; |
| 1808 | |
| 1809 | case 'l': { |
| 1810 | /* lazyapply */ |
| 1811 | u64 mc_dpl_addr; |
| 1812 | |
| 1813 | if (argc < 4) |
| 1814 | goto usage; |
| 1815 | |
| 1816 | if (get_dpl_apply_status() == 0) { |
| 1817 | printf("fsl-mc: DPL already applied\n"); |
| 1818 | return err; |
| 1819 | } |
| 1820 | |
| 1821 | mc_dpl_addr = simple_strtoull(argv[3], NULL, 16); |
| 1822 | |
| 1823 | if (get_mc_boot_status() != 0) { |
| 1824 | printf("fsl-mc: Deploying data path layout .."); |
| 1825 | printf("ERROR (MC is not booted)\n"); |
| 1826 | return -ENODEV; |
| 1827 | } |
| 1828 | |
| 1829 | /* |
| 1830 | * We will do the actual dpaa exit and dpl apply |
| 1831 | * later from announce_and_cleanup(). |
| 1832 | */ |
| 1833 | mc_lazy_dpl_addr = mc_dpl_addr; |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1834 | break; |
Florinel Iordache | ae6d852 | 2019-11-19 10:28:17 +0000 | [diff] [blame] | 1835 | } |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1836 | |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1837 | case 'a': { |
Florinel Iordache | ae6d852 | 2019-11-19 10:28:17 +0000 | [diff] [blame] | 1838 | /* apply */ |
| 1839 | char sub_cmd; |
| 1840 | u64 mc_apply_addr; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1841 | |
Florinel Iordache | ae6d852 | 2019-11-19 10:28:17 +0000 | [diff] [blame] | 1842 | if (argc < 4) |
| 1843 | goto usage; |
| 1844 | |
| 1845 | sub_cmd = argv[2][0]; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1846 | |
Florinel Iordache | ae6d852 | 2019-11-19 10:28:17 +0000 | [diff] [blame] | 1847 | switch (sub_cmd) { |
| 1848 | case 'd': |
| 1849 | case 'D': |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1850 | if (get_dpl_apply_status() == 0) { |
| 1851 | printf("fsl-mc: DPL already applied\n"); |
| 1852 | return err; |
| 1853 | } |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1854 | if (get_mc_boot_status() != 0) { |
| 1855 | printf("fsl-mc: Deploying data path layout .."); |
| 1856 | printf("ERROR (MC is not booted)\n"); |
| 1857 | return -ENODEV; |
| 1858 | } |
Prabhakar Kushwaha | 316b71c | 2015-11-04 12:25:59 +0530 | [diff] [blame] | 1859 | |
Florinel Iordache | ae6d852 | 2019-11-19 10:28:17 +0000 | [diff] [blame] | 1860 | mc_apply_addr = simple_strtoull(argv[3], NULL, 16); |
| 1861 | |
| 1862 | /* The user wants DPL applied now */ |
| 1863 | if (!fsl_mc_ldpaa_exit(NULL)) |
| 1864 | err = mc_apply_dpl(mc_apply_addr); |
| 1865 | break; |
| 1866 | |
| 1867 | case 's': |
| 1868 | if (!is_dpsparser_supported()) { |
| 1869 | printf("fsl-mc: apply spb command .. "); |
| 1870 | printf("ERROR: requires at least MC 10.12.0\n"); |
| 1871 | return err; |
Alexander Graf | 2ebeb44 | 2016-11-17 01:02:57 +0100 | [diff] [blame] | 1872 | } |
Florinel Iordache | ae6d852 | 2019-11-19 10:28:17 +0000 | [diff] [blame] | 1873 | if (get_mc_boot_status() != 0) { |
| 1874 | printf("fsl-mc: Deploying Soft Parser Blob..."); |
| 1875 | printf("ERROR (MC is not booted)\n"); |
| 1876 | return err; |
| 1877 | } |
| 1878 | |
| 1879 | mc_apply_addr = simple_strtoull(argv[3], NULL, 16); |
| 1880 | |
| 1881 | /* Apply spb (Soft Parser Blob) */ |
| 1882 | err = mc_apply_spb(mc_apply_addr); |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1883 | break; |
Florinel Iordache | ae6d852 | 2019-11-19 10:28:17 +0000 | [diff] [blame] | 1884 | |
| 1885 | default: |
| 1886 | printf("Invalid option: %s\n", argv[2]); |
| 1887 | goto usage; |
| 1888 | } |
| 1889 | break; |
J. German Rivera | f4fed4b | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 1890 | } |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1891 | default: |
| 1892 | printf("Invalid option: %s\n", argv[1]); |
| 1893 | goto usage; |
| 1894 | break; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1895 | } |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1896 | return err; |
| 1897 | usage: |
| 1898 | return CMD_RET_USAGE; |
Prabhakar Kushwaha | cfd9fbf | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1899 | } |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1900 | |
| 1901 | U_BOOT_CMD( |
| 1902 | fsl_mc, CONFIG_SYS_MAXARGS, 1, do_fsl_mc, |
| 1903 | "DPAA2 command to manage Management Complex (MC)", |
| 1904 | "start mc [FW_addr] [DPC_addr] - Start Management Complex\n" |
| 1905 | "fsl_mc apply DPL [DPL_addr] - Apply DPL file\n" |
Alexander Graf | 2ebeb44 | 2016-11-17 01:02:57 +0100 | [diff] [blame] | 1906 | "fsl_mc lazyapply DPL [DPL_addr] - Apply DPL file on exit\n" |
Florinel Iordache | ae6d852 | 2019-11-19 10:28:17 +0000 | [diff] [blame] | 1907 | "fsl_mc apply spb [spb_addr] - Apply SPB Soft Parser Blob\n" |
Prabhakar Kushwaha | 29a63e4 | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1908 | "fsl_mc start aiop [FW_addr] - Start AIOP\n" |
| 1909 | ); |
Bogdan Purcareata | 08bc014 | 2017-05-24 16:40:21 +0000 | [diff] [blame] | 1910 | |
| 1911 | void mc_env_boot(void) |
| 1912 | { |
| 1913 | #if defined(CONFIG_FSL_MC_ENET) |
| 1914 | char *mc_boot_env_var; |
| 1915 | /* The MC may only be initialized in the reset PHY function |
| 1916 | * because otherwise U-Boot has not yet set up all the MAC |
| 1917 | * address info properly. Without MAC addresses, the MC code |
| 1918 | * can not properly initialize the DPC. |
| 1919 | */ |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 1920 | mc_boot_env_var = env_get(MC_BOOT_ENV_VAR); |
Bogdan Purcareata | 08bc014 | 2017-05-24 16:40:21 +0000 | [diff] [blame] | 1921 | if (mc_boot_env_var) |
| 1922 | run_command_list(mc_boot_env_var, -1, 0); |
| 1923 | #endif /* CONFIG_FSL_MC_ENET */ |
| 1924 | } |