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 #ifdef CONFIG_CAVIUM_DECODE_RSL
45 extern void cvmx_interrupt_rsl_decode(void);
46 extern int __cvmx_interrupt_ecc_report_single_bit_errors
;
47 extern void cvmx_interrupt_rsl_enable(void);
50 extern struct plat_smp_ops octeon_smp_ops
;
53 extern void pci_console_init(const char *arg
);
56 static unsigned long long MAX_MEMORY
= 512ull << 20;
58 struct octeon_boot_descriptor
*octeon_boot_desc_ptr
;
60 struct cvmx_bootinfo
*octeon_bootinfo
;
61 EXPORT_SYMBOL(octeon_bootinfo
);
63 static unsigned long long RESERVE_LOW_MEM
= 0ull;
67 * Wait for relocation code is prepared and send
68 * secondary CPUs to spin until kernel is relocated.
70 static void octeon_kexec_smp_down(void *ignored
)
72 int cpu
= smp_processor_id();
75 set_cpu_online(cpu
, false);
76 while (!atomic_read(&kexec_ready_to_reboot
))
83 relocated_kexec_smp_wait(NULL
);
87 #define OCTEON_DDR0_BASE (0x0ULL)
88 #define OCTEON_DDR0_SIZE (0x010000000ULL)
89 #define OCTEON_DDR1_BASE (0x410000000ULL)
90 #define OCTEON_DDR1_SIZE (0x010000000ULL)
91 #define OCTEON_DDR2_BASE (0x020000000ULL)
92 #define OCTEON_DDR2_SIZE (0x3e0000000ULL)
93 #define OCTEON_MAX_PHY_MEM_SIZE (16*1024*1024*1024ULL)
95 static struct kimage
*kimage_ptr
;
97 static void kexec_bootmem_init(uint64_t mem_size
, uint32_t low_reserved_bytes
)
100 struct cvmx_bootmem_desc
*bootmem_desc
;
102 bootmem_desc
= cvmx_bootmem_get_desc();
104 if (mem_size
> OCTEON_MAX_PHY_MEM_SIZE
) {
105 mem_size
= OCTEON_MAX_PHY_MEM_SIZE
;
106 pr_err("Error: requested memory too large,"
107 "truncating to maximum size\n");
110 bootmem_desc
->major_version
= CVMX_BOOTMEM_DESC_MAJ_VER
;
111 bootmem_desc
->minor_version
= CVMX_BOOTMEM_DESC_MIN_VER
;
113 addr
= (OCTEON_DDR0_BASE
+ RESERVE_LOW_MEM
+ low_reserved_bytes
);
114 bootmem_desc
->head_addr
= 0;
116 if (mem_size
<= OCTEON_DDR0_SIZE
) {
117 __cvmx_bootmem_phy_free(addr
,
118 mem_size
- RESERVE_LOW_MEM
-
119 low_reserved_bytes
, 0);
123 __cvmx_bootmem_phy_free(addr
,
124 OCTEON_DDR0_SIZE
- RESERVE_LOW_MEM
-
125 low_reserved_bytes
, 0);
127 mem_size
-= OCTEON_DDR0_SIZE
;
129 if (mem_size
> OCTEON_DDR1_SIZE
) {
130 __cvmx_bootmem_phy_free(OCTEON_DDR1_BASE
, OCTEON_DDR1_SIZE
, 0);
131 __cvmx_bootmem_phy_free(OCTEON_DDR2_BASE
,
132 mem_size
- OCTEON_DDR1_SIZE
, 0);
134 __cvmx_bootmem_phy_free(OCTEON_DDR1_BASE
, mem_size
, 0);
137 static int octeon_kexec_prepare(struct kimage
*image
)
140 char *bootloader
= "kexec";
142 octeon_boot_desc_ptr
->argc
= 0;
143 for (i
= 0; i
< image
->nr_segments
; i
++) {
144 if (!strncmp(bootloader
, (char *)image
->segment
[i
].buf
,
145 strlen(bootloader
))) {
147 * convert command line string to array
148 * of parameters (as bootloader does).
151 char *str
= (char *)image
->segment
[i
].buf
;
152 char *ptr
= strchr(str
, ' ');
153 while (ptr
&& (OCTEON_ARGV_MAX_ARGS
> argc
)) {
156 offt
= (int)(ptr
- str
+ 1);
157 octeon_boot_desc_ptr
->argv
[argc
] =
158 image
->segment
[i
].mem
+ offt
;
161 ptr
= strchr(ptr
+ 1, ' ');
163 octeon_boot_desc_ptr
->argc
= argc
;
169 * Information about segments will be needed during pre-boot memory
176 static void octeon_generic_shutdown(void)
182 struct cvmx_bootmem_desc
*bootmem_desc
;
183 void *named_block_array_ptr
;
185 bootmem_desc
= cvmx_bootmem_get_desc();
186 named_block_array_ptr
=
187 cvmx_phys_to_ptr(bootmem_desc
->named_block_array_addr
);
190 /* disable watchdogs */
191 for_each_online_cpu(cpu
)
192 cvmx_write_csr(CVMX_CIU_WDOGX(cpu_logical_map(cpu
)), 0);
194 cvmx_write_csr(CVMX_CIU_WDOGX(cvmx_get_core_num()), 0);
196 if (kimage_ptr
!= kexec_crash_image
) {
197 memset(named_block_array_ptr
,
199 CVMX_BOOTMEM_NUM_NAMED_BLOCKS
*
200 sizeof(struct cvmx_bootmem_named_block_desc
));
202 * Mark all memory (except low 0x100000 bytes) as free.
203 * It is the same thing that bootloader does.
205 kexec_bootmem_init(octeon_bootinfo
->dram_size
*1024ULL*1024ULL,
208 * Allocate all segments to avoid their corruption during boot.
210 for (i
= 0; i
< kimage_ptr
->nr_segments
; i
++)
211 cvmx_bootmem_alloc_address(
212 kimage_ptr
->segment
[i
].memsz
+ 2*PAGE_SIZE
,
213 kimage_ptr
->segment
[i
].mem
- PAGE_SIZE
,
217 * Do not mark all memory as free. Free only named sections
218 * leaving the rest of memory unchanged.
220 struct cvmx_bootmem_named_block_desc
*ptr
=
221 (struct cvmx_bootmem_named_block_desc
*)
222 named_block_array_ptr
;
224 for (i
= 0; i
< bootmem_desc
->named_block_num_blocks
; i
++)
226 cvmx_bootmem_free_named(ptr
[i
].name
);
228 kexec_args
[2] = 1UL; /* running on octeon_main_processor */
229 kexec_args
[3] = (unsigned long)octeon_boot_desc_ptr
;
231 secondary_kexec_args
[2] = 0UL; /* running on secondary cpu */
232 secondary_kexec_args
[3] = (unsigned long)octeon_boot_desc_ptr
;
236 static void octeon_shutdown(void)
238 octeon_generic_shutdown();
240 smp_call_function(octeon_kexec_smp_down
, NULL
, 0);
242 while (num_online_cpus() > 1) {
249 static void octeon_crash_shutdown(struct pt_regs
*regs
)
251 octeon_generic_shutdown();
252 default_machine_crash_shutdown(regs
);
255 #endif /* CONFIG_KEXEC */
257 #ifdef CONFIG_CAVIUM_RESERVE32
258 uint64_t octeon_reserve32_memory
;
259 EXPORT_SYMBOL(octeon_reserve32_memory
);
263 /* crashkernel cmdline parameter is parsed _after_ memory setup
264 * we also parse it here (workaround for EHB5200) */
265 static uint64_t crashk_size
, crashk_base
;
268 static int octeon_uart
;
270 extern asmlinkage
void handle_int(void);
271 extern asmlinkage
void plat_irq_dispatch(void);
274 * Return non zero if we are currently running in the Octeon simulator
278 int octeon_is_simulation(void)
280 return octeon_bootinfo
->board_type
== CVMX_BOARD_TYPE_SIM
;
282 EXPORT_SYMBOL(octeon_is_simulation
);
285 * Return true if Octeon is in PCI Host mode. This means
286 * Linux can control the PCI bus.
288 * Returns Non zero if Octeon in host mode.
290 int octeon_is_pci_host(void)
293 return octeon_bootinfo
->config_flags
& CVMX_BOOTINFO_CFG_FLAG_PCI_HOST
;
300 * Get the clock rate of Octeon
302 * Returns Clock rate in HZ
304 uint64_t octeon_get_clock_rate(void)
306 struct cvmx_sysinfo
*sysinfo
= cvmx_sysinfo_get();
308 return sysinfo
->cpu_clock_hz
;
310 EXPORT_SYMBOL(octeon_get_clock_rate
);
312 static u64 octeon_io_clock_rate
;
314 u64
octeon_get_io_clock_rate(void)
316 return octeon_io_clock_rate
;
318 EXPORT_SYMBOL(octeon_get_io_clock_rate
);
322 * Write to the LCD display connected to the bootbus. This display
323 * exists on most Cavium evaluation boards. If it doesn't exist, then
324 * this function doesn't do anything.
326 * @s: String to write
328 void octeon_write_lcd(const char *s
)
330 if (octeon_bootinfo
->led_display_base_addr
) {
331 void __iomem
*lcd_address
=
332 ioremap_nocache(octeon_bootinfo
->led_display_base_addr
,
335 for (i
= 0; i
< 8; i
++, s
++) {
337 iowrite8(*s
, lcd_address
+ i
);
339 iowrite8(' ', lcd_address
+ i
);
341 iounmap(lcd_address
);
346 * Return the console uart passed by the bootloader
348 * Returns uart (0 or 1)
350 int octeon_get_boot_uart(void)
353 #ifdef CONFIG_CAVIUM_OCTEON_2ND_KERNEL
356 uart
= (octeon_boot_desc_ptr
->flags
& OCTEON_BL_FLAG_CONSOLE_UART1
) ?
363 * Get the coremask Linux was booted on.
367 int octeon_get_boot_coremask(void)
369 return octeon_boot_desc_ptr
->core_mask
;
373 * Check the hardware BIST results for a CPU
375 void octeon_check_cpu_bist(void)
377 const int coreid
= cvmx_get_core_num();
378 unsigned long long mask
;
379 unsigned long long bist_val
;
381 /* Check BIST results for COP0 registers */
382 mask
= 0x1f00000000ull
;
383 bist_val
= read_octeon_c0_icacheerr();
385 pr_err("Core%d BIST Failure: CacheErr(icache) = 0x%llx\n",
388 bist_val
= read_octeon_c0_dcacheerr();
390 pr_err("Core%d L1 Dcache parity error: "
391 "CacheErr(dcache) = 0x%llx\n",
394 mask
= 0xfc00000000000000ull
;
395 bist_val
= read_c0_cvmmemctl();
397 pr_err("Core%d BIST Failure: COP0_CVM_MEM_CTL = 0x%llx\n",
400 write_octeon_c0_dcacheerr(0);
406 * @command: Command to pass to the bootloader. Currently ignored.
408 static void octeon_restart(char *command
)
410 /* Disable all watchdogs before soft reset. They don't get cleared */
413 for_each_online_cpu(cpu
)
414 cvmx_write_csr(CVMX_CIU_WDOGX(cpu_logical_map(cpu
)), 0);
416 cvmx_write_csr(CVMX_CIU_WDOGX(cvmx_get_core_num()), 0);
421 cvmx_write_csr(CVMX_CIU_SOFT_RST
, 1);
426 * Permanently stop a core.
430 static void octeon_kill_core(void *arg
)
432 if (octeon_is_simulation())
433 /* A break instruction causes the simulator stop a core */
434 asm volatile ("break" ::: "memory");
437 /* Disable watchdog on this core. */
438 cvmx_write_csr(CVMX_CIU_WDOGX(cvmx_get_core_num()), 0);
439 /* Spin in a low power mode. */
441 asm volatile ("wait" ::: "memory");
448 static void octeon_halt(void)
450 smp_call_function(octeon_kill_core
, NULL
, 0);
452 switch (octeon_bootinfo
->board_type
) {
453 case CVMX_BOARD_TYPE_NAO38
:
454 /* Driving a 1 to GPIO 12 shuts off this board */
455 cvmx_write_csr(CVMX_GPIO_BIT_CFGX(12), 1);
456 cvmx_write_csr(CVMX_GPIO_TX_SET
, 0x1000);
459 octeon_write_lcd("PowerOff");
463 octeon_kill_core(NULL
);
467 * Handle all the error condition interrupts that might occur.
470 #ifdef CONFIG_CAVIUM_DECODE_RSL
471 static irqreturn_t
octeon_rlm_interrupt(int cpl
, void *dev_id
)
473 cvmx_interrupt_rsl_decode();
479 * Return a string representing the system type
483 const char *octeon_board_type_string(void)
485 static char name
[80];
486 sprintf(name
, "%s (%s)",
487 cvmx_board_type_to_string(octeon_bootinfo
->board_type
),
488 octeon_model_get_string(read_c0_prid()));
492 const char *get_system_type(void)
493 __attribute__ ((alias("octeon_board_type_string")));
495 void octeon_user_io_init(void)
497 union octeon_cvmemctl cvmmemctl
;
498 union cvmx_iob_fau_timeout fau_timeout
;
499 union cvmx_pow_nw_tim nm_tim
;
501 /* Get the current settings for CP0_CVMMEMCTL_REG */
502 cvmmemctl
.u64
= read_c0_cvmmemctl();
503 /* R/W If set, marked write-buffer entries time out the same
504 * as as other entries; if clear, marked write-buffer entries
505 * use the maximum timeout. */
506 cvmmemctl
.s
.dismarkwblongto
= 1;
507 /* R/W If set, a merged store does not clear the write-buffer
508 * entry timeout state. */
509 cvmmemctl
.s
.dismrgclrwbto
= 0;
510 /* R/W Two bits that are the MSBs of the resultant CVMSEG LM
511 * word location for an IOBDMA. The other 8 bits come from the
512 * SCRADDR field of the IOBDMA. */
513 cvmmemctl
.s
.iobdmascrmsb
= 0;
514 /* R/W If set, SYNCWS and SYNCS only order marked stores; if
515 * clear, SYNCWS and SYNCS only order unmarked
516 * stores. SYNCWSMARKED has no effect when DISSYNCWS is
518 cvmmemctl
.s
.syncwsmarked
= 0;
519 /* R/W If set, SYNCWS acts as SYNCW and SYNCS acts as SYNC. */
520 cvmmemctl
.s
.dissyncws
= 0;
521 /* R/W If set, no stall happens on write buffer full. */
522 if (OCTEON_IS_MODEL(OCTEON_CN38XX_PASS2
))
523 cvmmemctl
.s
.diswbfst
= 1;
525 cvmmemctl
.s
.diswbfst
= 0;
526 /* R/W If set (and SX set), supervisor-level loads/stores can
527 * use XKPHYS addresses with <48>==0 */
528 cvmmemctl
.s
.xkmemenas
= 0;
530 /* R/W If set (and UX set), user-level loads/stores can use
531 * XKPHYS addresses with VA<48>==0 */
532 cvmmemctl
.s
.xkmemenau
= 0;
534 /* R/W If set (and SX set), supervisor-level loads/stores can
535 * use XKPHYS addresses with VA<48>==1 */
536 cvmmemctl
.s
.xkioenas
= 0;
538 /* R/W If set (and UX set), user-level loads/stores can use
539 * XKPHYS addresses with VA<48>==1 */
540 cvmmemctl
.s
.xkioenau
= 0;
542 /* R/W If set, all stores act as SYNCW (NOMERGE must be set
543 * when this is set) RW, reset to 0. */
544 cvmmemctl
.s
.allsyncw
= 0;
546 /* R/W If set, no stores merge, and all stores reach the
547 * coherent bus in order. */
548 cvmmemctl
.s
.nomerge
= 0;
549 /* R/W Selects the bit in the counter used for DID time-outs 0
550 * = 231, 1 = 230, 2 = 229, 3 = 214. Actual time-out is
551 * between 1x and 2x this interval. For example, with
552 * DIDTTO=3, expiration interval is between 16K and 32K. */
553 cvmmemctl
.s
.didtto
= 0;
554 /* R/W If set, the (mem) CSR clock never turns off. */
555 cvmmemctl
.s
.csrckalwys
= 0;
556 /* R/W If set, mclk never turns off. */
557 cvmmemctl
.s
.mclkalwys
= 0;
558 /* R/W Selects the bit in the counter used for write buffer
559 * flush time-outs (WBFLT+11) is the bit position in an
560 * internal counter used to determine expiration. The write
561 * buffer expires between 1x and 2x this interval. For
562 * example, with WBFLT = 0, a write buffer expires between 2K
563 * and 4K cycles after the write buffer entry is allocated. */
564 cvmmemctl
.s
.wbfltime
= 0;
565 /* R/W If set, do not put Istream in the L2 cache. */
566 cvmmemctl
.s
.istrnol2
= 0;
569 * R/W The write buffer threshold. As per erratum Core-14752
570 * for CN63XX, a sc/scd might fail if the write buffer is
571 * full. Lowering WBTHRESH greatly lowers the chances of the
572 * write buffer ever being full and triggering the erratum.
574 if (OCTEON_IS_MODEL(OCTEON_CN63XX_PASS1_X
))
575 cvmmemctl
.s
.wbthresh
= 4;
577 cvmmemctl
.s
.wbthresh
= 10;
579 /* R/W If set, CVMSEG is available for loads/stores in
580 * kernel/debug mode. */
581 #if CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE > 0
582 cvmmemctl
.s
.cvmsegenak
= 1;
584 cvmmemctl
.s
.cvmsegenak
= 0;
586 /* R/W If set, CVMSEG is available for loads/stores in
587 * supervisor mode. */
588 cvmmemctl
.s
.cvmsegenas
= 0;
589 /* R/W If set, CVMSEG is available for loads/stores in user
591 cvmmemctl
.s
.cvmsegenau
= 0;
592 /* R/W Size of local memory in cache blocks, 54 (6912 bytes)
593 * is max legal value. */
594 cvmmemctl
.s
.lmemsz
= CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE
;
596 write_c0_cvmmemctl(cvmmemctl
.u64
);
598 if (smp_processor_id() == 0)
599 pr_notice("CVMSEG size: %d cache lines (%d bytes)\n",
600 CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE
,
601 CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE
* 128);
603 /* Set a default for the hardware timeouts */
605 fau_timeout
.s
.tout_val
= 0xfff;
606 /* Disable tagwait FAU timeout */
607 fau_timeout
.s
.tout_enb
= 0;
608 cvmx_write_csr(CVMX_IOB_FAU_TIMEOUT
, fau_timeout
.u64
);
613 cvmx_write_csr(CVMX_POW_NW_TIM
, nm_tim
.u64
);
615 write_octeon_c0_icacheerr(0);
616 write_c0_derraddr1(0);
620 * Early entry point for arch setup
622 void __init
prom_init(void)
624 struct cvmx_sysinfo
*sysinfo
;
629 #ifdef CONFIG_CAVIUM_RESERVE32
633 * The bootloader passes a pointer to the boot descriptor in
634 * $a3, this is available as fw_arg3.
636 octeon_boot_desc_ptr
= (struct octeon_boot_descriptor
*)fw_arg3
;
638 cvmx_phys_to_ptr(octeon_boot_desc_ptr
->cvmx_desc_vaddr
);
639 cvmx_bootmem_init(cvmx_phys_to_ptr(octeon_bootinfo
->phy_mem_desc_addr
));
641 sysinfo
= cvmx_sysinfo_get();
642 memset(sysinfo
, 0, sizeof(*sysinfo
));
643 sysinfo
->system_dram_size
= octeon_bootinfo
->dram_size
<< 20;
644 sysinfo
->phy_mem_desc_ptr
=
645 cvmx_phys_to_ptr(octeon_bootinfo
->phy_mem_desc_addr
);
646 sysinfo
->core_mask
= octeon_bootinfo
->core_mask
;
647 sysinfo
->exception_base_addr
= octeon_bootinfo
->exception_base_addr
;
648 sysinfo
->cpu_clock_hz
= octeon_bootinfo
->eclock_hz
;
649 sysinfo
->dram_data_rate_hz
= octeon_bootinfo
->dclock_hz
* 2;
650 sysinfo
->board_type
= octeon_bootinfo
->board_type
;
651 sysinfo
->board_rev_major
= octeon_bootinfo
->board_rev_major
;
652 sysinfo
->board_rev_minor
= octeon_bootinfo
->board_rev_minor
;
653 memcpy(sysinfo
->mac_addr_base
, octeon_bootinfo
->mac_addr_base
,
654 sizeof(sysinfo
->mac_addr_base
));
655 sysinfo
->mac_addr_count
= octeon_bootinfo
->mac_addr_count
;
656 memcpy(sysinfo
->board_serial_number
,
657 octeon_bootinfo
->board_serial_number
,
658 sizeof(sysinfo
->board_serial_number
));
659 sysinfo
->compact_flash_common_base_addr
=
660 octeon_bootinfo
->compact_flash_common_base_addr
;
661 sysinfo
->compact_flash_attribute_base_addr
=
662 octeon_bootinfo
->compact_flash_attribute_base_addr
;
663 sysinfo
->led_display_base_addr
= octeon_bootinfo
->led_display_base_addr
;
664 sysinfo
->dfa_ref_clock_hz
= octeon_bootinfo
->dfa_ref_clock_hz
;
665 sysinfo
->bootloader_config_flags
= octeon_bootinfo
->config_flags
;
667 if (OCTEON_IS_MODEL(OCTEON_CN6XXX
)) {
668 /* I/O clock runs at a different rate than the CPU. */
669 union cvmx_mio_rst_boot rst_boot
;
670 rst_boot
.u64
= cvmx_read_csr(CVMX_MIO_RST_BOOT
);
671 octeon_io_clock_rate
= 50000000 * rst_boot
.s
.pnr_mul
;
673 octeon_io_clock_rate
= sysinfo
->cpu_clock_hz
;
677 * Only enable the LED controller if we're running on a CN38XX, CN58XX,
678 * or CN56XX. The CN30XX and CN31XX don't have an LED controller.
680 if (!octeon_is_simulation() &&
681 octeon_has_feature(OCTEON_FEATURE_LED_CONTROLLER
)) {
682 cvmx_write_csr(CVMX_LED_EN
, 0);
683 cvmx_write_csr(CVMX_LED_PRT
, 0);
684 cvmx_write_csr(CVMX_LED_DBG
, 0);
685 cvmx_write_csr(CVMX_LED_PRT_FMT
, 0);
686 cvmx_write_csr(CVMX_LED_UDD_CNTX(0), 32);
687 cvmx_write_csr(CVMX_LED_UDD_CNTX(1), 32);
688 cvmx_write_csr(CVMX_LED_UDD_DATX(0), 0);
689 cvmx_write_csr(CVMX_LED_UDD_DATX(1), 0);
690 cvmx_write_csr(CVMX_LED_EN
, 1);
692 #ifdef CONFIG_CAVIUM_RESERVE32
694 * We need to temporarily allocate all memory in the reserve32
695 * region. This makes sure the kernel doesn't allocate this
696 * memory when it is getting memory from the
697 * bootloader. Later, after the memory allocations are
698 * complete, the reserve32 will be freed.
700 * Allocate memory for RESERVED32 aligned on 2MB boundary. This
701 * is in case we later use hugetlb entries with it.
703 addr
= cvmx_bootmem_phy_named_block_alloc(CONFIG_CAVIUM_RESERVE32
<< 20,
705 "CAVIUM_RESERVE32", 0);
707 pr_err("Failed to allocate CAVIUM_RESERVE32 memory area\n");
709 octeon_reserve32_memory
= addr
;
712 #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2
713 if (cvmx_read_csr(CVMX_L2D_FUS3
) & (3ull << 34)) {
714 pr_info("Skipping L2 locking due to reduced L2 cache size\n");
716 uint32_t __maybe_unused ebase
= read_c0_ebase() & 0x3ffff000;
717 #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_TLB
719 cvmx_l2c_lock_mem_region(ebase
, 0x100);
721 #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_EXCEPTION
722 /* General exception */
723 cvmx_l2c_lock_mem_region(ebase
+ 0x180, 0x80);
725 #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_LOW_LEVEL_INTERRUPT
726 /* Interrupt handler */
727 cvmx_l2c_lock_mem_region(ebase
+ 0x200, 0x80);
729 #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_INTERRUPT
730 cvmx_l2c_lock_mem_region(__pa_symbol(handle_int
), 0x100);
731 cvmx_l2c_lock_mem_region(__pa_symbol(plat_irq_dispatch
), 0x80);
733 #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_MEMCPY
734 cvmx_l2c_lock_mem_region(__pa_symbol(memcpy
), 0x480);
739 octeon_check_cpu_bist();
741 octeon_uart
= octeon_get_boot_uart();
744 octeon_write_lcd("LinuxSMP");
746 octeon_write_lcd("Linux");
749 #ifdef CONFIG_CAVIUM_GDB
751 * When debugging the linux kernel, force the cores to enter
752 * the debug exception handler to break in.
754 if (octeon_get_boot_debug_flag()) {
755 cvmx_write_csr(CVMX_CIU_DINT
, 1 << cvmx_get_core_num());
756 cvmx_read_csr(CVMX_CIU_DINT
);
760 octeon_setup_delays();
763 * BIST should always be enabled when doing a soft reset. L2
764 * Cache locking for instance is not cleared unless BIST is
765 * enabled. Unfortunately due to a chip errata G-200 for
766 * Cn38XX and CN31XX, BIST msut be disabled on these parts.
768 if (OCTEON_IS_MODEL(OCTEON_CN38XX_PASS2
) ||
769 OCTEON_IS_MODEL(OCTEON_CN31XX
))
770 cvmx_write_csr(CVMX_CIU_SOFT_BIST
, 0);
772 cvmx_write_csr(CVMX_CIU_SOFT_BIST
, 1);
774 /* Default to 64MB in the simulator to speed things up */
775 if (octeon_is_simulation())
776 MAX_MEMORY
= 64ull << 20;
778 arg
= strstr(arcs_cmdline
, "mem=");
780 MAX_MEMORY
= memparse(arg
+ 4, &p
);
782 MAX_MEMORY
= 32ull << 30;
784 RESERVE_LOW_MEM
= memparse(p
+ 1, &p
);
788 argc
= octeon_boot_desc_ptr
->argc
;
789 for (i
= 0; i
< argc
; i
++) {
791 cvmx_phys_to_ptr(octeon_boot_desc_ptr
->argv
[i
]);
792 if ((strncmp(arg
, "MEM=", 4) == 0) ||
793 (strncmp(arg
, "mem=", 4) == 0)) {
794 MAX_MEMORY
= memparse(arg
+ 4, &p
);
796 MAX_MEMORY
= 32ull << 30;
798 RESERVE_LOW_MEM
= memparse(p
+ 1, &p
);
799 } else if (strcmp(arg
, "ecc_verbose") == 0) {
800 #ifdef CONFIG_CAVIUM_REPORT_SINGLE_BIT_ECC
801 __cvmx_interrupt_ecc_report_single_bit_errors
= 1;
802 pr_notice("Reporting of single bit ECC errors is "
806 } else if (strncmp(arg
, "crashkernel=", 12) == 0) {
807 crashk_size
= memparse(arg
+12, &p
);
809 crashk_base
= memparse(p
+1, &p
);
810 strcat(arcs_cmdline
, " ");
811 strcat(arcs_cmdline
, arg
);
813 * To do: switch parsing to new style, something like:
814 * parse_crashkernel(arg, sysinfo->system_dram_size,
815 * &crashk_size, &crashk_base);
818 } else if (strlen(arcs_cmdline
) + strlen(arg
) + 1 <
819 sizeof(arcs_cmdline
) - 1) {
820 strcat(arcs_cmdline
, " ");
821 strcat(arcs_cmdline
, arg
);
825 if (strstr(arcs_cmdline
, "console=") == NULL
) {
826 #ifdef CONFIG_CAVIUM_OCTEON_2ND_KERNEL
827 strcat(arcs_cmdline
, " console=ttyS0,115200");
829 if (octeon_uart
== 1)
830 strcat(arcs_cmdline
, " console=ttyS1,115200");
832 strcat(arcs_cmdline
, " console=ttyS0,115200");
836 if (octeon_is_simulation()) {
838 * The simulator uses a mtdram device pre filled with
839 * the filesystem. Also specify the calibration delay
840 * to avoid calculating it every time.
842 strcat(arcs_cmdline
, " rw root=1f00 slram=root,0x40000000,+1073741824");
845 mips_hpt_frequency
= octeon_get_clock_rate();
847 octeon_init_cvmcount();
849 _machine_restart
= octeon_restart
;
850 _machine_halt
= octeon_halt
;
853 _machine_kexec_shutdown
= octeon_shutdown
;
854 _machine_crash_shutdown
= octeon_crash_shutdown
;
855 _machine_kexec_prepare
= octeon_kexec_prepare
;
858 octeon_user_io_init();
859 register_smp_ops(&octeon_smp_ops
);
862 /* Exclude a single page from the regions obtained in plat_mem_setup. */
863 #ifndef CONFIG_CRASH_DUMP
864 static __init
void memory_exclude_page(u64 addr
, u64
*mem
, u64
*size
)
866 if (addr
> *mem
&& addr
< *mem
+ *size
) {
867 u64 inc
= addr
- *mem
;
868 add_memory_region(*mem
, inc
, BOOT_MEM_RAM
);
873 if (addr
== *mem
&& *size
> PAGE_SIZE
) {
878 #endif /* CONFIG_CRASH_DUMP */
880 void __init
plat_mem_setup(void)
882 uint64_t mem_alloc_size
;
885 #ifndef CONFIG_CRASH_DUMP
887 uint64_t kernel_start
;
888 uint64_t kernel_size
;
895 * The Mips memory init uses the first memory location for
896 * some memory vectors. When SPARSEMEM is in use, it doesn't
897 * verify that the size is big enough for the final
898 * vectors. Making the smallest chuck 4MB seems to be enough
899 * to consistently work.
901 mem_alloc_size
= 4 << 20;
902 if (mem_alloc_size
> MAX_MEMORY
)
903 mem_alloc_size
= MAX_MEMORY
;
905 /* Crashkernel ignores bootmem list. It relies on mem=X@Y option */
906 #ifdef CONFIG_CRASH_DUMP
907 add_memory_region(RESERVE_LOW_MEM
, MAX_MEMORY
, BOOT_MEM_RAM
);
911 if (crashk_size
> 0) {
912 add_memory_region(crashk_base
, crashk_size
, BOOT_MEM_RAM
);
913 crashk_end
= crashk_base
+ crashk_size
;
917 * When allocating memory, we want incrementing addresses from
918 * bootmem_alloc so the code in add_memory_region can merge
919 * regions next to each other.
922 while ((boot_mem_map
.nr_map
< BOOT_MEM_MAP_MAX
)
923 && (total
< MAX_MEMORY
)) {
924 memory
= cvmx_bootmem_phy_alloc(mem_alloc_size
,
925 __pa_symbol(&__init_end
), -1,
927 CVMX_BOOTMEM_FLAG_NO_LOCKING
);
929 u64 size
= mem_alloc_size
;
935 * exclude a page at the beginning and end of
936 * the 256MB PCIe 'hole' so the kernel will not
937 * try to allocate multi-page buffers that
938 * span the discontinuity.
940 memory_exclude_page(CVMX_PCIE_BAR1_PHYS_BASE
,
942 memory_exclude_page(CVMX_PCIE_BAR1_PHYS_BASE
+
943 CVMX_PCIE_BAR1_PHYS_SIZE
,
946 end
= memory
+ mem_alloc_size
;
949 * This function automatically merges address regions
950 * next to each other if they are received in
953 if (memory
< crashk_base
&& end
> crashk_end
) {
954 /* region is fully in */
955 add_memory_region(memory
,
956 crashk_base
- memory
,
958 total
+= crashk_base
- memory
;
959 add_memory_region(crashk_end
,
962 total
+= end
- crashk_end
;
966 if (memory
>= crashk_base
&& end
<= crashk_end
)
968 * Entire memory region is within the new
969 * kernel's memory, ignore it.
973 if (memory
> crashk_base
&& memory
< crashk_end
&&
976 * Overlap with the beginning of the region,
977 * reserve the beginning.
979 mem_alloc_size
-= crashk_end
- memory
;
981 } else if (memory
< crashk_base
&& end
> crashk_base
&&
984 * Overlap with the beginning of the region,
987 mem_alloc_size
-= end
- crashk_base
;
989 add_memory_region(memory
, mem_alloc_size
, BOOT_MEM_RAM
);
990 total
+= mem_alloc_size
;
991 /* Recovering mem_alloc_size */
992 mem_alloc_size
= 4 << 20;
997 cvmx_bootmem_unlock();
998 /* Add the memory region for the kernel. */
999 kernel_start
= (unsigned long) _text
;
1000 kernel_size
= _end
- _text
;
1002 /* Adjust for physical offset. */
1003 kernel_start
&= ~0xffffffff80000000ULL
;
1004 add_memory_region(kernel_start
, kernel_size
, BOOT_MEM_RAM
);
1005 #endif /* CONFIG_CRASH_DUMP */
1007 #ifdef CONFIG_CAVIUM_RESERVE32
1009 * Now that we've allocated the kernel memory it is safe to
1010 * free the reserved region. We free it here so that builtin
1011 * drivers can use the memory.
1013 if (octeon_reserve32_memory
)
1014 cvmx_bootmem_free_named("CAVIUM_RESERVE32");
1015 #endif /* CONFIG_CAVIUM_RESERVE32 */
1018 panic("Unable to allocate memory from "
1019 "cvmx_bootmem_phy_alloc\n");
1023 * Emit one character to the boot UART. Exported for use by the
1026 int prom_putchar(char c
)
1030 /* Spin until there is room */
1032 lsrval
= cvmx_read_csr(CVMX_MIO_UARTX_LSR(octeon_uart
));
1033 } while ((lsrval
& 0x20) == 0);
1035 /* Write the byte */
1036 cvmx_write_csr(CVMX_MIO_UARTX_THR(octeon_uart
), c
& 0xffull
);
1039 EXPORT_SYMBOL(prom_putchar
);
1041 void prom_free_prom_memory(void)
1043 if (OCTEON_IS_MODEL(OCTEON_CN63XX_PASS1_X
)) {
1044 /* Check for presence of Core-14449 fix. */
1050 asm volatile("# before" : : : "memory");
1054 ".set noreorder\n\t"
1057 "1:\tlw %0,-12($31)\n\t"
1059 : "=r" (insn
) : : "$31", "memory");
1061 if ((insn
>> 26) != 0x33)
1062 panic("No PREF instruction at Core-14449 probe point.");
1064 if (((insn
>> 16) & 0x1f) != 28)
1065 panic("Core-14449 WAR not in place (%04x).\n"
1066 "Please build kernel with proper options (CONFIG_CAVIUM_CN63XXP1).", insn
);
1068 #ifdef CONFIG_CAVIUM_DECODE_RSL
1069 cvmx_interrupt_rsl_enable();
1071 /* Add an interrupt handler for general failures. */
1072 if (request_irq(OCTEON_IRQ_RML
, octeon_rlm_interrupt
, IRQF_SHARED
,
1073 "RML/RSL", octeon_rlm_interrupt
)) {
1074 panic("Unable to request_irq(OCTEON_IRQ_RML)");
1079 int octeon_prune_device_tree(void);
1081 extern const char __dtb_octeon_3xxx_begin
;
1082 extern const char __dtb_octeon_3xxx_end
;
1083 extern const char __dtb_octeon_68xx_begin
;
1084 extern const char __dtb_octeon_68xx_end
;
1085 void __init
device_tree_init(void)
1088 struct boot_param_header
*fdt
;
1091 if (octeon_bootinfo
->minor_version
>= 3 && octeon_bootinfo
->fdt_addr
) {
1092 fdt
= phys_to_virt(octeon_bootinfo
->fdt_addr
);
1093 if (fdt_check_header(fdt
))
1094 panic("Corrupt Device Tree passed to kernel.");
1095 dt_size
= be32_to_cpu(fdt
->totalsize
);
1097 } else if (OCTEON_IS_MODEL(OCTEON_CN68XX
)) {
1098 fdt
= (struct boot_param_header
*)&__dtb_octeon_68xx_begin
;
1099 dt_size
= &__dtb_octeon_68xx_end
- &__dtb_octeon_68xx_begin
;
1102 fdt
= (struct boot_param_header
*)&__dtb_octeon_3xxx_begin
;
1103 dt_size
= &__dtb_octeon_3xxx_end
- &__dtb_octeon_3xxx_begin
;
1107 /* Copy the default tree from init memory. */
1108 initial_boot_params
= early_init_dt_alloc_memory_arch(dt_size
, 8);
1109 if (initial_boot_params
== NULL
)
1110 panic("Could not allocate initial_boot_params\n");
1111 memcpy(initial_boot_params
, fdt
, dt_size
);
1114 octeon_prune_device_tree();
1115 pr_info("Using internal Device Tree.\n");
1117 pr_info("Using passed Device Tree.\n");
1119 unflatten_device_tree();
1122 static int __initdata disable_octeon_edac_p
;
1124 static int __init
disable_octeon_edac(char *str
)
1126 disable_octeon_edac_p
= 1;
1129 early_param("disable_octeon_edac", disable_octeon_edac
);
1131 static char *edac_device_names
[] = {
1136 static int __init
edac_devinit(void)
1138 struct platform_device
*dev
;
1143 if (disable_octeon_edac_p
)
1146 for (i
= 0; i
< ARRAY_SIZE(edac_device_names
); i
++) {
1147 name
= edac_device_names
[i
];
1148 dev
= platform_device_register_simple(name
, -1, NULL
, 0);
1150 pr_err("Registation of %s failed!\n", name
);
1155 num_lmc
= OCTEON_IS_MODEL(OCTEON_CN68XX
) ? 4 :
1156 (OCTEON_IS_MODEL(OCTEON_CN56XX
) ? 2 : 1);
1157 for (i
= 0; i
< num_lmc
; i
++) {
1158 dev
= platform_device_register_simple("octeon_lmc_edac",
1161 pr_err("Registation of octeon_lmc_edac %d failed!\n", i
);
1168 device_initcall(edac_devinit
);