setup.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825
  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. #ifdef CONFIG_CAVIUM_RESERVE32_USE_WIRED_TLB
  167. /**
  168. * Called on every core to setup the wired tlb entry needed
  169. * if CONFIG_CAVIUM_RESERVE32_USE_WIRED_TLB is set.
  170. *
  171. */
  172. static void octeon_hal_setup_per_cpu_reserved32(void *unused)
  173. {
  174. /*
  175. * The config has selected to wire the reserve32 memory for all
  176. * userspace applications. We need to put a wired TLB entry in for each
  177. * 512MB of reserve32 memory. We only handle double 256MB pages here,
  178. * so reserve32 must be multiple of 512MB.
  179. */
  180. uint32_t size = CONFIG_CAVIUM_RESERVE32;
  181. uint32_t entrylo0 =
  182. 0x7 | ((octeon_reserve32_memory & ((1ul << 40) - 1)) >> 6);
  183. uint32_t entrylo1 = entrylo0 + (256 << 14);
  184. uint32_t entryhi = (0x80000000UL - (CONFIG_CAVIUM_RESERVE32 << 20));
  185. while (size >= 512) {
  186. #if 0
  187. pr_info("CPU%d: Adding double wired TLB entry for 0x%lx\n",
  188. smp_processor_id(), entryhi);
  189. #endif
  190. add_wired_entry(entrylo0, entrylo1, entryhi, PM_256M);
  191. entrylo0 += 512 << 14;
  192. entrylo1 += 512 << 14;
  193. entryhi += 512 << 20;
  194. size -= 512;
  195. }
  196. }
  197. #endif /* CONFIG_CAVIUM_RESERVE32_USE_WIRED_TLB */
  198. /**
  199. * Called to release the named block which was used to made sure
  200. * that nobody used the memory for something else during
  201. * init. Now we'll free it so userspace apps can use this
  202. * memory region with bootmem_alloc.
  203. *
  204. * This function is called only once from prom_free_prom_memory().
  205. */
  206. void octeon_hal_setup_reserved32(void)
  207. {
  208. #ifdef CONFIG_CAVIUM_RESERVE32_USE_WIRED_TLB
  209. on_each_cpu(octeon_hal_setup_per_cpu_reserved32, NULL, 0, 1);
  210. #endif
  211. }
  212. /**
  213. * Reboot Octeon
  214. *
  215. * @command: Command to pass to the bootloader. Currently ignored.
  216. */
  217. static void octeon_restart(char *command)
  218. {
  219. /* Disable all watchdogs before soft reset. They don't get cleared */
  220. #ifdef CONFIG_SMP
  221. int cpu;
  222. for_each_online_cpu(cpu)
  223. cvmx_write_csr(CVMX_CIU_WDOGX(cpu_logical_map(cpu)), 0);
  224. #else
  225. cvmx_write_csr(CVMX_CIU_WDOGX(cvmx_get_core_num()), 0);
  226. #endif
  227. mb();
  228. while (1)
  229. cvmx_write_csr(CVMX_CIU_SOFT_RST, 1);
  230. }
  231. /**
  232. * Permanently stop a core.
  233. *
  234. * @arg: Ignored.
  235. */
  236. static void octeon_kill_core(void *arg)
  237. {
  238. mb();
  239. if (octeon_is_simulation()) {
  240. /* The simulator needs the watchdog to stop for dead cores */
  241. cvmx_write_csr(CVMX_CIU_WDOGX(cvmx_get_core_num()), 0);
  242. /* A break instruction causes the simulator stop a core */
  243. asm volatile ("sync\nbreak");
  244. }
  245. }
  246. /**
  247. * Halt the system
  248. */
  249. static void octeon_halt(void)
  250. {
  251. smp_call_function(octeon_kill_core, NULL, 0);
  252. switch (octeon_bootinfo->board_type) {
  253. case CVMX_BOARD_TYPE_NAO38:
  254. /* Driving a 1 to GPIO 12 shuts off this board */
  255. cvmx_write_csr(CVMX_GPIO_BIT_CFGX(12), 1);
  256. cvmx_write_csr(CVMX_GPIO_TX_SET, 0x1000);
  257. break;
  258. default:
  259. octeon_write_lcd("PowerOff");
  260. break;
  261. }
  262. octeon_kill_core(NULL);
  263. }
  264. #if 0
  265. /**
  266. * Platform time init specifics.
  267. * Returns
  268. */
  269. void __init plat_time_init(void)
  270. {
  271. /* Nothing special here, but we are required to have one */
  272. }
  273. #endif
  274. /**
  275. * Handle all the error condition interrupts that might occur.
  276. *
  277. */
  278. #ifdef CONFIG_CAVIUM_DECODE_RSL
  279. static irqreturn_t octeon_rlm_interrupt(int cpl, void *dev_id)
  280. {
  281. cvmx_interrupt_rsl_decode();
  282. return IRQ_HANDLED;
  283. }
  284. #endif
  285. /**
  286. * Return a string representing the system type
  287. *
  288. * Returns
  289. */
  290. const char *octeon_board_type_string(void)
  291. {
  292. static char name[80];
  293. sprintf(name, "%s (%s)",
  294. cvmx_board_type_to_string(octeon_bootinfo->board_type),
  295. octeon_model_get_string(read_c0_prid()));
  296. return name;
  297. }
  298. const char *get_system_type(void)
  299. __attribute__ ((alias("octeon_board_type_string")));
  300. void octeon_user_io_init(void)
  301. {
  302. union octeon_cvmemctl cvmmemctl;
  303. union cvmx_iob_fau_timeout fau_timeout;
  304. union cvmx_pow_nw_tim nm_tim;
  305. uint64_t cvmctl;
  306. /* Get the current settings for CP0_CVMMEMCTL_REG */
  307. cvmmemctl.u64 = read_c0_cvmmemctl();
  308. /* R/W If set, marked write-buffer entries time out the same
  309. * as as other entries; if clear, marked write-buffer entries
  310. * use the maximum timeout. */
  311. cvmmemctl.s.dismarkwblongto = 1;
  312. /* R/W If set, a merged store does not clear the write-buffer
  313. * entry timeout state. */
  314. cvmmemctl.s.dismrgclrwbto = 0;
  315. /* R/W Two bits that are the MSBs of the resultant CVMSEG LM
  316. * word location for an IOBDMA. The other 8 bits come from the
  317. * SCRADDR field of the IOBDMA. */
  318. cvmmemctl.s.iobdmascrmsb = 0;
  319. /* R/W If set, SYNCWS and SYNCS only order marked stores; if
  320. * clear, SYNCWS and SYNCS only order unmarked
  321. * stores. SYNCWSMARKED has no effect when DISSYNCWS is
  322. * set. */
  323. cvmmemctl.s.syncwsmarked = 0;
  324. /* R/W If set, SYNCWS acts as SYNCW and SYNCS acts as SYNC. */
  325. cvmmemctl.s.dissyncws = 0;
  326. /* R/W If set, no stall happens on write buffer full. */
  327. if (OCTEON_IS_MODEL(OCTEON_CN38XX_PASS2))
  328. cvmmemctl.s.diswbfst = 1;
  329. else
  330. cvmmemctl.s.diswbfst = 0;
  331. /* R/W If set (and SX set), supervisor-level loads/stores can
  332. * use XKPHYS addresses with <48>==0 */
  333. cvmmemctl.s.xkmemenas = 0;
  334. /* R/W If set (and UX set), user-level loads/stores can use
  335. * XKPHYS addresses with VA<48>==0 */
  336. cvmmemctl.s.xkmemenau = 0;
  337. /* R/W If set (and SX set), supervisor-level loads/stores can
  338. * use XKPHYS addresses with VA<48>==1 */
  339. cvmmemctl.s.xkioenas = 0;
  340. /* R/W If set (and UX set), user-level loads/stores can use
  341. * XKPHYS addresses with VA<48>==1 */
  342. cvmmemctl.s.xkioenau = 0;
  343. /* R/W If set, all stores act as SYNCW (NOMERGE must be set
  344. * when this is set) RW, reset to 0. */
  345. cvmmemctl.s.allsyncw = 0;
  346. /* R/W If set, no stores merge, and all stores reach the
  347. * coherent bus in order. */
  348. cvmmemctl.s.nomerge = 0;
  349. /* R/W Selects the bit in the counter used for DID time-outs 0
  350. * = 231, 1 = 230, 2 = 229, 3 = 214. Actual time-out is
  351. * between 1x and 2x this interval. For example, with
  352. * DIDTTO=3, expiration interval is between 16K and 32K. */
  353. cvmmemctl.s.didtto = 0;
  354. /* R/W If set, the (mem) CSR clock never turns off. */
  355. cvmmemctl.s.csrckalwys = 0;
  356. /* R/W If set, mclk never turns off. */
  357. cvmmemctl.s.mclkalwys = 0;
  358. /* R/W Selects the bit in the counter used for write buffer
  359. * flush time-outs (WBFLT+11) is the bit position in an
  360. * internal counter used to determine expiration. The write
  361. * buffer expires between 1x and 2x this interval. For
  362. * example, with WBFLT = 0, a write buffer expires between 2K
  363. * and 4K cycles after the write buffer entry is allocated. */
  364. cvmmemctl.s.wbfltime = 0;
  365. /* R/W If set, do not put Istream in the L2 cache. */
  366. cvmmemctl.s.istrnol2 = 0;
  367. /* R/W The write buffer threshold. */
  368. cvmmemctl.s.wbthresh = 10;
  369. /* R/W If set, CVMSEG is available for loads/stores in
  370. * kernel/debug mode. */
  371. #if CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE > 0
  372. cvmmemctl.s.cvmsegenak = 1;
  373. #else
  374. cvmmemctl.s.cvmsegenak = 0;
  375. #endif
  376. /* R/W If set, CVMSEG is available for loads/stores in
  377. * supervisor mode. */
  378. cvmmemctl.s.cvmsegenas = 0;
  379. /* R/W If set, CVMSEG is available for loads/stores in user
  380. * mode. */
  381. cvmmemctl.s.cvmsegenau = 0;
  382. /* R/W Size of local memory in cache blocks, 54 (6912 bytes)
  383. * is max legal value. */
  384. cvmmemctl.s.lmemsz = CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE;
  385. if (smp_processor_id() == 0)
  386. pr_notice("CVMSEG size: %d cache lines (%d bytes)\n",
  387. CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE,
  388. CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE * 128);
  389. write_c0_cvmmemctl(cvmmemctl.u64);
  390. /* Move the performance counter interrupts to IRQ 6 */
  391. cvmctl = read_c0_cvmctl();
  392. cvmctl &= ~(7 << 7);
  393. cvmctl |= 6 << 7;
  394. write_c0_cvmctl(cvmctl);
  395. /* Set a default for the hardware timeouts */
  396. fau_timeout.u64 = 0;
  397. fau_timeout.s.tout_val = 0xfff;
  398. /* Disable tagwait FAU timeout */
  399. fau_timeout.s.tout_enb = 0;
  400. cvmx_write_csr(CVMX_IOB_FAU_TIMEOUT, fau_timeout.u64);
  401. nm_tim.u64 = 0;
  402. /* 4096 cycles */
  403. nm_tim.s.nw_tim = 3;
  404. cvmx_write_csr(CVMX_POW_NW_TIM, nm_tim.u64);
  405. write_octeon_c0_icacheerr(0);
  406. write_c0_derraddr1(0);
  407. }
  408. /**
  409. * Early entry point for arch setup
  410. */
  411. void __init prom_init(void)
  412. {
  413. struct cvmx_sysinfo *sysinfo;
  414. const int coreid = cvmx_get_core_num();
  415. int i;
  416. int argc;
  417. struct uart_port octeon_port;
  418. #ifdef CONFIG_CAVIUM_RESERVE32
  419. int64_t addr = -1;
  420. #endif
  421. /*
  422. * The bootloader passes a pointer to the boot descriptor in
  423. * $a3, this is available as fw_arg3.
  424. */
  425. octeon_boot_desc_ptr = (struct octeon_boot_descriptor *)fw_arg3;
  426. octeon_bootinfo =
  427. cvmx_phys_to_ptr(octeon_boot_desc_ptr->cvmx_desc_vaddr);
  428. cvmx_bootmem_init(cvmx_phys_to_ptr(octeon_bootinfo->phy_mem_desc_addr));
  429. /*
  430. * Only enable the LED controller if we're running on a CN38XX, CN58XX,
  431. * or CN56XX. The CN30XX and CN31XX don't have an LED controller.
  432. */
  433. if (!octeon_is_simulation() &&
  434. octeon_has_feature(OCTEON_FEATURE_LED_CONTROLLER)) {
  435. cvmx_write_csr(CVMX_LED_EN, 0);
  436. cvmx_write_csr(CVMX_LED_PRT, 0);
  437. cvmx_write_csr(CVMX_LED_DBG, 0);
  438. cvmx_write_csr(CVMX_LED_PRT_FMT, 0);
  439. cvmx_write_csr(CVMX_LED_UDD_CNTX(0), 32);
  440. cvmx_write_csr(CVMX_LED_UDD_CNTX(1), 32);
  441. cvmx_write_csr(CVMX_LED_UDD_DATX(0), 0);
  442. cvmx_write_csr(CVMX_LED_UDD_DATX(1), 0);
  443. cvmx_write_csr(CVMX_LED_EN, 1);
  444. }
  445. #ifdef CONFIG_CAVIUM_RESERVE32
  446. /*
  447. * We need to temporarily allocate all memory in the reserve32
  448. * region. This makes sure the kernel doesn't allocate this
  449. * memory when it is getting memory from the
  450. * bootloader. Later, after the memory allocations are
  451. * complete, the reserve32 will be freed.
  452. */
  453. #ifdef CONFIG_CAVIUM_RESERVE32_USE_WIRED_TLB
  454. if (CONFIG_CAVIUM_RESERVE32 & 0x1ff)
  455. pr_err("CAVIUM_RESERVE32 isn't a multiple of 512MB. "
  456. "This is required if CAVIUM_RESERVE32_USE_WIRED_TLB "
  457. "is set\n");
  458. else
  459. addr = cvmx_bootmem_phy_named_block_alloc(CONFIG_CAVIUM_RESERVE32 << 20,
  460. 0, 0, 512 << 20,
  461. "CAVIUM_RESERVE32", 0);
  462. #else
  463. /*
  464. * Allocate memory for RESERVED32 aligned on 2MB boundary. This
  465. * is in case we later use hugetlb entries with it.
  466. */
  467. addr = cvmx_bootmem_phy_named_block_alloc(CONFIG_CAVIUM_RESERVE32 << 20,
  468. 0, 0, 2 << 20,
  469. "CAVIUM_RESERVE32", 0);
  470. #endif
  471. if (addr < 0)
  472. pr_err("Failed to allocate CAVIUM_RESERVE32 memory area\n");
  473. else
  474. octeon_reserve32_memory = addr;
  475. #endif
  476. #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2
  477. if (cvmx_read_csr(CVMX_L2D_FUS3) & (3ull << 34)) {
  478. pr_info("Skipping L2 locking due to reduced L2 cache size\n");
  479. } else {
  480. uint32_t ebase = read_c0_ebase() & 0x3ffff000;
  481. #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_TLB
  482. /* TLB refill */
  483. cvmx_l2c_lock_mem_region(ebase, 0x100);
  484. #endif
  485. #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_EXCEPTION
  486. /* General exception */
  487. cvmx_l2c_lock_mem_region(ebase + 0x180, 0x80);
  488. #endif
  489. #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_LOW_LEVEL_INTERRUPT
  490. /* Interrupt handler */
  491. cvmx_l2c_lock_mem_region(ebase + 0x200, 0x80);
  492. #endif
  493. #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_INTERRUPT
  494. cvmx_l2c_lock_mem_region(__pa_symbol(handle_int), 0x100);
  495. cvmx_l2c_lock_mem_region(__pa_symbol(plat_irq_dispatch), 0x80);
  496. #endif
  497. #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_MEMCPY
  498. cvmx_l2c_lock_mem_region(__pa_symbol(memcpy), 0x480);
  499. #endif
  500. }
  501. #endif
  502. sysinfo = cvmx_sysinfo_get();
  503. memset(sysinfo, 0, sizeof(*sysinfo));
  504. sysinfo->system_dram_size = octeon_bootinfo->dram_size << 20;
  505. sysinfo->phy_mem_desc_ptr =
  506. cvmx_phys_to_ptr(octeon_bootinfo->phy_mem_desc_addr);
  507. sysinfo->core_mask = octeon_bootinfo->core_mask;
  508. sysinfo->exception_base_addr = octeon_bootinfo->exception_base_addr;
  509. sysinfo->cpu_clock_hz = octeon_bootinfo->eclock_hz;
  510. sysinfo->dram_data_rate_hz = octeon_bootinfo->dclock_hz * 2;
  511. sysinfo->board_type = octeon_bootinfo->board_type;
  512. sysinfo->board_rev_major = octeon_bootinfo->board_rev_major;
  513. sysinfo->board_rev_minor = octeon_bootinfo->board_rev_minor;
  514. memcpy(sysinfo->mac_addr_base, octeon_bootinfo->mac_addr_base,
  515. sizeof(sysinfo->mac_addr_base));
  516. sysinfo->mac_addr_count = octeon_bootinfo->mac_addr_count;
  517. memcpy(sysinfo->board_serial_number,
  518. octeon_bootinfo->board_serial_number,
  519. sizeof(sysinfo->board_serial_number));
  520. sysinfo->compact_flash_common_base_addr =
  521. octeon_bootinfo->compact_flash_common_base_addr;
  522. sysinfo->compact_flash_attribute_base_addr =
  523. octeon_bootinfo->compact_flash_attribute_base_addr;
  524. sysinfo->led_display_base_addr = octeon_bootinfo->led_display_base_addr;
  525. sysinfo->dfa_ref_clock_hz = octeon_bootinfo->dfa_ref_clock_hz;
  526. sysinfo->bootloader_config_flags = octeon_bootinfo->config_flags;
  527. octeon_check_cpu_bist();
  528. octeon_uart = octeon_get_boot_uart();
  529. /*
  530. * Disable All CIU Interrupts. The ones we need will be
  531. * enabled later. Read the SUM register so we know the write
  532. * completed.
  533. */
  534. cvmx_write_csr(CVMX_CIU_INTX_EN0((coreid * 2)), 0);
  535. cvmx_write_csr(CVMX_CIU_INTX_EN0((coreid * 2 + 1)), 0);
  536. cvmx_write_csr(CVMX_CIU_INTX_EN1((coreid * 2)), 0);
  537. cvmx_write_csr(CVMX_CIU_INTX_EN1((coreid * 2 + 1)), 0);
  538. cvmx_read_csr(CVMX_CIU_INTX_SUM0((coreid * 2)));
  539. #ifdef CONFIG_SMP
  540. octeon_write_lcd("LinuxSMP");
  541. #else
  542. octeon_write_lcd("Linux");
  543. #endif
  544. #ifdef CONFIG_CAVIUM_GDB
  545. /*
  546. * When debugging the linux kernel, force the cores to enter
  547. * the debug exception handler to break in.
  548. */
  549. if (octeon_get_boot_debug_flag()) {
  550. cvmx_write_csr(CVMX_CIU_DINT, 1 << cvmx_get_core_num());
  551. cvmx_read_csr(CVMX_CIU_DINT);
  552. }
  553. #endif
  554. /*
  555. * BIST should always be enabled when doing a soft reset. L2
  556. * Cache locking for instance is not cleared unless BIST is
  557. * enabled. Unfortunately due to a chip errata G-200 for
  558. * Cn38XX and CN31XX, BIST msut be disabled on these parts.
  559. */
  560. if (OCTEON_IS_MODEL(OCTEON_CN38XX_PASS2) ||
  561. OCTEON_IS_MODEL(OCTEON_CN31XX))
  562. cvmx_write_csr(CVMX_CIU_SOFT_BIST, 0);
  563. else
  564. cvmx_write_csr(CVMX_CIU_SOFT_BIST, 1);
  565. /* Default to 64MB in the simulator to speed things up */
  566. if (octeon_is_simulation())
  567. MAX_MEMORY = 64ull << 20;
  568. arcs_cmdline[0] = 0;
  569. argc = octeon_boot_desc_ptr->argc;
  570. for (i = 0; i < argc; i++) {
  571. const char *arg =
  572. cvmx_phys_to_ptr(octeon_boot_desc_ptr->argv[i]);
  573. if ((strncmp(arg, "MEM=", 4) == 0) ||
  574. (strncmp(arg, "mem=", 4) == 0)) {
  575. sscanf(arg + 4, "%llu", &MAX_MEMORY);
  576. MAX_MEMORY <<= 20;
  577. if (MAX_MEMORY == 0)
  578. MAX_MEMORY = 32ull << 30;
  579. } else if (strcmp(arg, "ecc_verbose") == 0) {
  580. #ifdef CONFIG_CAVIUM_REPORT_SINGLE_BIT_ECC
  581. __cvmx_interrupt_ecc_report_single_bit_errors = 1;
  582. pr_notice("Reporting of single bit ECC errors is "
  583. "turned on\n");
  584. #endif
  585. } else if (strlen(arcs_cmdline) + strlen(arg) + 1 <
  586. sizeof(arcs_cmdline) - 1) {
  587. strcat(arcs_cmdline, " ");
  588. strcat(arcs_cmdline, arg);
  589. }
  590. }
  591. if (strstr(arcs_cmdline, "console=") == NULL) {
  592. #ifdef CONFIG_GDB_CONSOLE
  593. strcat(arcs_cmdline, " console=gdb");
  594. #else
  595. #ifdef CONFIG_CAVIUM_OCTEON_2ND_KERNEL
  596. strcat(arcs_cmdline, " console=ttyS0,115200");
  597. #else
  598. if (octeon_uart == 1)
  599. strcat(arcs_cmdline, " console=ttyS1,115200");
  600. else
  601. strcat(arcs_cmdline, " console=ttyS0,115200");
  602. #endif
  603. #endif
  604. }
  605. if (octeon_is_simulation()) {
  606. /*
  607. * The simulator uses a mtdram device pre filled with
  608. * the filesystem. Also specify the calibration delay
  609. * to avoid calculating it every time.
  610. */
  611. strcat(arcs_cmdline, " rw root=1f00"
  612. " lpj=60176 slram=root,0x40000000,+1073741824");
  613. }
  614. mips_hpt_frequency = octeon_get_clock_rate();
  615. octeon_init_cvmcount();
  616. _machine_restart = octeon_restart;
  617. _machine_halt = octeon_halt;
  618. memset(&octeon_port, 0, sizeof(octeon_port));
  619. /*
  620. * For early_serial_setup we don't set the port type or
  621. * UPF_FIXED_TYPE.
  622. */
  623. octeon_port.flags = ASYNC_SKIP_TEST | UPF_SHARE_IRQ;
  624. octeon_port.iotype = UPIO_MEM;
  625. /* I/O addresses are every 8 bytes */
  626. octeon_port.regshift = 3;
  627. /* Clock rate of the chip */
  628. octeon_port.uartclk = mips_hpt_frequency;
  629. octeon_port.fifosize = 64;
  630. octeon_port.mapbase = 0x0001180000000800ull + (1024 * octeon_uart);
  631. octeon_port.membase = cvmx_phys_to_ptr(octeon_port.mapbase);
  632. octeon_port.serial_in = octeon_serial_in;
  633. octeon_port.serial_out = octeon_serial_out;
  634. #ifdef CONFIG_CAVIUM_OCTEON_2ND_KERNEL
  635. octeon_port.line = 0;
  636. #else
  637. octeon_port.line = octeon_uart;
  638. #endif
  639. octeon_port.irq = 42 + octeon_uart;
  640. early_serial_setup(&octeon_port);
  641. octeon_user_io_init();
  642. register_smp_ops(&octeon_smp_ops);
  643. }
  644. void __init plat_mem_setup(void)
  645. {
  646. uint64_t mem_alloc_size;
  647. uint64_t total;
  648. int64_t memory;
  649. total = 0;
  650. /* First add the init memory we will be returning. */
  651. memory = __pa_symbol(&__init_begin) & PAGE_MASK;
  652. mem_alloc_size = (__pa_symbol(&__init_end) & PAGE_MASK) - memory;
  653. if (mem_alloc_size > 0) {
  654. add_memory_region(memory, mem_alloc_size, BOOT_MEM_RAM);
  655. total += mem_alloc_size;
  656. }
  657. /*
  658. * The Mips memory init uses the first memory location for
  659. * some memory vectors. When SPARSEMEM is in use, it doesn't
  660. * verify that the size is big enough for the final
  661. * vectors. Making the smallest chuck 4MB seems to be enough
  662. * to consistantly work.
  663. */
  664. mem_alloc_size = 4 << 20;
  665. if (mem_alloc_size > MAX_MEMORY)
  666. mem_alloc_size = MAX_MEMORY;
  667. /*
  668. * When allocating memory, we want incrementing addresses from
  669. * bootmem_alloc so the code in add_memory_region can merge
  670. * regions next to each other.
  671. */
  672. cvmx_bootmem_lock();
  673. while ((boot_mem_map.nr_map < BOOT_MEM_MAP_MAX)
  674. && (total < MAX_MEMORY)) {
  675. #if defined(CONFIG_64BIT) || defined(CONFIG_64BIT_PHYS_ADDR)
  676. memory = cvmx_bootmem_phy_alloc(mem_alloc_size,
  677. __pa_symbol(&__init_end), -1,
  678. 0x100000,
  679. CVMX_BOOTMEM_FLAG_NO_LOCKING);
  680. #elif defined(CONFIG_HIGHMEM)
  681. memory = cvmx_bootmem_phy_alloc(mem_alloc_size, 0, 1ull << 31,
  682. 0x100000,
  683. CVMX_BOOTMEM_FLAG_NO_LOCKING);
  684. #else
  685. memory = cvmx_bootmem_phy_alloc(mem_alloc_size, 0, 512 << 20,
  686. 0x100000,
  687. CVMX_BOOTMEM_FLAG_NO_LOCKING);
  688. #endif
  689. if (memory >= 0) {
  690. /*
  691. * This function automatically merges address
  692. * regions next to each other if they are
  693. * received in incrementing order.
  694. */
  695. add_memory_region(memory, mem_alloc_size, BOOT_MEM_RAM);
  696. total += mem_alloc_size;
  697. } else {
  698. break;
  699. }
  700. }
  701. cvmx_bootmem_unlock();
  702. #ifdef CONFIG_CAVIUM_RESERVE32
  703. /*
  704. * Now that we've allocated the kernel memory it is safe to
  705. * free the reserved region. We free it here so that builtin
  706. * drivers can use the memory.
  707. */
  708. if (octeon_reserve32_memory)
  709. cvmx_bootmem_free_named("CAVIUM_RESERVE32");
  710. #endif /* CONFIG_CAVIUM_RESERVE32 */
  711. if (total == 0)
  712. panic("Unable to allocate memory from "
  713. "cvmx_bootmem_phy_alloc\n");
  714. }
  715. int prom_putchar(char c)
  716. {
  717. uint64_t lsrval;
  718. /* Spin until there is room */
  719. do {
  720. lsrval = cvmx_read_csr(CVMX_MIO_UARTX_LSR(octeon_uart));
  721. } while ((lsrval & 0x20) == 0);
  722. /* Write the byte */
  723. cvmx_write_csr(CVMX_MIO_UARTX_THR(octeon_uart), c);
  724. return 1;
  725. }
  726. void prom_free_prom_memory(void)
  727. {
  728. #ifdef CONFIG_CAVIUM_DECODE_RSL
  729. cvmx_interrupt_rsl_enable();
  730. /* Add an interrupt handler for general failures. */
  731. if (request_irq(OCTEON_IRQ_RML, octeon_rlm_interrupt, IRQF_SHARED,
  732. "RML/RSL", octeon_rlm_interrupt)) {
  733. panic("Unable to request_irq(OCTEON_IRQ_RML)\n");
  734. }
  735. #endif
  736. /* This call is here so that it is performed after any TLB
  737. initializations. It needs to be after these in case the
  738. CONFIG_CAVIUM_RESERVE32_USE_WIRED_TLB option is set */
  739. octeon_hal_setup_reserved32();
  740. }