setup.c 21 KB

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