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