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 Wind River Systems
9 #include <linux/init.h>
10 #include <linux/console.h>
11 #include <linux/delay.h>
12 #include <linux/export.h>
13 #include <linux/interrupt.h>
15 #include <linux/serial.h>
16 #include <linux/smp.h>
17 #include <linux/types.h>
18 #include <linux/string.h> /* for memset */
19 #include <linux/tty.h>
20 #include <linux/time.h>
21 #include <linux/platform_device.h>
22 #include <linux/serial_core.h>
23 #include <linux/serial_8250.h>
24 #include <linux/of_fdt.h>
25 #include <linux/libfdt.h>
27 #include <asm/processor.h>
28 #include <asm/reboot.h>
29 #include <asm/smp-ops.h>
30 #include <asm/irq_cpu.h>
31 #include <asm/mipsregs.h>
32 #include <asm/bootinfo.h>
33 #include <asm/sections.h>
36 #include <asm/octeon/octeon.h>
37 #include <asm/octeon/pci-octeon.h>
38 #include <asm/octeon/cvmx-mio-defs.h>
40 #ifdef CONFIG_CAVIUM_DECODE_RSL
41 extern void cvmx_interrupt_rsl_decode(void);
42 extern int __cvmx_interrupt_ecc_report_single_bit_errors
;
43 extern void cvmx_interrupt_rsl_enable(void);
46 extern struct plat_smp_ops octeon_smp_ops
;
49 extern void pci_console_init(const char *arg
);
52 static unsigned long long MAX_MEMORY
= 512ull << 20;
54 struct octeon_boot_descriptor
*octeon_boot_desc_ptr
;
56 struct cvmx_bootinfo
*octeon_bootinfo
;
57 EXPORT_SYMBOL(octeon_bootinfo
);
59 #ifdef CONFIG_CAVIUM_RESERVE32
60 uint64_t octeon_reserve32_memory
;
61 EXPORT_SYMBOL(octeon_reserve32_memory
);
64 static int octeon_uart
;
66 extern asmlinkage
void handle_int(void);
67 extern asmlinkage
void plat_irq_dispatch(void);
70 * Return non zero if we are currently running in the Octeon simulator
74 int octeon_is_simulation(void)
76 return octeon_bootinfo
->board_type
== CVMX_BOARD_TYPE_SIM
;
78 EXPORT_SYMBOL(octeon_is_simulation
);
81 * Return true if Octeon is in PCI Host mode. This means
82 * Linux can control the PCI bus.
84 * Returns Non zero if Octeon in host mode.
86 int octeon_is_pci_host(void)
89 return octeon_bootinfo
->config_flags
& CVMX_BOOTINFO_CFG_FLAG_PCI_HOST
;
96 * Get the clock rate of Octeon
98 * Returns Clock rate in HZ
100 uint64_t octeon_get_clock_rate(void)
102 struct cvmx_sysinfo
*sysinfo
= cvmx_sysinfo_get();
104 return sysinfo
->cpu_clock_hz
;
106 EXPORT_SYMBOL(octeon_get_clock_rate
);
108 static u64 octeon_io_clock_rate
;
110 u64
octeon_get_io_clock_rate(void)
112 return octeon_io_clock_rate
;
114 EXPORT_SYMBOL(octeon_get_io_clock_rate
);
118 * Write to the LCD display connected to the bootbus. This display
119 * exists on most Cavium evaluation boards. If it doesn't exist, then
120 * this function doesn't do anything.
122 * @s: String to write
124 void octeon_write_lcd(const char *s
)
126 if (octeon_bootinfo
->led_display_base_addr
) {
127 void __iomem
*lcd_address
=
128 ioremap_nocache(octeon_bootinfo
->led_display_base_addr
,
131 for (i
= 0; i
< 8; i
++, s
++) {
133 iowrite8(*s
, lcd_address
+ i
);
135 iowrite8(' ', lcd_address
+ i
);
137 iounmap(lcd_address
);
142 * Return the console uart passed by the bootloader
144 * Returns uart (0 or 1)
146 int octeon_get_boot_uart(void)
149 #ifdef CONFIG_CAVIUM_OCTEON_2ND_KERNEL
152 uart
= (octeon_boot_desc_ptr
->flags
& OCTEON_BL_FLAG_CONSOLE_UART1
) ?
159 * Get the coremask Linux was booted on.
163 int octeon_get_boot_coremask(void)
165 return octeon_boot_desc_ptr
->core_mask
;
169 * Check the hardware BIST results for a CPU
171 void octeon_check_cpu_bist(void)
173 const int coreid
= cvmx_get_core_num();
174 unsigned long long mask
;
175 unsigned long long bist_val
;
177 /* Check BIST results for COP0 registers */
178 mask
= 0x1f00000000ull
;
179 bist_val
= read_octeon_c0_icacheerr();
181 pr_err("Core%d BIST Failure: CacheErr(icache) = 0x%llx\n",
184 bist_val
= read_octeon_c0_dcacheerr();
186 pr_err("Core%d L1 Dcache parity error: "
187 "CacheErr(dcache) = 0x%llx\n",
190 mask
= 0xfc00000000000000ull
;
191 bist_val
= read_c0_cvmmemctl();
193 pr_err("Core%d BIST Failure: COP0_CVM_MEM_CTL = 0x%llx\n",
196 write_octeon_c0_dcacheerr(0);
202 * @command: Command to pass to the bootloader. Currently ignored.
204 static void octeon_restart(char *command
)
206 /* Disable all watchdogs before soft reset. They don't get cleared */
209 for_each_online_cpu(cpu
)
210 cvmx_write_csr(CVMX_CIU_WDOGX(cpu_logical_map(cpu
)), 0);
212 cvmx_write_csr(CVMX_CIU_WDOGX(cvmx_get_core_num()), 0);
217 cvmx_write_csr(CVMX_CIU_SOFT_RST
, 1);
222 * Permanently stop a core.
226 static void octeon_kill_core(void *arg
)
229 if (octeon_is_simulation()) {
230 /* The simulator needs the watchdog to stop for dead cores */
231 cvmx_write_csr(CVMX_CIU_WDOGX(cvmx_get_core_num()), 0);
232 /* A break instruction causes the simulator stop a core */
233 asm volatile ("sync\nbreak");
241 static void octeon_halt(void)
243 smp_call_function(octeon_kill_core
, NULL
, 0);
245 switch (octeon_bootinfo
->board_type
) {
246 case CVMX_BOARD_TYPE_NAO38
:
247 /* Driving a 1 to GPIO 12 shuts off this board */
248 cvmx_write_csr(CVMX_GPIO_BIT_CFGX(12), 1);
249 cvmx_write_csr(CVMX_GPIO_TX_SET
, 0x1000);
252 octeon_write_lcd("PowerOff");
256 octeon_kill_core(NULL
);
260 * Handle all the error condition interrupts that might occur.
263 #ifdef CONFIG_CAVIUM_DECODE_RSL
264 static irqreturn_t
octeon_rlm_interrupt(int cpl
, void *dev_id
)
266 cvmx_interrupt_rsl_decode();
272 * Return a string representing the system type
276 const char *octeon_board_type_string(void)
278 static char name
[80];
279 sprintf(name
, "%s (%s)",
280 cvmx_board_type_to_string(octeon_bootinfo
->board_type
),
281 octeon_model_get_string(read_c0_prid()));
285 const char *get_system_type(void)
286 __attribute__ ((alias("octeon_board_type_string")));
288 void octeon_user_io_init(void)
290 union octeon_cvmemctl cvmmemctl
;
291 union cvmx_iob_fau_timeout fau_timeout
;
292 union cvmx_pow_nw_tim nm_tim
;
294 /* Get the current settings for CP0_CVMMEMCTL_REG */
295 cvmmemctl
.u64
= read_c0_cvmmemctl();
296 /* R/W If set, marked write-buffer entries time out the same
297 * as as other entries; if clear, marked write-buffer entries
298 * use the maximum timeout. */
299 cvmmemctl
.s
.dismarkwblongto
= 1;
300 /* R/W If set, a merged store does not clear the write-buffer
301 * entry timeout state. */
302 cvmmemctl
.s
.dismrgclrwbto
= 0;
303 /* R/W Two bits that are the MSBs of the resultant CVMSEG LM
304 * word location for an IOBDMA. The other 8 bits come from the
305 * SCRADDR field of the IOBDMA. */
306 cvmmemctl
.s
.iobdmascrmsb
= 0;
307 /* R/W If set, SYNCWS and SYNCS only order marked stores; if
308 * clear, SYNCWS and SYNCS only order unmarked
309 * stores. SYNCWSMARKED has no effect when DISSYNCWS is
311 cvmmemctl
.s
.syncwsmarked
= 0;
312 /* R/W If set, SYNCWS acts as SYNCW and SYNCS acts as SYNC. */
313 cvmmemctl
.s
.dissyncws
= 0;
314 /* R/W If set, no stall happens on write buffer full. */
315 if (OCTEON_IS_MODEL(OCTEON_CN38XX_PASS2
))
316 cvmmemctl
.s
.diswbfst
= 1;
318 cvmmemctl
.s
.diswbfst
= 0;
319 /* R/W If set (and SX set), supervisor-level loads/stores can
320 * use XKPHYS addresses with <48>==0 */
321 cvmmemctl
.s
.xkmemenas
= 0;
323 /* R/W If set (and UX set), user-level loads/stores can use
324 * XKPHYS addresses with VA<48>==0 */
325 cvmmemctl
.s
.xkmemenau
= 0;
327 /* R/W If set (and SX set), supervisor-level loads/stores can
328 * use XKPHYS addresses with VA<48>==1 */
329 cvmmemctl
.s
.xkioenas
= 0;
331 /* R/W If set (and UX set), user-level loads/stores can use
332 * XKPHYS addresses with VA<48>==1 */
333 cvmmemctl
.s
.xkioenau
= 0;
335 /* R/W If set, all stores act as SYNCW (NOMERGE must be set
336 * when this is set) RW, reset to 0. */
337 cvmmemctl
.s
.allsyncw
= 0;
339 /* R/W If set, no stores merge, and all stores reach the
340 * coherent bus in order. */
341 cvmmemctl
.s
.nomerge
= 0;
342 /* R/W Selects the bit in the counter used for DID time-outs 0
343 * = 231, 1 = 230, 2 = 229, 3 = 214. Actual time-out is
344 * between 1x and 2x this interval. For example, with
345 * DIDTTO=3, expiration interval is between 16K and 32K. */
346 cvmmemctl
.s
.didtto
= 0;
347 /* R/W If set, the (mem) CSR clock never turns off. */
348 cvmmemctl
.s
.csrckalwys
= 0;
349 /* R/W If set, mclk never turns off. */
350 cvmmemctl
.s
.mclkalwys
= 0;
351 /* R/W Selects the bit in the counter used for write buffer
352 * flush time-outs (WBFLT+11) is the bit position in an
353 * internal counter used to determine expiration. The write
354 * buffer expires between 1x and 2x this interval. For
355 * example, with WBFLT = 0, a write buffer expires between 2K
356 * and 4K cycles after the write buffer entry is allocated. */
357 cvmmemctl
.s
.wbfltime
= 0;
358 /* R/W If set, do not put Istream in the L2 cache. */
359 cvmmemctl
.s
.istrnol2
= 0;
362 * R/W The write buffer threshold. As per erratum Core-14752
363 * for CN63XX, a sc/scd might fail if the write buffer is
364 * full. Lowering WBTHRESH greatly lowers the chances of the
365 * write buffer ever being full and triggering the erratum.
367 if (OCTEON_IS_MODEL(OCTEON_CN63XX_PASS1_X
))
368 cvmmemctl
.s
.wbthresh
= 4;
370 cvmmemctl
.s
.wbthresh
= 10;
372 /* R/W If set, CVMSEG is available for loads/stores in
373 * kernel/debug mode. */
374 #if CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE > 0
375 cvmmemctl
.s
.cvmsegenak
= 1;
377 cvmmemctl
.s
.cvmsegenak
= 0;
379 /* R/W If set, CVMSEG is available for loads/stores in
380 * supervisor mode. */
381 cvmmemctl
.s
.cvmsegenas
= 0;
382 /* R/W If set, CVMSEG is available for loads/stores in user
384 cvmmemctl
.s
.cvmsegenau
= 0;
385 /* R/W Size of local memory in cache blocks, 54 (6912 bytes)
386 * is max legal value. */
387 cvmmemctl
.s
.lmemsz
= CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE
;
389 write_c0_cvmmemctl(cvmmemctl
.u64
);
391 if (smp_processor_id() == 0)
392 pr_notice("CVMSEG size: %d cache lines (%d bytes)\n",
393 CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE
,
394 CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE
* 128);
396 /* Set a default for the hardware timeouts */
398 fau_timeout
.s
.tout_val
= 0xfff;
399 /* Disable tagwait FAU timeout */
400 fau_timeout
.s
.tout_enb
= 0;
401 cvmx_write_csr(CVMX_IOB_FAU_TIMEOUT
, fau_timeout
.u64
);
406 cvmx_write_csr(CVMX_POW_NW_TIM
, nm_tim
.u64
);
408 write_octeon_c0_icacheerr(0);
409 write_c0_derraddr1(0);
413 * Early entry point for arch setup
415 void __init
prom_init(void)
417 struct cvmx_sysinfo
*sysinfo
;
420 #ifdef CONFIG_CAVIUM_RESERVE32
424 * The bootloader passes a pointer to the boot descriptor in
425 * $a3, this is available as fw_arg3.
427 octeon_boot_desc_ptr
= (struct octeon_boot_descriptor
*)fw_arg3
;
429 cvmx_phys_to_ptr(octeon_boot_desc_ptr
->cvmx_desc_vaddr
);
430 cvmx_bootmem_init(cvmx_phys_to_ptr(octeon_bootinfo
->phy_mem_desc_addr
));
432 sysinfo
= cvmx_sysinfo_get();
433 memset(sysinfo
, 0, sizeof(*sysinfo
));
434 sysinfo
->system_dram_size
= octeon_bootinfo
->dram_size
<< 20;
435 sysinfo
->phy_mem_desc_ptr
=
436 cvmx_phys_to_ptr(octeon_bootinfo
->phy_mem_desc_addr
);
437 sysinfo
->core_mask
= octeon_bootinfo
->core_mask
;
438 sysinfo
->exception_base_addr
= octeon_bootinfo
->exception_base_addr
;
439 sysinfo
->cpu_clock_hz
= octeon_bootinfo
->eclock_hz
;
440 sysinfo
->dram_data_rate_hz
= octeon_bootinfo
->dclock_hz
* 2;
441 sysinfo
->board_type
= octeon_bootinfo
->board_type
;
442 sysinfo
->board_rev_major
= octeon_bootinfo
->board_rev_major
;
443 sysinfo
->board_rev_minor
= octeon_bootinfo
->board_rev_minor
;
444 memcpy(sysinfo
->mac_addr_base
, octeon_bootinfo
->mac_addr_base
,
445 sizeof(sysinfo
->mac_addr_base
));
446 sysinfo
->mac_addr_count
= octeon_bootinfo
->mac_addr_count
;
447 memcpy(sysinfo
->board_serial_number
,
448 octeon_bootinfo
->board_serial_number
,
449 sizeof(sysinfo
->board_serial_number
));
450 sysinfo
->compact_flash_common_base_addr
=
451 octeon_bootinfo
->compact_flash_common_base_addr
;
452 sysinfo
->compact_flash_attribute_base_addr
=
453 octeon_bootinfo
->compact_flash_attribute_base_addr
;
454 sysinfo
->led_display_base_addr
= octeon_bootinfo
->led_display_base_addr
;
455 sysinfo
->dfa_ref_clock_hz
= octeon_bootinfo
->dfa_ref_clock_hz
;
456 sysinfo
->bootloader_config_flags
= octeon_bootinfo
->config_flags
;
458 if (OCTEON_IS_MODEL(OCTEON_CN6XXX
)) {
459 /* I/O clock runs at a different rate than the CPU. */
460 union cvmx_mio_rst_boot rst_boot
;
461 rst_boot
.u64
= cvmx_read_csr(CVMX_MIO_RST_BOOT
);
462 octeon_io_clock_rate
= 50000000 * rst_boot
.s
.pnr_mul
;
464 octeon_io_clock_rate
= sysinfo
->cpu_clock_hz
;
468 * Only enable the LED controller if we're running on a CN38XX, CN58XX,
469 * or CN56XX. The CN30XX and CN31XX don't have an LED controller.
471 if (!octeon_is_simulation() &&
472 octeon_has_feature(OCTEON_FEATURE_LED_CONTROLLER
)) {
473 cvmx_write_csr(CVMX_LED_EN
, 0);
474 cvmx_write_csr(CVMX_LED_PRT
, 0);
475 cvmx_write_csr(CVMX_LED_DBG
, 0);
476 cvmx_write_csr(CVMX_LED_PRT_FMT
, 0);
477 cvmx_write_csr(CVMX_LED_UDD_CNTX(0), 32);
478 cvmx_write_csr(CVMX_LED_UDD_CNTX(1), 32);
479 cvmx_write_csr(CVMX_LED_UDD_DATX(0), 0);
480 cvmx_write_csr(CVMX_LED_UDD_DATX(1), 0);
481 cvmx_write_csr(CVMX_LED_EN
, 1);
483 #ifdef CONFIG_CAVIUM_RESERVE32
485 * We need to temporarily allocate all memory in the reserve32
486 * region. This makes sure the kernel doesn't allocate this
487 * memory when it is getting memory from the
488 * bootloader. Later, after the memory allocations are
489 * complete, the reserve32 will be freed.
491 * Allocate memory for RESERVED32 aligned on 2MB boundary. This
492 * is in case we later use hugetlb entries with it.
494 addr
= cvmx_bootmem_phy_named_block_alloc(CONFIG_CAVIUM_RESERVE32
<< 20,
496 "CAVIUM_RESERVE32", 0);
498 pr_err("Failed to allocate CAVIUM_RESERVE32 memory area\n");
500 octeon_reserve32_memory
= addr
;
503 #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2
504 if (cvmx_read_csr(CVMX_L2D_FUS3
) & (3ull << 34)) {
505 pr_info("Skipping L2 locking due to reduced L2 cache size\n");
507 uint32_t ebase
= read_c0_ebase() & 0x3ffff000;
508 #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_TLB
510 cvmx_l2c_lock_mem_region(ebase
, 0x100);
512 #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_EXCEPTION
513 /* General exception */
514 cvmx_l2c_lock_mem_region(ebase
+ 0x180, 0x80);
516 #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_LOW_LEVEL_INTERRUPT
517 /* Interrupt handler */
518 cvmx_l2c_lock_mem_region(ebase
+ 0x200, 0x80);
520 #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_INTERRUPT
521 cvmx_l2c_lock_mem_region(__pa_symbol(handle_int
), 0x100);
522 cvmx_l2c_lock_mem_region(__pa_symbol(plat_irq_dispatch
), 0x80);
524 #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_MEMCPY
525 cvmx_l2c_lock_mem_region(__pa_symbol(memcpy
), 0x480);
530 octeon_check_cpu_bist();
532 octeon_uart
= octeon_get_boot_uart();
535 octeon_write_lcd("LinuxSMP");
537 octeon_write_lcd("Linux");
540 #ifdef CONFIG_CAVIUM_GDB
542 * When debugging the linux kernel, force the cores to enter
543 * the debug exception handler to break in.
545 if (octeon_get_boot_debug_flag()) {
546 cvmx_write_csr(CVMX_CIU_DINT
, 1 << cvmx_get_core_num());
547 cvmx_read_csr(CVMX_CIU_DINT
);
552 * BIST should always be enabled when doing a soft reset. L2
553 * Cache locking for instance is not cleared unless BIST is
554 * enabled. Unfortunately due to a chip errata G-200 for
555 * Cn38XX and CN31XX, BIST msut be disabled on these parts.
557 if (OCTEON_IS_MODEL(OCTEON_CN38XX_PASS2
) ||
558 OCTEON_IS_MODEL(OCTEON_CN31XX
))
559 cvmx_write_csr(CVMX_CIU_SOFT_BIST
, 0);
561 cvmx_write_csr(CVMX_CIU_SOFT_BIST
, 1);
563 /* Default to 64MB in the simulator to speed things up */
564 if (octeon_is_simulation())
565 MAX_MEMORY
= 64ull << 20;
568 argc
= octeon_boot_desc_ptr
->argc
;
569 for (i
= 0; i
< argc
; i
++) {
571 cvmx_phys_to_ptr(octeon_boot_desc_ptr
->argv
[i
]);
572 if ((strncmp(arg
, "MEM=", 4) == 0) ||
573 (strncmp(arg
, "mem=", 4) == 0)) {
574 sscanf(arg
+ 4, "%llu", &MAX_MEMORY
);
577 MAX_MEMORY
= 32ull << 30;
578 } else if (strcmp(arg
, "ecc_verbose") == 0) {
579 #ifdef CONFIG_CAVIUM_REPORT_SINGLE_BIT_ECC
580 __cvmx_interrupt_ecc_report_single_bit_errors
= 1;
581 pr_notice("Reporting of single bit ECC errors is "
584 } else if (strlen(arcs_cmdline
) + strlen(arg
) + 1 <
585 sizeof(arcs_cmdline
) - 1) {
586 strcat(arcs_cmdline
, " ");
587 strcat(arcs_cmdline
, arg
);
591 if (strstr(arcs_cmdline
, "console=") == NULL
) {
592 #ifdef CONFIG_CAVIUM_OCTEON_2ND_KERNEL
593 strcat(arcs_cmdline
, " console=ttyS0,115200");
595 if (octeon_uart
== 1)
596 strcat(arcs_cmdline
, " console=ttyS1,115200");
598 strcat(arcs_cmdline
, " console=ttyS0,115200");
602 if (octeon_is_simulation()) {
604 * The simulator uses a mtdram device pre filled with
605 * the filesystem. Also specify the calibration delay
606 * to avoid calculating it every time.
608 strcat(arcs_cmdline
, " rw root=1f00 slram=root,0x40000000,+1073741824");
611 mips_hpt_frequency
= octeon_get_clock_rate();
613 octeon_init_cvmcount();
614 octeon_setup_delays();
616 _machine_restart
= octeon_restart
;
617 _machine_halt
= octeon_halt
;
619 octeon_user_io_init();
620 register_smp_ops(&octeon_smp_ops
);
623 /* Exclude a single page from the regions obtained in plat_mem_setup. */
624 static __init
void memory_exclude_page(u64 addr
, u64
*mem
, u64
*size
)
626 if (addr
> *mem
&& addr
< *mem
+ *size
) {
627 u64 inc
= addr
- *mem
;
628 add_memory_region(*mem
, inc
, BOOT_MEM_RAM
);
633 if (addr
== *mem
&& *size
> PAGE_SIZE
) {
639 void __init
plat_mem_setup(void)
641 uint64_t mem_alloc_size
;
648 * The Mips memory init uses the first memory location for
649 * some memory vectors. When SPARSEMEM is in use, it doesn't
650 * verify that the size is big enough for the final
651 * vectors. Making the smallest chuck 4MB seems to be enough
652 * to consistently work.
654 mem_alloc_size
= 4 << 20;
655 if (mem_alloc_size
> MAX_MEMORY
)
656 mem_alloc_size
= MAX_MEMORY
;
659 * When allocating memory, we want incrementing addresses from
660 * bootmem_alloc so the code in add_memory_region can merge
661 * regions next to each other.
664 while ((boot_mem_map
.nr_map
< BOOT_MEM_MAP_MAX
)
665 && (total
< MAX_MEMORY
)) {
666 #if defined(CONFIG_64BIT) || defined(CONFIG_64BIT_PHYS_ADDR)
667 memory
= cvmx_bootmem_phy_alloc(mem_alloc_size
,
668 __pa_symbol(&__init_end
), -1,
670 CVMX_BOOTMEM_FLAG_NO_LOCKING
);
671 #elif defined(CONFIG_HIGHMEM)
672 memory
= cvmx_bootmem_phy_alloc(mem_alloc_size
, 0, 1ull << 31,
674 CVMX_BOOTMEM_FLAG_NO_LOCKING
);
676 memory
= cvmx_bootmem_phy_alloc(mem_alloc_size
, 0, 512 << 20,
678 CVMX_BOOTMEM_FLAG_NO_LOCKING
);
681 u64 size
= mem_alloc_size
;
684 * exclude a page at the beginning and end of
685 * the 256MB PCIe 'hole' so the kernel will not
686 * try to allocate multi-page buffers that
687 * span the discontinuity.
689 memory_exclude_page(CVMX_PCIE_BAR1_PHYS_BASE
,
691 memory_exclude_page(CVMX_PCIE_BAR1_PHYS_BASE
+
692 CVMX_PCIE_BAR1_PHYS_SIZE
,
696 * This function automatically merges address
697 * regions next to each other if they are
698 * received in incrementing order.
701 add_memory_region(memory
, size
, BOOT_MEM_RAM
);
702 total
+= mem_alloc_size
;
707 cvmx_bootmem_unlock();
709 #ifdef CONFIG_CAVIUM_RESERVE32
711 * Now that we've allocated the kernel memory it is safe to
712 * free the reserved region. We free it here so that builtin
713 * drivers can use the memory.
715 if (octeon_reserve32_memory
)
716 cvmx_bootmem_free_named("CAVIUM_RESERVE32");
717 #endif /* CONFIG_CAVIUM_RESERVE32 */
720 panic("Unable to allocate memory from "
721 "cvmx_bootmem_phy_alloc\n");
725 * Emit one character to the boot UART. Exported for use by the
728 int prom_putchar(char c
)
732 /* Spin until there is room */
734 lsrval
= cvmx_read_csr(CVMX_MIO_UARTX_LSR(octeon_uart
));
735 } while ((lsrval
& 0x20) == 0);
738 cvmx_write_csr(CVMX_MIO_UARTX_THR(octeon_uart
), c
& 0xffull
);
741 EXPORT_SYMBOL(prom_putchar
);
743 void prom_free_prom_memory(void)
745 if (OCTEON_IS_MODEL(OCTEON_CN63XX_PASS1_X
)) {
746 /* Check for presence of Core-14449 fix. */
752 asm volatile("# before" : : : "memory");
759 "1:\tlw %0,-12($31)\n\t"
761 : "=r" (insn
) : : "$31", "memory");
763 if ((insn
>> 26) != 0x33)
764 panic("No PREF instruction at Core-14449 probe point.");
766 if (((insn
>> 16) & 0x1f) != 28)
767 panic("Core-14449 WAR not in place (%04x).\n"
768 "Please build kernel with proper options (CONFIG_CAVIUM_CN63XXP1).", insn
);
770 #ifdef CONFIG_CAVIUM_DECODE_RSL
771 cvmx_interrupt_rsl_enable();
773 /* Add an interrupt handler for general failures. */
774 if (request_irq(OCTEON_IRQ_RML
, octeon_rlm_interrupt
, IRQF_SHARED
,
775 "RML/RSL", octeon_rlm_interrupt
)) {
776 panic("Unable to request_irq(OCTEON_IRQ_RML)");
781 int octeon_prune_device_tree(void);
783 extern const char __dtb_octeon_3xxx_begin
;
784 extern const char __dtb_octeon_3xxx_end
;
785 extern const char __dtb_octeon_68xx_begin
;
786 extern const char __dtb_octeon_68xx_end
;
787 void __init
device_tree_init(void)
790 struct boot_param_header
*fdt
;
793 if (octeon_bootinfo
->minor_version
>= 3 && octeon_bootinfo
->fdt_addr
) {
794 fdt
= phys_to_virt(octeon_bootinfo
->fdt_addr
);
795 if (fdt_check_header(fdt
))
796 panic("Corrupt Device Tree passed to kernel.");
797 dt_size
= be32_to_cpu(fdt
->totalsize
);
799 } else if (OCTEON_IS_MODEL(OCTEON_CN68XX
)) {
800 fdt
= (struct boot_param_header
*)&__dtb_octeon_68xx_begin
;
801 dt_size
= &__dtb_octeon_68xx_end
- &__dtb_octeon_68xx_begin
;
804 fdt
= (struct boot_param_header
*)&__dtb_octeon_3xxx_begin
;
805 dt_size
= &__dtb_octeon_3xxx_end
- &__dtb_octeon_3xxx_begin
;
809 /* Copy the default tree from init memory. */
810 initial_boot_params
= early_init_dt_alloc_memory_arch(dt_size
, 8);
811 if (initial_boot_params
== NULL
)
812 panic("Could not allocate initial_boot_params\n");
813 memcpy(initial_boot_params
, fdt
, dt_size
);
816 octeon_prune_device_tree();
817 pr_info("Using internal Device Tree.\n");
819 pr_info("Using passed Device Tree.\n");
821 unflatten_device_tree();