setup.c 22 KB

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