1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2014 Freescale Semiconductor, Inc.
5 * Copyright 2017-2018 NXP
11 #include <linux/libfdt.h>
13 #include <fdt_support.h>
14 #include <fsl-mc/fsl_mc.h>
15 #include <fsl-mc/fsl_mc_sys.h>
16 #include <fsl-mc/fsl_mc_private.h>
17 #include <fsl-mc/fsl_dpmng.h>
18 #include <fsl-mc/fsl_dprc.h>
19 #include <fsl-mc/fsl_dpio.h>
20 #include <fsl-mc/fsl_dpni.h>
21 #include <fsl-mc/fsl_qbman_portal.h>
22 #include <fsl-mc/ldpaa_wriop.h>
24 #define MC_RAM_BASE_ADDR_ALIGNMENT (512UL * 1024 * 1024)
25 #define MC_RAM_BASE_ADDR_ALIGNMENT_MASK (~(MC_RAM_BASE_ADDR_ALIGNMENT - 1))
26 #define MC_RAM_SIZE_ALIGNMENT (256UL * 1024 * 1024)
28 #define MC_MEM_SIZE_ENV_VAR "mcmemsize"
29 #define MC_BOOT_TIMEOUT_ENV_VAR "mcboottimeout"
30 #define MC_BOOT_ENV_VAR "mcinitcmd"
32 DECLARE_GLOBAL_DATA_PTR;
33 static int mc_memset_resv_ram;
34 static int mc_boot_status = -1;
35 static int mc_dpl_applied = -1;
36 #ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
37 static int mc_aiop_applied = -1;
39 struct fsl_mc_io *root_mc_io = NULL;
40 struct fsl_mc_io *dflt_mc_io = NULL; /* child container */
41 uint16_t root_dprc_handle = 0;
42 uint16_t dflt_dprc_handle = 0;
44 struct fsl_dpbp_obj *dflt_dpbp = NULL;
45 struct fsl_dpio_obj *dflt_dpio = NULL;
46 struct fsl_dpni_obj *dflt_dpni = NULL;
47 static u64 mc_lazy_dpl_addr;
50 void dump_ram_words(const char *title, void *addr)
53 uint32_t *words = addr;
55 printf("Dumping beginning of %s (%p):\n", title, addr);
56 for (i = 0; i < 16; i++)
57 printf("%#x ", words[i]);
62 void dump_mc_ccsr_regs(struct mc_ccsr_registers __iomem *mc_ccsr_regs)
64 printf("MC CCSR registers:\n"
74 mc_ccsr_regs->reg_gcr1,
75 mc_ccsr_regs->reg_gsr,
76 mc_ccsr_regs->reg_sicbalr,
77 mc_ccsr_regs->reg_sicbahr,
78 mc_ccsr_regs->reg_sicapr,
79 mc_ccsr_regs->reg_mcfbalr,
80 mc_ccsr_regs->reg_mcfbahr,
81 mc_ccsr_regs->reg_mcfapr,
82 mc_ccsr_regs->reg_psr);
86 #define dump_ram_words(title, addr)
87 #define dump_mc_ccsr_regs(mc_ccsr_regs)
91 #ifndef CONFIG_SYS_LS_MC_FW_IN_DDR
93 * Copying MC firmware or DPL image to DDR
95 static int mc_copy_image(const char *title,
96 u64 image_addr, u32 image_size, u64 mc_ram_addr)
98 debug("%s copied to address %p\n", title, (void *)mc_ram_addr);
99 memcpy((void *)mc_ram_addr, (void *)image_addr, image_size);
100 flush_dcache_range(mc_ram_addr, mc_ram_addr + image_size);
105 * MC firmware FIT image parser checks if the image is in FIT
106 * format, verifies integrity of the image and calculates
107 * raw image address and size values.
108 * Returns 0 on success and a negative errno on error.
111 int parse_mc_firmware_fit_image(u64 mc_fw_addr,
112 const void **raw_image_addr,
113 size_t *raw_image_size)
120 const char *uname = "firmware";
122 fit_hdr = (void *)mc_fw_addr;
124 /* Check if Image is in FIT format */
125 format = genimg_get_format(fit_hdr);
127 if (format != IMAGE_FORMAT_FIT) {
128 printf("fsl-mc: ERR: Bad firmware image (not a FIT image)\n");
132 if (!fit_check_format(fit_hdr)) {
133 printf("fsl-mc: ERR: Bad firmware image (bad FIT header)\n");
137 node_offset = fit_image_get_node(fit_hdr, uname);
139 if (node_offset < 0) {
140 printf("fsl-mc: ERR: Bad firmware image (missing subimage)\n");
144 /* Verify MC firmware image */
145 if (!(fit_image_verify(fit_hdr, node_offset))) {
146 printf("fsl-mc: ERR: Bad firmware image (bad CRC)\n");
150 /* Get address and size of raw image */
151 fit_image_get_data(fit_hdr, node_offset, &data, &size);
153 *raw_image_addr = data;
154 *raw_image_size = size;
160 #define MC_DT_INCREASE_SIZE 64
167 static int mc_fixup_mac_addr(void *blob, int nodeoffset,
168 const char *propname, struct eth_device *eth_dev,
169 enum mc_fixup_type type)
171 int err = 0, len = 0, size, i;
172 unsigned char env_enetaddr[ARP_HLEN];
173 unsigned int enetaddr_32[ARP_HLEN];
178 /* DPL likes its addresses on 32 * ARP_HLEN bits */
179 for (i = 0; i < ARP_HLEN; i++)
180 enetaddr_32[i] = cpu_to_fdt32(eth_dev->enetaddr[i]);
182 len = sizeof(enetaddr_32);
186 val = eth_dev->enetaddr;
191 /* MAC address property present */
192 if (fdt_get_property(blob, nodeoffset, propname, NULL)) {
193 /* u-boot MAC addr randomly assigned - leave the present one */
194 if (!eth_env_get_enetaddr_by_index("eth", eth_dev->index,
198 size = MC_DT_INCREASE_SIZE + strlen(propname) + len;
199 /* make room for mac address property */
200 err = fdt_increase_size(blob, size);
202 printf("fdt_increase_size: err=%s\n",
208 err = fdt_setprop(blob, nodeoffset, propname, val, len);
210 printf("fdt_setprop: err=%s\n", fdt_strerror(err));
217 #define is_dpni(s) (s != NULL ? !strncmp(s, "dpni@", 5) : 0)
219 const char *dpl_get_connection_endpoint(void *blob, char *endpoint)
221 int connoffset = fdt_path_offset(blob, "/connections"), off;
224 for (off = fdt_first_subnode(blob, connoffset);
226 off = fdt_next_subnode(blob, off)) {
227 s1 = fdt_stringlist_get(blob, off, "endpoint1", 0, NULL);
228 s2 = fdt_stringlist_get(blob, off, "endpoint2", 0, NULL);
233 if (strcmp(endpoint, s1) == 0)
236 if (strcmp(endpoint, s2) == 0)
243 static int mc_fixup_dpl_mac_addr(void *blob, int dpmac_id,
244 struct eth_device *eth_dev)
246 int objoff = fdt_path_offset(blob, "/objects");
247 int dpmacoff = -1, dpnioff = -1;
248 const char *endpoint;
252 sprintf(mac_name, "dpmac@%d", dpmac_id);
253 dpmacoff = fdt_subnode_offset(blob, objoff, mac_name);
255 /* dpmac not defined in DPL, so skip it. */
258 err = mc_fixup_mac_addr(blob, dpmacoff, "mac_addr", eth_dev,
261 printf("Error fixing up dpmac mac_addr in DPL\n");
265 /* now we need to figure out if there is any
266 * DPNI connected to this MAC, so we walk the
269 endpoint = dpl_get_connection_endpoint(blob, mac_name);
270 if (!is_dpni(endpoint))
273 /* let's see if we can fixup the DPNI as well */
274 dpnioff = fdt_subnode_offset(blob, objoff, endpoint);
276 /* DPNI not defined in DPL in the objects area */
279 return mc_fixup_mac_addr(blob, dpnioff, "mac_addr", eth_dev,
283 void fdt_fsl_mc_fixup_iommu_map_entry(void *blob)
290 /* find fsl-mc node */
291 offset = fdt_path_offset(blob, "/soc/fsl-mc");
293 offset = fdt_path_offset(blob, "/fsl-mc");
295 printf("%s: fsl-mc: ERR: fsl-mc node not found in DT, err %d\n",
300 prop = fdt_getprop_w(blob, offset, "iommu-map", &lenp);
302 debug("%s: fsl-mc: ERR: missing iommu-map in fsl-mc bus node\n",
307 iommu_map[0] = cpu_to_fdt32(FSL_DPAA2_STREAM_ID_START);
308 iommu_map[1] = *++prop;
309 iommu_map[2] = cpu_to_fdt32(FSL_DPAA2_STREAM_ID_START);
310 iommu_map[3] = cpu_to_fdt32(FSL_DPAA2_STREAM_ID_END -
311 FSL_DPAA2_STREAM_ID_START + 1);
313 fdt_setprop_inplace(blob, offset, "iommu-map",
314 iommu_map, sizeof(iommu_map));
317 static int mc_fixup_dpc_mac_addr(void *blob, int dpmac_id,
318 struct eth_device *eth_dev)
320 int nodeoffset = fdt_path_offset(blob, "/board_info/ports"), noff;
323 const char link_type_mode[] = "MAC_LINK_TYPE_FIXED";
325 sprintf(mac_name, "mac@%d", dpmac_id);
327 /* node not found - create it */
328 noff = fdt_subnode_offset(blob, nodeoffset, (const char *)mac_name);
330 err = fdt_increase_size(blob, 200);
332 printf("fdt_increase_size: err=%s\n",
337 noff = fdt_add_subnode(blob, nodeoffset, mac_name);
339 printf("fdt_add_subnode: err=%s\n",
344 /* add default property of fixed link */
345 err = fdt_appendprop_string(blob, noff,
346 "link_type", link_type_mode);
348 printf("fdt_appendprop_string: err=%s\n",
354 return mc_fixup_mac_addr(blob, noff, "port_mac_address", eth_dev,
358 static int mc_fixup_mac_addrs(void *blob, enum mc_fixup_type type)
360 int i, err = 0, ret = 0;
361 char ethname[ETH_NAME_LEN];
362 struct eth_device *eth_dev;
364 for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++) {
365 /* port not enabled */
366 if ((wriop_is_enabled_dpmac(i) != 1) ||
367 (wriop_get_phy_address(i) == -1))
370 snprintf(ethname, ETH_NAME_LEN, "DPMAC%d@%s", i,
371 phy_interface_strings[wriop_get_enet_if(i)]);
373 eth_dev = eth_get_dev_by_name(ethname);
379 err = mc_fixup_dpl_mac_addr(blob, i, eth_dev);
382 err = mc_fixup_dpc_mac_addr(blob, i, eth_dev);
389 printf("fsl-mc: ERROR fixing mac address for %s\n",
397 static int mc_fixup_dpc(u64 dpc_addr)
399 void *blob = (void *)dpc_addr;
400 int nodeoffset, err = 0;
402 /* delete any existing ICID pools */
403 nodeoffset = fdt_path_offset(blob, "/resources/icid_pools");
404 if (fdt_del_node(blob, nodeoffset) < 0)
405 printf("\nfsl-mc: WARNING: could not delete ICID pool\n");
408 nodeoffset = fdt_path_offset(blob, "/resources");
409 if (nodeoffset < 0) {
410 printf("\nfsl-mc: ERROR: DPC is missing /resources\n");
413 nodeoffset = fdt_add_subnode(blob, nodeoffset, "icid_pools");
414 nodeoffset = fdt_add_subnode(blob, nodeoffset, "icid_pool@0");
415 do_fixup_by_path_u32(blob, "/resources/icid_pools/icid_pool@0",
416 "base_icid", FSL_DPAA2_STREAM_ID_START, 1);
417 do_fixup_by_path_u32(blob, "/resources/icid_pools/icid_pool@0",
419 FSL_DPAA2_STREAM_ID_END -
420 FSL_DPAA2_STREAM_ID_START + 1, 1);
422 /* fixup MAC addresses for dpmac ports */
423 nodeoffset = fdt_path_offset(blob, "/board_info/ports");
427 err = mc_fixup_mac_addrs(blob, MC_FIXUP_DPC);
428 flush_dcache_range(dpc_addr, dpc_addr + fdt_totalsize(blob));
433 static int load_mc_dpc(u64 mc_ram_addr, size_t mc_ram_size, u64 mc_dpc_addr)
436 #ifndef CONFIG_SYS_LS_MC_DPC_IN_DDR
442 #ifdef CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET
443 BUILD_BUG_ON((CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET & 0x3) != 0 ||
444 CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET > 0xffffffff);
446 mc_dpc_offset = CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET;
448 #error "CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET not defined"
452 * Load the MC DPC blob in the MC private DRAM block:
454 #ifdef CONFIG_SYS_LS_MC_DPC_IN_DDR
455 printf("MC DPC is preloaded to %#llx\n", mc_ram_addr + mc_dpc_offset);
458 * Get address and size of the DPC blob stored in flash:
460 dpc_fdt_hdr = (void *)mc_dpc_addr;
462 error = fdt_check_header(dpc_fdt_hdr);
465 * Don't return with error here, since the MC firmware can
466 * still boot without a DPC
468 printf("\nfsl-mc: WARNING: No DPC image found");
472 dpc_size = fdt_totalsize(dpc_fdt_hdr);
473 if (dpc_size > CONFIG_SYS_LS_MC_DPC_MAX_LENGTH) {
474 printf("\nfsl-mc: ERROR: Bad DPC image (too large: %d)\n",
479 mc_copy_image("MC DPC blob",
480 (u64)dpc_fdt_hdr, dpc_size, mc_ram_addr + mc_dpc_offset);
481 #endif /* not defined CONFIG_SYS_LS_MC_DPC_IN_DDR */
483 if (mc_fixup_dpc(mc_ram_addr + mc_dpc_offset))
486 dump_ram_words("DPC", (void *)(mc_ram_addr + mc_dpc_offset));
491 static int mc_fixup_dpl(u64 dpl_addr)
493 void *blob = (void *)dpl_addr;
494 u32 ver = fdt_getprop_u32_default(blob, "/", "dpl-version", 0);
497 /* The DPL fixup for mac addresses is only relevant
503 err = mc_fixup_mac_addrs(blob, MC_FIXUP_DPL);
504 flush_dcache_range(dpl_addr, dpl_addr + fdt_totalsize(blob));
509 static int load_mc_dpl(u64 mc_ram_addr, size_t mc_ram_size, u64 mc_dpl_addr)
512 #ifndef CONFIG_SYS_LS_MC_DPL_IN_DDR
518 #ifdef CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET
519 BUILD_BUG_ON((CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET & 0x3) != 0 ||
520 CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET > 0xffffffff);
522 mc_dpl_offset = CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET;
524 #error "CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET not defined"
528 * Load the MC DPL blob in the MC private DRAM block:
530 #ifdef CONFIG_SYS_LS_MC_DPL_IN_DDR
531 printf("MC DPL is preloaded to %#llx\n", mc_ram_addr + mc_dpl_offset);
534 * Get address and size of the DPL blob stored in flash:
536 dpl_fdt_hdr = (void *)mc_dpl_addr;
538 error = fdt_check_header(dpl_fdt_hdr);
540 printf("\nfsl-mc: ERROR: Bad DPL image (bad header)\n");
544 dpl_size = fdt_totalsize(dpl_fdt_hdr);
545 if (dpl_size > CONFIG_SYS_LS_MC_DPL_MAX_LENGTH) {
546 printf("\nfsl-mc: ERROR: Bad DPL image (too large: %d)\n",
551 mc_copy_image("MC DPL blob",
552 (u64)dpl_fdt_hdr, dpl_size, mc_ram_addr + mc_dpl_offset);
553 #endif /* not defined CONFIG_SYS_LS_MC_DPL_IN_DDR */
555 if (mc_fixup_dpl(mc_ram_addr + mc_dpl_offset))
557 dump_ram_words("DPL", (void *)(mc_ram_addr + mc_dpl_offset));
562 * Return the MC boot timeout value in milliseconds
564 static unsigned long get_mc_boot_timeout_ms(void)
566 unsigned long timeout_ms = CONFIG_SYS_LS_MC_BOOT_TIMEOUT_MS;
568 char *timeout_ms_env_var = env_get(MC_BOOT_TIMEOUT_ENV_VAR);
570 if (timeout_ms_env_var) {
571 timeout_ms = simple_strtoul(timeout_ms_env_var, NULL, 10);
572 if (timeout_ms == 0) {
573 printf("fsl-mc: WARNING: Invalid value for \'"
574 MC_BOOT_TIMEOUT_ENV_VAR
575 "\' environment variable: %lu\n",
578 timeout_ms = CONFIG_SYS_LS_MC_BOOT_TIMEOUT_MS;
585 #ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
587 __weak bool soc_has_aiop(void)
592 static int load_mc_aiop_img(u64 aiop_fw_addr)
594 u64 mc_ram_addr = mc_get_dram_addr();
595 #ifndef CONFIG_SYS_LS_MC_DPC_IN_DDR
599 /* Check if AIOP is available */
603 * Load the MC AIOP image in the MC private DRAM block:
606 #ifdef CONFIG_SYS_LS_MC_DPC_IN_DDR
607 printf("MC AIOP is preloaded to %#llx\n", mc_ram_addr +
608 CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET);
610 aiop_img = (void *)aiop_fw_addr;
611 mc_copy_image("MC AIOP image",
612 (u64)aiop_img, CONFIG_SYS_LS_MC_AIOP_IMG_MAX_LENGTH,
613 mc_ram_addr + CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET);
621 static int wait_for_mc(bool booting_mc, u32 *final_reg_gsr)
624 u32 mc_fw_boot_status;
625 unsigned long timeout_ms = get_mc_boot_timeout_ms();
626 struct mc_ccsr_registers __iomem *mc_ccsr_regs = MC_CCSR_BASE_ADDR;
629 assert(timeout_ms > 0);
631 udelay(1000); /* throttle polling */
632 reg_gsr = in_le32(&mc_ccsr_regs->reg_gsr);
633 mc_fw_boot_status = (reg_gsr & GSR_FS_MASK);
634 if (mc_fw_boot_status & 0x1)
642 if (timeout_ms == 0) {
643 printf("ERROR: timeout\n");
645 /* TODO: Get an error status from an MC CCSR register */
649 if (mc_fw_boot_status != 0x1) {
651 * TODO: Identify critical errors from the GSR register's FS
652 * field and for those errors, set error to -ENODEV or other
653 * appropriate errno, so that the status property is set to
654 * failure in the fsl,dprc device tree node.
656 printf("WARNING: Firmware returned an error (GSR: %#x)\n",
663 *final_reg_gsr = reg_gsr;
667 int mc_init(u64 mc_fw_addr, u64 mc_dpc_addr)
671 struct mc_ccsr_registers __iomem *mc_ccsr_regs = MC_CCSR_BASE_ADDR;
672 u64 mc_ram_addr = mc_get_dram_addr();
675 #ifndef CONFIG_SYS_LS_MC_FW_IN_DDR
676 const void *raw_image_addr;
677 size_t raw_image_size = 0;
679 struct mc_version mc_ver_info;
680 u8 mc_ram_num_256mb_blocks;
681 size_t mc_ram_size = mc_get_dram_block_size();
683 mc_ram_num_256mb_blocks = mc_ram_size / MC_RAM_SIZE_ALIGNMENT;
684 if (mc_ram_num_256mb_blocks < 1 || mc_ram_num_256mb_blocks > 0xff) {
686 printf("fsl-mc: ERROR: invalid MC private RAM size (%lu)\n",
692 * Management Complex cores should be held at reset out of POR.
693 * U-Boot should be the first software to touch MC. To be safe,
694 * we reset all cores again by setting GCR1 to 0. It doesn't do
695 * anything if they are held at reset. After we setup the firmware
696 * we kick off MC by deasserting the reset bit for core 0, and
697 * deasserting the reset bits for Command Portal Managers.
698 * The stop bits are not touched here. They are used to stop the
699 * cores when they are active. Setting stop bits doesn't stop the
700 * cores from fetching instructions when they are released from
703 out_le32(&mc_ccsr_regs->reg_gcr1, 0);
706 #ifdef CONFIG_SYS_LS_MC_FW_IN_DDR
707 printf("MC firmware is preloaded to %#llx\n", mc_ram_addr);
709 error = parse_mc_firmware_fit_image(mc_fw_addr, &raw_image_addr,
714 * Load the MC FW at the beginning of the MC private DRAM block:
716 mc_copy_image("MC Firmware",
717 (u64)raw_image_addr, raw_image_size, mc_ram_addr);
719 dump_ram_words("firmware", (void *)mc_ram_addr);
721 error = load_mc_dpc(mc_ram_addr, mc_ram_size, mc_dpc_addr);
725 debug("mc_ccsr_regs %p\n", mc_ccsr_regs);
726 dump_mc_ccsr_regs(mc_ccsr_regs);
729 * Tell MC what is the address range of the DRAM block assigned to it:
731 reg_mcfbalr = (u32)mc_ram_addr |
732 (mc_ram_num_256mb_blocks - 1);
733 out_le32(&mc_ccsr_regs->reg_mcfbalr, reg_mcfbalr);
734 out_le32(&mc_ccsr_regs->reg_mcfbahr,
735 (u32)(mc_ram_addr >> 32));
736 out_le32(&mc_ccsr_regs->reg_mcfapr, FSL_BYPASS_AMQ);
739 * Tell the MC that we want delayed DPL deployment.
741 out_le32(&mc_ccsr_regs->reg_gsr, 0xDD00);
743 printf("\nfsl-mc: Booting Management Complex ... ");
746 * Deassert reset and release MC core 0 to run
748 out_le32(&mc_ccsr_regs->reg_gcr1, GCR1_P1_DE_RST | GCR1_M_ALL_DE_RST);
749 error = wait_for_mc(true, ®_gsr);
754 * TODO: need to obtain the portal_id for the root container from the
760 * Initialize the global default MC portal
761 * And check that the MC firmware is responding portal commands:
763 root_mc_io = (struct fsl_mc_io *)calloc(sizeof(struct fsl_mc_io), 1);
765 printf(" No memory: calloc() failed\n");
769 root_mc_io->mmio_regs = SOC_MC_PORTAL_ADDR(portal_id);
770 debug("Checking access to MC portal of root DPRC container (portal_id %d, portal physical addr %p)\n",
771 portal_id, root_mc_io->mmio_regs);
773 error = mc_get_version(root_mc_io, MC_CMD_NO_FLAGS, &mc_ver_info);
775 printf("fsl-mc: ERROR: Firmware version check failed (error: %d)\n",
780 printf("fsl-mc: Management Complex booted (version: %d.%d.%d, boot status: %#x)\n",
781 mc_ver_info.major, mc_ver_info.minor, mc_ver_info.revision,
782 reg_gsr & GSR_FS_MASK);
786 mc_boot_status = error;
793 int mc_apply_dpl(u64 mc_dpl_addr)
795 struct mc_ccsr_registers __iomem *mc_ccsr_regs = MC_CCSR_BASE_ADDR;
798 u64 mc_ram_addr = mc_get_dram_addr();
799 size_t mc_ram_size = mc_get_dram_block_size();
804 error = load_mc_dpl(mc_ram_addr, mc_ram_size, mc_dpl_addr);
809 * Tell the MC to deploy the DPL:
811 out_le32(&mc_ccsr_regs->reg_gsr, 0x0);
812 printf("fsl-mc: Deploying data path layout ... ");
813 error = wait_for_mc(false, ®_gsr);
821 int get_mc_boot_status(void)
823 return mc_boot_status;
826 #ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
827 int get_aiop_apply_status(void)
829 return mc_aiop_applied;
833 int get_dpl_apply_status(void)
835 return mc_dpl_applied;
839 * Return the MC address of private DRAM block.
840 * As per MC design document, MC initial base address
841 * should be least significant 512MB address of MC private
842 * memory, i.e. address should point to end address masked
843 * with 512MB offset in private DRAM block.
845 u64 mc_get_dram_addr(void)
847 size_t mc_ram_size = mc_get_dram_block_size();
849 if (!mc_memset_resv_ram || (get_mc_boot_status() < 0)) {
850 mc_memset_resv_ram = 1;
851 memset((void *)gd->arch.resv_ram, 0, mc_ram_size);
854 return (gd->arch.resv_ram + mc_ram_size - 1) &
855 MC_RAM_BASE_ADDR_ALIGNMENT_MASK;
859 * Return the actual size of the MC private DRAM block.
861 unsigned long mc_get_dram_block_size(void)
863 unsigned long dram_block_size = CONFIG_SYS_LS_MC_DRAM_BLOCK_MIN_SIZE;
865 char *dram_block_size_env_var = env_get(MC_MEM_SIZE_ENV_VAR);
867 if (dram_block_size_env_var) {
868 dram_block_size = simple_strtoul(dram_block_size_env_var, NULL,
871 if (dram_block_size < CONFIG_SYS_LS_MC_DRAM_BLOCK_MIN_SIZE) {
872 printf("fsl-mc: WARNING: Invalid value for \'"
874 "\' environment variable: %lu\n",
877 dram_block_size = CONFIG_SYS_LS_MC_DRAM_BLOCK_MIN_SIZE;
881 return dram_block_size;
884 int fsl_mc_ldpaa_init(bd_t *bis)
888 for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++)
889 if ((wriop_is_enabled_dpmac(i) == 1) &&
890 (wriop_get_phy_address(i) != -1))
891 ldpaa_eth_init(i, wriop_get_enet_if(i));
895 static int dprc_version_check(struct fsl_mc_io *mc_io, uint16_t handle)
898 uint16_t major_ver, minor_ver;
900 error = dprc_get_api_version(mc_io, 0,
904 printf("dprc_get_api_version() failed: %d\n", error);
908 if (major_ver < DPRC_VER_MAJOR || (major_ver == DPRC_VER_MAJOR &&
909 minor_ver < DPRC_VER_MINOR)) {
910 printf("DPRC version mismatch found %u.%u,",
911 major_ver, minor_ver);
912 printf("supported version is %u.%u\n",
913 DPRC_VER_MAJOR, DPRC_VER_MINOR);
919 static int dpio_init(void)
921 struct qbman_swp_desc p_des;
922 struct dpio_attr attr;
923 struct dpio_cfg dpio_cfg;
925 uint16_t major_ver, minor_ver;
927 dflt_dpio = (struct fsl_dpio_obj *)calloc(
928 sizeof(struct fsl_dpio_obj), 1);
930 printf("No memory: calloc() failed\n");
934 dpio_cfg.channel_mode = DPIO_LOCAL_CHANNEL;
935 dpio_cfg.num_priorities = 8;
937 err = dpio_create(dflt_mc_io,
941 &dflt_dpio->dpio_id);
943 printf("dpio_create() failed: %d\n", err);
948 err = dpio_get_api_version(dflt_mc_io, 0,
952 printf("dpio_get_api_version() failed: %d\n", err);
953 goto err_get_api_ver;
956 if (major_ver < DPIO_VER_MAJOR || (major_ver == DPIO_VER_MAJOR &&
957 minor_ver < DPIO_VER_MINOR)) {
958 printf("DPRC version mismatch found %u.%u,",
963 err = dpio_open(dflt_mc_io,
966 &dflt_dpio->dpio_handle);
968 printf("dpio_open() failed\n");
972 memset(&attr, 0, sizeof(struct dpio_attr));
973 err = dpio_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS,
974 dflt_dpio->dpio_handle, &attr);
976 printf("dpio_get_attributes() failed: %d\n", err);
980 if (dflt_dpio->dpio_id != attr.id) {
981 printf("dnpi object id and attribute id are not same\n");
982 goto err_attr_not_same;
986 printf("Init: DPIO id=0x%d\n", dflt_dpio->dpio_id);
988 err = dpio_enable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
990 printf("dpio_enable() failed %d\n", err);
993 debug("ce_offset=0x%llx, ci_offset=0x%llx, portalid=%d, prios=%d\n",
994 attr.qbman_portal_ce_offset,
995 attr.qbman_portal_ci_offset,
996 attr.qbman_portal_id,
997 attr.num_priorities);
999 p_des.cena_bar = (void *)(SOC_QBMAN_PORTALS_BASE_ADDR
1000 + attr.qbman_portal_ce_offset);
1001 p_des.cinh_bar = (void *)(SOC_QBMAN_PORTALS_BASE_ADDR
1002 + attr.qbman_portal_ci_offset);
1004 dflt_dpio->sw_portal = qbman_swp_init(&p_des);
1005 if (dflt_dpio->sw_portal == NULL) {
1006 printf("qbman_swp_init() failed\n");
1007 goto err_get_swp_init;
1012 dpio_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
1016 dpio_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
1019 dpio_destroy(dflt_mc_io,
1022 dflt_dpio->dpio_id);
1029 static int dpio_exit(void)
1033 err = dpio_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
1035 printf("dpio_disable() failed: %d\n", err);
1039 dpio_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle);
1041 printf("dpio_close() failed: %d\n", err);
1045 err = dpio_destroy(dflt_mc_io,
1048 dflt_dpio->dpio_id);
1050 printf("dpio_destroy() failed: %d\n", err);
1055 printf("Exit: DPIO id=0x%d\n", dflt_dpio->dpio_id);
1066 static int dprc_init(void)
1068 int err, child_portal_id, container_id;
1069 struct dprc_cfg cfg;
1070 uint64_t mc_portal_offset;
1072 /* Open root container */
1073 err = dprc_get_container_id(root_mc_io, MC_CMD_NO_FLAGS, &container_id);
1075 printf("dprc_get_container_id(): Root failed: %d\n", err);
1076 goto err_root_container_id;
1080 printf("Root container id = %d\n", container_id);
1082 err = dprc_open(root_mc_io, MC_CMD_NO_FLAGS, container_id,
1085 printf("dprc_open(): Root Container failed: %d\n", err);
1089 if (!root_dprc_handle) {
1090 printf("dprc_open(): Root Container Handle is not valid\n");
1094 err = dprc_version_check(root_mc_io, root_dprc_handle);
1096 printf("dprc_version_check() failed: %d\n", err);
1100 memset(&cfg, 0, sizeof(struct dprc_cfg));
1101 cfg.options = DPRC_CFG_OPT_TOPOLOGY_CHANGES_ALLOWED |
1102 DPRC_CFG_OPT_OBJ_CREATE_ALLOWED |
1103 DPRC_CFG_OPT_ALLOC_ALLOWED;
1104 cfg.icid = DPRC_GET_ICID_FROM_POOL;
1105 cfg.portal_id = DPRC_GET_PORTAL_ID_FROM_POOL;
1106 err = dprc_create_container(root_mc_io, MC_CMD_NO_FLAGS,
1112 printf("dprc_create_container() failed: %d\n", err);
1116 dflt_mc_io = (struct fsl_mc_io *)calloc(sizeof(struct fsl_mc_io), 1);
1119 printf(" No memory: calloc() failed\n");
1123 child_portal_id = MC_PORTAL_OFFSET_TO_PORTAL_ID(mc_portal_offset);
1124 dflt_mc_io->mmio_regs = SOC_MC_PORTAL_ADDR(child_portal_id);
1127 printf("MC portal of child DPRC container: %d, physical addr %p)\n",
1128 child_dprc_id, dflt_mc_io->mmio_regs);
1131 err = dprc_open(dflt_mc_io, MC_CMD_NO_FLAGS, child_dprc_id,
1134 printf("dprc_open(): Child container failed: %d\n", err);
1135 goto err_child_open;
1138 if (!dflt_dprc_handle) {
1139 printf("dprc_open(): Child container Handle is not valid\n");
1140 goto err_child_open;
1147 dprc_destroy_container(root_mc_io, MC_CMD_NO_FLAGS,
1148 root_dprc_handle, child_dprc_id);
1150 dprc_close(root_mc_io, MC_CMD_NO_FLAGS, root_dprc_handle);
1152 err_root_container_id:
1156 static int dprc_exit(void)
1160 err = dprc_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dprc_handle);
1162 printf("dprc_close(): Child failed: %d\n", err);
1166 err = dprc_destroy_container(root_mc_io, MC_CMD_NO_FLAGS,
1167 root_dprc_handle, child_dprc_id);
1169 printf("dprc_destroy_container() failed: %d\n", err);
1173 err = dprc_close(root_mc_io, MC_CMD_NO_FLAGS, root_dprc_handle);
1175 printf("dprc_close(): Root failed: %d\n", err);
1191 static int dpbp_init(void)
1194 struct dpbp_attr dpbp_attr;
1195 struct dpbp_cfg dpbp_cfg;
1196 uint16_t major_ver, minor_ver;
1198 dflt_dpbp = (struct fsl_dpbp_obj *)calloc(
1199 sizeof(struct fsl_dpbp_obj), 1);
1201 printf("No memory: calloc() failed\n");
1206 dpbp_cfg.options = 512;
1208 err = dpbp_create(dflt_mc_io,
1212 &dflt_dpbp->dpbp_id);
1216 printf("dpbp_create() failed: %d\n", err);
1220 err = dpbp_get_api_version(dflt_mc_io, 0,
1224 printf("dpbp_get_api_version() failed: %d\n", err);
1225 goto err_get_api_ver;
1228 if (major_ver < DPBP_VER_MAJOR || (major_ver == DPBP_VER_MAJOR &&
1229 minor_ver < DPBP_VER_MINOR)) {
1230 printf("DPBP version mismatch found %u.%u,",
1231 major_ver, minor_ver);
1232 printf("supported version is %u.%u\n",
1233 DPBP_VER_MAJOR, DPBP_VER_MINOR);
1236 err = dpbp_open(dflt_mc_io,
1239 &dflt_dpbp->dpbp_handle);
1241 printf("dpbp_open() failed\n");
1245 memset(&dpbp_attr, 0, sizeof(struct dpbp_attr));
1246 err = dpbp_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS,
1247 dflt_dpbp->dpbp_handle,
1250 printf("dpbp_get_attributes() failed: %d\n", err);
1254 if (dflt_dpbp->dpbp_id != dpbp_attr.id) {
1255 printf("dpbp object id and attribute id are not same\n");
1256 goto err_attr_not_same;
1260 printf("Init: DPBP id=0x%x\n", dflt_dpbp->dpbp_attr.id);
1263 err = dpbp_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
1265 printf("dpbp_close() failed: %d\n", err);
1273 dpbp_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle);
1274 dpbp_destroy(dflt_mc_io,
1277 dflt_dpbp->dpbp_id);
1287 static int dpbp_exit(void)
1291 err = dpbp_destroy(dflt_mc_io, dflt_dprc_handle, MC_CMD_NO_FLAGS,
1292 dflt_dpbp->dpbp_id);
1294 printf("dpbp_destroy() failed: %d\n", err);
1299 printf("Exit: DPBP id=0x%d\n", dflt_dpbp->dpbp_attr.id);
1310 static int dpni_init(void)
1313 uint8_t cfg_buf[256] = {0};
1314 struct dpni_cfg dpni_cfg;
1315 uint16_t major_ver, minor_ver;
1317 dflt_dpni = (struct fsl_dpni_obj *)calloc(
1318 sizeof(struct fsl_dpni_obj), 1);
1320 printf("No memory: calloc() failed\n");
1325 memset(&dpni_cfg, 0, sizeof(dpni_cfg));
1326 err = dpni_prepare_cfg(&dpni_cfg, &cfg_buf[0]);
1329 printf("dpni_prepare_cfg() failed: %d\n", err);
1330 goto err_prepare_cfg;
1333 err = dpni_create(dflt_mc_io,
1337 &dflt_dpni->dpni_id);
1340 printf("dpni create() failed: %d\n", err);
1344 err = dpni_get_api_version(dflt_mc_io, 0,
1348 printf("dpni_get_api_version() failed: %d\n", err);
1349 goto err_get_version;
1352 if (major_ver < DPNI_VER_MAJOR || (major_ver == DPNI_VER_MAJOR &&
1353 minor_ver < DPNI_VER_MINOR)) {
1354 printf("DPNI version mismatch found %u.%u,",
1355 major_ver, minor_ver);
1356 printf("supported version is %u.%u\n",
1357 DPNI_VER_MAJOR, DPNI_VER_MINOR);
1360 err = dpni_open(dflt_mc_io,
1363 &dflt_dpni->dpni_handle);
1365 printf("dpni_open() failed\n");
1370 printf("Init: DPNI id=0x%d\n", dflt_dpni->dpni_id);
1372 err = dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
1374 printf("dpni_close() failed: %d\n", err);
1381 dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle);
1384 dpni_destroy(dflt_mc_io,
1387 dflt_dpni->dpni_id);
1395 static int dpni_exit(void)
1399 err = dpni_destroy(dflt_mc_io, dflt_dprc_handle, MC_CMD_NO_FLAGS,
1400 dflt_dpni->dpni_id);
1402 printf("dpni_destroy() failed: %d\n", err);
1407 printf("Exit: DPNI id=0x%d\n", dflt_dpni->dpni_id);
1418 static int mc_init_object(void)
1424 printf("dprc_init() failed: %d\n", err);
1430 printf("dpbp_init() failed: %d\n", err);
1436 printf("dpio_init() failed: %d\n", err);
1442 printf("dpni_init() failed: %d\n", err);
1451 int fsl_mc_ldpaa_exit(bd_t *bd)
1454 bool is_dpl_apply_status = false;
1455 bool mc_boot_status = false;
1457 if (bd && mc_lazy_dpl_addr && !fsl_mc_ldpaa_exit(NULL)) {
1458 err = mc_apply_dpl(mc_lazy_dpl_addr);
1460 fdt_fixup_board_enet(working_fdt);
1461 mc_lazy_dpl_addr = 0;
1464 if (!get_mc_boot_status())
1465 mc_boot_status = true;
1467 /* MC is not loaded intentionally, So return success. */
1468 if (bd && !mc_boot_status)
1471 /* If DPL is deployed, set is_dpl_apply_status as TRUE. */
1472 if (!get_dpl_apply_status())
1473 is_dpl_apply_status = true;
1476 * For case MC is loaded but DPL is not deployed, return success and
1477 * print message on console. Else FDT fix-up code execution hanged.
1479 if (bd && mc_boot_status && !is_dpl_apply_status) {
1480 printf("fsl-mc: DPL not deployed, DPAA2 ethernet not work\n");
1481 goto mc_obj_cleanup;
1484 if (bd && mc_boot_status && is_dpl_apply_status)
1490 printf("dpbp_exit() failed: %d\n", err);
1496 printf("dpio_exit() failed: %d\n", err);
1502 printf("dpni_exit() failed: %d\n", err);
1508 printf("dprc_exit() failed: %d\n", err);
1517 static int do_fsl_mc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1523 switch (argv[1][0]) {
1526 u64 mc_fw_addr, mc_dpc_addr;
1527 #ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
1531 sub_cmd = argv[2][0];
1538 if (get_mc_boot_status() == 0) {
1539 printf("fsl-mc: MC is already booted");
1543 mc_fw_addr = simple_strtoull(argv[3], NULL, 16);
1544 mc_dpc_addr = simple_strtoull(argv[4], NULL,
1547 if (!mc_init(mc_fw_addr, mc_dpc_addr))
1548 err = mc_init_object();
1551 #ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET
1555 if (get_aiop_apply_status() == 0) {
1556 printf("fsl-mc: AIOP FW is already");
1557 printf(" applied\n");
1561 aiop_fw_addr = simple_strtoull(argv[3], NULL,
1564 /* if SoC doesn't have AIOP, err = -ENODEV */
1565 err = load_mc_aiop_img(aiop_fw_addr);
1567 printf("fsl-mc: AIOP FW applied\n");
1571 printf("Invalid option: %s\n", argv[2]);
1586 if (get_dpl_apply_status() == 0) {
1587 printf("fsl-mc: DPL already applied\n");
1591 mc_dpl_addr = simple_strtoull(argv[3], NULL,
1594 if (get_mc_boot_status() != 0) {
1595 printf("fsl-mc: Deploying data path layout ..");
1596 printf("ERROR (MC is not booted)\n");
1600 if (argv[1][0] == 'l') {
1602 * We will do the actual dpaa exit and dpl apply
1603 * later from announce_and_cleanup().
1605 mc_lazy_dpl_addr = mc_dpl_addr;
1607 /* The user wants it applied now */
1608 if (!fsl_mc_ldpaa_exit(NULL))
1609 err = mc_apply_dpl(mc_dpl_addr);
1614 printf("Invalid option: %s\n", argv[1]);
1620 return CMD_RET_USAGE;
1624 fsl_mc, CONFIG_SYS_MAXARGS, 1, do_fsl_mc,
1625 "DPAA2 command to manage Management Complex (MC)",
1626 "start mc [FW_addr] [DPC_addr] - Start Management Complex\n"
1627 "fsl_mc apply DPL [DPL_addr] - Apply DPL file\n"
1628 "fsl_mc lazyapply DPL [DPL_addr] - Apply DPL file on exit\n"
1629 "fsl_mc start aiop [FW_addr] - Start AIOP\n"
1632 void mc_env_boot(void)
1634 #if defined(CONFIG_FSL_MC_ENET)
1635 char *mc_boot_env_var;
1636 /* The MC may only be initialized in the reset PHY function
1637 * because otherwise U-Boot has not yet set up all the MAC
1638 * address info properly. Without MAC addresses, the MC code
1639 * can not properly initialize the DPC.
1641 mc_boot_env_var = env_get(MC_BOOT_ENV_VAR);
1642 if (mc_boot_env_var)
1643 run_command_list(mc_boot_env_var, -1, 0);
1644 #endif /* CONFIG_FSL_MC_ENET */