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/memblock.h>
20 #include <linux/serial.h>
21 #include <linux/smp.h>
22 #include <linux/types.h>
23 #include <linux/string.h> /* for memset */
24 #include <linux/tty.h>
25 #include <linux/time.h>
26 #include <linux/platform_device.h>
27 #include <linux/serial_core.h>
28 #include <linux/serial_8250.h>
29 #include <linux/of_fdt.h>
30 #include <linux/libfdt.h>
31 #include <linux/kexec.h>
33 #include <asm/processor.h>
34 #include <asm/reboot.h>
35 #include <asm/smp-ops.h>
36 #include <asm/irq_cpu.h>
37 #include <asm/mipsregs.h>
38 #include <asm/bootinfo.h>
39 #include <asm/sections.h>
40 #include <asm/fw/fw.h>
41 #include <asm/setup.h>
45 #include <asm/octeon/octeon.h>
46 #include <asm/octeon/pci-octeon.h>
47 #include <asm/octeon/cvmx-rst-defs.h>
50 * TRUE for devices having registers with little-endian byte
51 * order, FALSE for registers with native-endian byte order.
52 * PCI mandates little-endian, USB and SATA are configuraable,
53 * but we chose little-endian for these.
55 const bool octeon_should_swizzle_table
[256] = {
56 [0x00] = true, /* bootbus/CF */
57 [0x1b] = true, /* PCI mmio window */
58 [0x1c] = true, /* PCI mmio window */
59 [0x1d] = true, /* PCI mmio window */
60 [0x1e] = true, /* PCI mmio window */
61 [0x68] = true, /* OCTEON III USB */
62 [0x69] = true, /* OCTEON III USB */
63 [0x6c] = true, /* OCTEON III SATA */
64 [0x6f] = true, /* OCTEON II USB */
66 EXPORT_SYMBOL(octeon_should_swizzle_table
);
69 extern void pci_console_init(const char *arg
);
72 static unsigned long long max_memory
= ULLONG_MAX
;
73 static unsigned long long reserve_low_mem
;
75 DEFINE_SEMAPHORE(octeon_bootbus_sem
);
76 EXPORT_SYMBOL(octeon_bootbus_sem
);
78 static struct octeon_boot_descriptor
*octeon_boot_desc_ptr
;
80 struct cvmx_bootinfo
*octeon_bootinfo
;
81 EXPORT_SYMBOL(octeon_bootinfo
);
86 * Wait for relocation code is prepared and send
87 * secondary CPUs to spin until kernel is relocated.
89 static void octeon_kexec_smp_down(void *ignored
)
91 int cpu
= smp_processor_id();
94 set_cpu_online(cpu
, false);
95 while (!atomic_read(&kexec_ready_to_reboot
))
106 #define OCTEON_DDR0_BASE (0x0ULL)
107 #define OCTEON_DDR0_SIZE (0x010000000ULL)
108 #define OCTEON_DDR1_BASE (0x410000000ULL)
109 #define OCTEON_DDR1_SIZE (0x010000000ULL)
110 #define OCTEON_DDR2_BASE (0x020000000ULL)
111 #define OCTEON_DDR2_SIZE (0x3e0000000ULL)
112 #define OCTEON_MAX_PHY_MEM_SIZE (16*1024*1024*1024ULL)
114 static struct kimage
*kimage_ptr
;
116 static void kexec_bootmem_init(uint64_t mem_size
, uint32_t low_reserved_bytes
)
119 struct cvmx_bootmem_desc
*bootmem_desc
;
121 bootmem_desc
= cvmx_bootmem_get_desc();
123 if (mem_size
> OCTEON_MAX_PHY_MEM_SIZE
) {
124 mem_size
= OCTEON_MAX_PHY_MEM_SIZE
;
125 pr_err("Error: requested memory too large,"
126 "truncating to maximum size\n");
129 bootmem_desc
->major_version
= CVMX_BOOTMEM_DESC_MAJ_VER
;
130 bootmem_desc
->minor_version
= CVMX_BOOTMEM_DESC_MIN_VER
;
132 addr
= (OCTEON_DDR0_BASE
+ reserve_low_mem
+ low_reserved_bytes
);
133 bootmem_desc
->head_addr
= 0;
135 if (mem_size
<= OCTEON_DDR0_SIZE
) {
136 __cvmx_bootmem_phy_free(addr
,
137 mem_size
- reserve_low_mem
-
138 low_reserved_bytes
, 0);
142 __cvmx_bootmem_phy_free(addr
,
143 OCTEON_DDR0_SIZE
- reserve_low_mem
-
144 low_reserved_bytes
, 0);
146 mem_size
-= OCTEON_DDR0_SIZE
;
148 if (mem_size
> OCTEON_DDR1_SIZE
) {
149 __cvmx_bootmem_phy_free(OCTEON_DDR1_BASE
, OCTEON_DDR1_SIZE
, 0);
150 __cvmx_bootmem_phy_free(OCTEON_DDR2_BASE
,
151 mem_size
- OCTEON_DDR1_SIZE
, 0);
153 __cvmx_bootmem_phy_free(OCTEON_DDR1_BASE
, mem_size
, 0);
156 static int octeon_kexec_prepare(struct kimage
*image
)
159 char *bootloader
= "kexec";
161 octeon_boot_desc_ptr
->argc
= 0;
162 for (i
= 0; i
< image
->nr_segments
; i
++) {
163 if (!strncmp(bootloader
, (char *)image
->segment
[i
].buf
,
164 strlen(bootloader
))) {
166 * convert command line string to array
167 * of parameters (as bootloader does).
170 char *str
= (char *)image
->segment
[i
].buf
;
171 char *ptr
= strchr(str
, ' ');
172 while (ptr
&& (OCTEON_ARGV_MAX_ARGS
> argc
)) {
175 offt
= (int)(ptr
- str
+ 1);
176 octeon_boot_desc_ptr
->argv
[argc
] =
177 image
->segment
[i
].mem
+ offt
;
180 ptr
= strchr(ptr
+ 1, ' ');
182 octeon_boot_desc_ptr
->argc
= argc
;
188 * Information about segments will be needed during pre-boot memory
195 static void octeon_generic_shutdown(void)
201 struct cvmx_bootmem_desc
*bootmem_desc
;
202 void *named_block_array_ptr
;
204 bootmem_desc
= cvmx_bootmem_get_desc();
205 named_block_array_ptr
=
206 cvmx_phys_to_ptr(bootmem_desc
->named_block_array_addr
);
209 /* disable watchdogs */
210 for_each_online_cpu(cpu
)
211 cvmx_write_csr(CVMX_CIU_WDOGX(cpu_logical_map(cpu
)), 0);
213 cvmx_write_csr(CVMX_CIU_WDOGX(cvmx_get_core_num()), 0);
215 if (kimage_ptr
!= kexec_crash_image
) {
216 memset(named_block_array_ptr
,
218 CVMX_BOOTMEM_NUM_NAMED_BLOCKS
*
219 sizeof(struct cvmx_bootmem_named_block_desc
));
221 * Mark all memory (except low 0x100000 bytes) as free.
222 * It is the same thing that bootloader does.
224 kexec_bootmem_init(octeon_bootinfo
->dram_size
*1024ULL*1024ULL,
227 * Allocate all segments to avoid their corruption during boot.
229 for (i
= 0; i
< kimage_ptr
->nr_segments
; i
++)
230 cvmx_bootmem_alloc_address(
231 kimage_ptr
->segment
[i
].memsz
+ 2*PAGE_SIZE
,
232 kimage_ptr
->segment
[i
].mem
- PAGE_SIZE
,
236 * Do not mark all memory as free. Free only named sections
237 * leaving the rest of memory unchanged.
239 struct cvmx_bootmem_named_block_desc
*ptr
=
240 (struct cvmx_bootmem_named_block_desc
*)
241 named_block_array_ptr
;
243 for (i
= 0; i
< bootmem_desc
->named_block_num_blocks
; i
++)
245 cvmx_bootmem_free_named(ptr
[i
].name
);
247 kexec_args
[2] = 1UL; /* running on octeon_main_processor */
248 kexec_args
[3] = (unsigned long)octeon_boot_desc_ptr
;
250 secondary_kexec_args
[2] = 0UL; /* running on secondary cpu */
251 secondary_kexec_args
[3] = (unsigned long)octeon_boot_desc_ptr
;
255 static void octeon_shutdown(void)
257 octeon_generic_shutdown();
259 smp_call_function(octeon_kexec_smp_down
, NULL
, 0);
261 while (num_online_cpus() > 1) {
268 static void octeon_crash_shutdown(struct pt_regs
*regs
)
270 octeon_generic_shutdown();
271 default_machine_crash_shutdown(regs
);
275 void octeon_crash_smp_send_stop(void)
279 /* disable watchdogs */
280 for_each_online_cpu(cpu
)
281 cvmx_write_csr(CVMX_CIU_WDOGX(cpu_logical_map(cpu
)), 0);
285 #endif /* CONFIG_KEXEC */
287 #ifdef CONFIG_CAVIUM_RESERVE32
288 uint64_t octeon_reserve32_memory
;
289 EXPORT_SYMBOL(octeon_reserve32_memory
);
293 /* crashkernel cmdline parameter is parsed _after_ memory setup
294 * we also parse it here (workaround for EHB5200) */
295 static uint64_t crashk_size
, crashk_base
;
298 static int octeon_uart
;
300 extern asmlinkage
void handle_int(void);
303 * Return non zero if we are currently running in the Octeon simulator
307 int octeon_is_simulation(void)
309 return octeon_bootinfo
->board_type
== CVMX_BOARD_TYPE_SIM
;
311 EXPORT_SYMBOL(octeon_is_simulation
);
314 * Return true if Octeon is in PCI Host mode. This means
315 * Linux can control the PCI bus.
317 * Returns Non zero if Octeon in host mode.
319 int octeon_is_pci_host(void)
322 return octeon_bootinfo
->config_flags
& CVMX_BOOTINFO_CFG_FLAG_PCI_HOST
;
329 * Get the clock rate of Octeon
331 * Returns Clock rate in HZ
333 uint64_t octeon_get_clock_rate(void)
335 struct cvmx_sysinfo
*sysinfo
= cvmx_sysinfo_get();
337 return sysinfo
->cpu_clock_hz
;
339 EXPORT_SYMBOL(octeon_get_clock_rate
);
341 static u64 octeon_io_clock_rate
;
343 u64
octeon_get_io_clock_rate(void)
345 return octeon_io_clock_rate
;
347 EXPORT_SYMBOL(octeon_get_io_clock_rate
);
351 * Write to the LCD display connected to the bootbus. This display
352 * exists on most Cavium evaluation boards. If it doesn't exist, then
353 * this function doesn't do anything.
355 * @s: String to write
357 static void octeon_write_lcd(const char *s
)
359 if (octeon_bootinfo
->led_display_base_addr
) {
360 void __iomem
*lcd_address
=
361 ioremap(octeon_bootinfo
->led_display_base_addr
,
364 for (i
= 0; i
< 8; i
++, s
++) {
366 iowrite8(*s
, lcd_address
+ i
);
368 iowrite8(' ', lcd_address
+ i
);
370 iounmap(lcd_address
);
375 * Return the console uart passed by the bootloader
377 * Returns uart (0 or 1)
379 static int octeon_get_boot_uart(void)
381 return (octeon_boot_desc_ptr
->flags
& OCTEON_BL_FLAG_CONSOLE_UART1
) ?
386 * Get the coremask Linux was booted on.
390 int octeon_get_boot_coremask(void)
392 return octeon_boot_desc_ptr
->core_mask
;
396 * Check the hardware BIST results for a CPU
398 void octeon_check_cpu_bist(void)
400 const int coreid
= cvmx_get_core_num();
401 unsigned long long mask
;
402 unsigned long long bist_val
;
404 /* Check BIST results for COP0 registers */
405 mask
= 0x1f00000000ull
;
406 bist_val
= read_octeon_c0_icacheerr();
408 pr_err("Core%d BIST Failure: CacheErr(icache) = 0x%llx\n",
411 bist_val
= read_octeon_c0_dcacheerr();
413 pr_err("Core%d L1 Dcache parity error: "
414 "CacheErr(dcache) = 0x%llx\n",
417 mask
= 0xfc00000000000000ull
;
418 bist_val
= read_c0_cvmmemctl();
420 pr_err("Core%d BIST Failure: COP0_CVM_MEM_CTL = 0x%llx\n",
423 write_octeon_c0_dcacheerr(0);
429 * @command: Command to pass to the bootloader. Currently ignored.
431 static void octeon_restart(char *command
)
433 /* Disable all watchdogs before soft reset. They don't get cleared */
436 for_each_online_cpu(cpu
)
437 cvmx_write_csr(CVMX_CIU_WDOGX(cpu_logical_map(cpu
)), 0);
439 cvmx_write_csr(CVMX_CIU_WDOGX(cvmx_get_core_num()), 0);
444 if (OCTEON_IS_OCTEON3())
445 cvmx_write_csr(CVMX_RST_SOFT_RST
, 1);
447 cvmx_write_csr(CVMX_CIU_SOFT_RST
, 1);
452 * Permanently stop a core.
456 static void octeon_kill_core(void *arg
)
458 if (octeon_is_simulation())
459 /* A break instruction causes the simulator stop a core */
460 asm volatile ("break" ::: "memory");
463 /* Disable watchdog on this core. */
464 cvmx_write_csr(CVMX_CIU_WDOGX(cvmx_get_core_num()), 0);
465 /* Spin in a low power mode. */
467 asm volatile ("wait" ::: "memory");
474 static void octeon_halt(void)
476 smp_call_function(octeon_kill_core
, NULL
, 0);
478 switch (octeon_bootinfo
->board_type
) {
479 case CVMX_BOARD_TYPE_NAO38
:
480 /* Driving a 1 to GPIO 12 shuts off this board */
481 cvmx_write_csr(CVMX_GPIO_BIT_CFGX(12), 1);
482 cvmx_write_csr(CVMX_GPIO_TX_SET
, 0x1000);
485 octeon_write_lcd("PowerOff");
489 octeon_kill_core(NULL
);
492 static char __read_mostly octeon_system_type
[80];
494 static void __init
init_octeon_system_type(void)
496 char const *board_type
;
498 board_type
= cvmx_board_type_to_string(octeon_bootinfo
->board_type
);
499 if (board_type
== NULL
) {
500 struct device_node
*root
;
503 root
= of_find_node_by_path("/");
504 ret
= of_property_read_string(root
, "model", &board_type
);
507 board_type
= "Unsupported Board";
510 snprintf(octeon_system_type
, sizeof(octeon_system_type
), "%s (%s)",
511 board_type
, octeon_model_get_string(read_c0_prid()));
515 * Return a string representing the system type
519 const char *octeon_board_type_string(void)
521 return octeon_system_type
;
524 const char *get_system_type(void)
525 __attribute__ ((alias("octeon_board_type_string")));
527 void octeon_user_io_init(void)
529 union octeon_cvmemctl cvmmemctl
;
531 /* Get the current settings for CP0_CVMMEMCTL_REG */
532 cvmmemctl
.u64
= read_c0_cvmmemctl();
533 /* R/W If set, marked write-buffer entries time out the same
534 * as as other entries; if clear, marked write-buffer entries
535 * use the maximum timeout. */
536 cvmmemctl
.s
.dismarkwblongto
= 1;
537 /* R/W If set, a merged store does not clear the write-buffer
538 * entry timeout state. */
539 cvmmemctl
.s
.dismrgclrwbto
= 0;
540 /* R/W Two bits that are the MSBs of the resultant CVMSEG LM
541 * word location for an IOBDMA. The other 8 bits come from the
542 * SCRADDR field of the IOBDMA. */
543 cvmmemctl
.s
.iobdmascrmsb
= 0;
544 /* R/W If set, SYNCWS and SYNCS only order marked stores; if
545 * clear, SYNCWS and SYNCS only order unmarked
546 * stores. SYNCWSMARKED has no effect when DISSYNCWS is
548 cvmmemctl
.s
.syncwsmarked
= 0;
549 /* R/W If set, SYNCWS acts as SYNCW and SYNCS acts as SYNC. */
550 cvmmemctl
.s
.dissyncws
= 0;
551 /* R/W If set, no stall happens on write buffer full. */
552 if (OCTEON_IS_MODEL(OCTEON_CN38XX_PASS2
))
553 cvmmemctl
.s
.diswbfst
= 1;
555 cvmmemctl
.s
.diswbfst
= 0;
556 /* R/W If set (and SX set), supervisor-level loads/stores can
557 * use XKPHYS addresses with <48>==0 */
558 cvmmemctl
.s
.xkmemenas
= 0;
560 /* R/W If set (and UX set), user-level loads/stores can use
561 * XKPHYS addresses with VA<48>==0 */
562 cvmmemctl
.s
.xkmemenau
= 0;
564 /* R/W If set (and SX set), supervisor-level loads/stores can
565 * use XKPHYS addresses with VA<48>==1 */
566 cvmmemctl
.s
.xkioenas
= 0;
568 /* R/W If set (and UX set), user-level loads/stores can use
569 * XKPHYS addresses with VA<48>==1 */
570 cvmmemctl
.s
.xkioenau
= 0;
572 /* R/W If set, all stores act as SYNCW (NOMERGE must be set
573 * when this is set) RW, reset to 0. */
574 cvmmemctl
.s
.allsyncw
= 0;
576 /* R/W If set, no stores merge, and all stores reach the
577 * coherent bus in order. */
578 cvmmemctl
.s
.nomerge
= 0;
579 /* R/W Selects the bit in the counter used for DID time-outs 0
580 * = 231, 1 = 230, 2 = 229, 3 = 214. Actual time-out is
581 * between 1x and 2x this interval. For example, with
582 * DIDTTO=3, expiration interval is between 16K and 32K. */
583 cvmmemctl
.s
.didtto
= 0;
584 /* R/W If set, the (mem) CSR clock never turns off. */
585 cvmmemctl
.s
.csrckalwys
= 0;
586 /* R/W If set, mclk never turns off. */
587 cvmmemctl
.s
.mclkalwys
= 0;
588 /* R/W Selects the bit in the counter used for write buffer
589 * flush time-outs (WBFLT+11) is the bit position in an
590 * internal counter used to determine expiration. The write
591 * buffer expires between 1x and 2x this interval. For
592 * example, with WBFLT = 0, a write buffer expires between 2K
593 * and 4K cycles after the write buffer entry is allocated. */
594 cvmmemctl
.s
.wbfltime
= 0;
595 /* R/W If set, do not put Istream in the L2 cache. */
596 cvmmemctl
.s
.istrnol2
= 0;
599 * R/W The write buffer threshold. As per erratum Core-14752
600 * for CN63XX, a sc/scd might fail if the write buffer is
601 * full. Lowering WBTHRESH greatly lowers the chances of the
602 * write buffer ever being full and triggering the erratum.
604 if (OCTEON_IS_MODEL(OCTEON_CN63XX_PASS1_X
))
605 cvmmemctl
.s
.wbthresh
= 4;
607 cvmmemctl
.s
.wbthresh
= 10;
609 /* R/W If set, CVMSEG is available for loads/stores in
610 * kernel/debug mode. */
611 #if CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE > 0
612 cvmmemctl
.s
.cvmsegenak
= 1;
614 cvmmemctl
.s
.cvmsegenak
= 0;
616 /* R/W If set, CVMSEG is available for loads/stores in
617 * supervisor mode. */
618 cvmmemctl
.s
.cvmsegenas
= 0;
619 /* R/W If set, CVMSEG is available for loads/stores in user
621 cvmmemctl
.s
.cvmsegenau
= 0;
623 write_c0_cvmmemctl(cvmmemctl
.u64
);
625 /* Setup of CVMSEG is done in kernel-entry-init.h */
626 if (smp_processor_id() == 0)
627 pr_notice("CVMSEG size: %d cache lines (%d bytes)\n",
628 CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE
,
629 CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE
* 128);
631 if (octeon_has_feature(OCTEON_FEATURE_FAU
)) {
632 union cvmx_iob_fau_timeout fau_timeout
;
634 /* Set a default for the hardware timeouts */
636 fau_timeout
.s
.tout_val
= 0xfff;
637 /* Disable tagwait FAU timeout */
638 fau_timeout
.s
.tout_enb
= 0;
639 cvmx_write_csr(CVMX_IOB_FAU_TIMEOUT
, fau_timeout
.u64
);
642 if ((!OCTEON_IS_MODEL(OCTEON_CN68XX
) &&
643 !OCTEON_IS_MODEL(OCTEON_CN7XXX
)) ||
644 OCTEON_IS_MODEL(OCTEON_CN70XX
)) {
645 union cvmx_pow_nw_tim nm_tim
;
650 cvmx_write_csr(CVMX_POW_NW_TIM
, nm_tim
.u64
);
653 write_octeon_c0_icacheerr(0);
654 write_c0_derraddr1(0);
658 * Early entry point for arch setup
660 void __init
prom_init(void)
662 struct cvmx_sysinfo
*sysinfo
;
668 #ifdef CONFIG_CAVIUM_RESERVE32
672 * The bootloader passes a pointer to the boot descriptor in
673 * $a3, this is available as fw_arg3.
675 octeon_boot_desc_ptr
= (struct octeon_boot_descriptor
*)fw_arg3
;
677 cvmx_phys_to_ptr(octeon_boot_desc_ptr
->cvmx_desc_vaddr
);
678 cvmx_bootmem_init(cvmx_phys_to_ptr(octeon_bootinfo
->phy_mem_desc_addr
));
680 sysinfo
= cvmx_sysinfo_get();
681 memset(sysinfo
, 0, sizeof(*sysinfo
));
682 sysinfo
->system_dram_size
= octeon_bootinfo
->dram_size
<< 20;
683 sysinfo
->phy_mem_desc_addr
= (u64
)phys_to_virt(octeon_bootinfo
->phy_mem_desc_addr
);
685 if ((octeon_bootinfo
->major_version
> 1) ||
686 (octeon_bootinfo
->major_version
== 1 &&
687 octeon_bootinfo
->minor_version
>= 4))
688 cvmx_coremask_copy(&sysinfo
->core_mask
,
689 &octeon_bootinfo
->ext_core_mask
);
691 cvmx_coremask_set64(&sysinfo
->core_mask
,
692 octeon_bootinfo
->core_mask
);
694 /* Some broken u-boot pass garbage in upper bits, clear them out */
695 if (!OCTEON_IS_MODEL(OCTEON_CN78XX
))
696 for (i
= 512; i
< 1024; i
++)
697 cvmx_coremask_clear_core(&sysinfo
->core_mask
, i
);
699 sysinfo
->exception_base_addr
= octeon_bootinfo
->exception_base_addr
;
700 sysinfo
->cpu_clock_hz
= octeon_bootinfo
->eclock_hz
;
701 sysinfo
->dram_data_rate_hz
= octeon_bootinfo
->dclock_hz
* 2;
702 sysinfo
->board_type
= octeon_bootinfo
->board_type
;
703 sysinfo
->board_rev_major
= octeon_bootinfo
->board_rev_major
;
704 sysinfo
->board_rev_minor
= octeon_bootinfo
->board_rev_minor
;
705 memcpy(sysinfo
->mac_addr_base
, octeon_bootinfo
->mac_addr_base
,
706 sizeof(sysinfo
->mac_addr_base
));
707 sysinfo
->mac_addr_count
= octeon_bootinfo
->mac_addr_count
;
708 memcpy(sysinfo
->board_serial_number
,
709 octeon_bootinfo
->board_serial_number
,
710 sizeof(sysinfo
->board_serial_number
));
711 sysinfo
->compact_flash_common_base_addr
=
712 octeon_bootinfo
->compact_flash_common_base_addr
;
713 sysinfo
->compact_flash_attribute_base_addr
=
714 octeon_bootinfo
->compact_flash_attribute_base_addr
;
715 sysinfo
->led_display_base_addr
= octeon_bootinfo
->led_display_base_addr
;
716 sysinfo
->dfa_ref_clock_hz
= octeon_bootinfo
->dfa_ref_clock_hz
;
717 sysinfo
->bootloader_config_flags
= octeon_bootinfo
->config_flags
;
719 if (OCTEON_IS_OCTEON2()) {
720 /* I/O clock runs at a different rate than the CPU. */
721 union cvmx_mio_rst_boot rst_boot
;
722 rst_boot
.u64
= cvmx_read_csr(CVMX_MIO_RST_BOOT
);
723 octeon_io_clock_rate
= 50000000 * rst_boot
.s
.pnr_mul
;
724 } else if (OCTEON_IS_OCTEON3()) {
725 /* I/O clock runs at a different rate than the CPU. */
726 union cvmx_rst_boot rst_boot
;
727 rst_boot
.u64
= cvmx_read_csr(CVMX_RST_BOOT
);
728 octeon_io_clock_rate
= 50000000 * rst_boot
.s
.pnr_mul
;
730 octeon_io_clock_rate
= sysinfo
->cpu_clock_hz
;
733 t
= read_c0_cvmctl();
734 if ((t
& (1ull << 27)) == 0) {
736 * Setup the multiplier save/restore code if
737 * CvmCtl[NOMUL] clear.
745 int save_max
= (char *)octeon_mult_save_end
-
746 (char *)octeon_mult_save
;
747 int restore_max
= (char *)octeon_mult_restore_end
-
748 (char *)octeon_mult_restore
;
749 if (current_cpu_data
.cputype
== CPU_CAVIUM_OCTEON3
) {
750 save
= octeon_mult_save3
;
751 save_end
= octeon_mult_save3_end
;
752 restore
= octeon_mult_restore3
;
753 restore_end
= octeon_mult_restore3_end
;
755 save
= octeon_mult_save2
;
756 save_end
= octeon_mult_save2_end
;
757 restore
= octeon_mult_restore2
;
758 restore_end
= octeon_mult_restore2_end
;
760 save_len
= (char *)save_end
- (char *)save
;
761 restore_len
= (char *)restore_end
- (char *)restore
;
762 if (!WARN_ON(save_len
> save_max
||
763 restore_len
> restore_max
)) {
764 memcpy(octeon_mult_save
, save
, save_len
);
765 memcpy(octeon_mult_restore
, restore
, restore_len
);
770 * Only enable the LED controller if we're running on a CN38XX, CN58XX,
771 * or CN56XX. The CN30XX and CN31XX don't have an LED controller.
773 if (!octeon_is_simulation() &&
774 octeon_has_feature(OCTEON_FEATURE_LED_CONTROLLER
)) {
775 cvmx_write_csr(CVMX_LED_EN
, 0);
776 cvmx_write_csr(CVMX_LED_PRT
, 0);
777 cvmx_write_csr(CVMX_LED_DBG
, 0);
778 cvmx_write_csr(CVMX_LED_PRT_FMT
, 0);
779 cvmx_write_csr(CVMX_LED_UDD_CNTX(0), 32);
780 cvmx_write_csr(CVMX_LED_UDD_CNTX(1), 32);
781 cvmx_write_csr(CVMX_LED_UDD_DATX(0), 0);
782 cvmx_write_csr(CVMX_LED_UDD_DATX(1), 0);
783 cvmx_write_csr(CVMX_LED_EN
, 1);
785 #ifdef CONFIG_CAVIUM_RESERVE32
787 * We need to temporarily allocate all memory in the reserve32
788 * region. This makes sure the kernel doesn't allocate this
789 * memory when it is getting memory from the
790 * bootloader. Later, after the memory allocations are
791 * complete, the reserve32 will be freed.
793 * Allocate memory for RESERVED32 aligned on 2MB boundary. This
794 * is in case we later use hugetlb entries with it.
796 addr
= cvmx_bootmem_phy_named_block_alloc(CONFIG_CAVIUM_RESERVE32
<< 20,
798 "CAVIUM_RESERVE32", 0);
800 pr_err("Failed to allocate CAVIUM_RESERVE32 memory area\n");
802 octeon_reserve32_memory
= addr
;
805 #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2
806 if (cvmx_read_csr(CVMX_L2D_FUS3
) & (3ull << 34)) {
807 pr_info("Skipping L2 locking due to reduced L2 cache size\n");
809 uint32_t __maybe_unused ebase
= read_c0_ebase() & 0x3ffff000;
810 #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_TLB
812 cvmx_l2c_lock_mem_region(ebase
, 0x100);
814 #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_EXCEPTION
815 /* General exception */
816 cvmx_l2c_lock_mem_region(ebase
+ 0x180, 0x80);
818 #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_LOW_LEVEL_INTERRUPT
819 /* Interrupt handler */
820 cvmx_l2c_lock_mem_region(ebase
+ 0x200, 0x80);
822 #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_INTERRUPT
823 cvmx_l2c_lock_mem_region(__pa_symbol(handle_int
), 0x100);
824 cvmx_l2c_lock_mem_region(__pa_symbol(plat_irq_dispatch
), 0x80);
826 #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_MEMCPY
827 cvmx_l2c_lock_mem_region(__pa_symbol(memcpy
), 0x480);
832 octeon_check_cpu_bist();
834 octeon_uart
= octeon_get_boot_uart();
837 octeon_write_lcd("LinuxSMP");
839 octeon_write_lcd("Linux");
842 octeon_setup_delays();
845 * BIST should always be enabled when doing a soft reset. L2
846 * Cache locking for instance is not cleared unless BIST is
847 * enabled. Unfortunately due to a chip errata G-200 for
848 * Cn38XX and CN31XX, BIST must be disabled on these parts.
850 if (OCTEON_IS_MODEL(OCTEON_CN38XX_PASS2
) ||
851 OCTEON_IS_MODEL(OCTEON_CN31XX
))
852 cvmx_write_csr(CVMX_CIU_SOFT_BIST
, 0);
854 cvmx_write_csr(CVMX_CIU_SOFT_BIST
, 1);
856 /* Default to 64MB in the simulator to speed things up */
857 if (octeon_is_simulation())
858 max_memory
= 64ull << 20;
860 arg
= strstr(arcs_cmdline
, "mem=");
862 max_memory
= memparse(arg
+ 4, &p
);
864 max_memory
= 32ull << 30;
866 reserve_low_mem
= memparse(p
+ 1, &p
);
870 argc
= octeon_boot_desc_ptr
->argc
;
871 for (i
= 0; i
< argc
; i
++) {
873 cvmx_phys_to_ptr(octeon_boot_desc_ptr
->argv
[i
]);
874 if ((strncmp(arg
, "MEM=", 4) == 0) ||
875 (strncmp(arg
, "mem=", 4) == 0)) {
876 max_memory
= memparse(arg
+ 4, &p
);
878 max_memory
= 32ull << 30;
880 reserve_low_mem
= memparse(p
+ 1, &p
);
882 } else if (strncmp(arg
, "crashkernel=", 12) == 0) {
883 crashk_size
= memparse(arg
+12, &p
);
885 crashk_base
= memparse(p
+1, &p
);
886 strcat(arcs_cmdline
, " ");
887 strcat(arcs_cmdline
, arg
);
889 * To do: switch parsing to new style, something like:
890 * parse_crashkernel(arg, sysinfo->system_dram_size,
891 * &crashk_size, &crashk_base);
894 } else if (strlen(arcs_cmdline
) + strlen(arg
) + 1 <
895 sizeof(arcs_cmdline
) - 1) {
896 strcat(arcs_cmdline
, " ");
897 strcat(arcs_cmdline
, arg
);
901 if (strstr(arcs_cmdline
, "console=") == NULL
) {
902 if (octeon_uart
== 1)
903 strcat(arcs_cmdline
, " console=ttyS1,115200");
905 strcat(arcs_cmdline
, " console=ttyS0,115200");
908 mips_hpt_frequency
= octeon_get_clock_rate();
910 octeon_init_cvmcount();
912 _machine_restart
= octeon_restart
;
913 _machine_halt
= octeon_halt
;
916 _machine_kexec_shutdown
= octeon_shutdown
;
917 _machine_crash_shutdown
= octeon_crash_shutdown
;
918 _machine_kexec_prepare
= octeon_kexec_prepare
;
920 _crash_smp_send_stop
= octeon_crash_smp_send_stop
;
924 octeon_user_io_init();
928 /* Exclude a single page from the regions obtained in plat_mem_setup. */
929 #ifndef CONFIG_CRASH_DUMP
930 static __init
void memory_exclude_page(u64 addr
, u64
*mem
, u64
*size
)
932 if (addr
> *mem
&& addr
< *mem
+ *size
) {
933 u64 inc
= addr
- *mem
;
934 memblock_add(*mem
, inc
);
939 if (addr
== *mem
&& *size
> PAGE_SIZE
) {
944 #endif /* CONFIG_CRASH_DUMP */
946 void __init
fw_init_cmdline(void)
950 octeon_boot_desc_ptr
= (struct octeon_boot_descriptor
*)fw_arg3
;
951 for (i
= 0; i
< octeon_boot_desc_ptr
->argc
; i
++) {
953 cvmx_phys_to_ptr(octeon_boot_desc_ptr
->argv
[i
]);
954 if (strlen(arcs_cmdline
) + strlen(arg
) + 1 <
955 sizeof(arcs_cmdline
) - 1) {
956 strcat(arcs_cmdline
, " ");
957 strcat(arcs_cmdline
, arg
);
962 void __init
*plat_get_fdt(void)
965 cvmx_phys_to_ptr(octeon_boot_desc_ptr
->cvmx_desc_vaddr
);
966 return phys_to_virt(octeon_bootinfo
->fdt_addr
);
969 void __init
plat_mem_setup(void)
971 uint64_t mem_alloc_size
;
974 #ifndef CONFIG_CRASH_DUMP
982 * The Mips memory init uses the first memory location for
983 * some memory vectors. When SPARSEMEM is in use, it doesn't
984 * verify that the size is big enough for the final
985 * vectors. Making the smallest chuck 4MB seems to be enough
986 * to consistently work.
988 mem_alloc_size
= 4 << 20;
989 if (mem_alloc_size
> max_memory
)
990 mem_alloc_size
= max_memory
;
992 /* Crashkernel ignores bootmem list. It relies on mem=X@Y option */
993 #ifdef CONFIG_CRASH_DUMP
994 memblock_add(reserve_low_mem
, max_memory
);
998 if (crashk_size
> 0) {
999 memblock_add(crashk_base
, crashk_size
);
1000 crashk_end
= crashk_base
+ crashk_size
;
1004 * When allocating memory, we want incrementing addresses,
1005 * which is handled by memblock
1007 cvmx_bootmem_lock();
1008 while (total
< max_memory
) {
1009 memory
= cvmx_bootmem_phy_alloc(mem_alloc_size
,
1010 __pa_symbol(&_end
), -1,
1012 CVMX_BOOTMEM_FLAG_NO_LOCKING
);
1014 u64 size
= mem_alloc_size
;
1020 * exclude a page at the beginning and end of
1021 * the 256MB PCIe 'hole' so the kernel will not
1022 * try to allocate multi-page buffers that
1023 * span the discontinuity.
1025 memory_exclude_page(CVMX_PCIE_BAR1_PHYS_BASE
,
1027 memory_exclude_page(CVMX_PCIE_BAR1_PHYS_BASE
+
1028 CVMX_PCIE_BAR1_PHYS_SIZE
,
1031 end
= memory
+ mem_alloc_size
;
1034 * This function automatically merges address regions
1035 * next to each other if they are received in
1036 * incrementing order
1038 if (memory
< crashk_base
&& end
> crashk_end
) {
1039 /* region is fully in */
1040 memblock_add(memory
, crashk_base
- memory
);
1041 total
+= crashk_base
- memory
;
1042 memblock_add(crashk_end
, end
- crashk_end
);
1043 total
+= end
- crashk_end
;
1047 if (memory
>= crashk_base
&& end
<= crashk_end
)
1049 * Entire memory region is within the new
1050 * kernel's memory, ignore it.
1054 if (memory
> crashk_base
&& memory
< crashk_end
&&
1057 * Overlap with the beginning of the region,
1058 * reserve the beginning.
1060 mem_alloc_size
-= crashk_end
- memory
;
1061 memory
= crashk_end
;
1062 } else if (memory
< crashk_base
&& end
> crashk_base
&&
1065 * Overlap with the beginning of the region,
1068 mem_alloc_size
-= end
- crashk_base
;
1070 memblock_add(memory
, mem_alloc_size
);
1071 total
+= mem_alloc_size
;
1072 /* Recovering mem_alloc_size */
1073 mem_alloc_size
= 4 << 20;
1078 cvmx_bootmem_unlock();
1079 #endif /* CONFIG_CRASH_DUMP */
1081 #ifdef CONFIG_CAVIUM_RESERVE32
1083 * Now that we've allocated the kernel memory it is safe to
1084 * free the reserved region. We free it here so that builtin
1085 * drivers can use the memory.
1087 if (octeon_reserve32_memory
)
1088 cvmx_bootmem_free_named("CAVIUM_RESERVE32");
1089 #endif /* CONFIG_CAVIUM_RESERVE32 */
1092 panic("Unable to allocate memory from "
1093 "cvmx_bootmem_phy_alloc");
1097 * Emit one character to the boot UART. Exported for use by the
1100 void prom_putchar(char c
)
1104 /* Spin until there is room */
1106 lsrval
= cvmx_read_csr(CVMX_MIO_UARTX_LSR(octeon_uart
));
1107 } while ((lsrval
& 0x20) == 0);
1109 /* Write the byte */
1110 cvmx_write_csr(CVMX_MIO_UARTX_THR(octeon_uart
), c
& 0xffull
);
1112 EXPORT_SYMBOL(prom_putchar
);
1114 void __init
prom_free_prom_memory(void)
1116 if (OCTEON_IS_MODEL(OCTEON_CN6XXX
)) {
1117 /* Check for presence of Core-14449 fix. */
1123 asm volatile("# before" : : : "memory");
1127 ".set noreorder\n\t"
1130 "1:\tlw %0,-12($31)\n\t"
1132 : "=r" (insn
) : : "$31", "memory");
1134 if ((insn
>> 26) != 0x33)
1135 panic("No PREF instruction at Core-14449 probe point.");
1137 if (((insn
>> 16) & 0x1f) != 28)
1138 panic("OCTEON II DCache prefetch workaround not in place (%04x).\n"
1139 "Please build kernel with proper options (CONFIG_CAVIUM_CN63XXP1).",
1144 void __init
octeon_fill_mac_addresses(void);
1146 void __init
device_tree_init(void)
1152 if (fw_passed_dtb
) {
1153 fdt
= (void *)fw_passed_dtb
;
1156 pr_info("Using appended Device Tree.\n");
1157 } else if (octeon_bootinfo
->minor_version
>= 3 && octeon_bootinfo
->fdt_addr
) {
1158 fdt
= phys_to_virt(octeon_bootinfo
->fdt_addr
);
1159 if (fdt_check_header(fdt
))
1160 panic("Corrupt Device Tree passed to kernel.");
1163 pr_info("Using passed Device Tree.\n");
1164 } else if (OCTEON_IS_MODEL(OCTEON_CN68XX
)) {
1165 fdt
= &__dtb_octeon_68xx_begin
;
1169 fdt
= &__dtb_octeon_3xxx_begin
;
1174 initial_boot_params
= (void *)fdt
;
1177 octeon_prune_device_tree();
1178 pr_info("Using internal Device Tree.\n");
1181 octeon_fill_mac_addresses();
1182 unflatten_and_copy_device_tree();
1183 init_octeon_system_type();
1186 static int __initdata disable_octeon_edac_p
;
1188 static int __init
disable_octeon_edac(char *str
)
1190 disable_octeon_edac_p
= 1;
1193 early_param("disable_octeon_edac", disable_octeon_edac
);
1195 static char *edac_device_names
[] = {
1200 static int __init
edac_devinit(void)
1202 struct platform_device
*dev
;
1207 if (disable_octeon_edac_p
)
1210 for (i
= 0; i
< ARRAY_SIZE(edac_device_names
); i
++) {
1211 name
= edac_device_names
[i
];
1212 dev
= platform_device_register_simple(name
, -1, NULL
, 0);
1214 pr_err("Registration of %s failed!\n", name
);
1219 num_lmc
= OCTEON_IS_MODEL(OCTEON_CN68XX
) ? 4 :
1220 (OCTEON_IS_MODEL(OCTEON_CN56XX
) ? 2 : 1);
1221 for (i
= 0; i
< num_lmc
; i
++) {
1222 dev
= platform_device_register_simple("octeon_lmc_edac",
1225 pr_err("Registration of octeon_lmc_edac %d failed!\n", i
);
1232 device_initcall(edac_devinit
);
1234 static void __initdata
*octeon_dummy_iospace
;
1236 static int __init
octeon_no_pci_init(void)
1239 * Initially assume there is no PCI. The PCI/PCIe platform code will
1240 * later re-initialize these to correct values if they are present.
1242 octeon_dummy_iospace
= vzalloc(IO_SPACE_LIMIT
);
1243 set_io_port_base((unsigned long)octeon_dummy_iospace
);
1244 ioport_resource
.start
= MAX_RESOURCE
;
1245 ioport_resource
.end
= 0;
1248 core_initcall(octeon_no_pci_init
);
1250 static int __init
octeon_no_pci_release(void)
1253 * Release the allocated memory if a real IO space is there.
1255 if ((unsigned long)octeon_dummy_iospace
!= mips_io_port_base
)
1256 vfree(octeon_dummy_iospace
);
1259 late_initcall(octeon_no_pci_release
);