setup.c 21 KB

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