mc.c 32 KB

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