blob: dba7cf7656c75bd977e41bfcf64e03c619d4ff2d [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>
David Daney5b3b1682009-01-08 16:46:40 -080044
David Daney5b3b1682009-01-08 16:46:40 -080045extern struct plat_smp_ops octeon_smp_ops;
46
47#ifdef CONFIG_PCI
48extern void pci_console_init(const char *arg);
49#endif
50
David Daney5b3b1682009-01-08 16:46:40 -080051static unsigned long long MAX_MEMORY = 512ull << 20;
52
53struct octeon_boot_descriptor *octeon_boot_desc_ptr;
54
55struct cvmx_bootinfo *octeon_bootinfo;
56EXPORT_SYMBOL(octeon_bootinfo);
57
Ralf Baechleabe77f92012-10-25 16:23:31 +020058static unsigned long long RESERVE_LOW_MEM = 0ull;
59#ifdef CONFIG_KEXEC
60#ifdef CONFIG_SMP
61/*
62 * Wait for relocation code is prepared and send
63 * secondary CPUs to spin until kernel is relocated.
64 */
65static void octeon_kexec_smp_down(void *ignored)
66{
67 int cpu = smp_processor_id();
68
69 local_irq_disable();
70 set_cpu_online(cpu, false);
71 while (!atomic_read(&kexec_ready_to_reboot))
72 cpu_relax();
73
74 asm volatile (
75 " sync \n"
76 " synci ($0) \n");
77
78 relocated_kexec_smp_wait(NULL);
79}
80#endif
81
82#define OCTEON_DDR0_BASE (0x0ULL)
83#define OCTEON_DDR0_SIZE (0x010000000ULL)
84#define OCTEON_DDR1_BASE (0x410000000ULL)
85#define OCTEON_DDR1_SIZE (0x010000000ULL)
86#define OCTEON_DDR2_BASE (0x020000000ULL)
87#define OCTEON_DDR2_SIZE (0x3e0000000ULL)
88#define OCTEON_MAX_PHY_MEM_SIZE (16*1024*1024*1024ULL)
89
90static struct kimage *kimage_ptr;
91
92static void kexec_bootmem_init(uint64_t mem_size, uint32_t low_reserved_bytes)
93{
94 int64_t addr;
95 struct cvmx_bootmem_desc *bootmem_desc;
96
97 bootmem_desc = cvmx_bootmem_get_desc();
98
99 if (mem_size > OCTEON_MAX_PHY_MEM_SIZE) {
100 mem_size = OCTEON_MAX_PHY_MEM_SIZE;
101 pr_err("Error: requested memory too large,"
102 "truncating to maximum size\n");
103 }
104
105 bootmem_desc->major_version = CVMX_BOOTMEM_DESC_MAJ_VER;
106 bootmem_desc->minor_version = CVMX_BOOTMEM_DESC_MIN_VER;
107
108 addr = (OCTEON_DDR0_BASE + RESERVE_LOW_MEM + low_reserved_bytes);
109 bootmem_desc->head_addr = 0;
110
111 if (mem_size <= OCTEON_DDR0_SIZE) {
112 __cvmx_bootmem_phy_free(addr,
113 mem_size - RESERVE_LOW_MEM -
114 low_reserved_bytes, 0);
115 return;
116 }
117
118 __cvmx_bootmem_phy_free(addr,
119 OCTEON_DDR0_SIZE - RESERVE_LOW_MEM -
120 low_reserved_bytes, 0);
121
122 mem_size -= OCTEON_DDR0_SIZE;
123
124 if (mem_size > OCTEON_DDR1_SIZE) {
125 __cvmx_bootmem_phy_free(OCTEON_DDR1_BASE, OCTEON_DDR1_SIZE, 0);
126 __cvmx_bootmem_phy_free(OCTEON_DDR2_BASE,
127 mem_size - OCTEON_DDR1_SIZE, 0);
128 } else
129 __cvmx_bootmem_phy_free(OCTEON_DDR1_BASE, mem_size, 0);
130}
131
132static int octeon_kexec_prepare(struct kimage *image)
133{
134 int i;
135 char *bootloader = "kexec";
136
137 octeon_boot_desc_ptr->argc = 0;
138 for (i = 0; i < image->nr_segments; i++) {
139 if (!strncmp(bootloader, (char *)image->segment[i].buf,
140 strlen(bootloader))) {
141 /*
142 * convert command line string to array
143 * of parameters (as bootloader does).
144 */
145 int argc = 0, offt;
146 char *str = (char *)image->segment[i].buf;
147 char *ptr = strchr(str, ' ');
148 while (ptr && (OCTEON_ARGV_MAX_ARGS > argc)) {
149 *ptr = '\0';
150 if (ptr[1] != ' ') {
151 offt = (int)(ptr - str + 1);
152 octeon_boot_desc_ptr->argv[argc] =
153 image->segment[i].mem + offt;
154 argc++;
155 }
156 ptr = strchr(ptr + 1, ' ');
157 }
158 octeon_boot_desc_ptr->argc = argc;
159 break;
160 }
161 }
162
163 /*
164 * Information about segments will be needed during pre-boot memory
165 * initialization.
166 */
167 kimage_ptr = image;
168 return 0;
169}
170
171static void octeon_generic_shutdown(void)
172{
EunBong Songed1197f2013-03-24 22:18:35 +0000173 int i;
174#ifdef CONFIG_SMP
175 int cpu;
176#endif
Ralf Baechleabe77f92012-10-25 16:23:31 +0200177 struct cvmx_bootmem_desc *bootmem_desc;
178 void *named_block_array_ptr;
179
180 bootmem_desc = cvmx_bootmem_get_desc();
181 named_block_array_ptr =
182 cvmx_phys_to_ptr(bootmem_desc->named_block_array_addr);
183
184#ifdef CONFIG_SMP
185 /* disable watchdogs */
186 for_each_online_cpu(cpu)
187 cvmx_write_csr(CVMX_CIU_WDOGX(cpu_logical_map(cpu)), 0);
188#else
189 cvmx_write_csr(CVMX_CIU_WDOGX(cvmx_get_core_num()), 0);
190#endif
191 if (kimage_ptr != kexec_crash_image) {
192 memset(named_block_array_ptr,
193 0x0,
194 CVMX_BOOTMEM_NUM_NAMED_BLOCKS *
195 sizeof(struct cvmx_bootmem_named_block_desc));
196 /*
197 * Mark all memory (except low 0x100000 bytes) as free.
198 * It is the same thing that bootloader does.
199 */
200 kexec_bootmem_init(octeon_bootinfo->dram_size*1024ULL*1024ULL,
201 0x100000);
202 /*
203 * Allocate all segments to avoid their corruption during boot.
204 */
205 for (i = 0; i < kimage_ptr->nr_segments; i++)
206 cvmx_bootmem_alloc_address(
207 kimage_ptr->segment[i].memsz + 2*PAGE_SIZE,
208 kimage_ptr->segment[i].mem - PAGE_SIZE,
209 PAGE_SIZE);
210 } else {
211 /*
212 * Do not mark all memory as free. Free only named sections
213 * leaving the rest of memory unchanged.
214 */
215 struct cvmx_bootmem_named_block_desc *ptr =
216 (struct cvmx_bootmem_named_block_desc *)
217 named_block_array_ptr;
218
219 for (i = 0; i < bootmem_desc->named_block_num_blocks; i++)
220 if (ptr[i].size)
221 cvmx_bootmem_free_named(ptr[i].name);
222 }
223 kexec_args[2] = 1UL; /* running on octeon_main_processor */
224 kexec_args[3] = (unsigned long)octeon_boot_desc_ptr;
225#ifdef CONFIG_SMP
226 secondary_kexec_args[2] = 0UL; /* running on secondary cpu */
227 secondary_kexec_args[3] = (unsigned long)octeon_boot_desc_ptr;
228#endif
229}
230
231static void octeon_shutdown(void)
232{
233 octeon_generic_shutdown();
234#ifdef CONFIG_SMP
235 smp_call_function(octeon_kexec_smp_down, NULL, 0);
236 smp_wmb();
237 while (num_online_cpus() > 1) {
238 cpu_relax();
239 mdelay(1);
240 }
241#endif
242}
243
244static void octeon_crash_shutdown(struct pt_regs *regs)
245{
246 octeon_generic_shutdown();
247 default_machine_crash_shutdown(regs);
248}
249
250#endif /* CONFIG_KEXEC */
251
David Daney5b3b1682009-01-08 16:46:40 -0800252#ifdef CONFIG_CAVIUM_RESERVE32
253uint64_t octeon_reserve32_memory;
254EXPORT_SYMBOL(octeon_reserve32_memory);
255#endif
256
Ralf Baechleabe77f92012-10-25 16:23:31 +0200257#ifdef CONFIG_KEXEC
258/* crashkernel cmdline parameter is parsed _after_ memory setup
259 * we also parse it here (workaround for EHB5200) */
260static uint64_t crashk_size, crashk_base;
261#endif
262
David Daney5b3b1682009-01-08 16:46:40 -0800263static int octeon_uart;
264
265extern asmlinkage void handle_int(void);
David Daney5b3b1682009-01-08 16:46:40 -0800266
267/**
268 * Return non zero if we are currently running in the Octeon simulator
269 *
270 * Returns
271 */
272int octeon_is_simulation(void)
273{
274 return octeon_bootinfo->board_type == CVMX_BOARD_TYPE_SIM;
275}
276EXPORT_SYMBOL(octeon_is_simulation);
277
278/**
279 * Return true if Octeon is in PCI Host mode. This means
280 * Linux can control the PCI bus.
281 *
282 * Returns Non zero if Octeon in host mode.
283 */
284int octeon_is_pci_host(void)
285{
286#ifdef CONFIG_PCI
287 return octeon_bootinfo->config_flags & CVMX_BOOTINFO_CFG_FLAG_PCI_HOST;
288#else
289 return 0;
290#endif
291}
292
293/**
294 * Get the clock rate of Octeon
295 *
296 * Returns Clock rate in HZ
297 */
298uint64_t octeon_get_clock_rate(void)
299{
David Daneye195aa32010-10-07 16:03:49 -0700300 struct cvmx_sysinfo *sysinfo = cvmx_sysinfo_get();
301
302 return sysinfo->cpu_clock_hz;
David Daney5b3b1682009-01-08 16:46:40 -0800303}
304EXPORT_SYMBOL(octeon_get_clock_rate);
305
David Daneye195aa32010-10-07 16:03:49 -0700306static u64 octeon_io_clock_rate;
307
308u64 octeon_get_io_clock_rate(void)
309{
310 return octeon_io_clock_rate;
311}
312EXPORT_SYMBOL(octeon_get_io_clock_rate);
313
314
David Daney5b3b1682009-01-08 16:46:40 -0800315/**
316 * Write to the LCD display connected to the bootbus. This display
317 * exists on most Cavium evaluation boards. If it doesn't exist, then
318 * this function doesn't do anything.
319 *
Ralf Baechle70342282013-01-22 12:59:30 +0100320 * @s: String to write
David Daney5b3b1682009-01-08 16:46:40 -0800321 */
322void octeon_write_lcd(const char *s)
323{
324 if (octeon_bootinfo->led_display_base_addr) {
325 void __iomem *lcd_address =
326 ioremap_nocache(octeon_bootinfo->led_display_base_addr,
327 8);
328 int i;
329 for (i = 0; i < 8; i++, s++) {
330 if (*s)
331 iowrite8(*s, lcd_address + i);
332 else
333 iowrite8(' ', lcd_address + i);
334 }
335 iounmap(lcd_address);
336 }
337}
338
339/**
340 * Return the console uart passed by the bootloader
341 *
Ralf Baechle70342282013-01-22 12:59:30 +0100342 * Returns uart (0 or 1)
David Daney5b3b1682009-01-08 16:46:40 -0800343 */
344int octeon_get_boot_uart(void)
345{
346 int uart;
347#ifdef CONFIG_CAVIUM_OCTEON_2ND_KERNEL
348 uart = 1;
349#else
350 uart = (octeon_boot_desc_ptr->flags & OCTEON_BL_FLAG_CONSOLE_UART1) ?
351 1 : 0;
352#endif
353 return uart;
354}
355
356/**
357 * Get the coremask Linux was booted on.
358 *
359 * Returns Core mask
360 */
361int octeon_get_boot_coremask(void)
362{
363 return octeon_boot_desc_ptr->core_mask;
364}
365
366/**
367 * Check the hardware BIST results for a CPU
368 */
369void octeon_check_cpu_bist(void)
370{
371 const int coreid = cvmx_get_core_num();
372 unsigned long long mask;
373 unsigned long long bist_val;
374
375 /* Check BIST results for COP0 registers */
376 mask = 0x1f00000000ull;
377 bist_val = read_octeon_c0_icacheerr();
378 if (bist_val & mask)
379 pr_err("Core%d BIST Failure: CacheErr(icache) = 0x%llx\n",
380 coreid, bist_val);
381
382 bist_val = read_octeon_c0_dcacheerr();
383 if (bist_val & 1)
384 pr_err("Core%d L1 Dcache parity error: "
385 "CacheErr(dcache) = 0x%llx\n",
386 coreid, bist_val);
387
388 mask = 0xfc00000000000000ull;
389 bist_val = read_c0_cvmmemctl();
390 if (bist_val & mask)
391 pr_err("Core%d BIST Failure: COP0_CVM_MEM_CTL = 0x%llx\n",
392 coreid, bist_val);
393
394 write_octeon_c0_dcacheerr(0);
395}
396
David Daney5b3b1682009-01-08 16:46:40 -0800397/**
398 * Reboot Octeon
399 *
400 * @command: Command to pass to the bootloader. Currently ignored.
401 */
402static void octeon_restart(char *command)
403{
404 /* Disable all watchdogs before soft reset. They don't get cleared */
405#ifdef CONFIG_SMP
406 int cpu;
407 for_each_online_cpu(cpu)
408 cvmx_write_csr(CVMX_CIU_WDOGX(cpu_logical_map(cpu)), 0);
409#else
410 cvmx_write_csr(CVMX_CIU_WDOGX(cvmx_get_core_num()), 0);
411#endif
412
413 mb();
414 while (1)
415 cvmx_write_csr(CVMX_CIU_SOFT_RST, 1);
416}
417
418
419/**
420 * Permanently stop a core.
421 *
422 * @arg: Ignored.
423 */
424static void octeon_kill_core(void *arg)
425{
David Daney38c3c0f2013-05-24 16:23:02 +0000426 if (octeon_is_simulation())
David Daney5b3b1682009-01-08 16:46:40 -0800427 /* A break instruction causes the simulator stop a core */
David Daney38c3c0f2013-05-24 16:23:02 +0000428 asm volatile ("break" ::: "memory");
429
430 local_irq_disable();
431 /* Disable watchdog on this core. */
432 cvmx_write_csr(CVMX_CIU_WDOGX(cvmx_get_core_num()), 0);
433 /* Spin in a low power mode. */
434 while (true)
435 asm volatile ("wait" ::: "memory");
David Daney5b3b1682009-01-08 16:46:40 -0800436}
437
438
439/**
440 * Halt the system
441 */
442static void octeon_halt(void)
443{
444 smp_call_function(octeon_kill_core, NULL, 0);
445
446 switch (octeon_bootinfo->board_type) {
447 case CVMX_BOARD_TYPE_NAO38:
448 /* Driving a 1 to GPIO 12 shuts off this board */
449 cvmx_write_csr(CVMX_GPIO_BIT_CFGX(12), 1);
450 cvmx_write_csr(CVMX_GPIO_TX_SET, 0x1000);
451 break;
452 default:
453 octeon_write_lcd("PowerOff");
454 break;
455 }
456
457 octeon_kill_core(NULL);
458}
459
David Daney5b3b1682009-01-08 16:46:40 -0800460/**
David Daney5b3b1682009-01-08 16:46:40 -0800461 * Return a string representing the system type
462 *
463 * Returns
464 */
465const char *octeon_board_type_string(void)
466{
467 static char name[80];
468 sprintf(name, "%s (%s)",
469 cvmx_board_type_to_string(octeon_bootinfo->board_type),
470 octeon_model_get_string(read_c0_prid()));
471 return name;
472}
473
474const char *get_system_type(void)
475 __attribute__ ((alias("octeon_board_type_string")));
476
477void octeon_user_io_init(void)
478{
479 union octeon_cvmemctl cvmmemctl;
480 union cvmx_iob_fau_timeout fau_timeout;
481 union cvmx_pow_nw_tim nm_tim;
David Daney5b3b1682009-01-08 16:46:40 -0800482
483 /* Get the current settings for CP0_CVMMEMCTL_REG */
484 cvmmemctl.u64 = read_c0_cvmmemctl();
485 /* R/W If set, marked write-buffer entries time out the same
486 * as as other entries; if clear, marked write-buffer entries
487 * use the maximum timeout. */
488 cvmmemctl.s.dismarkwblongto = 1;
489 /* R/W If set, a merged store does not clear the write-buffer
490 * entry timeout state. */
491 cvmmemctl.s.dismrgclrwbto = 0;
492 /* R/W Two bits that are the MSBs of the resultant CVMSEG LM
493 * word location for an IOBDMA. The other 8 bits come from the
494 * SCRADDR field of the IOBDMA. */
495 cvmmemctl.s.iobdmascrmsb = 0;
496 /* R/W If set, SYNCWS and SYNCS only order marked stores; if
497 * clear, SYNCWS and SYNCS only order unmarked
498 * stores. SYNCWSMARKED has no effect when DISSYNCWS is
499 * set. */
500 cvmmemctl.s.syncwsmarked = 0;
501 /* R/W If set, SYNCWS acts as SYNCW and SYNCS acts as SYNC. */
502 cvmmemctl.s.dissyncws = 0;
503 /* R/W If set, no stall happens on write buffer full. */
504 if (OCTEON_IS_MODEL(OCTEON_CN38XX_PASS2))
505 cvmmemctl.s.diswbfst = 1;
506 else
507 cvmmemctl.s.diswbfst = 0;
508 /* R/W If set (and SX set), supervisor-level loads/stores can
509 * use XKPHYS addresses with <48>==0 */
510 cvmmemctl.s.xkmemenas = 0;
511
512 /* R/W If set (and UX set), user-level loads/stores can use
513 * XKPHYS addresses with VA<48>==0 */
514 cvmmemctl.s.xkmemenau = 0;
515
516 /* R/W If set (and SX set), supervisor-level loads/stores can
517 * use XKPHYS addresses with VA<48>==1 */
518 cvmmemctl.s.xkioenas = 0;
519
520 /* R/W If set (and UX set), user-level loads/stores can use
521 * XKPHYS addresses with VA<48>==1 */
522 cvmmemctl.s.xkioenau = 0;
523
524 /* R/W If set, all stores act as SYNCW (NOMERGE must be set
525 * when this is set) RW, reset to 0. */
526 cvmmemctl.s.allsyncw = 0;
527
528 /* R/W If set, no stores merge, and all stores reach the
529 * coherent bus in order. */
530 cvmmemctl.s.nomerge = 0;
531 /* R/W Selects the bit in the counter used for DID time-outs 0
532 * = 231, 1 = 230, 2 = 229, 3 = 214. Actual time-out is
533 * between 1x and 2x this interval. For example, with
534 * DIDTTO=3, expiration interval is between 16K and 32K. */
535 cvmmemctl.s.didtto = 0;
536 /* R/W If set, the (mem) CSR clock never turns off. */
537 cvmmemctl.s.csrckalwys = 0;
538 /* R/W If set, mclk never turns off. */
539 cvmmemctl.s.mclkalwys = 0;
540 /* R/W Selects the bit in the counter used for write buffer
541 * flush time-outs (WBFLT+11) is the bit position in an
542 * internal counter used to determine expiration. The write
543 * buffer expires between 1x and 2x this interval. For
544 * example, with WBFLT = 0, a write buffer expires between 2K
545 * and 4K cycles after the write buffer entry is allocated. */
546 cvmmemctl.s.wbfltime = 0;
547 /* R/W If set, do not put Istream in the L2 cache. */
548 cvmmemctl.s.istrnol2 = 0;
David Daneyc9941152010-10-07 16:03:53 -0700549
550 /*
551 * R/W The write buffer threshold. As per erratum Core-14752
552 * for CN63XX, a sc/scd might fail if the write buffer is
553 * full. Lowering WBTHRESH greatly lowers the chances of the
554 * write buffer ever being full and triggering the erratum.
555 */
556 if (OCTEON_IS_MODEL(OCTEON_CN63XX_PASS1_X))
557 cvmmemctl.s.wbthresh = 4;
558 else
559 cvmmemctl.s.wbthresh = 10;
560
David Daney5b3b1682009-01-08 16:46:40 -0800561 /* R/W If set, CVMSEG is available for loads/stores in
562 * kernel/debug mode. */
563#if CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE > 0
564 cvmmemctl.s.cvmsegenak = 1;
565#else
566 cvmmemctl.s.cvmsegenak = 0;
567#endif
568 /* R/W If set, CVMSEG is available for loads/stores in
569 * supervisor mode. */
570 cvmmemctl.s.cvmsegenas = 0;
571 /* R/W If set, CVMSEG is available for loads/stores in user
572 * mode. */
573 cvmmemctl.s.cvmsegenau = 0;
574 /* R/W Size of local memory in cache blocks, 54 (6912 bytes)
575 * is max legal value. */
576 cvmmemctl.s.lmemsz = CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE;
577
David Daneyc9941152010-10-07 16:03:53 -0700578 write_c0_cvmmemctl(cvmmemctl.u64);
David Daney5b3b1682009-01-08 16:46:40 -0800579
580 if (smp_processor_id() == 0)
581 pr_notice("CVMSEG size: %d cache lines (%d bytes)\n",
582 CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE,
583 CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE * 128);
584
David Daney5b3b1682009-01-08 16:46:40 -0800585 /* Set a default for the hardware timeouts */
586 fau_timeout.u64 = 0;
587 fau_timeout.s.tout_val = 0xfff;
588 /* Disable tagwait FAU timeout */
589 fau_timeout.s.tout_enb = 0;
590 cvmx_write_csr(CVMX_IOB_FAU_TIMEOUT, fau_timeout.u64);
591
592 nm_tim.u64 = 0;
593 /* 4096 cycles */
594 nm_tim.s.nw_tim = 3;
595 cvmx_write_csr(CVMX_POW_NW_TIM, nm_tim.u64);
596
597 write_octeon_c0_icacheerr(0);
598 write_c0_derraddr1(0);
599}
600
601/**
602 * Early entry point for arch setup
603 */
604void __init prom_init(void)
605{
606 struct cvmx_sysinfo *sysinfo;
Ralf Baechleabe77f92012-10-25 16:23:31 +0200607 const char *arg;
608 char *p;
David Daney5b3b1682009-01-08 16:46:40 -0800609 int i;
610 int argc;
David Daney5b3b1682009-01-08 16:46:40 -0800611#ifdef CONFIG_CAVIUM_RESERVE32
612 int64_t addr = -1;
613#endif
614 /*
615 * The bootloader passes a pointer to the boot descriptor in
616 * $a3, this is available as fw_arg3.
617 */
618 octeon_boot_desc_ptr = (struct octeon_boot_descriptor *)fw_arg3;
619 octeon_bootinfo =
620 cvmx_phys_to_ptr(octeon_boot_desc_ptr->cvmx_desc_vaddr);
621 cvmx_bootmem_init(cvmx_phys_to_ptr(octeon_bootinfo->phy_mem_desc_addr));
622
David Daneye195aa32010-10-07 16:03:49 -0700623 sysinfo = cvmx_sysinfo_get();
624 memset(sysinfo, 0, sizeof(*sysinfo));
625 sysinfo->system_dram_size = octeon_bootinfo->dram_size << 20;
626 sysinfo->phy_mem_desc_ptr =
627 cvmx_phys_to_ptr(octeon_bootinfo->phy_mem_desc_addr);
628 sysinfo->core_mask = octeon_bootinfo->core_mask;
629 sysinfo->exception_base_addr = octeon_bootinfo->exception_base_addr;
630 sysinfo->cpu_clock_hz = octeon_bootinfo->eclock_hz;
631 sysinfo->dram_data_rate_hz = octeon_bootinfo->dclock_hz * 2;
632 sysinfo->board_type = octeon_bootinfo->board_type;
633 sysinfo->board_rev_major = octeon_bootinfo->board_rev_major;
634 sysinfo->board_rev_minor = octeon_bootinfo->board_rev_minor;
635 memcpy(sysinfo->mac_addr_base, octeon_bootinfo->mac_addr_base,
636 sizeof(sysinfo->mac_addr_base));
637 sysinfo->mac_addr_count = octeon_bootinfo->mac_addr_count;
638 memcpy(sysinfo->board_serial_number,
639 octeon_bootinfo->board_serial_number,
640 sizeof(sysinfo->board_serial_number));
641 sysinfo->compact_flash_common_base_addr =
642 octeon_bootinfo->compact_flash_common_base_addr;
643 sysinfo->compact_flash_attribute_base_addr =
644 octeon_bootinfo->compact_flash_attribute_base_addr;
645 sysinfo->led_display_base_addr = octeon_bootinfo->led_display_base_addr;
646 sysinfo->dfa_ref_clock_hz = octeon_bootinfo->dfa_ref_clock_hz;
647 sysinfo->bootloader_config_flags = octeon_bootinfo->config_flags;
648
649 if (OCTEON_IS_MODEL(OCTEON_CN6XXX)) {
650 /* I/O clock runs at a different rate than the CPU. */
651 union cvmx_mio_rst_boot rst_boot;
652 rst_boot.u64 = cvmx_read_csr(CVMX_MIO_RST_BOOT);
653 octeon_io_clock_rate = 50000000 * rst_boot.s.pnr_mul;
654 } else {
655 octeon_io_clock_rate = sysinfo->cpu_clock_hz;
656 }
657
David Daney5b3b1682009-01-08 16:46:40 -0800658 /*
659 * Only enable the LED controller if we're running on a CN38XX, CN58XX,
660 * or CN56XX. The CN30XX and CN31XX don't have an LED controller.
661 */
662 if (!octeon_is_simulation() &&
663 octeon_has_feature(OCTEON_FEATURE_LED_CONTROLLER)) {
664 cvmx_write_csr(CVMX_LED_EN, 0);
665 cvmx_write_csr(CVMX_LED_PRT, 0);
666 cvmx_write_csr(CVMX_LED_DBG, 0);
667 cvmx_write_csr(CVMX_LED_PRT_FMT, 0);
668 cvmx_write_csr(CVMX_LED_UDD_CNTX(0), 32);
669 cvmx_write_csr(CVMX_LED_UDD_CNTX(1), 32);
670 cvmx_write_csr(CVMX_LED_UDD_DATX(0), 0);
671 cvmx_write_csr(CVMX_LED_UDD_DATX(1), 0);
672 cvmx_write_csr(CVMX_LED_EN, 1);
673 }
674#ifdef CONFIG_CAVIUM_RESERVE32
675 /*
676 * We need to temporarily allocate all memory in the reserve32
677 * region. This makes sure the kernel doesn't allocate this
678 * memory when it is getting memory from the
679 * bootloader. Later, after the memory allocations are
680 * complete, the reserve32 will be freed.
David Daney1ef28872010-03-03 11:07:07 -0800681 *
David Daney5b3b1682009-01-08 16:46:40 -0800682 * Allocate memory for RESERVED32 aligned on 2MB boundary. This
683 * is in case we later use hugetlb entries with it.
684 */
685 addr = cvmx_bootmem_phy_named_block_alloc(CONFIG_CAVIUM_RESERVE32 << 20,
686 0, 0, 2 << 20,
687 "CAVIUM_RESERVE32", 0);
David Daney5b3b1682009-01-08 16:46:40 -0800688 if (addr < 0)
689 pr_err("Failed to allocate CAVIUM_RESERVE32 memory area\n");
690 else
691 octeon_reserve32_memory = addr;
692#endif
693
694#ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2
695 if (cvmx_read_csr(CVMX_L2D_FUS3) & (3ull << 34)) {
696 pr_info("Skipping L2 locking due to reduced L2 cache size\n");
697 } else {
Ralf Baechle39205752013-06-13 01:29:24 +0200698 uint32_t __maybe_unused ebase = read_c0_ebase() & 0x3ffff000;
David Daney5b3b1682009-01-08 16:46:40 -0800699#ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_TLB
700 /* TLB refill */
701 cvmx_l2c_lock_mem_region(ebase, 0x100);
702#endif
703#ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_EXCEPTION
704 /* General exception */
705 cvmx_l2c_lock_mem_region(ebase + 0x180, 0x80);
706#endif
707#ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_LOW_LEVEL_INTERRUPT
708 /* Interrupt handler */
709 cvmx_l2c_lock_mem_region(ebase + 0x200, 0x80);
710#endif
711#ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_INTERRUPT
712 cvmx_l2c_lock_mem_region(__pa_symbol(handle_int), 0x100);
713 cvmx_l2c_lock_mem_region(__pa_symbol(plat_irq_dispatch), 0x80);
714#endif
715#ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_MEMCPY
716 cvmx_l2c_lock_mem_region(__pa_symbol(memcpy), 0x480);
717#endif
718 }
719#endif
720
David Daney5b3b1682009-01-08 16:46:40 -0800721 octeon_check_cpu_bist();
722
723 octeon_uart = octeon_get_boot_uart();
724
David Daney5b3b1682009-01-08 16:46:40 -0800725#ifdef CONFIG_SMP
726 octeon_write_lcd("LinuxSMP");
727#else
728 octeon_write_lcd("Linux");
729#endif
730
David Daney70a26a22012-08-21 11:45:05 -0700731 octeon_setup_delays();
732
David Daney5b3b1682009-01-08 16:46:40 -0800733 /*
734 * BIST should always be enabled when doing a soft reset. L2
735 * Cache locking for instance is not cleared unless BIST is
736 * enabled. Unfortunately due to a chip errata G-200 for
737 * Cn38XX and CN31XX, BIST msut be disabled on these parts.
738 */
739 if (OCTEON_IS_MODEL(OCTEON_CN38XX_PASS2) ||
740 OCTEON_IS_MODEL(OCTEON_CN31XX))
741 cvmx_write_csr(CVMX_CIU_SOFT_BIST, 0);
742 else
743 cvmx_write_csr(CVMX_CIU_SOFT_BIST, 1);
744
745 /* Default to 64MB in the simulator to speed things up */
746 if (octeon_is_simulation())
747 MAX_MEMORY = 64ull << 20;
748
Ralf Baechleabe77f92012-10-25 16:23:31 +0200749 arg = strstr(arcs_cmdline, "mem=");
750 if (arg) {
751 MAX_MEMORY = memparse(arg + 4, &p);
752 if (MAX_MEMORY == 0)
753 MAX_MEMORY = 32ull << 30;
754 if (*p == '@')
755 RESERVE_LOW_MEM = memparse(p + 1, &p);
756 }
757
David Daney5b3b1682009-01-08 16:46:40 -0800758 arcs_cmdline[0] = 0;
759 argc = octeon_boot_desc_ptr->argc;
760 for (i = 0; i < argc; i++) {
761 const char *arg =
762 cvmx_phys_to_ptr(octeon_boot_desc_ptr->argv[i]);
763 if ((strncmp(arg, "MEM=", 4) == 0) ||
764 (strncmp(arg, "mem=", 4) == 0)) {
Ralf Baechleabe77f92012-10-25 16:23:31 +0200765 MAX_MEMORY = memparse(arg + 4, &p);
David Daney5b3b1682009-01-08 16:46:40 -0800766 if (MAX_MEMORY == 0)
767 MAX_MEMORY = 32ull << 30;
Ralf Baechleabe77f92012-10-25 16:23:31 +0200768 if (*p == '@')
769 RESERVE_LOW_MEM = memparse(p + 1, &p);
Ralf Baechleabe77f92012-10-25 16:23:31 +0200770#ifdef CONFIG_KEXEC
771 } else if (strncmp(arg, "crashkernel=", 12) == 0) {
772 crashk_size = memparse(arg+12, &p);
773 if (*p == '@')
774 crashk_base = memparse(p+1, &p);
775 strcat(arcs_cmdline, " ");
776 strcat(arcs_cmdline, arg);
777 /*
778 * To do: switch parsing to new style, something like:
779 * parse_crashkernel(arg, sysinfo->system_dram_size,
Ralf Baechle70342282013-01-22 12:59:30 +0100780 * &crashk_size, &crashk_base);
Ralf Baechleabe77f92012-10-25 16:23:31 +0200781 */
782#endif
David Daney5b3b1682009-01-08 16:46:40 -0800783 } else if (strlen(arcs_cmdline) + strlen(arg) + 1 <
784 sizeof(arcs_cmdline) - 1) {
785 strcat(arcs_cmdline, " ");
786 strcat(arcs_cmdline, arg);
787 }
788 }
789
790 if (strstr(arcs_cmdline, "console=") == NULL) {
David Daney5b3b1682009-01-08 16:46:40 -0800791#ifdef CONFIG_CAVIUM_OCTEON_2ND_KERNEL
792 strcat(arcs_cmdline, " console=ttyS0,115200");
793#else
794 if (octeon_uart == 1)
795 strcat(arcs_cmdline, " console=ttyS1,115200");
796 else
797 strcat(arcs_cmdline, " console=ttyS0,115200");
798#endif
David Daney5b3b1682009-01-08 16:46:40 -0800799 }
800
801 if (octeon_is_simulation()) {
802 /*
803 * The simulator uses a mtdram device pre filled with
804 * the filesystem. Also specify the calibration delay
805 * to avoid calculating it every time.
806 */
David Daneyca148122010-06-01 13:18:15 -0700807 strcat(arcs_cmdline, " rw root=1f00 slram=root,0x40000000,+1073741824");
David Daney5b3b1682009-01-08 16:46:40 -0800808 }
809
810 mips_hpt_frequency = octeon_get_clock_rate();
811
812 octeon_init_cvmcount();
813
814 _machine_restart = octeon_restart;
815 _machine_halt = octeon_halt;
816
Ralf Baechleabe77f92012-10-25 16:23:31 +0200817#ifdef CONFIG_KEXEC
818 _machine_kexec_shutdown = octeon_shutdown;
819 _machine_crash_shutdown = octeon_crash_shutdown;
820 _machine_kexec_prepare = octeon_kexec_prepare;
821#endif
822
David Daney5b3b1682009-01-08 16:46:40 -0800823 octeon_user_io_init();
824 register_smp_ops(&octeon_smp_ops);
825}
826
David Daney2b5987a2010-08-04 14:53:57 -0700827/* Exclude a single page from the regions obtained in plat_mem_setup. */
Ralf Baechleabe77f92012-10-25 16:23:31 +0200828#ifndef CONFIG_CRASH_DUMP
David Daney2b5987a2010-08-04 14:53:57 -0700829static __init void memory_exclude_page(u64 addr, u64 *mem, u64 *size)
830{
831 if (addr > *mem && addr < *mem + *size) {
832 u64 inc = addr - *mem;
833 add_memory_region(*mem, inc, BOOT_MEM_RAM);
834 *mem += inc;
835 *size -= inc;
836 }
837
838 if (addr == *mem && *size > PAGE_SIZE) {
839 *mem += PAGE_SIZE;
840 *size -= PAGE_SIZE;
841 }
842}
Ralf Baechleabe77f92012-10-25 16:23:31 +0200843#endif /* CONFIG_CRASH_DUMP */
David Daney2b5987a2010-08-04 14:53:57 -0700844
David Daney5b3b1682009-01-08 16:46:40 -0800845void __init plat_mem_setup(void)
846{
847 uint64_t mem_alloc_size;
848 uint64_t total;
Ralf Baechleabe77f92012-10-25 16:23:31 +0200849 uint64_t crashk_end;
850#ifndef CONFIG_CRASH_DUMP
David Daney5b3b1682009-01-08 16:46:40 -0800851 int64_t memory;
Ralf Baechleabe77f92012-10-25 16:23:31 +0200852 uint64_t kernel_start;
853 uint64_t kernel_size;
854#endif
David Daney5b3b1682009-01-08 16:46:40 -0800855
856 total = 0;
Ralf Baechleabe77f92012-10-25 16:23:31 +0200857 crashk_end = 0;
David Daney5b3b1682009-01-08 16:46:40 -0800858
David Daney5b3b1682009-01-08 16:46:40 -0800859 /*
860 * The Mips memory init uses the first memory location for
861 * some memory vectors. When SPARSEMEM is in use, it doesn't
862 * verify that the size is big enough for the final
863 * vectors. Making the smallest chuck 4MB seems to be enough
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300864 * to consistently work.
David Daney5b3b1682009-01-08 16:46:40 -0800865 */
866 mem_alloc_size = 4 << 20;
867 if (mem_alloc_size > MAX_MEMORY)
868 mem_alloc_size = MAX_MEMORY;
869
Ralf Baechleabe77f92012-10-25 16:23:31 +0200870/* Crashkernel ignores bootmem list. It relies on mem=X@Y option */
871#ifdef CONFIG_CRASH_DUMP
872 add_memory_region(RESERVE_LOW_MEM, MAX_MEMORY, BOOT_MEM_RAM);
873 total += MAX_MEMORY;
874#else
875#ifdef CONFIG_KEXEC
876 if (crashk_size > 0) {
877 add_memory_region(crashk_base, crashk_size, BOOT_MEM_RAM);
878 crashk_end = crashk_base + crashk_size;
879 }
880#endif
David Daney5b3b1682009-01-08 16:46:40 -0800881 /*
882 * When allocating memory, we want incrementing addresses from
883 * bootmem_alloc so the code in add_memory_region can merge
884 * regions next to each other.
885 */
886 cvmx_bootmem_lock();
887 while ((boot_mem_map.nr_map < BOOT_MEM_MAP_MAX)
888 && (total < MAX_MEMORY)) {
David Daney5b3b1682009-01-08 16:46:40 -0800889 memory = cvmx_bootmem_phy_alloc(mem_alloc_size,
890 __pa_symbol(&__init_end), -1,
891 0x100000,
892 CVMX_BOOTMEM_FLAG_NO_LOCKING);
David Daney5b3b1682009-01-08 16:46:40 -0800893 if (memory >= 0) {
David Daney2b5987a2010-08-04 14:53:57 -0700894 u64 size = mem_alloc_size;
Ralf Baechleabe77f92012-10-25 16:23:31 +0200895#ifdef CONFIG_KEXEC
896 uint64_t end;
897#endif
David Daney2b5987a2010-08-04 14:53:57 -0700898
899 /*
900 * exclude a page at the beginning and end of
901 * the 256MB PCIe 'hole' so the kernel will not
902 * try to allocate multi-page buffers that
903 * span the discontinuity.
904 */
905 memory_exclude_page(CVMX_PCIE_BAR1_PHYS_BASE,
906 &memory, &size);
907 memory_exclude_page(CVMX_PCIE_BAR1_PHYS_BASE +
908 CVMX_PCIE_BAR1_PHYS_SIZE,
909 &memory, &size);
Ralf Baechleabe77f92012-10-25 16:23:31 +0200910#ifdef CONFIG_KEXEC
911 end = memory + mem_alloc_size;
David Daney2b5987a2010-08-04 14:53:57 -0700912
David Daney5b3b1682009-01-08 16:46:40 -0800913 /*
Ralf Baechleabe77f92012-10-25 16:23:31 +0200914 * This function automatically merges address regions
915 * next to each other if they are received in
916 * incrementing order
David Daney5b3b1682009-01-08 16:46:40 -0800917 */
Ralf Baechleabe77f92012-10-25 16:23:31 +0200918 if (memory < crashk_base && end > crashk_end) {
919 /* region is fully in */
920 add_memory_region(memory,
921 crashk_base - memory,
922 BOOT_MEM_RAM);
923 total += crashk_base - memory;
924 add_memory_region(crashk_end,
925 end - crashk_end,
926 BOOT_MEM_RAM);
927 total += end - crashk_end;
928 continue;
929 }
930
931 if (memory >= crashk_base && end <= crashk_end)
932 /*
933 * Entire memory region is within the new
934 * kernel's memory, ignore it.
935 */
936 continue;
937
938 if (memory > crashk_base && memory < crashk_end &&
939 end > crashk_end) {
940 /*
941 * Overlap with the beginning of the region,
942 * reserve the beginning.
943 */
944 mem_alloc_size -= crashk_end - memory;
945 memory = crashk_end;
946 } else if (memory < crashk_base && end > crashk_base &&
947 end < crashk_end)
948 /*
949 * Overlap with the beginning of the region,
950 * chop of end.
951 */
952 mem_alloc_size -= end - crashk_base;
953#endif
954 add_memory_region(memory, mem_alloc_size, BOOT_MEM_RAM);
David Daney5b3b1682009-01-08 16:46:40 -0800955 total += mem_alloc_size;
Ralf Baechleabe77f92012-10-25 16:23:31 +0200956 /* Recovering mem_alloc_size */
957 mem_alloc_size = 4 << 20;
David Daney5b3b1682009-01-08 16:46:40 -0800958 } else {
959 break;
960 }
961 }
962 cvmx_bootmem_unlock();
Ralf Baechleabe77f92012-10-25 16:23:31 +0200963 /* Add the memory region for the kernel. */
964 kernel_start = (unsigned long) _text;
David Daneyd949b4f2013-06-12 17:28:33 +0000965 kernel_size = _end - _text;
Ralf Baechleabe77f92012-10-25 16:23:31 +0200966
967 /* Adjust for physical offset. */
968 kernel_start &= ~0xffffffff80000000ULL;
969 add_memory_region(kernel_start, kernel_size, BOOT_MEM_RAM);
970#endif /* CONFIG_CRASH_DUMP */
David Daney5b3b1682009-01-08 16:46:40 -0800971
972#ifdef CONFIG_CAVIUM_RESERVE32
973 /*
974 * Now that we've allocated the kernel memory it is safe to
975 * free the reserved region. We free it here so that builtin
976 * drivers can use the memory.
977 */
978 if (octeon_reserve32_memory)
979 cvmx_bootmem_free_named("CAVIUM_RESERVE32");
980#endif /* CONFIG_CAVIUM_RESERVE32 */
981
982 if (total == 0)
983 panic("Unable to allocate memory from "
Ralf Baechlef7777dc2013-09-18 16:05:26 +0200984 "cvmx_bootmem_phy_alloc");
David Daney5b3b1682009-01-08 16:46:40 -0800985}
986
David Daneyea4354642010-07-23 18:41:44 -0700987/*
Ralf Baechle70342282013-01-22 12:59:30 +0100988 * Emit one character to the boot UART. Exported for use by the
David Daneyea4354642010-07-23 18:41:44 -0700989 * watchdog timer.
990 */
David Daney5b3b1682009-01-08 16:46:40 -0800991int prom_putchar(char c)
992{
993 uint64_t lsrval;
994
995 /* Spin until there is room */
996 do {
997 lsrval = cvmx_read_csr(CVMX_MIO_UARTX_LSR(octeon_uart));
998 } while ((lsrval & 0x20) == 0);
999
1000 /* Write the byte */
David Daney606c9582010-05-19 14:16:32 -07001001 cvmx_write_csr(CVMX_MIO_UARTX_THR(octeon_uart), c & 0xffull);
David Daney5b3b1682009-01-08 16:46:40 -08001002 return 1;
1003}
David Daneyea4354642010-07-23 18:41:44 -07001004EXPORT_SYMBOL(prom_putchar);
David Daney5b3b1682009-01-08 16:46:40 -08001005
1006void prom_free_prom_memory(void)
1007{
David Daneyc9941152010-10-07 16:03:53 -07001008 if (OCTEON_IS_MODEL(OCTEON_CN63XX_PASS1_X)) {
1009 /* Check for presence of Core-14449 fix. */
1010 u32 insn;
1011 u32 *foo;
1012
1013 foo = &insn;
1014
1015 asm volatile("# before" : : : "memory");
1016 prefetch(foo);
1017 asm volatile(
1018 ".set push\n\t"
1019 ".set noreorder\n\t"
1020 "bal 1f\n\t"
1021 "nop\n"
1022 "1:\tlw %0,-12($31)\n\t"
1023 ".set pop\n\t"
1024 : "=r" (insn) : : "$31", "memory");
1025
1026 if ((insn >> 26) != 0x33)
Ralf Baechleab75dc02011-11-17 15:07:31 +00001027 panic("No PREF instruction at Core-14449 probe point.");
David Daneyc9941152010-10-07 16:03:53 -07001028
1029 if (((insn >> 16) & 0x1f) != 28)
1030 panic("Core-14449 WAR not in place (%04x).\n"
Ralf Baechleab75dc02011-11-17 15:07:31 +00001031 "Please build kernel with proper options (CONFIG_CAVIUM_CN63XXP1).", insn);
David Daneyc9941152010-10-07 16:03:53 -07001032 }
David Daney5b3b1682009-01-08 16:46:40 -08001033}
David Daney7ed18152012-07-05 18:12:38 +02001034
1035int octeon_prune_device_tree(void);
1036
1037extern const char __dtb_octeon_3xxx_begin;
David Daney7ed18152012-07-05 18:12:38 +02001038extern const char __dtb_octeon_68xx_begin;
David Daney7ed18152012-07-05 18:12:38 +02001039void __init device_tree_init(void)
1040{
Rob Herring8c97cec2014-04-02 17:45:06 -05001041 const void *fdt;
David Daney7ed18152012-07-05 18:12:38 +02001042 bool do_prune;
1043
1044 if (octeon_bootinfo->minor_version >= 3 && octeon_bootinfo->fdt_addr) {
1045 fdt = phys_to_virt(octeon_bootinfo->fdt_addr);
1046 if (fdt_check_header(fdt))
1047 panic("Corrupt Device Tree passed to kernel.");
David Daney7ed18152012-07-05 18:12:38 +02001048 do_prune = false;
1049 } else if (OCTEON_IS_MODEL(OCTEON_CN68XX)) {
Rob Herring8c97cec2014-04-02 17:45:06 -05001050 fdt = &__dtb_octeon_68xx_begin;
David Daney7ed18152012-07-05 18:12:38 +02001051 do_prune = true;
1052 } else {
Rob Herring8c97cec2014-04-02 17:45:06 -05001053 fdt = &__dtb_octeon_3xxx_begin;
David Daney7ed18152012-07-05 18:12:38 +02001054 do_prune = true;
1055 }
1056
Rob Herring8c97cec2014-04-02 17:45:06 -05001057 initial_boot_params = (void *)fdt;
David Daney7ed18152012-07-05 18:12:38 +02001058
1059 if (do_prune) {
1060 octeon_prune_device_tree();
1061 pr_info("Using internal Device Tree.\n");
1062 } else {
1063 pr_info("Using passed Device Tree.\n");
1064 }
Rob Herring8c97cec2014-04-02 17:45:06 -05001065 unflatten_and_copy_device_tree();
David Daney7ed18152012-07-05 18:12:38 +02001066}
Ralf Baechlef65aad42012-10-17 00:39:09 +02001067
David Daneye1ced092012-11-15 13:58:59 -08001068static int __initdata disable_octeon_edac_p;
1069
1070static int __init disable_octeon_edac(char *str)
1071{
1072 disable_octeon_edac_p = 1;
1073 return 0;
1074}
1075early_param("disable_octeon_edac", disable_octeon_edac);
1076
Ralf Baechlef65aad42012-10-17 00:39:09 +02001077static char *edac_device_names[] = {
David Daneye1ced092012-11-15 13:58:59 -08001078 "octeon_l2c_edac",
1079 "octeon_pc_edac",
Ralf Baechlef65aad42012-10-17 00:39:09 +02001080};
1081
1082static int __init edac_devinit(void)
1083{
1084 struct platform_device *dev;
1085 int i, err = 0;
David Daneye1ced092012-11-15 13:58:59 -08001086 int num_lmc;
Ralf Baechlef65aad42012-10-17 00:39:09 +02001087 char *name;
1088
David Daneye1ced092012-11-15 13:58:59 -08001089 if (disable_octeon_edac_p)
1090 return 0;
1091
Ralf Baechlef65aad42012-10-17 00:39:09 +02001092 for (i = 0; i < ARRAY_SIZE(edac_device_names); i++) {
1093 name = edac_device_names[i];
1094 dev = platform_device_register_simple(name, -1, NULL, 0);
1095 if (IS_ERR(dev)) {
1096 pr_err("Registation of %s failed!\n", name);
1097 err = PTR_ERR(dev);
1098 }
1099 }
1100
David Daneye1ced092012-11-15 13:58:59 -08001101 num_lmc = OCTEON_IS_MODEL(OCTEON_CN68XX) ? 4 :
1102 (OCTEON_IS_MODEL(OCTEON_CN56XX) ? 2 : 1);
1103 for (i = 0; i < num_lmc; i++) {
1104 dev = platform_device_register_simple("octeon_lmc_edac",
1105 i, NULL, 0);
1106 if (IS_ERR(dev)) {
1107 pr_err("Registation of octeon_lmc_edac %d failed!\n", i);
1108 err = PTR_ERR(dev);
1109 }
1110 }
1111
Ralf Baechlef65aad42012-10-17 00:39:09 +02001112 return err;
1113}
Ralf Baechlef65aad42012-10-17 00:39:09 +02001114device_initcall(edac_devinit);
Aaro Koskinend8b74272013-07-25 20:26:48 +03001115
1116static void __initdata *octeon_dummy_iospace;
1117
1118static int __init octeon_no_pci_init(void)
1119{
1120 /*
1121 * Initially assume there is no PCI. The PCI/PCIe platform code will
1122 * later re-initialize these to correct values if they are present.
1123 */
1124 octeon_dummy_iospace = vzalloc(IO_SPACE_LIMIT);
1125 set_io_port_base((unsigned long)octeon_dummy_iospace);
1126 ioport_resource.start = MAX_RESOURCE;
1127 ioport_resource.end = 0;
1128 return 0;
1129}
1130core_initcall(octeon_no_pci_init);
1131
1132static int __init octeon_no_pci_release(void)
1133{
1134 /*
1135 * Release the allocated memory if a real IO space is there.
1136 */
1137 if ((unsigned long)octeon_dummy_iospace != mips_io_port_base)
1138 vfree(octeon_dummy_iospace);
1139 return 0;
1140}
1141late_initcall(octeon_no_pci_release);