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
6 * Copyright (C) 2004-2007 Cavium Networks
7 * Copyright (C) 2008, 2009 Wind River Systems
8 * written by Ralf Baechle <ralf@linux-mips.org>
10 #include <linux/compiler.h>
11 #include <linux/init.h>
12 #include <linux/kernel.h>
13 #include <linux/console.h>
14 #include <linux/delay.h>
15 #include <linux/export.h>
16 #include <linux/interrupt.h>
18 #include <linux/serial.h>
19 #include <linux/smp.h>
20 #include <linux/types.h>
21 #include <linux/string.h> /* for memset */
22 #include <linux/tty.h>
23 #include <linux/time.h>
24 #include <linux/platform_device.h>
25 #include <linux/serial_core.h>
26 #include <linux/serial_8250.h>
27 #include <linux/of_fdt.h>
28 #include <linux/libfdt.h>
29 #include <linux/kexec.h>
31 #include <asm/processor.h>
32 #include <asm/reboot.h>
33 #include <asm/smp-ops.h>
34 #include <asm/irq_cpu.h>
35 #include <asm/mipsregs.h>
36 #include <asm/bootinfo.h>
37 #include <asm/sections.h>
40 #include <asm/octeon/octeon.h>
41 #include <asm/octeon/pci-octeon.h>
42 #include <asm/octeon/cvmx-mio-defs.h>
44 extern struct plat_smp_ops octeon_smp_ops;
47 extern void pci_console_init(const char *arg);
50 static unsigned long long MAX_MEMORY = 512ull << 20;
52 struct octeon_boot_descriptor *octeon_boot_desc_ptr;
54 struct cvmx_bootinfo *octeon_bootinfo;
55 EXPORT_SYMBOL(octeon_bootinfo);
57 static unsigned long long RESERVE_LOW_MEM = 0ull;
61 * Wait for relocation code is prepared and send
62 * secondary CPUs to spin until kernel is relocated.
64 static void octeon_kexec_smp_down(void *ignored)
66 int cpu = smp_processor_id();
69 set_cpu_online(cpu, false);
70 while (!atomic_read(&kexec_ready_to_reboot))
77 relocated_kexec_smp_wait(NULL);
81 #define OCTEON_DDR0_BASE (0x0ULL)
82 #define OCTEON_DDR0_SIZE (0x010000000ULL)
83 #define OCTEON_DDR1_BASE (0x410000000ULL)
84 #define OCTEON_DDR1_SIZE (0x010000000ULL)
85 #define OCTEON_DDR2_BASE (0x020000000ULL)
86 #define OCTEON_DDR2_SIZE (0x3e0000000ULL)
87 #define OCTEON_MAX_PHY_MEM_SIZE (16*1024*1024*1024ULL)
89 static struct kimage *kimage_ptr;
91 static void kexec_bootmem_init(uint64_t mem_size, uint32_t low_reserved_bytes)
94 struct cvmx_bootmem_desc *bootmem_desc;
96 bootmem_desc = cvmx_bootmem_get_desc();
98 if (mem_size > OCTEON_MAX_PHY_MEM_SIZE) {
99 mem_size = OCTEON_MAX_PHY_MEM_SIZE;
100 pr_err("Error: requested memory too large,"
101 "truncating to maximum size\n");
104 bootmem_desc->major_version = CVMX_BOOTMEM_DESC_MAJ_VER;
105 bootmem_desc->minor_version = CVMX_BOOTMEM_DESC_MIN_VER;
107 addr = (OCTEON_DDR0_BASE + RESERVE_LOW_MEM + low_reserved_bytes);
108 bootmem_desc->head_addr = 0;
110 if (mem_size <= OCTEON_DDR0_SIZE) {
111 __cvmx_bootmem_phy_free(addr,
112 mem_size - RESERVE_LOW_MEM -
113 low_reserved_bytes, 0);
117 __cvmx_bootmem_phy_free(addr,
118 OCTEON_DDR0_SIZE - RESERVE_LOW_MEM -
119 low_reserved_bytes, 0);
121 mem_size -= OCTEON_DDR0_SIZE;
123 if (mem_size > OCTEON_DDR1_SIZE) {
124 __cvmx_bootmem_phy_free(OCTEON_DDR1_BASE, OCTEON_DDR1_SIZE, 0);
125 __cvmx_bootmem_phy_free(OCTEON_DDR2_BASE,
126 mem_size - OCTEON_DDR1_SIZE, 0);
128 __cvmx_bootmem_phy_free(OCTEON_DDR1_BASE, mem_size, 0);
131 static int octeon_kexec_prepare(struct kimage *image)
134 char *bootloader = "kexec";
136 octeon_boot_desc_ptr->argc = 0;
137 for (i = 0; i < image->nr_segments; i++) {
138 if (!strncmp(bootloader, (char *)image->segment[i].buf,
139 strlen(bootloader))) {
141 * convert command line string to array
142 * of parameters (as bootloader does).
145 char *str = (char *)image->segment[i].buf;
146 char *ptr = strchr(str, ' ');
147 while (ptr && (OCTEON_ARGV_MAX_ARGS > argc)) {
150 offt = (int)(ptr - str + 1);
151 octeon_boot_desc_ptr->argv[argc] =
152 image->segment[i].mem + offt;
155 ptr = strchr(ptr + 1, ' ');
157 octeon_boot_desc_ptr->argc = argc;
163 * Information about segments will be needed during pre-boot memory
170 static void octeon_generic_shutdown(void)
176 struct cvmx_bootmem_desc *bootmem_desc;
177 void *named_block_array_ptr;
179 bootmem_desc = cvmx_bootmem_get_desc();
180 named_block_array_ptr =
181 cvmx_phys_to_ptr(bootmem_desc->named_block_array_addr);
184 /* disable watchdogs */
185 for_each_online_cpu(cpu)
186 cvmx_write_csr(CVMX_CIU_WDOGX(cpu_logical_map(cpu)), 0);
188 cvmx_write_csr(CVMX_CIU_WDOGX(cvmx_get_core_num()), 0);
190 if (kimage_ptr != kexec_crash_image) {
191 memset(named_block_array_ptr,
193 CVMX_BOOTMEM_NUM_NAMED_BLOCKS *
194 sizeof(struct cvmx_bootmem_named_block_desc));
196 * Mark all memory (except low 0x100000 bytes) as free.
197 * It is the same thing that bootloader does.
199 kexec_bootmem_init(octeon_bootinfo->dram_size*1024ULL*1024ULL,
202 * Allocate all segments to avoid their corruption during boot.
204 for (i = 0; i < kimage_ptr->nr_segments; i++)
205 cvmx_bootmem_alloc_address(
206 kimage_ptr->segment[i].memsz + 2*PAGE_SIZE,
207 kimage_ptr->segment[i].mem - PAGE_SIZE,
211 * Do not mark all memory as free. Free only named sections
212 * leaving the rest of memory unchanged.
214 struct cvmx_bootmem_named_block_desc *ptr =
215 (struct cvmx_bootmem_named_block_desc *)
216 named_block_array_ptr;
218 for (i = 0; i < bootmem_desc->named_block_num_blocks; i++)
220 cvmx_bootmem_free_named(ptr[i].name);
222 kexec_args[2] = 1UL; /* running on octeon_main_processor */
223 kexec_args[3] = (unsigned long)octeon_boot_desc_ptr;
225 secondary_kexec_args[2] = 0UL; /* running on secondary cpu */
226 secondary_kexec_args[3] = (unsigned long)octeon_boot_desc_ptr;
230 static void octeon_shutdown(void)
232 octeon_generic_shutdown();
234 smp_call_function(octeon_kexec_smp_down, NULL, 0);
236 while (num_online_cpus() > 1) {
243 static void octeon_crash_shutdown(struct pt_regs *regs)
245 octeon_generic_shutdown();
246 default_machine_crash_shutdown(regs);
249 #endif /* CONFIG_KEXEC */
251 #ifdef CONFIG_CAVIUM_RESERVE32
252 uint64_t octeon_reserve32_memory;
253 EXPORT_SYMBOL(octeon_reserve32_memory);
257 /* crashkernel cmdline parameter is parsed _after_ memory setup
258 * we also parse it here (workaround for EHB5200) */
259 static uint64_t crashk_size, crashk_base;
262 static int octeon_uart;
264 extern asmlinkage void handle_int(void);
265 extern asmlinkage void plat_irq_dispatch(void);
268 * Return non zero if we are currently running in the Octeon simulator
272 int octeon_is_simulation(void)
274 return octeon_bootinfo->board_type == CVMX_BOARD_TYPE_SIM;
276 EXPORT_SYMBOL(octeon_is_simulation);
279 * Return true if Octeon is in PCI Host mode. This means
280 * Linux can control the PCI bus.
282 * Returns Non zero if Octeon in host mode.
284 int octeon_is_pci_host(void)
287 return octeon_bootinfo->config_flags & CVMX_BOOTINFO_CFG_FLAG_PCI_HOST;
294 * Get the clock rate of Octeon
296 * Returns Clock rate in HZ
298 uint64_t octeon_get_clock_rate(void)
300 struct cvmx_sysinfo *sysinfo = cvmx_sysinfo_get();
302 return sysinfo->cpu_clock_hz;
304 EXPORT_SYMBOL(octeon_get_clock_rate);
306 static u64 octeon_io_clock_rate;
308 u64 octeon_get_io_clock_rate(void)
310 return octeon_io_clock_rate;
312 EXPORT_SYMBOL(octeon_get_io_clock_rate);
316 * Write to the LCD display connected to the bootbus. This display
317 * exists on most Cavium evaluation boards. If it doesn't exist, then
318 * this function doesn't do anything.
320 * @s: String to write
322 void octeon_write_lcd(const char *s)
324 if (octeon_bootinfo->led_display_base_addr) {
325 void __iomem *lcd_address =
326 ioremap_nocache(octeon_bootinfo->led_display_base_addr,
329 for (i = 0; i < 8; i++, s++) {
331 iowrite8(*s, lcd_address + i);
333 iowrite8(' ', lcd_address + i);
335 iounmap(lcd_address);
340 * Return the console uart passed by the bootloader
342 * Returns uart (0 or 1)
344 int octeon_get_boot_uart(void)
347 #ifdef CONFIG_CAVIUM_OCTEON_2ND_KERNEL
350 uart = (octeon_boot_desc_ptr->flags & OCTEON_BL_FLAG_CONSOLE_UART1) ?
357 * Get the coremask Linux was booted on.
361 int octeon_get_boot_coremask(void)
363 return octeon_boot_desc_ptr->core_mask;
367 * Check the hardware BIST results for a CPU
369 void octeon_check_cpu_bist(void)
371 const int coreid = cvmx_get_core_num();
372 unsigned long long mask;
373 unsigned long long bist_val;
375 /* Check BIST results for COP0 registers */
376 mask = 0x1f00000000ull;
377 bist_val = read_octeon_c0_icacheerr();
379 pr_err("Core%d BIST Failure: CacheErr(icache) = 0x%llx\n",
382 bist_val = read_octeon_c0_dcacheerr();
384 pr_err("Core%d L1 Dcache parity error: "
385 "CacheErr(dcache) = 0x%llx\n",
388 mask = 0xfc00000000000000ull;
389 bist_val = read_c0_cvmmemctl();
391 pr_err("Core%d BIST Failure: COP0_CVM_MEM_CTL = 0x%llx\n",
394 write_octeon_c0_dcacheerr(0);
400 * @command: Command to pass to the bootloader. Currently ignored.
402 static void octeon_restart(char *command)
404 /* Disable all watchdogs before soft reset. They don't get cleared */
407 for_each_online_cpu(cpu)
408 cvmx_write_csr(CVMX_CIU_WDOGX(cpu_logical_map(cpu)), 0);
410 cvmx_write_csr(CVMX_CIU_WDOGX(cvmx_get_core_num()), 0);
415 cvmx_write_csr(CVMX_CIU_SOFT_RST, 1);
420 * Permanently stop a core.
424 static void octeon_kill_core(void *arg)
426 if (octeon_is_simulation())
427 /* A break instruction causes the simulator stop a core */
428 asm volatile ("break" ::: "memory");
431 /* Disable watchdog on this core. */
432 cvmx_write_csr(CVMX_CIU_WDOGX(cvmx_get_core_num()), 0);
433 /* Spin in a low power mode. */
435 asm volatile ("wait" ::: "memory");
442 static void octeon_halt(void)
444 smp_call_function(octeon_kill_core, NULL, 0);
446 switch (octeon_bootinfo->board_type) {
447 case CVMX_BOARD_TYPE_NAO38:
448 /* Driving a 1 to GPIO 12 shuts off this board */
449 cvmx_write_csr(CVMX_GPIO_BIT_CFGX(12), 1);
450 cvmx_write_csr(CVMX_GPIO_TX_SET, 0x1000);
453 octeon_write_lcd("PowerOff");
457 octeon_kill_core(NULL);
461 * Return a string representing the system type
465 const char *octeon_board_type_string(void)
467 static char name[80];
468 sprintf(name, "%s (%s)",
469 cvmx_board_type_to_string(octeon_bootinfo->board_type),
470 octeon_model_get_string(read_c0_prid()));
474 const char *get_system_type(void)
475 __attribute__ ((alias("octeon_board_type_string")));
477 void octeon_user_io_init(void)
479 union octeon_cvmemctl cvmmemctl;
480 union cvmx_iob_fau_timeout fau_timeout;
481 union cvmx_pow_nw_tim nm_tim;
483 /* Get the current settings for CP0_CVMMEMCTL_REG */
484 cvmmemctl.u64 = read_c0_cvmmemctl();
485 /* R/W If set, marked write-buffer entries time out the same
486 * as as other entries; if clear, marked write-buffer entries
487 * use the maximum timeout. */
488 cvmmemctl.s.dismarkwblongto = 1;
489 /* R/W If set, a merged store does not clear the write-buffer
490 * entry timeout state. */
491 cvmmemctl.s.dismrgclrwbto = 0;
492 /* R/W Two bits that are the MSBs of the resultant CVMSEG LM
493 * word location for an IOBDMA. The other 8 bits come from the
494 * SCRADDR field of the IOBDMA. */
495 cvmmemctl.s.iobdmascrmsb = 0;
496 /* R/W If set, SYNCWS and SYNCS only order marked stores; if
497 * clear, SYNCWS and SYNCS only order unmarked
498 * stores. SYNCWSMARKED has no effect when DISSYNCWS is
500 cvmmemctl.s.syncwsmarked = 0;
501 /* R/W If set, SYNCWS acts as SYNCW and SYNCS acts as SYNC. */
502 cvmmemctl.s.dissyncws = 0;
503 /* R/W If set, no stall happens on write buffer full. */
504 if (OCTEON_IS_MODEL(OCTEON_CN38XX_PASS2))
505 cvmmemctl.s.diswbfst = 1;
507 cvmmemctl.s.diswbfst = 0;
508 /* R/W If set (and SX set), supervisor-level loads/stores can
509 * use XKPHYS addresses with <48>==0 */
510 cvmmemctl.s.xkmemenas = 0;
512 /* R/W If set (and UX set), user-level loads/stores can use
513 * XKPHYS addresses with VA<48>==0 */
514 cvmmemctl.s.xkmemenau = 0;
516 /* R/W If set (and SX set), supervisor-level loads/stores can
517 * use XKPHYS addresses with VA<48>==1 */
518 cvmmemctl.s.xkioenas = 0;
520 /* R/W If set (and UX set), user-level loads/stores can use
521 * XKPHYS addresses with VA<48>==1 */
522 cvmmemctl.s.xkioenau = 0;
524 /* R/W If set, all stores act as SYNCW (NOMERGE must be set
525 * when this is set) RW, reset to 0. */
526 cvmmemctl.s.allsyncw = 0;
528 /* R/W If set, no stores merge, and all stores reach the
529 * coherent bus in order. */
530 cvmmemctl.s.nomerge = 0;
531 /* R/W Selects the bit in the counter used for DID time-outs 0
532 * = 231, 1 = 230, 2 = 229, 3 = 214. Actual time-out is
533 * between 1x and 2x this interval. For example, with
534 * DIDTTO=3, expiration interval is between 16K and 32K. */
535 cvmmemctl.s.didtto = 0;
536 /* R/W If set, the (mem) CSR clock never turns off. */
537 cvmmemctl.s.csrckalwys = 0;
538 /* R/W If set, mclk never turns off. */
539 cvmmemctl.s.mclkalwys = 0;
540 /* R/W Selects the bit in the counter used for write buffer
541 * flush time-outs (WBFLT+11) is the bit position in an
542 * internal counter used to determine expiration. The write
543 * buffer expires between 1x and 2x this interval. For
544 * example, with WBFLT = 0, a write buffer expires between 2K
545 * and 4K cycles after the write buffer entry is allocated. */
546 cvmmemctl.s.wbfltime = 0;
547 /* R/W If set, do not put Istream in the L2 cache. */
548 cvmmemctl.s.istrnol2 = 0;
551 * R/W The write buffer threshold. As per erratum Core-14752
552 * for CN63XX, a sc/scd might fail if the write buffer is
553 * full. Lowering WBTHRESH greatly lowers the chances of the
554 * write buffer ever being full and triggering the erratum.
556 if (OCTEON_IS_MODEL(OCTEON_CN63XX_PASS1_X))
557 cvmmemctl.s.wbthresh = 4;
559 cvmmemctl.s.wbthresh = 10;
561 /* R/W If set, CVMSEG is available for loads/stores in
562 * kernel/debug mode. */
563 #if CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE > 0
564 cvmmemctl.s.cvmsegenak = 1;
566 cvmmemctl.s.cvmsegenak = 0;
568 /* R/W If set, CVMSEG is available for loads/stores in
569 * supervisor mode. */
570 cvmmemctl.s.cvmsegenas = 0;
571 /* R/W If set, CVMSEG is available for loads/stores in user
573 cvmmemctl.s.cvmsegenau = 0;
574 /* R/W Size of local memory in cache blocks, 54 (6912 bytes)
575 * is max legal value. */
576 cvmmemctl.s.lmemsz = CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE;
578 write_c0_cvmmemctl(cvmmemctl.u64);
580 if (smp_processor_id() == 0)
581 pr_notice("CVMSEG size: %d cache lines (%d bytes)\n",
582 CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE,
583 CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE * 128);
585 /* Set a default for the hardware timeouts */
587 fau_timeout.s.tout_val = 0xfff;
588 /* Disable tagwait FAU timeout */
589 fau_timeout.s.tout_enb = 0;
590 cvmx_write_csr(CVMX_IOB_FAU_TIMEOUT, fau_timeout.u64);
595 cvmx_write_csr(CVMX_POW_NW_TIM, nm_tim.u64);
597 write_octeon_c0_icacheerr(0);
598 write_c0_derraddr1(0);
602 * Early entry point for arch setup
604 void __init prom_init(void)
606 struct cvmx_sysinfo *sysinfo;
611 #ifdef CONFIG_CAVIUM_RESERVE32
615 * The bootloader passes a pointer to the boot descriptor in
616 * $a3, this is available as fw_arg3.
618 octeon_boot_desc_ptr = (struct octeon_boot_descriptor *)fw_arg3;
620 cvmx_phys_to_ptr(octeon_boot_desc_ptr->cvmx_desc_vaddr);
621 cvmx_bootmem_init(cvmx_phys_to_ptr(octeon_bootinfo->phy_mem_desc_addr));
623 sysinfo = cvmx_sysinfo_get();
624 memset(sysinfo, 0, sizeof(*sysinfo));
625 sysinfo->system_dram_size = octeon_bootinfo->dram_size << 20;
626 sysinfo->phy_mem_desc_ptr =
627 cvmx_phys_to_ptr(octeon_bootinfo->phy_mem_desc_addr);
628 sysinfo->core_mask = octeon_bootinfo->core_mask;
629 sysinfo->exception_base_addr = octeon_bootinfo->exception_base_addr;
630 sysinfo->cpu_clock_hz = octeon_bootinfo->eclock_hz;
631 sysinfo->dram_data_rate_hz = octeon_bootinfo->dclock_hz * 2;
632 sysinfo->board_type = octeon_bootinfo->board_type;
633 sysinfo->board_rev_major = octeon_bootinfo->board_rev_major;
634 sysinfo->board_rev_minor = octeon_bootinfo->board_rev_minor;
635 memcpy(sysinfo->mac_addr_base, octeon_bootinfo->mac_addr_base,
636 sizeof(sysinfo->mac_addr_base));
637 sysinfo->mac_addr_count = octeon_bootinfo->mac_addr_count;
638 memcpy(sysinfo->board_serial_number,
639 octeon_bootinfo->board_serial_number,
640 sizeof(sysinfo->board_serial_number));
641 sysinfo->compact_flash_common_base_addr =
642 octeon_bootinfo->compact_flash_common_base_addr;
643 sysinfo->compact_flash_attribute_base_addr =
644 octeon_bootinfo->compact_flash_attribute_base_addr;
645 sysinfo->led_display_base_addr = octeon_bootinfo->led_display_base_addr;
646 sysinfo->dfa_ref_clock_hz = octeon_bootinfo->dfa_ref_clock_hz;
647 sysinfo->bootloader_config_flags = octeon_bootinfo->config_flags;
649 if (OCTEON_IS_MODEL(OCTEON_CN6XXX)) {
650 /* I/O clock runs at a different rate than the CPU. */
651 union cvmx_mio_rst_boot rst_boot;
652 rst_boot.u64 = cvmx_read_csr(CVMX_MIO_RST_BOOT);
653 octeon_io_clock_rate = 50000000 * rst_boot.s.pnr_mul;
655 octeon_io_clock_rate = sysinfo->cpu_clock_hz;
659 * Only enable the LED controller if we're running on a CN38XX, CN58XX,
660 * or CN56XX. The CN30XX and CN31XX don't have an LED controller.
662 if (!octeon_is_simulation() &&
663 octeon_has_feature(OCTEON_FEATURE_LED_CONTROLLER)) {
664 cvmx_write_csr(CVMX_LED_EN, 0);
665 cvmx_write_csr(CVMX_LED_PRT, 0);
666 cvmx_write_csr(CVMX_LED_DBG, 0);
667 cvmx_write_csr(CVMX_LED_PRT_FMT, 0);
668 cvmx_write_csr(CVMX_LED_UDD_CNTX(0), 32);
669 cvmx_write_csr(CVMX_LED_UDD_CNTX(1), 32);
670 cvmx_write_csr(CVMX_LED_UDD_DATX(0), 0);
671 cvmx_write_csr(CVMX_LED_UDD_DATX(1), 0);
672 cvmx_write_csr(CVMX_LED_EN, 1);
674 #ifdef CONFIG_CAVIUM_RESERVE32
676 * We need to temporarily allocate all memory in the reserve32
677 * region. This makes sure the kernel doesn't allocate this
678 * memory when it is getting memory from the
679 * bootloader. Later, after the memory allocations are
680 * complete, the reserve32 will be freed.
682 * Allocate memory for RESERVED32 aligned on 2MB boundary. This
683 * is in case we later use hugetlb entries with it.
685 addr = cvmx_bootmem_phy_named_block_alloc(CONFIG_CAVIUM_RESERVE32 << 20,
687 "CAVIUM_RESERVE32", 0);
689 pr_err("Failed to allocate CAVIUM_RESERVE32 memory area\n");
691 octeon_reserve32_memory = addr;
694 #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2
695 if (cvmx_read_csr(CVMX_L2D_FUS3) & (3ull << 34)) {
696 pr_info("Skipping L2 locking due to reduced L2 cache size\n");
698 uint32_t __maybe_unused ebase = read_c0_ebase() & 0x3ffff000;
699 #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_TLB
701 cvmx_l2c_lock_mem_region(ebase, 0x100);
703 #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_EXCEPTION
704 /* General exception */
705 cvmx_l2c_lock_mem_region(ebase + 0x180, 0x80);
707 #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_LOW_LEVEL_INTERRUPT
708 /* Interrupt handler */
709 cvmx_l2c_lock_mem_region(ebase + 0x200, 0x80);
711 #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_INTERRUPT
712 cvmx_l2c_lock_mem_region(__pa_symbol(handle_int), 0x100);
713 cvmx_l2c_lock_mem_region(__pa_symbol(plat_irq_dispatch), 0x80);
715 #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_MEMCPY
716 cvmx_l2c_lock_mem_region(__pa_symbol(memcpy), 0x480);
721 octeon_check_cpu_bist();
723 octeon_uart = octeon_get_boot_uart();
726 octeon_write_lcd("LinuxSMP");
728 octeon_write_lcd("Linux");
731 #ifdef CONFIG_CAVIUM_GDB
733 * When debugging the linux kernel, force the cores to enter
734 * the debug exception handler to break in.
736 if (octeon_get_boot_debug_flag()) {
737 cvmx_write_csr(CVMX_CIU_DINT, 1 << cvmx_get_core_num());
738 cvmx_read_csr(CVMX_CIU_DINT);
742 octeon_setup_delays();
745 * BIST should always be enabled when doing a soft reset. L2
746 * Cache locking for instance is not cleared unless BIST is
747 * enabled. Unfortunately due to a chip errata G-200 for
748 * Cn38XX and CN31XX, BIST msut be disabled on these parts.
750 if (OCTEON_IS_MODEL(OCTEON_CN38XX_PASS2) ||
751 OCTEON_IS_MODEL(OCTEON_CN31XX))
752 cvmx_write_csr(CVMX_CIU_SOFT_BIST, 0);
754 cvmx_write_csr(CVMX_CIU_SOFT_BIST, 1);
756 /* Default to 64MB in the simulator to speed things up */
757 if (octeon_is_simulation())
758 MAX_MEMORY = 64ull << 20;
760 arg = strstr(arcs_cmdline, "mem=");
762 MAX_MEMORY = memparse(arg + 4, &p);
764 MAX_MEMORY = 32ull << 30;
766 RESERVE_LOW_MEM = memparse(p + 1, &p);
770 argc = octeon_boot_desc_ptr->argc;
771 for (i = 0; i < argc; i++) {
773 cvmx_phys_to_ptr(octeon_boot_desc_ptr->argv[i]);
774 if ((strncmp(arg, "MEM=", 4) == 0) ||
775 (strncmp(arg, "mem=", 4) == 0)) {
776 MAX_MEMORY = memparse(arg + 4, &p);
778 MAX_MEMORY = 32ull << 30;
780 RESERVE_LOW_MEM = memparse(p + 1, &p);
781 } else if (strcmp(arg, "ecc_verbose") == 0) {
782 #ifdef CONFIG_CAVIUM_REPORT_SINGLE_BIT_ECC
783 __cvmx_interrupt_ecc_report_single_bit_errors = 1;
784 pr_notice("Reporting of single bit ECC errors is "
788 } else if (strncmp(arg, "crashkernel=", 12) == 0) {
789 crashk_size = memparse(arg+12, &p);
791 crashk_base = memparse(p+1, &p);
792 strcat(arcs_cmdline, " ");
793 strcat(arcs_cmdline, arg);
795 * To do: switch parsing to new style, something like:
796 * parse_crashkernel(arg, sysinfo->system_dram_size,
797 * &crashk_size, &crashk_base);
800 } else if (strlen(arcs_cmdline) + strlen(arg) + 1 <
801 sizeof(arcs_cmdline) - 1) {
802 strcat(arcs_cmdline, " ");
803 strcat(arcs_cmdline, arg);
807 if (strstr(arcs_cmdline, "console=") == NULL) {
808 #ifdef CONFIG_CAVIUM_OCTEON_2ND_KERNEL
809 strcat(arcs_cmdline, " console=ttyS0,115200");
811 if (octeon_uart == 1)
812 strcat(arcs_cmdline, " console=ttyS1,115200");
814 strcat(arcs_cmdline, " console=ttyS0,115200");
818 if (octeon_is_simulation()) {
820 * The simulator uses a mtdram device pre filled with
821 * the filesystem. Also specify the calibration delay
822 * to avoid calculating it every time.
824 strcat(arcs_cmdline, " rw root=1f00 slram=root,0x40000000,+1073741824");
827 mips_hpt_frequency = octeon_get_clock_rate();
829 octeon_init_cvmcount();
831 _machine_restart = octeon_restart;
832 _machine_halt = octeon_halt;
835 _machine_kexec_shutdown = octeon_shutdown;
836 _machine_crash_shutdown = octeon_crash_shutdown;
837 _machine_kexec_prepare = octeon_kexec_prepare;
840 octeon_user_io_init();
841 register_smp_ops(&octeon_smp_ops);
844 /* Exclude a single page from the regions obtained in plat_mem_setup. */
845 #ifndef CONFIG_CRASH_DUMP
846 static __init void memory_exclude_page(u64 addr, u64 *mem, u64 *size)
848 if (addr > *mem && addr < *mem + *size) {
849 u64 inc = addr - *mem;
850 add_memory_region(*mem, inc, BOOT_MEM_RAM);
855 if (addr == *mem && *size > PAGE_SIZE) {
860 #endif /* CONFIG_CRASH_DUMP */
862 void __init plat_mem_setup(void)
864 uint64_t mem_alloc_size;
867 #ifndef CONFIG_CRASH_DUMP
869 uint64_t kernel_start;
870 uint64_t kernel_size;
877 * The Mips memory init uses the first memory location for
878 * some memory vectors. When SPARSEMEM is in use, it doesn't
879 * verify that the size is big enough for the final
880 * vectors. Making the smallest chuck 4MB seems to be enough
881 * to consistently work.
883 mem_alloc_size = 4 << 20;
884 if (mem_alloc_size > MAX_MEMORY)
885 mem_alloc_size = MAX_MEMORY;
887 /* Crashkernel ignores bootmem list. It relies on mem=X@Y option */
888 #ifdef CONFIG_CRASH_DUMP
889 add_memory_region(RESERVE_LOW_MEM, MAX_MEMORY, BOOT_MEM_RAM);
893 if (crashk_size > 0) {
894 add_memory_region(crashk_base, crashk_size, BOOT_MEM_RAM);
895 crashk_end = crashk_base + crashk_size;
899 * When allocating memory, we want incrementing addresses from
900 * bootmem_alloc so the code in add_memory_region can merge
901 * regions next to each other.
904 while ((boot_mem_map.nr_map < BOOT_MEM_MAP_MAX)
905 && (total < MAX_MEMORY)) {
906 memory = cvmx_bootmem_phy_alloc(mem_alloc_size,
907 __pa_symbol(&__init_end), -1,
909 CVMX_BOOTMEM_FLAG_NO_LOCKING);
911 u64 size = mem_alloc_size;
917 * exclude a page at the beginning and end of
918 * the 256MB PCIe 'hole' so the kernel will not
919 * try to allocate multi-page buffers that
920 * span the discontinuity.
922 memory_exclude_page(CVMX_PCIE_BAR1_PHYS_BASE,
924 memory_exclude_page(CVMX_PCIE_BAR1_PHYS_BASE +
925 CVMX_PCIE_BAR1_PHYS_SIZE,
928 end = memory + mem_alloc_size;
931 * This function automatically merges address regions
932 * next to each other if they are received in
935 if (memory < crashk_base && end > crashk_end) {
936 /* region is fully in */
937 add_memory_region(memory,
938 crashk_base - memory,
940 total += crashk_base - memory;
941 add_memory_region(crashk_end,
944 total += end - crashk_end;
948 if (memory >= crashk_base && end <= crashk_end)
950 * Entire memory region is within the new
951 * kernel's memory, ignore it.
955 if (memory > crashk_base && memory < crashk_end &&
958 * Overlap with the beginning of the region,
959 * reserve the beginning.
961 mem_alloc_size -= crashk_end - memory;
963 } else if (memory < crashk_base && end > crashk_base &&
966 * Overlap with the beginning of the region,
969 mem_alloc_size -= end - crashk_base;
971 add_memory_region(memory, mem_alloc_size, BOOT_MEM_RAM);
972 total += mem_alloc_size;
973 /* Recovering mem_alloc_size */
974 mem_alloc_size = 4 << 20;
979 cvmx_bootmem_unlock();
980 /* Add the memory region for the kernel. */
981 kernel_start = (unsigned long) _text;
982 kernel_size = _end - _text;
984 /* Adjust for physical offset. */
985 kernel_start &= ~0xffffffff80000000ULL;
986 add_memory_region(kernel_start, kernel_size, BOOT_MEM_RAM);
987 #endif /* CONFIG_CRASH_DUMP */
989 #ifdef CONFIG_CAVIUM_RESERVE32
991 * Now that we've allocated the kernel memory it is safe to
992 * free the reserved region. We free it here so that builtin
993 * drivers can use the memory.
995 if (octeon_reserve32_memory)
996 cvmx_bootmem_free_named("CAVIUM_RESERVE32");
997 #endif /* CONFIG_CAVIUM_RESERVE32 */
1000 panic("Unable to allocate memory from "
1001 "cvmx_bootmem_phy_alloc\n");
1005 * Emit one character to the boot UART. Exported for use by the
1008 int prom_putchar(char c)
1012 /* Spin until there is room */
1014 lsrval = cvmx_read_csr(CVMX_MIO_UARTX_LSR(octeon_uart));
1015 } while ((lsrval & 0x20) == 0);
1017 /* Write the byte */
1018 cvmx_write_csr(CVMX_MIO_UARTX_THR(octeon_uart), c & 0xffull);
1021 EXPORT_SYMBOL(prom_putchar);
1023 void prom_free_prom_memory(void)
1025 if (OCTEON_IS_MODEL(OCTEON_CN63XX_PASS1_X)) {
1026 /* Check for presence of Core-14449 fix. */
1032 asm volatile("# before" : : : "memory");
1036 ".set noreorder\n\t"
1039 "1:\tlw %0,-12($31)\n\t"
1041 : "=r" (insn) : : "$31", "memory");
1043 if ((insn >> 26) != 0x33)
1044 panic("No PREF instruction at Core-14449 probe point.");
1046 if (((insn >> 16) & 0x1f) != 28)
1047 panic("Core-14449 WAR not in place (%04x).\n"
1048 "Please build kernel with proper options (CONFIG_CAVIUM_CN63XXP1).", insn);
1052 int octeon_prune_device_tree(void);
1054 extern const char __dtb_octeon_3xxx_begin;
1055 extern const char __dtb_octeon_3xxx_end;
1056 extern const char __dtb_octeon_68xx_begin;
1057 extern const char __dtb_octeon_68xx_end;
1058 void __init device_tree_init(void)
1061 struct boot_param_header *fdt;
1064 if (octeon_bootinfo->minor_version >= 3 && octeon_bootinfo->fdt_addr) {
1065 fdt = phys_to_virt(octeon_bootinfo->fdt_addr);
1066 if (fdt_check_header(fdt))
1067 panic("Corrupt Device Tree passed to kernel.");
1068 dt_size = be32_to_cpu(fdt->totalsize);
1070 } else if (OCTEON_IS_MODEL(OCTEON_CN68XX)) {
1071 fdt = (struct boot_param_header *)&__dtb_octeon_68xx_begin;
1072 dt_size = &__dtb_octeon_68xx_end - &__dtb_octeon_68xx_begin;
1075 fdt = (struct boot_param_header *)&__dtb_octeon_3xxx_begin;
1076 dt_size = &__dtb_octeon_3xxx_end - &__dtb_octeon_3xxx_begin;
1080 /* Copy the default tree from init memory. */
1081 initial_boot_params = early_init_dt_alloc_memory_arch(dt_size, 8);
1082 if (initial_boot_params == NULL)
1083 panic("Could not allocate initial_boot_params\n");
1084 memcpy(initial_boot_params, fdt, dt_size);
1087 octeon_prune_device_tree();
1088 pr_info("Using internal Device Tree.\n");
1090 pr_info("Using passed Device Tree.\n");
1092 unflatten_device_tree();
1095 static int __initdata disable_octeon_edac_p;
1097 static int __init disable_octeon_edac(char *str)
1099 disable_octeon_edac_p = 1;
1102 early_param("disable_octeon_edac", disable_octeon_edac);
1104 static char *edac_device_names[] = {
1109 static int __init edac_devinit(void)
1111 struct platform_device *dev;
1116 if (disable_octeon_edac_p)
1119 for (i = 0; i < ARRAY_SIZE(edac_device_names); i++) {
1120 name = edac_device_names[i];
1121 dev = platform_device_register_simple(name, -1, NULL, 0);
1123 pr_err("Registation of %s failed!\n", name);
1128 num_lmc = OCTEON_IS_MODEL(OCTEON_CN68XX) ? 4 :
1129 (OCTEON_IS_MODEL(OCTEON_CN56XX) ? 2 : 1);
1130 for (i = 0; i < num_lmc; i++) {
1131 dev = platform_device_register_simple("octeon_lmc_edac",
1134 pr_err("Registation of octeon_lmc_edac %d failed!\n", i);
1141 device_initcall(edac_devinit);