1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * This file is subject to the terms and conditions of the GNU General Public
3*4882a593Smuzhiyun * License. See the file "COPYING" in the main directory of this archive
4*4882a593Smuzhiyun * for more details.
5*4882a593Smuzhiyun *
6*4882a593Smuzhiyun * Copyright (C) 2004-2007 Cavium Networks
7*4882a593Smuzhiyun * Copyright (C) 2008, 2009 Wind River Systems
8*4882a593Smuzhiyun * written by Ralf Baechle <ralf@linux-mips.org>
9*4882a593Smuzhiyun */
10*4882a593Smuzhiyun #include <linux/compiler.h>
11*4882a593Smuzhiyun #include <linux/vmalloc.h>
12*4882a593Smuzhiyun #include <linux/init.h>
13*4882a593Smuzhiyun #include <linux/kernel.h>
14*4882a593Smuzhiyun #include <linux/console.h>
15*4882a593Smuzhiyun #include <linux/delay.h>
16*4882a593Smuzhiyun #include <linux/export.h>
17*4882a593Smuzhiyun #include <linux/interrupt.h>
18*4882a593Smuzhiyun #include <linux/io.h>
19*4882a593Smuzhiyun #include <linux/memblock.h>
20*4882a593Smuzhiyun #include <linux/serial.h>
21*4882a593Smuzhiyun #include <linux/smp.h>
22*4882a593Smuzhiyun #include <linux/types.h>
23*4882a593Smuzhiyun #include <linux/string.h> /* for memset */
24*4882a593Smuzhiyun #include <linux/tty.h>
25*4882a593Smuzhiyun #include <linux/time.h>
26*4882a593Smuzhiyun #include <linux/platform_device.h>
27*4882a593Smuzhiyun #include <linux/serial_core.h>
28*4882a593Smuzhiyun #include <linux/serial_8250.h>
29*4882a593Smuzhiyun #include <linux/of_fdt.h>
30*4882a593Smuzhiyun #include <linux/libfdt.h>
31*4882a593Smuzhiyun #include <linux/kexec.h>
32*4882a593Smuzhiyun
33*4882a593Smuzhiyun #include <asm/processor.h>
34*4882a593Smuzhiyun #include <asm/reboot.h>
35*4882a593Smuzhiyun #include <asm/smp-ops.h>
36*4882a593Smuzhiyun #include <asm/irq_cpu.h>
37*4882a593Smuzhiyun #include <asm/mipsregs.h>
38*4882a593Smuzhiyun #include <asm/bootinfo.h>
39*4882a593Smuzhiyun #include <asm/sections.h>
40*4882a593Smuzhiyun #include <asm/fw/fw.h>
41*4882a593Smuzhiyun #include <asm/setup.h>
42*4882a593Smuzhiyun #include <asm/prom.h>
43*4882a593Smuzhiyun #include <asm/time.h>
44*4882a593Smuzhiyun
45*4882a593Smuzhiyun #include <asm/octeon/octeon.h>
46*4882a593Smuzhiyun #include <asm/octeon/pci-octeon.h>
47*4882a593Smuzhiyun #include <asm/octeon/cvmx-rst-defs.h>
48*4882a593Smuzhiyun
49*4882a593Smuzhiyun /*
50*4882a593Smuzhiyun * TRUE for devices having registers with little-endian byte
51*4882a593Smuzhiyun * order, FALSE for registers with native-endian byte order.
52*4882a593Smuzhiyun * PCI mandates little-endian, USB and SATA are configuraable,
53*4882a593Smuzhiyun * but we chose little-endian for these.
54*4882a593Smuzhiyun */
55*4882a593Smuzhiyun const bool octeon_should_swizzle_table[256] = {
56*4882a593Smuzhiyun [0x00] = true, /* bootbus/CF */
57*4882a593Smuzhiyun [0x1b] = true, /* PCI mmio window */
58*4882a593Smuzhiyun [0x1c] = true, /* PCI mmio window */
59*4882a593Smuzhiyun [0x1d] = true, /* PCI mmio window */
60*4882a593Smuzhiyun [0x1e] = true, /* PCI mmio window */
61*4882a593Smuzhiyun [0x68] = true, /* OCTEON III USB */
62*4882a593Smuzhiyun [0x69] = true, /* OCTEON III USB */
63*4882a593Smuzhiyun [0x6c] = true, /* OCTEON III SATA */
64*4882a593Smuzhiyun [0x6f] = true, /* OCTEON II USB */
65*4882a593Smuzhiyun };
66*4882a593Smuzhiyun EXPORT_SYMBOL(octeon_should_swizzle_table);
67*4882a593Smuzhiyun
68*4882a593Smuzhiyun #ifdef CONFIG_PCI
69*4882a593Smuzhiyun extern void pci_console_init(const char *arg);
70*4882a593Smuzhiyun #endif
71*4882a593Smuzhiyun
72*4882a593Smuzhiyun static unsigned long long max_memory = ULLONG_MAX;
73*4882a593Smuzhiyun static unsigned long long reserve_low_mem;
74*4882a593Smuzhiyun
75*4882a593Smuzhiyun DEFINE_SEMAPHORE(octeon_bootbus_sem);
76*4882a593Smuzhiyun EXPORT_SYMBOL(octeon_bootbus_sem);
77*4882a593Smuzhiyun
78*4882a593Smuzhiyun static struct octeon_boot_descriptor *octeon_boot_desc_ptr;
79*4882a593Smuzhiyun
80*4882a593Smuzhiyun struct cvmx_bootinfo *octeon_bootinfo;
81*4882a593Smuzhiyun EXPORT_SYMBOL(octeon_bootinfo);
82*4882a593Smuzhiyun
83*4882a593Smuzhiyun #ifdef CONFIG_KEXEC
84*4882a593Smuzhiyun #ifdef CONFIG_SMP
85*4882a593Smuzhiyun /*
86*4882a593Smuzhiyun * Wait for relocation code is prepared and send
87*4882a593Smuzhiyun * secondary CPUs to spin until kernel is relocated.
88*4882a593Smuzhiyun */
octeon_kexec_smp_down(void * ignored)89*4882a593Smuzhiyun static void octeon_kexec_smp_down(void *ignored)
90*4882a593Smuzhiyun {
91*4882a593Smuzhiyun int cpu = smp_processor_id();
92*4882a593Smuzhiyun
93*4882a593Smuzhiyun local_irq_disable();
94*4882a593Smuzhiyun set_cpu_online(cpu, false);
95*4882a593Smuzhiyun while (!atomic_read(&kexec_ready_to_reboot))
96*4882a593Smuzhiyun cpu_relax();
97*4882a593Smuzhiyun
98*4882a593Smuzhiyun asm volatile (
99*4882a593Smuzhiyun " sync \n"
100*4882a593Smuzhiyun " synci ($0) \n");
101*4882a593Smuzhiyun
102*4882a593Smuzhiyun kexec_reboot();
103*4882a593Smuzhiyun }
104*4882a593Smuzhiyun #endif
105*4882a593Smuzhiyun
106*4882a593Smuzhiyun #define OCTEON_DDR0_BASE (0x0ULL)
107*4882a593Smuzhiyun #define OCTEON_DDR0_SIZE (0x010000000ULL)
108*4882a593Smuzhiyun #define OCTEON_DDR1_BASE (0x410000000ULL)
109*4882a593Smuzhiyun #define OCTEON_DDR1_SIZE (0x010000000ULL)
110*4882a593Smuzhiyun #define OCTEON_DDR2_BASE (0x020000000ULL)
111*4882a593Smuzhiyun #define OCTEON_DDR2_SIZE (0x3e0000000ULL)
112*4882a593Smuzhiyun #define OCTEON_MAX_PHY_MEM_SIZE (16*1024*1024*1024ULL)
113*4882a593Smuzhiyun
114*4882a593Smuzhiyun static struct kimage *kimage_ptr;
115*4882a593Smuzhiyun
kexec_bootmem_init(uint64_t mem_size,uint32_t low_reserved_bytes)116*4882a593Smuzhiyun static void kexec_bootmem_init(uint64_t mem_size, uint32_t low_reserved_bytes)
117*4882a593Smuzhiyun {
118*4882a593Smuzhiyun int64_t addr;
119*4882a593Smuzhiyun struct cvmx_bootmem_desc *bootmem_desc;
120*4882a593Smuzhiyun
121*4882a593Smuzhiyun bootmem_desc = cvmx_bootmem_get_desc();
122*4882a593Smuzhiyun
123*4882a593Smuzhiyun if (mem_size > OCTEON_MAX_PHY_MEM_SIZE) {
124*4882a593Smuzhiyun mem_size = OCTEON_MAX_PHY_MEM_SIZE;
125*4882a593Smuzhiyun pr_err("Error: requested memory too large,"
126*4882a593Smuzhiyun "truncating to maximum size\n");
127*4882a593Smuzhiyun }
128*4882a593Smuzhiyun
129*4882a593Smuzhiyun bootmem_desc->major_version = CVMX_BOOTMEM_DESC_MAJ_VER;
130*4882a593Smuzhiyun bootmem_desc->minor_version = CVMX_BOOTMEM_DESC_MIN_VER;
131*4882a593Smuzhiyun
132*4882a593Smuzhiyun addr = (OCTEON_DDR0_BASE + reserve_low_mem + low_reserved_bytes);
133*4882a593Smuzhiyun bootmem_desc->head_addr = 0;
134*4882a593Smuzhiyun
135*4882a593Smuzhiyun if (mem_size <= OCTEON_DDR0_SIZE) {
136*4882a593Smuzhiyun __cvmx_bootmem_phy_free(addr,
137*4882a593Smuzhiyun mem_size - reserve_low_mem -
138*4882a593Smuzhiyun low_reserved_bytes, 0);
139*4882a593Smuzhiyun return;
140*4882a593Smuzhiyun }
141*4882a593Smuzhiyun
142*4882a593Smuzhiyun __cvmx_bootmem_phy_free(addr,
143*4882a593Smuzhiyun OCTEON_DDR0_SIZE - reserve_low_mem -
144*4882a593Smuzhiyun low_reserved_bytes, 0);
145*4882a593Smuzhiyun
146*4882a593Smuzhiyun mem_size -= OCTEON_DDR0_SIZE;
147*4882a593Smuzhiyun
148*4882a593Smuzhiyun if (mem_size > OCTEON_DDR1_SIZE) {
149*4882a593Smuzhiyun __cvmx_bootmem_phy_free(OCTEON_DDR1_BASE, OCTEON_DDR1_SIZE, 0);
150*4882a593Smuzhiyun __cvmx_bootmem_phy_free(OCTEON_DDR2_BASE,
151*4882a593Smuzhiyun mem_size - OCTEON_DDR1_SIZE, 0);
152*4882a593Smuzhiyun } else
153*4882a593Smuzhiyun __cvmx_bootmem_phy_free(OCTEON_DDR1_BASE, mem_size, 0);
154*4882a593Smuzhiyun }
155*4882a593Smuzhiyun
octeon_kexec_prepare(struct kimage * image)156*4882a593Smuzhiyun static int octeon_kexec_prepare(struct kimage *image)
157*4882a593Smuzhiyun {
158*4882a593Smuzhiyun int i;
159*4882a593Smuzhiyun char *bootloader = "kexec";
160*4882a593Smuzhiyun
161*4882a593Smuzhiyun octeon_boot_desc_ptr->argc = 0;
162*4882a593Smuzhiyun for (i = 0; i < image->nr_segments; i++) {
163*4882a593Smuzhiyun if (!strncmp(bootloader, (char *)image->segment[i].buf,
164*4882a593Smuzhiyun strlen(bootloader))) {
165*4882a593Smuzhiyun /*
166*4882a593Smuzhiyun * convert command line string to array
167*4882a593Smuzhiyun * of parameters (as bootloader does).
168*4882a593Smuzhiyun */
169*4882a593Smuzhiyun int argc = 0, offt;
170*4882a593Smuzhiyun char *str = (char *)image->segment[i].buf;
171*4882a593Smuzhiyun char *ptr = strchr(str, ' ');
172*4882a593Smuzhiyun while (ptr && (OCTEON_ARGV_MAX_ARGS > argc)) {
173*4882a593Smuzhiyun *ptr = '\0';
174*4882a593Smuzhiyun if (ptr[1] != ' ') {
175*4882a593Smuzhiyun offt = (int)(ptr - str + 1);
176*4882a593Smuzhiyun octeon_boot_desc_ptr->argv[argc] =
177*4882a593Smuzhiyun image->segment[i].mem + offt;
178*4882a593Smuzhiyun argc++;
179*4882a593Smuzhiyun }
180*4882a593Smuzhiyun ptr = strchr(ptr + 1, ' ');
181*4882a593Smuzhiyun }
182*4882a593Smuzhiyun octeon_boot_desc_ptr->argc = argc;
183*4882a593Smuzhiyun break;
184*4882a593Smuzhiyun }
185*4882a593Smuzhiyun }
186*4882a593Smuzhiyun
187*4882a593Smuzhiyun /*
188*4882a593Smuzhiyun * Information about segments will be needed during pre-boot memory
189*4882a593Smuzhiyun * initialization.
190*4882a593Smuzhiyun */
191*4882a593Smuzhiyun kimage_ptr = image;
192*4882a593Smuzhiyun return 0;
193*4882a593Smuzhiyun }
194*4882a593Smuzhiyun
octeon_generic_shutdown(void)195*4882a593Smuzhiyun static void octeon_generic_shutdown(void)
196*4882a593Smuzhiyun {
197*4882a593Smuzhiyun int i;
198*4882a593Smuzhiyun #ifdef CONFIG_SMP
199*4882a593Smuzhiyun int cpu;
200*4882a593Smuzhiyun #endif
201*4882a593Smuzhiyun struct cvmx_bootmem_desc *bootmem_desc;
202*4882a593Smuzhiyun void *named_block_array_ptr;
203*4882a593Smuzhiyun
204*4882a593Smuzhiyun bootmem_desc = cvmx_bootmem_get_desc();
205*4882a593Smuzhiyun named_block_array_ptr =
206*4882a593Smuzhiyun cvmx_phys_to_ptr(bootmem_desc->named_block_array_addr);
207*4882a593Smuzhiyun
208*4882a593Smuzhiyun #ifdef CONFIG_SMP
209*4882a593Smuzhiyun /* disable watchdogs */
210*4882a593Smuzhiyun for_each_online_cpu(cpu)
211*4882a593Smuzhiyun cvmx_write_csr(CVMX_CIU_WDOGX(cpu_logical_map(cpu)), 0);
212*4882a593Smuzhiyun #else
213*4882a593Smuzhiyun cvmx_write_csr(CVMX_CIU_WDOGX(cvmx_get_core_num()), 0);
214*4882a593Smuzhiyun #endif
215*4882a593Smuzhiyun if (kimage_ptr != kexec_crash_image) {
216*4882a593Smuzhiyun memset(named_block_array_ptr,
217*4882a593Smuzhiyun 0x0,
218*4882a593Smuzhiyun CVMX_BOOTMEM_NUM_NAMED_BLOCKS *
219*4882a593Smuzhiyun sizeof(struct cvmx_bootmem_named_block_desc));
220*4882a593Smuzhiyun /*
221*4882a593Smuzhiyun * Mark all memory (except low 0x100000 bytes) as free.
222*4882a593Smuzhiyun * It is the same thing that bootloader does.
223*4882a593Smuzhiyun */
224*4882a593Smuzhiyun kexec_bootmem_init(octeon_bootinfo->dram_size*1024ULL*1024ULL,
225*4882a593Smuzhiyun 0x100000);
226*4882a593Smuzhiyun /*
227*4882a593Smuzhiyun * Allocate all segments to avoid their corruption during boot.
228*4882a593Smuzhiyun */
229*4882a593Smuzhiyun for (i = 0; i < kimage_ptr->nr_segments; i++)
230*4882a593Smuzhiyun cvmx_bootmem_alloc_address(
231*4882a593Smuzhiyun kimage_ptr->segment[i].memsz + 2*PAGE_SIZE,
232*4882a593Smuzhiyun kimage_ptr->segment[i].mem - PAGE_SIZE,
233*4882a593Smuzhiyun PAGE_SIZE);
234*4882a593Smuzhiyun } else {
235*4882a593Smuzhiyun /*
236*4882a593Smuzhiyun * Do not mark all memory as free. Free only named sections
237*4882a593Smuzhiyun * leaving the rest of memory unchanged.
238*4882a593Smuzhiyun */
239*4882a593Smuzhiyun struct cvmx_bootmem_named_block_desc *ptr =
240*4882a593Smuzhiyun (struct cvmx_bootmem_named_block_desc *)
241*4882a593Smuzhiyun named_block_array_ptr;
242*4882a593Smuzhiyun
243*4882a593Smuzhiyun for (i = 0; i < bootmem_desc->named_block_num_blocks; i++)
244*4882a593Smuzhiyun if (ptr[i].size)
245*4882a593Smuzhiyun cvmx_bootmem_free_named(ptr[i].name);
246*4882a593Smuzhiyun }
247*4882a593Smuzhiyun kexec_args[2] = 1UL; /* running on octeon_main_processor */
248*4882a593Smuzhiyun kexec_args[3] = (unsigned long)octeon_boot_desc_ptr;
249*4882a593Smuzhiyun #ifdef CONFIG_SMP
250*4882a593Smuzhiyun secondary_kexec_args[2] = 0UL; /* running on secondary cpu */
251*4882a593Smuzhiyun secondary_kexec_args[3] = (unsigned long)octeon_boot_desc_ptr;
252*4882a593Smuzhiyun #endif
253*4882a593Smuzhiyun }
254*4882a593Smuzhiyun
octeon_shutdown(void)255*4882a593Smuzhiyun static void octeon_shutdown(void)
256*4882a593Smuzhiyun {
257*4882a593Smuzhiyun octeon_generic_shutdown();
258*4882a593Smuzhiyun #ifdef CONFIG_SMP
259*4882a593Smuzhiyun smp_call_function(octeon_kexec_smp_down, NULL, 0);
260*4882a593Smuzhiyun smp_wmb();
261*4882a593Smuzhiyun while (num_online_cpus() > 1) {
262*4882a593Smuzhiyun cpu_relax();
263*4882a593Smuzhiyun mdelay(1);
264*4882a593Smuzhiyun }
265*4882a593Smuzhiyun #endif
266*4882a593Smuzhiyun }
267*4882a593Smuzhiyun
octeon_crash_shutdown(struct pt_regs * regs)268*4882a593Smuzhiyun static void octeon_crash_shutdown(struct pt_regs *regs)
269*4882a593Smuzhiyun {
270*4882a593Smuzhiyun octeon_generic_shutdown();
271*4882a593Smuzhiyun default_machine_crash_shutdown(regs);
272*4882a593Smuzhiyun }
273*4882a593Smuzhiyun
274*4882a593Smuzhiyun #ifdef CONFIG_SMP
octeon_crash_smp_send_stop(void)275*4882a593Smuzhiyun void octeon_crash_smp_send_stop(void)
276*4882a593Smuzhiyun {
277*4882a593Smuzhiyun int cpu;
278*4882a593Smuzhiyun
279*4882a593Smuzhiyun /* disable watchdogs */
280*4882a593Smuzhiyun for_each_online_cpu(cpu)
281*4882a593Smuzhiyun cvmx_write_csr(CVMX_CIU_WDOGX(cpu_logical_map(cpu)), 0);
282*4882a593Smuzhiyun }
283*4882a593Smuzhiyun #endif
284*4882a593Smuzhiyun
285*4882a593Smuzhiyun #endif /* CONFIG_KEXEC */
286*4882a593Smuzhiyun
287*4882a593Smuzhiyun #ifdef CONFIG_CAVIUM_RESERVE32
288*4882a593Smuzhiyun uint64_t octeon_reserve32_memory;
289*4882a593Smuzhiyun EXPORT_SYMBOL(octeon_reserve32_memory);
290*4882a593Smuzhiyun #endif
291*4882a593Smuzhiyun
292*4882a593Smuzhiyun #ifdef CONFIG_KEXEC
293*4882a593Smuzhiyun /* crashkernel cmdline parameter is parsed _after_ memory setup
294*4882a593Smuzhiyun * we also parse it here (workaround for EHB5200) */
295*4882a593Smuzhiyun static uint64_t crashk_size, crashk_base;
296*4882a593Smuzhiyun #endif
297*4882a593Smuzhiyun
298*4882a593Smuzhiyun static int octeon_uart;
299*4882a593Smuzhiyun
300*4882a593Smuzhiyun extern asmlinkage void handle_int(void);
301*4882a593Smuzhiyun
302*4882a593Smuzhiyun /**
303*4882a593Smuzhiyun * Return non zero if we are currently running in the Octeon simulator
304*4882a593Smuzhiyun *
305*4882a593Smuzhiyun * Returns
306*4882a593Smuzhiyun */
octeon_is_simulation(void)307*4882a593Smuzhiyun int octeon_is_simulation(void)
308*4882a593Smuzhiyun {
309*4882a593Smuzhiyun return octeon_bootinfo->board_type == CVMX_BOARD_TYPE_SIM;
310*4882a593Smuzhiyun }
311*4882a593Smuzhiyun EXPORT_SYMBOL(octeon_is_simulation);
312*4882a593Smuzhiyun
313*4882a593Smuzhiyun /**
314*4882a593Smuzhiyun * Return true if Octeon is in PCI Host mode. This means
315*4882a593Smuzhiyun * Linux can control the PCI bus.
316*4882a593Smuzhiyun *
317*4882a593Smuzhiyun * Returns Non zero if Octeon in host mode.
318*4882a593Smuzhiyun */
octeon_is_pci_host(void)319*4882a593Smuzhiyun int octeon_is_pci_host(void)
320*4882a593Smuzhiyun {
321*4882a593Smuzhiyun #ifdef CONFIG_PCI
322*4882a593Smuzhiyun return octeon_bootinfo->config_flags & CVMX_BOOTINFO_CFG_FLAG_PCI_HOST;
323*4882a593Smuzhiyun #else
324*4882a593Smuzhiyun return 0;
325*4882a593Smuzhiyun #endif
326*4882a593Smuzhiyun }
327*4882a593Smuzhiyun
328*4882a593Smuzhiyun /**
329*4882a593Smuzhiyun * Get the clock rate of Octeon
330*4882a593Smuzhiyun *
331*4882a593Smuzhiyun * Returns Clock rate in HZ
332*4882a593Smuzhiyun */
octeon_get_clock_rate(void)333*4882a593Smuzhiyun uint64_t octeon_get_clock_rate(void)
334*4882a593Smuzhiyun {
335*4882a593Smuzhiyun struct cvmx_sysinfo *sysinfo = cvmx_sysinfo_get();
336*4882a593Smuzhiyun
337*4882a593Smuzhiyun return sysinfo->cpu_clock_hz;
338*4882a593Smuzhiyun }
339*4882a593Smuzhiyun EXPORT_SYMBOL(octeon_get_clock_rate);
340*4882a593Smuzhiyun
341*4882a593Smuzhiyun static u64 octeon_io_clock_rate;
342*4882a593Smuzhiyun
octeon_get_io_clock_rate(void)343*4882a593Smuzhiyun u64 octeon_get_io_clock_rate(void)
344*4882a593Smuzhiyun {
345*4882a593Smuzhiyun return octeon_io_clock_rate;
346*4882a593Smuzhiyun }
347*4882a593Smuzhiyun EXPORT_SYMBOL(octeon_get_io_clock_rate);
348*4882a593Smuzhiyun
349*4882a593Smuzhiyun
350*4882a593Smuzhiyun /**
351*4882a593Smuzhiyun * Write to the LCD display connected to the bootbus. This display
352*4882a593Smuzhiyun * exists on most Cavium evaluation boards. If it doesn't exist, then
353*4882a593Smuzhiyun * this function doesn't do anything.
354*4882a593Smuzhiyun *
355*4882a593Smuzhiyun * @s: String to write
356*4882a593Smuzhiyun */
octeon_write_lcd(const char * s)357*4882a593Smuzhiyun static void octeon_write_lcd(const char *s)
358*4882a593Smuzhiyun {
359*4882a593Smuzhiyun if (octeon_bootinfo->led_display_base_addr) {
360*4882a593Smuzhiyun void __iomem *lcd_address =
361*4882a593Smuzhiyun ioremap(octeon_bootinfo->led_display_base_addr,
362*4882a593Smuzhiyun 8);
363*4882a593Smuzhiyun int i;
364*4882a593Smuzhiyun for (i = 0; i < 8; i++, s++) {
365*4882a593Smuzhiyun if (*s)
366*4882a593Smuzhiyun iowrite8(*s, lcd_address + i);
367*4882a593Smuzhiyun else
368*4882a593Smuzhiyun iowrite8(' ', lcd_address + i);
369*4882a593Smuzhiyun }
370*4882a593Smuzhiyun iounmap(lcd_address);
371*4882a593Smuzhiyun }
372*4882a593Smuzhiyun }
373*4882a593Smuzhiyun
374*4882a593Smuzhiyun /**
375*4882a593Smuzhiyun * Return the console uart passed by the bootloader
376*4882a593Smuzhiyun *
377*4882a593Smuzhiyun * Returns uart (0 or 1)
378*4882a593Smuzhiyun */
octeon_get_boot_uart(void)379*4882a593Smuzhiyun static int octeon_get_boot_uart(void)
380*4882a593Smuzhiyun {
381*4882a593Smuzhiyun return (octeon_boot_desc_ptr->flags & OCTEON_BL_FLAG_CONSOLE_UART1) ?
382*4882a593Smuzhiyun 1 : 0;
383*4882a593Smuzhiyun }
384*4882a593Smuzhiyun
385*4882a593Smuzhiyun /**
386*4882a593Smuzhiyun * Get the coremask Linux was booted on.
387*4882a593Smuzhiyun *
388*4882a593Smuzhiyun * Returns Core mask
389*4882a593Smuzhiyun */
octeon_get_boot_coremask(void)390*4882a593Smuzhiyun int octeon_get_boot_coremask(void)
391*4882a593Smuzhiyun {
392*4882a593Smuzhiyun return octeon_boot_desc_ptr->core_mask;
393*4882a593Smuzhiyun }
394*4882a593Smuzhiyun
395*4882a593Smuzhiyun /**
396*4882a593Smuzhiyun * Check the hardware BIST results for a CPU
397*4882a593Smuzhiyun */
octeon_check_cpu_bist(void)398*4882a593Smuzhiyun void octeon_check_cpu_bist(void)
399*4882a593Smuzhiyun {
400*4882a593Smuzhiyun const int coreid = cvmx_get_core_num();
401*4882a593Smuzhiyun unsigned long long mask;
402*4882a593Smuzhiyun unsigned long long bist_val;
403*4882a593Smuzhiyun
404*4882a593Smuzhiyun /* Check BIST results for COP0 registers */
405*4882a593Smuzhiyun mask = 0x1f00000000ull;
406*4882a593Smuzhiyun bist_val = read_octeon_c0_icacheerr();
407*4882a593Smuzhiyun if (bist_val & mask)
408*4882a593Smuzhiyun pr_err("Core%d BIST Failure: CacheErr(icache) = 0x%llx\n",
409*4882a593Smuzhiyun coreid, bist_val);
410*4882a593Smuzhiyun
411*4882a593Smuzhiyun bist_val = read_octeon_c0_dcacheerr();
412*4882a593Smuzhiyun if (bist_val & 1)
413*4882a593Smuzhiyun pr_err("Core%d L1 Dcache parity error: "
414*4882a593Smuzhiyun "CacheErr(dcache) = 0x%llx\n",
415*4882a593Smuzhiyun coreid, bist_val);
416*4882a593Smuzhiyun
417*4882a593Smuzhiyun mask = 0xfc00000000000000ull;
418*4882a593Smuzhiyun bist_val = read_c0_cvmmemctl();
419*4882a593Smuzhiyun if (bist_val & mask)
420*4882a593Smuzhiyun pr_err("Core%d BIST Failure: COP0_CVM_MEM_CTL = 0x%llx\n",
421*4882a593Smuzhiyun coreid, bist_val);
422*4882a593Smuzhiyun
423*4882a593Smuzhiyun write_octeon_c0_dcacheerr(0);
424*4882a593Smuzhiyun }
425*4882a593Smuzhiyun
426*4882a593Smuzhiyun /**
427*4882a593Smuzhiyun * Reboot Octeon
428*4882a593Smuzhiyun *
429*4882a593Smuzhiyun * @command: Command to pass to the bootloader. Currently ignored.
430*4882a593Smuzhiyun */
octeon_restart(char * command)431*4882a593Smuzhiyun static void octeon_restart(char *command)
432*4882a593Smuzhiyun {
433*4882a593Smuzhiyun /* Disable all watchdogs before soft reset. They don't get cleared */
434*4882a593Smuzhiyun #ifdef CONFIG_SMP
435*4882a593Smuzhiyun int cpu;
436*4882a593Smuzhiyun for_each_online_cpu(cpu)
437*4882a593Smuzhiyun cvmx_write_csr(CVMX_CIU_WDOGX(cpu_logical_map(cpu)), 0);
438*4882a593Smuzhiyun #else
439*4882a593Smuzhiyun cvmx_write_csr(CVMX_CIU_WDOGX(cvmx_get_core_num()), 0);
440*4882a593Smuzhiyun #endif
441*4882a593Smuzhiyun
442*4882a593Smuzhiyun mb();
443*4882a593Smuzhiyun while (1)
444*4882a593Smuzhiyun if (OCTEON_IS_OCTEON3())
445*4882a593Smuzhiyun cvmx_write_csr(CVMX_RST_SOFT_RST, 1);
446*4882a593Smuzhiyun else
447*4882a593Smuzhiyun cvmx_write_csr(CVMX_CIU_SOFT_RST, 1);
448*4882a593Smuzhiyun }
449*4882a593Smuzhiyun
450*4882a593Smuzhiyun
451*4882a593Smuzhiyun /**
452*4882a593Smuzhiyun * Permanently stop a core.
453*4882a593Smuzhiyun *
454*4882a593Smuzhiyun * @arg: Ignored.
455*4882a593Smuzhiyun */
octeon_kill_core(void * arg)456*4882a593Smuzhiyun static void octeon_kill_core(void *arg)
457*4882a593Smuzhiyun {
458*4882a593Smuzhiyun if (octeon_is_simulation())
459*4882a593Smuzhiyun /* A break instruction causes the simulator stop a core */
460*4882a593Smuzhiyun asm volatile ("break" ::: "memory");
461*4882a593Smuzhiyun
462*4882a593Smuzhiyun local_irq_disable();
463*4882a593Smuzhiyun /* Disable watchdog on this core. */
464*4882a593Smuzhiyun cvmx_write_csr(CVMX_CIU_WDOGX(cvmx_get_core_num()), 0);
465*4882a593Smuzhiyun /* Spin in a low power mode. */
466*4882a593Smuzhiyun while (true)
467*4882a593Smuzhiyun asm volatile ("wait" ::: "memory");
468*4882a593Smuzhiyun }
469*4882a593Smuzhiyun
470*4882a593Smuzhiyun
471*4882a593Smuzhiyun /**
472*4882a593Smuzhiyun * Halt the system
473*4882a593Smuzhiyun */
octeon_halt(void)474*4882a593Smuzhiyun static void octeon_halt(void)
475*4882a593Smuzhiyun {
476*4882a593Smuzhiyun smp_call_function(octeon_kill_core, NULL, 0);
477*4882a593Smuzhiyun
478*4882a593Smuzhiyun switch (octeon_bootinfo->board_type) {
479*4882a593Smuzhiyun case CVMX_BOARD_TYPE_NAO38:
480*4882a593Smuzhiyun /* Driving a 1 to GPIO 12 shuts off this board */
481*4882a593Smuzhiyun cvmx_write_csr(CVMX_GPIO_BIT_CFGX(12), 1);
482*4882a593Smuzhiyun cvmx_write_csr(CVMX_GPIO_TX_SET, 0x1000);
483*4882a593Smuzhiyun break;
484*4882a593Smuzhiyun default:
485*4882a593Smuzhiyun octeon_write_lcd("PowerOff");
486*4882a593Smuzhiyun break;
487*4882a593Smuzhiyun }
488*4882a593Smuzhiyun
489*4882a593Smuzhiyun octeon_kill_core(NULL);
490*4882a593Smuzhiyun }
491*4882a593Smuzhiyun
492*4882a593Smuzhiyun static char __read_mostly octeon_system_type[80];
493*4882a593Smuzhiyun
init_octeon_system_type(void)494*4882a593Smuzhiyun static void __init init_octeon_system_type(void)
495*4882a593Smuzhiyun {
496*4882a593Smuzhiyun char const *board_type;
497*4882a593Smuzhiyun
498*4882a593Smuzhiyun board_type = cvmx_board_type_to_string(octeon_bootinfo->board_type);
499*4882a593Smuzhiyun if (board_type == NULL) {
500*4882a593Smuzhiyun struct device_node *root;
501*4882a593Smuzhiyun int ret;
502*4882a593Smuzhiyun
503*4882a593Smuzhiyun root = of_find_node_by_path("/");
504*4882a593Smuzhiyun ret = of_property_read_string(root, "model", &board_type);
505*4882a593Smuzhiyun of_node_put(root);
506*4882a593Smuzhiyun if (ret)
507*4882a593Smuzhiyun board_type = "Unsupported Board";
508*4882a593Smuzhiyun }
509*4882a593Smuzhiyun
510*4882a593Smuzhiyun snprintf(octeon_system_type, sizeof(octeon_system_type), "%s (%s)",
511*4882a593Smuzhiyun board_type, octeon_model_get_string(read_c0_prid()));
512*4882a593Smuzhiyun }
513*4882a593Smuzhiyun
514*4882a593Smuzhiyun /**
515*4882a593Smuzhiyun * Return a string representing the system type
516*4882a593Smuzhiyun *
517*4882a593Smuzhiyun * Returns
518*4882a593Smuzhiyun */
octeon_board_type_string(void)519*4882a593Smuzhiyun const char *octeon_board_type_string(void)
520*4882a593Smuzhiyun {
521*4882a593Smuzhiyun return octeon_system_type;
522*4882a593Smuzhiyun }
523*4882a593Smuzhiyun
524*4882a593Smuzhiyun const char *get_system_type(void)
525*4882a593Smuzhiyun __attribute__ ((alias("octeon_board_type_string")));
526*4882a593Smuzhiyun
octeon_user_io_init(void)527*4882a593Smuzhiyun void octeon_user_io_init(void)
528*4882a593Smuzhiyun {
529*4882a593Smuzhiyun union octeon_cvmemctl cvmmemctl;
530*4882a593Smuzhiyun
531*4882a593Smuzhiyun /* Get the current settings for CP0_CVMMEMCTL_REG */
532*4882a593Smuzhiyun cvmmemctl.u64 = read_c0_cvmmemctl();
533*4882a593Smuzhiyun /* R/W If set, marked write-buffer entries time out the same
534*4882a593Smuzhiyun * as as other entries; if clear, marked write-buffer entries
535*4882a593Smuzhiyun * use the maximum timeout. */
536*4882a593Smuzhiyun cvmmemctl.s.dismarkwblongto = 1;
537*4882a593Smuzhiyun /* R/W If set, a merged store does not clear the write-buffer
538*4882a593Smuzhiyun * entry timeout state. */
539*4882a593Smuzhiyun cvmmemctl.s.dismrgclrwbto = 0;
540*4882a593Smuzhiyun /* R/W Two bits that are the MSBs of the resultant CVMSEG LM
541*4882a593Smuzhiyun * word location for an IOBDMA. The other 8 bits come from the
542*4882a593Smuzhiyun * SCRADDR field of the IOBDMA. */
543*4882a593Smuzhiyun cvmmemctl.s.iobdmascrmsb = 0;
544*4882a593Smuzhiyun /* R/W If set, SYNCWS and SYNCS only order marked stores; if
545*4882a593Smuzhiyun * clear, SYNCWS and SYNCS only order unmarked
546*4882a593Smuzhiyun * stores. SYNCWSMARKED has no effect when DISSYNCWS is
547*4882a593Smuzhiyun * set. */
548*4882a593Smuzhiyun cvmmemctl.s.syncwsmarked = 0;
549*4882a593Smuzhiyun /* R/W If set, SYNCWS acts as SYNCW and SYNCS acts as SYNC. */
550*4882a593Smuzhiyun cvmmemctl.s.dissyncws = 0;
551*4882a593Smuzhiyun /* R/W If set, no stall happens on write buffer full. */
552*4882a593Smuzhiyun if (OCTEON_IS_MODEL(OCTEON_CN38XX_PASS2))
553*4882a593Smuzhiyun cvmmemctl.s.diswbfst = 1;
554*4882a593Smuzhiyun else
555*4882a593Smuzhiyun cvmmemctl.s.diswbfst = 0;
556*4882a593Smuzhiyun /* R/W If set (and SX set), supervisor-level loads/stores can
557*4882a593Smuzhiyun * use XKPHYS addresses with <48>==0 */
558*4882a593Smuzhiyun cvmmemctl.s.xkmemenas = 0;
559*4882a593Smuzhiyun
560*4882a593Smuzhiyun /* R/W If set (and UX set), user-level loads/stores can use
561*4882a593Smuzhiyun * XKPHYS addresses with VA<48>==0 */
562*4882a593Smuzhiyun cvmmemctl.s.xkmemenau = 0;
563*4882a593Smuzhiyun
564*4882a593Smuzhiyun /* R/W If set (and SX set), supervisor-level loads/stores can
565*4882a593Smuzhiyun * use XKPHYS addresses with VA<48>==1 */
566*4882a593Smuzhiyun cvmmemctl.s.xkioenas = 0;
567*4882a593Smuzhiyun
568*4882a593Smuzhiyun /* R/W If set (and UX set), user-level loads/stores can use
569*4882a593Smuzhiyun * XKPHYS addresses with VA<48>==1 */
570*4882a593Smuzhiyun cvmmemctl.s.xkioenau = 0;
571*4882a593Smuzhiyun
572*4882a593Smuzhiyun /* R/W If set, all stores act as SYNCW (NOMERGE must be set
573*4882a593Smuzhiyun * when this is set) RW, reset to 0. */
574*4882a593Smuzhiyun cvmmemctl.s.allsyncw = 0;
575*4882a593Smuzhiyun
576*4882a593Smuzhiyun /* R/W If set, no stores merge, and all stores reach the
577*4882a593Smuzhiyun * coherent bus in order. */
578*4882a593Smuzhiyun cvmmemctl.s.nomerge = 0;
579*4882a593Smuzhiyun /* R/W Selects the bit in the counter used for DID time-outs 0
580*4882a593Smuzhiyun * = 231, 1 = 230, 2 = 229, 3 = 214. Actual time-out is
581*4882a593Smuzhiyun * between 1x and 2x this interval. For example, with
582*4882a593Smuzhiyun * DIDTTO=3, expiration interval is between 16K and 32K. */
583*4882a593Smuzhiyun cvmmemctl.s.didtto = 0;
584*4882a593Smuzhiyun /* R/W If set, the (mem) CSR clock never turns off. */
585*4882a593Smuzhiyun cvmmemctl.s.csrckalwys = 0;
586*4882a593Smuzhiyun /* R/W If set, mclk never turns off. */
587*4882a593Smuzhiyun cvmmemctl.s.mclkalwys = 0;
588*4882a593Smuzhiyun /* R/W Selects the bit in the counter used for write buffer
589*4882a593Smuzhiyun * flush time-outs (WBFLT+11) is the bit position in an
590*4882a593Smuzhiyun * internal counter used to determine expiration. The write
591*4882a593Smuzhiyun * buffer expires between 1x and 2x this interval. For
592*4882a593Smuzhiyun * example, with WBFLT = 0, a write buffer expires between 2K
593*4882a593Smuzhiyun * and 4K cycles after the write buffer entry is allocated. */
594*4882a593Smuzhiyun cvmmemctl.s.wbfltime = 0;
595*4882a593Smuzhiyun /* R/W If set, do not put Istream in the L2 cache. */
596*4882a593Smuzhiyun cvmmemctl.s.istrnol2 = 0;
597*4882a593Smuzhiyun
598*4882a593Smuzhiyun /*
599*4882a593Smuzhiyun * R/W The write buffer threshold. As per erratum Core-14752
600*4882a593Smuzhiyun * for CN63XX, a sc/scd might fail if the write buffer is
601*4882a593Smuzhiyun * full. Lowering WBTHRESH greatly lowers the chances of the
602*4882a593Smuzhiyun * write buffer ever being full and triggering the erratum.
603*4882a593Smuzhiyun */
604*4882a593Smuzhiyun if (OCTEON_IS_MODEL(OCTEON_CN63XX_PASS1_X))
605*4882a593Smuzhiyun cvmmemctl.s.wbthresh = 4;
606*4882a593Smuzhiyun else
607*4882a593Smuzhiyun cvmmemctl.s.wbthresh = 10;
608*4882a593Smuzhiyun
609*4882a593Smuzhiyun /* R/W If set, CVMSEG is available for loads/stores in
610*4882a593Smuzhiyun * kernel/debug mode. */
611*4882a593Smuzhiyun #if CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE > 0
612*4882a593Smuzhiyun cvmmemctl.s.cvmsegenak = 1;
613*4882a593Smuzhiyun #else
614*4882a593Smuzhiyun cvmmemctl.s.cvmsegenak = 0;
615*4882a593Smuzhiyun #endif
616*4882a593Smuzhiyun /* R/W If set, CVMSEG is available for loads/stores in
617*4882a593Smuzhiyun * supervisor mode. */
618*4882a593Smuzhiyun cvmmemctl.s.cvmsegenas = 0;
619*4882a593Smuzhiyun /* R/W If set, CVMSEG is available for loads/stores in user
620*4882a593Smuzhiyun * mode. */
621*4882a593Smuzhiyun cvmmemctl.s.cvmsegenau = 0;
622*4882a593Smuzhiyun
623*4882a593Smuzhiyun write_c0_cvmmemctl(cvmmemctl.u64);
624*4882a593Smuzhiyun
625*4882a593Smuzhiyun /* Setup of CVMSEG is done in kernel-entry-init.h */
626*4882a593Smuzhiyun if (smp_processor_id() == 0)
627*4882a593Smuzhiyun pr_notice("CVMSEG size: %d cache lines (%d bytes)\n",
628*4882a593Smuzhiyun CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE,
629*4882a593Smuzhiyun CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE * 128);
630*4882a593Smuzhiyun
631*4882a593Smuzhiyun if (octeon_has_feature(OCTEON_FEATURE_FAU)) {
632*4882a593Smuzhiyun union cvmx_iob_fau_timeout fau_timeout;
633*4882a593Smuzhiyun
634*4882a593Smuzhiyun /* Set a default for the hardware timeouts */
635*4882a593Smuzhiyun fau_timeout.u64 = 0;
636*4882a593Smuzhiyun fau_timeout.s.tout_val = 0xfff;
637*4882a593Smuzhiyun /* Disable tagwait FAU timeout */
638*4882a593Smuzhiyun fau_timeout.s.tout_enb = 0;
639*4882a593Smuzhiyun cvmx_write_csr(CVMX_IOB_FAU_TIMEOUT, fau_timeout.u64);
640*4882a593Smuzhiyun }
641*4882a593Smuzhiyun
642*4882a593Smuzhiyun if ((!OCTEON_IS_MODEL(OCTEON_CN68XX) &&
643*4882a593Smuzhiyun !OCTEON_IS_MODEL(OCTEON_CN7XXX)) ||
644*4882a593Smuzhiyun OCTEON_IS_MODEL(OCTEON_CN70XX)) {
645*4882a593Smuzhiyun union cvmx_pow_nw_tim nm_tim;
646*4882a593Smuzhiyun
647*4882a593Smuzhiyun nm_tim.u64 = 0;
648*4882a593Smuzhiyun /* 4096 cycles */
649*4882a593Smuzhiyun nm_tim.s.nw_tim = 3;
650*4882a593Smuzhiyun cvmx_write_csr(CVMX_POW_NW_TIM, nm_tim.u64);
651*4882a593Smuzhiyun }
652*4882a593Smuzhiyun
653*4882a593Smuzhiyun write_octeon_c0_icacheerr(0);
654*4882a593Smuzhiyun write_c0_derraddr1(0);
655*4882a593Smuzhiyun }
656*4882a593Smuzhiyun
657*4882a593Smuzhiyun /**
658*4882a593Smuzhiyun * Early entry point for arch setup
659*4882a593Smuzhiyun */
prom_init(void)660*4882a593Smuzhiyun void __init prom_init(void)
661*4882a593Smuzhiyun {
662*4882a593Smuzhiyun struct cvmx_sysinfo *sysinfo;
663*4882a593Smuzhiyun const char *arg;
664*4882a593Smuzhiyun char *p;
665*4882a593Smuzhiyun int i;
666*4882a593Smuzhiyun u64 t;
667*4882a593Smuzhiyun int argc;
668*4882a593Smuzhiyun #ifdef CONFIG_CAVIUM_RESERVE32
669*4882a593Smuzhiyun int64_t addr = -1;
670*4882a593Smuzhiyun #endif
671*4882a593Smuzhiyun /*
672*4882a593Smuzhiyun * The bootloader passes a pointer to the boot descriptor in
673*4882a593Smuzhiyun * $a3, this is available as fw_arg3.
674*4882a593Smuzhiyun */
675*4882a593Smuzhiyun octeon_boot_desc_ptr = (struct octeon_boot_descriptor *)fw_arg3;
676*4882a593Smuzhiyun octeon_bootinfo =
677*4882a593Smuzhiyun cvmx_phys_to_ptr(octeon_boot_desc_ptr->cvmx_desc_vaddr);
678*4882a593Smuzhiyun cvmx_bootmem_init(cvmx_phys_to_ptr(octeon_bootinfo->phy_mem_desc_addr));
679*4882a593Smuzhiyun
680*4882a593Smuzhiyun sysinfo = cvmx_sysinfo_get();
681*4882a593Smuzhiyun memset(sysinfo, 0, sizeof(*sysinfo));
682*4882a593Smuzhiyun sysinfo->system_dram_size = octeon_bootinfo->dram_size << 20;
683*4882a593Smuzhiyun sysinfo->phy_mem_desc_addr = (u64)phys_to_virt(octeon_bootinfo->phy_mem_desc_addr);
684*4882a593Smuzhiyun
685*4882a593Smuzhiyun if ((octeon_bootinfo->major_version > 1) ||
686*4882a593Smuzhiyun (octeon_bootinfo->major_version == 1 &&
687*4882a593Smuzhiyun octeon_bootinfo->minor_version >= 4))
688*4882a593Smuzhiyun cvmx_coremask_copy(&sysinfo->core_mask,
689*4882a593Smuzhiyun &octeon_bootinfo->ext_core_mask);
690*4882a593Smuzhiyun else
691*4882a593Smuzhiyun cvmx_coremask_set64(&sysinfo->core_mask,
692*4882a593Smuzhiyun octeon_bootinfo->core_mask);
693*4882a593Smuzhiyun
694*4882a593Smuzhiyun /* Some broken u-boot pass garbage in upper bits, clear them out */
695*4882a593Smuzhiyun if (!OCTEON_IS_MODEL(OCTEON_CN78XX))
696*4882a593Smuzhiyun for (i = 512; i < 1024; i++)
697*4882a593Smuzhiyun cvmx_coremask_clear_core(&sysinfo->core_mask, i);
698*4882a593Smuzhiyun
699*4882a593Smuzhiyun sysinfo->exception_base_addr = octeon_bootinfo->exception_base_addr;
700*4882a593Smuzhiyun sysinfo->cpu_clock_hz = octeon_bootinfo->eclock_hz;
701*4882a593Smuzhiyun sysinfo->dram_data_rate_hz = octeon_bootinfo->dclock_hz * 2;
702*4882a593Smuzhiyun sysinfo->board_type = octeon_bootinfo->board_type;
703*4882a593Smuzhiyun sysinfo->board_rev_major = octeon_bootinfo->board_rev_major;
704*4882a593Smuzhiyun sysinfo->board_rev_minor = octeon_bootinfo->board_rev_minor;
705*4882a593Smuzhiyun memcpy(sysinfo->mac_addr_base, octeon_bootinfo->mac_addr_base,
706*4882a593Smuzhiyun sizeof(sysinfo->mac_addr_base));
707*4882a593Smuzhiyun sysinfo->mac_addr_count = octeon_bootinfo->mac_addr_count;
708*4882a593Smuzhiyun memcpy(sysinfo->board_serial_number,
709*4882a593Smuzhiyun octeon_bootinfo->board_serial_number,
710*4882a593Smuzhiyun sizeof(sysinfo->board_serial_number));
711*4882a593Smuzhiyun sysinfo->compact_flash_common_base_addr =
712*4882a593Smuzhiyun octeon_bootinfo->compact_flash_common_base_addr;
713*4882a593Smuzhiyun sysinfo->compact_flash_attribute_base_addr =
714*4882a593Smuzhiyun octeon_bootinfo->compact_flash_attribute_base_addr;
715*4882a593Smuzhiyun sysinfo->led_display_base_addr = octeon_bootinfo->led_display_base_addr;
716*4882a593Smuzhiyun sysinfo->dfa_ref_clock_hz = octeon_bootinfo->dfa_ref_clock_hz;
717*4882a593Smuzhiyun sysinfo->bootloader_config_flags = octeon_bootinfo->config_flags;
718*4882a593Smuzhiyun
719*4882a593Smuzhiyun if (OCTEON_IS_OCTEON2()) {
720*4882a593Smuzhiyun /* I/O clock runs at a different rate than the CPU. */
721*4882a593Smuzhiyun union cvmx_mio_rst_boot rst_boot;
722*4882a593Smuzhiyun rst_boot.u64 = cvmx_read_csr(CVMX_MIO_RST_BOOT);
723*4882a593Smuzhiyun octeon_io_clock_rate = 50000000 * rst_boot.s.pnr_mul;
724*4882a593Smuzhiyun } else if (OCTEON_IS_OCTEON3()) {
725*4882a593Smuzhiyun /* I/O clock runs at a different rate than the CPU. */
726*4882a593Smuzhiyun union cvmx_rst_boot rst_boot;
727*4882a593Smuzhiyun rst_boot.u64 = cvmx_read_csr(CVMX_RST_BOOT);
728*4882a593Smuzhiyun octeon_io_clock_rate = 50000000 * rst_boot.s.pnr_mul;
729*4882a593Smuzhiyun } else {
730*4882a593Smuzhiyun octeon_io_clock_rate = sysinfo->cpu_clock_hz;
731*4882a593Smuzhiyun }
732*4882a593Smuzhiyun
733*4882a593Smuzhiyun t = read_c0_cvmctl();
734*4882a593Smuzhiyun if ((t & (1ull << 27)) == 0) {
735*4882a593Smuzhiyun /*
736*4882a593Smuzhiyun * Setup the multiplier save/restore code if
737*4882a593Smuzhiyun * CvmCtl[NOMUL] clear.
738*4882a593Smuzhiyun */
739*4882a593Smuzhiyun void *save;
740*4882a593Smuzhiyun void *save_end;
741*4882a593Smuzhiyun void *restore;
742*4882a593Smuzhiyun void *restore_end;
743*4882a593Smuzhiyun int save_len;
744*4882a593Smuzhiyun int restore_len;
745*4882a593Smuzhiyun int save_max = (char *)octeon_mult_save_end -
746*4882a593Smuzhiyun (char *)octeon_mult_save;
747*4882a593Smuzhiyun int restore_max = (char *)octeon_mult_restore_end -
748*4882a593Smuzhiyun (char *)octeon_mult_restore;
749*4882a593Smuzhiyun if (current_cpu_data.cputype == CPU_CAVIUM_OCTEON3) {
750*4882a593Smuzhiyun save = octeon_mult_save3;
751*4882a593Smuzhiyun save_end = octeon_mult_save3_end;
752*4882a593Smuzhiyun restore = octeon_mult_restore3;
753*4882a593Smuzhiyun restore_end = octeon_mult_restore3_end;
754*4882a593Smuzhiyun } else {
755*4882a593Smuzhiyun save = octeon_mult_save2;
756*4882a593Smuzhiyun save_end = octeon_mult_save2_end;
757*4882a593Smuzhiyun restore = octeon_mult_restore2;
758*4882a593Smuzhiyun restore_end = octeon_mult_restore2_end;
759*4882a593Smuzhiyun }
760*4882a593Smuzhiyun save_len = (char *)save_end - (char *)save;
761*4882a593Smuzhiyun restore_len = (char *)restore_end - (char *)restore;
762*4882a593Smuzhiyun if (!WARN_ON(save_len > save_max ||
763*4882a593Smuzhiyun restore_len > restore_max)) {
764*4882a593Smuzhiyun memcpy(octeon_mult_save, save, save_len);
765*4882a593Smuzhiyun memcpy(octeon_mult_restore, restore, restore_len);
766*4882a593Smuzhiyun }
767*4882a593Smuzhiyun }
768*4882a593Smuzhiyun
769*4882a593Smuzhiyun /*
770*4882a593Smuzhiyun * Only enable the LED controller if we're running on a CN38XX, CN58XX,
771*4882a593Smuzhiyun * or CN56XX. The CN30XX and CN31XX don't have an LED controller.
772*4882a593Smuzhiyun */
773*4882a593Smuzhiyun if (!octeon_is_simulation() &&
774*4882a593Smuzhiyun octeon_has_feature(OCTEON_FEATURE_LED_CONTROLLER)) {
775*4882a593Smuzhiyun cvmx_write_csr(CVMX_LED_EN, 0);
776*4882a593Smuzhiyun cvmx_write_csr(CVMX_LED_PRT, 0);
777*4882a593Smuzhiyun cvmx_write_csr(CVMX_LED_DBG, 0);
778*4882a593Smuzhiyun cvmx_write_csr(CVMX_LED_PRT_FMT, 0);
779*4882a593Smuzhiyun cvmx_write_csr(CVMX_LED_UDD_CNTX(0), 32);
780*4882a593Smuzhiyun cvmx_write_csr(CVMX_LED_UDD_CNTX(1), 32);
781*4882a593Smuzhiyun cvmx_write_csr(CVMX_LED_UDD_DATX(0), 0);
782*4882a593Smuzhiyun cvmx_write_csr(CVMX_LED_UDD_DATX(1), 0);
783*4882a593Smuzhiyun cvmx_write_csr(CVMX_LED_EN, 1);
784*4882a593Smuzhiyun }
785*4882a593Smuzhiyun #ifdef CONFIG_CAVIUM_RESERVE32
786*4882a593Smuzhiyun /*
787*4882a593Smuzhiyun * We need to temporarily allocate all memory in the reserve32
788*4882a593Smuzhiyun * region. This makes sure the kernel doesn't allocate this
789*4882a593Smuzhiyun * memory when it is getting memory from the
790*4882a593Smuzhiyun * bootloader. Later, after the memory allocations are
791*4882a593Smuzhiyun * complete, the reserve32 will be freed.
792*4882a593Smuzhiyun *
793*4882a593Smuzhiyun * Allocate memory for RESERVED32 aligned on 2MB boundary. This
794*4882a593Smuzhiyun * is in case we later use hugetlb entries with it.
795*4882a593Smuzhiyun */
796*4882a593Smuzhiyun addr = cvmx_bootmem_phy_named_block_alloc(CONFIG_CAVIUM_RESERVE32 << 20,
797*4882a593Smuzhiyun 0, 0, 2 << 20,
798*4882a593Smuzhiyun "CAVIUM_RESERVE32", 0);
799*4882a593Smuzhiyun if (addr < 0)
800*4882a593Smuzhiyun pr_err("Failed to allocate CAVIUM_RESERVE32 memory area\n");
801*4882a593Smuzhiyun else
802*4882a593Smuzhiyun octeon_reserve32_memory = addr;
803*4882a593Smuzhiyun #endif
804*4882a593Smuzhiyun
805*4882a593Smuzhiyun #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2
806*4882a593Smuzhiyun if (cvmx_read_csr(CVMX_L2D_FUS3) & (3ull << 34)) {
807*4882a593Smuzhiyun pr_info("Skipping L2 locking due to reduced L2 cache size\n");
808*4882a593Smuzhiyun } else {
809*4882a593Smuzhiyun uint32_t __maybe_unused ebase = read_c0_ebase() & 0x3ffff000;
810*4882a593Smuzhiyun #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_TLB
811*4882a593Smuzhiyun /* TLB refill */
812*4882a593Smuzhiyun cvmx_l2c_lock_mem_region(ebase, 0x100);
813*4882a593Smuzhiyun #endif
814*4882a593Smuzhiyun #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_EXCEPTION
815*4882a593Smuzhiyun /* General exception */
816*4882a593Smuzhiyun cvmx_l2c_lock_mem_region(ebase + 0x180, 0x80);
817*4882a593Smuzhiyun #endif
818*4882a593Smuzhiyun #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_LOW_LEVEL_INTERRUPT
819*4882a593Smuzhiyun /* Interrupt handler */
820*4882a593Smuzhiyun cvmx_l2c_lock_mem_region(ebase + 0x200, 0x80);
821*4882a593Smuzhiyun #endif
822*4882a593Smuzhiyun #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_INTERRUPT
823*4882a593Smuzhiyun cvmx_l2c_lock_mem_region(__pa_symbol(handle_int), 0x100);
824*4882a593Smuzhiyun cvmx_l2c_lock_mem_region(__pa_symbol(plat_irq_dispatch), 0x80);
825*4882a593Smuzhiyun #endif
826*4882a593Smuzhiyun #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_MEMCPY
827*4882a593Smuzhiyun cvmx_l2c_lock_mem_region(__pa_symbol(memcpy), 0x480);
828*4882a593Smuzhiyun #endif
829*4882a593Smuzhiyun }
830*4882a593Smuzhiyun #endif
831*4882a593Smuzhiyun
832*4882a593Smuzhiyun octeon_check_cpu_bist();
833*4882a593Smuzhiyun
834*4882a593Smuzhiyun octeon_uart = octeon_get_boot_uart();
835*4882a593Smuzhiyun
836*4882a593Smuzhiyun #ifdef CONFIG_SMP
837*4882a593Smuzhiyun octeon_write_lcd("LinuxSMP");
838*4882a593Smuzhiyun #else
839*4882a593Smuzhiyun octeon_write_lcd("Linux");
840*4882a593Smuzhiyun #endif
841*4882a593Smuzhiyun
842*4882a593Smuzhiyun octeon_setup_delays();
843*4882a593Smuzhiyun
844*4882a593Smuzhiyun /*
845*4882a593Smuzhiyun * BIST should always be enabled when doing a soft reset. L2
846*4882a593Smuzhiyun * Cache locking for instance is not cleared unless BIST is
847*4882a593Smuzhiyun * enabled. Unfortunately due to a chip errata G-200 for
848*4882a593Smuzhiyun * Cn38XX and CN31XX, BIST must be disabled on these parts.
849*4882a593Smuzhiyun */
850*4882a593Smuzhiyun if (OCTEON_IS_MODEL(OCTEON_CN38XX_PASS2) ||
851*4882a593Smuzhiyun OCTEON_IS_MODEL(OCTEON_CN31XX))
852*4882a593Smuzhiyun cvmx_write_csr(CVMX_CIU_SOFT_BIST, 0);
853*4882a593Smuzhiyun else
854*4882a593Smuzhiyun cvmx_write_csr(CVMX_CIU_SOFT_BIST, 1);
855*4882a593Smuzhiyun
856*4882a593Smuzhiyun /* Default to 64MB in the simulator to speed things up */
857*4882a593Smuzhiyun if (octeon_is_simulation())
858*4882a593Smuzhiyun max_memory = 64ull << 20;
859*4882a593Smuzhiyun
860*4882a593Smuzhiyun arg = strstr(arcs_cmdline, "mem=");
861*4882a593Smuzhiyun if (arg) {
862*4882a593Smuzhiyun max_memory = memparse(arg + 4, &p);
863*4882a593Smuzhiyun if (max_memory == 0)
864*4882a593Smuzhiyun max_memory = 32ull << 30;
865*4882a593Smuzhiyun if (*p == '@')
866*4882a593Smuzhiyun reserve_low_mem = memparse(p + 1, &p);
867*4882a593Smuzhiyun }
868*4882a593Smuzhiyun
869*4882a593Smuzhiyun arcs_cmdline[0] = 0;
870*4882a593Smuzhiyun argc = octeon_boot_desc_ptr->argc;
871*4882a593Smuzhiyun for (i = 0; i < argc; i++) {
872*4882a593Smuzhiyun const char *arg =
873*4882a593Smuzhiyun cvmx_phys_to_ptr(octeon_boot_desc_ptr->argv[i]);
874*4882a593Smuzhiyun if ((strncmp(arg, "MEM=", 4) == 0) ||
875*4882a593Smuzhiyun (strncmp(arg, "mem=", 4) == 0)) {
876*4882a593Smuzhiyun max_memory = memparse(arg + 4, &p);
877*4882a593Smuzhiyun if (max_memory == 0)
878*4882a593Smuzhiyun max_memory = 32ull << 30;
879*4882a593Smuzhiyun if (*p == '@')
880*4882a593Smuzhiyun reserve_low_mem = memparse(p + 1, &p);
881*4882a593Smuzhiyun #ifdef CONFIG_KEXEC
882*4882a593Smuzhiyun } else if (strncmp(arg, "crashkernel=", 12) == 0) {
883*4882a593Smuzhiyun crashk_size = memparse(arg+12, &p);
884*4882a593Smuzhiyun if (*p == '@')
885*4882a593Smuzhiyun crashk_base = memparse(p+1, &p);
886*4882a593Smuzhiyun strcat(arcs_cmdline, " ");
887*4882a593Smuzhiyun strcat(arcs_cmdline, arg);
888*4882a593Smuzhiyun /*
889*4882a593Smuzhiyun * To do: switch parsing to new style, something like:
890*4882a593Smuzhiyun * parse_crashkernel(arg, sysinfo->system_dram_size,
891*4882a593Smuzhiyun * &crashk_size, &crashk_base);
892*4882a593Smuzhiyun */
893*4882a593Smuzhiyun #endif
894*4882a593Smuzhiyun } else if (strlen(arcs_cmdline) + strlen(arg) + 1 <
895*4882a593Smuzhiyun sizeof(arcs_cmdline) - 1) {
896*4882a593Smuzhiyun strcat(arcs_cmdline, " ");
897*4882a593Smuzhiyun strcat(arcs_cmdline, arg);
898*4882a593Smuzhiyun }
899*4882a593Smuzhiyun }
900*4882a593Smuzhiyun
901*4882a593Smuzhiyun if (strstr(arcs_cmdline, "console=") == NULL) {
902*4882a593Smuzhiyun if (octeon_uart == 1)
903*4882a593Smuzhiyun strcat(arcs_cmdline, " console=ttyS1,115200");
904*4882a593Smuzhiyun else
905*4882a593Smuzhiyun strcat(arcs_cmdline, " console=ttyS0,115200");
906*4882a593Smuzhiyun }
907*4882a593Smuzhiyun
908*4882a593Smuzhiyun mips_hpt_frequency = octeon_get_clock_rate();
909*4882a593Smuzhiyun
910*4882a593Smuzhiyun octeon_init_cvmcount();
911*4882a593Smuzhiyun
912*4882a593Smuzhiyun _machine_restart = octeon_restart;
913*4882a593Smuzhiyun _machine_halt = octeon_halt;
914*4882a593Smuzhiyun
915*4882a593Smuzhiyun #ifdef CONFIG_KEXEC
916*4882a593Smuzhiyun _machine_kexec_shutdown = octeon_shutdown;
917*4882a593Smuzhiyun _machine_crash_shutdown = octeon_crash_shutdown;
918*4882a593Smuzhiyun _machine_kexec_prepare = octeon_kexec_prepare;
919*4882a593Smuzhiyun #ifdef CONFIG_SMP
920*4882a593Smuzhiyun _crash_smp_send_stop = octeon_crash_smp_send_stop;
921*4882a593Smuzhiyun #endif
922*4882a593Smuzhiyun #endif
923*4882a593Smuzhiyun
924*4882a593Smuzhiyun octeon_user_io_init();
925*4882a593Smuzhiyun octeon_setup_smp();
926*4882a593Smuzhiyun }
927*4882a593Smuzhiyun
928*4882a593Smuzhiyun /* Exclude a single page from the regions obtained in plat_mem_setup. */
929*4882a593Smuzhiyun #ifndef CONFIG_CRASH_DUMP
memory_exclude_page(u64 addr,u64 * mem,u64 * size)930*4882a593Smuzhiyun static __init void memory_exclude_page(u64 addr, u64 *mem, u64 *size)
931*4882a593Smuzhiyun {
932*4882a593Smuzhiyun if (addr > *mem && addr < *mem + *size) {
933*4882a593Smuzhiyun u64 inc = addr - *mem;
934*4882a593Smuzhiyun memblock_add(*mem, inc);
935*4882a593Smuzhiyun *mem += inc;
936*4882a593Smuzhiyun *size -= inc;
937*4882a593Smuzhiyun }
938*4882a593Smuzhiyun
939*4882a593Smuzhiyun if (addr == *mem && *size > PAGE_SIZE) {
940*4882a593Smuzhiyun *mem += PAGE_SIZE;
941*4882a593Smuzhiyun *size -= PAGE_SIZE;
942*4882a593Smuzhiyun }
943*4882a593Smuzhiyun }
944*4882a593Smuzhiyun #endif /* CONFIG_CRASH_DUMP */
945*4882a593Smuzhiyun
fw_init_cmdline(void)946*4882a593Smuzhiyun void __init fw_init_cmdline(void)
947*4882a593Smuzhiyun {
948*4882a593Smuzhiyun int i;
949*4882a593Smuzhiyun
950*4882a593Smuzhiyun octeon_boot_desc_ptr = (struct octeon_boot_descriptor *)fw_arg3;
951*4882a593Smuzhiyun for (i = 0; i < octeon_boot_desc_ptr->argc; i++) {
952*4882a593Smuzhiyun const char *arg =
953*4882a593Smuzhiyun cvmx_phys_to_ptr(octeon_boot_desc_ptr->argv[i]);
954*4882a593Smuzhiyun if (strlen(arcs_cmdline) + strlen(arg) + 1 <
955*4882a593Smuzhiyun sizeof(arcs_cmdline) - 1) {
956*4882a593Smuzhiyun strcat(arcs_cmdline, " ");
957*4882a593Smuzhiyun strcat(arcs_cmdline, arg);
958*4882a593Smuzhiyun }
959*4882a593Smuzhiyun }
960*4882a593Smuzhiyun }
961*4882a593Smuzhiyun
plat_get_fdt(void)962*4882a593Smuzhiyun void __init *plat_get_fdt(void)
963*4882a593Smuzhiyun {
964*4882a593Smuzhiyun octeon_bootinfo =
965*4882a593Smuzhiyun cvmx_phys_to_ptr(octeon_boot_desc_ptr->cvmx_desc_vaddr);
966*4882a593Smuzhiyun return phys_to_virt(octeon_bootinfo->fdt_addr);
967*4882a593Smuzhiyun }
968*4882a593Smuzhiyun
plat_mem_setup(void)969*4882a593Smuzhiyun void __init plat_mem_setup(void)
970*4882a593Smuzhiyun {
971*4882a593Smuzhiyun uint64_t mem_alloc_size;
972*4882a593Smuzhiyun uint64_t total;
973*4882a593Smuzhiyun uint64_t crashk_end;
974*4882a593Smuzhiyun #ifndef CONFIG_CRASH_DUMP
975*4882a593Smuzhiyun int64_t memory;
976*4882a593Smuzhiyun uint64_t kernel_start;
977*4882a593Smuzhiyun uint64_t kernel_size;
978*4882a593Smuzhiyun #endif
979*4882a593Smuzhiyun
980*4882a593Smuzhiyun total = 0;
981*4882a593Smuzhiyun crashk_end = 0;
982*4882a593Smuzhiyun
983*4882a593Smuzhiyun /*
984*4882a593Smuzhiyun * The Mips memory init uses the first memory location for
985*4882a593Smuzhiyun * some memory vectors. When SPARSEMEM is in use, it doesn't
986*4882a593Smuzhiyun * verify that the size is big enough for the final
987*4882a593Smuzhiyun * vectors. Making the smallest chuck 4MB seems to be enough
988*4882a593Smuzhiyun * to consistently work.
989*4882a593Smuzhiyun */
990*4882a593Smuzhiyun mem_alloc_size = 4 << 20;
991*4882a593Smuzhiyun if (mem_alloc_size > max_memory)
992*4882a593Smuzhiyun mem_alloc_size = max_memory;
993*4882a593Smuzhiyun
994*4882a593Smuzhiyun /* Crashkernel ignores bootmem list. It relies on mem=X@Y option */
995*4882a593Smuzhiyun #ifdef CONFIG_CRASH_DUMP
996*4882a593Smuzhiyun memblock_add(reserve_low_mem, max_memory);
997*4882a593Smuzhiyun total += max_memory;
998*4882a593Smuzhiyun #else
999*4882a593Smuzhiyun #ifdef CONFIG_KEXEC
1000*4882a593Smuzhiyun if (crashk_size > 0) {
1001*4882a593Smuzhiyun memblock_add(crashk_base, crashk_size);
1002*4882a593Smuzhiyun crashk_end = crashk_base + crashk_size;
1003*4882a593Smuzhiyun }
1004*4882a593Smuzhiyun #endif
1005*4882a593Smuzhiyun /*
1006*4882a593Smuzhiyun * When allocating memory, we want incrementing addresses,
1007*4882a593Smuzhiyun * which is handled by memblock
1008*4882a593Smuzhiyun */
1009*4882a593Smuzhiyun cvmx_bootmem_lock();
1010*4882a593Smuzhiyun while (total < max_memory) {
1011*4882a593Smuzhiyun memory = cvmx_bootmem_phy_alloc(mem_alloc_size,
1012*4882a593Smuzhiyun __pa_symbol(&_end), -1,
1013*4882a593Smuzhiyun 0x100000,
1014*4882a593Smuzhiyun CVMX_BOOTMEM_FLAG_NO_LOCKING);
1015*4882a593Smuzhiyun if (memory >= 0) {
1016*4882a593Smuzhiyun u64 size = mem_alloc_size;
1017*4882a593Smuzhiyun #ifdef CONFIG_KEXEC
1018*4882a593Smuzhiyun uint64_t end;
1019*4882a593Smuzhiyun #endif
1020*4882a593Smuzhiyun
1021*4882a593Smuzhiyun /*
1022*4882a593Smuzhiyun * exclude a page at the beginning and end of
1023*4882a593Smuzhiyun * the 256MB PCIe 'hole' so the kernel will not
1024*4882a593Smuzhiyun * try to allocate multi-page buffers that
1025*4882a593Smuzhiyun * span the discontinuity.
1026*4882a593Smuzhiyun */
1027*4882a593Smuzhiyun memory_exclude_page(CVMX_PCIE_BAR1_PHYS_BASE,
1028*4882a593Smuzhiyun &memory, &size);
1029*4882a593Smuzhiyun memory_exclude_page(CVMX_PCIE_BAR1_PHYS_BASE +
1030*4882a593Smuzhiyun CVMX_PCIE_BAR1_PHYS_SIZE,
1031*4882a593Smuzhiyun &memory, &size);
1032*4882a593Smuzhiyun #ifdef CONFIG_KEXEC
1033*4882a593Smuzhiyun end = memory + mem_alloc_size;
1034*4882a593Smuzhiyun
1035*4882a593Smuzhiyun /*
1036*4882a593Smuzhiyun * This function automatically merges address regions
1037*4882a593Smuzhiyun * next to each other if they are received in
1038*4882a593Smuzhiyun * incrementing order
1039*4882a593Smuzhiyun */
1040*4882a593Smuzhiyun if (memory < crashk_base && end > crashk_end) {
1041*4882a593Smuzhiyun /* region is fully in */
1042*4882a593Smuzhiyun memblock_add(memory, crashk_base - memory);
1043*4882a593Smuzhiyun total += crashk_base - memory;
1044*4882a593Smuzhiyun memblock_add(crashk_end, end - crashk_end);
1045*4882a593Smuzhiyun total += end - crashk_end;
1046*4882a593Smuzhiyun continue;
1047*4882a593Smuzhiyun }
1048*4882a593Smuzhiyun
1049*4882a593Smuzhiyun if (memory >= crashk_base && end <= crashk_end)
1050*4882a593Smuzhiyun /*
1051*4882a593Smuzhiyun * Entire memory region is within the new
1052*4882a593Smuzhiyun * kernel's memory, ignore it.
1053*4882a593Smuzhiyun */
1054*4882a593Smuzhiyun continue;
1055*4882a593Smuzhiyun
1056*4882a593Smuzhiyun if (memory > crashk_base && memory < crashk_end &&
1057*4882a593Smuzhiyun end > crashk_end) {
1058*4882a593Smuzhiyun /*
1059*4882a593Smuzhiyun * Overlap with the beginning of the region,
1060*4882a593Smuzhiyun * reserve the beginning.
1061*4882a593Smuzhiyun */
1062*4882a593Smuzhiyun mem_alloc_size -= crashk_end - memory;
1063*4882a593Smuzhiyun memory = crashk_end;
1064*4882a593Smuzhiyun } else if (memory < crashk_base && end > crashk_base &&
1065*4882a593Smuzhiyun end < crashk_end)
1066*4882a593Smuzhiyun /*
1067*4882a593Smuzhiyun * Overlap with the beginning of the region,
1068*4882a593Smuzhiyun * chop of end.
1069*4882a593Smuzhiyun */
1070*4882a593Smuzhiyun mem_alloc_size -= end - crashk_base;
1071*4882a593Smuzhiyun #endif
1072*4882a593Smuzhiyun memblock_add(memory, mem_alloc_size);
1073*4882a593Smuzhiyun total += mem_alloc_size;
1074*4882a593Smuzhiyun /* Recovering mem_alloc_size */
1075*4882a593Smuzhiyun mem_alloc_size = 4 << 20;
1076*4882a593Smuzhiyun } else {
1077*4882a593Smuzhiyun break;
1078*4882a593Smuzhiyun }
1079*4882a593Smuzhiyun }
1080*4882a593Smuzhiyun cvmx_bootmem_unlock();
1081*4882a593Smuzhiyun /* Add the memory region for the kernel. */
1082*4882a593Smuzhiyun kernel_start = (unsigned long) _text;
1083*4882a593Smuzhiyun kernel_size = _end - _text;
1084*4882a593Smuzhiyun
1085*4882a593Smuzhiyun /* Adjust for physical offset. */
1086*4882a593Smuzhiyun kernel_start &= ~0xffffffff80000000ULL;
1087*4882a593Smuzhiyun memblock_add(kernel_start, kernel_size);
1088*4882a593Smuzhiyun #endif /* CONFIG_CRASH_DUMP */
1089*4882a593Smuzhiyun
1090*4882a593Smuzhiyun #ifdef CONFIG_CAVIUM_RESERVE32
1091*4882a593Smuzhiyun /*
1092*4882a593Smuzhiyun * Now that we've allocated the kernel memory it is safe to
1093*4882a593Smuzhiyun * free the reserved region. We free it here so that builtin
1094*4882a593Smuzhiyun * drivers can use the memory.
1095*4882a593Smuzhiyun */
1096*4882a593Smuzhiyun if (octeon_reserve32_memory)
1097*4882a593Smuzhiyun cvmx_bootmem_free_named("CAVIUM_RESERVE32");
1098*4882a593Smuzhiyun #endif /* CONFIG_CAVIUM_RESERVE32 */
1099*4882a593Smuzhiyun
1100*4882a593Smuzhiyun if (total == 0)
1101*4882a593Smuzhiyun panic("Unable to allocate memory from "
1102*4882a593Smuzhiyun "cvmx_bootmem_phy_alloc");
1103*4882a593Smuzhiyun }
1104*4882a593Smuzhiyun
1105*4882a593Smuzhiyun /*
1106*4882a593Smuzhiyun * Emit one character to the boot UART. Exported for use by the
1107*4882a593Smuzhiyun * watchdog timer.
1108*4882a593Smuzhiyun */
prom_putchar(char c)1109*4882a593Smuzhiyun void prom_putchar(char c)
1110*4882a593Smuzhiyun {
1111*4882a593Smuzhiyun uint64_t lsrval;
1112*4882a593Smuzhiyun
1113*4882a593Smuzhiyun /* Spin until there is room */
1114*4882a593Smuzhiyun do {
1115*4882a593Smuzhiyun lsrval = cvmx_read_csr(CVMX_MIO_UARTX_LSR(octeon_uart));
1116*4882a593Smuzhiyun } while ((lsrval & 0x20) == 0);
1117*4882a593Smuzhiyun
1118*4882a593Smuzhiyun /* Write the byte */
1119*4882a593Smuzhiyun cvmx_write_csr(CVMX_MIO_UARTX_THR(octeon_uart), c & 0xffull);
1120*4882a593Smuzhiyun }
1121*4882a593Smuzhiyun EXPORT_SYMBOL(prom_putchar);
1122*4882a593Smuzhiyun
prom_free_prom_memory(void)1123*4882a593Smuzhiyun void __init prom_free_prom_memory(void)
1124*4882a593Smuzhiyun {
1125*4882a593Smuzhiyun if (OCTEON_IS_MODEL(OCTEON_CN6XXX)) {
1126*4882a593Smuzhiyun /* Check for presence of Core-14449 fix. */
1127*4882a593Smuzhiyun u32 insn;
1128*4882a593Smuzhiyun u32 *foo;
1129*4882a593Smuzhiyun
1130*4882a593Smuzhiyun foo = &insn;
1131*4882a593Smuzhiyun
1132*4882a593Smuzhiyun asm volatile("# before" : : : "memory");
1133*4882a593Smuzhiyun prefetch(foo);
1134*4882a593Smuzhiyun asm volatile(
1135*4882a593Smuzhiyun ".set push\n\t"
1136*4882a593Smuzhiyun ".set noreorder\n\t"
1137*4882a593Smuzhiyun "bal 1f\n\t"
1138*4882a593Smuzhiyun "nop\n"
1139*4882a593Smuzhiyun "1:\tlw %0,-12($31)\n\t"
1140*4882a593Smuzhiyun ".set pop\n\t"
1141*4882a593Smuzhiyun : "=r" (insn) : : "$31", "memory");
1142*4882a593Smuzhiyun
1143*4882a593Smuzhiyun if ((insn >> 26) != 0x33)
1144*4882a593Smuzhiyun panic("No PREF instruction at Core-14449 probe point.");
1145*4882a593Smuzhiyun
1146*4882a593Smuzhiyun if (((insn >> 16) & 0x1f) != 28)
1147*4882a593Smuzhiyun panic("OCTEON II DCache prefetch workaround not in place (%04x).\n"
1148*4882a593Smuzhiyun "Please build kernel with proper options (CONFIG_CAVIUM_CN63XXP1).",
1149*4882a593Smuzhiyun insn);
1150*4882a593Smuzhiyun }
1151*4882a593Smuzhiyun }
1152*4882a593Smuzhiyun
1153*4882a593Smuzhiyun void __init octeon_fill_mac_addresses(void);
1154*4882a593Smuzhiyun
device_tree_init(void)1155*4882a593Smuzhiyun void __init device_tree_init(void)
1156*4882a593Smuzhiyun {
1157*4882a593Smuzhiyun const void *fdt;
1158*4882a593Smuzhiyun bool do_prune;
1159*4882a593Smuzhiyun bool fill_mac;
1160*4882a593Smuzhiyun
1161*4882a593Smuzhiyun #ifdef CONFIG_MIPS_ELF_APPENDED_DTB
1162*4882a593Smuzhiyun if (!fdt_check_header(&__appended_dtb)) {
1163*4882a593Smuzhiyun fdt = &__appended_dtb;
1164*4882a593Smuzhiyun do_prune = false;
1165*4882a593Smuzhiyun fill_mac = true;
1166*4882a593Smuzhiyun pr_info("Using appended Device Tree.\n");
1167*4882a593Smuzhiyun } else
1168*4882a593Smuzhiyun #endif
1169*4882a593Smuzhiyun if (octeon_bootinfo->minor_version >= 3 && octeon_bootinfo->fdt_addr) {
1170*4882a593Smuzhiyun fdt = phys_to_virt(octeon_bootinfo->fdt_addr);
1171*4882a593Smuzhiyun if (fdt_check_header(fdt))
1172*4882a593Smuzhiyun panic("Corrupt Device Tree passed to kernel.");
1173*4882a593Smuzhiyun do_prune = false;
1174*4882a593Smuzhiyun fill_mac = false;
1175*4882a593Smuzhiyun pr_info("Using passed Device Tree.\n");
1176*4882a593Smuzhiyun } else if (OCTEON_IS_MODEL(OCTEON_CN68XX)) {
1177*4882a593Smuzhiyun fdt = &__dtb_octeon_68xx_begin;
1178*4882a593Smuzhiyun do_prune = true;
1179*4882a593Smuzhiyun fill_mac = true;
1180*4882a593Smuzhiyun } else {
1181*4882a593Smuzhiyun fdt = &__dtb_octeon_3xxx_begin;
1182*4882a593Smuzhiyun do_prune = true;
1183*4882a593Smuzhiyun fill_mac = true;
1184*4882a593Smuzhiyun }
1185*4882a593Smuzhiyun
1186*4882a593Smuzhiyun initial_boot_params = (void *)fdt;
1187*4882a593Smuzhiyun
1188*4882a593Smuzhiyun if (do_prune) {
1189*4882a593Smuzhiyun octeon_prune_device_tree();
1190*4882a593Smuzhiyun pr_info("Using internal Device Tree.\n");
1191*4882a593Smuzhiyun }
1192*4882a593Smuzhiyun if (fill_mac)
1193*4882a593Smuzhiyun octeon_fill_mac_addresses();
1194*4882a593Smuzhiyun unflatten_and_copy_device_tree();
1195*4882a593Smuzhiyun init_octeon_system_type();
1196*4882a593Smuzhiyun }
1197*4882a593Smuzhiyun
1198*4882a593Smuzhiyun static int __initdata disable_octeon_edac_p;
1199*4882a593Smuzhiyun
disable_octeon_edac(char * str)1200*4882a593Smuzhiyun static int __init disable_octeon_edac(char *str)
1201*4882a593Smuzhiyun {
1202*4882a593Smuzhiyun disable_octeon_edac_p = 1;
1203*4882a593Smuzhiyun return 0;
1204*4882a593Smuzhiyun }
1205*4882a593Smuzhiyun early_param("disable_octeon_edac", disable_octeon_edac);
1206*4882a593Smuzhiyun
1207*4882a593Smuzhiyun static char *edac_device_names[] = {
1208*4882a593Smuzhiyun "octeon_l2c_edac",
1209*4882a593Smuzhiyun "octeon_pc_edac",
1210*4882a593Smuzhiyun };
1211*4882a593Smuzhiyun
edac_devinit(void)1212*4882a593Smuzhiyun static int __init edac_devinit(void)
1213*4882a593Smuzhiyun {
1214*4882a593Smuzhiyun struct platform_device *dev;
1215*4882a593Smuzhiyun int i, err = 0;
1216*4882a593Smuzhiyun int num_lmc;
1217*4882a593Smuzhiyun char *name;
1218*4882a593Smuzhiyun
1219*4882a593Smuzhiyun if (disable_octeon_edac_p)
1220*4882a593Smuzhiyun return 0;
1221*4882a593Smuzhiyun
1222*4882a593Smuzhiyun for (i = 0; i < ARRAY_SIZE(edac_device_names); i++) {
1223*4882a593Smuzhiyun name = edac_device_names[i];
1224*4882a593Smuzhiyun dev = platform_device_register_simple(name, -1, NULL, 0);
1225*4882a593Smuzhiyun if (IS_ERR(dev)) {
1226*4882a593Smuzhiyun pr_err("Registration of %s failed!\n", name);
1227*4882a593Smuzhiyun err = PTR_ERR(dev);
1228*4882a593Smuzhiyun }
1229*4882a593Smuzhiyun }
1230*4882a593Smuzhiyun
1231*4882a593Smuzhiyun num_lmc = OCTEON_IS_MODEL(OCTEON_CN68XX) ? 4 :
1232*4882a593Smuzhiyun (OCTEON_IS_MODEL(OCTEON_CN56XX) ? 2 : 1);
1233*4882a593Smuzhiyun for (i = 0; i < num_lmc; i++) {
1234*4882a593Smuzhiyun dev = platform_device_register_simple("octeon_lmc_edac",
1235*4882a593Smuzhiyun i, NULL, 0);
1236*4882a593Smuzhiyun if (IS_ERR(dev)) {
1237*4882a593Smuzhiyun pr_err("Registration of octeon_lmc_edac %d failed!\n", i);
1238*4882a593Smuzhiyun err = PTR_ERR(dev);
1239*4882a593Smuzhiyun }
1240*4882a593Smuzhiyun }
1241*4882a593Smuzhiyun
1242*4882a593Smuzhiyun return err;
1243*4882a593Smuzhiyun }
1244*4882a593Smuzhiyun device_initcall(edac_devinit);
1245*4882a593Smuzhiyun
1246*4882a593Smuzhiyun static void __initdata *octeon_dummy_iospace;
1247*4882a593Smuzhiyun
octeon_no_pci_init(void)1248*4882a593Smuzhiyun static int __init octeon_no_pci_init(void)
1249*4882a593Smuzhiyun {
1250*4882a593Smuzhiyun /*
1251*4882a593Smuzhiyun * Initially assume there is no PCI. The PCI/PCIe platform code will
1252*4882a593Smuzhiyun * later re-initialize these to correct values if they are present.
1253*4882a593Smuzhiyun */
1254*4882a593Smuzhiyun octeon_dummy_iospace = vzalloc(IO_SPACE_LIMIT);
1255*4882a593Smuzhiyun set_io_port_base((unsigned long)octeon_dummy_iospace);
1256*4882a593Smuzhiyun ioport_resource.start = MAX_RESOURCE;
1257*4882a593Smuzhiyun ioport_resource.end = 0;
1258*4882a593Smuzhiyun return 0;
1259*4882a593Smuzhiyun }
1260*4882a593Smuzhiyun core_initcall(octeon_no_pci_init);
1261*4882a593Smuzhiyun
octeon_no_pci_release(void)1262*4882a593Smuzhiyun static int __init octeon_no_pci_release(void)
1263*4882a593Smuzhiyun {
1264*4882a593Smuzhiyun /*
1265*4882a593Smuzhiyun * Release the allocated memory if a real IO space is there.
1266*4882a593Smuzhiyun */
1267*4882a593Smuzhiyun if ((unsigned long)octeon_dummy_iospace != mips_io_port_base)
1268*4882a593Smuzhiyun vfree(octeon_dummy_iospace);
1269*4882a593Smuzhiyun return 0;
1270*4882a593Smuzhiyun }
1271*4882a593Smuzhiyun late_initcall(octeon_no_pci_release);
1272