setup.c 25 KB

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