setup.c 34 KB

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