/* * This file is subject to the terms and conditions of the GNU General Public * License. See the file "COPYING" in the main directory of this archive * for more details. * * Copyright (C) 2004-2007 Cavium Networks * Copyright (C) 2008, 2009 Wind River Systems * written by Ralf Baechle <ralf@linux-mips.org>
*/ #include <linux/compiler.h> #include <linux/vmalloc.h> #include <linux/init.h> #include <linux/kernel.h> #include <linux/console.h> #include <linux/delay.h> #include <linux/export.h> #include <linux/interrupt.h> #include <linux/io.h> #include <linux/memblock.h> #include <linux/serial.h> #include <linux/smp.h> #include <linux/types.h> #include <linux/string.h> /* for memset */ #include <linux/tty.h> #include <linux/time.h> #include <linux/platform_device.h> #include <linux/serial_core.h> #include <linux/serial_8250.h> #include <linux/of_fdt.h> #include <linux/libfdt.h> #include <linux/kexec.h>
#ifdef CONFIG_KEXEC #ifdef CONFIG_SMP /* * Wait for relocation code is prepared and send * secondary CPUs to spin until kernel is relocated.
*/ staticvoid octeon_kexec_smp_down(void *ignored)
{ int cpu = smp_processor_id();
local_irq_disable();
set_cpu_online(cpu, false); while (!atomic_read(&kexec_ready_to_reboot))
cpu_relax();
if (mem_size > OCTEON_MAX_PHY_MEM_SIZE) {
mem_size = OCTEON_MAX_PHY_MEM_SIZE;
pr_err("Error: requested memory too large," "truncating to maximum size\n");
}
#ifdef CONFIG_SMP /* disable watchdogs */
for_each_online_cpu(cpu)
cvmx_write_csr(CVMX_CIU_WDOGX(cpu_logical_map(cpu)), 0); #else
cvmx_write_csr(CVMX_CIU_WDOGX(cvmx_get_core_num()), 0); #endif if (kimage_ptr != kexec_crash_image) {
memset(named_block_array_ptr,
0x0,
CVMX_BOOTMEM_NUM_NAMED_BLOCKS * sizeof(struct cvmx_bootmem_named_block_desc)); /* * Mark all memory (except low 0x100000 bytes) as free. * It is the same thing that bootloader does.
*/
kexec_bootmem_init(octeon_bootinfo->dram_size*1024ULL*1024ULL,
0x100000); /* * Allocate all segments to avoid their corruption during boot.
*/ for (i = 0; i < kimage_ptr->nr_segments; i++)
cvmx_bootmem_alloc_address(
kimage_ptr->segment[i].memsz + 2*PAGE_SIZE,
kimage_ptr->segment[i].mem - PAGE_SIZE,
PAGE_SIZE);
} else { /* * Do not mark all memory as free. Free only named sections * leaving the rest of memory unchanged.
*/ struct cvmx_bootmem_named_block_desc *ptr =
(struct cvmx_bootmem_named_block_desc *)
named_block_array_ptr;
for (i = 0; i < bootmem_desc->named_block_num_blocks; i++) if (ptr[i].size)
cvmx_bootmem_free_named(ptr[i].name);
}
kexec_args[2] = 1UL; /* running on octeon_main_processor */
kexec_args[3] = (unsignedlong)octeon_boot_desc_ptr; #ifdef CONFIG_SMP
secondary_kexec_args[2] = 0UL; /* running on secondary cpu */
secondary_kexec_args[3] = (unsignedlong)octeon_boot_desc_ptr; #endif
}
#ifdef CONFIG_KEXEC /* crashkernel cmdline parameter is parsed _after_ memory setup
* we also parse it here (workaround for EHB5200) */ static uint64_t crashk_size, crashk_base; #endif
staticint octeon_uart;
extern asmlinkage void handle_int(void);
/** * octeon_is_simulation - Return non-zero if we are currently running * in the Octeon simulator * * Return: non-0 if running in the Octeon simulator, 0 otherwise
*/ int octeon_is_simulation(void)
{ return octeon_bootinfo->board_type == CVMX_BOARD_TYPE_SIM;
}
EXPORT_SYMBOL(octeon_is_simulation);
/** * octeon_is_pci_host - Return true if Octeon is in PCI Host mode. This means * Linux can control the PCI bus. * * Return: Non-zero if Octeon is in host mode.
*/ int octeon_is_pci_host(void)
{ #ifdef CONFIG_PCI return octeon_bootinfo->config_flags & CVMX_BOOTINFO_CFG_FLAG_PCI_HOST; #else return 0; #endif
}
/** * octeon_get_clock_rate - Get the clock rate of Octeon * * Return: Clock rate in HZ
*/
uint64_t octeon_get_clock_rate(void)
{ struct cvmx_sysinfo *sysinfo = cvmx_sysinfo_get();
/** * octeon_write_lcd - Write to the LCD display connected to the bootbus. * @s: String to write * * This display exists on most Cavium evaluation boards. If it doesn't exist, * then this function doesn't do anything.
*/ staticvoid octeon_write_lcd(constchar *s)
{ if (octeon_bootinfo->led_display_base_addr) { void __iomem *lcd_address =
ioremap(octeon_bootinfo->led_display_base_addr,
8); int i; for (i = 0; i < 8; i++, s++) { if (*s)
iowrite8(*s, lcd_address + i); else
iowrite8(' ', lcd_address + i);
}
iounmap(lcd_address);
}
}
/** * octeon_get_boot_uart - Return the console uart passed by the bootloader * * Return: uart number (0 or 1)
*/ staticint octeon_get_boot_uart(void)
{ return (octeon_boot_desc_ptr->flags & OCTEON_BL_FLAG_CONSOLE_UART1) ?
1 : 0;
}
/** * octeon_get_boot_coremask - Get the coremask Linux was booted on. * * Return: Core mask
*/ int octeon_get_boot_coremask(void)
{ return octeon_boot_desc_ptr->core_mask;
}
/** * octeon_check_cpu_bist - Check the hardware BIST results for a CPU
*/ void octeon_check_cpu_bist(void)
{ constint coreid = cvmx_get_core_num(); unsignedlonglong mask; unsignedlonglong bist_val;
/** * octeon_restart - Reboot Octeon * * @command: Command to pass to the bootloader. Currently ignored.
*/ staticvoid octeon_restart(char *command)
{ /* Disable all watchdogs before soft reset. They don't get cleared */ #ifdef CONFIG_SMP int cpu;
for_each_online_cpu(cpu)
cvmx_write_csr(CVMX_CIU_WDOGX(cpu_logical_map(cpu)), 0); #else
cvmx_write_csr(CVMX_CIU_WDOGX(cvmx_get_core_num()), 0); #endif
mb(); while (1) if (OCTEON_IS_OCTEON3())
cvmx_write_csr(CVMX_RST_SOFT_RST, 1); else
cvmx_write_csr(CVMX_CIU_SOFT_RST, 1);
}
/** * octeon_kill_core - Permanently stop a core. * * @arg: Ignored.
*/ staticvoid octeon_kill_core(void *arg)
{ if (octeon_is_simulation()) /* A break instruction causes the simulator stop a core */ asmvolatile ("break" ::: "memory");
local_irq_disable(); /* Disable watchdog on this core. */
cvmx_write_csr(CVMX_CIU_WDOGX(cvmx_get_core_num()), 0); /* Spin in a low power mode. */ while (true) asmvolatile ("wait" ::: "memory");
}
/** * octeon_halt - Halt the system
*/ staticvoid octeon_halt(void)
{
smp_call_function(octeon_kill_core, NULL, 0);
switch (octeon_bootinfo->board_type) { case CVMX_BOARD_TYPE_NAO38: /* Driving a 1 to GPIO 12 shuts off this board */
cvmx_write_csr(CVMX_GPIO_BIT_CFGX(12), 1);
cvmx_write_csr(CVMX_GPIO_TX_SET, 0x1000); break; default:
octeon_write_lcd("PowerOff"); break;
}
/** * octeon_board_type_string - Return a string representing the system type * * Return: system type string
*/ constchar *octeon_board_type_string(void)
{ return octeon_system_type;
}
void octeon_user_io_init(void)
{ union octeon_cvmemctl cvmmemctl;
/* Get the current settings for CP0_CVMMEMCTL_REG */
cvmmemctl.u64 = read_c0_cvmmemctl(); /* R/W If set, marked write-buffer entries time out the same * as other entries; if clear, marked write-buffer entries
* use the maximum timeout. */
cvmmemctl.s.dismarkwblongto = 1; /* R/W If set, a merged store does not clear the write-buffer
* entry timeout state. */
cvmmemctl.s.dismrgclrwbto = 0; /* R/W Two bits that are the MSBs of the resultant CVMSEG LM * word location for an IOBDMA. The other 8 bits come from the
* SCRADDR field of the IOBDMA. */
cvmmemctl.s.iobdmascrmsb = 0; /* R/W If set, SYNCWS and SYNCS only order marked stores; if * clear, SYNCWS and SYNCS only order unmarked * stores. SYNCWSMARKED has no effect when DISSYNCWS is
* set. */
cvmmemctl.s.syncwsmarked = 0; /* R/W If set, SYNCWS acts as SYNCW and SYNCS acts as SYNC. */
cvmmemctl.s.dissyncws = 0; /* R/W If set, no stall happens on write buffer full. */ if (OCTEON_IS_MODEL(OCTEON_CN38XX_PASS2))
cvmmemctl.s.diswbfst = 1; else
cvmmemctl.s.diswbfst = 0; /* R/W If set (and SX set), supervisor-level loads/stores can
* use XKPHYS addresses with <48>==0 */
cvmmemctl.s.xkmemenas = 0;
/* R/W If set (and UX set), user-level loads/stores can use
* XKPHYS addresses with VA<48>==0 */
cvmmemctl.s.xkmemenau = 0;
/* R/W If set (and SX set), supervisor-level loads/stores can
* use XKPHYS addresses with VA<48>==1 */
cvmmemctl.s.xkioenas = 0;
/* R/W If set (and UX set), user-level loads/stores can use
* XKPHYS addresses with VA<48>==1 */
cvmmemctl.s.xkioenau = 0;
/* R/W If set, all stores act as SYNCW (NOMERGE must be set
* when this is set) RW, reset to 0. */
cvmmemctl.s.allsyncw = 0;
/* R/W If set, no stores merge, and all stores reach the
* coherent bus in order. */
cvmmemctl.s.nomerge = 0; /* R/W Selects the bit in the counter used for DID time-outs 0 * = 231, 1 = 230, 2 = 229, 3 = 214. Actual time-out is * between 1x and 2x this interval. For example, with
* DIDTTO=3, expiration interval is between 16K and 32K. */
cvmmemctl.s.didtto = 0; /* R/W If set, the (mem) CSR clock never turns off. */
cvmmemctl.s.csrckalwys = 0; /* R/W If set, mclk never turns off. */
cvmmemctl.s.mclkalwys = 0; /* R/W Selects the bit in the counter used for write buffer * flush time-outs (WBFLT+11) is the bit position in an * internal counter used to determine expiration. The write * buffer expires between 1x and 2x this interval. For * example, with WBFLT = 0, a write buffer expires between 2K
* and 4K cycles after the write buffer entry is allocated. */
cvmmemctl.s.wbfltime = 0; /* R/W If set, do not put Istream in the L2 cache. */
cvmmemctl.s.istrnol2 = 0;
/* * R/W The write buffer threshold. As per erratum Core-14752 * for CN63XX, a sc/scd might fail if the write buffer is * full. Lowering WBTHRESH greatly lowers the chances of the * write buffer ever being full and triggering the erratum.
*/ if (OCTEON_IS_MODEL(OCTEON_CN63XX_PASS1_X))
cvmmemctl.s.wbthresh = 4; else
cvmmemctl.s.wbthresh = 10;
/* R/W If set, CVMSEG is available for loads/stores in
* kernel/debug mode. */ #if CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE > 0
cvmmemctl.s.cvmsegenak = 1; #else
cvmmemctl.s.cvmsegenak = 0; #endif /* R/W If set, CVMSEG is available for loads/stores in
* supervisor mode. */
cvmmemctl.s.cvmsegenas = 0; /* R/W If set, CVMSEG is available for loads/stores in user
* mode. */
cvmmemctl.s.cvmsegenau = 0;
write_c0_cvmmemctl(cvmmemctl.u64);
/* Setup of CVMSEG is done in kernel-entry-init.h */ if (smp_processor_id() == 0)
pr_notice("CVMSEG size: %d cache lines (%d bytes)\n",
CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE,
CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE * 128);
if (octeon_has_feature(OCTEON_FEATURE_FAU)) { union cvmx_iob_fau_timeout fau_timeout;
/* Set a default for the hardware timeouts */
fau_timeout.u64 = 0;
fau_timeout.s.tout_val = 0xfff; /* Disable tagwait FAU timeout */
fau_timeout.s.tout_enb = 0;
cvmx_write_csr(CVMX_IOB_FAU_TIMEOUT, fau_timeout.u64);
}
if ((!OCTEON_IS_MODEL(OCTEON_CN68XX) &&
!OCTEON_IS_MODEL(OCTEON_CN7XXX)) ||
OCTEON_IS_MODEL(OCTEON_CN70XX)) { union cvmx_pow_nw_tim nm_tim;
/** * prom_init - Early entry point for arch setup
*/ void __init prom_init(void)
{ struct cvmx_sysinfo *sysinfo; constchar *arg; char *p; int i;
u64 t; int argc; /* * The bootloader passes a pointer to the boot descriptor in * $a3, this is available as fw_arg3.
*/
octeon_boot_desc_ptr = (struct octeon_boot_descriptor *)fw_arg3;
octeon_bootinfo =
cvmx_phys_to_ptr(octeon_boot_desc_ptr->cvmx_desc_vaddr);
cvmx_bootmem_init(cvmx_phys_to_ptr(octeon_bootinfo->phy_mem_desc_addr));
/* Some broken u-boot pass garbage in upper bits, clear them out */ if (!OCTEON_IS_MODEL(OCTEON_CN78XX)) for (i = 512; i < 1024; i++)
cvmx_coremask_clear_core(&sysinfo->core_mask, i);
if (OCTEON_IS_OCTEON2()) { /* I/O clock runs at a different rate than the CPU. */ union cvmx_mio_rst_boot rst_boot;
rst_boot.u64 = cvmx_read_csr(CVMX_MIO_RST_BOOT);
octeon_io_clock_rate = 50000000 * rst_boot.s.pnr_mul;
} elseif (OCTEON_IS_OCTEON3()) { /* I/O clock runs at a different rate than the CPU. */ union cvmx_rst_boot rst_boot;
rst_boot.u64 = cvmx_read_csr(CVMX_RST_BOOT);
octeon_io_clock_rate = 50000000 * rst_boot.s.pnr_mul;
} else {
octeon_io_clock_rate = sysinfo->cpu_clock_hz;
}
t = read_c0_cvmctl(); if ((t & (1ull << 27)) == 0) { /* * Setup the multiplier save/restore code if * CvmCtl[NOMUL] clear.
*/ void *save; void *save_end; void *restore; void *restore_end; int save_len; int restore_len; int save_max = (char *)octeon_mult_save_end -
(char *)octeon_mult_save; int restore_max = (char *)octeon_mult_restore_end -
(char *)octeon_mult_restore; if (current_cpu_data.cputype == CPU_CAVIUM_OCTEON3) {
save = octeon_mult_save3;
save_end = octeon_mult_save3_end;
restore = octeon_mult_restore3;
restore_end = octeon_mult_restore3_end;
} else {
save = octeon_mult_save2;
save_end = octeon_mult_save2_end;
restore = octeon_mult_restore2;
restore_end = octeon_mult_restore2_end;
}
save_len = (char *)save_end - (char *)save;
restore_len = (char *)restore_end - (char *)restore; if (!WARN_ON(save_len > save_max ||
restore_len > restore_max)) {
memcpy(octeon_mult_save, save, save_len);
memcpy(octeon_mult_restore, restore, restore_len);
}
}
/* * Only enable the LED controller if we're running on a CN38XX, CN58XX, * or CN56XX. The CN30XX and CN31XX don't have an LED controller.
*/ if (!octeon_is_simulation() &&
octeon_has_feature(OCTEON_FEATURE_LED_CONTROLLER)) {
cvmx_write_csr(CVMX_LED_EN, 0);
cvmx_write_csr(CVMX_LED_PRT, 0);
cvmx_write_csr(CVMX_LED_DBG, 0);
cvmx_write_csr(CVMX_LED_PRT_FMT, 0);
cvmx_write_csr(CVMX_LED_UDD_CNTX(0), 32);
cvmx_write_csr(CVMX_LED_UDD_CNTX(1), 32);
cvmx_write_csr(CVMX_LED_UDD_DATX(0), 0);
cvmx_write_csr(CVMX_LED_UDD_DATX(1), 0);
cvmx_write_csr(CVMX_LED_EN, 1);
}
/* * We need to temporarily allocate all memory in the reserve32 * region. This makes sure the kernel doesn't allocate this * memory when it is getting memory from the * bootloader. Later, after the memory allocations are * complete, the reserve32 will be freed. * * Allocate memory for RESERVED32 aligned on 2MB boundary. This * is in case we later use hugetlb entries with it.
*/ if (CONFIG_CAVIUM_RESERVE32) {
int64_t addr =
cvmx_bootmem_phy_named_block_alloc(CONFIG_CAVIUM_RESERVE32 << 20,
0, 0, 2 << 20, "CAVIUM_RESERVE32", 0); if (addr < 0)
pr_err("Failed to allocate CAVIUM_RESERVE32 memory area\n"); else
octeon_reserve32_memory = addr;
}
/* * BIST should always be enabled when doing a soft reset. L2 * Cache locking for instance is not cleared unless BIST is * enabled. Unfortunately due to a chip errata G-200 for * Cn38XX and CN31XX, BIST must be disabled on these parts.
*/ if (OCTEON_IS_MODEL(OCTEON_CN38XX_PASS2) ||
OCTEON_IS_MODEL(OCTEON_CN31XX))
cvmx_write_csr(CVMX_CIU_SOFT_BIST, 0); else
cvmx_write_csr(CVMX_CIU_SOFT_BIST, 1);
/* Default to 64MB in the simulator to speed things up */ if (octeon_is_simulation())
max_memory = 64ull << 20;
/* * The Mips memory init uses the first memory location for * some memory vectors. When SPARSEMEM is in use, it doesn't * verify that the size is big enough for the final * vectors. Making the smallest chuck 4MB seems to be enough * to consistently work.
*/
mem_alloc_size = 4 << 20; if (mem_alloc_size > max_memory)
mem_alloc_size = max_memory;
/* Crashkernel ignores bootmem list. It relies on mem=X@Y option */ #ifdef CONFIG_CRASH_DUMP
memblock_add(reserve_low_mem, max_memory);
total += max_memory; #else #ifdef CONFIG_KEXEC if (crashk_size > 0) {
memblock_add(crashk_base, crashk_size);
crashk_end = crashk_base + crashk_size;
} #endif /* * When allocating memory, we want incrementing addresses, * which is handled by memblock
*/
cvmx_bootmem_lock(); while (total < max_memory) {
memory = cvmx_bootmem_phy_alloc(mem_alloc_size,
__pa_symbol(&_end), -1,
0x100000,
CVMX_BOOTMEM_FLAG_NO_LOCKING); if (memory >= 0) {
u64 size = mem_alloc_size; #ifdef CONFIG_KEXEC
uint64_t end; #endif
/* * exclude a page at the beginning and end of * the 256MB PCIe 'hole' so the kernel will not * try to allocate multi-page buffers that * span the discontinuity.
*/
memory_exclude_page(CVMX_PCIE_BAR1_PHYS_BASE,
&memory, &size);
memory_exclude_page(CVMX_PCIE_BAR1_PHYS_BASE +
CVMX_PCIE_BAR1_PHYS_SIZE,
&memory, &size); #ifdef CONFIG_KEXEC
end = memory + mem_alloc_size;
/* * This function automatically merges address regions * next to each other if they are received in * incrementing order
*/ if (memory < crashk_base && end > crashk_end) { /* region is fully in */
memblock_add(memory, crashk_base - memory);
total += crashk_base - memory;
memblock_add(crashk_end, end - crashk_end);
total += end - crashk_end; continue;
}
if (memory >= crashk_base && end <= crashk_end) /* * Entire memory region is within the new * kernel's memory, ignore it.
*/ continue;
if (memory > crashk_base && memory < crashk_end &&
end > crashk_end) { /* * Overlap with the beginning of the region, * reserve the beginning.
*/
mem_alloc_size -= crashk_end - memory;
memory = crashk_end;
} elseif (memory < crashk_base && end > crashk_base &&
end < crashk_end) /* * Overlap with the beginning of the region, * chop of end.
*/
mem_alloc_size -= end - crashk_base; #endif
memblock_add(memory, mem_alloc_size);
total += mem_alloc_size; /* Recovering mem_alloc_size */
mem_alloc_size = 4 << 20;
} else { break;
}
}
cvmx_bootmem_unlock(); #endif/* CONFIG_CRASH_DUMP */
/* * Now that we've allocated the kernel memory it is safe to * free the reserved region. We free it here so that builtin * drivers can use the memory.
*/ if (octeon_reserve32_memory)
cvmx_bootmem_free_named("CAVIUM_RESERVE32");
if (total == 0)
panic("Unable to allocate memory from " "cvmx_bootmem_phy_alloc");
}
/* * Emit one character to the boot UART. Exported for use by the * watchdog timer.
*/ void prom_putchar(char c)
{
uint64_t lsrval;
/* Spin until there is room */ do {
lsrval = cvmx_read_csr(CVMX_MIO_UARTX_LSR(octeon_uart));
} while ((lsrval & 0x20) == 0);
/* Write the byte */
cvmx_write_csr(CVMX_MIO_UARTX_THR(octeon_uart), c & 0xffull);
}
EXPORT_SYMBOL(prom_putchar);
void __init prom_free_prom_memory(void)
{ if (OCTEON_IS_MODEL(OCTEON_CN6XXX)) { /* Check for presence of Core-14449 fix. */
u32 insn;
u32 *foo;
if ((insn >> 26) != 0x33)
panic("No PREF instruction at Core-14449 probe point.");
if (((insn >> 16) & 0x1f) != 28)
panic("OCTEON II DCache prefetch workaround not in place (%04x).\n" "Please build kernel with proper options (CONFIG_CAVIUM_CN63XXP1).",
insn);
}
}
staticint __init edac_devinit(void)
{ struct platform_device *dev; int i, err = 0; int num_lmc; char *name;
if (disable_octeon_edac_p) return 0;
for (i = 0; i < ARRAY_SIZE(edac_device_names); i++) {
name = edac_device_names[i];
dev = platform_device_register_simple(name, -1, NULL, 0); if (IS_ERR(dev)) {
pr_err("Registration of %s failed!\n", name);
err = PTR_ERR(dev);
}
}
num_lmc = OCTEON_IS_MODEL(OCTEON_CN68XX) ? 4 :
(OCTEON_IS_MODEL(OCTEON_CN56XX) ? 2 : 1); for (i = 0; i < num_lmc; i++) {
dev = platform_device_register_simple("octeon_lmc_edac",
i, NULL, 0); if (IS_ERR(dev)) {
pr_err("Registration of octeon_lmc_edac %d failed!\n", i);
err = PTR_ERR(dev);
}
}
return err;
}
device_initcall(edac_devinit);
staticvoid __initdata *octeon_dummy_iospace;
staticint __init octeon_no_pci_init(void)
{ /* * Initially assume there is no PCI. The PCI/PCIe platform code will * later re-initialize these to correct values if they are present.
*/
octeon_dummy_iospace = vzalloc(IO_SPACE_LIMIT);
set_io_port_base((unsignedlong)octeon_dummy_iospace);
ioport_resource.start = RESOURCE_SIZE_MAX;
ioport_resource.end = 0; return 0;
}
core_initcall(octeon_no_pci_init);
staticint __init octeon_no_pci_release(void)
{ /* * Release the allocated memory if a real IO space is there.
*/ if ((unsignedlong)octeon_dummy_iospace != mips_io_port_base)
vfree(octeon_dummy_iospace); return 0;
}
late_initcall(octeon_no_pci_release);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.