board.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2018 Marvell International Ltd.
  4. *
  5. * https://spdx.org/licenses
  6. */
  7. #include <command.h>
  8. #include <console.h>
  9. #include <cpu_func.h>
  10. #include <dm.h>
  11. #include <dm/uclass-internal.h>
  12. #include <env.h>
  13. #include <init.h>
  14. #include <malloc.h>
  15. #include <net.h>
  16. #include <pci_ids.h>
  17. #include <errno.h>
  18. #include <asm/io.h>
  19. #include <linux/compiler.h>
  20. #include <linux/delay.h>
  21. #include <linux/libfdt.h>
  22. #include <fdt_support.h>
  23. #include <asm/arch/smc.h>
  24. #include <asm/arch/soc.h>
  25. #include <asm/arch/board.h>
  26. #include <dm/util.h>
  27. DECLARE_GLOBAL_DATA_PTR;
  28. void cleanup_env_ethaddr(void)
  29. {
  30. char ename[32];
  31. for (int i = 0; i < 20; i++) {
  32. sprintf(ename, i ? "eth%daddr" : "ethaddr", i);
  33. if (env_get(ename))
  34. env_set(ename, NULL);
  35. }
  36. }
  37. void octeontx2_board_get_mac_addr(u8 index, u8 *mac_addr)
  38. {
  39. u64 tmp_mac, board_mac_addr = fdt_get_board_mac_addr();
  40. static int board_mac_num;
  41. board_mac_num = fdt_get_board_mac_cnt();
  42. if ((!is_zero_ethaddr((u8 *)&board_mac_addr)) && board_mac_num) {
  43. tmp_mac = board_mac_addr;
  44. tmp_mac += index;
  45. tmp_mac = swab64(tmp_mac) >> 16;
  46. memcpy(mac_addr, (u8 *)&tmp_mac, ARP_HLEN);
  47. board_mac_num--;
  48. } else {
  49. memset(mac_addr, 0, ARP_HLEN);
  50. }
  51. debug("%s mac %pM\n", __func__, mac_addr);
  52. }
  53. void board_quiesce_devices(void)
  54. {
  55. struct uclass *uc_dev;
  56. int ret;
  57. /* Removes all RVU PF devices */
  58. ret = uclass_get(UCLASS_ETH, &uc_dev);
  59. if (uc_dev)
  60. ret = uclass_destroy(uc_dev);
  61. if (ret)
  62. printf("couldn't remove rvu pf devices\n");
  63. if (IS_ENABLED(CONFIG_OCTEONTX2_CGX_INTF)) {
  64. /* Bring down all cgx lmac links */
  65. cgx_intf_shutdown();
  66. }
  67. /* Removes all CGX and RVU AF devices */
  68. ret = uclass_get(UCLASS_MISC, &uc_dev);
  69. if (uc_dev)
  70. ret = uclass_destroy(uc_dev);
  71. if (ret)
  72. printf("couldn't remove misc (cgx/rvu_af) devices\n");
  73. /* SMC call - removes all LF<->PF mappings */
  74. smc_disable_rvu_lfs(0);
  75. }
  76. int board_early_init_r(void)
  77. {
  78. pci_init();
  79. return 0;
  80. }
  81. int board_init(void)
  82. {
  83. return 0;
  84. }
  85. int timer_init(void)
  86. {
  87. return 0;
  88. }
  89. int dram_init(void)
  90. {
  91. gd->ram_size = smc_dram_size(0);
  92. gd->ram_size -= CONFIG_SYS_SDRAM_BASE;
  93. mem_map_fill();
  94. return 0;
  95. }
  96. void board_late_probe_devices(void)
  97. {
  98. struct udevice *dev;
  99. int err, cgx_cnt = 3, i;
  100. /* Probe MAC(CGX) and NIC AF devices before Network stack init */
  101. for (i = 0; i < cgx_cnt; i++) {
  102. err = dm_pci_find_device(PCI_VENDOR_ID_CAVIUM,
  103. PCI_DEVICE_ID_CAVIUM_CGX, i, &dev);
  104. if (err)
  105. debug("%s CGX%d device not found\n", __func__, i);
  106. }
  107. err = dm_pci_find_device(PCI_VENDOR_ID_CAVIUM,
  108. PCI_DEVICE_ID_CAVIUM_RVU_AF, 0, &dev);
  109. if (err)
  110. debug("NIC AF device not found\n");
  111. }
  112. /**
  113. * Board late initialization routine.
  114. */
  115. int board_late_init(void)
  116. {
  117. char boardname[32];
  118. char boardserial[150], boardrev[150];
  119. long val;
  120. bool save_env = false;
  121. const char *str;
  122. debug("%s()\n", __func__);
  123. /*
  124. * Now that pci_init initializes env device.
  125. * Try to cleanup ethaddr env variables, this is needed
  126. * as with each boot, configuration of QLM can change.
  127. */
  128. cleanup_env_ethaddr();
  129. snprintf(boardname, sizeof(boardname), "%s> ", fdt_get_board_model());
  130. env_set("prompt", boardname);
  131. set_working_fdt_addr(env_get_hex("fdtcontroladdr", fdt_base_addr));
  132. str = fdt_get_board_revision();
  133. if (str) {
  134. snprintf(boardrev, sizeof(boardrev), "%s", str);
  135. if (env_get("boardrev") &&
  136. strcmp(boardrev, env_get("boardrev")))
  137. save_env = true;
  138. env_set("boardrev", boardrev);
  139. }
  140. str = fdt_get_board_serial();
  141. if (str) {
  142. snprintf(boardserial, sizeof(boardserial), "%s", str);
  143. if (env_get("serial#") &&
  144. strcmp(boardserial, env_get("serial#")))
  145. save_env = true;
  146. env_set("serial#", boardserial);
  147. }
  148. val = env_get_hex("disable_ooo", 0);
  149. smc_configure_ooo(val);
  150. if (IS_ENABLED(CONFIG_NET_OCTEONTX2))
  151. board_late_probe_devices();
  152. if (save_env)
  153. env_save();
  154. return 0;
  155. }
  156. /*
  157. * Invoked before relocation, so limit to stack variables.
  158. */
  159. int checkboard(void)
  160. {
  161. printf("Board: %s\n", fdt_get_board_model());
  162. return 0;
  163. }
  164. void board_acquire_flash_arb(bool acquire)
  165. {
  166. union cpc_boot_ownerx ownerx;
  167. if (!acquire) {
  168. ownerx.u = readl(CPC_BOOT_OWNERX(3));
  169. ownerx.s.boot_req = 0;
  170. writel(ownerx.u, CPC_BOOT_OWNERX(3));
  171. } else {
  172. ownerx.u = 0;
  173. ownerx.s.boot_req = 1;
  174. writel(ownerx.u, CPC_BOOT_OWNERX(3));
  175. udelay(1);
  176. do {
  177. ownerx.u = readl(CPC_BOOT_OWNERX(3));
  178. } while (ownerx.s.boot_wait);
  179. }
  180. }
  181. int last_stage_init(void)
  182. {
  183. (void)smc_flsf_fw_booted();
  184. return 0;
  185. }
  186. static int do_go_uboot(struct cmd_tbl *cmdtp, int flag, int argc,
  187. char *const argv[])
  188. {
  189. typedef void __noreturn (*uboot_entry_t)(ulong, void *);
  190. uboot_entry_t entry;
  191. ulong addr;
  192. void *fdt;
  193. if (argc < 2)
  194. return CMD_RET_USAGE;
  195. addr = simple_strtoul(argv[1], NULL, 16);
  196. fdt = board_fdt_blob_setup();
  197. entry = (uboot_entry_t)addr;
  198. flush_cache((ulong)addr, 1 << 20); /* 1MiB should be enough */
  199. dcache_disable();
  200. printf("## Starting U-Boot at %p (FDT at %p)...\n", entry, fdt);
  201. entry(0, fdt);
  202. return 0;
  203. }
  204. U_BOOT_CMD(go_uboot, 2, 0, do_go_uboot,
  205. "Start U-Boot from RAM (pass FDT via x1 register)",
  206. "");