J. German Rivera | b940ca6 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 Freescale Semiconductor |
| 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0+ |
| 5 | */ |
Stuart Yoder | 21c6987 | 2015-07-02 11:29:03 +0530 | [diff] [blame] | 6 | #include <common.h> |
J. German Rivera | b940ca6 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 7 | #include <errno.h> |
| 8 | #include <asm/io.h> |
Stuart Yoder | 21c6987 | 2015-07-02 11:29:03 +0530 | [diff] [blame] | 9 | #include <libfdt.h> |
| 10 | #include <fdt_support.h> |
J. German Rivera | 7b3bd9a | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 11 | #include <fsl-mc/fsl_mc.h> |
| 12 | #include <fsl-mc/fsl_mc_sys.h> |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 13 | #include <fsl-mc/fsl_mc_private.h> |
J. German Rivera | 7b3bd9a | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 14 | #include <fsl-mc/fsl_dpmng.h> |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 15 | #include <fsl-mc/fsl_dprc.h> |
| 16 | #include <fsl-mc/fsl_dpio.h> |
Prabhakar Kushwaha | fb4a87a | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 17 | #include <fsl-mc/fsl_dpni.h> |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 18 | #include <fsl-mc/fsl_qbman_portal.h> |
Prabhakar Kushwaha | fb4a87a | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 19 | #include <fsl-mc/ldpaa_wriop.h> |
J. German Rivera | b940ca6 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 20 | |
J. German Rivera | 125e2bc | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 21 | #define MC_RAM_BASE_ADDR_ALIGNMENT (512UL * 1024 * 1024) |
| 22 | #define MC_RAM_BASE_ADDR_ALIGNMENT_MASK (~(MC_RAM_BASE_ADDR_ALIGNMENT - 1)) |
| 23 | #define MC_RAM_SIZE_ALIGNMENT (256UL * 1024 * 1024) |
| 24 | |
| 25 | #define MC_MEM_SIZE_ENV_VAR "mcmemsize" |
| 26 | #define MC_BOOT_TIMEOUT_ENV_VAR "mcboottimeout" |
| 27 | |
J. German Rivera | b940ca6 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 28 | DECLARE_GLOBAL_DATA_PTR; |
Prabhakar Kushwaha | fb4a87a | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 29 | static int mc_boot_status = -1; |
| 30 | static int mc_dpl_applied = -1; |
| 31 | #ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET |
| 32 | static int mc_aiop_applied = -1; |
| 33 | #endif |
Prabhakar Kushwaha | 1730a17 | 2015-11-04 12:25:59 +0530 | [diff] [blame^] | 34 | struct fsl_mc_io *root_mc_io = NULL; |
| 35 | struct fsl_mc_io *dflt_mc_io = NULL; /* child container */ |
| 36 | uint16_t root_dprc_handle = 0; |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 37 | uint16_t dflt_dprc_handle = 0; |
Prabhakar Kushwaha | 1730a17 | 2015-11-04 12:25:59 +0530 | [diff] [blame^] | 38 | int child_dprc_id; |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 39 | struct fsl_dpbp_obj *dflt_dpbp = NULL; |
| 40 | struct fsl_dpio_obj *dflt_dpio = NULL; |
Prabhakar Kushwaha | 1730a17 | 2015-11-04 12:25:59 +0530 | [diff] [blame^] | 41 | struct fsl_dpni_obj *dflt_dpni = NULL; |
J. German Rivera | b940ca6 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 42 | |
J. German Rivera | 125e2bc | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 43 | #ifdef DEBUG |
| 44 | void dump_ram_words(const char *title, void *addr) |
| 45 | { |
| 46 | int i; |
| 47 | uint32_t *words = addr; |
| 48 | |
| 49 | printf("Dumping beginning of %s (%p):\n", title, addr); |
| 50 | for (i = 0; i < 16; i++) |
| 51 | printf("%#x ", words[i]); |
| 52 | |
| 53 | printf("\n"); |
| 54 | } |
| 55 | |
| 56 | void dump_mc_ccsr_regs(struct mc_ccsr_registers __iomem *mc_ccsr_regs) |
| 57 | { |
| 58 | printf("MC CCSR registers:\n" |
| 59 | "reg_gcr1 %#x\n" |
| 60 | "reg_gsr %#x\n" |
| 61 | "reg_sicbalr %#x\n" |
| 62 | "reg_sicbahr %#x\n" |
| 63 | "reg_sicapr %#x\n" |
| 64 | "reg_mcfbalr %#x\n" |
| 65 | "reg_mcfbahr %#x\n" |
| 66 | "reg_mcfapr %#x\n" |
| 67 | "reg_psr %#x\n", |
| 68 | mc_ccsr_regs->reg_gcr1, |
| 69 | mc_ccsr_regs->reg_gsr, |
| 70 | mc_ccsr_regs->reg_sicbalr, |
| 71 | mc_ccsr_regs->reg_sicbahr, |
| 72 | mc_ccsr_regs->reg_sicapr, |
| 73 | mc_ccsr_regs->reg_mcfbalr, |
| 74 | mc_ccsr_regs->reg_mcfbahr, |
| 75 | mc_ccsr_regs->reg_mcfapr, |
| 76 | mc_ccsr_regs->reg_psr); |
| 77 | } |
| 78 | #else |
| 79 | |
| 80 | #define dump_ram_words(title, addr) |
| 81 | #define dump_mc_ccsr_regs(mc_ccsr_regs) |
| 82 | |
| 83 | #endif /* DEBUG */ |
| 84 | |
| 85 | #ifndef CONFIG_SYS_LS_MC_FW_IN_DDR |
J. German Rivera | b940ca6 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 86 | /** |
| 87 | * Copying MC firmware or DPL image to DDR |
| 88 | */ |
| 89 | static int mc_copy_image(const char *title, |
J. German Rivera | 7b3bd9a | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 90 | u64 image_addr, u32 image_size, u64 mc_ram_addr) |
J. German Rivera | b940ca6 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 91 | { |
| 92 | debug("%s copied to address %p\n", title, (void *)mc_ram_addr); |
| 93 | memcpy((void *)mc_ram_addr, (void *)image_addr, image_size); |
J. German Rivera | 125e2bc | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 94 | flush_dcache_range(mc_ram_addr, mc_ram_addr + image_size); |
J. German Rivera | b940ca6 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 95 | return 0; |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * MC firmware FIT image parser checks if the image is in FIT |
| 100 | * format, verifies integrity of the image and calculates |
| 101 | * raw image address and size values. |
J. German Rivera | 7b3bd9a | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 102 | * Returns 0 on success and a negative errno on error. |
J. German Rivera | b940ca6 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 103 | * task fail. |
| 104 | **/ |
Prabhakar Kushwaha | fb4a87a | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 105 | int parse_mc_firmware_fit_image(u64 mc_fw_addr, |
| 106 | const void **raw_image_addr, |
J. German Rivera | b940ca6 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 107 | size_t *raw_image_size) |
| 108 | { |
| 109 | int format; |
| 110 | void *fit_hdr; |
| 111 | int node_offset; |
| 112 | const void *data; |
| 113 | size_t size; |
| 114 | const char *uname = "firmware"; |
| 115 | |
Prabhakar Kushwaha | fb4a87a | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 116 | fit_hdr = (void *)mc_fw_addr; |
J. German Rivera | b940ca6 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 117 | |
| 118 | /* Check if Image is in FIT format */ |
| 119 | format = genimg_get_format(fit_hdr); |
| 120 | |
| 121 | if (format != IMAGE_FORMAT_FIT) { |
Prabhakar Kushwaha | fb4a87a | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 122 | printf("fsl-mc: ERR: Bad firmware image (not a FIT image)\n"); |
J. German Rivera | 7b3bd9a | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 123 | return -EINVAL; |
J. German Rivera | b940ca6 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | if (!fit_check_format(fit_hdr)) { |
Prabhakar Kushwaha | fb4a87a | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 127 | printf("fsl-mc: ERR: Bad firmware image (bad FIT header)\n"); |
J. German Rivera | 7b3bd9a | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 128 | return -EINVAL; |
J. German Rivera | b940ca6 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | node_offset = fit_image_get_node(fit_hdr, uname); |
| 132 | |
| 133 | if (node_offset < 0) { |
Prabhakar Kushwaha | fb4a87a | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 134 | printf("fsl-mc: ERR: Bad firmware image (missing subimage)\n"); |
J. German Rivera | 7b3bd9a | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 135 | return -ENOENT; |
J. German Rivera | b940ca6 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | /* Verify MC firmware image */ |
| 139 | if (!(fit_image_verify(fit_hdr, node_offset))) { |
Prabhakar Kushwaha | fb4a87a | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 140 | printf("fsl-mc: ERR: Bad firmware image (bad CRC)\n"); |
J. German Rivera | 7b3bd9a | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 141 | return -EINVAL; |
J. German Rivera | b940ca6 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | /* Get address and size of raw image */ |
| 145 | fit_image_get_data(fit_hdr, node_offset, &data, &size); |
| 146 | |
| 147 | *raw_image_addr = data; |
| 148 | *raw_image_size = size; |
| 149 | |
| 150 | return 0; |
| 151 | } |
J. German Rivera | 125e2bc | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 152 | #endif |
| 153 | |
| 154 | /* |
| 155 | * Calculates the values to be used to specify the address range |
| 156 | * for the MC private DRAM block, in the MCFBALR/MCFBAHR registers. |
| 157 | * It returns the highest 512MB-aligned address within the given |
| 158 | * address range, in '*aligned_base_addr', and the number of 256 MiB |
| 159 | * blocks in it, in 'num_256mb_blocks'. |
| 160 | */ |
| 161 | static int calculate_mc_private_ram_params(u64 mc_private_ram_start_addr, |
| 162 | size_t mc_ram_size, |
| 163 | u64 *aligned_base_addr, |
| 164 | u8 *num_256mb_blocks) |
| 165 | { |
| 166 | u64 addr; |
| 167 | u16 num_blocks; |
| 168 | |
| 169 | if (mc_ram_size % MC_RAM_SIZE_ALIGNMENT != 0) { |
| 170 | printf("fsl-mc: ERROR: invalid MC private RAM size (%lu)\n", |
| 171 | mc_ram_size); |
| 172 | return -EINVAL; |
| 173 | } |
| 174 | |
| 175 | num_blocks = mc_ram_size / MC_RAM_SIZE_ALIGNMENT; |
| 176 | if (num_blocks < 1 || num_blocks > 0xff) { |
| 177 | printf("fsl-mc: ERROR: invalid MC private RAM size (%lu)\n", |
| 178 | mc_ram_size); |
| 179 | return -EINVAL; |
| 180 | } |
| 181 | |
| 182 | addr = (mc_private_ram_start_addr + mc_ram_size - 1) & |
| 183 | MC_RAM_BASE_ADDR_ALIGNMENT_MASK; |
| 184 | |
| 185 | if (addr < mc_private_ram_start_addr) { |
| 186 | printf("fsl-mc: ERROR: bad start address %#llx\n", |
| 187 | mc_private_ram_start_addr); |
| 188 | return -EFAULT; |
| 189 | } |
| 190 | |
| 191 | *aligned_base_addr = addr; |
| 192 | *num_256mb_blocks = num_blocks; |
| 193 | return 0; |
| 194 | } |
| 195 | |
Stuart Yoder | 21c6987 | 2015-07-02 11:29:03 +0530 | [diff] [blame] | 196 | static int mc_fixup_dpc(u64 dpc_addr) |
| 197 | { |
| 198 | void *blob = (void *)dpc_addr; |
| 199 | int nodeoffset; |
| 200 | |
| 201 | /* delete any existing ICID pools */ |
| 202 | nodeoffset = fdt_path_offset(blob, "/resources/icid_pools"); |
| 203 | if (fdt_del_node(blob, nodeoffset) < 0) |
| 204 | printf("\nfsl-mc: WARNING: could not delete ICID pool\n"); |
| 205 | |
| 206 | /* add a new pool */ |
| 207 | nodeoffset = fdt_path_offset(blob, "/resources"); |
| 208 | if (nodeoffset < 0) { |
| 209 | printf("\nfsl-mc: ERROR: DPC is missing /resources\n"); |
| 210 | return -EINVAL; |
| 211 | } |
| 212 | nodeoffset = fdt_add_subnode(blob, nodeoffset, "icid_pools"); |
| 213 | nodeoffset = fdt_add_subnode(blob, nodeoffset, "icid_pool@0"); |
| 214 | do_fixup_by_path_u32(blob, "/resources/icid_pools/icid_pool@0", |
| 215 | "base_icid", FSL_DPAA2_STREAM_ID_START, 1); |
| 216 | do_fixup_by_path_u32(blob, "/resources/icid_pools/icid_pool@0", |
| 217 | "num", |
| 218 | FSL_DPAA2_STREAM_ID_END - |
| 219 | FSL_DPAA2_STREAM_ID_START + 1, 1); |
| 220 | |
| 221 | flush_dcache_range(dpc_addr, dpc_addr + fdt_totalsize(blob)); |
| 222 | |
| 223 | return 0; |
| 224 | } |
| 225 | |
Prabhakar Kushwaha | fb4a87a | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 226 | static int load_mc_dpc(u64 mc_ram_addr, size_t mc_ram_size, u64 mc_dpc_addr) |
J. German Rivera | 125e2bc | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 227 | { |
| 228 | u64 mc_dpc_offset; |
| 229 | #ifndef CONFIG_SYS_LS_MC_DPC_IN_DDR |
| 230 | int error; |
| 231 | void *dpc_fdt_hdr; |
| 232 | int dpc_size; |
| 233 | #endif |
| 234 | |
| 235 | #ifdef CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET |
| 236 | BUILD_BUG_ON((CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET & 0x3) != 0 || |
| 237 | CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET > 0xffffffff); |
| 238 | |
| 239 | mc_dpc_offset = CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET; |
| 240 | #else |
| 241 | #error "CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET not defined" |
| 242 | #endif |
| 243 | |
| 244 | /* |
| 245 | * Load the MC DPC blob in the MC private DRAM block: |
| 246 | */ |
| 247 | #ifdef CONFIG_SYS_LS_MC_DPC_IN_DDR |
| 248 | printf("MC DPC is preloaded to %#llx\n", mc_ram_addr + mc_dpc_offset); |
| 249 | #else |
| 250 | /* |
| 251 | * Get address and size of the DPC blob stored in flash: |
| 252 | */ |
Prabhakar Kushwaha | fb4a87a | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 253 | dpc_fdt_hdr = (void *)mc_dpc_addr; |
J. German Rivera | 125e2bc | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 254 | |
| 255 | error = fdt_check_header(dpc_fdt_hdr); |
| 256 | if (error != 0) { |
| 257 | /* |
| 258 | * Don't return with error here, since the MC firmware can |
| 259 | * still boot without a DPC |
| 260 | */ |
J. German Rivera | cc088c3 | 2015-07-02 11:28:56 +0530 | [diff] [blame] | 261 | printf("\nfsl-mc: WARNING: No DPC image found"); |
J. German Rivera | 125e2bc | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 262 | return 0; |
| 263 | } |
| 264 | |
| 265 | dpc_size = fdt_totalsize(dpc_fdt_hdr); |
| 266 | if (dpc_size > CONFIG_SYS_LS_MC_DPC_MAX_LENGTH) { |
J. German Rivera | cc088c3 | 2015-07-02 11:28:56 +0530 | [diff] [blame] | 267 | printf("\nfsl-mc: ERROR: Bad DPC image (too large: %d)\n", |
J. German Rivera | 125e2bc | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 268 | dpc_size); |
| 269 | return -EINVAL; |
| 270 | } |
| 271 | |
| 272 | mc_copy_image("MC DPC blob", |
| 273 | (u64)dpc_fdt_hdr, dpc_size, mc_ram_addr + mc_dpc_offset); |
| 274 | #endif /* not defined CONFIG_SYS_LS_MC_DPC_IN_DDR */ |
| 275 | |
Stuart Yoder | 21c6987 | 2015-07-02 11:29:03 +0530 | [diff] [blame] | 276 | if (mc_fixup_dpc(mc_ram_addr + mc_dpc_offset)) |
| 277 | return -EINVAL; |
| 278 | |
J. German Rivera | 125e2bc | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 279 | dump_ram_words("DPC", (void *)(mc_ram_addr + mc_dpc_offset)); |
| 280 | return 0; |
| 281 | } |
| 282 | |
Prabhakar Kushwaha | fb4a87a | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 283 | static int load_mc_dpl(u64 mc_ram_addr, size_t mc_ram_size, u64 mc_dpl_addr) |
J. German Rivera | 125e2bc | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 284 | { |
| 285 | u64 mc_dpl_offset; |
| 286 | #ifndef CONFIG_SYS_LS_MC_DPL_IN_DDR |
| 287 | int error; |
| 288 | void *dpl_fdt_hdr; |
| 289 | int dpl_size; |
| 290 | #endif |
| 291 | |
| 292 | #ifdef CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET |
| 293 | BUILD_BUG_ON((CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET & 0x3) != 0 || |
| 294 | CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET > 0xffffffff); |
| 295 | |
| 296 | mc_dpl_offset = CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET; |
| 297 | #else |
| 298 | #error "CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET not defined" |
| 299 | #endif |
| 300 | |
| 301 | /* |
| 302 | * Load the MC DPL blob in the MC private DRAM block: |
| 303 | */ |
| 304 | #ifdef CONFIG_SYS_LS_MC_DPL_IN_DDR |
| 305 | printf("MC DPL is preloaded to %#llx\n", mc_ram_addr + mc_dpl_offset); |
| 306 | #else |
| 307 | /* |
| 308 | * Get address and size of the DPL blob stored in flash: |
| 309 | */ |
Prabhakar Kushwaha | fb4a87a | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 310 | dpl_fdt_hdr = (void *)mc_dpl_addr; |
J. German Rivera | 125e2bc | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 311 | |
| 312 | error = fdt_check_header(dpl_fdt_hdr); |
| 313 | if (error != 0) { |
J. German Rivera | cc088c3 | 2015-07-02 11:28:56 +0530 | [diff] [blame] | 314 | printf("\nfsl-mc: ERROR: Bad DPL image (bad header)\n"); |
J. German Rivera | 125e2bc | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 315 | return error; |
| 316 | } |
| 317 | |
| 318 | dpl_size = fdt_totalsize(dpl_fdt_hdr); |
| 319 | if (dpl_size > CONFIG_SYS_LS_MC_DPL_MAX_LENGTH) { |
J. German Rivera | cc088c3 | 2015-07-02 11:28:56 +0530 | [diff] [blame] | 320 | printf("\nfsl-mc: ERROR: Bad DPL image (too large: %d)\n", |
J. German Rivera | 125e2bc | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 321 | dpl_size); |
| 322 | return -EINVAL; |
| 323 | } |
| 324 | |
| 325 | mc_copy_image("MC DPL blob", |
| 326 | (u64)dpl_fdt_hdr, dpl_size, mc_ram_addr + mc_dpl_offset); |
| 327 | #endif /* not defined CONFIG_SYS_LS_MC_DPL_IN_DDR */ |
| 328 | |
| 329 | dump_ram_words("DPL", (void *)(mc_ram_addr + mc_dpl_offset)); |
| 330 | return 0; |
| 331 | } |
| 332 | |
| 333 | /** |
| 334 | * Return the MC boot timeout value in milliseconds |
| 335 | */ |
| 336 | static unsigned long get_mc_boot_timeout_ms(void) |
| 337 | { |
| 338 | unsigned long timeout_ms = CONFIG_SYS_LS_MC_BOOT_TIMEOUT_MS; |
| 339 | |
| 340 | char *timeout_ms_env_var = getenv(MC_BOOT_TIMEOUT_ENV_VAR); |
| 341 | |
| 342 | if (timeout_ms_env_var) { |
| 343 | timeout_ms = simple_strtoul(timeout_ms_env_var, NULL, 10); |
| 344 | if (timeout_ms == 0) { |
| 345 | printf("fsl-mc: WARNING: Invalid value for \'" |
| 346 | MC_BOOT_TIMEOUT_ENV_VAR |
| 347 | "\' environment variable: %lu\n", |
| 348 | timeout_ms); |
| 349 | |
| 350 | timeout_ms = CONFIG_SYS_LS_MC_BOOT_TIMEOUT_MS; |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | return timeout_ms; |
| 355 | } |
| 356 | |
Prabhakar Kushwaha | fb4a87a | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 357 | #ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET |
| 358 | static int load_mc_aiop_img(u64 aiop_fw_addr) |
J. German Rivera | c1000c1 | 2015-07-02 11:28:58 +0530 | [diff] [blame] | 359 | { |
Prabhakar Kushwaha | fb4a87a | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 360 | u64 mc_ram_addr = mc_get_dram_addr(); |
| 361 | #ifndef CONFIG_SYS_LS_MC_DPC_IN_DDR |
J. German Rivera | c1000c1 | 2015-07-02 11:28:58 +0530 | [diff] [blame] | 362 | void *aiop_img; |
Prabhakar Kushwaha | fb4a87a | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 363 | #endif |
J. German Rivera | c1000c1 | 2015-07-02 11:28:58 +0530 | [diff] [blame] | 364 | |
| 365 | /* |
| 366 | * Load the MC AIOP image in the MC private DRAM block: |
| 367 | */ |
| 368 | |
Prabhakar Kushwaha | fb4a87a | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 369 | #ifdef CONFIG_SYS_LS_MC_DPC_IN_DDR |
| 370 | printf("MC AIOP is preloaded to %#llx\n", mc_ram_addr + |
| 371 | CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET); |
| 372 | #else |
| 373 | aiop_img = (void *)aiop_fw_addr; |
J. German Rivera | c1000c1 | 2015-07-02 11:28:58 +0530 | [diff] [blame] | 374 | mc_copy_image("MC AIOP image", |
| 375 | (u64)aiop_img, CONFIG_SYS_LS_MC_AIOP_IMG_MAX_LENGTH, |
| 376 | mc_ram_addr + CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET); |
Prabhakar Kushwaha | fb4a87a | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 377 | #endif |
| 378 | mc_aiop_applied = 0; |
J. German Rivera | c1000c1 | 2015-07-02 11:28:58 +0530 | [diff] [blame] | 379 | |
| 380 | return 0; |
| 381 | } |
| 382 | #endif |
Prabhakar Kushwaha | fb4a87a | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 383 | |
J. German Rivera | 125e2bc | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 384 | static int wait_for_mc(bool booting_mc, u32 *final_reg_gsr) |
| 385 | { |
| 386 | u32 reg_gsr; |
| 387 | u32 mc_fw_boot_status; |
| 388 | unsigned long timeout_ms = get_mc_boot_timeout_ms(); |
| 389 | struct mc_ccsr_registers __iomem *mc_ccsr_regs = MC_CCSR_BASE_ADDR; |
| 390 | |
| 391 | dmb(); |
J. German Rivera | 125e2bc | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 392 | assert(timeout_ms > 0); |
| 393 | for (;;) { |
| 394 | udelay(1000); /* throttle polling */ |
| 395 | reg_gsr = in_le32(&mc_ccsr_regs->reg_gsr); |
| 396 | mc_fw_boot_status = (reg_gsr & GSR_FS_MASK); |
| 397 | if (mc_fw_boot_status & 0x1) |
| 398 | break; |
| 399 | |
| 400 | timeout_ms--; |
| 401 | if (timeout_ms == 0) |
| 402 | break; |
| 403 | } |
| 404 | |
| 405 | if (timeout_ms == 0) { |
J. German Rivera | cc088c3 | 2015-07-02 11:28:56 +0530 | [diff] [blame] | 406 | printf("ERROR: timeout\n"); |
J. German Rivera | 125e2bc | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 407 | |
| 408 | /* TODO: Get an error status from an MC CCSR register */ |
| 409 | return -ETIMEDOUT; |
| 410 | } |
| 411 | |
| 412 | if (mc_fw_boot_status != 0x1) { |
| 413 | /* |
| 414 | * TODO: Identify critical errors from the GSR register's FS |
| 415 | * field and for those errors, set error to -ENODEV or other |
| 416 | * appropriate errno, so that the status property is set to |
| 417 | * failure in the fsl,dprc device tree node. |
| 418 | */ |
J. German Rivera | cc088c3 | 2015-07-02 11:28:56 +0530 | [diff] [blame] | 419 | printf("WARNING: Firmware returned an error (GSR: %#x)\n", |
| 420 | reg_gsr); |
| 421 | } else { |
| 422 | printf("SUCCESS\n"); |
J. German Rivera | 125e2bc | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 423 | } |
| 424 | |
J. German Rivera | cc088c3 | 2015-07-02 11:28:56 +0530 | [diff] [blame] | 425 | |
J. German Rivera | 125e2bc | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 426 | *final_reg_gsr = reg_gsr; |
| 427 | return 0; |
| 428 | } |
J. German Rivera | b940ca6 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 429 | |
Prabhakar Kushwaha | fb4a87a | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 430 | int mc_init(u64 mc_fw_addr, u64 mc_dpc_addr) |
J. German Rivera | b940ca6 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 431 | { |
| 432 | int error = 0; |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 433 | int portal_id = 0; |
J. German Rivera | b940ca6 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 434 | struct mc_ccsr_registers __iomem *mc_ccsr_regs = MC_CCSR_BASE_ADDR; |
Prabhakar Kushwaha | fb4a87a | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 435 | u64 mc_ram_addr = mc_get_dram_addr(); |
J. German Rivera | b940ca6 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 436 | u32 reg_gsr; |
J. German Rivera | 125e2bc | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 437 | u32 reg_mcfbalr; |
| 438 | #ifndef CONFIG_SYS_LS_MC_FW_IN_DDR |
J. German Rivera | b940ca6 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 439 | const void *raw_image_addr; |
| 440 | size_t raw_image_size = 0; |
J. German Rivera | 125e2bc | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 441 | #endif |
J. German Rivera | 7b3bd9a | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 442 | struct mc_version mc_ver_info; |
J. German Rivera | 125e2bc | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 443 | u64 mc_ram_aligned_base_addr; |
| 444 | u8 mc_ram_num_256mb_blocks; |
| 445 | size_t mc_ram_size = mc_get_dram_block_size(); |
J. German Rivera | b940ca6 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 446 | |
J. German Rivera | b940ca6 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 447 | |
J. German Rivera | 125e2bc | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 448 | error = calculate_mc_private_ram_params(mc_ram_addr, |
| 449 | mc_ram_size, |
| 450 | &mc_ram_aligned_base_addr, |
| 451 | &mc_ram_num_256mb_blocks); |
| 452 | if (error != 0) |
| 453 | goto out; |
| 454 | |
J. German Rivera | b940ca6 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 455 | /* |
| 456 | * Management Complex cores should be held at reset out of POR. |
| 457 | * U-boot should be the first software to touch MC. To be safe, |
| 458 | * we reset all cores again by setting GCR1 to 0. It doesn't do |
| 459 | * anything if they are held at reset. After we setup the firmware |
| 460 | * we kick off MC by deasserting the reset bit for core 0, and |
| 461 | * deasserting the reset bits for Command Portal Managers. |
| 462 | * The stop bits are not touched here. They are used to stop the |
| 463 | * cores when they are active. Setting stop bits doesn't stop the |
| 464 | * cores from fetching instructions when they are released from |
| 465 | * reset. |
| 466 | */ |
| 467 | out_le32(&mc_ccsr_regs->reg_gcr1, 0); |
| 468 | dmb(); |
| 469 | |
J. German Rivera | 125e2bc | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 470 | #ifdef CONFIG_SYS_LS_MC_FW_IN_DDR |
| 471 | printf("MC firmware is preloaded to %#llx\n", mc_ram_addr); |
| 472 | #else |
Prabhakar Kushwaha | fb4a87a | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 473 | error = parse_mc_firmware_fit_image(mc_fw_addr, &raw_image_addr, |
| 474 | &raw_image_size); |
J. German Rivera | b940ca6 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 475 | if (error != 0) |
| 476 | goto out; |
| 477 | /* |
| 478 | * Load the MC FW at the beginning of the MC private DRAM block: |
| 479 | */ |
J. German Rivera | 7b3bd9a | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 480 | mc_copy_image("MC Firmware", |
| 481 | (u64)raw_image_addr, raw_image_size, mc_ram_addr); |
J. German Rivera | 7b3bd9a | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 482 | #endif |
J. German Rivera | 125e2bc | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 483 | dump_ram_words("firmware", (void *)mc_ram_addr); |
J. German Rivera | 7b3bd9a | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 484 | |
Prabhakar Kushwaha | fb4a87a | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 485 | error = load_mc_dpc(mc_ram_addr, mc_ram_size, mc_dpc_addr); |
J. German Rivera | 125e2bc | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 486 | if (error != 0) |
J. German Rivera | 7b3bd9a | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 487 | goto out; |
J. German Rivera | 7b3bd9a | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 488 | |
J. German Rivera | b940ca6 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 489 | debug("mc_ccsr_regs %p\n", mc_ccsr_regs); |
J. German Rivera | 125e2bc | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 490 | dump_mc_ccsr_regs(mc_ccsr_regs); |
J. German Rivera | b940ca6 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 491 | |
| 492 | /* |
J. German Rivera | 125e2bc | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 493 | * Tell MC what is the address range of the DRAM block assigned to it: |
J. German Rivera | b940ca6 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 494 | */ |
J. German Rivera | 125e2bc | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 495 | reg_mcfbalr = (u32)mc_ram_aligned_base_addr | |
| 496 | (mc_ram_num_256mb_blocks - 1); |
| 497 | out_le32(&mc_ccsr_regs->reg_mcfbalr, reg_mcfbalr); |
| 498 | out_le32(&mc_ccsr_regs->reg_mcfbahr, |
| 499 | (u32)(mc_ram_aligned_base_addr >> 32)); |
Stuart Yoder | 39da644 | 2015-07-02 11:29:02 +0530 | [diff] [blame] | 500 | out_le32(&mc_ccsr_regs->reg_mcfapr, FSL_BYPASS_AMQ); |
J. German Rivera | b940ca6 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 501 | |
| 502 | /* |
J. German Rivera | 125e2bc | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 503 | * Tell the MC that we want delayed DPL deployment. |
J. German Rivera | b940ca6 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 504 | */ |
J. German Rivera | 125e2bc | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 505 | out_le32(&mc_ccsr_regs->reg_gsr, 0xDD00); |
J. German Rivera | b940ca6 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 506 | |
J. German Rivera | cc088c3 | 2015-07-02 11:28:56 +0530 | [diff] [blame] | 507 | printf("\nfsl-mc: Booting Management Complex ... "); |
J. German Rivera | 7b3bd9a | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 508 | |
J. German Rivera | b940ca6 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 509 | /* |
| 510 | * Deassert reset and release MC core 0 to run |
| 511 | */ |
| 512 | out_le32(&mc_ccsr_regs->reg_gcr1, GCR1_P1_DE_RST | GCR1_M_ALL_DE_RST); |
J. German Rivera | 125e2bc | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 513 | error = wait_for_mc(true, ®_gsr); |
| 514 | if (error != 0) |
J. German Rivera | b940ca6 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 515 | goto out; |
J. German Rivera | b940ca6 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 516 | |
J. German Rivera | 7b3bd9a | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 517 | /* |
| 518 | * TODO: need to obtain the portal_id for the root container from the |
| 519 | * DPL |
| 520 | */ |
| 521 | portal_id = 0; |
| 522 | |
| 523 | /* |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 524 | * Initialize the global default MC portal |
| 525 | * And check that the MC firmware is responding portal commands: |
J. German Rivera | 7b3bd9a | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 526 | */ |
Prabhakar Kushwaha | 1730a17 | 2015-11-04 12:25:59 +0530 | [diff] [blame^] | 527 | root_mc_io = (struct fsl_mc_io *)malloc(sizeof(struct fsl_mc_io)); |
| 528 | if (!root_mc_io) { |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 529 | printf(" No memory: malloc() failed\n"); |
| 530 | return -ENOMEM; |
| 531 | } |
J. German Rivera | 7b3bd9a | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 532 | |
Prabhakar Kushwaha | 1730a17 | 2015-11-04 12:25:59 +0530 | [diff] [blame^] | 533 | root_mc_io->mmio_regs = SOC_MC_PORTAL_ADDR(portal_id); |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 534 | debug("Checking access to MC portal of root DPRC container (portal_id %d, portal physical addr %p)\n", |
Prabhakar Kushwaha | 1730a17 | 2015-11-04 12:25:59 +0530 | [diff] [blame^] | 535 | portal_id, root_mc_io->mmio_regs); |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 536 | |
Prabhakar Kushwaha | 1730a17 | 2015-11-04 12:25:59 +0530 | [diff] [blame^] | 537 | error = mc_get_version(root_mc_io, MC_CMD_NO_FLAGS, &mc_ver_info); |
J. German Rivera | 7b3bd9a | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 538 | if (error != 0) { |
| 539 | printf("fsl-mc: ERROR: Firmware version check failed (error: %d)\n", |
| 540 | error); |
| 541 | goto out; |
| 542 | } |
| 543 | |
Prabhakar Kushwaha | 2b7c4a1 | 2015-07-02 11:29:01 +0530 | [diff] [blame] | 544 | if (MC_VER_MAJOR != mc_ver_info.major) { |
J. German Rivera | 7b3bd9a | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 545 | printf("fsl-mc: ERROR: Firmware major version mismatch (found: %d, expected: %d)\n", |
| 546 | mc_ver_info.major, MC_VER_MAJOR); |
Prabhakar Kushwaha | 2b7c4a1 | 2015-07-02 11:29:01 +0530 | [diff] [blame] | 547 | printf("fsl-mc: Update the Management Complex firmware\n"); |
| 548 | |
| 549 | error = -ENODEV; |
| 550 | goto out; |
| 551 | } |
J. German Rivera | 7b3bd9a | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 552 | |
| 553 | if (MC_VER_MINOR != mc_ver_info.minor) |
| 554 | printf("fsl-mc: WARNING: Firmware minor version mismatch (found: %d, expected: %d)\n", |
| 555 | mc_ver_info.minor, MC_VER_MINOR); |
| 556 | |
| 557 | printf("fsl-mc: Management Complex booted (version: %d.%d.%d, boot status: %#x)\n", |
| 558 | mc_ver_info.major, mc_ver_info.minor, mc_ver_info.revision, |
J. German Rivera | 125e2bc | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 559 | reg_gsr & GSR_FS_MASK); |
| 560 | |
J. German Rivera | b940ca6 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 561 | out: |
| 562 | if (error != 0) |
Prabhakar Kushwaha | 2b7c4a1 | 2015-07-02 11:29:01 +0530 | [diff] [blame] | 563 | mc_boot_status = error; |
J. German Rivera | b940ca6 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 564 | else |
| 565 | mc_boot_status = 0; |
| 566 | |
| 567 | return error; |
| 568 | } |
| 569 | |
Prabhakar Kushwaha | fb4a87a | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 570 | int mc_apply_dpl(u64 mc_dpl_addr) |
| 571 | { |
| 572 | struct mc_ccsr_registers __iomem *mc_ccsr_regs = MC_CCSR_BASE_ADDR; |
| 573 | int error = 0; |
| 574 | u32 reg_gsr; |
| 575 | u64 mc_ram_addr = mc_get_dram_addr(); |
| 576 | size_t mc_ram_size = mc_get_dram_block_size(); |
| 577 | |
| 578 | error = load_mc_dpl(mc_ram_addr, mc_ram_size, mc_dpl_addr); |
| 579 | if (error != 0) |
| 580 | return error; |
| 581 | |
| 582 | /* |
| 583 | * Tell the MC to deploy the DPL: |
| 584 | */ |
| 585 | out_le32(&mc_ccsr_regs->reg_gsr, 0x0); |
| 586 | printf("fsl-mc: Deploying data path layout ... "); |
| 587 | error = wait_for_mc(false, ®_gsr); |
| 588 | |
| 589 | if (!error) |
| 590 | mc_dpl_applied = 0; |
| 591 | |
| 592 | return error; |
| 593 | } |
| 594 | |
J. German Rivera | b940ca6 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 595 | int get_mc_boot_status(void) |
| 596 | { |
| 597 | return mc_boot_status; |
| 598 | } |
| 599 | |
Prabhakar Kushwaha | fb4a87a | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 600 | #ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET |
| 601 | int get_aiop_apply_status(void) |
| 602 | { |
| 603 | return mc_aiop_applied; |
| 604 | } |
| 605 | #endif |
| 606 | |
| 607 | int get_dpl_apply_status(void) |
| 608 | { |
| 609 | return mc_dpl_applied; |
| 610 | } |
| 611 | |
| 612 | /** |
| 613 | * Return the MC address of private DRAM block. |
| 614 | */ |
| 615 | u64 mc_get_dram_addr(void) |
| 616 | { |
| 617 | u64 mc_ram_addr; |
| 618 | |
| 619 | /* |
| 620 | * The MC private DRAM block was already carved at the end of DRAM |
| 621 | * by board_init_f() using CONFIG_SYS_MEM_TOP_HIDE: |
| 622 | */ |
| 623 | if (gd->bd->bi_dram[1].start) { |
| 624 | mc_ram_addr = |
| 625 | gd->bd->bi_dram[1].start + gd->bd->bi_dram[1].size; |
| 626 | } else { |
| 627 | mc_ram_addr = |
| 628 | gd->bd->bi_dram[0].start + gd->bd->bi_dram[0].size; |
| 629 | } |
| 630 | |
| 631 | return mc_ram_addr; |
| 632 | } |
| 633 | |
J. German Rivera | b940ca6 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 634 | /** |
| 635 | * Return the actual size of the MC private DRAM block. |
J. German Rivera | b940ca6 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 636 | */ |
| 637 | unsigned long mc_get_dram_block_size(void) |
| 638 | { |
J. German Rivera | 125e2bc | 2015-03-20 19:28:18 -0700 | [diff] [blame] | 639 | unsigned long dram_block_size = CONFIG_SYS_LS_MC_DRAM_BLOCK_MIN_SIZE; |
| 640 | |
| 641 | char *dram_block_size_env_var = getenv(MC_MEM_SIZE_ENV_VAR); |
| 642 | |
| 643 | if (dram_block_size_env_var) { |
| 644 | dram_block_size = simple_strtoul(dram_block_size_env_var, NULL, |
| 645 | 10); |
| 646 | |
| 647 | if (dram_block_size < CONFIG_SYS_LS_MC_DRAM_BLOCK_MIN_SIZE) { |
| 648 | printf("fsl-mc: WARNING: Invalid value for \'" |
| 649 | MC_MEM_SIZE_ENV_VAR |
| 650 | "\' environment variable: %lu\n", |
| 651 | dram_block_size); |
| 652 | |
| 653 | dram_block_size = CONFIG_SYS_LS_MC_DRAM_BLOCK_MIN_SIZE; |
| 654 | } |
| 655 | } |
| 656 | |
| 657 | return dram_block_size; |
J. German Rivera | b940ca6 | 2014-06-23 15:15:55 -0700 | [diff] [blame] | 658 | } |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 659 | |
Prabhakar Kushwaha | 1730a17 | 2015-11-04 12:25:59 +0530 | [diff] [blame^] | 660 | int fsl_mc_ldpaa_init(bd_t *bis) |
| 661 | { |
| 662 | return 0; |
| 663 | } |
| 664 | |
| 665 | static int dpio_init(void) |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 666 | { |
| 667 | struct qbman_swp_desc p_des; |
| 668 | struct dpio_attr attr; |
Prabhakar Kushwaha | 1730a17 | 2015-11-04 12:25:59 +0530 | [diff] [blame^] | 669 | struct dpio_cfg dpio_cfg; |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 670 | int err = 0; |
| 671 | |
| 672 | dflt_dpio = (struct fsl_dpio_obj *)malloc(sizeof(struct fsl_dpio_obj)); |
| 673 | if (!dflt_dpio) { |
Prabhakar Kushwaha | 1730a17 | 2015-11-04 12:25:59 +0530 | [diff] [blame^] | 674 | printf("No memory: malloc() failed\n"); |
| 675 | err = -ENOMEM; |
| 676 | goto err_malloc; |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 677 | } |
| 678 | |
Prabhakar Kushwaha | 1730a17 | 2015-11-04 12:25:59 +0530 | [diff] [blame^] | 679 | dpio_cfg.channel_mode = DPIO_LOCAL_CHANNEL; |
| 680 | dpio_cfg.num_priorities = 8; |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 681 | |
Prabhakar Kushwaha | 1730a17 | 2015-11-04 12:25:59 +0530 | [diff] [blame^] | 682 | err = dpio_create(dflt_mc_io, MC_CMD_NO_FLAGS, &dpio_cfg, |
| 683 | &dflt_dpio->dpio_handle); |
| 684 | if (err < 0) { |
| 685 | printf("dpio_create() failed: %d\n", err); |
| 686 | err = -ENODEV; |
| 687 | goto err_create; |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 688 | } |
| 689 | |
Prabhakar Kushwaha | 1730a17 | 2015-11-04 12:25:59 +0530 | [diff] [blame^] | 690 | memset(&attr, 0, sizeof(struct dpio_attr)); |
Prabhakar Kushwaha | 87457d1 | 2015-07-07 15:40:06 +0530 | [diff] [blame] | 691 | err = dpio_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS, |
Prabhakar Kushwaha | 1730a17 | 2015-11-04 12:25:59 +0530 | [diff] [blame^] | 692 | dflt_dpio->dpio_handle, &attr); |
| 693 | if (err < 0) { |
| 694 | printf("dpio_get_attributes() failed: %d\n", err); |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 695 | goto err_get_attr; |
| 696 | } |
| 697 | |
Prabhakar Kushwaha | 1730a17 | 2015-11-04 12:25:59 +0530 | [diff] [blame^] | 698 | dflt_dpio->dpio_id = attr.id; |
| 699 | #ifdef DEBUG |
| 700 | printf("Init: DPIO id=0x%d\n", dflt_dpio->dpio_id); |
| 701 | #endif |
| 702 | |
| 703 | err = dpio_enable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle); |
| 704 | if (err < 0) { |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 705 | printf("dpio_enable() failed %d\n", err); |
| 706 | goto err_get_enable; |
| 707 | } |
Prabhakar Kushwaha | 1f1c25c | 2015-07-02 11:28:59 +0530 | [diff] [blame] | 708 | debug("ce_offset=0x%llx, ci_offset=0x%llx, portalid=%d, prios=%d\n", |
| 709 | attr.qbman_portal_ce_offset, |
| 710 | attr.qbman_portal_ci_offset, |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 711 | attr.qbman_portal_id, |
| 712 | attr.num_priorities); |
| 713 | |
Prabhakar Kushwaha | 1f1c25c | 2015-07-02 11:28:59 +0530 | [diff] [blame] | 714 | p_des.cena_bar = (void *)(SOC_QBMAN_PORTALS_BASE_ADDR |
| 715 | + attr.qbman_portal_ce_offset); |
| 716 | p_des.cinh_bar = (void *)(SOC_QBMAN_PORTALS_BASE_ADDR |
| 717 | + attr.qbman_portal_ci_offset); |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 718 | |
| 719 | dflt_dpio->sw_portal = qbman_swp_init(&p_des); |
| 720 | if (dflt_dpio->sw_portal == NULL) { |
| 721 | printf("qbman_swp_init() failed\n"); |
| 722 | goto err_get_swp_init; |
| 723 | } |
| 724 | return 0; |
| 725 | |
| 726 | err_get_swp_init: |
Prabhakar Kushwaha | 1730a17 | 2015-11-04 12:25:59 +0530 | [diff] [blame^] | 727 | dpio_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle); |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 728 | err_get_enable: |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 729 | free(dflt_dpio); |
Prabhakar Kushwaha | 1730a17 | 2015-11-04 12:25:59 +0530 | [diff] [blame^] | 730 | err_get_attr: |
| 731 | dpio_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle); |
| 732 | dpio_destroy(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle); |
| 733 | err_create: |
| 734 | err_malloc: |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 735 | return err; |
| 736 | } |
| 737 | |
Prabhakar Kushwaha | 1730a17 | 2015-11-04 12:25:59 +0530 | [diff] [blame^] | 738 | static int dpio_exit(void) |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 739 | { |
Prabhakar Kushwaha | 1730a17 | 2015-11-04 12:25:59 +0530 | [diff] [blame^] | 740 | int err; |
| 741 | |
| 742 | err = dpio_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle); |
| 743 | if (err < 0) { |
| 744 | printf("dpio_disable() failed: %d\n", err); |
| 745 | goto err; |
| 746 | } |
| 747 | |
| 748 | err = dpio_destroy(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio->dpio_handle); |
| 749 | if (err < 0) { |
| 750 | printf("dpio_destroy() failed: %d\n", err); |
| 751 | goto err; |
| 752 | } |
| 753 | |
| 754 | #ifdef DEBUG |
| 755 | printf("Exit: DPIO id=0x%d\n", dflt_dpio->dpio_id); |
| 756 | #endif |
| 757 | |
| 758 | if (dflt_dpio) |
| 759 | free(dflt_dpio); |
| 760 | |
| 761 | return 0; |
| 762 | err: |
| 763 | return err; |
| 764 | } |
| 765 | |
| 766 | static int dprc_init(void) |
| 767 | { |
| 768 | int err, child_portal_id, container_id; |
| 769 | struct dprc_cfg cfg; |
| 770 | uint64_t mc_portal_offset; |
| 771 | |
| 772 | /* Open root container */ |
| 773 | err = dprc_get_container_id(root_mc_io, MC_CMD_NO_FLAGS, &container_id); |
| 774 | if (err < 0) { |
| 775 | printf("dprc_get_container_id(): Root failed: %d\n", err); |
| 776 | goto err_root_container_id; |
| 777 | } |
| 778 | |
| 779 | #ifdef DEBUG |
| 780 | printf("Root container id = %d\n", container_id); |
| 781 | #endif |
| 782 | err = dprc_open(root_mc_io, MC_CMD_NO_FLAGS, container_id, |
| 783 | &root_dprc_handle); |
| 784 | if (err < 0) { |
| 785 | printf("dprc_open(): Root Container failed: %d\n", err); |
| 786 | goto err_root_open; |
| 787 | } |
| 788 | |
| 789 | if (!root_dprc_handle) { |
| 790 | printf("dprc_open(): Root Container Handle is not valid\n"); |
| 791 | goto err_root_open; |
| 792 | } |
| 793 | |
| 794 | cfg.options = DPRC_CFG_OPT_TOPOLOGY_CHANGES_ALLOWED | |
| 795 | DPRC_CFG_OPT_OBJ_CREATE_ALLOWED | |
| 796 | DPRC_CFG_OPT_ALLOC_ALLOWED; |
| 797 | cfg.icid = DPRC_GET_ICID_FROM_POOL; |
| 798 | cfg.portal_id = 250; |
| 799 | err = dprc_create_container(root_mc_io, MC_CMD_NO_FLAGS, |
| 800 | root_dprc_handle, |
| 801 | &cfg, |
| 802 | &child_dprc_id, |
| 803 | &mc_portal_offset); |
| 804 | if (err < 0) { |
| 805 | printf("dprc_create_container() failed: %d\n", err); |
| 806 | goto err_create; |
| 807 | } |
| 808 | |
| 809 | dflt_mc_io = (struct fsl_mc_io *)malloc(sizeof(struct fsl_mc_io)); |
| 810 | if (!dflt_mc_io) { |
| 811 | err = -ENOMEM; |
| 812 | printf(" No memory: malloc() failed\n"); |
| 813 | goto err_malloc; |
| 814 | } |
| 815 | |
| 816 | child_portal_id = MC_PORTAL_OFFSET_TO_PORTAL_ID(mc_portal_offset); |
| 817 | dflt_mc_io->mmio_regs = SOC_MC_PORTAL_ADDR(child_portal_id); |
| 818 | #ifdef DEBUG |
| 819 | printf("MC portal of child DPRC container: %d, physical addr %p)\n", |
| 820 | child_dprc_id, dflt_mc_io->mmio_regs); |
| 821 | #endif |
| 822 | |
| 823 | err = dprc_open(dflt_mc_io, MC_CMD_NO_FLAGS, child_dprc_id, |
| 824 | &dflt_dprc_handle); |
| 825 | if (err < 0) { |
| 826 | printf("dprc_open(): Child container failed: %d\n", err); |
| 827 | goto err_child_open; |
| 828 | } |
| 829 | |
| 830 | if (!dflt_dprc_handle) { |
| 831 | printf("dprc_open(): Child container Handle is not valid\n"); |
| 832 | goto err_child_open; |
| 833 | } |
| 834 | |
| 835 | return 0; |
| 836 | err_child_open: |
| 837 | free(dflt_mc_io); |
| 838 | err_malloc: |
| 839 | dprc_destroy_container(root_mc_io, MC_CMD_NO_FLAGS, |
| 840 | root_dprc_handle, child_dprc_id); |
| 841 | err_create: |
| 842 | dprc_close(root_mc_io, MC_CMD_NO_FLAGS, root_dprc_handle); |
| 843 | err_root_open: |
| 844 | err_root_container_id: |
| 845 | return err; |
| 846 | } |
| 847 | |
| 848 | static int dprc_exit(void) |
| 849 | { |
| 850 | int err; |
| 851 | |
| 852 | err = dprc_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dprc_handle); |
| 853 | if (err < 0) { |
| 854 | printf("dprc_close(): Child failed: %d\n", err); |
| 855 | goto err; |
| 856 | } |
| 857 | |
| 858 | err = dprc_destroy_container(root_mc_io, MC_CMD_NO_FLAGS, |
| 859 | root_dprc_handle, child_dprc_id); |
| 860 | if (err < 0) { |
| 861 | printf("dprc_destroy_container() failed: %d\n", err); |
| 862 | goto err; |
| 863 | } |
| 864 | |
| 865 | err = dprc_close(root_mc_io, MC_CMD_NO_FLAGS, root_dprc_handle); |
| 866 | if (err < 0) { |
| 867 | printf("dprc_close(): Root failed: %d\n", err); |
| 868 | goto err; |
| 869 | } |
| 870 | |
| 871 | if (dflt_mc_io) |
| 872 | free(dflt_mc_io); |
| 873 | |
| 874 | if (root_mc_io) |
| 875 | free(root_mc_io); |
| 876 | |
| 877 | return 0; |
| 878 | |
| 879 | err: |
| 880 | return err; |
| 881 | } |
| 882 | |
| 883 | static int dpbp_init(void) |
| 884 | { |
| 885 | int err; |
| 886 | struct dpbp_attr dpbp_attr; |
| 887 | struct dpbp_cfg dpbp_cfg; |
| 888 | |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 889 | dflt_dpbp = (struct fsl_dpbp_obj *)malloc(sizeof(struct fsl_dpbp_obj)); |
| 890 | if (!dflt_dpbp) { |
Prabhakar Kushwaha | 1730a17 | 2015-11-04 12:25:59 +0530 | [diff] [blame^] | 891 | printf("No memory: malloc() failed\n"); |
| 892 | err = -ENOMEM; |
| 893 | goto err_malloc; |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 894 | } |
Prabhakar Kushwaha | 1730a17 | 2015-11-04 12:25:59 +0530 | [diff] [blame^] | 895 | |
| 896 | dpbp_cfg.options = 512; |
| 897 | |
| 898 | err = dpbp_create(dflt_mc_io, MC_CMD_NO_FLAGS, &dpbp_cfg, |
| 899 | &dflt_dpbp->dpbp_handle); |
| 900 | |
| 901 | if (err < 0) { |
| 902 | err = -ENODEV; |
| 903 | printf("dpbp_create() failed: %d\n", err); |
| 904 | goto err_create; |
| 905 | } |
| 906 | |
| 907 | memset(&dpbp_attr, 0, sizeof(struct dpbp_attr)); |
| 908 | err = dpbp_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS, |
| 909 | dflt_dpbp->dpbp_handle, |
| 910 | &dpbp_attr); |
| 911 | if (err < 0) { |
| 912 | printf("dpbp_get_attributes() failed: %d\n", err); |
| 913 | goto err_get_attr; |
| 914 | } |
| 915 | |
| 916 | dflt_dpbp->dpbp_attr.id = dpbp_attr.id; |
| 917 | #ifdef DEBUG |
| 918 | printf("Init: DPBP id=0x%d\n", dflt_dpbp->dpbp_attr.id); |
| 919 | #endif |
| 920 | |
| 921 | err = dpbp_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle); |
| 922 | if (err < 0) { |
| 923 | printf("dpbp_close() failed: %d\n", err); |
| 924 | goto err_close; |
| 925 | } |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 926 | |
| 927 | return 0; |
Prabhakar Kushwaha | 1730a17 | 2015-11-04 12:25:59 +0530 | [diff] [blame^] | 928 | |
| 929 | err_close: |
| 930 | free(dflt_dpbp); |
| 931 | err_get_attr: |
| 932 | dpbp_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle); |
| 933 | dpbp_destroy(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_handle); |
| 934 | err_create: |
| 935 | err_malloc: |
| 936 | return err; |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 937 | } |
| 938 | |
Prabhakar Kushwaha | 1730a17 | 2015-11-04 12:25:59 +0530 | [diff] [blame^] | 939 | static int dpbp_exit(void) |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 940 | { |
Prabhakar Kushwaha | 1730a17 | 2015-11-04 12:25:59 +0530 | [diff] [blame^] | 941 | int err; |
| 942 | |
| 943 | err = dpbp_open(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpbp->dpbp_attr.id, |
| 944 | &dflt_dpbp->dpbp_handle); |
| 945 | if (err < 0) { |
| 946 | printf("dpbp_open() failed: %d\n", err); |
| 947 | goto err; |
| 948 | } |
| 949 | |
| 950 | err = dpbp_destroy(dflt_mc_io, MC_CMD_NO_FLAGS, |
| 951 | dflt_dpbp->dpbp_handle); |
| 952 | if (err < 0) { |
| 953 | printf("dpbp_destroy() failed: %d\n", err); |
| 954 | goto err; |
| 955 | } |
| 956 | |
| 957 | #ifdef DEBUG |
| 958 | printf("Exit: DPBP id=0x%d\n", dflt_dpbp->dpbp_attr.id); |
| 959 | #endif |
| 960 | |
| 961 | if (dflt_dpbp) |
| 962 | free(dflt_dpbp); |
| 963 | return 0; |
| 964 | |
| 965 | err: |
| 966 | return err; |
| 967 | } |
| 968 | |
| 969 | static int dpni_init(void) |
| 970 | { |
| 971 | int err; |
| 972 | struct dpni_attr dpni_attr; |
| 973 | struct dpni_cfg dpni_cfg; |
| 974 | |
| 975 | dflt_dpni = (struct fsl_dpni_obj *)malloc(sizeof(struct fsl_dpni_obj)); |
| 976 | if (!dflt_dpni) { |
| 977 | printf("No memory: malloc() failed\n"); |
| 978 | err = -ENOMEM; |
| 979 | goto err_malloc; |
| 980 | } |
| 981 | |
| 982 | memset(&dpni_cfg, 0, sizeof(dpni_cfg)); |
| 983 | dpni_cfg.adv.options = DPNI_OPT_UNICAST_FILTER | |
| 984 | DPNI_OPT_MULTICAST_FILTER; |
| 985 | |
| 986 | err = dpni_create(dflt_mc_io, MC_CMD_NO_FLAGS, &dpni_cfg, |
| 987 | &dflt_dpni->dpni_handle); |
| 988 | |
| 989 | if (err < 0) { |
| 990 | err = -ENODEV; |
| 991 | printf("dpni_create() failed: %d\n", err); |
| 992 | goto err_create; |
| 993 | } |
| 994 | |
| 995 | memset(&dpni_attr, 0, sizeof(struct dpni_attr)); |
| 996 | err = dpni_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS, |
| 997 | dflt_dpni->dpni_handle, |
| 998 | &dpni_attr); |
| 999 | if (err < 0) { |
| 1000 | printf("dpni_get_attributes() failed: %d\n", err); |
| 1001 | goto err_get_attr; |
| 1002 | } |
| 1003 | |
| 1004 | dflt_dpni->dpni_id = dpni_attr.id; |
| 1005 | #ifdef DEBUG |
| 1006 | printf("Init: DPNI id=0x%d\n", dflt_dpni->dpni_id); |
| 1007 | #endif |
| 1008 | |
| 1009 | err = dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle); |
| 1010 | if (err < 0) { |
| 1011 | printf("dpni_close() failed: %d\n", err); |
| 1012 | goto err_close; |
| 1013 | } |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1014 | |
Prabhakar Kushwaha | fb4a87a | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1015 | return 0; |
Prabhakar Kushwaha | 1730a17 | 2015-11-04 12:25:59 +0530 | [diff] [blame^] | 1016 | |
| 1017 | err_close: |
| 1018 | free(dflt_dpni); |
| 1019 | err_get_attr: |
| 1020 | dpni_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle); |
| 1021 | dpni_destroy(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_handle); |
| 1022 | err_create: |
| 1023 | err_malloc: |
| 1024 | return err; |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1025 | } |
| 1026 | |
Prabhakar Kushwaha | 1730a17 | 2015-11-04 12:25:59 +0530 | [diff] [blame^] | 1027 | static int dpni_exit(void) |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1028 | { |
Prabhakar Kushwaha | 1730a17 | 2015-11-04 12:25:59 +0530 | [diff] [blame^] | 1029 | int err; |
| 1030 | |
| 1031 | err = dpni_open(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpni->dpni_id, |
| 1032 | &dflt_dpni->dpni_handle); |
| 1033 | if (err < 0) { |
| 1034 | printf("dpni_open() failed: %d\n", err); |
| 1035 | goto err; |
| 1036 | } |
| 1037 | |
| 1038 | err = dpni_destroy(dflt_mc_io, MC_CMD_NO_FLAGS, |
| 1039 | dflt_dpni->dpni_handle); |
| 1040 | if (err < 0) { |
| 1041 | printf("dpni_destroy() failed: %d\n", err); |
| 1042 | goto err; |
| 1043 | } |
| 1044 | |
| 1045 | #ifdef DEBUG |
| 1046 | printf("Exit: DPNI id=0x%d\n", dflt_dpni->dpni_id); |
| 1047 | #endif |
| 1048 | |
| 1049 | if (dflt_dpni) |
| 1050 | free(dflt_dpni); |
| 1051 | return 0; |
| 1052 | |
| 1053 | err: |
| 1054 | return err; |
| 1055 | } |
| 1056 | |
| 1057 | static int mc_init_object(void) |
| 1058 | { |
| 1059 | int err = 0; |
| 1060 | |
| 1061 | err = dprc_init(); |
| 1062 | if (err < 0) { |
| 1063 | printf("dprc_init() failed: %d\n", err); |
| 1064 | goto err; |
| 1065 | } |
| 1066 | |
| 1067 | err = dpbp_init(); |
| 1068 | if (err < 0) { |
| 1069 | printf("dpbp_init() failed: %d\n", err); |
| 1070 | goto err; |
| 1071 | } |
| 1072 | |
| 1073 | err = dpio_init(); |
| 1074 | if (err < 0) { |
| 1075 | printf("dpio_init() failed: %d\n", err); |
| 1076 | goto err; |
| 1077 | } |
| 1078 | |
| 1079 | err = dpni_init(); |
| 1080 | if (err < 0) { |
| 1081 | printf("dpni_init() failed: %d\n", err); |
| 1082 | goto err; |
| 1083 | } |
| 1084 | |
| 1085 | return 0; |
| 1086 | err: |
| 1087 | return err; |
| 1088 | } |
| 1089 | |
| 1090 | int fsl_mc_ldpaa_exit(bd_t *bd) |
| 1091 | { |
| 1092 | int err = 0; |
| 1093 | |
| 1094 | if (bd && get_mc_boot_status() == -1) |
| 1095 | return 0; |
| 1096 | |
| 1097 | if (bd && !get_mc_boot_status() && get_dpl_apply_status() == -1) { |
| 1098 | printf("ERROR: fsl-mc: DPL is not applied\n"); |
| 1099 | err = -ENODEV; |
| 1100 | return err; |
| 1101 | } |
| 1102 | |
| 1103 | if (bd && !get_mc_boot_status() && !get_dpl_apply_status()) |
| 1104 | return err; |
| 1105 | |
| 1106 | err = dpbp_exit(); |
| 1107 | if (err < 0) { |
| 1108 | printf("dpni_exit() failed: %d\n", err); |
| 1109 | goto err; |
| 1110 | } |
| 1111 | |
| 1112 | err = dpio_exit(); |
| 1113 | if (err < 0) { |
| 1114 | printf("dpio_exit() failed: %d\n", err); |
| 1115 | goto err; |
| 1116 | } |
| 1117 | |
| 1118 | err = dpni_exit(); |
| 1119 | if (err < 0) { |
| 1120 | printf("dpni_exit() failed: %d\n", err); |
| 1121 | goto err; |
| 1122 | } |
| 1123 | |
| 1124 | err = dprc_exit(); |
| 1125 | if (err < 0) { |
| 1126 | printf("dprc_exit() failed: %d\n", err); |
| 1127 | goto err; |
| 1128 | } |
| 1129 | |
| 1130 | return 0; |
| 1131 | err: |
| 1132 | return err; |
Prabhakar Kushwaha | a2a55e5 | 2015-03-19 09:20:45 -0700 | [diff] [blame] | 1133 | } |
Prabhakar Kushwaha | fb4a87a | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1134 | |
| 1135 | static int do_fsl_mc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 1136 | { |
| 1137 | int err = 0; |
| 1138 | if (argc < 3) |
| 1139 | goto usage; |
| 1140 | |
| 1141 | switch (argv[1][0]) { |
| 1142 | case 's': { |
| 1143 | char sub_cmd; |
| 1144 | u64 mc_fw_addr, mc_dpc_addr, aiop_fw_addr; |
| 1145 | |
| 1146 | sub_cmd = argv[2][0]; |
| 1147 | switch (sub_cmd) { |
| 1148 | case 'm': |
| 1149 | if (argc < 5) |
| 1150 | goto usage; |
| 1151 | |
| 1152 | if (get_mc_boot_status() == 0) { |
| 1153 | printf("fsl-mc: MC is already booted"); |
| 1154 | printf("\n"); |
| 1155 | return err; |
| 1156 | } |
| 1157 | mc_fw_addr = simple_strtoull(argv[3], NULL, 16); |
| 1158 | mc_dpc_addr = simple_strtoull(argv[4], NULL, |
| 1159 | 16); |
Prabhakar Kushwaha | 1730a17 | 2015-11-04 12:25:59 +0530 | [diff] [blame^] | 1160 | |
| 1161 | if (!mc_init(mc_fw_addr, mc_dpc_addr)) |
| 1162 | err = mc_init_object(); |
Prabhakar Kushwaha | fb4a87a | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1163 | break; |
| 1164 | |
| 1165 | #ifdef CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET |
| 1166 | case 'a': |
| 1167 | if (argc < 4) |
| 1168 | goto usage; |
| 1169 | if (get_aiop_apply_status() == 0) { |
| 1170 | printf("fsl-mc: AIOP FW is already"); |
| 1171 | printf(" applied\n"); |
| 1172 | return err; |
| 1173 | } |
| 1174 | |
| 1175 | aiop_fw_addr = simple_strtoull(argv[3], NULL, |
| 1176 | 16); |
| 1177 | |
| 1178 | err = load_mc_aiop_img(aiop_fw_addr); |
| 1179 | if (!err) |
| 1180 | printf("fsl-mc: AIOP FW applied\n"); |
| 1181 | break; |
| 1182 | #endif |
| 1183 | default: |
| 1184 | printf("Invalid option: %s\n", argv[2]); |
| 1185 | goto usage; |
| 1186 | |
| 1187 | break; |
| 1188 | } |
| 1189 | } |
| 1190 | break; |
| 1191 | |
| 1192 | case 'a': { |
| 1193 | u64 mc_dpl_addr; |
| 1194 | |
| 1195 | if (argc < 4) |
| 1196 | goto usage; |
| 1197 | |
| 1198 | if (get_dpl_apply_status() == 0) { |
| 1199 | printf("fsl-mc: DPL already applied\n"); |
| 1200 | return err; |
| 1201 | } |
| 1202 | |
| 1203 | mc_dpl_addr = simple_strtoull(argv[3], NULL, |
| 1204 | 16); |
Prabhakar Kushwaha | 1730a17 | 2015-11-04 12:25:59 +0530 | [diff] [blame^] | 1205 | |
Prabhakar Kushwaha | fb4a87a | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1206 | if (get_mc_boot_status() != 0) { |
| 1207 | printf("fsl-mc: Deploying data path layout .."); |
| 1208 | printf("ERROR (MC is not booted)\n"); |
| 1209 | return -ENODEV; |
| 1210 | } |
Prabhakar Kushwaha | 1730a17 | 2015-11-04 12:25:59 +0530 | [diff] [blame^] | 1211 | |
| 1212 | if (!fsl_mc_ldpaa_exit(NULL)) |
| 1213 | err = mc_apply_dpl(mc_dpl_addr); |
Prabhakar Kushwaha | fb4a87a | 2015-11-04 12:25:58 +0530 | [diff] [blame] | 1214 | break; |
| 1215 | } |
| 1216 | default: |
| 1217 | printf("Invalid option: %s\n", argv[1]); |
| 1218 | goto usage; |
| 1219 | break; |
| 1220 | } |
| 1221 | return err; |
| 1222 | usage: |
| 1223 | return CMD_RET_USAGE; |
| 1224 | } |
| 1225 | |
| 1226 | U_BOOT_CMD( |
| 1227 | fsl_mc, CONFIG_SYS_MAXARGS, 1, do_fsl_mc, |
| 1228 | "DPAA2 command to manage Management Complex (MC)", |
| 1229 | "start mc [FW_addr] [DPC_addr] - Start Management Complex\n" |
| 1230 | "fsl_mc apply DPL [DPL_addr] - Apply DPL file\n" |
| 1231 | "fsl_mc start aiop [FW_addr] - Start AIOP\n" |
| 1232 | ); |