mc.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847
  1. /*
  2. * Copyright (C) 2014 Freescale Semiconductor
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <errno.h>
  8. #include <asm/io.h>
  9. #include <libfdt.h>
  10. #include <fdt_support.h>
  11. #include <fsl-mc/fsl_mc.h>
  12. #include <fsl-mc/fsl_mc_sys.h>
  13. #include <fsl-mc/fsl_mc_private.h>
  14. #include <fsl-mc/fsl_dpmng.h>
  15. #include <fsl-mc/fsl_dprc.h>
  16. #include <fsl-mc/fsl_dpio.h>
  17. #include <fsl-mc/fsl_qbman_portal.h>
  18. #define MC_RAM_BASE_ADDR_ALIGNMENT (512UL * 1024 * 1024)
  19. #define MC_RAM_BASE_ADDR_ALIGNMENT_MASK (~(MC_RAM_BASE_ADDR_ALIGNMENT - 1))
  20. #define MC_RAM_SIZE_ALIGNMENT (256UL * 1024 * 1024)
  21. #define MC_MEM_SIZE_ENV_VAR "mcmemsize"
  22. #define MC_BOOT_TIMEOUT_ENV_VAR "mcboottimeout"
  23. DECLARE_GLOBAL_DATA_PTR;
  24. static int mc_boot_status;
  25. struct fsl_mc_io *dflt_mc_io = NULL;
  26. uint16_t dflt_dprc_handle = 0;
  27. struct fsl_dpbp_obj *dflt_dpbp = NULL;
  28. struct fsl_dpio_obj *dflt_dpio = NULL;
  29. uint16_t dflt_dpio_handle = 0;
  30. #ifdef DEBUG
  31. void dump_ram_words(const char *title, void *addr)
  32. {
  33. int i;
  34. uint32_t *words = addr;
  35. printf("Dumping beginning of %s (%p):\n", title, addr);
  36. for (i = 0; i < 16; i++)
  37. printf("%#x ", words[i]);
  38. printf("\n");
  39. }
  40. void dump_mc_ccsr_regs(struct mc_ccsr_registers __iomem *mc_ccsr_regs)
  41. {
  42. printf("MC CCSR registers:\n"
  43. "reg_gcr1 %#x\n"
  44. "reg_gsr %#x\n"
  45. "reg_sicbalr %#x\n"
  46. "reg_sicbahr %#x\n"
  47. "reg_sicapr %#x\n"
  48. "reg_mcfbalr %#x\n"
  49. "reg_mcfbahr %#x\n"
  50. "reg_mcfapr %#x\n"
  51. "reg_psr %#x\n",
  52. mc_ccsr_regs->reg_gcr1,
  53. mc_ccsr_regs->reg_gsr,
  54. mc_ccsr_regs->reg_sicbalr,
  55. mc_ccsr_regs->reg_sicbahr,
  56. mc_ccsr_regs->reg_sicapr,
  57. mc_ccsr_regs->reg_mcfbalr,
  58. mc_ccsr_regs->reg_mcfbahr,
  59. mc_ccsr_regs->reg_mcfapr,
  60. mc_ccsr_regs->reg_psr);
  61. }
  62. #else
  63. #define dump_ram_words(title, addr)
  64. #define dump_mc_ccsr_regs(mc_ccsr_regs)
  65. #endif /* DEBUG */
  66. #ifndef CONFIG_SYS_LS_MC_FW_IN_DDR
  67. /**
  68. * Copying MC firmware or DPL image to DDR
  69. */
  70. static int mc_copy_image(const char *title,
  71. u64 image_addr, u32 image_size, u64 mc_ram_addr)
  72. {
  73. debug("%s copied to address %p\n", title, (void *)mc_ram_addr);
  74. memcpy((void *)mc_ram_addr, (void *)image_addr, image_size);
  75. flush_dcache_range(mc_ram_addr, mc_ram_addr + image_size);
  76. return 0;
  77. }
  78. /**
  79. * MC firmware FIT image parser checks if the image is in FIT
  80. * format, verifies integrity of the image and calculates
  81. * raw image address and size values.
  82. * Returns 0 on success and a negative errno on error.
  83. * task fail.
  84. **/
  85. int parse_mc_firmware_fit_image(const void **raw_image_addr,
  86. size_t *raw_image_size)
  87. {
  88. int format;
  89. void *fit_hdr;
  90. int node_offset;
  91. const void *data;
  92. size_t size;
  93. const char *uname = "firmware";
  94. /* Check if the image is in NOR flash */
  95. #ifdef CONFIG_SYS_LS_MC_FW_IN_NOR
  96. fit_hdr = (void *)CONFIG_SYS_LS_MC_FW_ADDR;
  97. #else
  98. #error "No CONFIG_SYS_LS_MC_FW_IN_xxx defined"
  99. #endif
  100. /* Check if Image is in FIT format */
  101. format = genimg_get_format(fit_hdr);
  102. if (format != IMAGE_FORMAT_FIT) {
  103. printf("fsl-mc: ERROR: Bad firmware image (not a FIT image)\n");
  104. return -EINVAL;
  105. }
  106. if (!fit_check_format(fit_hdr)) {
  107. printf("fsl-mc: ERROR: Bad firmware image (bad FIT header)\n");
  108. return -EINVAL;
  109. }
  110. node_offset = fit_image_get_node(fit_hdr, uname);
  111. if (node_offset < 0) {
  112. printf("fsl-mc: ERROR: Bad firmware image (missing subimage)\n");
  113. return -ENOENT;
  114. }
  115. /* Verify MC firmware image */
  116. if (!(fit_image_verify(fit_hdr, node_offset))) {
  117. printf("fsl-mc: ERROR: Bad firmware image (bad CRC)\n");
  118. return -EINVAL;
  119. }
  120. /* Get address and size of raw image */
  121. fit_image_get_data(fit_hdr, node_offset, &data, &size);
  122. *raw_image_addr = data;
  123. *raw_image_size = size;
  124. return 0;
  125. }
  126. #endif
  127. /*
  128. * Calculates the values to be used to specify the address range
  129. * for the MC private DRAM block, in the MCFBALR/MCFBAHR registers.
  130. * It returns the highest 512MB-aligned address within the given
  131. * address range, in '*aligned_base_addr', and the number of 256 MiB
  132. * blocks in it, in 'num_256mb_blocks'.
  133. */
  134. static int calculate_mc_private_ram_params(u64 mc_private_ram_start_addr,
  135. size_t mc_ram_size,
  136. u64 *aligned_base_addr,
  137. u8 *num_256mb_blocks)
  138. {
  139. u64 addr;
  140. u16 num_blocks;
  141. if (mc_ram_size % MC_RAM_SIZE_ALIGNMENT != 0) {
  142. printf("fsl-mc: ERROR: invalid MC private RAM size (%lu)\n",
  143. mc_ram_size);
  144. return -EINVAL;
  145. }
  146. num_blocks = mc_ram_size / MC_RAM_SIZE_ALIGNMENT;
  147. if (num_blocks < 1 || num_blocks > 0xff) {
  148. printf("fsl-mc: ERROR: invalid MC private RAM size (%lu)\n",
  149. mc_ram_size);
  150. return -EINVAL;
  151. }
  152. addr = (mc_private_ram_start_addr + mc_ram_size - 1) &
  153. MC_RAM_BASE_ADDR_ALIGNMENT_MASK;
  154. if (addr < mc_private_ram_start_addr) {
  155. printf("fsl-mc: ERROR: bad start address %#llx\n",
  156. mc_private_ram_start_addr);
  157. return -EFAULT;
  158. }
  159. *aligned_base_addr = addr;
  160. *num_256mb_blocks = num_blocks;
  161. return 0;
  162. }
  163. static int mc_fixup_dpc(u64 dpc_addr)
  164. {
  165. void *blob = (void *)dpc_addr;
  166. int nodeoffset;
  167. /* delete any existing ICID pools */
  168. nodeoffset = fdt_path_offset(blob, "/resources/icid_pools");
  169. if (fdt_del_node(blob, nodeoffset) < 0)
  170. printf("\nfsl-mc: WARNING: could not delete ICID pool\n");
  171. /* add a new pool */
  172. nodeoffset = fdt_path_offset(blob, "/resources");
  173. if (nodeoffset < 0) {
  174. printf("\nfsl-mc: ERROR: DPC is missing /resources\n");
  175. return -EINVAL;
  176. }
  177. nodeoffset = fdt_add_subnode(blob, nodeoffset, "icid_pools");
  178. nodeoffset = fdt_add_subnode(blob, nodeoffset, "icid_pool@0");
  179. do_fixup_by_path_u32(blob, "/resources/icid_pools/icid_pool@0",
  180. "base_icid", FSL_DPAA2_STREAM_ID_START, 1);
  181. do_fixup_by_path_u32(blob, "/resources/icid_pools/icid_pool@0",
  182. "num",
  183. FSL_DPAA2_STREAM_ID_END -
  184. FSL_DPAA2_STREAM_ID_START + 1, 1);
  185. flush_dcache_range(dpc_addr, dpc_addr + fdt_totalsize(blob));
  186. return 0;
  187. }
  188. static int load_mc_dpc(u64 mc_ram_addr, size_t mc_ram_size)
  189. {
  190. u64 mc_dpc_offset;
  191. #ifndef CONFIG_SYS_LS_MC_DPC_IN_DDR
  192. int error;
  193. void *dpc_fdt_hdr;
  194. int dpc_size;
  195. #endif
  196. #ifdef CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET
  197. BUILD_BUG_ON((CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET & 0x3) != 0 ||
  198. CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET > 0xffffffff);
  199. mc_dpc_offset = CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET;
  200. #else
  201. #error "CONFIG_SYS_LS_MC_DRAM_DPC_OFFSET not defined"
  202. #endif
  203. /*
  204. * Load the MC DPC blob in the MC private DRAM block:
  205. */
  206. #ifdef CONFIG_SYS_LS_MC_DPC_IN_DDR
  207. printf("MC DPC is preloaded to %#llx\n", mc_ram_addr + mc_dpc_offset);
  208. #else
  209. /*
  210. * Get address and size of the DPC blob stored in flash:
  211. */
  212. #ifdef CONFIG_SYS_LS_MC_DPC_IN_NOR
  213. dpc_fdt_hdr = (void *)CONFIG_SYS_LS_MC_DPC_ADDR;
  214. #else
  215. #error "No CONFIG_SYS_LS_MC_DPC_IN_xxx defined"
  216. #endif
  217. error = fdt_check_header(dpc_fdt_hdr);
  218. if (error != 0) {
  219. /*
  220. * Don't return with error here, since the MC firmware can
  221. * still boot without a DPC
  222. */
  223. printf("\nfsl-mc: WARNING: No DPC image found");
  224. return 0;
  225. }
  226. dpc_size = fdt_totalsize(dpc_fdt_hdr);
  227. if (dpc_size > CONFIG_SYS_LS_MC_DPC_MAX_LENGTH) {
  228. printf("\nfsl-mc: ERROR: Bad DPC image (too large: %d)\n",
  229. dpc_size);
  230. return -EINVAL;
  231. }
  232. mc_copy_image("MC DPC blob",
  233. (u64)dpc_fdt_hdr, dpc_size, mc_ram_addr + mc_dpc_offset);
  234. #endif /* not defined CONFIG_SYS_LS_MC_DPC_IN_DDR */
  235. if (mc_fixup_dpc(mc_ram_addr + mc_dpc_offset))
  236. return -EINVAL;
  237. dump_ram_words("DPC", (void *)(mc_ram_addr + mc_dpc_offset));
  238. return 0;
  239. }
  240. static int load_mc_dpl(u64 mc_ram_addr, size_t mc_ram_size)
  241. {
  242. u64 mc_dpl_offset;
  243. #ifndef CONFIG_SYS_LS_MC_DPL_IN_DDR
  244. int error;
  245. void *dpl_fdt_hdr;
  246. int dpl_size;
  247. #endif
  248. #ifdef CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET
  249. BUILD_BUG_ON((CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET & 0x3) != 0 ||
  250. CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET > 0xffffffff);
  251. mc_dpl_offset = CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET;
  252. #else
  253. #error "CONFIG_SYS_LS_MC_DRAM_DPL_OFFSET not defined"
  254. #endif
  255. /*
  256. * Load the MC DPL blob in the MC private DRAM block:
  257. */
  258. #ifdef CONFIG_SYS_LS_MC_DPL_IN_DDR
  259. printf("MC DPL is preloaded to %#llx\n", mc_ram_addr + mc_dpl_offset);
  260. #else
  261. /*
  262. * Get address and size of the DPL blob stored in flash:
  263. */
  264. #ifdef CONFIG_SYS_LS_MC_DPL_IN_NOR
  265. dpl_fdt_hdr = (void *)CONFIG_SYS_LS_MC_DPL_ADDR;
  266. #else
  267. #error "No CONFIG_SYS_LS_MC_DPL_IN_xxx defined"
  268. #endif
  269. error = fdt_check_header(dpl_fdt_hdr);
  270. if (error != 0) {
  271. printf("\nfsl-mc: ERROR: Bad DPL image (bad header)\n");
  272. return error;
  273. }
  274. dpl_size = fdt_totalsize(dpl_fdt_hdr);
  275. if (dpl_size > CONFIG_SYS_LS_MC_DPL_MAX_LENGTH) {
  276. printf("\nfsl-mc: ERROR: Bad DPL image (too large: %d)\n",
  277. dpl_size);
  278. return -EINVAL;
  279. }
  280. mc_copy_image("MC DPL blob",
  281. (u64)dpl_fdt_hdr, dpl_size, mc_ram_addr + mc_dpl_offset);
  282. #endif /* not defined CONFIG_SYS_LS_MC_DPL_IN_DDR */
  283. dump_ram_words("DPL", (void *)(mc_ram_addr + mc_dpl_offset));
  284. return 0;
  285. }
  286. /**
  287. * Return the MC boot timeout value in milliseconds
  288. */
  289. static unsigned long get_mc_boot_timeout_ms(void)
  290. {
  291. unsigned long timeout_ms = CONFIG_SYS_LS_MC_BOOT_TIMEOUT_MS;
  292. char *timeout_ms_env_var = getenv(MC_BOOT_TIMEOUT_ENV_VAR);
  293. if (timeout_ms_env_var) {
  294. timeout_ms = simple_strtoul(timeout_ms_env_var, NULL, 10);
  295. if (timeout_ms == 0) {
  296. printf("fsl-mc: WARNING: Invalid value for \'"
  297. MC_BOOT_TIMEOUT_ENV_VAR
  298. "\' environment variable: %lu\n",
  299. timeout_ms);
  300. timeout_ms = CONFIG_SYS_LS_MC_BOOT_TIMEOUT_MS;
  301. }
  302. }
  303. return timeout_ms;
  304. }
  305. #ifdef CONFIG_SYS_LS_MC_AIOP_IMG_IN_NOR
  306. static int load_mc_aiop_img(u64 mc_ram_addr, size_t mc_ram_size)
  307. {
  308. void *aiop_img;
  309. /*
  310. * Load the MC AIOP image in the MC private DRAM block:
  311. */
  312. aiop_img = (void *)CONFIG_SYS_LS_MC_AIOP_IMG_ADDR;
  313. mc_copy_image("MC AIOP image",
  314. (u64)aiop_img, CONFIG_SYS_LS_MC_AIOP_IMG_MAX_LENGTH,
  315. mc_ram_addr + CONFIG_SYS_LS_MC_DRAM_AIOP_IMG_OFFSET);
  316. return 0;
  317. }
  318. #endif
  319. static int wait_for_mc(bool booting_mc, u32 *final_reg_gsr)
  320. {
  321. u32 reg_gsr;
  322. u32 mc_fw_boot_status;
  323. unsigned long timeout_ms = get_mc_boot_timeout_ms();
  324. struct mc_ccsr_registers __iomem *mc_ccsr_regs = MC_CCSR_BASE_ADDR;
  325. dmb();
  326. assert(timeout_ms > 0);
  327. for (;;) {
  328. udelay(1000); /* throttle polling */
  329. reg_gsr = in_le32(&mc_ccsr_regs->reg_gsr);
  330. mc_fw_boot_status = (reg_gsr & GSR_FS_MASK);
  331. if (mc_fw_boot_status & 0x1)
  332. break;
  333. timeout_ms--;
  334. if (timeout_ms == 0)
  335. break;
  336. }
  337. if (timeout_ms == 0) {
  338. printf("ERROR: timeout\n");
  339. /* TODO: Get an error status from an MC CCSR register */
  340. return -ETIMEDOUT;
  341. }
  342. if (mc_fw_boot_status != 0x1) {
  343. /*
  344. * TODO: Identify critical errors from the GSR register's FS
  345. * field and for those errors, set error to -ENODEV or other
  346. * appropriate errno, so that the status property is set to
  347. * failure in the fsl,dprc device tree node.
  348. */
  349. printf("WARNING: Firmware returned an error (GSR: %#x)\n",
  350. reg_gsr);
  351. } else {
  352. printf("SUCCESS\n");
  353. }
  354. *final_reg_gsr = reg_gsr;
  355. return 0;
  356. }
  357. int mc_init(void)
  358. {
  359. int error = 0;
  360. int portal_id = 0;
  361. struct mc_ccsr_registers __iomem *mc_ccsr_regs = MC_CCSR_BASE_ADDR;
  362. u64 mc_ram_addr;
  363. u32 reg_gsr;
  364. u32 reg_mcfbalr;
  365. #ifndef CONFIG_SYS_LS_MC_FW_IN_DDR
  366. const void *raw_image_addr;
  367. size_t raw_image_size = 0;
  368. #endif
  369. struct mc_version mc_ver_info;
  370. u64 mc_ram_aligned_base_addr;
  371. u8 mc_ram_num_256mb_blocks;
  372. size_t mc_ram_size = mc_get_dram_block_size();
  373. /*
  374. * The MC private DRAM block was already carved at the end of DRAM
  375. * by board_init_f() using CONFIG_SYS_MEM_TOP_HIDE:
  376. */
  377. if (gd->bd->bi_dram[1].start) {
  378. mc_ram_addr =
  379. gd->bd->bi_dram[1].start + gd->bd->bi_dram[1].size;
  380. } else {
  381. mc_ram_addr =
  382. gd->bd->bi_dram[0].start + gd->bd->bi_dram[0].size;
  383. }
  384. error = calculate_mc_private_ram_params(mc_ram_addr,
  385. mc_ram_size,
  386. &mc_ram_aligned_base_addr,
  387. &mc_ram_num_256mb_blocks);
  388. if (error != 0)
  389. goto out;
  390. /*
  391. * Management Complex cores should be held at reset out of POR.
  392. * U-boot should be the first software to touch MC. To be safe,
  393. * we reset all cores again by setting GCR1 to 0. It doesn't do
  394. * anything if they are held at reset. After we setup the firmware
  395. * we kick off MC by deasserting the reset bit for core 0, and
  396. * deasserting the reset bits for Command Portal Managers.
  397. * The stop bits are not touched here. They are used to stop the
  398. * cores when they are active. Setting stop bits doesn't stop the
  399. * cores from fetching instructions when they are released from
  400. * reset.
  401. */
  402. out_le32(&mc_ccsr_regs->reg_gcr1, 0);
  403. dmb();
  404. #ifdef CONFIG_SYS_LS_MC_FW_IN_DDR
  405. printf("MC firmware is preloaded to %#llx\n", mc_ram_addr);
  406. #else
  407. error = parse_mc_firmware_fit_image(&raw_image_addr, &raw_image_size);
  408. if (error != 0)
  409. goto out;
  410. /*
  411. * Load the MC FW at the beginning of the MC private DRAM block:
  412. */
  413. mc_copy_image("MC Firmware",
  414. (u64)raw_image_addr, raw_image_size, mc_ram_addr);
  415. #endif
  416. dump_ram_words("firmware", (void *)mc_ram_addr);
  417. error = load_mc_dpc(mc_ram_addr, mc_ram_size);
  418. if (error != 0)
  419. goto out;
  420. error = load_mc_dpl(mc_ram_addr, mc_ram_size);
  421. if (error != 0)
  422. goto out;
  423. #ifdef CONFIG_SYS_LS_MC_AIOP_IMG_IN_NOR
  424. error = load_mc_aiop_img(mc_ram_addr, mc_ram_size);
  425. if (error != 0)
  426. goto out;
  427. #endif
  428. debug("mc_ccsr_regs %p\n", mc_ccsr_regs);
  429. dump_mc_ccsr_regs(mc_ccsr_regs);
  430. /*
  431. * Tell MC what is the address range of the DRAM block assigned to it:
  432. */
  433. reg_mcfbalr = (u32)mc_ram_aligned_base_addr |
  434. (mc_ram_num_256mb_blocks - 1);
  435. out_le32(&mc_ccsr_regs->reg_mcfbalr, reg_mcfbalr);
  436. out_le32(&mc_ccsr_regs->reg_mcfbahr,
  437. (u32)(mc_ram_aligned_base_addr >> 32));
  438. out_le32(&mc_ccsr_regs->reg_mcfapr, FSL_BYPASS_AMQ);
  439. /*
  440. * Tell the MC that we want delayed DPL deployment.
  441. */
  442. out_le32(&mc_ccsr_regs->reg_gsr, 0xDD00);
  443. printf("\nfsl-mc: Booting Management Complex ... ");
  444. /*
  445. * Deassert reset and release MC core 0 to run
  446. */
  447. out_le32(&mc_ccsr_regs->reg_gcr1, GCR1_P1_DE_RST | GCR1_M_ALL_DE_RST);
  448. error = wait_for_mc(true, &reg_gsr);
  449. if (error != 0)
  450. goto out;
  451. /*
  452. * TODO: need to obtain the portal_id for the root container from the
  453. * DPL
  454. */
  455. portal_id = 0;
  456. /*
  457. * Initialize the global default MC portal
  458. * And check that the MC firmware is responding portal commands:
  459. */
  460. dflt_mc_io = (struct fsl_mc_io *)malloc(sizeof(struct fsl_mc_io));
  461. if (!dflt_mc_io) {
  462. printf(" No memory: malloc() failed\n");
  463. return -ENOMEM;
  464. }
  465. dflt_mc_io->mmio_regs = SOC_MC_PORTAL_ADDR(portal_id);
  466. debug("Checking access to MC portal of root DPRC container (portal_id %d, portal physical addr %p)\n",
  467. portal_id, dflt_mc_io->mmio_regs);
  468. error = mc_get_version(dflt_mc_io, MC_CMD_NO_FLAGS, &mc_ver_info);
  469. if (error != 0) {
  470. printf("fsl-mc: ERROR: Firmware version check failed (error: %d)\n",
  471. error);
  472. goto out;
  473. }
  474. if (MC_VER_MAJOR != mc_ver_info.major) {
  475. printf("fsl-mc: ERROR: Firmware major version mismatch (found: %d, expected: %d)\n",
  476. mc_ver_info.major, MC_VER_MAJOR);
  477. printf("fsl-mc: Update the Management Complex firmware\n");
  478. error = -ENODEV;
  479. goto out;
  480. }
  481. if (MC_VER_MINOR != mc_ver_info.minor)
  482. printf("fsl-mc: WARNING: Firmware minor version mismatch (found: %d, expected: %d)\n",
  483. mc_ver_info.minor, MC_VER_MINOR);
  484. printf("fsl-mc: Management Complex booted (version: %d.%d.%d, boot status: %#x)\n",
  485. mc_ver_info.major, mc_ver_info.minor, mc_ver_info.revision,
  486. reg_gsr & GSR_FS_MASK);
  487. /*
  488. * Tell the MC to deploy the DPL:
  489. */
  490. out_le32(&mc_ccsr_regs->reg_gsr, 0x0);
  491. printf("fsl-mc: Deploying data path layout ... ");
  492. error = wait_for_mc(false, &reg_gsr);
  493. if (error != 0)
  494. goto out;
  495. out:
  496. if (error != 0)
  497. mc_boot_status = error;
  498. else
  499. mc_boot_status = 0;
  500. return error;
  501. }
  502. int get_mc_boot_status(void)
  503. {
  504. return mc_boot_status;
  505. }
  506. /**
  507. * Return the actual size of the MC private DRAM block.
  508. */
  509. unsigned long mc_get_dram_block_size(void)
  510. {
  511. unsigned long dram_block_size = CONFIG_SYS_LS_MC_DRAM_BLOCK_MIN_SIZE;
  512. char *dram_block_size_env_var = getenv(MC_MEM_SIZE_ENV_VAR);
  513. if (dram_block_size_env_var) {
  514. dram_block_size = simple_strtoul(dram_block_size_env_var, NULL,
  515. 10);
  516. if (dram_block_size < CONFIG_SYS_LS_MC_DRAM_BLOCK_MIN_SIZE) {
  517. printf("fsl-mc: WARNING: Invalid value for \'"
  518. MC_MEM_SIZE_ENV_VAR
  519. "\' environment variable: %lu\n",
  520. dram_block_size);
  521. dram_block_size = CONFIG_SYS_LS_MC_DRAM_BLOCK_MIN_SIZE;
  522. }
  523. }
  524. return dram_block_size;
  525. }
  526. int dpio_init(struct dprc_obj_desc obj_desc)
  527. {
  528. struct qbman_swp_desc p_des;
  529. struct dpio_attr attr;
  530. int err = 0;
  531. dflt_dpio = (struct fsl_dpio_obj *)malloc(sizeof(struct fsl_dpio_obj));
  532. if (!dflt_dpio) {
  533. printf(" No memory: malloc() failed\n");
  534. return -ENOMEM;
  535. }
  536. dflt_dpio->dpio_id = obj_desc.id;
  537. err = dpio_open(dflt_mc_io, MC_CMD_NO_FLAGS, obj_desc.id,
  538. &dflt_dpio_handle);
  539. if (err) {
  540. printf("dpio_open() failed\n");
  541. goto err_open;
  542. }
  543. err = dpio_get_attributes(dflt_mc_io, MC_CMD_NO_FLAGS,
  544. dflt_dpio_handle, &attr);
  545. if (err) {
  546. printf("dpio_get_attributes() failed %d\n", err);
  547. goto err_get_attr;
  548. }
  549. err = dpio_enable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio_handle);
  550. if (err) {
  551. printf("dpio_enable() failed %d\n", err);
  552. goto err_get_enable;
  553. }
  554. debug("ce_offset=0x%llx, ci_offset=0x%llx, portalid=%d, prios=%d\n",
  555. attr.qbman_portal_ce_offset,
  556. attr.qbman_portal_ci_offset,
  557. attr.qbman_portal_id,
  558. attr.num_priorities);
  559. p_des.cena_bar = (void *)(SOC_QBMAN_PORTALS_BASE_ADDR
  560. + attr.qbman_portal_ce_offset);
  561. p_des.cinh_bar = (void *)(SOC_QBMAN_PORTALS_BASE_ADDR
  562. + attr.qbman_portal_ci_offset);
  563. dflt_dpio->sw_portal = qbman_swp_init(&p_des);
  564. if (dflt_dpio->sw_portal == NULL) {
  565. printf("qbman_swp_init() failed\n");
  566. goto err_get_swp_init;
  567. }
  568. return 0;
  569. err_get_swp_init:
  570. err_get_enable:
  571. dpio_disable(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio_handle);
  572. err_get_attr:
  573. dpio_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dpio_handle);
  574. err_open:
  575. free(dflt_dpio);
  576. return err;
  577. }
  578. int dpbp_init(struct dprc_obj_desc obj_desc)
  579. {
  580. dflt_dpbp = (struct fsl_dpbp_obj *)malloc(sizeof(struct fsl_dpbp_obj));
  581. if (!dflt_dpbp) {
  582. printf(" No memory: malloc() failed\n");
  583. return -ENOMEM;
  584. }
  585. dflt_dpbp->dpbp_attr.id = obj_desc.id;
  586. return 0;
  587. }
  588. int dprc_init_container_obj(struct dprc_obj_desc obj_desc, uint16_t dprc_handle)
  589. {
  590. int error = 0, state = 0;
  591. struct dprc_endpoint dpni_endpoint, dpmac_endpoint;
  592. if (!strcmp(obj_desc.type, "dpbp")) {
  593. if (!dflt_dpbp) {
  594. error = dpbp_init(obj_desc);
  595. if (error < 0)
  596. printf("dpbp_init failed\n");
  597. }
  598. } else if (!strcmp(obj_desc.type, "dpio")) {
  599. if (!dflt_dpio) {
  600. error = dpio_init(obj_desc);
  601. if (error < 0)
  602. printf("dpio_init failed\n");
  603. }
  604. } else if (!strcmp(obj_desc.type, "dpni")) {
  605. strcpy(dpni_endpoint.type, obj_desc.type);
  606. dpni_endpoint.id = obj_desc.id;
  607. error = dprc_get_connection(dflt_mc_io, MC_CMD_NO_FLAGS,
  608. dprc_handle, &dpni_endpoint,
  609. &dpmac_endpoint, &state);
  610. if (!strcmp(dpmac_endpoint.type, "dpmac"))
  611. error = ldpaa_eth_init(obj_desc);
  612. if (error < 0)
  613. printf("ldpaa_eth_init failed\n");
  614. }
  615. return error;
  616. }
  617. int dprc_scan_container_obj(uint16_t dprc_handle, char *obj_type, int i)
  618. {
  619. int error = 0;
  620. struct dprc_obj_desc obj_desc;
  621. memset((void *)&obj_desc, 0x00, sizeof(struct dprc_obj_desc));
  622. error = dprc_get_obj(dflt_mc_io, MC_CMD_NO_FLAGS, dprc_handle,
  623. i, &obj_desc);
  624. if (error < 0) {
  625. printf("dprc_get_obj(i=%d) failed: %d\n",
  626. i, error);
  627. return error;
  628. }
  629. if (!strcmp(obj_desc.type, obj_type)) {
  630. debug("Discovered object: type %s, id %d, req %s\n",
  631. obj_desc.type, obj_desc.id, obj_type);
  632. error = dprc_init_container_obj(obj_desc, dprc_handle);
  633. if (error < 0) {
  634. printf("dprc_init_container_obj(i=%d) failed: %d\n",
  635. i, error);
  636. return error;
  637. }
  638. }
  639. return error;
  640. }
  641. int fsl_mc_ldpaa_init(bd_t *bis)
  642. {
  643. int i, error = 0;
  644. int dprc_opened = 0, container_id;
  645. int num_child_objects = 0;
  646. error = mc_init();
  647. if (error < 0)
  648. goto error;
  649. error = dprc_get_container_id(dflt_mc_io, MC_CMD_NO_FLAGS,
  650. &container_id);
  651. if (error < 0) {
  652. printf("dprc_get_container_id() failed: %d\n", error);
  653. goto error;
  654. }
  655. debug("fsl-mc: Container id=0x%x\n", container_id);
  656. error = dprc_open(dflt_mc_io, MC_CMD_NO_FLAGS, container_id,
  657. &dflt_dprc_handle);
  658. if (error < 0) {
  659. printf("dprc_open() failed: %d\n", error);
  660. goto error;
  661. }
  662. dprc_opened = true;
  663. error = dprc_get_obj_count(dflt_mc_io,
  664. MC_CMD_NO_FLAGS, dflt_dprc_handle,
  665. &num_child_objects);
  666. if (error < 0) {
  667. printf("dprc_get_obj_count() failed: %d\n", error);
  668. goto error;
  669. }
  670. debug("Total child in container %d = %d\n", container_id,
  671. num_child_objects);
  672. if (num_child_objects != 0) {
  673. /*
  674. * Discover objects currently in the DPRC container in the MC:
  675. */
  676. for (i = 0; i < num_child_objects; i++)
  677. error = dprc_scan_container_obj(dflt_dprc_handle,
  678. "dpbp", i);
  679. for (i = 0; i < num_child_objects; i++)
  680. error = dprc_scan_container_obj(dflt_dprc_handle,
  681. "dpio", i);
  682. for (i = 0; i < num_child_objects; i++)
  683. error = dprc_scan_container_obj(dflt_dprc_handle,
  684. "dpni", i);
  685. }
  686. error:
  687. if (dprc_opened)
  688. dprc_close(dflt_mc_io, MC_CMD_NO_FLAGS, dflt_dprc_handle);
  689. return error;
  690. }
  691. void fsl_mc_ldpaa_exit(bd_t *bis)
  692. {
  693. int err;
  694. if (get_mc_boot_status() == 0) {
  695. err = dpio_disable(dflt_mc_io, MC_CMD_NO_FLAGS,
  696. dflt_dpio_handle);
  697. if (err < 0) {
  698. printf("dpio_disable() failed: %d\n", err);
  699. return;
  700. }
  701. err = dpio_reset(dflt_mc_io, MC_CMD_NO_FLAGS,
  702. dflt_dpio_handle);
  703. if (err < 0) {
  704. printf("dpio_reset() failed: %d\n", err);
  705. return;
  706. }
  707. err = dpio_close(dflt_mc_io, MC_CMD_NO_FLAGS,
  708. dflt_dpio_handle);
  709. if (err < 0) {
  710. printf("dpio_close() failed: %d\n", err);
  711. return;
  712. }
  713. free(dflt_dpio);
  714. free(dflt_dpbp);
  715. }
  716. if (dflt_mc_io)
  717. free(dflt_mc_io);
  718. }