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