setup.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847
  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/init.h>
  11. #include <linux/kernel.h>
  12. #include <linux/console.h>
  13. #include <linux/delay.h>
  14. #include <linux/export.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/io.h>
  17. #include <linux/serial.h>
  18. #include <linux/smp.h>
  19. #include <linux/types.h>
  20. #include <linux/string.h> /* for memset */
  21. #include <linux/tty.h>
  22. #include <linux/time.h>
  23. #include <linux/platform_device.h>
  24. #include <linux/serial_core.h>
  25. #include <linux/serial_8250.h>
  26. #include <linux/of_fdt.h>
  27. #include <linux/libfdt.h>
  28. #include <asm/processor.h>
  29. #include <asm/reboot.h>
  30. #include <asm/smp-ops.h>
  31. #include <asm/irq_cpu.h>
  32. #include <asm/mipsregs.h>
  33. #include <asm/bootinfo.h>
  34. #include <asm/sections.h>
  35. #include <asm/time.h>
  36. #include <asm/octeon/octeon.h>
  37. #include <asm/octeon/pci-octeon.h>
  38. #include <asm/octeon/cvmx-mio-defs.h>
  39. #ifdef CONFIG_CAVIUM_DECODE_RSL
  40. extern void cvmx_interrupt_rsl_decode(void);
  41. extern int __cvmx_interrupt_ecc_report_single_bit_errors;
  42. extern void cvmx_interrupt_rsl_enable(void);
  43. #endif
  44. extern struct plat_smp_ops octeon_smp_ops;
  45. #ifdef CONFIG_PCI
  46. extern void pci_console_init(const char *arg);
  47. #endif
  48. static unsigned long long MAX_MEMORY = 512ull << 20;
  49. struct octeon_boot_descriptor *octeon_boot_desc_ptr;
  50. struct cvmx_bootinfo *octeon_bootinfo;
  51. EXPORT_SYMBOL(octeon_bootinfo);
  52. #ifdef CONFIG_CAVIUM_RESERVE32
  53. uint64_t octeon_reserve32_memory;
  54. EXPORT_SYMBOL(octeon_reserve32_memory);
  55. #endif
  56. static int octeon_uart;
  57. extern asmlinkage void handle_int(void);
  58. extern asmlinkage void plat_irq_dispatch(void);
  59. /**
  60. * Return non zero if we are currently running in the Octeon simulator
  61. *
  62. * Returns
  63. */
  64. int octeon_is_simulation(void)
  65. {
  66. return octeon_bootinfo->board_type == CVMX_BOARD_TYPE_SIM;
  67. }
  68. EXPORT_SYMBOL(octeon_is_simulation);
  69. /**
  70. * Return true if Octeon is in PCI Host mode. This means
  71. * Linux can control the PCI bus.
  72. *
  73. * Returns Non zero if Octeon in host mode.
  74. */
  75. int octeon_is_pci_host(void)
  76. {
  77. #ifdef CONFIG_PCI
  78. return octeon_bootinfo->config_flags & CVMX_BOOTINFO_CFG_FLAG_PCI_HOST;
  79. #else
  80. return 0;
  81. #endif
  82. }
  83. /**
  84. * Get the clock rate of Octeon
  85. *
  86. * Returns Clock rate in HZ
  87. */
  88. uint64_t octeon_get_clock_rate(void)
  89. {
  90. struct cvmx_sysinfo *sysinfo = cvmx_sysinfo_get();
  91. return sysinfo->cpu_clock_hz;
  92. }
  93. EXPORT_SYMBOL(octeon_get_clock_rate);
  94. static u64 octeon_io_clock_rate;
  95. u64 octeon_get_io_clock_rate(void)
  96. {
  97. return octeon_io_clock_rate;
  98. }
  99. EXPORT_SYMBOL(octeon_get_io_clock_rate);
  100. /**
  101. * Write to the LCD display connected to the bootbus. This display
  102. * exists on most Cavium evaluation boards. If it doesn't exist, then
  103. * this function doesn't do anything.
  104. *
  105. * @s: String to write
  106. */
  107. void octeon_write_lcd(const char *s)
  108. {
  109. if (octeon_bootinfo->led_display_base_addr) {
  110. void __iomem *lcd_address =
  111. ioremap_nocache(octeon_bootinfo->led_display_base_addr,
  112. 8);
  113. int i;
  114. for (i = 0; i < 8; i++, s++) {
  115. if (*s)
  116. iowrite8(*s, lcd_address + i);
  117. else
  118. iowrite8(' ', lcd_address + i);
  119. }
  120. iounmap(lcd_address);
  121. }
  122. }
  123. /**
  124. * Return the console uart passed by the bootloader
  125. *
  126. * Returns uart (0 or 1)
  127. */
  128. int octeon_get_boot_uart(void)
  129. {
  130. int uart;
  131. #ifdef CONFIG_CAVIUM_OCTEON_2ND_KERNEL
  132. uart = 1;
  133. #else
  134. uart = (octeon_boot_desc_ptr->flags & OCTEON_BL_FLAG_CONSOLE_UART1) ?
  135. 1 : 0;
  136. #endif
  137. return uart;
  138. }
  139. /**
  140. * Get the coremask Linux was booted on.
  141. *
  142. * Returns Core mask
  143. */
  144. int octeon_get_boot_coremask(void)
  145. {
  146. return octeon_boot_desc_ptr->core_mask;
  147. }
  148. /**
  149. * Check the hardware BIST results for a CPU
  150. */
  151. void octeon_check_cpu_bist(void)
  152. {
  153. const int coreid = cvmx_get_core_num();
  154. unsigned long long mask;
  155. unsigned long long bist_val;
  156. /* Check BIST results for COP0 registers */
  157. mask = 0x1f00000000ull;
  158. bist_val = read_octeon_c0_icacheerr();
  159. if (bist_val & mask)
  160. pr_err("Core%d BIST Failure: CacheErr(icache) = 0x%llx\n",
  161. coreid, bist_val);
  162. bist_val = read_octeon_c0_dcacheerr();
  163. if (bist_val & 1)
  164. pr_err("Core%d L1 Dcache parity error: "
  165. "CacheErr(dcache) = 0x%llx\n",
  166. coreid, bist_val);
  167. mask = 0xfc00000000000000ull;
  168. bist_val = read_c0_cvmmemctl();
  169. if (bist_val & mask)
  170. pr_err("Core%d BIST Failure: COP0_CVM_MEM_CTL = 0x%llx\n",
  171. coreid, bist_val);
  172. write_octeon_c0_dcacheerr(0);
  173. }
  174. /**
  175. * Reboot Octeon
  176. *
  177. * @command: Command to pass to the bootloader. Currently ignored.
  178. */
  179. static void octeon_restart(char *command)
  180. {
  181. /* Disable all watchdogs before soft reset. They don't get cleared */
  182. #ifdef CONFIG_SMP
  183. int cpu;
  184. for_each_online_cpu(cpu)
  185. cvmx_write_csr(CVMX_CIU_WDOGX(cpu_logical_map(cpu)), 0);
  186. #else
  187. cvmx_write_csr(CVMX_CIU_WDOGX(cvmx_get_core_num()), 0);
  188. #endif
  189. mb();
  190. while (1)
  191. cvmx_write_csr(CVMX_CIU_SOFT_RST, 1);
  192. }
  193. /**
  194. * Permanently stop a core.
  195. *
  196. * @arg: Ignored.
  197. */
  198. static void octeon_kill_core(void *arg)
  199. {
  200. mb();
  201. if (octeon_is_simulation()) {
  202. /* The simulator needs the watchdog to stop for dead cores */
  203. cvmx_write_csr(CVMX_CIU_WDOGX(cvmx_get_core_num()), 0);
  204. /* A break instruction causes the simulator stop a core */
  205. asm volatile ("sync\nbreak");
  206. }
  207. }
  208. /**
  209. * Halt the system
  210. */
  211. static void octeon_halt(void)
  212. {
  213. smp_call_function(octeon_kill_core, NULL, 0);
  214. switch (octeon_bootinfo->board_type) {
  215. case CVMX_BOARD_TYPE_NAO38:
  216. /* Driving a 1 to GPIO 12 shuts off this board */
  217. cvmx_write_csr(CVMX_GPIO_BIT_CFGX(12), 1);
  218. cvmx_write_csr(CVMX_GPIO_TX_SET, 0x1000);
  219. break;
  220. default:
  221. octeon_write_lcd("PowerOff");
  222. break;
  223. }
  224. octeon_kill_core(NULL);
  225. }
  226. /**
  227. * Handle all the error condition interrupts that might occur.
  228. *
  229. */
  230. #ifdef CONFIG_CAVIUM_DECODE_RSL
  231. static irqreturn_t octeon_rlm_interrupt(int cpl, void *dev_id)
  232. {
  233. cvmx_interrupt_rsl_decode();
  234. return IRQ_HANDLED;
  235. }
  236. #endif
  237. /**
  238. * Return a string representing the system type
  239. *
  240. * Returns
  241. */
  242. const char *octeon_board_type_string(void)
  243. {
  244. static char name[80];
  245. sprintf(name, "%s (%s)",
  246. cvmx_board_type_to_string(octeon_bootinfo->board_type),
  247. octeon_model_get_string(read_c0_prid()));
  248. return name;
  249. }
  250. const char *get_system_type(void)
  251. __attribute__ ((alias("octeon_board_type_string")));
  252. void octeon_user_io_init(void)
  253. {
  254. union octeon_cvmemctl cvmmemctl;
  255. union cvmx_iob_fau_timeout fau_timeout;
  256. union cvmx_pow_nw_tim nm_tim;
  257. /* Get the current settings for CP0_CVMMEMCTL_REG */
  258. cvmmemctl.u64 = read_c0_cvmmemctl();
  259. /* R/W If set, marked write-buffer entries time out the same
  260. * as as other entries; if clear, marked write-buffer entries
  261. * use the maximum timeout. */
  262. cvmmemctl.s.dismarkwblongto = 1;
  263. /* R/W If set, a merged store does not clear the write-buffer
  264. * entry timeout state. */
  265. cvmmemctl.s.dismrgclrwbto = 0;
  266. /* R/W Two bits that are the MSBs of the resultant CVMSEG LM
  267. * word location for an IOBDMA. The other 8 bits come from the
  268. * SCRADDR field of the IOBDMA. */
  269. cvmmemctl.s.iobdmascrmsb = 0;
  270. /* R/W If set, SYNCWS and SYNCS only order marked stores; if
  271. * clear, SYNCWS and SYNCS only order unmarked
  272. * stores. SYNCWSMARKED has no effect when DISSYNCWS is
  273. * set. */
  274. cvmmemctl.s.syncwsmarked = 0;
  275. /* R/W If set, SYNCWS acts as SYNCW and SYNCS acts as SYNC. */
  276. cvmmemctl.s.dissyncws = 0;
  277. /* R/W If set, no stall happens on write buffer full. */
  278. if (OCTEON_IS_MODEL(OCTEON_CN38XX_PASS2))
  279. cvmmemctl.s.diswbfst = 1;
  280. else
  281. cvmmemctl.s.diswbfst = 0;
  282. /* R/W If set (and SX set), supervisor-level loads/stores can
  283. * use XKPHYS addresses with <48>==0 */
  284. cvmmemctl.s.xkmemenas = 0;
  285. /* R/W If set (and UX set), user-level loads/stores can use
  286. * XKPHYS addresses with VA<48>==0 */
  287. cvmmemctl.s.xkmemenau = 0;
  288. /* R/W If set (and SX set), supervisor-level loads/stores can
  289. * use XKPHYS addresses with VA<48>==1 */
  290. cvmmemctl.s.xkioenas = 0;
  291. /* R/W If set (and UX set), user-level loads/stores can use
  292. * XKPHYS addresses with VA<48>==1 */
  293. cvmmemctl.s.xkioenau = 0;
  294. /* R/W If set, all stores act as SYNCW (NOMERGE must be set
  295. * when this is set) RW, reset to 0. */
  296. cvmmemctl.s.allsyncw = 0;
  297. /* R/W If set, no stores merge, and all stores reach the
  298. * coherent bus in order. */
  299. cvmmemctl.s.nomerge = 0;
  300. /* R/W Selects the bit in the counter used for DID time-outs 0
  301. * = 231, 1 = 230, 2 = 229, 3 = 214. Actual time-out is
  302. * between 1x and 2x this interval. For example, with
  303. * DIDTTO=3, expiration interval is between 16K and 32K. */
  304. cvmmemctl.s.didtto = 0;
  305. /* R/W If set, the (mem) CSR clock never turns off. */
  306. cvmmemctl.s.csrckalwys = 0;
  307. /* R/W If set, mclk never turns off. */
  308. cvmmemctl.s.mclkalwys = 0;
  309. /* R/W Selects the bit in the counter used for write buffer
  310. * flush time-outs (WBFLT+11) is the bit position in an
  311. * internal counter used to determine expiration. The write
  312. * buffer expires between 1x and 2x this interval. For
  313. * example, with WBFLT = 0, a write buffer expires between 2K
  314. * and 4K cycles after the write buffer entry is allocated. */
  315. cvmmemctl.s.wbfltime = 0;
  316. /* R/W If set, do not put Istream in the L2 cache. */
  317. cvmmemctl.s.istrnol2 = 0;
  318. /*
  319. * R/W The write buffer threshold. As per erratum Core-14752
  320. * for CN63XX, a sc/scd might fail if the write buffer is
  321. * full. Lowering WBTHRESH greatly lowers the chances of the
  322. * write buffer ever being full and triggering the erratum.
  323. */
  324. if (OCTEON_IS_MODEL(OCTEON_CN63XX_PASS1_X))
  325. cvmmemctl.s.wbthresh = 4;
  326. else
  327. cvmmemctl.s.wbthresh = 10;
  328. /* R/W If set, CVMSEG is available for loads/stores in
  329. * kernel/debug mode. */
  330. #if CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE > 0
  331. cvmmemctl.s.cvmsegenak = 1;
  332. #else
  333. cvmmemctl.s.cvmsegenak = 0;
  334. #endif
  335. /* R/W If set, CVMSEG is available for loads/stores in
  336. * supervisor mode. */
  337. cvmmemctl.s.cvmsegenas = 0;
  338. /* R/W If set, CVMSEG is available for loads/stores in user
  339. * mode. */
  340. cvmmemctl.s.cvmsegenau = 0;
  341. /* R/W Size of local memory in cache blocks, 54 (6912 bytes)
  342. * is max legal value. */
  343. cvmmemctl.s.lmemsz = CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE;
  344. write_c0_cvmmemctl(cvmmemctl.u64);
  345. if (smp_processor_id() == 0)
  346. pr_notice("CVMSEG size: %d cache lines (%d bytes)\n",
  347. CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE,
  348. CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE * 128);
  349. /* Set a default for the hardware timeouts */
  350. fau_timeout.u64 = 0;
  351. fau_timeout.s.tout_val = 0xfff;
  352. /* Disable tagwait FAU timeout */
  353. fau_timeout.s.tout_enb = 0;
  354. cvmx_write_csr(CVMX_IOB_FAU_TIMEOUT, fau_timeout.u64);
  355. nm_tim.u64 = 0;
  356. /* 4096 cycles */
  357. nm_tim.s.nw_tim = 3;
  358. cvmx_write_csr(CVMX_POW_NW_TIM, nm_tim.u64);
  359. write_octeon_c0_icacheerr(0);
  360. write_c0_derraddr1(0);
  361. }
  362. /**
  363. * Early entry point for arch setup
  364. */
  365. void __init prom_init(void)
  366. {
  367. struct cvmx_sysinfo *sysinfo;
  368. int i;
  369. int argc;
  370. #ifdef CONFIG_CAVIUM_RESERVE32
  371. int64_t addr = -1;
  372. #endif
  373. /*
  374. * The bootloader passes a pointer to the boot descriptor in
  375. * $a3, this is available as fw_arg3.
  376. */
  377. octeon_boot_desc_ptr = (struct octeon_boot_descriptor *)fw_arg3;
  378. octeon_bootinfo =
  379. cvmx_phys_to_ptr(octeon_boot_desc_ptr->cvmx_desc_vaddr);
  380. cvmx_bootmem_init(cvmx_phys_to_ptr(octeon_bootinfo->phy_mem_desc_addr));
  381. sysinfo = cvmx_sysinfo_get();
  382. memset(sysinfo, 0, sizeof(*sysinfo));
  383. sysinfo->system_dram_size = octeon_bootinfo->dram_size << 20;
  384. sysinfo->phy_mem_desc_ptr =
  385. cvmx_phys_to_ptr(octeon_bootinfo->phy_mem_desc_addr);
  386. sysinfo->core_mask = octeon_bootinfo->core_mask;
  387. sysinfo->exception_base_addr = octeon_bootinfo->exception_base_addr;
  388. sysinfo->cpu_clock_hz = octeon_bootinfo->eclock_hz;
  389. sysinfo->dram_data_rate_hz = octeon_bootinfo->dclock_hz * 2;
  390. sysinfo->board_type = octeon_bootinfo->board_type;
  391. sysinfo->board_rev_major = octeon_bootinfo->board_rev_major;
  392. sysinfo->board_rev_minor = octeon_bootinfo->board_rev_minor;
  393. memcpy(sysinfo->mac_addr_base, octeon_bootinfo->mac_addr_base,
  394. sizeof(sysinfo->mac_addr_base));
  395. sysinfo->mac_addr_count = octeon_bootinfo->mac_addr_count;
  396. memcpy(sysinfo->board_serial_number,
  397. octeon_bootinfo->board_serial_number,
  398. sizeof(sysinfo->board_serial_number));
  399. sysinfo->compact_flash_common_base_addr =
  400. octeon_bootinfo->compact_flash_common_base_addr;
  401. sysinfo->compact_flash_attribute_base_addr =
  402. octeon_bootinfo->compact_flash_attribute_base_addr;
  403. sysinfo->led_display_base_addr = octeon_bootinfo->led_display_base_addr;
  404. sysinfo->dfa_ref_clock_hz = octeon_bootinfo->dfa_ref_clock_hz;
  405. sysinfo->bootloader_config_flags = octeon_bootinfo->config_flags;
  406. if (OCTEON_IS_MODEL(OCTEON_CN6XXX)) {
  407. /* I/O clock runs at a different rate than the CPU. */
  408. union cvmx_mio_rst_boot rst_boot;
  409. rst_boot.u64 = cvmx_read_csr(CVMX_MIO_RST_BOOT);
  410. octeon_io_clock_rate = 50000000 * rst_boot.s.pnr_mul;
  411. } else {
  412. octeon_io_clock_rate = sysinfo->cpu_clock_hz;
  413. }
  414. /*
  415. * Only enable the LED controller if we're running on a CN38XX, CN58XX,
  416. * or CN56XX. The CN30XX and CN31XX don't have an LED controller.
  417. */
  418. if (!octeon_is_simulation() &&
  419. octeon_has_feature(OCTEON_FEATURE_LED_CONTROLLER)) {
  420. cvmx_write_csr(CVMX_LED_EN, 0);
  421. cvmx_write_csr(CVMX_LED_PRT, 0);
  422. cvmx_write_csr(CVMX_LED_DBG, 0);
  423. cvmx_write_csr(CVMX_LED_PRT_FMT, 0);
  424. cvmx_write_csr(CVMX_LED_UDD_CNTX(0), 32);
  425. cvmx_write_csr(CVMX_LED_UDD_CNTX(1), 32);
  426. cvmx_write_csr(CVMX_LED_UDD_DATX(0), 0);
  427. cvmx_write_csr(CVMX_LED_UDD_DATX(1), 0);
  428. cvmx_write_csr(CVMX_LED_EN, 1);
  429. }
  430. #ifdef CONFIG_CAVIUM_RESERVE32
  431. /*
  432. * We need to temporarily allocate all memory in the reserve32
  433. * region. This makes sure the kernel doesn't allocate this
  434. * memory when it is getting memory from the
  435. * bootloader. Later, after the memory allocations are
  436. * complete, the reserve32 will be freed.
  437. *
  438. * Allocate memory for RESERVED32 aligned on 2MB boundary. This
  439. * is in case we later use hugetlb entries with it.
  440. */
  441. addr = cvmx_bootmem_phy_named_block_alloc(CONFIG_CAVIUM_RESERVE32 << 20,
  442. 0, 0, 2 << 20,
  443. "CAVIUM_RESERVE32", 0);
  444. if (addr < 0)
  445. pr_err("Failed to allocate CAVIUM_RESERVE32 memory area\n");
  446. else
  447. octeon_reserve32_memory = addr;
  448. #endif
  449. #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2
  450. if (cvmx_read_csr(CVMX_L2D_FUS3) & (3ull << 34)) {
  451. pr_info("Skipping L2 locking due to reduced L2 cache size\n");
  452. } else {
  453. uint32_t ebase = read_c0_ebase() & 0x3ffff000;
  454. #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_TLB
  455. /* TLB refill */
  456. cvmx_l2c_lock_mem_region(ebase, 0x100);
  457. #endif
  458. #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_EXCEPTION
  459. /* General exception */
  460. cvmx_l2c_lock_mem_region(ebase + 0x180, 0x80);
  461. #endif
  462. #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_LOW_LEVEL_INTERRUPT
  463. /* Interrupt handler */
  464. cvmx_l2c_lock_mem_region(ebase + 0x200, 0x80);
  465. #endif
  466. #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_INTERRUPT
  467. cvmx_l2c_lock_mem_region(__pa_symbol(handle_int), 0x100);
  468. cvmx_l2c_lock_mem_region(__pa_symbol(plat_irq_dispatch), 0x80);
  469. #endif
  470. #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_MEMCPY
  471. cvmx_l2c_lock_mem_region(__pa_symbol(memcpy), 0x480);
  472. #endif
  473. }
  474. #endif
  475. octeon_check_cpu_bist();
  476. octeon_uart = octeon_get_boot_uart();
  477. #ifdef CONFIG_SMP
  478. octeon_write_lcd("LinuxSMP");
  479. #else
  480. octeon_write_lcd("Linux");
  481. #endif
  482. #ifdef CONFIG_CAVIUM_GDB
  483. /*
  484. * When debugging the linux kernel, force the cores to enter
  485. * the debug exception handler to break in.
  486. */
  487. if (octeon_get_boot_debug_flag()) {
  488. cvmx_write_csr(CVMX_CIU_DINT, 1 << cvmx_get_core_num());
  489. cvmx_read_csr(CVMX_CIU_DINT);
  490. }
  491. #endif
  492. octeon_setup_delays();
  493. /*
  494. * BIST should always be enabled when doing a soft reset. L2
  495. * Cache locking for instance is not cleared unless BIST is
  496. * enabled. Unfortunately due to a chip errata G-200 for
  497. * Cn38XX and CN31XX, BIST msut be disabled on these parts.
  498. */
  499. if (OCTEON_IS_MODEL(OCTEON_CN38XX_PASS2) ||
  500. OCTEON_IS_MODEL(OCTEON_CN31XX))
  501. cvmx_write_csr(CVMX_CIU_SOFT_BIST, 0);
  502. else
  503. cvmx_write_csr(CVMX_CIU_SOFT_BIST, 1);
  504. /* Default to 64MB in the simulator to speed things up */
  505. if (octeon_is_simulation())
  506. MAX_MEMORY = 64ull << 20;
  507. arcs_cmdline[0] = 0;
  508. argc = octeon_boot_desc_ptr->argc;
  509. for (i = 0; i < argc; i++) {
  510. const char *arg =
  511. cvmx_phys_to_ptr(octeon_boot_desc_ptr->argv[i]);
  512. if ((strncmp(arg, "MEM=", 4) == 0) ||
  513. (strncmp(arg, "mem=", 4) == 0)) {
  514. sscanf(arg + 4, "%llu", &MAX_MEMORY);
  515. MAX_MEMORY <<= 20;
  516. if (MAX_MEMORY == 0)
  517. MAX_MEMORY = 32ull << 30;
  518. } else if (strcmp(arg, "ecc_verbose") == 0) {
  519. #ifdef CONFIG_CAVIUM_REPORT_SINGLE_BIT_ECC
  520. __cvmx_interrupt_ecc_report_single_bit_errors = 1;
  521. pr_notice("Reporting of single bit ECC errors is "
  522. "turned on\n");
  523. #endif
  524. } else if (strlen(arcs_cmdline) + strlen(arg) + 1 <
  525. sizeof(arcs_cmdline) - 1) {
  526. strcat(arcs_cmdline, " ");
  527. strcat(arcs_cmdline, arg);
  528. }
  529. }
  530. if (strstr(arcs_cmdline, "console=") == NULL) {
  531. #ifdef CONFIG_CAVIUM_OCTEON_2ND_KERNEL
  532. strcat(arcs_cmdline, " console=ttyS0,115200");
  533. #else
  534. if (octeon_uart == 1)
  535. strcat(arcs_cmdline, " console=ttyS1,115200");
  536. else
  537. strcat(arcs_cmdline, " console=ttyS0,115200");
  538. #endif
  539. }
  540. if (octeon_is_simulation()) {
  541. /*
  542. * The simulator uses a mtdram device pre filled with
  543. * the filesystem. Also specify the calibration delay
  544. * to avoid calculating it every time.
  545. */
  546. strcat(arcs_cmdline, " rw root=1f00 slram=root,0x40000000,+1073741824");
  547. }
  548. mips_hpt_frequency = octeon_get_clock_rate();
  549. octeon_init_cvmcount();
  550. _machine_restart = octeon_restart;
  551. _machine_halt = octeon_halt;
  552. octeon_user_io_init();
  553. register_smp_ops(&octeon_smp_ops);
  554. }
  555. /* Exclude a single page from the regions obtained in plat_mem_setup. */
  556. static __init void memory_exclude_page(u64 addr, u64 *mem, u64 *size)
  557. {
  558. if (addr > *mem && addr < *mem + *size) {
  559. u64 inc = addr - *mem;
  560. add_memory_region(*mem, inc, BOOT_MEM_RAM);
  561. *mem += inc;
  562. *size -= inc;
  563. }
  564. if (addr == *mem && *size > PAGE_SIZE) {
  565. *mem += PAGE_SIZE;
  566. *size -= PAGE_SIZE;
  567. }
  568. }
  569. void __init plat_mem_setup(void)
  570. {
  571. uint64_t mem_alloc_size;
  572. uint64_t total;
  573. int64_t memory;
  574. total = 0;
  575. /*
  576. * The Mips memory init uses the first memory location for
  577. * some memory vectors. When SPARSEMEM is in use, it doesn't
  578. * verify that the size is big enough for the final
  579. * vectors. Making the smallest chuck 4MB seems to be enough
  580. * to consistently work.
  581. */
  582. mem_alloc_size = 4 << 20;
  583. if (mem_alloc_size > MAX_MEMORY)
  584. mem_alloc_size = MAX_MEMORY;
  585. /*
  586. * When allocating memory, we want incrementing addresses from
  587. * bootmem_alloc so the code in add_memory_region can merge
  588. * regions next to each other.
  589. */
  590. cvmx_bootmem_lock();
  591. while ((boot_mem_map.nr_map < BOOT_MEM_MAP_MAX)
  592. && (total < MAX_MEMORY)) {
  593. #if defined(CONFIG_64BIT) || defined(CONFIG_64BIT_PHYS_ADDR)
  594. memory = cvmx_bootmem_phy_alloc(mem_alloc_size,
  595. __pa_symbol(&__init_end), -1,
  596. 0x100000,
  597. CVMX_BOOTMEM_FLAG_NO_LOCKING);
  598. #else
  599. memory = cvmx_bootmem_phy_alloc(mem_alloc_size, 0, 512 << 20,
  600. 0x100000,
  601. CVMX_BOOTMEM_FLAG_NO_LOCKING);
  602. #endif
  603. if (memory >= 0) {
  604. u64 size = mem_alloc_size;
  605. /*
  606. * exclude a page at the beginning and end of
  607. * the 256MB PCIe 'hole' so the kernel will not
  608. * try to allocate multi-page buffers that
  609. * span the discontinuity.
  610. */
  611. memory_exclude_page(CVMX_PCIE_BAR1_PHYS_BASE,
  612. &memory, &size);
  613. memory_exclude_page(CVMX_PCIE_BAR1_PHYS_BASE +
  614. CVMX_PCIE_BAR1_PHYS_SIZE,
  615. &memory, &size);
  616. /*
  617. * This function automatically merges address
  618. * regions next to each other if they are
  619. * received in incrementing order.
  620. */
  621. if (size)
  622. add_memory_region(memory, size, BOOT_MEM_RAM);
  623. total += mem_alloc_size;
  624. } else {
  625. break;
  626. }
  627. }
  628. cvmx_bootmem_unlock();
  629. #ifdef CONFIG_CAVIUM_RESERVE32
  630. /*
  631. * Now that we've allocated the kernel memory it is safe to
  632. * free the reserved region. We free it here so that builtin
  633. * drivers can use the memory.
  634. */
  635. if (octeon_reserve32_memory)
  636. cvmx_bootmem_free_named("CAVIUM_RESERVE32");
  637. #endif /* CONFIG_CAVIUM_RESERVE32 */
  638. if (total == 0)
  639. panic("Unable to allocate memory from "
  640. "cvmx_bootmem_phy_alloc\n");
  641. }
  642. /*
  643. * Emit one character to the boot UART. Exported for use by the
  644. * watchdog timer.
  645. */
  646. int prom_putchar(char c)
  647. {
  648. uint64_t lsrval;
  649. /* Spin until there is room */
  650. do {
  651. lsrval = cvmx_read_csr(CVMX_MIO_UARTX_LSR(octeon_uart));
  652. } while ((lsrval & 0x20) == 0);
  653. /* Write the byte */
  654. cvmx_write_csr(CVMX_MIO_UARTX_THR(octeon_uart), c & 0xffull);
  655. return 1;
  656. }
  657. EXPORT_SYMBOL(prom_putchar);
  658. void prom_free_prom_memory(void)
  659. {
  660. if (OCTEON_IS_MODEL(OCTEON_CN63XX_PASS1_X)) {
  661. /* Check for presence of Core-14449 fix. */
  662. u32 insn;
  663. u32 *foo;
  664. foo = &insn;
  665. asm volatile("# before" : : : "memory");
  666. prefetch(foo);
  667. asm volatile(
  668. ".set push\n\t"
  669. ".set noreorder\n\t"
  670. "bal 1f\n\t"
  671. "nop\n"
  672. "1:\tlw %0,-12($31)\n\t"
  673. ".set pop\n\t"
  674. : "=r" (insn) : : "$31", "memory");
  675. if ((insn >> 26) != 0x33)
  676. panic("No PREF instruction at Core-14449 probe point.");
  677. if (((insn >> 16) & 0x1f) != 28)
  678. panic("Core-14449 WAR not in place (%04x).\n"
  679. "Please build kernel with proper options (CONFIG_CAVIUM_CN63XXP1).", insn);
  680. }
  681. #ifdef CONFIG_CAVIUM_DECODE_RSL
  682. cvmx_interrupt_rsl_enable();
  683. /* Add an interrupt handler for general failures. */
  684. if (request_irq(OCTEON_IRQ_RML, octeon_rlm_interrupt, IRQF_SHARED,
  685. "RML/RSL", octeon_rlm_interrupt)) {
  686. panic("Unable to request_irq(OCTEON_IRQ_RML)");
  687. }
  688. #endif
  689. }
  690. int octeon_prune_device_tree(void);
  691. extern const char __dtb_octeon_3xxx_begin;
  692. extern const char __dtb_octeon_3xxx_end;
  693. extern const char __dtb_octeon_68xx_begin;
  694. extern const char __dtb_octeon_68xx_end;
  695. void __init device_tree_init(void)
  696. {
  697. int dt_size;
  698. struct boot_param_header *fdt;
  699. bool do_prune;
  700. if (octeon_bootinfo->minor_version >= 3 && octeon_bootinfo->fdt_addr) {
  701. fdt = phys_to_virt(octeon_bootinfo->fdt_addr);
  702. if (fdt_check_header(fdt))
  703. panic("Corrupt Device Tree passed to kernel.");
  704. dt_size = be32_to_cpu(fdt->totalsize);
  705. do_prune = false;
  706. } else if (OCTEON_IS_MODEL(OCTEON_CN68XX)) {
  707. fdt = (struct boot_param_header *)&__dtb_octeon_68xx_begin;
  708. dt_size = &__dtb_octeon_68xx_end - &__dtb_octeon_68xx_begin;
  709. do_prune = true;
  710. } else {
  711. fdt = (struct boot_param_header *)&__dtb_octeon_3xxx_begin;
  712. dt_size = &__dtb_octeon_3xxx_end - &__dtb_octeon_3xxx_begin;
  713. do_prune = true;
  714. }
  715. /* Copy the default tree from init memory. */
  716. initial_boot_params = early_init_dt_alloc_memory_arch(dt_size, 8);
  717. if (initial_boot_params == NULL)
  718. panic("Could not allocate initial_boot_params\n");
  719. memcpy(initial_boot_params, fdt, dt_size);
  720. if (do_prune) {
  721. octeon_prune_device_tree();
  722. pr_info("Using internal Device Tree.\n");
  723. } else {
  724. pr_info("Using passed Device Tree.\n");
  725. }
  726. unflatten_device_tree();
  727. }
  728. static char *edac_device_names[] = {
  729. "co_l2c_edac",
  730. "co_lmc_edac",
  731. "co_pc_edac",
  732. };
  733. static int __init edac_devinit(void)
  734. {
  735. struct platform_device *dev;
  736. int i, err = 0;
  737. char *name;
  738. for (i = 0; i < ARRAY_SIZE(edac_device_names); i++) {
  739. name = edac_device_names[i];
  740. dev = platform_device_register_simple(name, -1, NULL, 0);
  741. if (IS_ERR(dev)) {
  742. pr_err("Registation of %s failed!\n", name);
  743. err = PTR_ERR(dev);
  744. }
  745. }
  746. return err;
  747. }
  748. device_initcall(edac_devinit);