blob: 4759494c3ff482f793807b01e57cabc0b52abd95 [file] [log] [blame]
David Daney5b3b1682009-01-08 16:46:40 -08001/*
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
4 * for more details.
5 *
6 * Copyright (C) 2004-2007 Cavium Networks
Ralf Baechlef65aad42012-10-17 00:39:09 +02007 * Copyright (C) 2008, 2009 Wind River Systems
8 * written by Ralf Baechle <ralf@linux-mips.org>
David Daney5b3b1682009-01-08 16:46:40 -08009 */
Ralf Baechle39205752013-06-13 01:29:24 +020010#include <linux/compiler.h>
Aaro Koskinend8b74272013-07-25 20:26:48 +030011#include <linux/vmalloc.h>
David Daney5b3b1682009-01-08 16:46:40 -080012#include <linux/init.h>
Ralf Baechlef65aad42012-10-17 00:39:09 +020013#include <linux/kernel.h>
David Daney5b3b1682009-01-08 16:46:40 -080014#include <linux/console.h>
15#include <linux/delay.h>
Paul Gortmakerf9ded562012-02-28 19:24:46 -050016#include <linux/export.h>
David Daney5b3b1682009-01-08 16:46:40 -080017#include <linux/interrupt.h>
18#include <linux/io.h>
David Daney5b3b1682009-01-08 16:46:40 -080019#include <linux/serial.h>
Ralf Baechle631330f2009-06-19 14:05:26 +010020#include <linux/smp.h>
David Daney5b3b1682009-01-08 16:46:40 -080021#include <linux/types.h>
22#include <linux/string.h> /* for memset */
David Daney5b3b1682009-01-08 16:46:40 -080023#include <linux/tty.h>
24#include <linux/time.h>
25#include <linux/platform_device.h>
26#include <linux/serial_core.h>
27#include <linux/serial_8250.h>
David Daney7ed18152012-07-05 18:12:38 +020028#include <linux/of_fdt.h>
29#include <linux/libfdt.h>
Ralf Baechleabe77f92012-10-25 16:23:31 +020030#include <linux/kexec.h>
David Daney5b3b1682009-01-08 16:46:40 -080031
32#include <asm/processor.h>
33#include <asm/reboot.h>
34#include <asm/smp-ops.h>
David Daney5b3b1682009-01-08 16:46:40 -080035#include <asm/irq_cpu.h>
36#include <asm/mipsregs.h>
37#include <asm/bootinfo.h>
38#include <asm/sections.h>
39#include <asm/time.h>
40
41#include <asm/octeon/octeon.h>
David Daney2b5987a2010-08-04 14:53:57 -070042#include <asm/octeon/pci-octeon.h>
David Daneye195aa32010-10-07 16:03:49 -070043#include <asm/octeon/cvmx-mio-defs.h>
Chandrakala Chavvaac6d9b32015-01-15 16:11:17 +030044#include <asm/octeon/cvmx-rst-defs.h>
David Daney5b3b1682009-01-08 16:46:40 -080045
David Daney5b3b1682009-01-08 16:46:40 -080046#ifdef CONFIG_PCI
47extern void pci_console_init(const char *arg);
48#endif
49
David Daney5b3b1682009-01-08 16:46:40 -080050static unsigned long long MAX_MEMORY = 512ull << 20;
51
David Daney24d4e7f62015-03-05 17:31:29 +030052DEFINE_SEMAPHORE(octeon_bootbus_sem);
53EXPORT_SYMBOL(octeon_bootbus_sem);
54
David Daney5b3b1682009-01-08 16:46:40 -080055struct octeon_boot_descriptor *octeon_boot_desc_ptr;
56
57struct cvmx_bootinfo *octeon_bootinfo;
58EXPORT_SYMBOL(octeon_bootinfo);
59
Ralf Baechleabe77f92012-10-25 16:23:31 +020060static unsigned long long RESERVE_LOW_MEM = 0ull;
61#ifdef CONFIG_KEXEC
62#ifdef CONFIG_SMP
63/*
64 * Wait for relocation code is prepared and send
65 * secondary CPUs to spin until kernel is relocated.
66 */
67static void octeon_kexec_smp_down(void *ignored)
68{
69 int cpu = smp_processor_id();
70
71 local_irq_disable();
72 set_cpu_online(cpu, false);
73 while (!atomic_read(&kexec_ready_to_reboot))
74 cpu_relax();
75
76 asm volatile (
77 " sync \n"
78 " synci ($0) \n");
79
80 relocated_kexec_smp_wait(NULL);
81}
82#endif
83
84#define OCTEON_DDR0_BASE (0x0ULL)
85#define OCTEON_DDR0_SIZE (0x010000000ULL)
86#define OCTEON_DDR1_BASE (0x410000000ULL)
87#define OCTEON_DDR1_SIZE (0x010000000ULL)
88#define OCTEON_DDR2_BASE (0x020000000ULL)
89#define OCTEON_DDR2_SIZE (0x3e0000000ULL)
90#define OCTEON_MAX_PHY_MEM_SIZE (16*1024*1024*1024ULL)
91
92static struct kimage *kimage_ptr;
93
94static void kexec_bootmem_init(uint64_t mem_size, uint32_t low_reserved_bytes)
95{
96 int64_t addr;
97 struct cvmx_bootmem_desc *bootmem_desc;
98
99 bootmem_desc = cvmx_bootmem_get_desc();
100
101 if (mem_size > OCTEON_MAX_PHY_MEM_SIZE) {
102 mem_size = OCTEON_MAX_PHY_MEM_SIZE;
103 pr_err("Error: requested memory too large,"
104 "truncating to maximum size\n");
105 }
106
107 bootmem_desc->major_version = CVMX_BOOTMEM_DESC_MAJ_VER;
108 bootmem_desc->minor_version = CVMX_BOOTMEM_DESC_MIN_VER;
109
110 addr = (OCTEON_DDR0_BASE + RESERVE_LOW_MEM + low_reserved_bytes);
111 bootmem_desc->head_addr = 0;
112
113 if (mem_size <= OCTEON_DDR0_SIZE) {
114 __cvmx_bootmem_phy_free(addr,
115 mem_size - RESERVE_LOW_MEM -
116 low_reserved_bytes, 0);
117 return;
118 }
119
120 __cvmx_bootmem_phy_free(addr,
121 OCTEON_DDR0_SIZE - RESERVE_LOW_MEM -
122 low_reserved_bytes, 0);
123
124 mem_size -= OCTEON_DDR0_SIZE;
125
126 if (mem_size > OCTEON_DDR1_SIZE) {
127 __cvmx_bootmem_phy_free(OCTEON_DDR1_BASE, OCTEON_DDR1_SIZE, 0);
128 __cvmx_bootmem_phy_free(OCTEON_DDR2_BASE,
129 mem_size - OCTEON_DDR1_SIZE, 0);
130 } else
131 __cvmx_bootmem_phy_free(OCTEON_DDR1_BASE, mem_size, 0);
132}
133
134static int octeon_kexec_prepare(struct kimage *image)
135{
136 int i;
137 char *bootloader = "kexec";
138
139 octeon_boot_desc_ptr->argc = 0;
140 for (i = 0; i < image->nr_segments; i++) {
141 if (!strncmp(bootloader, (char *)image->segment[i].buf,
142 strlen(bootloader))) {
143 /*
144 * convert command line string to array
145 * of parameters (as bootloader does).
146 */
147 int argc = 0, offt;
148 char *str = (char *)image->segment[i].buf;
149 char *ptr = strchr(str, ' ');
150 while (ptr && (OCTEON_ARGV_MAX_ARGS > argc)) {
151 *ptr = '\0';
152 if (ptr[1] != ' ') {
153 offt = (int)(ptr - str + 1);
154 octeon_boot_desc_ptr->argv[argc] =
155 image->segment[i].mem + offt;
156 argc++;
157 }
158 ptr = strchr(ptr + 1, ' ');
159 }
160 octeon_boot_desc_ptr->argc = argc;
161 break;
162 }
163 }
164
165 /*
166 * Information about segments will be needed during pre-boot memory
167 * initialization.
168 */
169 kimage_ptr = image;
170 return 0;
171}
172
173static void octeon_generic_shutdown(void)
174{
EunBong Songed1197f2013-03-24 22:18:35 +0000175 int i;
176#ifdef CONFIG_SMP
177 int cpu;
178#endif
Ralf Baechleabe77f92012-10-25 16:23:31 +0200179 struct cvmx_bootmem_desc *bootmem_desc;
180 void *named_block_array_ptr;
181
182 bootmem_desc = cvmx_bootmem_get_desc();
183 named_block_array_ptr =
184 cvmx_phys_to_ptr(bootmem_desc->named_block_array_addr);
185
186#ifdef CONFIG_SMP
187 /* disable watchdogs */
188 for_each_online_cpu(cpu)
189 cvmx_write_csr(CVMX_CIU_WDOGX(cpu_logical_map(cpu)), 0);
190#else
191 cvmx_write_csr(CVMX_CIU_WDOGX(cvmx_get_core_num()), 0);
192#endif
193 if (kimage_ptr != kexec_crash_image) {
194 memset(named_block_array_ptr,
195 0x0,
196 CVMX_BOOTMEM_NUM_NAMED_BLOCKS *
197 sizeof(struct cvmx_bootmem_named_block_desc));
198 /*
199 * Mark all memory (except low 0x100000 bytes) as free.
200 * It is the same thing that bootloader does.
201 */
202 kexec_bootmem_init(octeon_bootinfo->dram_size*1024ULL*1024ULL,
203 0x100000);
204 /*
205 * Allocate all segments to avoid their corruption during boot.
206 */
207 for (i = 0; i < kimage_ptr->nr_segments; i++)
208 cvmx_bootmem_alloc_address(
209 kimage_ptr->segment[i].memsz + 2*PAGE_SIZE,
210 kimage_ptr->segment[i].mem - PAGE_SIZE,
211 PAGE_SIZE);
212 } else {
213 /*
214 * Do not mark all memory as free. Free only named sections
215 * leaving the rest of memory unchanged.
216 */
217 struct cvmx_bootmem_named_block_desc *ptr =
218 (struct cvmx_bootmem_named_block_desc *)
219 named_block_array_ptr;
220
221 for (i = 0; i < bootmem_desc->named_block_num_blocks; i++)
222 if (ptr[i].size)
223 cvmx_bootmem_free_named(ptr[i].name);
224 }
225 kexec_args[2] = 1UL; /* running on octeon_main_processor */
226 kexec_args[3] = (unsigned long)octeon_boot_desc_ptr;
227#ifdef CONFIG_SMP
228 secondary_kexec_args[2] = 0UL; /* running on secondary cpu */
229 secondary_kexec_args[3] = (unsigned long)octeon_boot_desc_ptr;
230#endif
231}
232
233static void octeon_shutdown(void)
234{
235 octeon_generic_shutdown();
236#ifdef CONFIG_SMP
237 smp_call_function(octeon_kexec_smp_down, NULL, 0);
238 smp_wmb();
239 while (num_online_cpus() > 1) {
240 cpu_relax();
241 mdelay(1);
242 }
243#endif
244}
245
246static void octeon_crash_shutdown(struct pt_regs *regs)
247{
248 octeon_generic_shutdown();
249 default_machine_crash_shutdown(regs);
250}
251
252#endif /* CONFIG_KEXEC */
253
David Daney5b3b1682009-01-08 16:46:40 -0800254#ifdef CONFIG_CAVIUM_RESERVE32
255uint64_t octeon_reserve32_memory;
256EXPORT_SYMBOL(octeon_reserve32_memory);
257#endif
258
Ralf Baechleabe77f92012-10-25 16:23:31 +0200259#ifdef CONFIG_KEXEC
260/* crashkernel cmdline parameter is parsed _after_ memory setup
261 * we also parse it here (workaround for EHB5200) */
262static uint64_t crashk_size, crashk_base;
263#endif
264
David Daney5b3b1682009-01-08 16:46:40 -0800265static int octeon_uart;
266
267extern asmlinkage void handle_int(void);
David Daney5b3b1682009-01-08 16:46:40 -0800268
269/**
270 * Return non zero if we are currently running in the Octeon simulator
271 *
272 * Returns
273 */
274int octeon_is_simulation(void)
275{
276 return octeon_bootinfo->board_type == CVMX_BOARD_TYPE_SIM;
277}
278EXPORT_SYMBOL(octeon_is_simulation);
279
280/**
281 * Return true if Octeon is in PCI Host mode. This means
282 * Linux can control the PCI bus.
283 *
284 * Returns Non zero if Octeon in host mode.
285 */
286int octeon_is_pci_host(void)
287{
288#ifdef CONFIG_PCI
289 return octeon_bootinfo->config_flags & CVMX_BOOTINFO_CFG_FLAG_PCI_HOST;
290#else
291 return 0;
292#endif
293}
294
295/**
296 * Get the clock rate of Octeon
297 *
298 * Returns Clock rate in HZ
299 */
300uint64_t octeon_get_clock_rate(void)
301{
David Daneye195aa32010-10-07 16:03:49 -0700302 struct cvmx_sysinfo *sysinfo = cvmx_sysinfo_get();
303
304 return sysinfo->cpu_clock_hz;
David Daney5b3b1682009-01-08 16:46:40 -0800305}
306EXPORT_SYMBOL(octeon_get_clock_rate);
307
David Daneye195aa32010-10-07 16:03:49 -0700308static u64 octeon_io_clock_rate;
309
310u64 octeon_get_io_clock_rate(void)
311{
312 return octeon_io_clock_rate;
313}
314EXPORT_SYMBOL(octeon_get_io_clock_rate);
315
316
David Daney5b3b1682009-01-08 16:46:40 -0800317/**
318 * Write to the LCD display connected to the bootbus. This display
319 * exists on most Cavium evaluation boards. If it doesn't exist, then
320 * this function doesn't do anything.
321 *
Ralf Baechle70342282013-01-22 12:59:30 +0100322 * @s: String to write
David Daney5b3b1682009-01-08 16:46:40 -0800323 */
324void octeon_write_lcd(const char *s)
325{
326 if (octeon_bootinfo->led_display_base_addr) {
327 void __iomem *lcd_address =
328 ioremap_nocache(octeon_bootinfo->led_display_base_addr,
329 8);
330 int i;
331 for (i = 0; i < 8; i++, s++) {
332 if (*s)
333 iowrite8(*s, lcd_address + i);
334 else
335 iowrite8(' ', lcd_address + i);
336 }
337 iounmap(lcd_address);
338 }
339}
340
341/**
342 * Return the console uart passed by the bootloader
343 *
Ralf Baechle70342282013-01-22 12:59:30 +0100344 * Returns uart (0 or 1)
David Daney5b3b1682009-01-08 16:46:40 -0800345 */
346int octeon_get_boot_uart(void)
347{
348 int uart;
349#ifdef CONFIG_CAVIUM_OCTEON_2ND_KERNEL
350 uart = 1;
351#else
352 uart = (octeon_boot_desc_ptr->flags & OCTEON_BL_FLAG_CONSOLE_UART1) ?
353 1 : 0;
354#endif
355 return uart;
356}
357
358/**
359 * Get the coremask Linux was booted on.
360 *
361 * Returns Core mask
362 */
363int octeon_get_boot_coremask(void)
364{
365 return octeon_boot_desc_ptr->core_mask;
366}
367
368/**
369 * Check the hardware BIST results for a CPU
370 */
371void octeon_check_cpu_bist(void)
372{
373 const int coreid = cvmx_get_core_num();
374 unsigned long long mask;
375 unsigned long long bist_val;
376
377 /* Check BIST results for COP0 registers */
378 mask = 0x1f00000000ull;
379 bist_val = read_octeon_c0_icacheerr();
380 if (bist_val & mask)
381 pr_err("Core%d BIST Failure: CacheErr(icache) = 0x%llx\n",
382 coreid, bist_val);
383
384 bist_val = read_octeon_c0_dcacheerr();
385 if (bist_val & 1)
386 pr_err("Core%d L1 Dcache parity error: "
387 "CacheErr(dcache) = 0x%llx\n",
388 coreid, bist_val);
389
390 mask = 0xfc00000000000000ull;
391 bist_val = read_c0_cvmmemctl();
392 if (bist_val & mask)
393 pr_err("Core%d BIST Failure: COP0_CVM_MEM_CTL = 0x%llx\n",
394 coreid, bist_val);
395
396 write_octeon_c0_dcacheerr(0);
397}
398
David Daney5b3b1682009-01-08 16:46:40 -0800399/**
400 * Reboot Octeon
401 *
402 * @command: Command to pass to the bootloader. Currently ignored.
403 */
404static void octeon_restart(char *command)
405{
406 /* Disable all watchdogs before soft reset. They don't get cleared */
407#ifdef CONFIG_SMP
408 int cpu;
409 for_each_online_cpu(cpu)
410 cvmx_write_csr(CVMX_CIU_WDOGX(cpu_logical_map(cpu)), 0);
411#else
412 cvmx_write_csr(CVMX_CIU_WDOGX(cvmx_get_core_num()), 0);
413#endif
414
415 mb();
416 while (1)
Chandrakala Chavvafe2360f2015-03-05 18:06:11 +0300417 if (OCTEON_IS_OCTEON3())
418 cvmx_write_csr(CVMX_RST_SOFT_RST, 1);
419 else
420 cvmx_write_csr(CVMX_CIU_SOFT_RST, 1);
David Daney5b3b1682009-01-08 16:46:40 -0800421}
422
423
424/**
425 * Permanently stop a core.
426 *
427 * @arg: Ignored.
428 */
429static void octeon_kill_core(void *arg)
430{
David Daney38c3c0f2013-05-24 16:23:02 +0000431 if (octeon_is_simulation())
David Daney5b3b1682009-01-08 16:46:40 -0800432 /* A break instruction causes the simulator stop a core */
David Daney38c3c0f2013-05-24 16:23:02 +0000433 asm volatile ("break" ::: "memory");
434
435 local_irq_disable();
436 /* Disable watchdog on this core. */
437 cvmx_write_csr(CVMX_CIU_WDOGX(cvmx_get_core_num()), 0);
438 /* Spin in a low power mode. */
439 while (true)
440 asm volatile ("wait" ::: "memory");
David Daney5b3b1682009-01-08 16:46:40 -0800441}
442
443
444/**
445 * Halt the system
446 */
447static void octeon_halt(void)
448{
449 smp_call_function(octeon_kill_core, NULL, 0);
450
451 switch (octeon_bootinfo->board_type) {
452 case CVMX_BOARD_TYPE_NAO38:
453 /* Driving a 1 to GPIO 12 shuts off this board */
454 cvmx_write_csr(CVMX_GPIO_BIT_CFGX(12), 1);
455 cvmx_write_csr(CVMX_GPIO_TX_SET, 0x1000);
456 break;
457 default:
458 octeon_write_lcd("PowerOff");
459 break;
460 }
461
462 octeon_kill_core(NULL);
463}
464
Aaro Koskinen60830862014-07-22 14:51:08 +0300465static char __read_mostly octeon_system_type[80];
466
467static int __init init_octeon_system_type(void)
468{
Aaro Koskinen6ecffaf2016-02-23 00:22:55 +0200469 char const *board_type;
470
471 board_type = cvmx_board_type_to_string(octeon_bootinfo->board_type);
472 if (board_type == NULL)
473 board_type = "Unsupported Board";
474
Aaro Koskinen60830862014-07-22 14:51:08 +0300475 snprintf(octeon_system_type, sizeof(octeon_system_type), "%s (%s)",
Aaro Koskinen6ecffaf2016-02-23 00:22:55 +0200476 board_type, octeon_model_get_string(read_c0_prid()));
Aaro Koskinen60830862014-07-22 14:51:08 +0300477
478 return 0;
479}
480early_initcall(init_octeon_system_type);
481
David Daney5b3b1682009-01-08 16:46:40 -0800482/**
David Daney5b3b1682009-01-08 16:46:40 -0800483 * Return a string representing the system type
484 *
485 * Returns
486 */
487const char *octeon_board_type_string(void)
488{
Aaro Koskinen60830862014-07-22 14:51:08 +0300489 return octeon_system_type;
David Daney5b3b1682009-01-08 16:46:40 -0800490}
491
492const char *get_system_type(void)
493 __attribute__ ((alias("octeon_board_type_string")));
494
495void octeon_user_io_init(void)
496{
497 union octeon_cvmemctl cvmmemctl;
David Daney5b3b1682009-01-08 16:46:40 -0800498
499 /* Get the current settings for CP0_CVMMEMCTL_REG */
500 cvmmemctl.u64 = read_c0_cvmmemctl();
501 /* R/W If set, marked write-buffer entries time out the same
502 * as as other entries; if clear, marked write-buffer entries
503 * use the maximum timeout. */
504 cvmmemctl.s.dismarkwblongto = 1;
505 /* R/W If set, a merged store does not clear the write-buffer
506 * entry timeout state. */
507 cvmmemctl.s.dismrgclrwbto = 0;
508 /* R/W Two bits that are the MSBs of the resultant CVMSEG LM
509 * word location for an IOBDMA. The other 8 bits come from the
510 * SCRADDR field of the IOBDMA. */
511 cvmmemctl.s.iobdmascrmsb = 0;
512 /* R/W If set, SYNCWS and SYNCS only order marked stores; if
513 * clear, SYNCWS and SYNCS only order unmarked
514 * stores. SYNCWSMARKED has no effect when DISSYNCWS is
515 * set. */
516 cvmmemctl.s.syncwsmarked = 0;
517 /* R/W If set, SYNCWS acts as SYNCW and SYNCS acts as SYNC. */
518 cvmmemctl.s.dissyncws = 0;
519 /* R/W If set, no stall happens on write buffer full. */
520 if (OCTEON_IS_MODEL(OCTEON_CN38XX_PASS2))
521 cvmmemctl.s.diswbfst = 1;
522 else
523 cvmmemctl.s.diswbfst = 0;
524 /* R/W If set (and SX set), supervisor-level loads/stores can
525 * use XKPHYS addresses with <48>==0 */
526 cvmmemctl.s.xkmemenas = 0;
527
528 /* R/W If set (and UX set), user-level loads/stores can use
529 * XKPHYS addresses with VA<48>==0 */
530 cvmmemctl.s.xkmemenau = 0;
531
532 /* R/W If set (and SX set), supervisor-level loads/stores can
533 * use XKPHYS addresses with VA<48>==1 */
534 cvmmemctl.s.xkioenas = 0;
535
536 /* R/W If set (and UX set), user-level loads/stores can use
537 * XKPHYS addresses with VA<48>==1 */
538 cvmmemctl.s.xkioenau = 0;
539
540 /* R/W If set, all stores act as SYNCW (NOMERGE must be set
541 * when this is set) RW, reset to 0. */
542 cvmmemctl.s.allsyncw = 0;
543
544 /* R/W If set, no stores merge, and all stores reach the
545 * coherent bus in order. */
546 cvmmemctl.s.nomerge = 0;
547 /* R/W Selects the bit in the counter used for DID time-outs 0
548 * = 231, 1 = 230, 2 = 229, 3 = 214. Actual time-out is
549 * between 1x and 2x this interval. For example, with
550 * DIDTTO=3, expiration interval is between 16K and 32K. */
551 cvmmemctl.s.didtto = 0;
552 /* R/W If set, the (mem) CSR clock never turns off. */
553 cvmmemctl.s.csrckalwys = 0;
554 /* R/W If set, mclk never turns off. */
555 cvmmemctl.s.mclkalwys = 0;
556 /* R/W Selects the bit in the counter used for write buffer
557 * flush time-outs (WBFLT+11) is the bit position in an
558 * internal counter used to determine expiration. The write
559 * buffer expires between 1x and 2x this interval. For
560 * example, with WBFLT = 0, a write buffer expires between 2K
561 * and 4K cycles after the write buffer entry is allocated. */
562 cvmmemctl.s.wbfltime = 0;
563 /* R/W If set, do not put Istream in the L2 cache. */
564 cvmmemctl.s.istrnol2 = 0;
David Daneyc9941152010-10-07 16:03:53 -0700565
566 /*
567 * R/W The write buffer threshold. As per erratum Core-14752
568 * for CN63XX, a sc/scd might fail if the write buffer is
569 * full. Lowering WBTHRESH greatly lowers the chances of the
570 * write buffer ever being full and triggering the erratum.
571 */
572 if (OCTEON_IS_MODEL(OCTEON_CN63XX_PASS1_X))
573 cvmmemctl.s.wbthresh = 4;
574 else
575 cvmmemctl.s.wbthresh = 10;
576
David Daney5b3b1682009-01-08 16:46:40 -0800577 /* R/W If set, CVMSEG is available for loads/stores in
578 * kernel/debug mode. */
579#if CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE > 0
580 cvmmemctl.s.cvmsegenak = 1;
581#else
582 cvmmemctl.s.cvmsegenak = 0;
583#endif
584 /* R/W If set, CVMSEG is available for loads/stores in
585 * supervisor mode. */
586 cvmmemctl.s.cvmsegenas = 0;
587 /* R/W If set, CVMSEG is available for loads/stores in user
588 * mode. */
589 cvmmemctl.s.cvmsegenau = 0;
David Daney5b3b1682009-01-08 16:46:40 -0800590
David Daneyc9941152010-10-07 16:03:53 -0700591 write_c0_cvmmemctl(cvmmemctl.u64);
David Daney5b3b1682009-01-08 16:46:40 -0800592
David Daney726da2f2015-01-15 16:11:15 +0300593 /* Setup of CVMSEG is done in kernel-entry-init.h */
David Daney5b3b1682009-01-08 16:46:40 -0800594 if (smp_processor_id() == 0)
595 pr_notice("CVMSEG size: %d cache lines (%d bytes)\n",
596 CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE,
597 CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE * 128);
598
David Daney9bc22232016-02-09 11:00:10 -0800599 if (octeon_has_feature(OCTEON_FEATURE_FAU)) {
600 union cvmx_iob_fau_timeout fau_timeout;
David Daney5b3b1682009-01-08 16:46:40 -0800601
David Daney9bc22232016-02-09 11:00:10 -0800602 /* Set a default for the hardware timeouts */
603 fau_timeout.u64 = 0;
604 fau_timeout.s.tout_val = 0xfff;
605 /* Disable tagwait FAU timeout */
606 fau_timeout.s.tout_enb = 0;
607 cvmx_write_csr(CVMX_IOB_FAU_TIMEOUT, fau_timeout.u64);
608 }
609
610 if ((!OCTEON_IS_MODEL(OCTEON_CN68XX) &&
611 !OCTEON_IS_MODEL(OCTEON_CN7XXX)) ||
612 OCTEON_IS_MODEL(OCTEON_CN70XX)) {
613 union cvmx_pow_nw_tim nm_tim;
614
615 nm_tim.u64 = 0;
616 /* 4096 cycles */
617 nm_tim.s.nw_tim = 3;
618 cvmx_write_csr(CVMX_POW_NW_TIM, nm_tim.u64);
619 }
David Daney5b3b1682009-01-08 16:46:40 -0800620
621 write_octeon_c0_icacheerr(0);
622 write_c0_derraddr1(0);
623}
624
625/**
626 * Early entry point for arch setup
627 */
628void __init prom_init(void)
629{
630 struct cvmx_sysinfo *sysinfo;
Ralf Baechleabe77f92012-10-25 16:23:31 +0200631 const char *arg;
632 char *p;
David Daney5b3b1682009-01-08 16:46:40 -0800633 int i;
David Daneyac655fb2015-01-15 16:11:05 +0300634 u64 t;
David Daney5b3b1682009-01-08 16:46:40 -0800635 int argc;
David Daney5b3b1682009-01-08 16:46:40 -0800636#ifdef CONFIG_CAVIUM_RESERVE32
637 int64_t addr = -1;
638#endif
639 /*
640 * The bootloader passes a pointer to the boot descriptor in
641 * $a3, this is available as fw_arg3.
642 */
643 octeon_boot_desc_ptr = (struct octeon_boot_descriptor *)fw_arg3;
644 octeon_bootinfo =
645 cvmx_phys_to_ptr(octeon_boot_desc_ptr->cvmx_desc_vaddr);
646 cvmx_bootmem_init(cvmx_phys_to_ptr(octeon_bootinfo->phy_mem_desc_addr));
647
David Daneye195aa32010-10-07 16:03:49 -0700648 sysinfo = cvmx_sysinfo_get();
649 memset(sysinfo, 0, sizeof(*sysinfo));
650 sysinfo->system_dram_size = octeon_bootinfo->dram_size << 20;
David Daney7d52ab12016-02-01 17:46:54 -0800651 sysinfo->phy_mem_desc_addr = (u64)phys_to_virt(octeon_bootinfo->phy_mem_desc_addr);
652
653 if ((octeon_bootinfo->major_version > 1) ||
654 (octeon_bootinfo->major_version == 1 &&
655 octeon_bootinfo->minor_version >= 4))
656 cvmx_coremask_copy(&sysinfo->core_mask,
657 &octeon_bootinfo->ext_core_mask);
658 else
659 cvmx_coremask_set64(&sysinfo->core_mask,
660 octeon_bootinfo->core_mask);
661
662 /* Some broken u-boot pass garbage in upper bits, clear them out */
663 if (!OCTEON_IS_MODEL(OCTEON_CN78XX))
664 for (i = 512; i < 1024; i++)
665 cvmx_coremask_clear_core(&sysinfo->core_mask, i);
666
David Daneye195aa32010-10-07 16:03:49 -0700667 sysinfo->exception_base_addr = octeon_bootinfo->exception_base_addr;
668 sysinfo->cpu_clock_hz = octeon_bootinfo->eclock_hz;
669 sysinfo->dram_data_rate_hz = octeon_bootinfo->dclock_hz * 2;
670 sysinfo->board_type = octeon_bootinfo->board_type;
671 sysinfo->board_rev_major = octeon_bootinfo->board_rev_major;
672 sysinfo->board_rev_minor = octeon_bootinfo->board_rev_minor;
673 memcpy(sysinfo->mac_addr_base, octeon_bootinfo->mac_addr_base,
674 sizeof(sysinfo->mac_addr_base));
675 sysinfo->mac_addr_count = octeon_bootinfo->mac_addr_count;
676 memcpy(sysinfo->board_serial_number,
677 octeon_bootinfo->board_serial_number,
678 sizeof(sysinfo->board_serial_number));
679 sysinfo->compact_flash_common_base_addr =
680 octeon_bootinfo->compact_flash_common_base_addr;
681 sysinfo->compact_flash_attribute_base_addr =
682 octeon_bootinfo->compact_flash_attribute_base_addr;
683 sysinfo->led_display_base_addr = octeon_bootinfo->led_display_base_addr;
684 sysinfo->dfa_ref_clock_hz = octeon_bootinfo->dfa_ref_clock_hz;
685 sysinfo->bootloader_config_flags = octeon_bootinfo->config_flags;
686
Chandrakala Chavvaac6d9b32015-01-15 16:11:17 +0300687 if (OCTEON_IS_OCTEON2()) {
David Daneye195aa32010-10-07 16:03:49 -0700688 /* I/O clock runs at a different rate than the CPU. */
689 union cvmx_mio_rst_boot rst_boot;
690 rst_boot.u64 = cvmx_read_csr(CVMX_MIO_RST_BOOT);
691 octeon_io_clock_rate = 50000000 * rst_boot.s.pnr_mul;
Chandrakala Chavvaac6d9b32015-01-15 16:11:17 +0300692 } else if (OCTEON_IS_OCTEON3()) {
693 /* I/O clock runs at a different rate than the CPU. */
694 union cvmx_rst_boot rst_boot;
695 rst_boot.u64 = cvmx_read_csr(CVMX_RST_BOOT);
696 octeon_io_clock_rate = 50000000 * rst_boot.s.pnr_mul;
David Daneye195aa32010-10-07 16:03:49 -0700697 } else {
698 octeon_io_clock_rate = sysinfo->cpu_clock_hz;
699 }
700
David Daneyac655fb2015-01-15 16:11:05 +0300701 t = read_c0_cvmctl();
702 if ((t & (1ull << 27)) == 0) {
703 /*
704 * Setup the multiplier save/restore code if
705 * CvmCtl[NOMUL] clear.
706 */
707 void *save;
708 void *save_end;
709 void *restore;
710 void *restore_end;
711 int save_len;
712 int restore_len;
713 int save_max = (char *)octeon_mult_save_end -
714 (char *)octeon_mult_save;
715 int restore_max = (char *)octeon_mult_restore_end -
716 (char *)octeon_mult_restore;
717 if (current_cpu_data.cputype == CPU_CAVIUM_OCTEON3) {
718 save = octeon_mult_save3;
719 save_end = octeon_mult_save3_end;
720 restore = octeon_mult_restore3;
721 restore_end = octeon_mult_restore3_end;
722 } else {
723 save = octeon_mult_save2;
724 save_end = octeon_mult_save2_end;
725 restore = octeon_mult_restore2;
726 restore_end = octeon_mult_restore2_end;
727 }
728 save_len = (char *)save_end - (char *)save;
729 restore_len = (char *)restore_end - (char *)restore;
730 if (!WARN_ON(save_len > save_max ||
731 restore_len > restore_max)) {
732 memcpy(octeon_mult_save, save, save_len);
733 memcpy(octeon_mult_restore, restore, restore_len);
734 }
735 }
736
David Daney5b3b1682009-01-08 16:46:40 -0800737 /*
738 * Only enable the LED controller if we're running on a CN38XX, CN58XX,
739 * or CN56XX. The CN30XX and CN31XX don't have an LED controller.
740 */
741 if (!octeon_is_simulation() &&
742 octeon_has_feature(OCTEON_FEATURE_LED_CONTROLLER)) {
743 cvmx_write_csr(CVMX_LED_EN, 0);
744 cvmx_write_csr(CVMX_LED_PRT, 0);
745 cvmx_write_csr(CVMX_LED_DBG, 0);
746 cvmx_write_csr(CVMX_LED_PRT_FMT, 0);
747 cvmx_write_csr(CVMX_LED_UDD_CNTX(0), 32);
748 cvmx_write_csr(CVMX_LED_UDD_CNTX(1), 32);
749 cvmx_write_csr(CVMX_LED_UDD_DATX(0), 0);
750 cvmx_write_csr(CVMX_LED_UDD_DATX(1), 0);
751 cvmx_write_csr(CVMX_LED_EN, 1);
752 }
753#ifdef CONFIG_CAVIUM_RESERVE32
754 /*
755 * We need to temporarily allocate all memory in the reserve32
756 * region. This makes sure the kernel doesn't allocate this
757 * memory when it is getting memory from the
758 * bootloader. Later, after the memory allocations are
759 * complete, the reserve32 will be freed.
David Daney1ef28872010-03-03 11:07:07 -0800760 *
David Daney5b3b1682009-01-08 16:46:40 -0800761 * Allocate memory for RESERVED32 aligned on 2MB boundary. This
762 * is in case we later use hugetlb entries with it.
763 */
764 addr = cvmx_bootmem_phy_named_block_alloc(CONFIG_CAVIUM_RESERVE32 << 20,
765 0, 0, 2 << 20,
766 "CAVIUM_RESERVE32", 0);
David Daney5b3b1682009-01-08 16:46:40 -0800767 if (addr < 0)
768 pr_err("Failed to allocate CAVIUM_RESERVE32 memory area\n");
769 else
770 octeon_reserve32_memory = addr;
771#endif
772
773#ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2
774 if (cvmx_read_csr(CVMX_L2D_FUS3) & (3ull << 34)) {
775 pr_info("Skipping L2 locking due to reduced L2 cache size\n");
776 } else {
Ralf Baechle39205752013-06-13 01:29:24 +0200777 uint32_t __maybe_unused ebase = read_c0_ebase() & 0x3ffff000;
David Daney5b3b1682009-01-08 16:46:40 -0800778#ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_TLB
779 /* TLB refill */
780 cvmx_l2c_lock_mem_region(ebase, 0x100);
781#endif
782#ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_EXCEPTION
783 /* General exception */
784 cvmx_l2c_lock_mem_region(ebase + 0x180, 0x80);
785#endif
786#ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_LOW_LEVEL_INTERRUPT
787 /* Interrupt handler */
788 cvmx_l2c_lock_mem_region(ebase + 0x200, 0x80);
789#endif
790#ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_INTERRUPT
791 cvmx_l2c_lock_mem_region(__pa_symbol(handle_int), 0x100);
792 cvmx_l2c_lock_mem_region(__pa_symbol(plat_irq_dispatch), 0x80);
793#endif
794#ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_MEMCPY
795 cvmx_l2c_lock_mem_region(__pa_symbol(memcpy), 0x480);
796#endif
797 }
798#endif
799
David Daney5b3b1682009-01-08 16:46:40 -0800800 octeon_check_cpu_bist();
801
802 octeon_uart = octeon_get_boot_uart();
803
David Daney5b3b1682009-01-08 16:46:40 -0800804#ifdef CONFIG_SMP
805 octeon_write_lcd("LinuxSMP");
806#else
807 octeon_write_lcd("Linux");
808#endif
809
David Daney70a26a22012-08-21 11:45:05 -0700810 octeon_setup_delays();
811
David Daney5b3b1682009-01-08 16:46:40 -0800812 /*
813 * BIST should always be enabled when doing a soft reset. L2
814 * Cache locking for instance is not cleared unless BIST is
815 * enabled. Unfortunately due to a chip errata G-200 for
816 * Cn38XX and CN31XX, BIST msut be disabled on these parts.
817 */
818 if (OCTEON_IS_MODEL(OCTEON_CN38XX_PASS2) ||
819 OCTEON_IS_MODEL(OCTEON_CN31XX))
820 cvmx_write_csr(CVMX_CIU_SOFT_BIST, 0);
821 else
822 cvmx_write_csr(CVMX_CIU_SOFT_BIST, 1);
823
824 /* Default to 64MB in the simulator to speed things up */
825 if (octeon_is_simulation())
826 MAX_MEMORY = 64ull << 20;
827
Ralf Baechleabe77f92012-10-25 16:23:31 +0200828 arg = strstr(arcs_cmdline, "mem=");
829 if (arg) {
830 MAX_MEMORY = memparse(arg + 4, &p);
831 if (MAX_MEMORY == 0)
832 MAX_MEMORY = 32ull << 30;
833 if (*p == '@')
834 RESERVE_LOW_MEM = memparse(p + 1, &p);
835 }
836
David Daney5b3b1682009-01-08 16:46:40 -0800837 arcs_cmdline[0] = 0;
838 argc = octeon_boot_desc_ptr->argc;
839 for (i = 0; i < argc; i++) {
840 const char *arg =
841 cvmx_phys_to_ptr(octeon_boot_desc_ptr->argv[i]);
842 if ((strncmp(arg, "MEM=", 4) == 0) ||
843 (strncmp(arg, "mem=", 4) == 0)) {
Ralf Baechleabe77f92012-10-25 16:23:31 +0200844 MAX_MEMORY = memparse(arg + 4, &p);
David Daney5b3b1682009-01-08 16:46:40 -0800845 if (MAX_MEMORY == 0)
846 MAX_MEMORY = 32ull << 30;
Ralf Baechleabe77f92012-10-25 16:23:31 +0200847 if (*p == '@')
848 RESERVE_LOW_MEM = memparse(p + 1, &p);
Ralf Baechleabe77f92012-10-25 16:23:31 +0200849#ifdef CONFIG_KEXEC
850 } else if (strncmp(arg, "crashkernel=", 12) == 0) {
851 crashk_size = memparse(arg+12, &p);
852 if (*p == '@')
853 crashk_base = memparse(p+1, &p);
854 strcat(arcs_cmdline, " ");
855 strcat(arcs_cmdline, arg);
856 /*
857 * To do: switch parsing to new style, something like:
858 * parse_crashkernel(arg, sysinfo->system_dram_size,
Ralf Baechle70342282013-01-22 12:59:30 +0100859 * &crashk_size, &crashk_base);
Ralf Baechleabe77f92012-10-25 16:23:31 +0200860 */
861#endif
David Daney5b3b1682009-01-08 16:46:40 -0800862 } else if (strlen(arcs_cmdline) + strlen(arg) + 1 <
863 sizeof(arcs_cmdline) - 1) {
864 strcat(arcs_cmdline, " ");
865 strcat(arcs_cmdline, arg);
866 }
867 }
868
869 if (strstr(arcs_cmdline, "console=") == NULL) {
David Daney5b3b1682009-01-08 16:46:40 -0800870#ifdef CONFIG_CAVIUM_OCTEON_2ND_KERNEL
871 strcat(arcs_cmdline, " console=ttyS0,115200");
872#else
873 if (octeon_uart == 1)
874 strcat(arcs_cmdline, " console=ttyS1,115200");
875 else
876 strcat(arcs_cmdline, " console=ttyS0,115200");
877#endif
David Daney5b3b1682009-01-08 16:46:40 -0800878 }
879
David Daney5b3b1682009-01-08 16:46:40 -0800880 mips_hpt_frequency = octeon_get_clock_rate();
881
882 octeon_init_cvmcount();
883
884 _machine_restart = octeon_restart;
885 _machine_halt = octeon_halt;
886
Ralf Baechleabe77f92012-10-25 16:23:31 +0200887#ifdef CONFIG_KEXEC
888 _machine_kexec_shutdown = octeon_shutdown;
889 _machine_crash_shutdown = octeon_crash_shutdown;
890 _machine_kexec_prepare = octeon_kexec_prepare;
891#endif
892
David Daney5b3b1682009-01-08 16:46:40 -0800893 octeon_user_io_init();
David Daneyc6d2b222016-02-09 11:00:12 -0800894 octeon_setup_smp();
David Daney5b3b1682009-01-08 16:46:40 -0800895}
896
David Daney2b5987a2010-08-04 14:53:57 -0700897/* Exclude a single page from the regions obtained in plat_mem_setup. */
Ralf Baechleabe77f92012-10-25 16:23:31 +0200898#ifndef CONFIG_CRASH_DUMP
David Daney2b5987a2010-08-04 14:53:57 -0700899static __init void memory_exclude_page(u64 addr, u64 *mem, u64 *size)
900{
901 if (addr > *mem && addr < *mem + *size) {
902 u64 inc = addr - *mem;
903 add_memory_region(*mem, inc, BOOT_MEM_RAM);
904 *mem += inc;
905 *size -= inc;
906 }
907
908 if (addr == *mem && *size > PAGE_SIZE) {
909 *mem += PAGE_SIZE;
910 *size -= PAGE_SIZE;
911 }
912}
Ralf Baechleabe77f92012-10-25 16:23:31 +0200913#endif /* CONFIG_CRASH_DUMP */
David Daney2b5987a2010-08-04 14:53:57 -0700914
David Daney5b3b1682009-01-08 16:46:40 -0800915void __init plat_mem_setup(void)
916{
917 uint64_t mem_alloc_size;
918 uint64_t total;
Ralf Baechleabe77f92012-10-25 16:23:31 +0200919 uint64_t crashk_end;
920#ifndef CONFIG_CRASH_DUMP
David Daney5b3b1682009-01-08 16:46:40 -0800921 int64_t memory;
Ralf Baechleabe77f92012-10-25 16:23:31 +0200922 uint64_t kernel_start;
923 uint64_t kernel_size;
924#endif
David Daney5b3b1682009-01-08 16:46:40 -0800925
926 total = 0;
Ralf Baechleabe77f92012-10-25 16:23:31 +0200927 crashk_end = 0;
David Daney5b3b1682009-01-08 16:46:40 -0800928
David Daney5b3b1682009-01-08 16:46:40 -0800929 /*
930 * The Mips memory init uses the first memory location for
931 * some memory vectors. When SPARSEMEM is in use, it doesn't
932 * verify that the size is big enough for the final
933 * vectors. Making the smallest chuck 4MB seems to be enough
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300934 * to consistently work.
David Daney5b3b1682009-01-08 16:46:40 -0800935 */
936 mem_alloc_size = 4 << 20;
937 if (mem_alloc_size > MAX_MEMORY)
938 mem_alloc_size = MAX_MEMORY;
939
Ralf Baechleabe77f92012-10-25 16:23:31 +0200940/* Crashkernel ignores bootmem list. It relies on mem=X@Y option */
941#ifdef CONFIG_CRASH_DUMP
942 add_memory_region(RESERVE_LOW_MEM, MAX_MEMORY, BOOT_MEM_RAM);
943 total += MAX_MEMORY;
944#else
945#ifdef CONFIG_KEXEC
946 if (crashk_size > 0) {
947 add_memory_region(crashk_base, crashk_size, BOOT_MEM_RAM);
948 crashk_end = crashk_base + crashk_size;
949 }
950#endif
David Daney5b3b1682009-01-08 16:46:40 -0800951 /*
952 * When allocating memory, we want incrementing addresses from
953 * bootmem_alloc so the code in add_memory_region can merge
954 * regions next to each other.
955 */
956 cvmx_bootmem_lock();
957 while ((boot_mem_map.nr_map < BOOT_MEM_MAP_MAX)
958 && (total < MAX_MEMORY)) {
David Daney5b3b1682009-01-08 16:46:40 -0800959 memory = cvmx_bootmem_phy_alloc(mem_alloc_size,
Matt Bennett66803dd2015-09-30 17:40:42 +1300960 __pa_symbol(&_end), -1,
David Daney5b3b1682009-01-08 16:46:40 -0800961 0x100000,
962 CVMX_BOOTMEM_FLAG_NO_LOCKING);
David Daney5b3b1682009-01-08 16:46:40 -0800963 if (memory >= 0) {
David Daney2b5987a2010-08-04 14:53:57 -0700964 u64 size = mem_alloc_size;
Ralf Baechleabe77f92012-10-25 16:23:31 +0200965#ifdef CONFIG_KEXEC
966 uint64_t end;
967#endif
David Daney2b5987a2010-08-04 14:53:57 -0700968
969 /*
970 * exclude a page at the beginning and end of
971 * the 256MB PCIe 'hole' so the kernel will not
972 * try to allocate multi-page buffers that
973 * span the discontinuity.
974 */
975 memory_exclude_page(CVMX_PCIE_BAR1_PHYS_BASE,
976 &memory, &size);
977 memory_exclude_page(CVMX_PCIE_BAR1_PHYS_BASE +
978 CVMX_PCIE_BAR1_PHYS_SIZE,
979 &memory, &size);
Ralf Baechleabe77f92012-10-25 16:23:31 +0200980#ifdef CONFIG_KEXEC
981 end = memory + mem_alloc_size;
David Daney2b5987a2010-08-04 14:53:57 -0700982
David Daney5b3b1682009-01-08 16:46:40 -0800983 /*
Ralf Baechleabe77f92012-10-25 16:23:31 +0200984 * This function automatically merges address regions
985 * next to each other if they are received in
986 * incrementing order
David Daney5b3b1682009-01-08 16:46:40 -0800987 */
Ralf Baechleabe77f92012-10-25 16:23:31 +0200988 if (memory < crashk_base && end > crashk_end) {
989 /* region is fully in */
990 add_memory_region(memory,
991 crashk_base - memory,
992 BOOT_MEM_RAM);
993 total += crashk_base - memory;
994 add_memory_region(crashk_end,
995 end - crashk_end,
996 BOOT_MEM_RAM);
997 total += end - crashk_end;
998 continue;
999 }
1000
1001 if (memory >= crashk_base && end <= crashk_end)
1002 /*
1003 * Entire memory region is within the new
1004 * kernel's memory, ignore it.
1005 */
1006 continue;
1007
1008 if (memory > crashk_base && memory < crashk_end &&
1009 end > crashk_end) {
1010 /*
1011 * Overlap with the beginning of the region,
1012 * reserve the beginning.
1013 */
1014 mem_alloc_size -= crashk_end - memory;
1015 memory = crashk_end;
1016 } else if (memory < crashk_base && end > crashk_base &&
1017 end < crashk_end)
1018 /*
1019 * Overlap with the beginning of the region,
1020 * chop of end.
1021 */
1022 mem_alloc_size -= end - crashk_base;
1023#endif
1024 add_memory_region(memory, mem_alloc_size, BOOT_MEM_RAM);
David Daney5b3b1682009-01-08 16:46:40 -08001025 total += mem_alloc_size;
Ralf Baechleabe77f92012-10-25 16:23:31 +02001026 /* Recovering mem_alloc_size */
1027 mem_alloc_size = 4 << 20;
David Daney5b3b1682009-01-08 16:46:40 -08001028 } else {
1029 break;
1030 }
1031 }
1032 cvmx_bootmem_unlock();
Ralf Baechleabe77f92012-10-25 16:23:31 +02001033 /* Add the memory region for the kernel. */
1034 kernel_start = (unsigned long) _text;
David Daneyd949b4f2013-06-12 17:28:33 +00001035 kernel_size = _end - _text;
Ralf Baechleabe77f92012-10-25 16:23:31 +02001036
1037 /* Adjust for physical offset. */
1038 kernel_start &= ~0xffffffff80000000ULL;
1039 add_memory_region(kernel_start, kernel_size, BOOT_MEM_RAM);
1040#endif /* CONFIG_CRASH_DUMP */
David Daney5b3b1682009-01-08 16:46:40 -08001041
1042#ifdef CONFIG_CAVIUM_RESERVE32
1043 /*
1044 * Now that we've allocated the kernel memory it is safe to
1045 * free the reserved region. We free it here so that builtin
1046 * drivers can use the memory.
1047 */
1048 if (octeon_reserve32_memory)
1049 cvmx_bootmem_free_named("CAVIUM_RESERVE32");
1050#endif /* CONFIG_CAVIUM_RESERVE32 */
1051
1052 if (total == 0)
1053 panic("Unable to allocate memory from "
Ralf Baechlef7777dc2013-09-18 16:05:26 +02001054 "cvmx_bootmem_phy_alloc");
David Daney5b3b1682009-01-08 16:46:40 -08001055}
1056
David Daneyea4354642010-07-23 18:41:44 -07001057/*
Ralf Baechle70342282013-01-22 12:59:30 +01001058 * Emit one character to the boot UART. Exported for use by the
David Daneyea4354642010-07-23 18:41:44 -07001059 * watchdog timer.
1060 */
David Daney5b3b1682009-01-08 16:46:40 -08001061int prom_putchar(char c)
1062{
1063 uint64_t lsrval;
1064
1065 /* Spin until there is room */
1066 do {
1067 lsrval = cvmx_read_csr(CVMX_MIO_UARTX_LSR(octeon_uart));
1068 } while ((lsrval & 0x20) == 0);
1069
1070 /* Write the byte */
David Daney606c9582010-05-19 14:16:32 -07001071 cvmx_write_csr(CVMX_MIO_UARTX_THR(octeon_uart), c & 0xffull);
David Daney5b3b1682009-01-08 16:46:40 -08001072 return 1;
1073}
David Daneyea4354642010-07-23 18:41:44 -07001074EXPORT_SYMBOL(prom_putchar);
David Daney5b3b1682009-01-08 16:46:40 -08001075
Aaro Koskinenaa816c12015-02-26 01:31:04 +02001076void __init prom_free_prom_memory(void)
David Daney5b3b1682009-01-08 16:46:40 -08001077{
David Daneye3d0ead2015-01-15 16:11:13 +03001078 if (CAVIUM_OCTEON_DCACHE_PREFETCH_WAR) {
David Daneyc9941152010-10-07 16:03:53 -07001079 /* Check for presence of Core-14449 fix. */
1080 u32 insn;
1081 u32 *foo;
1082
1083 foo = &insn;
1084
1085 asm volatile("# before" : : : "memory");
1086 prefetch(foo);
1087 asm volatile(
1088 ".set push\n\t"
1089 ".set noreorder\n\t"
1090 "bal 1f\n\t"
1091 "nop\n"
1092 "1:\tlw %0,-12($31)\n\t"
1093 ".set pop\n\t"
1094 : "=r" (insn) : : "$31", "memory");
1095
1096 if ((insn >> 26) != 0x33)
Ralf Baechleab75dc02011-11-17 15:07:31 +00001097 panic("No PREF instruction at Core-14449 probe point.");
David Daneyc9941152010-10-07 16:03:53 -07001098
1099 if (((insn >> 16) & 0x1f) != 28)
David Daneye3d0ead2015-01-15 16:11:13 +03001100 panic("OCTEON II DCache prefetch workaround not in place (%04x).\n"
1101 "Please build kernel with proper options (CONFIG_CAVIUM_CN63XXP1).",
1102 insn);
David Daneyc9941152010-10-07 16:03:53 -07001103 }
David Daney5b3b1682009-01-08 16:46:40 -08001104}
David Daney7ed18152012-07-05 18:12:38 +02001105
1106int octeon_prune_device_tree(void);
1107
Aaro Koskinen651d19f2015-09-11 17:46:15 +03001108extern const char __appended_dtb;
David Daney7ed18152012-07-05 18:12:38 +02001109extern const char __dtb_octeon_3xxx_begin;
David Daney7ed18152012-07-05 18:12:38 +02001110extern const char __dtb_octeon_68xx_begin;
David Daney7ed18152012-07-05 18:12:38 +02001111void __init device_tree_init(void)
1112{
Rob Herring8c97cec2014-04-02 17:45:06 -05001113 const void *fdt;
David Daney7ed18152012-07-05 18:12:38 +02001114 bool do_prune;
1115
Aaro Koskinen651d19f2015-09-11 17:46:15 +03001116#ifdef CONFIG_MIPS_ELF_APPENDED_DTB
1117 if (!fdt_check_header(&__appended_dtb)) {
1118 fdt = &__appended_dtb;
1119 do_prune = false;
1120 pr_info("Using appended Device Tree.\n");
1121 } else
1122#endif
David Daney7ed18152012-07-05 18:12:38 +02001123 if (octeon_bootinfo->minor_version >= 3 && octeon_bootinfo->fdt_addr) {
1124 fdt = phys_to_virt(octeon_bootinfo->fdt_addr);
1125 if (fdt_check_header(fdt))
1126 panic("Corrupt Device Tree passed to kernel.");
David Daney7ed18152012-07-05 18:12:38 +02001127 do_prune = false;
Aaro Koskinen651d19f2015-09-11 17:46:15 +03001128 pr_info("Using passed Device Tree.\n");
David Daney7ed18152012-07-05 18:12:38 +02001129 } else if (OCTEON_IS_MODEL(OCTEON_CN68XX)) {
Rob Herring8c97cec2014-04-02 17:45:06 -05001130 fdt = &__dtb_octeon_68xx_begin;
David Daney7ed18152012-07-05 18:12:38 +02001131 do_prune = true;
1132 } else {
Rob Herring8c97cec2014-04-02 17:45:06 -05001133 fdt = &__dtb_octeon_3xxx_begin;
David Daney7ed18152012-07-05 18:12:38 +02001134 do_prune = true;
1135 }
1136
Rob Herring8c97cec2014-04-02 17:45:06 -05001137 initial_boot_params = (void *)fdt;
David Daney7ed18152012-07-05 18:12:38 +02001138
1139 if (do_prune) {
1140 octeon_prune_device_tree();
1141 pr_info("Using internal Device Tree.\n");
David Daney7ed18152012-07-05 18:12:38 +02001142 }
Rob Herring8c97cec2014-04-02 17:45:06 -05001143 unflatten_and_copy_device_tree();
David Daney7ed18152012-07-05 18:12:38 +02001144}
Ralf Baechlef65aad42012-10-17 00:39:09 +02001145
David Daneye1ced092012-11-15 13:58:59 -08001146static int __initdata disable_octeon_edac_p;
1147
1148static int __init disable_octeon_edac(char *str)
1149{
1150 disable_octeon_edac_p = 1;
1151 return 0;
1152}
1153early_param("disable_octeon_edac", disable_octeon_edac);
1154
Ralf Baechlef65aad42012-10-17 00:39:09 +02001155static char *edac_device_names[] = {
David Daneye1ced092012-11-15 13:58:59 -08001156 "octeon_l2c_edac",
1157 "octeon_pc_edac",
Ralf Baechlef65aad42012-10-17 00:39:09 +02001158};
1159
1160static int __init edac_devinit(void)
1161{
1162 struct platform_device *dev;
1163 int i, err = 0;
David Daneye1ced092012-11-15 13:58:59 -08001164 int num_lmc;
Ralf Baechlef65aad42012-10-17 00:39:09 +02001165 char *name;
1166
David Daneye1ced092012-11-15 13:58:59 -08001167 if (disable_octeon_edac_p)
1168 return 0;
1169
Ralf Baechlef65aad42012-10-17 00:39:09 +02001170 for (i = 0; i < ARRAY_SIZE(edac_device_names); i++) {
1171 name = edac_device_names[i];
1172 dev = platform_device_register_simple(name, -1, NULL, 0);
1173 if (IS_ERR(dev)) {
Masanari Iida6774def2014-11-05 22:26:48 +09001174 pr_err("Registration of %s failed!\n", name);
Ralf Baechlef65aad42012-10-17 00:39:09 +02001175 err = PTR_ERR(dev);
1176 }
1177 }
1178
David Daneye1ced092012-11-15 13:58:59 -08001179 num_lmc = OCTEON_IS_MODEL(OCTEON_CN68XX) ? 4 :
1180 (OCTEON_IS_MODEL(OCTEON_CN56XX) ? 2 : 1);
1181 for (i = 0; i < num_lmc; i++) {
1182 dev = platform_device_register_simple("octeon_lmc_edac",
1183 i, NULL, 0);
1184 if (IS_ERR(dev)) {
Masanari Iida6774def2014-11-05 22:26:48 +09001185 pr_err("Registration of octeon_lmc_edac %d failed!\n", i);
David Daneye1ced092012-11-15 13:58:59 -08001186 err = PTR_ERR(dev);
1187 }
1188 }
1189
Ralf Baechlef65aad42012-10-17 00:39:09 +02001190 return err;
1191}
Ralf Baechlef65aad42012-10-17 00:39:09 +02001192device_initcall(edac_devinit);
Aaro Koskinend8b74272013-07-25 20:26:48 +03001193
1194static void __initdata *octeon_dummy_iospace;
1195
1196static int __init octeon_no_pci_init(void)
1197{
1198 /*
1199 * Initially assume there is no PCI. The PCI/PCIe platform code will
1200 * later re-initialize these to correct values if they are present.
1201 */
1202 octeon_dummy_iospace = vzalloc(IO_SPACE_LIMIT);
1203 set_io_port_base((unsigned long)octeon_dummy_iospace);
1204 ioport_resource.start = MAX_RESOURCE;
1205 ioport_resource.end = 0;
1206 return 0;
1207}
1208core_initcall(octeon_no_pci_init);
1209
1210static int __init octeon_no_pci_release(void)
1211{
1212 /*
1213 * Release the allocated memory if a real IO space is there.
1214 */
1215 if ((unsigned long)octeon_dummy_iospace != mips_io_port_base)
1216 vfree(octeon_dummy_iospace);
1217 return 0;
1218}
1219late_initcall(octeon_no_pci_release);