setup.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 2004-2007 Cavium Networks
  7. * Copyright (C) 2008, 2009 Wind River Systems
  8. * written by Ralf Baechle <ralf@linux-mips.org>
  9. */
  10. #include <linux/compiler.h>
  11. #include <linux/vmalloc.h>
  12. #include <linux/init.h>
  13. #include <linux/kernel.h>
  14. #include <linux/console.h>
  15. #include <linux/delay.h>
  16. #include <linux/export.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/io.h>
  19. #include <linux/serial.h>
  20. #include <linux/smp.h>
  21. #include <linux/types.h>
  22. #include <linux/string.h> /* for memset */
  23. #include <linux/tty.h>
  24. #include <linux/time.h>
  25. #include <linux/platform_device.h>
  26. #include <linux/serial_core.h>
  27. #include <linux/serial_8250.h>
  28. #include <linux/of_fdt.h>
  29. #include <linux/libfdt.h>
  30. #include <linux/kexec.h>
  31. #include <asm/processor.h>
  32. #include <asm/reboot.h>
  33. #include <asm/smp-ops.h>
  34. #include <asm/irq_cpu.h>
  35. #include <asm/mipsregs.h>
  36. #include <asm/bootinfo.h>
  37. #include <asm/sections.h>
  38. #include <asm/time.h>
  39. #include <asm/octeon/octeon.h>
  40. #include <asm/octeon/pci-octeon.h>
  41. #include <asm/octeon/cvmx-rst-defs.h>
  42. /*
  43. * TRUE for devices having registers with little-endian byte
  44. * order, FALSE for registers with native-endian byte order.
  45. * PCI mandates little-endian, USB and SATA are configuraable,
  46. * but we chose little-endian for these.
  47. */
  48. const bool octeon_should_swizzle_table[256] = {
  49. [0x00] = true, /* bootbus/CF */
  50. [0x1b] = true, /* PCI mmio window */
  51. [0x1c] = true, /* PCI mmio window */
  52. [0x1d] = true, /* PCI mmio window */
  53. [0x1e] = true, /* PCI mmio window */
  54. [0x68] = true, /* OCTEON III USB */
  55. [0x69] = true, /* OCTEON III USB */
  56. [0x6c] = true, /* OCTEON III SATA */
  57. [0x6f] = true, /* OCTEON II USB */
  58. };
  59. EXPORT_SYMBOL(octeon_should_swizzle_table);
  60. #ifdef CONFIG_PCI
  61. extern void pci_console_init(const char *arg);
  62. #endif
  63. static unsigned long long max_memory = ULLONG_MAX;
  64. static unsigned long long reserve_low_mem;
  65. DEFINE_SEMAPHORE(octeon_bootbus_sem);
  66. EXPORT_SYMBOL(octeon_bootbus_sem);
  67. struct octeon_boot_descriptor *octeon_boot_desc_ptr;
  68. struct cvmx_bootinfo *octeon_bootinfo;
  69. EXPORT_SYMBOL(octeon_bootinfo);
  70. #ifdef CONFIG_KEXEC
  71. #ifdef CONFIG_SMP
  72. /*
  73. * Wait for relocation code is prepared and send
  74. * secondary CPUs to spin until kernel is relocated.
  75. */
  76. static void octeon_kexec_smp_down(void *ignored)
  77. {
  78. int cpu = smp_processor_id();
  79. local_irq_disable();
  80. set_cpu_online(cpu, false);
  81. while (!atomic_read(&kexec_ready_to_reboot))
  82. cpu_relax();
  83. asm volatile (
  84. " sync \n"
  85. " synci ($0) \n");
  86. relocated_kexec_smp_wait(NULL);
  87. }
  88. #endif
  89. #define OCTEON_DDR0_BASE (0x0ULL)
  90. #define OCTEON_DDR0_SIZE (0x010000000ULL)
  91. #define OCTEON_DDR1_BASE (0x410000000ULL)
  92. #define OCTEON_DDR1_SIZE (0x010000000ULL)
  93. #define OCTEON_DDR2_BASE (0x020000000ULL)
  94. #define OCTEON_DDR2_SIZE (0x3e0000000ULL)
  95. #define OCTEON_MAX_PHY_MEM_SIZE (16*1024*1024*1024ULL)
  96. static struct kimage *kimage_ptr;
  97. static void kexec_bootmem_init(uint64_t mem_size, uint32_t low_reserved_bytes)
  98. {
  99. int64_t addr;
  100. struct cvmx_bootmem_desc *bootmem_desc;
  101. bootmem_desc = cvmx_bootmem_get_desc();
  102. if (mem_size > OCTEON_MAX_PHY_MEM_SIZE) {
  103. mem_size = OCTEON_MAX_PHY_MEM_SIZE;
  104. pr_err("Error: requested memory too large,"
  105. "truncating to maximum size\n");
  106. }
  107. bootmem_desc->major_version = CVMX_BOOTMEM_DESC_MAJ_VER;
  108. bootmem_desc->minor_version = CVMX_BOOTMEM_DESC_MIN_VER;
  109. addr = (OCTEON_DDR0_BASE + reserve_low_mem + low_reserved_bytes);
  110. bootmem_desc->head_addr = 0;
  111. if (mem_size <= OCTEON_DDR0_SIZE) {
  112. __cvmx_bootmem_phy_free(addr,
  113. mem_size - reserve_low_mem -
  114. low_reserved_bytes, 0);
  115. return;
  116. }
  117. __cvmx_bootmem_phy_free(addr,
  118. OCTEON_DDR0_SIZE - reserve_low_mem -
  119. low_reserved_bytes, 0);
  120. mem_size -= OCTEON_DDR0_SIZE;
  121. if (mem_size > OCTEON_DDR1_SIZE) {
  122. __cvmx_bootmem_phy_free(OCTEON_DDR1_BASE, OCTEON_DDR1_SIZE, 0);
  123. __cvmx_bootmem_phy_free(OCTEON_DDR2_BASE,
  124. mem_size - OCTEON_DDR1_SIZE, 0);
  125. } else
  126. __cvmx_bootmem_phy_free(OCTEON_DDR1_BASE, mem_size, 0);
  127. }
  128. static int octeon_kexec_prepare(struct kimage *image)
  129. {
  130. int i;
  131. char *bootloader = "kexec";
  132. octeon_boot_desc_ptr->argc = 0;
  133. for (i = 0; i < image->nr_segments; i++) {
  134. if (!strncmp(bootloader, (char *)image->segment[i].buf,
  135. strlen(bootloader))) {
  136. /*
  137. * convert command line string to array
  138. * of parameters (as bootloader does).
  139. */
  140. int argc = 0, offt;
  141. char *str = (char *)image->segment[i].buf;
  142. char *ptr = strchr(str, ' ');
  143. while (ptr && (OCTEON_ARGV_MAX_ARGS > argc)) {
  144. *ptr = '\0';
  145. if (ptr[1] != ' ') {
  146. offt = (int)(ptr - str + 1);
  147. octeon_boot_desc_ptr->argv[argc] =
  148. image->segment[i].mem + offt;
  149. argc++;
  150. }
  151. ptr = strchr(ptr + 1, ' ');
  152. }
  153. octeon_boot_desc_ptr->argc = argc;
  154. break;
  155. }
  156. }
  157. /*
  158. * Information about segments will be needed during pre-boot memory
  159. * initialization.
  160. */
  161. kimage_ptr = image;
  162. return 0;
  163. }
  164. static void octeon_generic_shutdown(void)
  165. {
  166. int i;
  167. #ifdef CONFIG_SMP
  168. int cpu;
  169. #endif
  170. struct cvmx_bootmem_desc *bootmem_desc;
  171. void *named_block_array_ptr;
  172. bootmem_desc = cvmx_bootmem_get_desc();
  173. named_block_array_ptr =
  174. cvmx_phys_to_ptr(bootmem_desc->named_block_array_addr);
  175. #ifdef CONFIG_SMP
  176. /* disable watchdogs */
  177. for_each_online_cpu(cpu)
  178. cvmx_write_csr(CVMX_CIU_WDOGX(cpu_logical_map(cpu)), 0);
  179. #else
  180. cvmx_write_csr(CVMX_CIU_WDOGX(cvmx_get_core_num()), 0);
  181. #endif
  182. if (kimage_ptr != kexec_crash_image) {
  183. memset(named_block_array_ptr,
  184. 0x0,
  185. CVMX_BOOTMEM_NUM_NAMED_BLOCKS *
  186. sizeof(struct cvmx_bootmem_named_block_desc));
  187. /*
  188. * Mark all memory (except low 0x100000 bytes) as free.
  189. * It is the same thing that bootloader does.
  190. */
  191. kexec_bootmem_init(octeon_bootinfo->dram_size*1024ULL*1024ULL,
  192. 0x100000);
  193. /*
  194. * Allocate all segments to avoid their corruption during boot.
  195. */
  196. for (i = 0; i < kimage_ptr->nr_segments; i++)
  197. cvmx_bootmem_alloc_address(
  198. kimage_ptr->segment[i].memsz + 2*PAGE_SIZE,
  199. kimage_ptr->segment[i].mem - PAGE_SIZE,
  200. PAGE_SIZE);
  201. } else {
  202. /*
  203. * Do not mark all memory as free. Free only named sections
  204. * leaving the rest of memory unchanged.
  205. */
  206. struct cvmx_bootmem_named_block_desc *ptr =
  207. (struct cvmx_bootmem_named_block_desc *)
  208. named_block_array_ptr;
  209. for (i = 0; i < bootmem_desc->named_block_num_blocks; i++)
  210. if (ptr[i].size)
  211. cvmx_bootmem_free_named(ptr[i].name);
  212. }
  213. kexec_args[2] = 1UL; /* running on octeon_main_processor */
  214. kexec_args[3] = (unsigned long)octeon_boot_desc_ptr;
  215. #ifdef CONFIG_SMP
  216. secondary_kexec_args[2] = 0UL; /* running on secondary cpu */
  217. secondary_kexec_args[3] = (unsigned long)octeon_boot_desc_ptr;
  218. #endif
  219. }
  220. static void octeon_shutdown(void)
  221. {
  222. octeon_generic_shutdown();
  223. #ifdef CONFIG_SMP
  224. smp_call_function(octeon_kexec_smp_down, NULL, 0);
  225. smp_wmb();
  226. while (num_online_cpus() > 1) {
  227. cpu_relax();
  228. mdelay(1);
  229. }
  230. #endif
  231. }
  232. static void octeon_crash_shutdown(struct pt_regs *regs)
  233. {
  234. octeon_generic_shutdown();
  235. default_machine_crash_shutdown(regs);
  236. }
  237. #ifdef CONFIG_SMP
  238. void octeon_crash_smp_send_stop(void)
  239. {
  240. int cpu;
  241. /* disable watchdogs */
  242. for_each_online_cpu(cpu)
  243. cvmx_write_csr(CVMX_CIU_WDOGX(cpu_logical_map(cpu)), 0);
  244. }
  245. #endif
  246. #endif /* CONFIG_KEXEC */
  247. #ifdef CONFIG_CAVIUM_RESERVE32
  248. uint64_t octeon_reserve32_memory;
  249. EXPORT_SYMBOL(octeon_reserve32_memory);
  250. #endif
  251. #ifdef CONFIG_KEXEC
  252. /* crashkernel cmdline parameter is parsed _after_ memory setup
  253. * we also parse it here (workaround for EHB5200) */
  254. static uint64_t crashk_size, crashk_base;
  255. #endif
  256. static int octeon_uart;
  257. extern asmlinkage void handle_int(void);
  258. /**
  259. * Return non zero if we are currently running in the Octeon simulator
  260. *
  261. * Returns
  262. */
  263. int octeon_is_simulation(void)
  264. {
  265. return octeon_bootinfo->board_type == CVMX_BOARD_TYPE_SIM;
  266. }
  267. EXPORT_SYMBOL(octeon_is_simulation);
  268. /**
  269. * Return true if Octeon is in PCI Host mode. This means
  270. * Linux can control the PCI bus.
  271. *
  272. * Returns Non zero if Octeon in host mode.
  273. */
  274. int octeon_is_pci_host(void)
  275. {
  276. #ifdef CONFIG_PCI
  277. return octeon_bootinfo->config_flags & CVMX_BOOTINFO_CFG_FLAG_PCI_HOST;
  278. #else
  279. return 0;
  280. #endif
  281. }
  282. /**
  283. * Get the clock rate of Octeon
  284. *
  285. * Returns Clock rate in HZ
  286. */
  287. uint64_t octeon_get_clock_rate(void)
  288. {
  289. struct cvmx_sysinfo *sysinfo = cvmx_sysinfo_get();
  290. return sysinfo->cpu_clock_hz;
  291. }
  292. EXPORT_SYMBOL(octeon_get_clock_rate);
  293. static u64 octeon_io_clock_rate;
  294. u64 octeon_get_io_clock_rate(void)
  295. {
  296. return octeon_io_clock_rate;
  297. }
  298. EXPORT_SYMBOL(octeon_get_io_clock_rate);
  299. /**
  300. * Write to the LCD display connected to the bootbus. This display
  301. * exists on most Cavium evaluation boards. If it doesn't exist, then
  302. * this function doesn't do anything.
  303. *
  304. * @s: String to write
  305. */
  306. void octeon_write_lcd(const char *s)
  307. {
  308. if (octeon_bootinfo->led_display_base_addr) {
  309. void __iomem *lcd_address =
  310. ioremap_nocache(octeon_bootinfo->led_display_base_addr,
  311. 8);
  312. int i;
  313. for (i = 0; i < 8; i++, s++) {
  314. if (*s)
  315. iowrite8(*s, lcd_address + i);
  316. else
  317. iowrite8(' ', lcd_address + i);
  318. }
  319. iounmap(lcd_address);
  320. }
  321. }
  322. /**
  323. * Return the console uart passed by the bootloader
  324. *
  325. * Returns uart (0 or 1)
  326. */
  327. int octeon_get_boot_uart(void)
  328. {
  329. int uart;
  330. #ifdef CONFIG_CAVIUM_OCTEON_2ND_KERNEL
  331. uart = 1;
  332. #else
  333. uart = (octeon_boot_desc_ptr->flags & OCTEON_BL_FLAG_CONSOLE_UART1) ?
  334. 1 : 0;
  335. #endif
  336. return uart;
  337. }
  338. /**
  339. * Get the coremask Linux was booted on.
  340. *
  341. * Returns Core mask
  342. */
  343. int octeon_get_boot_coremask(void)
  344. {
  345. return octeon_boot_desc_ptr->core_mask;
  346. }
  347. /**
  348. * Check the hardware BIST results for a CPU
  349. */
  350. void octeon_check_cpu_bist(void)
  351. {
  352. const int coreid = cvmx_get_core_num();
  353. unsigned long long mask;
  354. unsigned long long bist_val;
  355. /* Check BIST results for COP0 registers */
  356. mask = 0x1f00000000ull;
  357. bist_val = read_octeon_c0_icacheerr();
  358. if (bist_val & mask)
  359. pr_err("Core%d BIST Failure: CacheErr(icache) = 0x%llx\n",
  360. coreid, bist_val);
  361. bist_val = read_octeon_c0_dcacheerr();
  362. if (bist_val & 1)
  363. pr_err("Core%d L1 Dcache parity error: "
  364. "CacheErr(dcache) = 0x%llx\n",
  365. coreid, bist_val);
  366. mask = 0xfc00000000000000ull;
  367. bist_val = read_c0_cvmmemctl();
  368. if (bist_val & mask)
  369. pr_err("Core%d BIST Failure: COP0_CVM_MEM_CTL = 0x%llx\n",
  370. coreid, bist_val);
  371. write_octeon_c0_dcacheerr(0);
  372. }
  373. /**
  374. * Reboot Octeon
  375. *
  376. * @command: Command to pass to the bootloader. Currently ignored.
  377. */
  378. static void octeon_restart(char *command)
  379. {
  380. /* Disable all watchdogs before soft reset. They don't get cleared */
  381. #ifdef CONFIG_SMP
  382. int cpu;
  383. for_each_online_cpu(cpu)
  384. cvmx_write_csr(CVMX_CIU_WDOGX(cpu_logical_map(cpu)), 0);
  385. #else
  386. cvmx_write_csr(CVMX_CIU_WDOGX(cvmx_get_core_num()), 0);
  387. #endif
  388. mb();
  389. while (1)
  390. if (OCTEON_IS_OCTEON3())
  391. cvmx_write_csr(CVMX_RST_SOFT_RST, 1);
  392. else
  393. cvmx_write_csr(CVMX_CIU_SOFT_RST, 1);
  394. }
  395. /**
  396. * Permanently stop a core.
  397. *
  398. * @arg: Ignored.
  399. */
  400. static void octeon_kill_core(void *arg)
  401. {
  402. if (octeon_is_simulation())
  403. /* A break instruction causes the simulator stop a core */
  404. asm volatile ("break" ::: "memory");
  405. local_irq_disable();
  406. /* Disable watchdog on this core. */
  407. cvmx_write_csr(CVMX_CIU_WDOGX(cvmx_get_core_num()), 0);
  408. /* Spin in a low power mode. */
  409. while (true)
  410. asm volatile ("wait" ::: "memory");
  411. }
  412. /**
  413. * Halt the system
  414. */
  415. static void octeon_halt(void)
  416. {
  417. smp_call_function(octeon_kill_core, NULL, 0);
  418. switch (octeon_bootinfo->board_type) {
  419. case CVMX_BOARD_TYPE_NAO38:
  420. /* Driving a 1 to GPIO 12 shuts off this board */
  421. cvmx_write_csr(CVMX_GPIO_BIT_CFGX(12), 1);
  422. cvmx_write_csr(CVMX_GPIO_TX_SET, 0x1000);
  423. break;
  424. default:
  425. octeon_write_lcd("PowerOff");
  426. break;
  427. }
  428. octeon_kill_core(NULL);
  429. }
  430. static char __read_mostly octeon_system_type[80];
  431. static void __init init_octeon_system_type(void)
  432. {
  433. char const *board_type;
  434. board_type = cvmx_board_type_to_string(octeon_bootinfo->board_type);
  435. if (board_type == NULL) {
  436. struct device_node *root;
  437. int ret;
  438. root = of_find_node_by_path("/");
  439. ret = of_property_read_string(root, "model", &board_type);
  440. of_node_put(root);
  441. if (ret)
  442. board_type = "Unsupported Board";
  443. }
  444. snprintf(octeon_system_type, sizeof(octeon_system_type), "%s (%s)",
  445. board_type, octeon_model_get_string(read_c0_prid()));
  446. }
  447. /**
  448. * Return a string representing the system type
  449. *
  450. * Returns
  451. */
  452. const char *octeon_board_type_string(void)
  453. {
  454. return octeon_system_type;
  455. }
  456. const char *get_system_type(void)
  457. __attribute__ ((alias("octeon_board_type_string")));
  458. void octeon_user_io_init(void)
  459. {
  460. union octeon_cvmemctl cvmmemctl;
  461. /* Get the current settings for CP0_CVMMEMCTL_REG */
  462. cvmmemctl.u64 = read_c0_cvmmemctl();
  463. /* R/W If set, marked write-buffer entries time out the same
  464. * as as other entries; if clear, marked write-buffer entries
  465. * use the maximum timeout. */
  466. cvmmemctl.s.dismarkwblongto = 1;
  467. /* R/W If set, a merged store does not clear the write-buffer
  468. * entry timeout state. */
  469. cvmmemctl.s.dismrgclrwbto = 0;
  470. /* R/W Two bits that are the MSBs of the resultant CVMSEG LM
  471. * word location for an IOBDMA. The other 8 bits come from the
  472. * SCRADDR field of the IOBDMA. */
  473. cvmmemctl.s.iobdmascrmsb = 0;
  474. /* R/W If set, SYNCWS and SYNCS only order marked stores; if
  475. * clear, SYNCWS and SYNCS only order unmarked
  476. * stores. SYNCWSMARKED has no effect when DISSYNCWS is
  477. * set. */
  478. cvmmemctl.s.syncwsmarked = 0;
  479. /* R/W If set, SYNCWS acts as SYNCW and SYNCS acts as SYNC. */
  480. cvmmemctl.s.dissyncws = 0;
  481. /* R/W If set, no stall happens on write buffer full. */
  482. if (OCTEON_IS_MODEL(OCTEON_CN38XX_PASS2))
  483. cvmmemctl.s.diswbfst = 1;
  484. else
  485. cvmmemctl.s.diswbfst = 0;
  486. /* R/W If set (and SX set), supervisor-level loads/stores can
  487. * use XKPHYS addresses with <48>==0 */
  488. cvmmemctl.s.xkmemenas = 0;
  489. /* R/W If set (and UX set), user-level loads/stores can use
  490. * XKPHYS addresses with VA<48>==0 */
  491. cvmmemctl.s.xkmemenau = 0;
  492. /* R/W If set (and SX set), supervisor-level loads/stores can
  493. * use XKPHYS addresses with VA<48>==1 */
  494. cvmmemctl.s.xkioenas = 0;
  495. /* R/W If set (and UX set), user-level loads/stores can use
  496. * XKPHYS addresses with VA<48>==1 */
  497. cvmmemctl.s.xkioenau = 0;
  498. /* R/W If set, all stores act as SYNCW (NOMERGE must be set
  499. * when this is set) RW, reset to 0. */
  500. cvmmemctl.s.allsyncw = 0;
  501. /* R/W If set, no stores merge, and all stores reach the
  502. * coherent bus in order. */
  503. cvmmemctl.s.nomerge = 0;
  504. /* R/W Selects the bit in the counter used for DID time-outs 0
  505. * = 231, 1 = 230, 2 = 229, 3 = 214. Actual time-out is
  506. * between 1x and 2x this interval. For example, with
  507. * DIDTTO=3, expiration interval is between 16K and 32K. */
  508. cvmmemctl.s.didtto = 0;
  509. /* R/W If set, the (mem) CSR clock never turns off. */
  510. cvmmemctl.s.csrckalwys = 0;
  511. /* R/W If set, mclk never turns off. */
  512. cvmmemctl.s.mclkalwys = 0;
  513. /* R/W Selects the bit in the counter used for write buffer
  514. * flush time-outs (WBFLT+11) is the bit position in an
  515. * internal counter used to determine expiration. The write
  516. * buffer expires between 1x and 2x this interval. For
  517. * example, with WBFLT = 0, a write buffer expires between 2K
  518. * and 4K cycles after the write buffer entry is allocated. */
  519. cvmmemctl.s.wbfltime = 0;
  520. /* R/W If set, do not put Istream in the L2 cache. */
  521. cvmmemctl.s.istrnol2 = 0;
  522. /*
  523. * R/W The write buffer threshold. As per erratum Core-14752
  524. * for CN63XX, a sc/scd might fail if the write buffer is
  525. * full. Lowering WBTHRESH greatly lowers the chances of the
  526. * write buffer ever being full and triggering the erratum.
  527. */
  528. if (OCTEON_IS_MODEL(OCTEON_CN63XX_PASS1_X))
  529. cvmmemctl.s.wbthresh = 4;
  530. else
  531. cvmmemctl.s.wbthresh = 10;
  532. /* R/W If set, CVMSEG is available for loads/stores in
  533. * kernel/debug mode. */
  534. #if CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE > 0
  535. cvmmemctl.s.cvmsegenak = 1;
  536. #else
  537. cvmmemctl.s.cvmsegenak = 0;
  538. #endif
  539. /* R/W If set, CVMSEG is available for loads/stores in
  540. * supervisor mode. */
  541. cvmmemctl.s.cvmsegenas = 0;
  542. /* R/W If set, CVMSEG is available for loads/stores in user
  543. * mode. */
  544. cvmmemctl.s.cvmsegenau = 0;
  545. write_c0_cvmmemctl(cvmmemctl.u64);
  546. /* Setup of CVMSEG is done in kernel-entry-init.h */
  547. if (smp_processor_id() == 0)
  548. pr_notice("CVMSEG size: %d cache lines (%d bytes)\n",
  549. CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE,
  550. CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE * 128);
  551. if (octeon_has_feature(OCTEON_FEATURE_FAU)) {
  552. union cvmx_iob_fau_timeout fau_timeout;
  553. /* Set a default for the hardware timeouts */
  554. fau_timeout.u64 = 0;
  555. fau_timeout.s.tout_val = 0xfff;
  556. /* Disable tagwait FAU timeout */
  557. fau_timeout.s.tout_enb = 0;
  558. cvmx_write_csr(CVMX_IOB_FAU_TIMEOUT, fau_timeout.u64);
  559. }
  560. if ((!OCTEON_IS_MODEL(OCTEON_CN68XX) &&
  561. !OCTEON_IS_MODEL(OCTEON_CN7XXX)) ||
  562. OCTEON_IS_MODEL(OCTEON_CN70XX)) {
  563. union cvmx_pow_nw_tim nm_tim;
  564. nm_tim.u64 = 0;
  565. /* 4096 cycles */
  566. nm_tim.s.nw_tim = 3;
  567. cvmx_write_csr(CVMX_POW_NW_TIM, nm_tim.u64);
  568. }
  569. write_octeon_c0_icacheerr(0);
  570. write_c0_derraddr1(0);
  571. }
  572. /**
  573. * Early entry point for arch setup
  574. */
  575. void __init prom_init(void)
  576. {
  577. struct cvmx_sysinfo *sysinfo;
  578. const char *arg;
  579. char *p;
  580. int i;
  581. u64 t;
  582. int argc;
  583. #ifdef CONFIG_CAVIUM_RESERVE32
  584. int64_t addr = -1;
  585. #endif
  586. /*
  587. * The bootloader passes a pointer to the boot descriptor in
  588. * $a3, this is available as fw_arg3.
  589. */
  590. octeon_boot_desc_ptr = (struct octeon_boot_descriptor *)fw_arg3;
  591. octeon_bootinfo =
  592. cvmx_phys_to_ptr(octeon_boot_desc_ptr->cvmx_desc_vaddr);
  593. cvmx_bootmem_init(cvmx_phys_to_ptr(octeon_bootinfo->phy_mem_desc_addr));
  594. sysinfo = cvmx_sysinfo_get();
  595. memset(sysinfo, 0, sizeof(*sysinfo));
  596. sysinfo->system_dram_size = octeon_bootinfo->dram_size << 20;
  597. sysinfo->phy_mem_desc_addr = (u64)phys_to_virt(octeon_bootinfo->phy_mem_desc_addr);
  598. if ((octeon_bootinfo->major_version > 1) ||
  599. (octeon_bootinfo->major_version == 1 &&
  600. octeon_bootinfo->minor_version >= 4))
  601. cvmx_coremask_copy(&sysinfo->core_mask,
  602. &octeon_bootinfo->ext_core_mask);
  603. else
  604. cvmx_coremask_set64(&sysinfo->core_mask,
  605. octeon_bootinfo->core_mask);
  606. /* Some broken u-boot pass garbage in upper bits, clear them out */
  607. if (!OCTEON_IS_MODEL(OCTEON_CN78XX))
  608. for (i = 512; i < 1024; i++)
  609. cvmx_coremask_clear_core(&sysinfo->core_mask, i);
  610. sysinfo->exception_base_addr = octeon_bootinfo->exception_base_addr;
  611. sysinfo->cpu_clock_hz = octeon_bootinfo->eclock_hz;
  612. sysinfo->dram_data_rate_hz = octeon_bootinfo->dclock_hz * 2;
  613. sysinfo->board_type = octeon_bootinfo->board_type;
  614. sysinfo->board_rev_major = octeon_bootinfo->board_rev_major;
  615. sysinfo->board_rev_minor = octeon_bootinfo->board_rev_minor;
  616. memcpy(sysinfo->mac_addr_base, octeon_bootinfo->mac_addr_base,
  617. sizeof(sysinfo->mac_addr_base));
  618. sysinfo->mac_addr_count = octeon_bootinfo->mac_addr_count;
  619. memcpy(sysinfo->board_serial_number,
  620. octeon_bootinfo->board_serial_number,
  621. sizeof(sysinfo->board_serial_number));
  622. sysinfo->compact_flash_common_base_addr =
  623. octeon_bootinfo->compact_flash_common_base_addr;
  624. sysinfo->compact_flash_attribute_base_addr =
  625. octeon_bootinfo->compact_flash_attribute_base_addr;
  626. sysinfo->led_display_base_addr = octeon_bootinfo->led_display_base_addr;
  627. sysinfo->dfa_ref_clock_hz = octeon_bootinfo->dfa_ref_clock_hz;
  628. sysinfo->bootloader_config_flags = octeon_bootinfo->config_flags;
  629. if (OCTEON_IS_OCTEON2()) {
  630. /* I/O clock runs at a different rate than the CPU. */
  631. union cvmx_mio_rst_boot rst_boot;
  632. rst_boot.u64 = cvmx_read_csr(CVMX_MIO_RST_BOOT);
  633. octeon_io_clock_rate = 50000000 * rst_boot.s.pnr_mul;
  634. } else if (OCTEON_IS_OCTEON3()) {
  635. /* I/O clock runs at a different rate than the CPU. */
  636. union cvmx_rst_boot rst_boot;
  637. rst_boot.u64 = cvmx_read_csr(CVMX_RST_BOOT);
  638. octeon_io_clock_rate = 50000000 * rst_boot.s.pnr_mul;
  639. } else {
  640. octeon_io_clock_rate = sysinfo->cpu_clock_hz;
  641. }
  642. t = read_c0_cvmctl();
  643. if ((t & (1ull << 27)) == 0) {
  644. /*
  645. * Setup the multiplier save/restore code if
  646. * CvmCtl[NOMUL] clear.
  647. */
  648. void *save;
  649. void *save_end;
  650. void *restore;
  651. void *restore_end;
  652. int save_len;
  653. int restore_len;
  654. int save_max = (char *)octeon_mult_save_end -
  655. (char *)octeon_mult_save;
  656. int restore_max = (char *)octeon_mult_restore_end -
  657. (char *)octeon_mult_restore;
  658. if (current_cpu_data.cputype == CPU_CAVIUM_OCTEON3) {
  659. save = octeon_mult_save3;
  660. save_end = octeon_mult_save3_end;
  661. restore = octeon_mult_restore3;
  662. restore_end = octeon_mult_restore3_end;
  663. } else {
  664. save = octeon_mult_save2;
  665. save_end = octeon_mult_save2_end;
  666. restore = octeon_mult_restore2;
  667. restore_end = octeon_mult_restore2_end;
  668. }
  669. save_len = (char *)save_end - (char *)save;
  670. restore_len = (char *)restore_end - (char *)restore;
  671. if (!WARN_ON(save_len > save_max ||
  672. restore_len > restore_max)) {
  673. memcpy(octeon_mult_save, save, save_len);
  674. memcpy(octeon_mult_restore, restore, restore_len);
  675. }
  676. }
  677. /*
  678. * Only enable the LED controller if we're running on a CN38XX, CN58XX,
  679. * or CN56XX. The CN30XX and CN31XX don't have an LED controller.
  680. */
  681. if (!octeon_is_simulation() &&
  682. octeon_has_feature(OCTEON_FEATURE_LED_CONTROLLER)) {
  683. cvmx_write_csr(CVMX_LED_EN, 0);
  684. cvmx_write_csr(CVMX_LED_PRT, 0);
  685. cvmx_write_csr(CVMX_LED_DBG, 0);
  686. cvmx_write_csr(CVMX_LED_PRT_FMT, 0);
  687. cvmx_write_csr(CVMX_LED_UDD_CNTX(0), 32);
  688. cvmx_write_csr(CVMX_LED_UDD_CNTX(1), 32);
  689. cvmx_write_csr(CVMX_LED_UDD_DATX(0), 0);
  690. cvmx_write_csr(CVMX_LED_UDD_DATX(1), 0);
  691. cvmx_write_csr(CVMX_LED_EN, 1);
  692. }
  693. #ifdef CONFIG_CAVIUM_RESERVE32
  694. /*
  695. * We need to temporarily allocate all memory in the reserve32
  696. * region. This makes sure the kernel doesn't allocate this
  697. * memory when it is getting memory from the
  698. * bootloader. Later, after the memory allocations are
  699. * complete, the reserve32 will be freed.
  700. *
  701. * Allocate memory for RESERVED32 aligned on 2MB boundary. This
  702. * is in case we later use hugetlb entries with it.
  703. */
  704. addr = cvmx_bootmem_phy_named_block_alloc(CONFIG_CAVIUM_RESERVE32 << 20,
  705. 0, 0, 2 << 20,
  706. "CAVIUM_RESERVE32", 0);
  707. if (addr < 0)
  708. pr_err("Failed to allocate CAVIUM_RESERVE32 memory area\n");
  709. else
  710. octeon_reserve32_memory = addr;
  711. #endif
  712. #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2
  713. if (cvmx_read_csr(CVMX_L2D_FUS3) & (3ull << 34)) {
  714. pr_info("Skipping L2 locking due to reduced L2 cache size\n");
  715. } else {
  716. uint32_t __maybe_unused ebase = read_c0_ebase() & 0x3ffff000;
  717. #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_TLB
  718. /* TLB refill */
  719. cvmx_l2c_lock_mem_region(ebase, 0x100);
  720. #endif
  721. #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_EXCEPTION
  722. /* General exception */
  723. cvmx_l2c_lock_mem_region(ebase + 0x180, 0x80);
  724. #endif
  725. #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_LOW_LEVEL_INTERRUPT
  726. /* Interrupt handler */
  727. cvmx_l2c_lock_mem_region(ebase + 0x200, 0x80);
  728. #endif
  729. #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_INTERRUPT
  730. cvmx_l2c_lock_mem_region(__pa_symbol(handle_int), 0x100);
  731. cvmx_l2c_lock_mem_region(__pa_symbol(plat_irq_dispatch), 0x80);
  732. #endif
  733. #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_MEMCPY
  734. cvmx_l2c_lock_mem_region(__pa_symbol(memcpy), 0x480);
  735. #endif
  736. }
  737. #endif
  738. octeon_check_cpu_bist();
  739. octeon_uart = octeon_get_boot_uart();
  740. #ifdef CONFIG_SMP
  741. octeon_write_lcd("LinuxSMP");
  742. #else
  743. octeon_write_lcd("Linux");
  744. #endif
  745. octeon_setup_delays();
  746. /*
  747. * BIST should always be enabled when doing a soft reset. L2
  748. * Cache locking for instance is not cleared unless BIST is
  749. * enabled. Unfortunately due to a chip errata G-200 for
  750. * Cn38XX and CN31XX, BIST msut be disabled on these parts.
  751. */
  752. if (OCTEON_IS_MODEL(OCTEON_CN38XX_PASS2) ||
  753. OCTEON_IS_MODEL(OCTEON_CN31XX))
  754. cvmx_write_csr(CVMX_CIU_SOFT_BIST, 0);
  755. else
  756. cvmx_write_csr(CVMX_CIU_SOFT_BIST, 1);
  757. /* Default to 64MB in the simulator to speed things up */
  758. if (octeon_is_simulation())
  759. max_memory = 64ull << 20;
  760. arg = strstr(arcs_cmdline, "mem=");
  761. if (arg) {
  762. max_memory = memparse(arg + 4, &p);
  763. if (max_memory == 0)
  764. max_memory = 32ull << 30;
  765. if (*p == '@')
  766. reserve_low_mem = memparse(p + 1, &p);
  767. }
  768. arcs_cmdline[0] = 0;
  769. argc = octeon_boot_desc_ptr->argc;
  770. for (i = 0; i < argc; i++) {
  771. const char *arg =
  772. cvmx_phys_to_ptr(octeon_boot_desc_ptr->argv[i]);
  773. if ((strncmp(arg, "MEM=", 4) == 0) ||
  774. (strncmp(arg, "mem=", 4) == 0)) {
  775. max_memory = memparse(arg + 4, &p);
  776. if (max_memory == 0)
  777. max_memory = 32ull << 30;
  778. if (*p == '@')
  779. reserve_low_mem = memparse(p + 1, &p);
  780. #ifdef CONFIG_KEXEC
  781. } else if (strncmp(arg, "crashkernel=", 12) == 0) {
  782. crashk_size = memparse(arg+12, &p);
  783. if (*p == '@')
  784. crashk_base = memparse(p+1, &p);
  785. strcat(arcs_cmdline, " ");
  786. strcat(arcs_cmdline, arg);
  787. /*
  788. * To do: switch parsing to new style, something like:
  789. * parse_crashkernel(arg, sysinfo->system_dram_size,
  790. * &crashk_size, &crashk_base);
  791. */
  792. #endif
  793. } else if (strlen(arcs_cmdline) + strlen(arg) + 1 <
  794. sizeof(arcs_cmdline) - 1) {
  795. strcat(arcs_cmdline, " ");
  796. strcat(arcs_cmdline, arg);
  797. }
  798. }
  799. if (strstr(arcs_cmdline, "console=") == NULL) {
  800. #ifdef CONFIG_CAVIUM_OCTEON_2ND_KERNEL
  801. strcat(arcs_cmdline, " console=ttyS0,115200");
  802. #else
  803. if (octeon_uart == 1)
  804. strcat(arcs_cmdline, " console=ttyS1,115200");
  805. else
  806. strcat(arcs_cmdline, " console=ttyS0,115200");
  807. #endif
  808. }
  809. mips_hpt_frequency = octeon_get_clock_rate();
  810. octeon_init_cvmcount();
  811. _machine_restart = octeon_restart;
  812. _machine_halt = octeon_halt;
  813. #ifdef CONFIG_KEXEC
  814. _machine_kexec_shutdown = octeon_shutdown;
  815. _machine_crash_shutdown = octeon_crash_shutdown;
  816. _machine_kexec_prepare = octeon_kexec_prepare;
  817. #ifdef CONFIG_SMP
  818. _crash_smp_send_stop = octeon_crash_smp_send_stop;
  819. #endif
  820. #endif
  821. octeon_user_io_init();
  822. octeon_setup_smp();
  823. }
  824. /* Exclude a single page from the regions obtained in plat_mem_setup. */
  825. #ifndef CONFIG_CRASH_DUMP
  826. static __init void memory_exclude_page(u64 addr, u64 *mem, u64 *size)
  827. {
  828. if (addr > *mem && addr < *mem + *size) {
  829. u64 inc = addr - *mem;
  830. add_memory_region(*mem, inc, BOOT_MEM_RAM);
  831. *mem += inc;
  832. *size -= inc;
  833. }
  834. if (addr == *mem && *size > PAGE_SIZE) {
  835. *mem += PAGE_SIZE;
  836. *size -= PAGE_SIZE;
  837. }
  838. }
  839. #endif /* CONFIG_CRASH_DUMP */
  840. void __init plat_mem_setup(void)
  841. {
  842. uint64_t mem_alloc_size;
  843. uint64_t total;
  844. uint64_t crashk_end;
  845. #ifndef CONFIG_CRASH_DUMP
  846. int64_t memory;
  847. uint64_t kernel_start;
  848. uint64_t kernel_size;
  849. #endif
  850. total = 0;
  851. crashk_end = 0;
  852. /*
  853. * The Mips memory init uses the first memory location for
  854. * some memory vectors. When SPARSEMEM is in use, it doesn't
  855. * verify that the size is big enough for the final
  856. * vectors. Making the smallest chuck 4MB seems to be enough
  857. * to consistently work.
  858. */
  859. mem_alloc_size = 4 << 20;
  860. if (mem_alloc_size > max_memory)
  861. mem_alloc_size = max_memory;
  862. /* Crashkernel ignores bootmem list. It relies on mem=X@Y option */
  863. #ifdef CONFIG_CRASH_DUMP
  864. add_memory_region(reserve_low_mem, max_memory, BOOT_MEM_RAM);
  865. total += max_memory;
  866. #else
  867. #ifdef CONFIG_KEXEC
  868. if (crashk_size > 0) {
  869. add_memory_region(crashk_base, crashk_size, BOOT_MEM_RAM);
  870. crashk_end = crashk_base + crashk_size;
  871. }
  872. #endif
  873. /*
  874. * When allocating memory, we want incrementing addresses from
  875. * bootmem_alloc so the code in add_memory_region can merge
  876. * regions next to each other.
  877. */
  878. cvmx_bootmem_lock();
  879. while ((boot_mem_map.nr_map < BOOT_MEM_MAP_MAX)
  880. && (total < max_memory)) {
  881. memory = cvmx_bootmem_phy_alloc(mem_alloc_size,
  882. __pa_symbol(&_end), -1,
  883. 0x100000,
  884. CVMX_BOOTMEM_FLAG_NO_LOCKING);
  885. if (memory >= 0) {
  886. u64 size = mem_alloc_size;
  887. #ifdef CONFIG_KEXEC
  888. uint64_t end;
  889. #endif
  890. /*
  891. * exclude a page at the beginning and end of
  892. * the 256MB PCIe 'hole' so the kernel will not
  893. * try to allocate multi-page buffers that
  894. * span the discontinuity.
  895. */
  896. memory_exclude_page(CVMX_PCIE_BAR1_PHYS_BASE,
  897. &memory, &size);
  898. memory_exclude_page(CVMX_PCIE_BAR1_PHYS_BASE +
  899. CVMX_PCIE_BAR1_PHYS_SIZE,
  900. &memory, &size);
  901. #ifdef CONFIG_KEXEC
  902. end = memory + mem_alloc_size;
  903. /*
  904. * This function automatically merges address regions
  905. * next to each other if they are received in
  906. * incrementing order
  907. */
  908. if (memory < crashk_base && end > crashk_end) {
  909. /* region is fully in */
  910. add_memory_region(memory,
  911. crashk_base - memory,
  912. BOOT_MEM_RAM);
  913. total += crashk_base - memory;
  914. add_memory_region(crashk_end,
  915. end - crashk_end,
  916. BOOT_MEM_RAM);
  917. total += end - crashk_end;
  918. continue;
  919. }
  920. if (memory >= crashk_base && end <= crashk_end)
  921. /*
  922. * Entire memory region is within the new
  923. * kernel's memory, ignore it.
  924. */
  925. continue;
  926. if (memory > crashk_base && memory < crashk_end &&
  927. end > crashk_end) {
  928. /*
  929. * Overlap with the beginning of the region,
  930. * reserve the beginning.
  931. */
  932. mem_alloc_size -= crashk_end - memory;
  933. memory = crashk_end;
  934. } else if (memory < crashk_base && end > crashk_base &&
  935. end < crashk_end)
  936. /*
  937. * Overlap with the beginning of the region,
  938. * chop of end.
  939. */
  940. mem_alloc_size -= end - crashk_base;
  941. #endif
  942. add_memory_region(memory, mem_alloc_size, BOOT_MEM_RAM);
  943. total += mem_alloc_size;
  944. /* Recovering mem_alloc_size */
  945. mem_alloc_size = 4 << 20;
  946. } else {
  947. break;
  948. }
  949. }
  950. cvmx_bootmem_unlock();
  951. /* Add the memory region for the kernel. */
  952. kernel_start = (unsigned long) _text;
  953. kernel_size = _end - _text;
  954. /* Adjust for physical offset. */
  955. kernel_start &= ~0xffffffff80000000ULL;
  956. add_memory_region(kernel_start, kernel_size, BOOT_MEM_RAM);
  957. #endif /* CONFIG_CRASH_DUMP */
  958. #ifdef CONFIG_CAVIUM_RESERVE32
  959. /*
  960. * Now that we've allocated the kernel memory it is safe to
  961. * free the reserved region. We free it here so that builtin
  962. * drivers can use the memory.
  963. */
  964. if (octeon_reserve32_memory)
  965. cvmx_bootmem_free_named("CAVIUM_RESERVE32");
  966. #endif /* CONFIG_CAVIUM_RESERVE32 */
  967. if (total == 0)
  968. panic("Unable to allocate memory from "
  969. "cvmx_bootmem_phy_alloc");
  970. }
  971. /*
  972. * Emit one character to the boot UART. Exported for use by the
  973. * watchdog timer.
  974. */
  975. int prom_putchar(char c)
  976. {
  977. uint64_t lsrval;
  978. /* Spin until there is room */
  979. do {
  980. lsrval = cvmx_read_csr(CVMX_MIO_UARTX_LSR(octeon_uart));
  981. } while ((lsrval & 0x20) == 0);
  982. /* Write the byte */
  983. cvmx_write_csr(CVMX_MIO_UARTX_THR(octeon_uart), c & 0xffull);
  984. return 1;
  985. }
  986. EXPORT_SYMBOL(prom_putchar);
  987. void __init prom_free_prom_memory(void)
  988. {
  989. if (CAVIUM_OCTEON_DCACHE_PREFETCH_WAR) {
  990. /* Check for presence of Core-14449 fix. */
  991. u32 insn;
  992. u32 *foo;
  993. foo = &insn;
  994. asm volatile("# before" : : : "memory");
  995. prefetch(foo);
  996. asm volatile(
  997. ".set push\n\t"
  998. ".set noreorder\n\t"
  999. "bal 1f\n\t"
  1000. "nop\n"
  1001. "1:\tlw %0,-12($31)\n\t"
  1002. ".set pop\n\t"
  1003. : "=r" (insn) : : "$31", "memory");
  1004. if ((insn >> 26) != 0x33)
  1005. panic("No PREF instruction at Core-14449 probe point.");
  1006. if (((insn >> 16) & 0x1f) != 28)
  1007. panic("OCTEON II DCache prefetch workaround not in place (%04x).\n"
  1008. "Please build kernel with proper options (CONFIG_CAVIUM_CN63XXP1).",
  1009. insn);
  1010. }
  1011. }
  1012. void __init octeon_fill_mac_addresses(void);
  1013. int octeon_prune_device_tree(void);
  1014. extern const char __appended_dtb;
  1015. extern const char __dtb_octeon_3xxx_begin;
  1016. extern const char __dtb_octeon_68xx_begin;
  1017. void __init device_tree_init(void)
  1018. {
  1019. const void *fdt;
  1020. bool do_prune;
  1021. bool fill_mac;
  1022. #ifdef CONFIG_MIPS_ELF_APPENDED_DTB
  1023. if (!fdt_check_header(&__appended_dtb)) {
  1024. fdt = &__appended_dtb;
  1025. do_prune = false;
  1026. fill_mac = true;
  1027. pr_info("Using appended Device Tree.\n");
  1028. } else
  1029. #endif
  1030. if (octeon_bootinfo->minor_version >= 3 && octeon_bootinfo->fdt_addr) {
  1031. fdt = phys_to_virt(octeon_bootinfo->fdt_addr);
  1032. if (fdt_check_header(fdt))
  1033. panic("Corrupt Device Tree passed to kernel.");
  1034. do_prune = false;
  1035. fill_mac = false;
  1036. pr_info("Using passed Device Tree.\n");
  1037. } else if (OCTEON_IS_MODEL(OCTEON_CN68XX)) {
  1038. fdt = &__dtb_octeon_68xx_begin;
  1039. do_prune = true;
  1040. fill_mac = true;
  1041. } else {
  1042. fdt = &__dtb_octeon_3xxx_begin;
  1043. do_prune = true;
  1044. fill_mac = true;
  1045. }
  1046. initial_boot_params = (void *)fdt;
  1047. if (do_prune) {
  1048. octeon_prune_device_tree();
  1049. pr_info("Using internal Device Tree.\n");
  1050. }
  1051. if (fill_mac)
  1052. octeon_fill_mac_addresses();
  1053. unflatten_and_copy_device_tree();
  1054. init_octeon_system_type();
  1055. }
  1056. static int __initdata disable_octeon_edac_p;
  1057. static int __init disable_octeon_edac(char *str)
  1058. {
  1059. disable_octeon_edac_p = 1;
  1060. return 0;
  1061. }
  1062. early_param("disable_octeon_edac", disable_octeon_edac);
  1063. static char *edac_device_names[] = {
  1064. "octeon_l2c_edac",
  1065. "octeon_pc_edac",
  1066. };
  1067. static int __init edac_devinit(void)
  1068. {
  1069. struct platform_device *dev;
  1070. int i, err = 0;
  1071. int num_lmc;
  1072. char *name;
  1073. if (disable_octeon_edac_p)
  1074. return 0;
  1075. for (i = 0; i < ARRAY_SIZE(edac_device_names); i++) {
  1076. name = edac_device_names[i];
  1077. dev = platform_device_register_simple(name, -1, NULL, 0);
  1078. if (IS_ERR(dev)) {
  1079. pr_err("Registration of %s failed!\n", name);
  1080. err = PTR_ERR(dev);
  1081. }
  1082. }
  1083. num_lmc = OCTEON_IS_MODEL(OCTEON_CN68XX) ? 4 :
  1084. (OCTEON_IS_MODEL(OCTEON_CN56XX) ? 2 : 1);
  1085. for (i = 0; i < num_lmc; i++) {
  1086. dev = platform_device_register_simple("octeon_lmc_edac",
  1087. i, NULL, 0);
  1088. if (IS_ERR(dev)) {
  1089. pr_err("Registration of octeon_lmc_edac %d failed!\n", i);
  1090. err = PTR_ERR(dev);
  1091. }
  1092. }
  1093. return err;
  1094. }
  1095. device_initcall(edac_devinit);
  1096. static void __initdata *octeon_dummy_iospace;
  1097. static int __init octeon_no_pci_init(void)
  1098. {
  1099. /*
  1100. * Initially assume there is no PCI. The PCI/PCIe platform code will
  1101. * later re-initialize these to correct values if they are present.
  1102. */
  1103. octeon_dummy_iospace = vzalloc(IO_SPACE_LIMIT);
  1104. set_io_port_base((unsigned long)octeon_dummy_iospace);
  1105. ioport_resource.start = MAX_RESOURCE;
  1106. ioport_resource.end = 0;
  1107. return 0;
  1108. }
  1109. core_initcall(octeon_no_pci_init);
  1110. static int __init octeon_no_pci_release(void)
  1111. {
  1112. /*
  1113. * Release the allocated memory if a real IO space is there.
  1114. */
  1115. if ((unsigned long)octeon_dummy_iospace != mips_io_port_base)
  1116. vfree(octeon_dummy_iospace);
  1117. return 0;
  1118. }
  1119. late_initcall(octeon_no_pci_release);