bootoctlinux.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2020 Stefan Roese <sr@denx.de>
  4. */
  5. #include <command.h>
  6. #include <config.h>
  7. #include <cpu_func.h>
  8. #include <dm.h>
  9. #include <elf.h>
  10. #include <env.h>
  11. #include <asm/global_data.h>
  12. #include <asm/io.h>
  13. #include <linux/compat.h>
  14. #include <linux/ctype.h>
  15. #include <linux/delay.h>
  16. #include <linux/io.h>
  17. #include <mach/cvmx-coremask.h>
  18. #include <mach/cvmx-bootinfo.h>
  19. #include <mach/cvmx-bootmem.h>
  20. #include <mach/cvmx-regs.h>
  21. #include <mach/cvmx-fuse.h>
  22. #include <mach/octeon-model.h>
  23. #include <mach/octeon-feature.h>
  24. #include <mach/bootoct_cmd.h>
  25. #include <mach/cvmx-ciu-defs.h>
  26. DECLARE_GLOBAL_DATA_PTR;
  27. /* ToDo: Revisit these settings */
  28. #define OCTEON_RESERVED_LOW_MEM_SIZE (512 * 1024)
  29. #define OCTEON_RESERVED_LOW_BOOT_MEM_SIZE (1024 * 1024)
  30. #define BOOTLOADER_BOOTMEM_DESC_SPACE (1024 * 1024)
  31. /* Default stack and heap sizes, in bytes */
  32. #define DEFAULT_STACK_SIZE (1 * 1024 * 1024)
  33. #define DEFAULT_HEAP_SIZE (3 * 1024 * 1024)
  34. /**
  35. * NOTE: This must duplicate octeon_boot_descriptor_t in the toolchain
  36. * octeon-app-init.h file.
  37. */
  38. enum {
  39. /* If set, core should do app-wide init, only one core per app will have
  40. * this flag set.
  41. */
  42. BOOT_FLAG_INIT_CORE = 1,
  43. OCTEON_BL_FLAG_DEBUG = 1 << 1,
  44. OCTEON_BL_FLAG_NO_MAGIC = 1 << 2,
  45. /* If set, use uart1 for console */
  46. OCTEON_BL_FLAG_CONSOLE_UART1 = 1 << 3,
  47. OCTEON_BL_FLAG_CONSOLE_PCI = 1 << 4, /* If set, use PCI console */
  48. /* Call exit on break on serial port */
  49. OCTEON_BL_FLAG_BREAK = 1 << 5,
  50. /*
  51. * Be sure to update OCTEON_APP_INIT_H_VERSION when new fields are added
  52. * and to conditionalize the new flag's usage based on the version.
  53. */
  54. } octeon_boot_descriptor_flag;
  55. /**
  56. * NOTE: This must duplicate octeon_boot_descriptor_t in the toolchain
  57. * octeon-app-init.h file.
  58. */
  59. #ifndef OCTEON_CURRENT_DESC_VERSION
  60. # define OCTEON_CURRENT_DESC_VERSION 7
  61. #endif
  62. /**
  63. * NOTE: This must duplicate octeon_boot_descriptor_t in the toolchain
  64. * octeon-app-init.h file.
  65. */
  66. /* Version 7 changes: Change names of deprecated fields */
  67. #ifndef OCTEON_ARGV_MAX_ARGS
  68. # define OCTEON_ARGV_MAX_ARGS 64
  69. #endif
  70. /**
  71. * NOTE: This must duplicate octeon_boot_descriptor_t in the toolchain
  72. * octeon-app-init.h file.
  73. */
  74. #ifndef OCTEON_SERIAL_LEN
  75. # define OCTEON_SERIAL_LEN 20
  76. #endif
  77. /**
  78. * Bootloader structure used to pass info to Octeon executive startup code.
  79. * NOTE: all fields are deprecated except for:
  80. * * desc_version
  81. * * desc_size,
  82. * * heap_base
  83. * * heap_end
  84. * * eclock_hz
  85. * * flags
  86. * * argc
  87. * * argv
  88. * * cvmx_desc_vaddr
  89. * * debugger_flags_base_addr
  90. *
  91. * All other fields have been moved to the cvmx_descriptor, and the new
  92. * fields should be added there. They are left as placeholders in this
  93. * structure for binary compatibility.
  94. *
  95. * NOTE: This structure must match what is in the toolchain octeon-app-init.h
  96. * file.
  97. */
  98. struct octeon_boot_descriptor {
  99. /* Start of block referenced by assembly code - do not change! */
  100. u32 desc_version;
  101. u32 desc_size;
  102. u64 stack_top;
  103. u64 heap_base;
  104. u64 heap_end;
  105. u64 deprecated17;
  106. u64 deprecated16;
  107. /* End of block referenced by assembly code - do not change! */
  108. u32 deprecated18;
  109. u32 deprecated15;
  110. u32 deprecated14;
  111. u32 argc; /* argc for main() */
  112. u32 argv[OCTEON_ARGV_MAX_ARGS]; /* argv for main() */
  113. u32 flags; /* Flags for application */
  114. u32 core_mask; /* Coremask running this image */
  115. u32 dram_size; /* DEPRECATED, DRAM size in megabyes. Used up to SDK 1.8.1 */
  116. u32 phy_mem_desc_addr;
  117. u32 debugger_flags_base_addr; /* used to pass flags from app to debugger. */
  118. u32 eclock_hz; /* CPU clock speed, in hz. */
  119. u32 deprecated10;
  120. u32 deprecated9;
  121. u16 deprecated8;
  122. u8 deprecated7;
  123. u8 deprecated6;
  124. u16 deprecated5;
  125. u8 deprecated4;
  126. u8 deprecated3;
  127. char deprecated2[OCTEON_SERIAL_LEN];
  128. u8 deprecated1[6];
  129. u8 deprecated0;
  130. u64 cvmx_desc_vaddr; /* Address of cvmx descriptor */
  131. };
  132. static struct octeon_boot_descriptor boot_desc[CVMX_MIPS_MAX_CORES];
  133. static struct cvmx_bootinfo cvmx_bootinfo_array[CVMX_MIPS_MAX_CORES];
  134. /**
  135. * Programs the boot bus moveable region
  136. * @param base base address to place the boot bus moveable region
  137. * (bits [31:7])
  138. * @param region_num Selects which region, 0 or 1 for node 0,
  139. * 2 or 3 for node 1
  140. * @param enable Set true to enable, false to disable
  141. * @param data Pointer to data to put in the region, up to
  142. * 16 dwords.
  143. * @param num_words Number of data dwords (up to 32)
  144. *
  145. * @return 0 for success, -1 on error
  146. */
  147. static int octeon_set_moveable_region(u32 base, int region_num,
  148. bool enable, const u64 *data,
  149. unsigned int num_words)
  150. {
  151. int node = region_num >> 1;
  152. u64 val;
  153. int i;
  154. u8 node_mask = 0x01; /* ToDo: Currently only one node is supported */
  155. debug("%s(0x%x, %d, %d, %p, %u)\n", __func__, base, region_num, enable,
  156. data, num_words);
  157. if (num_words > 32) {
  158. printf("%s: Too many words (%d) for region %d\n", __func__,
  159. num_words, region_num);
  160. return -1;
  161. }
  162. if (base & 0x7f) {
  163. printf("%s: Error: base address 0x%x must be 128 byte aligned\n",
  164. __func__, base);
  165. return -1;
  166. }
  167. if (region_num > (node_mask > 1 ? 3 : 1)) {
  168. printf("%s: Region number %d out of range\n",
  169. __func__, region_num);
  170. return -1;
  171. }
  172. if (!data && num_words > 0) {
  173. printf("%s: Error: NULL data\n", __func__);
  174. return -1;
  175. }
  176. region_num &= 1;
  177. val = MIO_BOOT_LOC_CFG_EN |
  178. FIELD_PREP(MIO_BOOT_LOC_CFG_BASE, base >> 7);
  179. debug("%s: Setting MIO_BOOT_LOC_CFG(%d) on node %d to 0x%llx\n",
  180. __func__, region_num, node, val);
  181. csr_wr(CVMX_MIO_BOOT_LOC_CFGX(region_num & 1), val);
  182. val = FIELD_PREP(MIO_BOOT_LOC_ADR_ADR, (region_num ? 0x80 : 0x00) >> 3);
  183. debug("%s: Setting MIO_BOOT_LOC_ADR start to 0x%llx\n", __func__, val);
  184. csr_wr(CVMX_MIO_BOOT_LOC_ADR, val);
  185. for (i = 0; i < num_words; i++) {
  186. debug(" 0x%02llx: 0x%016llx\n",
  187. csr_rd(CVMX_MIO_BOOT_LOC_ADR), data[i]);
  188. csr_wr(CVMX_MIO_BOOT_LOC_DAT, data[i]);
  189. }
  190. return 0;
  191. }
  192. /**
  193. * Parse comma separated numbers into an array
  194. *
  195. * @param[out] values values read for each node
  196. * @param[in] str string to parse
  197. * @param base 0 for auto, otherwise 8, 10 or 16 for the number base
  198. *
  199. * @return number of values read.
  200. */
  201. static int octeon_parse_nodes(u64 values[CVMX_MAX_NODES],
  202. const char *str, int base)
  203. {
  204. int node = 0;
  205. char *sep;
  206. do {
  207. debug("Parsing node %d: \"%s\"\n", node, str);
  208. values[node] = simple_strtoull(str, &sep, base);
  209. debug(" node %d: 0x%llx\n", node, values[node]);
  210. str = sep + 1;
  211. } while (++node < CVMX_MAX_NODES && *sep == ',');
  212. debug("%s: returning %d\n", __func__, node);
  213. return node;
  214. }
  215. /**
  216. * Parse command line arguments
  217. *
  218. * @param argc number of arguments
  219. * @param[in] argv array of argument strings
  220. * @param cmd command type
  221. * @param[out] boot_args parsed values
  222. *
  223. * @return number of arguments parsed
  224. */
  225. int octeon_parse_bootopts(int argc, char *const argv[],
  226. enum octeon_boot_cmd_type cmd,
  227. struct octeon_boot_args *boot_args)
  228. {
  229. u64 node_values[CVMX_MAX_NODES];
  230. int arg, j;
  231. int num_values;
  232. int node;
  233. u8 node_mask = 0x01; /* ToDo: Currently only one node is supported */
  234. debug("%s(%d, %p, %d, %p)\n", __func__, argc, argv, cmd, boot_args);
  235. memset(boot_args, 0, sizeof(*boot_args));
  236. boot_args->stack_size = DEFAULT_STACK_SIZE;
  237. boot_args->heap_size = DEFAULT_HEAP_SIZE;
  238. boot_args->node_mask = 0;
  239. for (arg = 0; arg < argc; arg++) {
  240. debug(" argv[%d]: %s\n", arg, argv[arg]);
  241. if (cmd == BOOTOCT && !strncmp(argv[arg], "stack=", 6)) {
  242. boot_args->stack_size = simple_strtoul(argv[arg] + 6,
  243. NULL, 0);
  244. } else if (cmd == BOOTOCT && !strncmp(argv[arg], "heap=", 5)) {
  245. boot_args->heap_size = simple_strtoul(argv[arg] + 5,
  246. NULL, 0);
  247. } else if (!strncmp(argv[arg], "debug", 5)) {
  248. puts("setting debug flag!\n");
  249. boot_args->boot_flags |= OCTEON_BL_FLAG_DEBUG;
  250. } else if (cmd == BOOTOCT && !strncmp(argv[arg], "break", 5)) {
  251. puts("setting break flag!\n");
  252. boot_args->boot_flags |= OCTEON_BL_FLAG_BREAK;
  253. } else if (!strncmp(argv[arg], "forceboot", 9)) {
  254. boot_args->forceboot = true;
  255. } else if (!strncmp(argv[arg], "nodemask=", 9)) {
  256. boot_args->node_mask = hextoul(argv[arg] + 9, NULL);
  257. } else if (!strncmp(argv[arg], "numcores=", 9)) {
  258. memset(node_values, 0, sizeof(node_values));
  259. num_values = octeon_parse_nodes(node_values,
  260. argv[arg] + 9, 0);
  261. for (j = 0; j < num_values; j++)
  262. boot_args->num_cores[j] = node_values[j];
  263. boot_args->num_cores_set = true;
  264. } else if (!strncmp(argv[arg], "skipcores=", 10)) {
  265. memset(node_values, 0, sizeof(node_values));
  266. num_values = octeon_parse_nodes(node_values,
  267. argv[arg] + 10, 0);
  268. for (j = 0; j < num_values; j++)
  269. boot_args->num_skipped[j] = node_values[j];
  270. boot_args->num_skipped_set = true;
  271. } else if (!strncmp(argv[arg], "console_uart=", 13)) {
  272. boot_args->console_uart = simple_strtoul(argv[arg] + 13,
  273. NULL, 0);
  274. if (boot_args->console_uart == 1) {
  275. boot_args->boot_flags |=
  276. OCTEON_BL_FLAG_CONSOLE_UART1;
  277. } else if (!boot_args->console_uart) {
  278. boot_args->boot_flags &=
  279. ~OCTEON_BL_FLAG_CONSOLE_UART1;
  280. }
  281. } else if (!strncmp(argv[arg], "coremask=", 9)) {
  282. memset(node_values, 0, sizeof(node_values));
  283. num_values = octeon_parse_nodes(node_values,
  284. argv[arg] + 9, 16);
  285. for (j = 0; j < num_values; j++)
  286. cvmx_coremask_set64_node(&boot_args->coremask,
  287. j, node_values[j]);
  288. boot_args->coremask_set = true;
  289. } else if (cmd == BOOTOCTLINUX &&
  290. !strncmp(argv[arg], "namedblock=", 11)) {
  291. boot_args->named_block = argv[arg] + 11;
  292. } else if (!strncmp(argv[arg], "endbootargs", 11)) {
  293. boot_args->endbootargs = 1;
  294. arg++;
  295. if (argc >= arg && cmd != BOOTOCTLINUX)
  296. boot_args->app_name = argv[arg];
  297. break;
  298. } else {
  299. debug(" Unknown argument \"%s\"\n", argv[arg]);
  300. }
  301. }
  302. if (boot_args->coremask_set && boot_args->num_cores_set) {
  303. puts("Warning: both coremask and numcores are set, using coremask.\n");
  304. } else if (!boot_args->coremask_set && !boot_args->num_cores_set) {
  305. cvmx_coremask_set_core(&boot_args->coremask, 0);
  306. boot_args->coremask_set = true;
  307. } else if ((!boot_args->coremask_set) && boot_args->num_cores_set) {
  308. cvmx_coremask_for_each_node(node, node_mask)
  309. cvmx_coremask_set64_node(&boot_args->coremask, node,
  310. ((1ull << boot_args->num_cores[node]) - 1) <<
  311. boot_args->num_skipped[node]);
  312. boot_args->coremask_set = true;
  313. }
  314. /* Update the node mask based on the coremask or the number of cores */
  315. for (j = 0; j < CVMX_MAX_NODES; j++) {
  316. if (cvmx_coremask_get64_node(&boot_args->coremask, j))
  317. boot_args->node_mask |= 1 << j;
  318. }
  319. debug("%s: return %d\n", __func__, arg);
  320. return arg;
  321. }
  322. int do_bootoctlinux(struct cmd_tbl *cmdtp, int flag, int argc,
  323. char *const argv[])
  324. {
  325. typedef void __noreturn (*kernel_entry_t)(int, ulong, ulong, ulong);
  326. kernel_entry_t kernel;
  327. struct octeon_boot_args boot_args;
  328. int arg_start = 1;
  329. int arg_count;
  330. u64 addr = 0; /* Address of the ELF image */
  331. int arg0;
  332. u64 arg1;
  333. u64 arg2;
  334. u64 arg3;
  335. int ret;
  336. struct cvmx_coremask core_mask;
  337. struct cvmx_coremask coremask_to_run;
  338. struct cvmx_coremask avail_coremask;
  339. int first_core;
  340. int core;
  341. const u64 *nmi_code;
  342. int num_dwords;
  343. u8 node_mask = 0x01;
  344. int i;
  345. cvmx_coremask_clear_all(&core_mask);
  346. cvmx_coremask_clear_all(&coremask_to_run);
  347. if (argc >= 2 && (isxdigit(argv[1][0]) && (isxdigit(argv[1][1]) ||
  348. argv[1][1] == 'x' ||
  349. argv[1][1] == 'X' ||
  350. argv[1][1] == '\0'))) {
  351. addr = hextoul(argv[1], NULL);
  352. if (!addr)
  353. addr = CONFIG_SYS_LOAD_ADDR;
  354. arg_start++;
  355. }
  356. if (addr == 0)
  357. addr = CONFIG_SYS_LOAD_ADDR;
  358. debug("%s: arg start: %d\n", __func__, arg_start);
  359. arg_count = octeon_parse_bootopts(argc - arg_start, argv + arg_start,
  360. BOOTOCTLINUX, &boot_args);
  361. debug("%s:\n"
  362. " named block: %s\n"
  363. " node mask: 0x%x\n"
  364. " stack size: 0x%x\n"
  365. " heap size: 0x%x\n"
  366. " boot flags: 0x%x\n"
  367. " force boot: %s\n"
  368. " coremask set: %s\n"
  369. " num cores set: %s\n"
  370. " num skipped set: %s\n"
  371. " endbootargs: %s\n",
  372. __func__,
  373. boot_args.named_block ? boot_args.named_block : "none",
  374. boot_args.node_mask,
  375. boot_args.stack_size,
  376. boot_args.heap_size,
  377. boot_args.boot_flags,
  378. boot_args.forceboot ? "true" : "false",
  379. boot_args.coremask_set ? "true" : "false",
  380. boot_args.num_cores_set ? "true" : "false",
  381. boot_args.num_skipped_set ? "true" : "false",
  382. boot_args.endbootargs ? "true" : "false");
  383. debug(" num cores: ");
  384. for (i = 0; i < CVMX_MAX_NODES; i++)
  385. debug("%s%d", i > 0 ? ", " : "", boot_args.num_cores[i]);
  386. debug("\n num skipped: ");
  387. for (i = 0; i < CVMX_MAX_NODES; i++) {
  388. debug("%s%d", i > 0 ? ", " : "", boot_args.num_skipped[i]);
  389. debug("\n coremask:\n");
  390. cvmx_coremask_dprint(&boot_args.coremask);
  391. }
  392. if (boot_args.endbootargs) {
  393. debug("endbootargs set, adjusting argc from %d to %d, arg_count: %d, arg_start: %d\n",
  394. argc, argc - (arg_count + arg_start), arg_count,
  395. arg_start);
  396. argc -= (arg_count + arg_start);
  397. argv += (arg_count + arg_start);
  398. }
  399. /*
  400. * numcores specification overrides a coremask on the same command line
  401. */
  402. cvmx_coremask_copy(&core_mask, &boot_args.coremask);
  403. /*
  404. * Remove cores from coremask based on environment variable stored in
  405. * flash
  406. */
  407. if (validate_coremask(&core_mask) != 0) {
  408. puts("Invalid coremask.\n");
  409. return 1;
  410. } else if (cvmx_coremask_is_empty(&core_mask)) {
  411. puts("Coremask is empty after coremask_override mask. Nothing to do.\n");
  412. return 0;
  413. }
  414. if (cvmx_coremask_intersects(&core_mask, &coremask_to_run)) {
  415. puts("ERROR: Can't load code on core twice! Provided coremask:\n");
  416. cvmx_coremask_print(&core_mask);
  417. puts("overlaps previously loaded coremask:\n");
  418. cvmx_coremask_print(&coremask_to_run);
  419. return -1;
  420. }
  421. debug("Setting up boot descriptor block with core mask:\n");
  422. cvmx_coremask_dprint(&core_mask);
  423. /*
  424. * Add coremask to global mask of cores that have been set up and are
  425. * runable
  426. */
  427. cvmx_coremask_or(&coremask_to_run, &coremask_to_run, &core_mask);
  428. /*
  429. * Load kernel ELF image, or try binary if ELF is not detected.
  430. * This way the much smaller vmlinux.bin can also be started but
  431. * has to be loaded at the correct address (ep as parameter).
  432. */
  433. if (!valid_elf_image(addr))
  434. printf("Booting binary image instead (vmlinux.bin)...\n");
  435. else
  436. addr = load_elf_image_shdr(addr);
  437. /* Set kernel entry point */
  438. kernel = (kernel_entry_t)addr;
  439. /* Init bootmem list for Linux kernel booting */
  440. if (!cvmx_bootmem_phy_mem_list_init(
  441. gd->ram_size, OCTEON_RESERVED_LOW_MEM_SIZE,
  442. (void *)CKSEG0ADDR(BOOTLOADER_BOOTMEM_DESC_SPACE))) {
  443. printf("FATAL: Error initializing free memory list\n");
  444. return 0;
  445. }
  446. first_core = cvmx_coremask_get_first_core(&coremask_to_run);
  447. cvmx_coremask_for_each_core(core, &coremask_to_run) {
  448. debug("%s: Activating core %d\n", __func__, core);
  449. cvmx_bootinfo_array[core].core_mask =
  450. cvmx_coremask_get32(&coremask_to_run);
  451. cvmx_coremask_copy(&cvmx_bootinfo_array[core].ext_core_mask,
  452. &coremask_to_run);
  453. if (core == first_core)
  454. cvmx_bootinfo_array[core].flags |= BOOT_FLAG_INIT_CORE;
  455. cvmx_bootinfo_array[core].dram_size = gd->ram_size /
  456. (1024 * 1024);
  457. cvmx_bootinfo_array[core].dclock_hz = gd->mem_clk * 1000000;
  458. cvmx_bootinfo_array[core].eclock_hz = gd->cpu_clk;
  459. cvmx_bootinfo_array[core].led_display_base_addr = 0;
  460. cvmx_bootinfo_array[core].phy_mem_desc_addr =
  461. ((u32)(u64)__cvmx_bootmem_internal_get_desc_ptr()) &
  462. 0x7ffffff;
  463. cvmx_bootinfo_array[core].major_version = CVMX_BOOTINFO_MAJ_VER;
  464. cvmx_bootinfo_array[core].minor_version = CVMX_BOOTINFO_MIN_VER;
  465. cvmx_bootinfo_array[core].fdt_addr = virt_to_phys(gd->fdt_blob);
  466. boot_desc[core].dram_size = gd->ram_size / (1024 * 1024);
  467. boot_desc[core].cvmx_desc_vaddr =
  468. virt_to_phys(&cvmx_bootinfo_array[core]);
  469. boot_desc[core].desc_version = OCTEON_CURRENT_DESC_VERSION;
  470. boot_desc[core].desc_size = sizeof(boot_desc[0]);
  471. boot_desc[core].flags = cvmx_bootinfo_array[core].flags;
  472. boot_desc[core].eclock_hz = cvmx_bootinfo_array[core].eclock_hz;
  473. boot_desc[core].argc = argc;
  474. for (i = 0; i < argc; i++)
  475. boot_desc[core].argv[i] = (u32)virt_to_phys(argv[i]);
  476. }
  477. core = 0;
  478. arg0 = argc;
  479. arg1 = (u64)argv;
  480. arg2 = 0x1; /* Core 0 sets init core for Linux */
  481. arg3 = XKPHYS | virt_to_phys(&boot_desc[core]);
  482. debug("## Transferring control to Linux (at address %p) ...\n", kernel);
  483. /*
  484. * Flush cache before jumping to application. Let's flush the
  485. * whole SDRAM area, since we don't know the size of the image
  486. * that was loaded.
  487. */
  488. flush_cache(gd->ram_base, gd->ram_top - gd->ram_base);
  489. /* Take all cores out of reset */
  490. csr_wr(CVMX_CIU_PP_RST, 0);
  491. sync();
  492. /* Wait a short while for the other cores... */
  493. mdelay(100);
  494. /* Install boot code into moveable bus for NMI (other cores) */
  495. nmi_code = (const u64 *)nmi_bootvector;
  496. num_dwords = (((u64)&nmi_handler_para[0] - (u64)nmi_code) + 7) / 8;
  497. ret = octeon_set_moveable_region(0x1fc00000, 0, true, nmi_code,
  498. num_dwords);
  499. if (ret) {
  500. printf("Error installing NMI handler for SMP core startup\n");
  501. return 0;
  502. }
  503. /* Write NMI handler parameters for Linux kernel booting */
  504. nmi_handler_para[0] = (u64)kernel;
  505. nmi_handler_para[1] = arg0;
  506. nmi_handler_para[2] = arg1;
  507. nmi_handler_para[3] = 0; /* Don't set init core for secondary cores */
  508. nmi_handler_para[4] = arg3;
  509. sync();
  510. /* Wait a short while for the other cores... */
  511. mdelay(100);
  512. /*
  513. * Cores have already been taken out of reset to conserve power.
  514. * We need to send a NMI to get the cores out of their wait loop
  515. */
  516. octeon_get_available_coremask(&avail_coremask);
  517. debug("Available coremask:\n");
  518. cvmx_coremask_dprint(&avail_coremask);
  519. debug("Starting coremask:\n");
  520. cvmx_coremask_dprint(&coremask_to_run);
  521. debug("Sending NMIs to other cores\n");
  522. if (octeon_has_feature(OCTEON_FEATURE_CIU3)) {
  523. u64 avail_cm;
  524. int node;
  525. cvmx_coremask_for_each_node(node, node_mask) {
  526. avail_cm = cvmx_coremask_get64_node(&avail_coremask,
  527. node);
  528. if (avail_cm != 0) {
  529. debug("Sending NMI to node %d, coremask=0x%llx, CIU3_NMI=0x%llx\n",
  530. node, avail_cm,
  531. (node > 0 ? -1ull : -2ull) & avail_cm);
  532. csr_wr(CVMX_CIU3_NMI,
  533. (node > 0 ? -1ull : -2ull) & avail_cm);
  534. }
  535. }
  536. } else {
  537. csr_wr(CVMX_CIU_NMI,
  538. -2ull & cvmx_coremask_get64(&avail_coremask));
  539. }
  540. debug("Done sending NMIs\n");
  541. /* Wait a short while for the other cores... */
  542. mdelay(100);
  543. /*
  544. * pass address parameter as argv[0] (aka command name),
  545. * and all remaining args
  546. * a0 = argc
  547. * a1 = argv (32 bit physical addresses, not pointers)
  548. * a2 = init core
  549. * a3 = boot descriptor address
  550. * a4/t0 = entry point (only used by assembly stub)
  551. */
  552. kernel(arg0, arg1, arg2, arg3);
  553. return 0;
  554. }
  555. U_BOOT_CMD(bootoctlinux, 32, 0, do_bootoctlinux,
  556. "Boot from a linux ELF image in memory",
  557. "elf_address [coremask=mask_to_run | numcores=core_cnt_to_run] "
  558. "[forceboot] [skipcores=core_cnt_to_skip] [namedblock=name] [endbootargs] [app_args ...]\n"
  559. "elf_address - address of ELF image to load. If 0, default load address\n"
  560. " is used.\n"
  561. "coremask - mask of cores to run on. Anded with coremask_override\n"
  562. " environment variable to ensure only working cores are used\n"
  563. "numcores - number of cores to run on. Runs on specified number of cores,\n"
  564. " taking into account the coremask_override.\n"
  565. "skipcores - only meaningful with numcores. Skips this many cores\n"
  566. " (starting from 0) when loading the numcores cores.\n"
  567. " For example, setting skipcores to 1 will skip core 0\n"
  568. " and load the application starting at the next available core.\n"
  569. "forceboot - if set, boots application even if core 0 is not in mask\n"
  570. "namedblock - specifies a named block to load the kernel\n"
  571. "endbootargs - if set, bootloader does not process any further arguments and\n"
  572. " only passes the arguments that follow to the kernel.\n"
  573. " If not set, the kernel gets the entire commnad line as\n"
  574. " arguments.\n" "\n");