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