blob: 54a214ec33d3d7bbad0bb68293f9a5cf4471bb44 [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 -080046extern struct plat_smp_ops octeon_smp_ops;
47
48#ifdef CONFIG_PCI
49extern void pci_console_init(const char *arg);
50#endif
51
David Daney5b3b1682009-01-08 16:46:40 -080052static unsigned long long MAX_MEMORY = 512ull << 20;
53
David Daney24d4e7f62015-03-05 17:31:29 +030054DEFINE_SEMAPHORE(octeon_bootbus_sem);
55EXPORT_SYMBOL(octeon_bootbus_sem);
56
David Daney5b3b1682009-01-08 16:46:40 -080057struct octeon_boot_descriptor *octeon_boot_desc_ptr;
58
59struct cvmx_bootinfo *octeon_bootinfo;
60EXPORT_SYMBOL(octeon_bootinfo);
61
Ralf Baechleabe77f92012-10-25 16:23:31 +020062static unsigned long long RESERVE_LOW_MEM = 0ull;
63#ifdef CONFIG_KEXEC
64#ifdef CONFIG_SMP
65/*
66 * Wait for relocation code is prepared and send
67 * secondary CPUs to spin until kernel is relocated.
68 */
69static void octeon_kexec_smp_down(void *ignored)
70{
71 int cpu = smp_processor_id();
72
73 local_irq_disable();
74 set_cpu_online(cpu, false);
75 while (!atomic_read(&kexec_ready_to_reboot))
76 cpu_relax();
77
78 asm volatile (
79 " sync \n"
80 " synci ($0) \n");
81
82 relocated_kexec_smp_wait(NULL);
83}
84#endif
85
86#define OCTEON_DDR0_BASE (0x0ULL)
87#define OCTEON_DDR0_SIZE (0x010000000ULL)
88#define OCTEON_DDR1_BASE (0x410000000ULL)
89#define OCTEON_DDR1_SIZE (0x010000000ULL)
90#define OCTEON_DDR2_BASE (0x020000000ULL)
91#define OCTEON_DDR2_SIZE (0x3e0000000ULL)
92#define OCTEON_MAX_PHY_MEM_SIZE (16*1024*1024*1024ULL)
93
94static struct kimage *kimage_ptr;
95
96static void kexec_bootmem_init(uint64_t mem_size, uint32_t low_reserved_bytes)
97{
98 int64_t addr;
99 struct cvmx_bootmem_desc *bootmem_desc;
100
101 bootmem_desc = cvmx_bootmem_get_desc();
102
103 if (mem_size > OCTEON_MAX_PHY_MEM_SIZE) {
104 mem_size = OCTEON_MAX_PHY_MEM_SIZE;
105 pr_err("Error: requested memory too large,"
106 "truncating to maximum size\n");
107 }
108
109 bootmem_desc->major_version = CVMX_BOOTMEM_DESC_MAJ_VER;
110 bootmem_desc->minor_version = CVMX_BOOTMEM_DESC_MIN_VER;
111
112 addr = (OCTEON_DDR0_BASE + RESERVE_LOW_MEM + low_reserved_bytes);
113 bootmem_desc->head_addr = 0;
114
115 if (mem_size <= OCTEON_DDR0_SIZE) {
116 __cvmx_bootmem_phy_free(addr,
117 mem_size - RESERVE_LOW_MEM -
118 low_reserved_bytes, 0);
119 return;
120 }
121
122 __cvmx_bootmem_phy_free(addr,
123 OCTEON_DDR0_SIZE - RESERVE_LOW_MEM -
124 low_reserved_bytes, 0);
125
126 mem_size -= OCTEON_DDR0_SIZE;
127
128 if (mem_size > OCTEON_DDR1_SIZE) {
129 __cvmx_bootmem_phy_free(OCTEON_DDR1_BASE, OCTEON_DDR1_SIZE, 0);
130 __cvmx_bootmem_phy_free(OCTEON_DDR2_BASE,
131 mem_size - OCTEON_DDR1_SIZE, 0);
132 } else
133 __cvmx_bootmem_phy_free(OCTEON_DDR1_BASE, mem_size, 0);
134}
135
136static int octeon_kexec_prepare(struct kimage *image)
137{
138 int i;
139 char *bootloader = "kexec";
140
141 octeon_boot_desc_ptr->argc = 0;
142 for (i = 0; i < image->nr_segments; i++) {
143 if (!strncmp(bootloader, (char *)image->segment[i].buf,
144 strlen(bootloader))) {
145 /*
146 * convert command line string to array
147 * of parameters (as bootloader does).
148 */
149 int argc = 0, offt;
150 char *str = (char *)image->segment[i].buf;
151 char *ptr = strchr(str, ' ');
152 while (ptr && (OCTEON_ARGV_MAX_ARGS > argc)) {
153 *ptr = '\0';
154 if (ptr[1] != ' ') {
155 offt = (int)(ptr - str + 1);
156 octeon_boot_desc_ptr->argv[argc] =
157 image->segment[i].mem + offt;
158 argc++;
159 }
160 ptr = strchr(ptr + 1, ' ');
161 }
162 octeon_boot_desc_ptr->argc = argc;
163 break;
164 }
165 }
166
167 /*
168 * Information about segments will be needed during pre-boot memory
169 * initialization.
170 */
171 kimage_ptr = image;
172 return 0;
173}
174
175static void octeon_generic_shutdown(void)
176{
EunBong Songed1197f2013-03-24 22:18:35 +0000177 int i;
178#ifdef CONFIG_SMP
179 int cpu;
180#endif
Ralf Baechleabe77f92012-10-25 16:23:31 +0200181 struct cvmx_bootmem_desc *bootmem_desc;
182 void *named_block_array_ptr;
183
184 bootmem_desc = cvmx_bootmem_get_desc();
185 named_block_array_ptr =
186 cvmx_phys_to_ptr(bootmem_desc->named_block_array_addr);
187
188#ifdef CONFIG_SMP
189 /* disable watchdogs */
190 for_each_online_cpu(cpu)
191 cvmx_write_csr(CVMX_CIU_WDOGX(cpu_logical_map(cpu)), 0);
192#else
193 cvmx_write_csr(CVMX_CIU_WDOGX(cvmx_get_core_num()), 0);
194#endif
195 if (kimage_ptr != kexec_crash_image) {
196 memset(named_block_array_ptr,
197 0x0,
198 CVMX_BOOTMEM_NUM_NAMED_BLOCKS *
199 sizeof(struct cvmx_bootmem_named_block_desc));
200 /*
201 * Mark all memory (except low 0x100000 bytes) as free.
202 * It is the same thing that bootloader does.
203 */
204 kexec_bootmem_init(octeon_bootinfo->dram_size*1024ULL*1024ULL,
205 0x100000);
206 /*
207 * Allocate all segments to avoid their corruption during boot.
208 */
209 for (i = 0; i < kimage_ptr->nr_segments; i++)
210 cvmx_bootmem_alloc_address(
211 kimage_ptr->segment[i].memsz + 2*PAGE_SIZE,
212 kimage_ptr->segment[i].mem - PAGE_SIZE,
213 PAGE_SIZE);
214 } else {
215 /*
216 * Do not mark all memory as free. Free only named sections
217 * leaving the rest of memory unchanged.
218 */
219 struct cvmx_bootmem_named_block_desc *ptr =
220 (struct cvmx_bootmem_named_block_desc *)
221 named_block_array_ptr;
222
223 for (i = 0; i < bootmem_desc->named_block_num_blocks; i++)
224 if (ptr[i].size)
225 cvmx_bootmem_free_named(ptr[i].name);
226 }
227 kexec_args[2] = 1UL; /* running on octeon_main_processor */
228 kexec_args[3] = (unsigned long)octeon_boot_desc_ptr;
229#ifdef CONFIG_SMP
230 secondary_kexec_args[2] = 0UL; /* running on secondary cpu */
231 secondary_kexec_args[3] = (unsigned long)octeon_boot_desc_ptr;
232#endif
233}
234
235static void octeon_shutdown(void)
236{
237 octeon_generic_shutdown();
238#ifdef CONFIG_SMP
239 smp_call_function(octeon_kexec_smp_down, NULL, 0);
240 smp_wmb();
241 while (num_online_cpus() > 1) {
242 cpu_relax();
243 mdelay(1);
244 }
245#endif
246}
247
248static void octeon_crash_shutdown(struct pt_regs *regs)
249{
250 octeon_generic_shutdown();
251 default_machine_crash_shutdown(regs);
252}
253
254#endif /* CONFIG_KEXEC */
255
David Daney5b3b1682009-01-08 16:46:40 -0800256#ifdef CONFIG_CAVIUM_RESERVE32
257uint64_t octeon_reserve32_memory;
258EXPORT_SYMBOL(octeon_reserve32_memory);
259#endif
260
Ralf Baechleabe77f92012-10-25 16:23:31 +0200261#ifdef CONFIG_KEXEC
262/* crashkernel cmdline parameter is parsed _after_ memory setup
263 * we also parse it here (workaround for EHB5200) */
264static uint64_t crashk_size, crashk_base;
265#endif
266
David Daney5b3b1682009-01-08 16:46:40 -0800267static int octeon_uart;
268
269extern asmlinkage void handle_int(void);
David Daney5b3b1682009-01-08 16:46:40 -0800270
271/**
272 * Return non zero if we are currently running in the Octeon simulator
273 *
274 * Returns
275 */
276int octeon_is_simulation(void)
277{
278 return octeon_bootinfo->board_type == CVMX_BOARD_TYPE_SIM;
279}
280EXPORT_SYMBOL(octeon_is_simulation);
281
282/**
283 * Return true if Octeon is in PCI Host mode. This means
284 * Linux can control the PCI bus.
285 *
286 * Returns Non zero if Octeon in host mode.
287 */
288int octeon_is_pci_host(void)
289{
290#ifdef CONFIG_PCI
291 return octeon_bootinfo->config_flags & CVMX_BOOTINFO_CFG_FLAG_PCI_HOST;
292#else
293 return 0;
294#endif
295}
296
297/**
298 * Get the clock rate of Octeon
299 *
300 * Returns Clock rate in HZ
301 */
302uint64_t octeon_get_clock_rate(void)
303{
David Daneye195aa32010-10-07 16:03:49 -0700304 struct cvmx_sysinfo *sysinfo = cvmx_sysinfo_get();
305
306 return sysinfo->cpu_clock_hz;
David Daney5b3b1682009-01-08 16:46:40 -0800307}
308EXPORT_SYMBOL(octeon_get_clock_rate);
309
David Daneye195aa32010-10-07 16:03:49 -0700310static u64 octeon_io_clock_rate;
311
312u64 octeon_get_io_clock_rate(void)
313{
314 return octeon_io_clock_rate;
315}
316EXPORT_SYMBOL(octeon_get_io_clock_rate);
317
318
David Daney5b3b1682009-01-08 16:46:40 -0800319/**
320 * Write to the LCD display connected to the bootbus. This display
321 * exists on most Cavium evaluation boards. If it doesn't exist, then
322 * this function doesn't do anything.
323 *
Ralf Baechle70342282013-01-22 12:59:30 +0100324 * @s: String to write
David Daney5b3b1682009-01-08 16:46:40 -0800325 */
326void octeon_write_lcd(const char *s)
327{
328 if (octeon_bootinfo->led_display_base_addr) {
329 void __iomem *lcd_address =
330 ioremap_nocache(octeon_bootinfo->led_display_base_addr,
331 8);
332 int i;
333 for (i = 0; i < 8; i++, s++) {
334 if (*s)
335 iowrite8(*s, lcd_address + i);
336 else
337 iowrite8(' ', lcd_address + i);
338 }
339 iounmap(lcd_address);
340 }
341}
342
343/**
344 * Return the console uart passed by the bootloader
345 *
Ralf Baechle70342282013-01-22 12:59:30 +0100346 * Returns uart (0 or 1)
David Daney5b3b1682009-01-08 16:46:40 -0800347 */
348int octeon_get_boot_uart(void)
349{
350 int uart;
351#ifdef CONFIG_CAVIUM_OCTEON_2ND_KERNEL
352 uart = 1;
353#else
354 uart = (octeon_boot_desc_ptr->flags & OCTEON_BL_FLAG_CONSOLE_UART1) ?
355 1 : 0;
356#endif
357 return uart;
358}
359
360/**
361 * Get the coremask Linux was booted on.
362 *
363 * Returns Core mask
364 */
365int octeon_get_boot_coremask(void)
366{
367 return octeon_boot_desc_ptr->core_mask;
368}
369
370/**
371 * Check the hardware BIST results for a CPU
372 */
373void octeon_check_cpu_bist(void)
374{
375 const int coreid = cvmx_get_core_num();
376 unsigned long long mask;
377 unsigned long long bist_val;
378
379 /* Check BIST results for COP0 registers */
380 mask = 0x1f00000000ull;
381 bist_val = read_octeon_c0_icacheerr();
382 if (bist_val & mask)
383 pr_err("Core%d BIST Failure: CacheErr(icache) = 0x%llx\n",
384 coreid, bist_val);
385
386 bist_val = read_octeon_c0_dcacheerr();
387 if (bist_val & 1)
388 pr_err("Core%d L1 Dcache parity error: "
389 "CacheErr(dcache) = 0x%llx\n",
390 coreid, bist_val);
391
392 mask = 0xfc00000000000000ull;
393 bist_val = read_c0_cvmmemctl();
394 if (bist_val & mask)
395 pr_err("Core%d BIST Failure: COP0_CVM_MEM_CTL = 0x%llx\n",
396 coreid, bist_val);
397
398 write_octeon_c0_dcacheerr(0);
399}
400
David Daney5b3b1682009-01-08 16:46:40 -0800401/**
402 * Reboot Octeon
403 *
404 * @command: Command to pass to the bootloader. Currently ignored.
405 */
406static void octeon_restart(char *command)
407{
408 /* Disable all watchdogs before soft reset. They don't get cleared */
409#ifdef CONFIG_SMP
410 int cpu;
411 for_each_online_cpu(cpu)
412 cvmx_write_csr(CVMX_CIU_WDOGX(cpu_logical_map(cpu)), 0);
413#else
414 cvmx_write_csr(CVMX_CIU_WDOGX(cvmx_get_core_num()), 0);
415#endif
416
417 mb();
418 while (1)
Chandrakala Chavvafe2360f2015-03-05 18:06:11 +0300419 if (OCTEON_IS_OCTEON3())
420 cvmx_write_csr(CVMX_RST_SOFT_RST, 1);
421 else
422 cvmx_write_csr(CVMX_CIU_SOFT_RST, 1);
David Daney5b3b1682009-01-08 16:46:40 -0800423}
424
425
426/**
427 * Permanently stop a core.
428 *
429 * @arg: Ignored.
430 */
431static void octeon_kill_core(void *arg)
432{
David Daney38c3c0f2013-05-24 16:23:02 +0000433 if (octeon_is_simulation())
David Daney5b3b1682009-01-08 16:46:40 -0800434 /* A break instruction causes the simulator stop a core */
David Daney38c3c0f2013-05-24 16:23:02 +0000435 asm volatile ("break" ::: "memory");
436
437 local_irq_disable();
438 /* Disable watchdog on this core. */
439 cvmx_write_csr(CVMX_CIU_WDOGX(cvmx_get_core_num()), 0);
440 /* Spin in a low power mode. */
441 while (true)
442 asm volatile ("wait" ::: "memory");
David Daney5b3b1682009-01-08 16:46:40 -0800443}
444
445
446/**
447 * Halt the system
448 */
449static void octeon_halt(void)
450{
451 smp_call_function(octeon_kill_core, NULL, 0);
452
453 switch (octeon_bootinfo->board_type) {
454 case CVMX_BOARD_TYPE_NAO38:
455 /* Driving a 1 to GPIO 12 shuts off this board */
456 cvmx_write_csr(CVMX_GPIO_BIT_CFGX(12), 1);
457 cvmx_write_csr(CVMX_GPIO_TX_SET, 0x1000);
458 break;
459 default:
460 octeon_write_lcd("PowerOff");
461 break;
462 }
463
464 octeon_kill_core(NULL);
465}
466
Aaro Koskinen60830862014-07-22 14:51:08 +0300467static char __read_mostly octeon_system_type[80];
468
469static int __init init_octeon_system_type(void)
470{
471 snprintf(octeon_system_type, sizeof(octeon_system_type), "%s (%s)",
472 cvmx_board_type_to_string(octeon_bootinfo->board_type),
473 octeon_model_get_string(read_c0_prid()));
474
475 return 0;
476}
477early_initcall(init_octeon_system_type);
478
David Daney5b3b1682009-01-08 16:46:40 -0800479/**
David Daney5b3b1682009-01-08 16:46:40 -0800480 * Return a string representing the system type
481 *
482 * Returns
483 */
484const char *octeon_board_type_string(void)
485{
Aaro Koskinen60830862014-07-22 14:51:08 +0300486 return octeon_system_type;
David Daney5b3b1682009-01-08 16:46:40 -0800487}
488
489const char *get_system_type(void)
490 __attribute__ ((alias("octeon_board_type_string")));
491
492void octeon_user_io_init(void)
493{
494 union octeon_cvmemctl cvmmemctl;
David Daney5b3b1682009-01-08 16:46:40 -0800495
496 /* Get the current settings for CP0_CVMMEMCTL_REG */
497 cvmmemctl.u64 = read_c0_cvmmemctl();
498 /* R/W If set, marked write-buffer entries time out the same
499 * as as other entries; if clear, marked write-buffer entries
500 * use the maximum timeout. */
501 cvmmemctl.s.dismarkwblongto = 1;
502 /* R/W If set, a merged store does not clear the write-buffer
503 * entry timeout state. */
504 cvmmemctl.s.dismrgclrwbto = 0;
505 /* R/W Two bits that are the MSBs of the resultant CVMSEG LM
506 * word location for an IOBDMA. The other 8 bits come from the
507 * SCRADDR field of the IOBDMA. */
508 cvmmemctl.s.iobdmascrmsb = 0;
509 /* R/W If set, SYNCWS and SYNCS only order marked stores; if
510 * clear, SYNCWS and SYNCS only order unmarked
511 * stores. SYNCWSMARKED has no effect when DISSYNCWS is
512 * set. */
513 cvmmemctl.s.syncwsmarked = 0;
514 /* R/W If set, SYNCWS acts as SYNCW and SYNCS acts as SYNC. */
515 cvmmemctl.s.dissyncws = 0;
516 /* R/W If set, no stall happens on write buffer full. */
517 if (OCTEON_IS_MODEL(OCTEON_CN38XX_PASS2))
518 cvmmemctl.s.diswbfst = 1;
519 else
520 cvmmemctl.s.diswbfst = 0;
521 /* R/W If set (and SX set), supervisor-level loads/stores can
522 * use XKPHYS addresses with <48>==0 */
523 cvmmemctl.s.xkmemenas = 0;
524
525 /* R/W If set (and UX set), user-level loads/stores can use
526 * XKPHYS addresses with VA<48>==0 */
527 cvmmemctl.s.xkmemenau = 0;
528
529 /* R/W If set (and SX set), supervisor-level loads/stores can
530 * use XKPHYS addresses with VA<48>==1 */
531 cvmmemctl.s.xkioenas = 0;
532
533 /* R/W If set (and UX set), user-level loads/stores can use
534 * XKPHYS addresses with VA<48>==1 */
535 cvmmemctl.s.xkioenau = 0;
536
537 /* R/W If set, all stores act as SYNCW (NOMERGE must be set
538 * when this is set) RW, reset to 0. */
539 cvmmemctl.s.allsyncw = 0;
540
541 /* R/W If set, no stores merge, and all stores reach the
542 * coherent bus in order. */
543 cvmmemctl.s.nomerge = 0;
544 /* R/W Selects the bit in the counter used for DID time-outs 0
545 * = 231, 1 = 230, 2 = 229, 3 = 214. Actual time-out is
546 * between 1x and 2x this interval. For example, with
547 * DIDTTO=3, expiration interval is between 16K and 32K. */
548 cvmmemctl.s.didtto = 0;
549 /* R/W If set, the (mem) CSR clock never turns off. */
550 cvmmemctl.s.csrckalwys = 0;
551 /* R/W If set, mclk never turns off. */
552 cvmmemctl.s.mclkalwys = 0;
553 /* R/W Selects the bit in the counter used for write buffer
554 * flush time-outs (WBFLT+11) is the bit position in an
555 * internal counter used to determine expiration. The write
556 * buffer expires between 1x and 2x this interval. For
557 * example, with WBFLT = 0, a write buffer expires between 2K
558 * and 4K cycles after the write buffer entry is allocated. */
559 cvmmemctl.s.wbfltime = 0;
560 /* R/W If set, do not put Istream in the L2 cache. */
561 cvmmemctl.s.istrnol2 = 0;
David Daneyc9941152010-10-07 16:03:53 -0700562
563 /*
564 * R/W The write buffer threshold. As per erratum Core-14752
565 * for CN63XX, a sc/scd might fail if the write buffer is
566 * full. Lowering WBTHRESH greatly lowers the chances of the
567 * write buffer ever being full and triggering the erratum.
568 */
569 if (OCTEON_IS_MODEL(OCTEON_CN63XX_PASS1_X))
570 cvmmemctl.s.wbthresh = 4;
571 else
572 cvmmemctl.s.wbthresh = 10;
573
David Daney5b3b1682009-01-08 16:46:40 -0800574 /* R/W If set, CVMSEG is available for loads/stores in
575 * kernel/debug mode. */
576#if CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE > 0
577 cvmmemctl.s.cvmsegenak = 1;
578#else
579 cvmmemctl.s.cvmsegenak = 0;
580#endif
581 /* R/W If set, CVMSEG is available for loads/stores in
582 * supervisor mode. */
583 cvmmemctl.s.cvmsegenas = 0;
584 /* R/W If set, CVMSEG is available for loads/stores in user
585 * mode. */
586 cvmmemctl.s.cvmsegenau = 0;
David Daney5b3b1682009-01-08 16:46:40 -0800587
David Daneyc9941152010-10-07 16:03:53 -0700588 write_c0_cvmmemctl(cvmmemctl.u64);
David Daney5b3b1682009-01-08 16:46:40 -0800589
David Daney726da2f2015-01-15 16:11:15 +0300590 /* Setup of CVMSEG is done in kernel-entry-init.h */
David Daney5b3b1682009-01-08 16:46:40 -0800591 if (smp_processor_id() == 0)
592 pr_notice("CVMSEG size: %d cache lines (%d bytes)\n",
593 CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE,
594 CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE * 128);
595
David Daney9bc22232016-02-09 11:00:10 -0800596 if (octeon_has_feature(OCTEON_FEATURE_FAU)) {
597 union cvmx_iob_fau_timeout fau_timeout;
David Daney5b3b1682009-01-08 16:46:40 -0800598
David Daney9bc22232016-02-09 11:00:10 -0800599 /* Set a default for the hardware timeouts */
600 fau_timeout.u64 = 0;
601 fau_timeout.s.tout_val = 0xfff;
602 /* Disable tagwait FAU timeout */
603 fau_timeout.s.tout_enb = 0;
604 cvmx_write_csr(CVMX_IOB_FAU_TIMEOUT, fau_timeout.u64);
605 }
606
607 if ((!OCTEON_IS_MODEL(OCTEON_CN68XX) &&
608 !OCTEON_IS_MODEL(OCTEON_CN7XXX)) ||
609 OCTEON_IS_MODEL(OCTEON_CN70XX)) {
610 union cvmx_pow_nw_tim nm_tim;
611
612 nm_tim.u64 = 0;
613 /* 4096 cycles */
614 nm_tim.s.nw_tim = 3;
615 cvmx_write_csr(CVMX_POW_NW_TIM, nm_tim.u64);
616 }
David Daney5b3b1682009-01-08 16:46:40 -0800617
618 write_octeon_c0_icacheerr(0);
619 write_c0_derraddr1(0);
620}
621
622/**
623 * Early entry point for arch setup
624 */
625void __init prom_init(void)
626{
627 struct cvmx_sysinfo *sysinfo;
Ralf Baechleabe77f92012-10-25 16:23:31 +0200628 const char *arg;
629 char *p;
David Daney5b3b1682009-01-08 16:46:40 -0800630 int i;
David Daneyac655fb2015-01-15 16:11:05 +0300631 u64 t;
David Daney5b3b1682009-01-08 16:46:40 -0800632 int argc;
David Daney5b3b1682009-01-08 16:46:40 -0800633#ifdef CONFIG_CAVIUM_RESERVE32
634 int64_t addr = -1;
635#endif
636 /*
637 * The bootloader passes a pointer to the boot descriptor in
638 * $a3, this is available as fw_arg3.
639 */
640 octeon_boot_desc_ptr = (struct octeon_boot_descriptor *)fw_arg3;
641 octeon_bootinfo =
642 cvmx_phys_to_ptr(octeon_boot_desc_ptr->cvmx_desc_vaddr);
643 cvmx_bootmem_init(cvmx_phys_to_ptr(octeon_bootinfo->phy_mem_desc_addr));
644
David Daneye195aa32010-10-07 16:03:49 -0700645 sysinfo = cvmx_sysinfo_get();
646 memset(sysinfo, 0, sizeof(*sysinfo));
647 sysinfo->system_dram_size = octeon_bootinfo->dram_size << 20;
David Daney7d52ab12016-02-01 17:46:54 -0800648 sysinfo->phy_mem_desc_addr = (u64)phys_to_virt(octeon_bootinfo->phy_mem_desc_addr);
649
650 if ((octeon_bootinfo->major_version > 1) ||
651 (octeon_bootinfo->major_version == 1 &&
652 octeon_bootinfo->minor_version >= 4))
653 cvmx_coremask_copy(&sysinfo->core_mask,
654 &octeon_bootinfo->ext_core_mask);
655 else
656 cvmx_coremask_set64(&sysinfo->core_mask,
657 octeon_bootinfo->core_mask);
658
659 /* Some broken u-boot pass garbage in upper bits, clear them out */
660 if (!OCTEON_IS_MODEL(OCTEON_CN78XX))
661 for (i = 512; i < 1024; i++)
662 cvmx_coremask_clear_core(&sysinfo->core_mask, i);
663
David Daneye195aa32010-10-07 16:03:49 -0700664 sysinfo->exception_base_addr = octeon_bootinfo->exception_base_addr;
665 sysinfo->cpu_clock_hz = octeon_bootinfo->eclock_hz;
666 sysinfo->dram_data_rate_hz = octeon_bootinfo->dclock_hz * 2;
667 sysinfo->board_type = octeon_bootinfo->board_type;
668 sysinfo->board_rev_major = octeon_bootinfo->board_rev_major;
669 sysinfo->board_rev_minor = octeon_bootinfo->board_rev_minor;
670 memcpy(sysinfo->mac_addr_base, octeon_bootinfo->mac_addr_base,
671 sizeof(sysinfo->mac_addr_base));
672 sysinfo->mac_addr_count = octeon_bootinfo->mac_addr_count;
673 memcpy(sysinfo->board_serial_number,
674 octeon_bootinfo->board_serial_number,
675 sizeof(sysinfo->board_serial_number));
676 sysinfo->compact_flash_common_base_addr =
677 octeon_bootinfo->compact_flash_common_base_addr;
678 sysinfo->compact_flash_attribute_base_addr =
679 octeon_bootinfo->compact_flash_attribute_base_addr;
680 sysinfo->led_display_base_addr = octeon_bootinfo->led_display_base_addr;
681 sysinfo->dfa_ref_clock_hz = octeon_bootinfo->dfa_ref_clock_hz;
682 sysinfo->bootloader_config_flags = octeon_bootinfo->config_flags;
683
Chandrakala Chavvaac6d9b32015-01-15 16:11:17 +0300684 if (OCTEON_IS_OCTEON2()) {
David Daneye195aa32010-10-07 16:03:49 -0700685 /* I/O clock runs at a different rate than the CPU. */
686 union cvmx_mio_rst_boot rst_boot;
687 rst_boot.u64 = cvmx_read_csr(CVMX_MIO_RST_BOOT);
688 octeon_io_clock_rate = 50000000 * rst_boot.s.pnr_mul;
Chandrakala Chavvaac6d9b32015-01-15 16:11:17 +0300689 } else if (OCTEON_IS_OCTEON3()) {
690 /* I/O clock runs at a different rate than the CPU. */
691 union cvmx_rst_boot rst_boot;
692 rst_boot.u64 = cvmx_read_csr(CVMX_RST_BOOT);
693 octeon_io_clock_rate = 50000000 * rst_boot.s.pnr_mul;
David Daneye195aa32010-10-07 16:03:49 -0700694 } else {
695 octeon_io_clock_rate = sysinfo->cpu_clock_hz;
696 }
697
David Daneyac655fb2015-01-15 16:11:05 +0300698 t = read_c0_cvmctl();
699 if ((t & (1ull << 27)) == 0) {
700 /*
701 * Setup the multiplier save/restore code if
702 * CvmCtl[NOMUL] clear.
703 */
704 void *save;
705 void *save_end;
706 void *restore;
707 void *restore_end;
708 int save_len;
709 int restore_len;
710 int save_max = (char *)octeon_mult_save_end -
711 (char *)octeon_mult_save;
712 int restore_max = (char *)octeon_mult_restore_end -
713 (char *)octeon_mult_restore;
714 if (current_cpu_data.cputype == CPU_CAVIUM_OCTEON3) {
715 save = octeon_mult_save3;
716 save_end = octeon_mult_save3_end;
717 restore = octeon_mult_restore3;
718 restore_end = octeon_mult_restore3_end;
719 } else {
720 save = octeon_mult_save2;
721 save_end = octeon_mult_save2_end;
722 restore = octeon_mult_restore2;
723 restore_end = octeon_mult_restore2_end;
724 }
725 save_len = (char *)save_end - (char *)save;
726 restore_len = (char *)restore_end - (char *)restore;
727 if (!WARN_ON(save_len > save_max ||
728 restore_len > restore_max)) {
729 memcpy(octeon_mult_save, save, save_len);
730 memcpy(octeon_mult_restore, restore, restore_len);
731 }
732 }
733
David Daney5b3b1682009-01-08 16:46:40 -0800734 /*
735 * Only enable the LED controller if we're running on a CN38XX, CN58XX,
736 * or CN56XX. The CN30XX and CN31XX don't have an LED controller.
737 */
738 if (!octeon_is_simulation() &&
739 octeon_has_feature(OCTEON_FEATURE_LED_CONTROLLER)) {
740 cvmx_write_csr(CVMX_LED_EN, 0);
741 cvmx_write_csr(CVMX_LED_PRT, 0);
742 cvmx_write_csr(CVMX_LED_DBG, 0);
743 cvmx_write_csr(CVMX_LED_PRT_FMT, 0);
744 cvmx_write_csr(CVMX_LED_UDD_CNTX(0), 32);
745 cvmx_write_csr(CVMX_LED_UDD_CNTX(1), 32);
746 cvmx_write_csr(CVMX_LED_UDD_DATX(0), 0);
747 cvmx_write_csr(CVMX_LED_UDD_DATX(1), 0);
748 cvmx_write_csr(CVMX_LED_EN, 1);
749 }
750#ifdef CONFIG_CAVIUM_RESERVE32
751 /*
752 * We need to temporarily allocate all memory in the reserve32
753 * region. This makes sure the kernel doesn't allocate this
754 * memory when it is getting memory from the
755 * bootloader. Later, after the memory allocations are
756 * complete, the reserve32 will be freed.
David Daney1ef28872010-03-03 11:07:07 -0800757 *
David Daney5b3b1682009-01-08 16:46:40 -0800758 * Allocate memory for RESERVED32 aligned on 2MB boundary. This
759 * is in case we later use hugetlb entries with it.
760 */
761 addr = cvmx_bootmem_phy_named_block_alloc(CONFIG_CAVIUM_RESERVE32 << 20,
762 0, 0, 2 << 20,
763 "CAVIUM_RESERVE32", 0);
David Daney5b3b1682009-01-08 16:46:40 -0800764 if (addr < 0)
765 pr_err("Failed to allocate CAVIUM_RESERVE32 memory area\n");
766 else
767 octeon_reserve32_memory = addr;
768#endif
769
770#ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2
771 if (cvmx_read_csr(CVMX_L2D_FUS3) & (3ull << 34)) {
772 pr_info("Skipping L2 locking due to reduced L2 cache size\n");
773 } else {
Ralf Baechle39205752013-06-13 01:29:24 +0200774 uint32_t __maybe_unused ebase = read_c0_ebase() & 0x3ffff000;
David Daney5b3b1682009-01-08 16:46:40 -0800775#ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_TLB
776 /* TLB refill */
777 cvmx_l2c_lock_mem_region(ebase, 0x100);
778#endif
779#ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_EXCEPTION
780 /* General exception */
781 cvmx_l2c_lock_mem_region(ebase + 0x180, 0x80);
782#endif
783#ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_LOW_LEVEL_INTERRUPT
784 /* Interrupt handler */
785 cvmx_l2c_lock_mem_region(ebase + 0x200, 0x80);
786#endif
787#ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_INTERRUPT
788 cvmx_l2c_lock_mem_region(__pa_symbol(handle_int), 0x100);
789 cvmx_l2c_lock_mem_region(__pa_symbol(plat_irq_dispatch), 0x80);
790#endif
791#ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_MEMCPY
792 cvmx_l2c_lock_mem_region(__pa_symbol(memcpy), 0x480);
793#endif
794 }
795#endif
796
David Daney5b3b1682009-01-08 16:46:40 -0800797 octeon_check_cpu_bist();
798
799 octeon_uart = octeon_get_boot_uart();
800
David Daney5b3b1682009-01-08 16:46:40 -0800801#ifdef CONFIG_SMP
802 octeon_write_lcd("LinuxSMP");
803#else
804 octeon_write_lcd("Linux");
805#endif
806
David Daney70a26a22012-08-21 11:45:05 -0700807 octeon_setup_delays();
808
David Daney5b3b1682009-01-08 16:46:40 -0800809 /*
810 * BIST should always be enabled when doing a soft reset. L2
811 * Cache locking for instance is not cleared unless BIST is
812 * enabled. Unfortunately due to a chip errata G-200 for
813 * Cn38XX and CN31XX, BIST msut be disabled on these parts.
814 */
815 if (OCTEON_IS_MODEL(OCTEON_CN38XX_PASS2) ||
816 OCTEON_IS_MODEL(OCTEON_CN31XX))
817 cvmx_write_csr(CVMX_CIU_SOFT_BIST, 0);
818 else
819 cvmx_write_csr(CVMX_CIU_SOFT_BIST, 1);
820
821 /* Default to 64MB in the simulator to speed things up */
822 if (octeon_is_simulation())
823 MAX_MEMORY = 64ull << 20;
824
Ralf Baechleabe77f92012-10-25 16:23:31 +0200825 arg = strstr(arcs_cmdline, "mem=");
826 if (arg) {
827 MAX_MEMORY = memparse(arg + 4, &p);
828 if (MAX_MEMORY == 0)
829 MAX_MEMORY = 32ull << 30;
830 if (*p == '@')
831 RESERVE_LOW_MEM = memparse(p + 1, &p);
832 }
833
David Daney5b3b1682009-01-08 16:46:40 -0800834 arcs_cmdline[0] = 0;
835 argc = octeon_boot_desc_ptr->argc;
836 for (i = 0; i < argc; i++) {
837 const char *arg =
838 cvmx_phys_to_ptr(octeon_boot_desc_ptr->argv[i]);
839 if ((strncmp(arg, "MEM=", 4) == 0) ||
840 (strncmp(arg, "mem=", 4) == 0)) {
Ralf Baechleabe77f92012-10-25 16:23:31 +0200841 MAX_MEMORY = memparse(arg + 4, &p);
David Daney5b3b1682009-01-08 16:46:40 -0800842 if (MAX_MEMORY == 0)
843 MAX_MEMORY = 32ull << 30;
Ralf Baechleabe77f92012-10-25 16:23:31 +0200844 if (*p == '@')
845 RESERVE_LOW_MEM = memparse(p + 1, &p);
Ralf Baechleabe77f92012-10-25 16:23:31 +0200846#ifdef CONFIG_KEXEC
847 } else if (strncmp(arg, "crashkernel=", 12) == 0) {
848 crashk_size = memparse(arg+12, &p);
849 if (*p == '@')
850 crashk_base = memparse(p+1, &p);
851 strcat(arcs_cmdline, " ");
852 strcat(arcs_cmdline, arg);
853 /*
854 * To do: switch parsing to new style, something like:
855 * parse_crashkernel(arg, sysinfo->system_dram_size,
Ralf Baechle70342282013-01-22 12:59:30 +0100856 * &crashk_size, &crashk_base);
Ralf Baechleabe77f92012-10-25 16:23:31 +0200857 */
858#endif
David Daney5b3b1682009-01-08 16:46:40 -0800859 } else if (strlen(arcs_cmdline) + strlen(arg) + 1 <
860 sizeof(arcs_cmdline) - 1) {
861 strcat(arcs_cmdline, " ");
862 strcat(arcs_cmdline, arg);
863 }
864 }
865
866 if (strstr(arcs_cmdline, "console=") == NULL) {
David Daney5b3b1682009-01-08 16:46:40 -0800867#ifdef CONFIG_CAVIUM_OCTEON_2ND_KERNEL
868 strcat(arcs_cmdline, " console=ttyS0,115200");
869#else
870 if (octeon_uart == 1)
871 strcat(arcs_cmdline, " console=ttyS1,115200");
872 else
873 strcat(arcs_cmdline, " console=ttyS0,115200");
874#endif
David Daney5b3b1682009-01-08 16:46:40 -0800875 }
876
David Daney5b3b1682009-01-08 16:46:40 -0800877 mips_hpt_frequency = octeon_get_clock_rate();
878
879 octeon_init_cvmcount();
880
881 _machine_restart = octeon_restart;
882 _machine_halt = octeon_halt;
883
Ralf Baechleabe77f92012-10-25 16:23:31 +0200884#ifdef CONFIG_KEXEC
885 _machine_kexec_shutdown = octeon_shutdown;
886 _machine_crash_shutdown = octeon_crash_shutdown;
887 _machine_kexec_prepare = octeon_kexec_prepare;
888#endif
889
David Daney5b3b1682009-01-08 16:46:40 -0800890 octeon_user_io_init();
891 register_smp_ops(&octeon_smp_ops);
892}
893
David Daney2b5987a2010-08-04 14:53:57 -0700894/* Exclude a single page from the regions obtained in plat_mem_setup. */
Ralf Baechleabe77f92012-10-25 16:23:31 +0200895#ifndef CONFIG_CRASH_DUMP
David Daney2b5987a2010-08-04 14:53:57 -0700896static __init void memory_exclude_page(u64 addr, u64 *mem, u64 *size)
897{
898 if (addr > *mem && addr < *mem + *size) {
899 u64 inc = addr - *mem;
900 add_memory_region(*mem, inc, BOOT_MEM_RAM);
901 *mem += inc;
902 *size -= inc;
903 }
904
905 if (addr == *mem && *size > PAGE_SIZE) {
906 *mem += PAGE_SIZE;
907 *size -= PAGE_SIZE;
908 }
909}
Ralf Baechleabe77f92012-10-25 16:23:31 +0200910#endif /* CONFIG_CRASH_DUMP */
David Daney2b5987a2010-08-04 14:53:57 -0700911
David Daney5b3b1682009-01-08 16:46:40 -0800912void __init plat_mem_setup(void)
913{
914 uint64_t mem_alloc_size;
915 uint64_t total;
Ralf Baechleabe77f92012-10-25 16:23:31 +0200916 uint64_t crashk_end;
917#ifndef CONFIG_CRASH_DUMP
David Daney5b3b1682009-01-08 16:46:40 -0800918 int64_t memory;
Ralf Baechleabe77f92012-10-25 16:23:31 +0200919 uint64_t kernel_start;
920 uint64_t kernel_size;
921#endif
David Daney5b3b1682009-01-08 16:46:40 -0800922
923 total = 0;
Ralf Baechleabe77f92012-10-25 16:23:31 +0200924 crashk_end = 0;
David Daney5b3b1682009-01-08 16:46:40 -0800925
David Daney5b3b1682009-01-08 16:46:40 -0800926 /*
927 * The Mips memory init uses the first memory location for
928 * some memory vectors. When SPARSEMEM is in use, it doesn't
929 * verify that the size is big enough for the final
930 * vectors. Making the smallest chuck 4MB seems to be enough
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300931 * to consistently work.
David Daney5b3b1682009-01-08 16:46:40 -0800932 */
933 mem_alloc_size = 4 << 20;
934 if (mem_alloc_size > MAX_MEMORY)
935 mem_alloc_size = MAX_MEMORY;
936
Ralf Baechleabe77f92012-10-25 16:23:31 +0200937/* Crashkernel ignores bootmem list. It relies on mem=X@Y option */
938#ifdef CONFIG_CRASH_DUMP
939 add_memory_region(RESERVE_LOW_MEM, MAX_MEMORY, BOOT_MEM_RAM);
940 total += MAX_MEMORY;
941#else
942#ifdef CONFIG_KEXEC
943 if (crashk_size > 0) {
944 add_memory_region(crashk_base, crashk_size, BOOT_MEM_RAM);
945 crashk_end = crashk_base + crashk_size;
946 }
947#endif
David Daney5b3b1682009-01-08 16:46:40 -0800948 /*
949 * When allocating memory, we want incrementing addresses from
950 * bootmem_alloc so the code in add_memory_region can merge
951 * regions next to each other.
952 */
953 cvmx_bootmem_lock();
954 while ((boot_mem_map.nr_map < BOOT_MEM_MAP_MAX)
955 && (total < MAX_MEMORY)) {
David Daney5b3b1682009-01-08 16:46:40 -0800956 memory = cvmx_bootmem_phy_alloc(mem_alloc_size,
Matt Bennett66803dd2015-09-30 17:40:42 +1300957 __pa_symbol(&_end), -1,
David Daney5b3b1682009-01-08 16:46:40 -0800958 0x100000,
959 CVMX_BOOTMEM_FLAG_NO_LOCKING);
David Daney5b3b1682009-01-08 16:46:40 -0800960 if (memory >= 0) {
David Daney2b5987a2010-08-04 14:53:57 -0700961 u64 size = mem_alloc_size;
Ralf Baechleabe77f92012-10-25 16:23:31 +0200962#ifdef CONFIG_KEXEC
963 uint64_t end;
964#endif
David Daney2b5987a2010-08-04 14:53:57 -0700965
966 /*
967 * exclude a page at the beginning and end of
968 * the 256MB PCIe 'hole' so the kernel will not
969 * try to allocate multi-page buffers that
970 * span the discontinuity.
971 */
972 memory_exclude_page(CVMX_PCIE_BAR1_PHYS_BASE,
973 &memory, &size);
974 memory_exclude_page(CVMX_PCIE_BAR1_PHYS_BASE +
975 CVMX_PCIE_BAR1_PHYS_SIZE,
976 &memory, &size);
Ralf Baechleabe77f92012-10-25 16:23:31 +0200977#ifdef CONFIG_KEXEC
978 end = memory + mem_alloc_size;
David Daney2b5987a2010-08-04 14:53:57 -0700979
David Daney5b3b1682009-01-08 16:46:40 -0800980 /*
Ralf Baechleabe77f92012-10-25 16:23:31 +0200981 * This function automatically merges address regions
982 * next to each other if they are received in
983 * incrementing order
David Daney5b3b1682009-01-08 16:46:40 -0800984 */
Ralf Baechleabe77f92012-10-25 16:23:31 +0200985 if (memory < crashk_base && end > crashk_end) {
986 /* region is fully in */
987 add_memory_region(memory,
988 crashk_base - memory,
989 BOOT_MEM_RAM);
990 total += crashk_base - memory;
991 add_memory_region(crashk_end,
992 end - crashk_end,
993 BOOT_MEM_RAM);
994 total += end - crashk_end;
995 continue;
996 }
997
998 if (memory >= crashk_base && end <= crashk_end)
999 /*
1000 * Entire memory region is within the new
1001 * kernel's memory, ignore it.
1002 */
1003 continue;
1004
1005 if (memory > crashk_base && memory < crashk_end &&
1006 end > crashk_end) {
1007 /*
1008 * Overlap with the beginning of the region,
1009 * reserve the beginning.
1010 */
1011 mem_alloc_size -= crashk_end - memory;
1012 memory = crashk_end;
1013 } else if (memory < crashk_base && end > crashk_base &&
1014 end < crashk_end)
1015 /*
1016 * Overlap with the beginning of the region,
1017 * chop of end.
1018 */
1019 mem_alloc_size -= end - crashk_base;
1020#endif
1021 add_memory_region(memory, mem_alloc_size, BOOT_MEM_RAM);
David Daney5b3b1682009-01-08 16:46:40 -08001022 total += mem_alloc_size;
Ralf Baechleabe77f92012-10-25 16:23:31 +02001023 /* Recovering mem_alloc_size */
1024 mem_alloc_size = 4 << 20;
David Daney5b3b1682009-01-08 16:46:40 -08001025 } else {
1026 break;
1027 }
1028 }
1029 cvmx_bootmem_unlock();
Ralf Baechleabe77f92012-10-25 16:23:31 +02001030 /* Add the memory region for the kernel. */
1031 kernel_start = (unsigned long) _text;
David Daneyd949b4f2013-06-12 17:28:33 +00001032 kernel_size = _end - _text;
Ralf Baechleabe77f92012-10-25 16:23:31 +02001033
1034 /* Adjust for physical offset. */
1035 kernel_start &= ~0xffffffff80000000ULL;
1036 add_memory_region(kernel_start, kernel_size, BOOT_MEM_RAM);
1037#endif /* CONFIG_CRASH_DUMP */
David Daney5b3b1682009-01-08 16:46:40 -08001038
1039#ifdef CONFIG_CAVIUM_RESERVE32
1040 /*
1041 * Now that we've allocated the kernel memory it is safe to
1042 * free the reserved region. We free it here so that builtin
1043 * drivers can use the memory.
1044 */
1045 if (octeon_reserve32_memory)
1046 cvmx_bootmem_free_named("CAVIUM_RESERVE32");
1047#endif /* CONFIG_CAVIUM_RESERVE32 */
1048
1049 if (total == 0)
1050 panic("Unable to allocate memory from "
Ralf Baechlef7777dc2013-09-18 16:05:26 +02001051 "cvmx_bootmem_phy_alloc");
David Daney5b3b1682009-01-08 16:46:40 -08001052}
1053
David Daneyea4354642010-07-23 18:41:44 -07001054/*
Ralf Baechle70342282013-01-22 12:59:30 +01001055 * Emit one character to the boot UART. Exported for use by the
David Daneyea4354642010-07-23 18:41:44 -07001056 * watchdog timer.
1057 */
David Daney5b3b1682009-01-08 16:46:40 -08001058int prom_putchar(char c)
1059{
1060 uint64_t lsrval;
1061
1062 /* Spin until there is room */
1063 do {
1064 lsrval = cvmx_read_csr(CVMX_MIO_UARTX_LSR(octeon_uart));
1065 } while ((lsrval & 0x20) == 0);
1066
1067 /* Write the byte */
David Daney606c9582010-05-19 14:16:32 -07001068 cvmx_write_csr(CVMX_MIO_UARTX_THR(octeon_uart), c & 0xffull);
David Daney5b3b1682009-01-08 16:46:40 -08001069 return 1;
1070}
David Daneyea4354642010-07-23 18:41:44 -07001071EXPORT_SYMBOL(prom_putchar);
David Daney5b3b1682009-01-08 16:46:40 -08001072
Aaro Koskinenaa816c12015-02-26 01:31:04 +02001073void __init prom_free_prom_memory(void)
David Daney5b3b1682009-01-08 16:46:40 -08001074{
David Daneye3d0ead2015-01-15 16:11:13 +03001075 if (CAVIUM_OCTEON_DCACHE_PREFETCH_WAR) {
David Daneyc9941152010-10-07 16:03:53 -07001076 /* Check for presence of Core-14449 fix. */
1077 u32 insn;
1078 u32 *foo;
1079
1080 foo = &insn;
1081
1082 asm volatile("# before" : : : "memory");
1083 prefetch(foo);
1084 asm volatile(
1085 ".set push\n\t"
1086 ".set noreorder\n\t"
1087 "bal 1f\n\t"
1088 "nop\n"
1089 "1:\tlw %0,-12($31)\n\t"
1090 ".set pop\n\t"
1091 : "=r" (insn) : : "$31", "memory");
1092
1093 if ((insn >> 26) != 0x33)
Ralf Baechleab75dc02011-11-17 15:07:31 +00001094 panic("No PREF instruction at Core-14449 probe point.");
David Daneyc9941152010-10-07 16:03:53 -07001095
1096 if (((insn >> 16) & 0x1f) != 28)
David Daneye3d0ead2015-01-15 16:11:13 +03001097 panic("OCTEON II DCache prefetch workaround not in place (%04x).\n"
1098 "Please build kernel with proper options (CONFIG_CAVIUM_CN63XXP1).",
1099 insn);
David Daneyc9941152010-10-07 16:03:53 -07001100 }
David Daney5b3b1682009-01-08 16:46:40 -08001101}
David Daney7ed18152012-07-05 18:12:38 +02001102
1103int octeon_prune_device_tree(void);
1104
Aaro Koskinen651d19f2015-09-11 17:46:15 +03001105extern const char __appended_dtb;
David Daney7ed18152012-07-05 18:12:38 +02001106extern const char __dtb_octeon_3xxx_begin;
David Daney7ed18152012-07-05 18:12:38 +02001107extern const char __dtb_octeon_68xx_begin;
David Daney7ed18152012-07-05 18:12:38 +02001108void __init device_tree_init(void)
1109{
Rob Herring8c97cec2014-04-02 17:45:06 -05001110 const void *fdt;
David Daney7ed18152012-07-05 18:12:38 +02001111 bool do_prune;
1112
Aaro Koskinen651d19f2015-09-11 17:46:15 +03001113#ifdef CONFIG_MIPS_ELF_APPENDED_DTB
1114 if (!fdt_check_header(&__appended_dtb)) {
1115 fdt = &__appended_dtb;
1116 do_prune = false;
1117 pr_info("Using appended Device Tree.\n");
1118 } else
1119#endif
David Daney7ed18152012-07-05 18:12:38 +02001120 if (octeon_bootinfo->minor_version >= 3 && octeon_bootinfo->fdt_addr) {
1121 fdt = phys_to_virt(octeon_bootinfo->fdt_addr);
1122 if (fdt_check_header(fdt))
1123 panic("Corrupt Device Tree passed to kernel.");
David Daney7ed18152012-07-05 18:12:38 +02001124 do_prune = false;
Aaro Koskinen651d19f2015-09-11 17:46:15 +03001125 pr_info("Using passed Device Tree.\n");
David Daney7ed18152012-07-05 18:12:38 +02001126 } else if (OCTEON_IS_MODEL(OCTEON_CN68XX)) {
Rob Herring8c97cec2014-04-02 17:45:06 -05001127 fdt = &__dtb_octeon_68xx_begin;
David Daney7ed18152012-07-05 18:12:38 +02001128 do_prune = true;
1129 } else {
Rob Herring8c97cec2014-04-02 17:45:06 -05001130 fdt = &__dtb_octeon_3xxx_begin;
David Daney7ed18152012-07-05 18:12:38 +02001131 do_prune = true;
1132 }
1133
Rob Herring8c97cec2014-04-02 17:45:06 -05001134 initial_boot_params = (void *)fdt;
David Daney7ed18152012-07-05 18:12:38 +02001135
1136 if (do_prune) {
1137 octeon_prune_device_tree();
1138 pr_info("Using internal Device Tree.\n");
David Daney7ed18152012-07-05 18:12:38 +02001139 }
Rob Herring8c97cec2014-04-02 17:45:06 -05001140 unflatten_and_copy_device_tree();
David Daney7ed18152012-07-05 18:12:38 +02001141}
Ralf Baechlef65aad42012-10-17 00:39:09 +02001142
David Daneye1ced092012-11-15 13:58:59 -08001143static int __initdata disable_octeon_edac_p;
1144
1145static int __init disable_octeon_edac(char *str)
1146{
1147 disable_octeon_edac_p = 1;
1148 return 0;
1149}
1150early_param("disable_octeon_edac", disable_octeon_edac);
1151
Ralf Baechlef65aad42012-10-17 00:39:09 +02001152static char *edac_device_names[] = {
David Daneye1ced092012-11-15 13:58:59 -08001153 "octeon_l2c_edac",
1154 "octeon_pc_edac",
Ralf Baechlef65aad42012-10-17 00:39:09 +02001155};
1156
1157static int __init edac_devinit(void)
1158{
1159 struct platform_device *dev;
1160 int i, err = 0;
David Daneye1ced092012-11-15 13:58:59 -08001161 int num_lmc;
Ralf Baechlef65aad42012-10-17 00:39:09 +02001162 char *name;
1163
David Daneye1ced092012-11-15 13:58:59 -08001164 if (disable_octeon_edac_p)
1165 return 0;
1166
Ralf Baechlef65aad42012-10-17 00:39:09 +02001167 for (i = 0; i < ARRAY_SIZE(edac_device_names); i++) {
1168 name = edac_device_names[i];
1169 dev = platform_device_register_simple(name, -1, NULL, 0);
1170 if (IS_ERR(dev)) {
Masanari Iida6774def2014-11-05 22:26:48 +09001171 pr_err("Registration of %s failed!\n", name);
Ralf Baechlef65aad42012-10-17 00:39:09 +02001172 err = PTR_ERR(dev);
1173 }
1174 }
1175
David Daneye1ced092012-11-15 13:58:59 -08001176 num_lmc = OCTEON_IS_MODEL(OCTEON_CN68XX) ? 4 :
1177 (OCTEON_IS_MODEL(OCTEON_CN56XX) ? 2 : 1);
1178 for (i = 0; i < num_lmc; i++) {
1179 dev = platform_device_register_simple("octeon_lmc_edac",
1180 i, NULL, 0);
1181 if (IS_ERR(dev)) {
Masanari Iida6774def2014-11-05 22:26:48 +09001182 pr_err("Registration of octeon_lmc_edac %d failed!\n", i);
David Daneye1ced092012-11-15 13:58:59 -08001183 err = PTR_ERR(dev);
1184 }
1185 }
1186
Ralf Baechlef65aad42012-10-17 00:39:09 +02001187 return err;
1188}
Ralf Baechlef65aad42012-10-17 00:39:09 +02001189device_initcall(edac_devinit);
Aaro Koskinend8b74272013-07-25 20:26:48 +03001190
1191static void __initdata *octeon_dummy_iospace;
1192
1193static int __init octeon_no_pci_init(void)
1194{
1195 /*
1196 * Initially assume there is no PCI. The PCI/PCIe platform code will
1197 * later re-initialize these to correct values if they are present.
1198 */
1199 octeon_dummy_iospace = vzalloc(IO_SPACE_LIMIT);
1200 set_io_port_base((unsigned long)octeon_dummy_iospace);
1201 ioport_resource.start = MAX_RESOURCE;
1202 ioport_resource.end = 0;
1203 return 0;
1204}
1205core_initcall(octeon_no_pci_init);
1206
1207static int __init octeon_no_pci_release(void)
1208{
1209 /*
1210 * Release the allocated memory if a real IO space is there.
1211 */
1212 if ((unsigned long)octeon_dummy_iospace != mips_io_port_base)
1213 vfree(octeon_dummy_iospace);
1214 return 0;
1215}
1216late_initcall(octeon_no_pci_release);