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