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