setup.c 25 KB

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