setup.c 20 KB

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