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/vmalloc.h>
12 #include <linux/init.h>
13 #include <linux/kernel.h>
14 #include <linux/console.h>
15 #include <linux/delay.h>
16 #include <linux/export.h>
17 #include <linux/interrupt.h>
19 #include <linux/serial.h>
20 #include <linux/smp.h>
21 #include <linux/types.h>
22 #include <linux/string.h> /* for memset */
23 #include <linux/tty.h>
24 #include <linux/time.h>
25 #include <linux/platform_device.h>
26 #include <linux/serial_core.h>
27 #include <linux/serial_8250.h>
28 #include <linux/of_fdt.h>
29 #include <linux/libfdt.h>
30 #include <linux/kexec.h>
32 #include <asm/processor.h>
33 #include <asm/reboot.h>
34 #include <asm/smp-ops.h>
35 #include <asm/irq_cpu.h>
36 #include <asm/mipsregs.h>
37 #include <asm/bootinfo.h>
38 #include <asm/sections.h>
41 #include <asm/octeon/octeon.h>
42 #include <asm/octeon/pci-octeon.h>
43 #include <asm/octeon/cvmx-mio-defs.h>
44 #include <asm/octeon/cvmx-rst-defs.h>
47 extern void pci_console_init(const char *arg);
50 static unsigned long long MAX_MEMORY = 512ull << 20;
52 DEFINE_SEMAPHORE(octeon_bootbus_sem);
53 EXPORT_SYMBOL(octeon_bootbus_sem);
55 struct octeon_boot_descriptor *octeon_boot_desc_ptr;
57 struct cvmx_bootinfo *octeon_bootinfo;
58 EXPORT_SYMBOL(octeon_bootinfo);
60 static unsigned long long RESERVE_LOW_MEM = 0ull;
64 * Wait for relocation code is prepared and send
65 * secondary CPUs to spin until kernel is relocated.
67 static void octeon_kexec_smp_down(void *ignored)
69 int cpu = smp_processor_id();
72 set_cpu_online(cpu, false);
73 while (!atomic_read(&kexec_ready_to_reboot))
80 relocated_kexec_smp_wait(NULL);
84 #define OCTEON_DDR0_BASE (0x0ULL)
85 #define OCTEON_DDR0_SIZE (0x010000000ULL)
86 #define OCTEON_DDR1_BASE (0x410000000ULL)
87 #define OCTEON_DDR1_SIZE (0x010000000ULL)
88 #define OCTEON_DDR2_BASE (0x020000000ULL)
89 #define OCTEON_DDR2_SIZE (0x3e0000000ULL)
90 #define OCTEON_MAX_PHY_MEM_SIZE (16*1024*1024*1024ULL)
92 static struct kimage *kimage_ptr;
94 static void kexec_bootmem_init(uint64_t mem_size, uint32_t low_reserved_bytes)
97 struct cvmx_bootmem_desc *bootmem_desc;
99 bootmem_desc = cvmx_bootmem_get_desc();
101 if (mem_size > OCTEON_MAX_PHY_MEM_SIZE) {
102 mem_size = OCTEON_MAX_PHY_MEM_SIZE;
103 pr_err("Error: requested memory too large,"
104 "truncating to maximum size\n");
107 bootmem_desc->major_version = CVMX_BOOTMEM_DESC_MAJ_VER;
108 bootmem_desc->minor_version = CVMX_BOOTMEM_DESC_MIN_VER;
110 addr = (OCTEON_DDR0_BASE + RESERVE_LOW_MEM + low_reserved_bytes);
111 bootmem_desc->head_addr = 0;
113 if (mem_size <= OCTEON_DDR0_SIZE) {
114 __cvmx_bootmem_phy_free(addr,
115 mem_size - RESERVE_LOW_MEM -
116 low_reserved_bytes, 0);
120 __cvmx_bootmem_phy_free(addr,
121 OCTEON_DDR0_SIZE - RESERVE_LOW_MEM -
122 low_reserved_bytes, 0);
124 mem_size -= OCTEON_DDR0_SIZE;
126 if (mem_size > OCTEON_DDR1_SIZE) {
127 __cvmx_bootmem_phy_free(OCTEON_DDR1_BASE, OCTEON_DDR1_SIZE, 0);
128 __cvmx_bootmem_phy_free(OCTEON_DDR2_BASE,
129 mem_size - OCTEON_DDR1_SIZE, 0);
131 __cvmx_bootmem_phy_free(OCTEON_DDR1_BASE, mem_size, 0);
134 static int octeon_kexec_prepare(struct kimage *image)
137 char *bootloader = "kexec";
139 octeon_boot_desc_ptr->argc = 0;
140 for (i = 0; i < image->nr_segments; i++) {
141 if (!strncmp(bootloader, (char *)image->segment[i].buf,
142 strlen(bootloader))) {
144 * convert command line string to array
145 * of parameters (as bootloader does).
148 char *str = (char *)image->segment[i].buf;
149 char *ptr = strchr(str, ' ');
150 while (ptr && (OCTEON_ARGV_MAX_ARGS > argc)) {
153 offt = (int)(ptr - str + 1);
154 octeon_boot_desc_ptr->argv[argc] =
155 image->segment[i].mem + offt;
158 ptr = strchr(ptr + 1, ' ');
160 octeon_boot_desc_ptr->argc = argc;
166 * Information about segments will be needed during pre-boot memory
173 static void octeon_generic_shutdown(void)
179 struct cvmx_bootmem_desc *bootmem_desc;
180 void *named_block_array_ptr;
182 bootmem_desc = cvmx_bootmem_get_desc();
183 named_block_array_ptr =
184 cvmx_phys_to_ptr(bootmem_desc->named_block_array_addr);
187 /* disable watchdogs */
188 for_each_online_cpu(cpu)
189 cvmx_write_csr(CVMX_CIU_WDOGX(cpu_logical_map(cpu)), 0);
191 cvmx_write_csr(CVMX_CIU_WDOGX(cvmx_get_core_num()), 0);
193 if (kimage_ptr != kexec_crash_image) {
194 memset(named_block_array_ptr,
196 CVMX_BOOTMEM_NUM_NAMED_BLOCKS *
197 sizeof(struct cvmx_bootmem_named_block_desc));
199 * Mark all memory (except low 0x100000 bytes) as free.
200 * It is the same thing that bootloader does.
202 kexec_bootmem_init(octeon_bootinfo->dram_size*1024ULL*1024ULL,
205 * Allocate all segments to avoid their corruption during boot.
207 for (i = 0; i < kimage_ptr->nr_segments; i++)
208 cvmx_bootmem_alloc_address(
209 kimage_ptr->segment[i].memsz + 2*PAGE_SIZE,
210 kimage_ptr->segment[i].mem - PAGE_SIZE,
214 * Do not mark all memory as free. Free only named sections
215 * leaving the rest of memory unchanged.
217 struct cvmx_bootmem_named_block_desc *ptr =
218 (struct cvmx_bootmem_named_block_desc *)
219 named_block_array_ptr;
221 for (i = 0; i < bootmem_desc->named_block_num_blocks; i++)
223 cvmx_bootmem_free_named(ptr[i].name);
225 kexec_args[2] = 1UL; /* running on octeon_main_processor */
226 kexec_args[3] = (unsigned long)octeon_boot_desc_ptr;
228 secondary_kexec_args[2] = 0UL; /* running on secondary cpu */
229 secondary_kexec_args[3] = (unsigned long)octeon_boot_desc_ptr;
233 static void octeon_shutdown(void)
235 octeon_generic_shutdown();
237 smp_call_function(octeon_kexec_smp_down, NULL, 0);
239 while (num_online_cpus() > 1) {
246 static void octeon_crash_shutdown(struct pt_regs *regs)
248 octeon_generic_shutdown();
249 default_machine_crash_shutdown(regs);
252 #endif /* CONFIG_KEXEC */
254 #ifdef CONFIG_CAVIUM_RESERVE32
255 uint64_t octeon_reserve32_memory;
256 EXPORT_SYMBOL(octeon_reserve32_memory);
260 /* crashkernel cmdline parameter is parsed _after_ memory setup
261 * we also parse it here (workaround for EHB5200) */
262 static uint64_t crashk_size, crashk_base;
265 static int octeon_uart;
267 extern asmlinkage void handle_int(void);
270 * Return non zero if we are currently running in the Octeon simulator
274 int octeon_is_simulation(void)
276 return octeon_bootinfo->board_type == CVMX_BOARD_TYPE_SIM;
278 EXPORT_SYMBOL(octeon_is_simulation);
281 * Return true if Octeon is in PCI Host mode. This means
282 * Linux can control the PCI bus.
284 * Returns Non zero if Octeon in host mode.
286 int octeon_is_pci_host(void)
289 return octeon_bootinfo->config_flags & CVMX_BOOTINFO_CFG_FLAG_PCI_HOST;
296 * Get the clock rate of Octeon
298 * Returns Clock rate in HZ
300 uint64_t octeon_get_clock_rate(void)
302 struct cvmx_sysinfo *sysinfo = cvmx_sysinfo_get();
304 return sysinfo->cpu_clock_hz;
306 EXPORT_SYMBOL(octeon_get_clock_rate);
308 static u64 octeon_io_clock_rate;
310 u64 octeon_get_io_clock_rate(void)
312 return octeon_io_clock_rate;
314 EXPORT_SYMBOL(octeon_get_io_clock_rate);
318 * Write to the LCD display connected to the bootbus. This display
319 * exists on most Cavium evaluation boards. If it doesn't exist, then
320 * this function doesn't do anything.
322 * @s: String to write
324 void octeon_write_lcd(const char *s)
326 if (octeon_bootinfo->led_display_base_addr) {
327 void __iomem *lcd_address =
328 ioremap_nocache(octeon_bootinfo->led_display_base_addr,
331 for (i = 0; i < 8; i++, s++) {
333 iowrite8(*s, lcd_address + i);
335 iowrite8(' ', lcd_address + i);
337 iounmap(lcd_address);
342 * Return the console uart passed by the bootloader
344 * Returns uart (0 or 1)
346 int octeon_get_boot_uart(void)
349 #ifdef CONFIG_CAVIUM_OCTEON_2ND_KERNEL
352 uart = (octeon_boot_desc_ptr->flags & OCTEON_BL_FLAG_CONSOLE_UART1) ?
359 * Get the coremask Linux was booted on.
363 int octeon_get_boot_coremask(void)
365 return octeon_boot_desc_ptr->core_mask;
369 * Check the hardware BIST results for a CPU
371 void octeon_check_cpu_bist(void)
373 const int coreid = cvmx_get_core_num();
374 unsigned long long mask;
375 unsigned long long bist_val;
377 /* Check BIST results for COP0 registers */
378 mask = 0x1f00000000ull;
379 bist_val = read_octeon_c0_icacheerr();
381 pr_err("Core%d BIST Failure: CacheErr(icache) = 0x%llx\n",
384 bist_val = read_octeon_c0_dcacheerr();
386 pr_err("Core%d L1 Dcache parity error: "
387 "CacheErr(dcache) = 0x%llx\n",
390 mask = 0xfc00000000000000ull;
391 bist_val = read_c0_cvmmemctl();
393 pr_err("Core%d BIST Failure: COP0_CVM_MEM_CTL = 0x%llx\n",
396 write_octeon_c0_dcacheerr(0);
402 * @command: Command to pass to the bootloader. Currently ignored.
404 static void octeon_restart(char *command)
406 /* Disable all watchdogs before soft reset. They don't get cleared */
409 for_each_online_cpu(cpu)
410 cvmx_write_csr(CVMX_CIU_WDOGX(cpu_logical_map(cpu)), 0);
412 cvmx_write_csr(CVMX_CIU_WDOGX(cvmx_get_core_num()), 0);
417 if (OCTEON_IS_OCTEON3())
418 cvmx_write_csr(CVMX_RST_SOFT_RST, 1);
420 cvmx_write_csr(CVMX_CIU_SOFT_RST, 1);
425 * Permanently stop a core.
429 static void octeon_kill_core(void *arg)
431 if (octeon_is_simulation())
432 /* A break instruction causes the simulator stop a core */
433 asm volatile ("break" ::: "memory");
436 /* Disable watchdog on this core. */
437 cvmx_write_csr(CVMX_CIU_WDOGX(cvmx_get_core_num()), 0);
438 /* Spin in a low power mode. */
440 asm volatile ("wait" ::: "memory");
447 static void octeon_halt(void)
449 smp_call_function(octeon_kill_core, NULL, 0);
451 switch (octeon_bootinfo->board_type) {
452 case CVMX_BOARD_TYPE_NAO38:
453 /* Driving a 1 to GPIO 12 shuts off this board */
454 cvmx_write_csr(CVMX_GPIO_BIT_CFGX(12), 1);
455 cvmx_write_csr(CVMX_GPIO_TX_SET, 0x1000);
458 octeon_write_lcd("PowerOff");
462 octeon_kill_core(NULL);
465 static char __read_mostly octeon_system_type[80];
467 static void __init init_octeon_system_type(void)
469 char const *board_type;
471 board_type = cvmx_board_type_to_string(octeon_bootinfo->board_type);
472 if (board_type == NULL) {
473 struct device_node *root;
476 root = of_find_node_by_path("/");
477 ret = of_property_read_string(root, "model", &board_type);
480 board_type = "Unsupported Board";
483 snprintf(octeon_system_type, sizeof(octeon_system_type), "%s (%s)",
484 board_type, octeon_model_get_string(read_c0_prid()));
488 * Return a string representing the system type
492 const char *octeon_board_type_string(void)
494 return octeon_system_type;
497 const char *get_system_type(void)
498 __attribute__ ((alias("octeon_board_type_string")));
500 void octeon_user_io_init(void)
502 union octeon_cvmemctl cvmmemctl;
504 /* Get the current settings for CP0_CVMMEMCTL_REG */
505 cvmmemctl.u64 = read_c0_cvmmemctl();
506 /* R/W If set, marked write-buffer entries time out the same
507 * as as other entries; if clear, marked write-buffer entries
508 * use the maximum timeout. */
509 cvmmemctl.s.dismarkwblongto = 1;
510 /* R/W If set, a merged store does not clear the write-buffer
511 * entry timeout state. */
512 cvmmemctl.s.dismrgclrwbto = 0;
513 /* R/W Two bits that are the MSBs of the resultant CVMSEG LM
514 * word location for an IOBDMA. The other 8 bits come from the
515 * SCRADDR field of the IOBDMA. */
516 cvmmemctl.s.iobdmascrmsb = 0;
517 /* R/W If set, SYNCWS and SYNCS only order marked stores; if
518 * clear, SYNCWS and SYNCS only order unmarked
519 * stores. SYNCWSMARKED has no effect when DISSYNCWS is
521 cvmmemctl.s.syncwsmarked = 0;
522 /* R/W If set, SYNCWS acts as SYNCW and SYNCS acts as SYNC. */
523 cvmmemctl.s.dissyncws = 0;
524 /* R/W If set, no stall happens on write buffer full. */
525 if (OCTEON_IS_MODEL(OCTEON_CN38XX_PASS2))
526 cvmmemctl.s.diswbfst = 1;
528 cvmmemctl.s.diswbfst = 0;
529 /* R/W If set (and SX set), supervisor-level loads/stores can
530 * use XKPHYS addresses with <48>==0 */
531 cvmmemctl.s.xkmemenas = 0;
533 /* R/W If set (and UX set), user-level loads/stores can use
534 * XKPHYS addresses with VA<48>==0 */
535 cvmmemctl.s.xkmemenau = 0;
537 /* R/W If set (and SX set), supervisor-level loads/stores can
538 * use XKPHYS addresses with VA<48>==1 */
539 cvmmemctl.s.xkioenas = 0;
541 /* R/W If set (and UX set), user-level loads/stores can use
542 * XKPHYS addresses with VA<48>==1 */
543 cvmmemctl.s.xkioenau = 0;
545 /* R/W If set, all stores act as SYNCW (NOMERGE must be set
546 * when this is set) RW, reset to 0. */
547 cvmmemctl.s.allsyncw = 0;
549 /* R/W If set, no stores merge, and all stores reach the
550 * coherent bus in order. */
551 cvmmemctl.s.nomerge = 0;
552 /* R/W Selects the bit in the counter used for DID time-outs 0
553 * = 231, 1 = 230, 2 = 229, 3 = 214. Actual time-out is
554 * between 1x and 2x this interval. For example, with
555 * DIDTTO=3, expiration interval is between 16K and 32K. */
556 cvmmemctl.s.didtto = 0;
557 /* R/W If set, the (mem) CSR clock never turns off. */
558 cvmmemctl.s.csrckalwys = 0;
559 /* R/W If set, mclk never turns off. */
560 cvmmemctl.s.mclkalwys = 0;
561 /* R/W Selects the bit in the counter used for write buffer
562 * flush time-outs (WBFLT+11) is the bit position in an
563 * internal counter used to determine expiration. The write
564 * buffer expires between 1x and 2x this interval. For
565 * example, with WBFLT = 0, a write buffer expires between 2K
566 * and 4K cycles after the write buffer entry is allocated. */
567 cvmmemctl.s.wbfltime = 0;
568 /* R/W If set, do not put Istream in the L2 cache. */
569 cvmmemctl.s.istrnol2 = 0;
572 * R/W The write buffer threshold. As per erratum Core-14752
573 * for CN63XX, a sc/scd might fail if the write buffer is
574 * full. Lowering WBTHRESH greatly lowers the chances of the
575 * write buffer ever being full and triggering the erratum.
577 if (OCTEON_IS_MODEL(OCTEON_CN63XX_PASS1_X))
578 cvmmemctl.s.wbthresh = 4;
580 cvmmemctl.s.wbthresh = 10;
582 /* R/W If set, CVMSEG is available for loads/stores in
583 * kernel/debug mode. */
584 #if CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE > 0
585 cvmmemctl.s.cvmsegenak = 1;
587 cvmmemctl.s.cvmsegenak = 0;
589 /* R/W If set, CVMSEG is available for loads/stores in
590 * supervisor mode. */
591 cvmmemctl.s.cvmsegenas = 0;
592 /* R/W If set, CVMSEG is available for loads/stores in user
594 cvmmemctl.s.cvmsegenau = 0;
596 write_c0_cvmmemctl(cvmmemctl.u64);
598 /* Setup of CVMSEG is done in kernel-entry-init.h */
599 if (smp_processor_id() == 0)
600 pr_notice("CVMSEG size: %d cache lines (%d bytes)\n",
601 CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE,
602 CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE * 128);
604 if (octeon_has_feature(OCTEON_FEATURE_FAU)) {
605 union cvmx_iob_fau_timeout fau_timeout;
607 /* Set a default for the hardware timeouts */
609 fau_timeout.s.tout_val = 0xfff;
610 /* Disable tagwait FAU timeout */
611 fau_timeout.s.tout_enb = 0;
612 cvmx_write_csr(CVMX_IOB_FAU_TIMEOUT, fau_timeout.u64);
615 if ((!OCTEON_IS_MODEL(OCTEON_CN68XX) &&
616 !OCTEON_IS_MODEL(OCTEON_CN7XXX)) ||
617 OCTEON_IS_MODEL(OCTEON_CN70XX)) {
618 union cvmx_pow_nw_tim nm_tim;
623 cvmx_write_csr(CVMX_POW_NW_TIM, nm_tim.u64);
626 write_octeon_c0_icacheerr(0);
627 write_c0_derraddr1(0);
631 * Early entry point for arch setup
633 void __init prom_init(void)
635 struct cvmx_sysinfo *sysinfo;
641 #ifdef CONFIG_CAVIUM_RESERVE32
645 * The bootloader passes a pointer to the boot descriptor in
646 * $a3, this is available as fw_arg3.
648 octeon_boot_desc_ptr = (struct octeon_boot_descriptor *)fw_arg3;
650 cvmx_phys_to_ptr(octeon_boot_desc_ptr->cvmx_desc_vaddr);
651 cvmx_bootmem_init(cvmx_phys_to_ptr(octeon_bootinfo->phy_mem_desc_addr));
653 sysinfo = cvmx_sysinfo_get();
654 memset(sysinfo, 0, sizeof(*sysinfo));
655 sysinfo->system_dram_size = octeon_bootinfo->dram_size << 20;
656 sysinfo->phy_mem_desc_addr = (u64)phys_to_virt(octeon_bootinfo->phy_mem_desc_addr);
658 if ((octeon_bootinfo->major_version > 1) ||
659 (octeon_bootinfo->major_version == 1 &&
660 octeon_bootinfo->minor_version >= 4))
661 cvmx_coremask_copy(&sysinfo->core_mask,
662 &octeon_bootinfo->ext_core_mask);
664 cvmx_coremask_set64(&sysinfo->core_mask,
665 octeon_bootinfo->core_mask);
667 /* Some broken u-boot pass garbage in upper bits, clear them out */
668 if (!OCTEON_IS_MODEL(OCTEON_CN78XX))
669 for (i = 512; i < 1024; i++)
670 cvmx_coremask_clear_core(&sysinfo->core_mask, i);
672 sysinfo->exception_base_addr = octeon_bootinfo->exception_base_addr;
673 sysinfo->cpu_clock_hz = octeon_bootinfo->eclock_hz;
674 sysinfo->dram_data_rate_hz = octeon_bootinfo->dclock_hz * 2;
675 sysinfo->board_type = octeon_bootinfo->board_type;
676 sysinfo->board_rev_major = octeon_bootinfo->board_rev_major;
677 sysinfo->board_rev_minor = octeon_bootinfo->board_rev_minor;
678 memcpy(sysinfo->mac_addr_base, octeon_bootinfo->mac_addr_base,
679 sizeof(sysinfo->mac_addr_base));
680 sysinfo->mac_addr_count = octeon_bootinfo->mac_addr_count;
681 memcpy(sysinfo->board_serial_number,
682 octeon_bootinfo->board_serial_number,
683 sizeof(sysinfo->board_serial_number));
684 sysinfo->compact_flash_common_base_addr =
685 octeon_bootinfo->compact_flash_common_base_addr;
686 sysinfo->compact_flash_attribute_base_addr =
687 octeon_bootinfo->compact_flash_attribute_base_addr;
688 sysinfo->led_display_base_addr = octeon_bootinfo->led_display_base_addr;
689 sysinfo->dfa_ref_clock_hz = octeon_bootinfo->dfa_ref_clock_hz;
690 sysinfo->bootloader_config_flags = octeon_bootinfo->config_flags;
692 if (OCTEON_IS_OCTEON2()) {
693 /* I/O clock runs at a different rate than the CPU. */
694 union cvmx_mio_rst_boot rst_boot;
695 rst_boot.u64 = cvmx_read_csr(CVMX_MIO_RST_BOOT);
696 octeon_io_clock_rate = 50000000 * rst_boot.s.pnr_mul;
697 } else if (OCTEON_IS_OCTEON3()) {
698 /* I/O clock runs at a different rate than the CPU. */
699 union cvmx_rst_boot rst_boot;
700 rst_boot.u64 = cvmx_read_csr(CVMX_RST_BOOT);
701 octeon_io_clock_rate = 50000000 * rst_boot.s.pnr_mul;
703 octeon_io_clock_rate = sysinfo->cpu_clock_hz;
706 t = read_c0_cvmctl();
707 if ((t & (1ull << 27)) == 0) {
709 * Setup the multiplier save/restore code if
710 * CvmCtl[NOMUL] clear.
718 int save_max = (char *)octeon_mult_save_end -
719 (char *)octeon_mult_save;
720 int restore_max = (char *)octeon_mult_restore_end -
721 (char *)octeon_mult_restore;
722 if (current_cpu_data.cputype == CPU_CAVIUM_OCTEON3) {
723 save = octeon_mult_save3;
724 save_end = octeon_mult_save3_end;
725 restore = octeon_mult_restore3;
726 restore_end = octeon_mult_restore3_end;
728 save = octeon_mult_save2;
729 save_end = octeon_mult_save2_end;
730 restore = octeon_mult_restore2;
731 restore_end = octeon_mult_restore2_end;
733 save_len = (char *)save_end - (char *)save;
734 restore_len = (char *)restore_end - (char *)restore;
735 if (!WARN_ON(save_len > save_max ||
736 restore_len > restore_max)) {
737 memcpy(octeon_mult_save, save, save_len);
738 memcpy(octeon_mult_restore, restore, restore_len);
743 * Only enable the LED controller if we're running on a CN38XX, CN58XX,
744 * or CN56XX. The CN30XX and CN31XX don't have an LED controller.
746 if (!octeon_is_simulation() &&
747 octeon_has_feature(OCTEON_FEATURE_LED_CONTROLLER)) {
748 cvmx_write_csr(CVMX_LED_EN, 0);
749 cvmx_write_csr(CVMX_LED_PRT, 0);
750 cvmx_write_csr(CVMX_LED_DBG, 0);
751 cvmx_write_csr(CVMX_LED_PRT_FMT, 0);
752 cvmx_write_csr(CVMX_LED_UDD_CNTX(0), 32);
753 cvmx_write_csr(CVMX_LED_UDD_CNTX(1), 32);
754 cvmx_write_csr(CVMX_LED_UDD_DATX(0), 0);
755 cvmx_write_csr(CVMX_LED_UDD_DATX(1), 0);
756 cvmx_write_csr(CVMX_LED_EN, 1);
758 #ifdef CONFIG_CAVIUM_RESERVE32
760 * We need to temporarily allocate all memory in the reserve32
761 * region. This makes sure the kernel doesn't allocate this
762 * memory when it is getting memory from the
763 * bootloader. Later, after the memory allocations are
764 * complete, the reserve32 will be freed.
766 * Allocate memory for RESERVED32 aligned on 2MB boundary. This
767 * is in case we later use hugetlb entries with it.
769 addr = cvmx_bootmem_phy_named_block_alloc(CONFIG_CAVIUM_RESERVE32 << 20,
771 "CAVIUM_RESERVE32", 0);
773 pr_err("Failed to allocate CAVIUM_RESERVE32 memory area\n");
775 octeon_reserve32_memory = addr;
778 #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2
779 if (cvmx_read_csr(CVMX_L2D_FUS3) & (3ull << 34)) {
780 pr_info("Skipping L2 locking due to reduced L2 cache size\n");
782 uint32_t __maybe_unused ebase = read_c0_ebase() & 0x3ffff000;
783 #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_TLB
785 cvmx_l2c_lock_mem_region(ebase, 0x100);
787 #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_EXCEPTION
788 /* General exception */
789 cvmx_l2c_lock_mem_region(ebase + 0x180, 0x80);
791 #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_LOW_LEVEL_INTERRUPT
792 /* Interrupt handler */
793 cvmx_l2c_lock_mem_region(ebase + 0x200, 0x80);
795 #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_INTERRUPT
796 cvmx_l2c_lock_mem_region(__pa_symbol(handle_int), 0x100);
797 cvmx_l2c_lock_mem_region(__pa_symbol(plat_irq_dispatch), 0x80);
799 #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_MEMCPY
800 cvmx_l2c_lock_mem_region(__pa_symbol(memcpy), 0x480);
805 octeon_check_cpu_bist();
807 octeon_uart = octeon_get_boot_uart();
810 octeon_write_lcd("LinuxSMP");
812 octeon_write_lcd("Linux");
815 octeon_setup_delays();
818 * BIST should always be enabled when doing a soft reset. L2
819 * Cache locking for instance is not cleared unless BIST is
820 * enabled. Unfortunately due to a chip errata G-200 for
821 * Cn38XX and CN31XX, BIST msut be disabled on these parts.
823 if (OCTEON_IS_MODEL(OCTEON_CN38XX_PASS2) ||
824 OCTEON_IS_MODEL(OCTEON_CN31XX))
825 cvmx_write_csr(CVMX_CIU_SOFT_BIST, 0);
827 cvmx_write_csr(CVMX_CIU_SOFT_BIST, 1);
829 /* Default to 64MB in the simulator to speed things up */
830 if (octeon_is_simulation())
831 MAX_MEMORY = 64ull << 20;
833 arg = strstr(arcs_cmdline, "mem=");
835 MAX_MEMORY = memparse(arg + 4, &p);
837 MAX_MEMORY = 32ull << 30;
839 RESERVE_LOW_MEM = memparse(p + 1, &p);
843 argc = octeon_boot_desc_ptr->argc;
844 for (i = 0; i < argc; i++) {
846 cvmx_phys_to_ptr(octeon_boot_desc_ptr->argv[i]);
847 if ((strncmp(arg, "MEM=", 4) == 0) ||
848 (strncmp(arg, "mem=", 4) == 0)) {
849 MAX_MEMORY = memparse(arg + 4, &p);
851 MAX_MEMORY = 32ull << 30;
853 RESERVE_LOW_MEM = memparse(p + 1, &p);
855 } else if (strncmp(arg, "crashkernel=", 12) == 0) {
856 crashk_size = memparse(arg+12, &p);
858 crashk_base = memparse(p+1, &p);
859 strcat(arcs_cmdline, " ");
860 strcat(arcs_cmdline, arg);
862 * To do: switch parsing to new style, something like:
863 * parse_crashkernel(arg, sysinfo->system_dram_size,
864 * &crashk_size, &crashk_base);
867 } else if (strlen(arcs_cmdline) + strlen(arg) + 1 <
868 sizeof(arcs_cmdline) - 1) {
869 strcat(arcs_cmdline, " ");
870 strcat(arcs_cmdline, arg);
874 if (strstr(arcs_cmdline, "console=") == NULL) {
875 #ifdef CONFIG_CAVIUM_OCTEON_2ND_KERNEL
876 strcat(arcs_cmdline, " console=ttyS0,115200");
878 if (octeon_uart == 1)
879 strcat(arcs_cmdline, " console=ttyS1,115200");
881 strcat(arcs_cmdline, " console=ttyS0,115200");
885 mips_hpt_frequency = octeon_get_clock_rate();
887 octeon_init_cvmcount();
889 _machine_restart = octeon_restart;
890 _machine_halt = octeon_halt;
893 _machine_kexec_shutdown = octeon_shutdown;
894 _machine_crash_shutdown = octeon_crash_shutdown;
895 _machine_kexec_prepare = octeon_kexec_prepare;
898 octeon_user_io_init();
902 /* Exclude a single page from the regions obtained in plat_mem_setup. */
903 #ifndef CONFIG_CRASH_DUMP
904 static __init void memory_exclude_page(u64 addr, u64 *mem, u64 *size)
906 if (addr > *mem && addr < *mem + *size) {
907 u64 inc = addr - *mem;
908 add_memory_region(*mem, inc, BOOT_MEM_RAM);
913 if (addr == *mem && *size > PAGE_SIZE) {
918 #endif /* CONFIG_CRASH_DUMP */
920 void __init plat_mem_setup(void)
922 uint64_t mem_alloc_size;
925 #ifndef CONFIG_CRASH_DUMP
927 uint64_t kernel_start;
928 uint64_t kernel_size;
935 * The Mips memory init uses the first memory location for
936 * some memory vectors. When SPARSEMEM is in use, it doesn't
937 * verify that the size is big enough for the final
938 * vectors. Making the smallest chuck 4MB seems to be enough
939 * to consistently work.
941 mem_alloc_size = 4 << 20;
942 if (mem_alloc_size > MAX_MEMORY)
943 mem_alloc_size = MAX_MEMORY;
945 /* Crashkernel ignores bootmem list. It relies on mem=X@Y option */
946 #ifdef CONFIG_CRASH_DUMP
947 add_memory_region(RESERVE_LOW_MEM, MAX_MEMORY, BOOT_MEM_RAM);
951 if (crashk_size > 0) {
952 add_memory_region(crashk_base, crashk_size, BOOT_MEM_RAM);
953 crashk_end = crashk_base + crashk_size;
957 * When allocating memory, we want incrementing addresses from
958 * bootmem_alloc so the code in add_memory_region can merge
959 * regions next to each other.
962 while ((boot_mem_map.nr_map < BOOT_MEM_MAP_MAX)
963 && (total < MAX_MEMORY)) {
964 memory = cvmx_bootmem_phy_alloc(mem_alloc_size,
965 __pa_symbol(&_end), -1,
967 CVMX_BOOTMEM_FLAG_NO_LOCKING);
969 u64 size = mem_alloc_size;
975 * exclude a page at the beginning and end of
976 * the 256MB PCIe 'hole' so the kernel will not
977 * try to allocate multi-page buffers that
978 * span the discontinuity.
980 memory_exclude_page(CVMX_PCIE_BAR1_PHYS_BASE,
982 memory_exclude_page(CVMX_PCIE_BAR1_PHYS_BASE +
983 CVMX_PCIE_BAR1_PHYS_SIZE,
986 end = memory + mem_alloc_size;
989 * This function automatically merges address regions
990 * next to each other if they are received in
993 if (memory < crashk_base && end > crashk_end) {
994 /* region is fully in */
995 add_memory_region(memory,
996 crashk_base - memory,
998 total += crashk_base - memory;
999 add_memory_region(crashk_end,
1002 total += end - crashk_end;
1006 if (memory >= crashk_base && end <= crashk_end)
1008 * Entire memory region is within the new
1009 * kernel's memory, ignore it.
1013 if (memory > crashk_base && memory < crashk_end &&
1016 * Overlap with the beginning of the region,
1017 * reserve the beginning.
1019 mem_alloc_size -= crashk_end - memory;
1020 memory = crashk_end;
1021 } else if (memory < crashk_base && end > crashk_base &&
1024 * Overlap with the beginning of the region,
1027 mem_alloc_size -= end - crashk_base;
1029 add_memory_region(memory, mem_alloc_size, BOOT_MEM_RAM);
1030 total += mem_alloc_size;
1031 /* Recovering mem_alloc_size */
1032 mem_alloc_size = 4 << 20;
1037 cvmx_bootmem_unlock();
1038 /* Add the memory region for the kernel. */
1039 kernel_start = (unsigned long) _text;
1040 kernel_size = _end - _text;
1042 /* Adjust for physical offset. */
1043 kernel_start &= ~0xffffffff80000000ULL;
1044 add_memory_region(kernel_start, kernel_size, BOOT_MEM_RAM);
1045 #endif /* CONFIG_CRASH_DUMP */
1047 #ifdef CONFIG_CAVIUM_RESERVE32
1049 * Now that we've allocated the kernel memory it is safe to
1050 * free the reserved region. We free it here so that builtin
1051 * drivers can use the memory.
1053 if (octeon_reserve32_memory)
1054 cvmx_bootmem_free_named("CAVIUM_RESERVE32");
1055 #endif /* CONFIG_CAVIUM_RESERVE32 */
1058 panic("Unable to allocate memory from "
1059 "cvmx_bootmem_phy_alloc");
1063 * Emit one character to the boot UART. Exported for use by the
1066 int prom_putchar(char c)
1070 /* Spin until there is room */
1072 lsrval = cvmx_read_csr(CVMX_MIO_UARTX_LSR(octeon_uart));
1073 } while ((lsrval & 0x20) == 0);
1075 /* Write the byte */
1076 cvmx_write_csr(CVMX_MIO_UARTX_THR(octeon_uart), c & 0xffull);
1079 EXPORT_SYMBOL(prom_putchar);
1081 void __init prom_free_prom_memory(void)
1083 if (CAVIUM_OCTEON_DCACHE_PREFETCH_WAR) {
1084 /* Check for presence of Core-14449 fix. */
1090 asm volatile("# before" : : : "memory");
1094 ".set noreorder\n\t"
1097 "1:\tlw %0,-12($31)\n\t"
1099 : "=r" (insn) : : "$31", "memory");
1101 if ((insn >> 26) != 0x33)
1102 panic("No PREF instruction at Core-14449 probe point.");
1104 if (((insn >> 16) & 0x1f) != 28)
1105 panic("OCTEON II DCache prefetch workaround not in place (%04x).\n"
1106 "Please build kernel with proper options (CONFIG_CAVIUM_CN63XXP1).",
1111 void __init octeon_fill_mac_addresses(void);
1112 int octeon_prune_device_tree(void);
1114 extern const char __appended_dtb;
1115 extern const char __dtb_octeon_3xxx_begin;
1116 extern const char __dtb_octeon_68xx_begin;
1117 void __init device_tree_init(void)
1123 #ifdef CONFIG_MIPS_ELF_APPENDED_DTB
1124 if (!fdt_check_header(&__appended_dtb)) {
1125 fdt = &__appended_dtb;
1128 pr_info("Using appended Device Tree.\n");
1131 if (octeon_bootinfo->minor_version >= 3 && octeon_bootinfo->fdt_addr) {
1132 fdt = phys_to_virt(octeon_bootinfo->fdt_addr);
1133 if (fdt_check_header(fdt))
1134 panic("Corrupt Device Tree passed to kernel.");
1137 pr_info("Using passed Device Tree.\n");
1138 } else if (OCTEON_IS_MODEL(OCTEON_CN68XX)) {
1139 fdt = &__dtb_octeon_68xx_begin;
1143 fdt = &__dtb_octeon_3xxx_begin;
1148 initial_boot_params = (void *)fdt;
1151 octeon_prune_device_tree();
1152 pr_info("Using internal Device Tree.\n");
1155 octeon_fill_mac_addresses();
1156 unflatten_and_copy_device_tree();
1157 init_octeon_system_type();
1160 static int __initdata disable_octeon_edac_p;
1162 static int __init disable_octeon_edac(char *str)
1164 disable_octeon_edac_p = 1;
1167 early_param("disable_octeon_edac", disable_octeon_edac);
1169 static char *edac_device_names[] = {
1174 static int __init edac_devinit(void)
1176 struct platform_device *dev;
1181 if (disable_octeon_edac_p)
1184 for (i = 0; i < ARRAY_SIZE(edac_device_names); i++) {
1185 name = edac_device_names[i];
1186 dev = platform_device_register_simple(name, -1, NULL, 0);
1188 pr_err("Registration of %s failed!\n", name);
1193 num_lmc = OCTEON_IS_MODEL(OCTEON_CN68XX) ? 4 :
1194 (OCTEON_IS_MODEL(OCTEON_CN56XX) ? 2 : 1);
1195 for (i = 0; i < num_lmc; i++) {
1196 dev = platform_device_register_simple("octeon_lmc_edac",
1199 pr_err("Registration of octeon_lmc_edac %d failed!\n", i);
1206 device_initcall(edac_devinit);
1208 static void __initdata *octeon_dummy_iospace;
1210 static int __init octeon_no_pci_init(void)
1213 * Initially assume there is no PCI. The PCI/PCIe platform code will
1214 * later re-initialize these to correct values if they are present.
1216 octeon_dummy_iospace = vzalloc(IO_SPACE_LIMIT);
1217 set_io_port_base((unsigned long)octeon_dummy_iospace);
1218 ioport_resource.start = MAX_RESOURCE;
1219 ioport_resource.end = 0;
1222 core_initcall(octeon_no_pci_init);
1224 static int __init octeon_no_pci_release(void)
1227 * Release the allocated memory if a real IO space is there.
1229 if ((unsigned long)octeon_dummy_iospace != mips_io_port_base)
1230 vfree(octeon_dummy_iospace);
1233 late_initcall(octeon_no_pci_release);