Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * This file is subject to the terms and conditions of the GNU General Public
0003  * License.  See the file "COPYING" in the main directory of this archive
0004  * for more details.
0005  *
0006  * Copyright (C) 2004-2007 Cavium Networks
0007  * Copyright (C) 2008, 2009 Wind River Systems
0008  *   written by Ralf Baechle <ralf@linux-mips.org>
0009  */
0010 #include <linux/compiler.h>
0011 #include <linux/vmalloc.h>
0012 #include <linux/init.h>
0013 #include <linux/kernel.h>
0014 #include <linux/console.h>
0015 #include <linux/delay.h>
0016 #include <linux/export.h>
0017 #include <linux/interrupt.h>
0018 #include <linux/io.h>
0019 #include <linux/memblock.h>
0020 #include <linux/serial.h>
0021 #include <linux/smp.h>
0022 #include <linux/types.h>
0023 #include <linux/string.h>   /* for memset */
0024 #include <linux/tty.h>
0025 #include <linux/time.h>
0026 #include <linux/platform_device.h>
0027 #include <linux/serial_core.h>
0028 #include <linux/serial_8250.h>
0029 #include <linux/of_fdt.h>
0030 #include <linux/libfdt.h>
0031 #include <linux/kexec.h>
0032 
0033 #include <asm/processor.h>
0034 #include <asm/reboot.h>
0035 #include <asm/smp-ops.h>
0036 #include <asm/irq_cpu.h>
0037 #include <asm/mipsregs.h>
0038 #include <asm/bootinfo.h>
0039 #include <asm/sections.h>
0040 #include <asm/fw/fw.h>
0041 #include <asm/setup.h>
0042 #include <asm/prom.h>
0043 #include <asm/time.h>
0044 
0045 #include <asm/octeon/octeon.h>
0046 #include <asm/octeon/pci-octeon.h>
0047 #include <asm/octeon/cvmx-rst-defs.h>
0048 
0049 /*
0050  * TRUE for devices having registers with little-endian byte
0051  * order, FALSE for registers with native-endian byte order.
0052  * PCI mandates little-endian, USB and SATA are configuraable,
0053  * but we chose little-endian for these.
0054  */
0055 const bool octeon_should_swizzle_table[256] = {
0056     [0x00] = true,  /* bootbus/CF */
0057     [0x1b] = true,  /* PCI mmio window */
0058     [0x1c] = true,  /* PCI mmio window */
0059     [0x1d] = true,  /* PCI mmio window */
0060     [0x1e] = true,  /* PCI mmio window */
0061     [0x68] = true,  /* OCTEON III USB */
0062     [0x69] = true,  /* OCTEON III USB */
0063     [0x6c] = true,  /* OCTEON III SATA */
0064     [0x6f] = true,  /* OCTEON II USB */
0065 };
0066 EXPORT_SYMBOL(octeon_should_swizzle_table);
0067 
0068 #ifdef CONFIG_PCI
0069 extern void pci_console_init(const char *arg);
0070 #endif
0071 
0072 static unsigned long long max_memory = ULLONG_MAX;
0073 static unsigned long long reserve_low_mem;
0074 
0075 DEFINE_SEMAPHORE(octeon_bootbus_sem);
0076 EXPORT_SYMBOL(octeon_bootbus_sem);
0077 
0078 static struct octeon_boot_descriptor *octeon_boot_desc_ptr;
0079 
0080 struct cvmx_bootinfo *octeon_bootinfo;
0081 EXPORT_SYMBOL(octeon_bootinfo);
0082 
0083 #ifdef CONFIG_KEXEC
0084 #ifdef CONFIG_SMP
0085 /*
0086  * Wait for relocation code is prepared and send
0087  * secondary CPUs to spin until kernel is relocated.
0088  */
0089 static void octeon_kexec_smp_down(void *ignored)
0090 {
0091     int cpu = smp_processor_id();
0092 
0093     local_irq_disable();
0094     set_cpu_online(cpu, false);
0095     while (!atomic_read(&kexec_ready_to_reboot))
0096         cpu_relax();
0097 
0098     asm volatile (
0099     "   sync                        \n"
0100     "   synci   ($0)                    \n");
0101 
0102     kexec_reboot();
0103 }
0104 #endif
0105 
0106 #define OCTEON_DDR0_BASE    (0x0ULL)
0107 #define OCTEON_DDR0_SIZE    (0x010000000ULL)
0108 #define OCTEON_DDR1_BASE    (0x410000000ULL)
0109 #define OCTEON_DDR1_SIZE    (0x010000000ULL)
0110 #define OCTEON_DDR2_BASE    (0x020000000ULL)
0111 #define OCTEON_DDR2_SIZE    (0x3e0000000ULL)
0112 #define OCTEON_MAX_PHY_MEM_SIZE (16*1024*1024*1024ULL)
0113 
0114 static struct kimage *kimage_ptr;
0115 
0116 static void kexec_bootmem_init(uint64_t mem_size, uint32_t low_reserved_bytes)
0117 {
0118     int64_t addr;
0119     struct cvmx_bootmem_desc *bootmem_desc;
0120 
0121     bootmem_desc = cvmx_bootmem_get_desc();
0122 
0123     if (mem_size > OCTEON_MAX_PHY_MEM_SIZE) {
0124         mem_size = OCTEON_MAX_PHY_MEM_SIZE;
0125         pr_err("Error: requested memory too large,"
0126                "truncating to maximum size\n");
0127     }
0128 
0129     bootmem_desc->major_version = CVMX_BOOTMEM_DESC_MAJ_VER;
0130     bootmem_desc->minor_version = CVMX_BOOTMEM_DESC_MIN_VER;
0131 
0132     addr = (OCTEON_DDR0_BASE + reserve_low_mem + low_reserved_bytes);
0133     bootmem_desc->head_addr = 0;
0134 
0135     if (mem_size <= OCTEON_DDR0_SIZE) {
0136         __cvmx_bootmem_phy_free(addr,
0137                 mem_size - reserve_low_mem -
0138                 low_reserved_bytes, 0);
0139         return;
0140     }
0141 
0142     __cvmx_bootmem_phy_free(addr,
0143             OCTEON_DDR0_SIZE - reserve_low_mem -
0144             low_reserved_bytes, 0);
0145 
0146     mem_size -= OCTEON_DDR0_SIZE;
0147 
0148     if (mem_size > OCTEON_DDR1_SIZE) {
0149         __cvmx_bootmem_phy_free(OCTEON_DDR1_BASE, OCTEON_DDR1_SIZE, 0);
0150         __cvmx_bootmem_phy_free(OCTEON_DDR2_BASE,
0151                 mem_size - OCTEON_DDR1_SIZE, 0);
0152     } else
0153         __cvmx_bootmem_phy_free(OCTEON_DDR1_BASE, mem_size, 0);
0154 }
0155 
0156 static int octeon_kexec_prepare(struct kimage *image)
0157 {
0158     int i;
0159     char *bootloader = "kexec";
0160 
0161     octeon_boot_desc_ptr->argc = 0;
0162     for (i = 0; i < image->nr_segments; i++) {
0163         if (!strncmp(bootloader, (char *)image->segment[i].buf,
0164                 strlen(bootloader))) {
0165             /*
0166              * convert command line string to array
0167              * of parameters (as bootloader does).
0168              */
0169             int argc = 0, offt;
0170             char *str = (char *)image->segment[i].buf;
0171             char *ptr = strchr(str, ' ');
0172             while (ptr && (OCTEON_ARGV_MAX_ARGS > argc)) {
0173                 *ptr = '\0';
0174                 if (ptr[1] != ' ') {
0175                     offt = (int)(ptr - str + 1);
0176                     octeon_boot_desc_ptr->argv[argc] =
0177                         image->segment[i].mem + offt;
0178                     argc++;
0179                 }
0180                 ptr = strchr(ptr + 1, ' ');
0181             }
0182             octeon_boot_desc_ptr->argc = argc;
0183             break;
0184         }
0185     }
0186 
0187     /*
0188      * Information about segments will be needed during pre-boot memory
0189      * initialization.
0190      */
0191     kimage_ptr = image;
0192     return 0;
0193 }
0194 
0195 static void octeon_generic_shutdown(void)
0196 {
0197     int i;
0198 #ifdef CONFIG_SMP
0199     int cpu;
0200 #endif
0201     struct cvmx_bootmem_desc *bootmem_desc;
0202     void *named_block_array_ptr;
0203 
0204     bootmem_desc = cvmx_bootmem_get_desc();
0205     named_block_array_ptr =
0206         cvmx_phys_to_ptr(bootmem_desc->named_block_array_addr);
0207 
0208 #ifdef CONFIG_SMP
0209     /* disable watchdogs */
0210     for_each_online_cpu(cpu)
0211         cvmx_write_csr(CVMX_CIU_WDOGX(cpu_logical_map(cpu)), 0);
0212 #else
0213     cvmx_write_csr(CVMX_CIU_WDOGX(cvmx_get_core_num()), 0);
0214 #endif
0215     if (kimage_ptr != kexec_crash_image) {
0216         memset(named_block_array_ptr,
0217             0x0,
0218             CVMX_BOOTMEM_NUM_NAMED_BLOCKS *
0219             sizeof(struct cvmx_bootmem_named_block_desc));
0220         /*
0221          * Mark all memory (except low 0x100000 bytes) as free.
0222          * It is the same thing that bootloader does.
0223          */
0224         kexec_bootmem_init(octeon_bootinfo->dram_size*1024ULL*1024ULL,
0225                 0x100000);
0226         /*
0227          * Allocate all segments to avoid their corruption during boot.
0228          */
0229         for (i = 0; i < kimage_ptr->nr_segments; i++)
0230             cvmx_bootmem_alloc_address(
0231                 kimage_ptr->segment[i].memsz + 2*PAGE_SIZE,
0232                 kimage_ptr->segment[i].mem - PAGE_SIZE,
0233                 PAGE_SIZE);
0234     } else {
0235         /*
0236          * Do not mark all memory as free. Free only named sections
0237          * leaving the rest of memory unchanged.
0238          */
0239         struct cvmx_bootmem_named_block_desc *ptr =
0240             (struct cvmx_bootmem_named_block_desc *)
0241             named_block_array_ptr;
0242 
0243         for (i = 0; i < bootmem_desc->named_block_num_blocks; i++)
0244             if (ptr[i].size)
0245                 cvmx_bootmem_free_named(ptr[i].name);
0246     }
0247     kexec_args[2] = 1UL; /* running on octeon_main_processor */
0248     kexec_args[3] = (unsigned long)octeon_boot_desc_ptr;
0249 #ifdef CONFIG_SMP
0250     secondary_kexec_args[2] = 0UL; /* running on secondary cpu */
0251     secondary_kexec_args[3] = (unsigned long)octeon_boot_desc_ptr;
0252 #endif
0253 }
0254 
0255 static void octeon_shutdown(void)
0256 {
0257     octeon_generic_shutdown();
0258 #ifdef CONFIG_SMP
0259     smp_call_function(octeon_kexec_smp_down, NULL, 0);
0260     smp_wmb();
0261     while (num_online_cpus() > 1) {
0262         cpu_relax();
0263         mdelay(1);
0264     }
0265 #endif
0266 }
0267 
0268 static void octeon_crash_shutdown(struct pt_regs *regs)
0269 {
0270     octeon_generic_shutdown();
0271     default_machine_crash_shutdown(regs);
0272 }
0273 
0274 #ifdef CONFIG_SMP
0275 void octeon_crash_smp_send_stop(void)
0276 {
0277     int cpu;
0278 
0279     /* disable watchdogs */
0280     for_each_online_cpu(cpu)
0281         cvmx_write_csr(CVMX_CIU_WDOGX(cpu_logical_map(cpu)), 0);
0282 }
0283 #endif
0284 
0285 #endif /* CONFIG_KEXEC */
0286 
0287 uint64_t octeon_reserve32_memory;
0288 EXPORT_SYMBOL(octeon_reserve32_memory);
0289 
0290 #ifdef CONFIG_KEXEC
0291 /* crashkernel cmdline parameter is parsed _after_ memory setup
0292  * we also parse it here (workaround for EHB5200) */
0293 static uint64_t crashk_size, crashk_base;
0294 #endif
0295 
0296 static int octeon_uart;
0297 
0298 extern asmlinkage void handle_int(void);
0299 
0300 /**
0301  * octeon_is_simulation - Return non-zero if we are currently running
0302  * in the Octeon simulator
0303  *
0304  * Return: non-0 if running in the Octeon simulator, 0 otherwise
0305  */
0306 int octeon_is_simulation(void)
0307 {
0308     return octeon_bootinfo->board_type == CVMX_BOARD_TYPE_SIM;
0309 }
0310 EXPORT_SYMBOL(octeon_is_simulation);
0311 
0312 /**
0313  * octeon_is_pci_host - Return true if Octeon is in PCI Host mode. This means
0314  * Linux can control the PCI bus.
0315  *
0316  * Return: Non-zero if Octeon is in host mode.
0317  */
0318 int octeon_is_pci_host(void)
0319 {
0320 #ifdef CONFIG_PCI
0321     return octeon_bootinfo->config_flags & CVMX_BOOTINFO_CFG_FLAG_PCI_HOST;
0322 #else
0323     return 0;
0324 #endif
0325 }
0326 
0327 /**
0328  * octeon_get_clock_rate - Get the clock rate of Octeon
0329  *
0330  * Return: Clock rate in HZ
0331  */
0332 uint64_t octeon_get_clock_rate(void)
0333 {
0334     struct cvmx_sysinfo *sysinfo = cvmx_sysinfo_get();
0335 
0336     return sysinfo->cpu_clock_hz;
0337 }
0338 EXPORT_SYMBOL(octeon_get_clock_rate);
0339 
0340 static u64 octeon_io_clock_rate;
0341 
0342 u64 octeon_get_io_clock_rate(void)
0343 {
0344     return octeon_io_clock_rate;
0345 }
0346 EXPORT_SYMBOL(octeon_get_io_clock_rate);
0347 
0348 
0349 /**
0350  * octeon_write_lcd - Write to the LCD display connected to the bootbus.
0351  * @s:      String to write
0352  *
0353  * This display exists on most Cavium evaluation boards. If it doesn't exist,
0354  * then this function doesn't do anything.
0355  */
0356 static void octeon_write_lcd(const char *s)
0357 {
0358     if (octeon_bootinfo->led_display_base_addr) {
0359         void __iomem *lcd_address =
0360             ioremap(octeon_bootinfo->led_display_base_addr,
0361                     8);
0362         int i;
0363         for (i = 0; i < 8; i++, s++) {
0364             if (*s)
0365                 iowrite8(*s, lcd_address + i);
0366             else
0367                 iowrite8(' ', lcd_address + i);
0368         }
0369         iounmap(lcd_address);
0370     }
0371 }
0372 
0373 /**
0374  * octeon_get_boot_uart - Return the console uart passed by the bootloader
0375  *
0376  * Return: uart number (0 or 1)
0377  */
0378 static int octeon_get_boot_uart(void)
0379 {
0380     return (octeon_boot_desc_ptr->flags & OCTEON_BL_FLAG_CONSOLE_UART1) ?
0381         1 : 0;
0382 }
0383 
0384 /**
0385  * octeon_get_boot_coremask - Get the coremask Linux was booted on.
0386  *
0387  * Return: Core mask
0388  */
0389 int octeon_get_boot_coremask(void)
0390 {
0391     return octeon_boot_desc_ptr->core_mask;
0392 }
0393 
0394 /**
0395  * octeon_check_cpu_bist - Check the hardware BIST results for a CPU
0396  */
0397 void octeon_check_cpu_bist(void)
0398 {
0399     const int coreid = cvmx_get_core_num();
0400     unsigned long long mask;
0401     unsigned long long bist_val;
0402 
0403     /* Check BIST results for COP0 registers */
0404     mask = 0x1f00000000ull;
0405     bist_val = read_octeon_c0_icacheerr();
0406     if (bist_val & mask)
0407         pr_err("Core%d BIST Failure: CacheErr(icache) = 0x%llx\n",
0408                coreid, bist_val);
0409 
0410     bist_val = read_octeon_c0_dcacheerr();
0411     if (bist_val & 1)
0412         pr_err("Core%d L1 Dcache parity error: "
0413                "CacheErr(dcache) = 0x%llx\n",
0414                coreid, bist_val);
0415 
0416     mask = 0xfc00000000000000ull;
0417     bist_val = read_c0_cvmmemctl();
0418     if (bist_val & mask)
0419         pr_err("Core%d BIST Failure: COP0_CVM_MEM_CTL = 0x%llx\n",
0420                coreid, bist_val);
0421 
0422     write_octeon_c0_dcacheerr(0);
0423 }
0424 
0425 /**
0426  * octeon_restart - Reboot Octeon
0427  *
0428  * @command: Command to pass to the bootloader. Currently ignored.
0429  */
0430 static void octeon_restart(char *command)
0431 {
0432     /* Disable all watchdogs before soft reset. They don't get cleared */
0433 #ifdef CONFIG_SMP
0434     int cpu;
0435     for_each_online_cpu(cpu)
0436         cvmx_write_csr(CVMX_CIU_WDOGX(cpu_logical_map(cpu)), 0);
0437 #else
0438     cvmx_write_csr(CVMX_CIU_WDOGX(cvmx_get_core_num()), 0);
0439 #endif
0440 
0441     mb();
0442     while (1)
0443         if (OCTEON_IS_OCTEON3())
0444             cvmx_write_csr(CVMX_RST_SOFT_RST, 1);
0445         else
0446             cvmx_write_csr(CVMX_CIU_SOFT_RST, 1);
0447 }
0448 
0449 
0450 /**
0451  * octeon_kill_core - Permanently stop a core.
0452  *
0453  * @arg: Ignored.
0454  */
0455 static void octeon_kill_core(void *arg)
0456 {
0457     if (octeon_is_simulation())
0458         /* A break instruction causes the simulator stop a core */
0459         asm volatile ("break" ::: "memory");
0460 
0461     local_irq_disable();
0462     /* Disable watchdog on this core. */
0463     cvmx_write_csr(CVMX_CIU_WDOGX(cvmx_get_core_num()), 0);
0464     /* Spin in a low power mode. */
0465     while (true)
0466         asm volatile ("wait" ::: "memory");
0467 }
0468 
0469 
0470 /**
0471  * octeon_halt - Halt the system
0472  */
0473 static void octeon_halt(void)
0474 {
0475     smp_call_function(octeon_kill_core, NULL, 0);
0476 
0477     switch (octeon_bootinfo->board_type) {
0478     case CVMX_BOARD_TYPE_NAO38:
0479         /* Driving a 1 to GPIO 12 shuts off this board */
0480         cvmx_write_csr(CVMX_GPIO_BIT_CFGX(12), 1);
0481         cvmx_write_csr(CVMX_GPIO_TX_SET, 0x1000);
0482         break;
0483     default:
0484         octeon_write_lcd("PowerOff");
0485         break;
0486     }
0487 
0488     octeon_kill_core(NULL);
0489 }
0490 
0491 static char __read_mostly octeon_system_type[80];
0492 
0493 static void __init init_octeon_system_type(void)
0494 {
0495     char const *board_type;
0496 
0497     board_type = cvmx_board_type_to_string(octeon_bootinfo->board_type);
0498     if (board_type == NULL) {
0499         struct device_node *root;
0500         int ret;
0501 
0502         root = of_find_node_by_path("/");
0503         ret = of_property_read_string(root, "model", &board_type);
0504         of_node_put(root);
0505         if (ret)
0506             board_type = "Unsupported Board";
0507     }
0508 
0509     snprintf(octeon_system_type, sizeof(octeon_system_type), "%s (%s)",
0510          board_type, octeon_model_get_string(read_c0_prid()));
0511 }
0512 
0513 /**
0514  * octeon_board_type_string - Return a string representing the system type
0515  *
0516  * Return: system type string
0517  */
0518 const char *octeon_board_type_string(void)
0519 {
0520     return octeon_system_type;
0521 }
0522 
0523 const char *get_system_type(void)
0524     __attribute__ ((alias("octeon_board_type_string")));
0525 
0526 void octeon_user_io_init(void)
0527 {
0528     union octeon_cvmemctl cvmmemctl;
0529 
0530     /* Get the current settings for CP0_CVMMEMCTL_REG */
0531     cvmmemctl.u64 = read_c0_cvmmemctl();
0532     /* R/W If set, marked write-buffer entries time out the same
0533      * as as other entries; if clear, marked write-buffer entries
0534      * use the maximum timeout. */
0535     cvmmemctl.s.dismarkwblongto = 1;
0536     /* R/W If set, a merged store does not clear the write-buffer
0537      * entry timeout state. */
0538     cvmmemctl.s.dismrgclrwbto = 0;
0539     /* R/W Two bits that are the MSBs of the resultant CVMSEG LM
0540      * word location for an IOBDMA. The other 8 bits come from the
0541      * SCRADDR field of the IOBDMA. */
0542     cvmmemctl.s.iobdmascrmsb = 0;
0543     /* R/W If set, SYNCWS and SYNCS only order marked stores; if
0544      * clear, SYNCWS and SYNCS only order unmarked
0545      * stores. SYNCWSMARKED has no effect when DISSYNCWS is
0546      * set. */
0547     cvmmemctl.s.syncwsmarked = 0;
0548     /* R/W If set, SYNCWS acts as SYNCW and SYNCS acts as SYNC. */
0549     cvmmemctl.s.dissyncws = 0;
0550     /* R/W If set, no stall happens on write buffer full. */
0551     if (OCTEON_IS_MODEL(OCTEON_CN38XX_PASS2))
0552         cvmmemctl.s.diswbfst = 1;
0553     else
0554         cvmmemctl.s.diswbfst = 0;
0555     /* R/W If set (and SX set), supervisor-level loads/stores can
0556      * use XKPHYS addresses with <48>==0 */
0557     cvmmemctl.s.xkmemenas = 0;
0558 
0559     /* R/W If set (and UX set), user-level loads/stores can use
0560      * XKPHYS addresses with VA<48>==0 */
0561     cvmmemctl.s.xkmemenau = 0;
0562 
0563     /* R/W If set (and SX set), supervisor-level loads/stores can
0564      * use XKPHYS addresses with VA<48>==1 */
0565     cvmmemctl.s.xkioenas = 0;
0566 
0567     /* R/W If set (and UX set), user-level loads/stores can use
0568      * XKPHYS addresses with VA<48>==1 */
0569     cvmmemctl.s.xkioenau = 0;
0570 
0571     /* R/W If set, all stores act as SYNCW (NOMERGE must be set
0572      * when this is set) RW, reset to 0. */
0573     cvmmemctl.s.allsyncw = 0;
0574 
0575     /* R/W If set, no stores merge, and all stores reach the
0576      * coherent bus in order. */
0577     cvmmemctl.s.nomerge = 0;
0578     /* R/W Selects the bit in the counter used for DID time-outs 0
0579      * = 231, 1 = 230, 2 = 229, 3 = 214. Actual time-out is
0580      * between 1x and 2x this interval. For example, with
0581      * DIDTTO=3, expiration interval is between 16K and 32K. */
0582     cvmmemctl.s.didtto = 0;
0583     /* R/W If set, the (mem) CSR clock never turns off. */
0584     cvmmemctl.s.csrckalwys = 0;
0585     /* R/W If set, mclk never turns off. */
0586     cvmmemctl.s.mclkalwys = 0;
0587     /* R/W Selects the bit in the counter used for write buffer
0588      * flush time-outs (WBFLT+11) is the bit position in an
0589      * internal counter used to determine expiration. The write
0590      * buffer expires between 1x and 2x this interval. For
0591      * example, with WBFLT = 0, a write buffer expires between 2K
0592      * and 4K cycles after the write buffer entry is allocated. */
0593     cvmmemctl.s.wbfltime = 0;
0594     /* R/W If set, do not put Istream in the L2 cache. */
0595     cvmmemctl.s.istrnol2 = 0;
0596 
0597     /*
0598      * R/W The write buffer threshold. As per erratum Core-14752
0599      * for CN63XX, a sc/scd might fail if the write buffer is
0600      * full.  Lowering WBTHRESH greatly lowers the chances of the
0601      * write buffer ever being full and triggering the erratum.
0602      */
0603     if (OCTEON_IS_MODEL(OCTEON_CN63XX_PASS1_X))
0604         cvmmemctl.s.wbthresh = 4;
0605     else
0606         cvmmemctl.s.wbthresh = 10;
0607 
0608     /* R/W If set, CVMSEG is available for loads/stores in
0609      * kernel/debug mode. */
0610 #if CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE > 0
0611     cvmmemctl.s.cvmsegenak = 1;
0612 #else
0613     cvmmemctl.s.cvmsegenak = 0;
0614 #endif
0615     /* R/W If set, CVMSEG is available for loads/stores in
0616      * supervisor mode. */
0617     cvmmemctl.s.cvmsegenas = 0;
0618     /* R/W If set, CVMSEG is available for loads/stores in user
0619      * mode. */
0620     cvmmemctl.s.cvmsegenau = 0;
0621 
0622     write_c0_cvmmemctl(cvmmemctl.u64);
0623 
0624     /* Setup of CVMSEG is done in kernel-entry-init.h */
0625     if (smp_processor_id() == 0)
0626         pr_notice("CVMSEG size: %d cache lines (%d bytes)\n",
0627               CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE,
0628               CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE * 128);
0629 
0630     if (octeon_has_feature(OCTEON_FEATURE_FAU)) {
0631         union cvmx_iob_fau_timeout fau_timeout;
0632 
0633         /* Set a default for the hardware timeouts */
0634         fau_timeout.u64 = 0;
0635         fau_timeout.s.tout_val = 0xfff;
0636         /* Disable tagwait FAU timeout */
0637         fau_timeout.s.tout_enb = 0;
0638         cvmx_write_csr(CVMX_IOB_FAU_TIMEOUT, fau_timeout.u64);
0639     }
0640 
0641     if ((!OCTEON_IS_MODEL(OCTEON_CN68XX) &&
0642          !OCTEON_IS_MODEL(OCTEON_CN7XXX)) ||
0643         OCTEON_IS_MODEL(OCTEON_CN70XX)) {
0644         union cvmx_pow_nw_tim nm_tim;
0645 
0646         nm_tim.u64 = 0;
0647         /* 4096 cycles */
0648         nm_tim.s.nw_tim = 3;
0649         cvmx_write_csr(CVMX_POW_NW_TIM, nm_tim.u64);
0650     }
0651 
0652     write_octeon_c0_icacheerr(0);
0653     write_c0_derraddr1(0);
0654 }
0655 
0656 /**
0657  * prom_init - Early entry point for arch setup
0658  */
0659 void __init prom_init(void)
0660 {
0661     struct cvmx_sysinfo *sysinfo;
0662     const char *arg;
0663     char *p;
0664     int i;
0665     u64 t;
0666     int argc;
0667     /*
0668      * The bootloader passes a pointer to the boot descriptor in
0669      * $a3, this is available as fw_arg3.
0670      */
0671     octeon_boot_desc_ptr = (struct octeon_boot_descriptor *)fw_arg3;
0672     octeon_bootinfo =
0673         cvmx_phys_to_ptr(octeon_boot_desc_ptr->cvmx_desc_vaddr);
0674     cvmx_bootmem_init(cvmx_phys_to_ptr(octeon_bootinfo->phy_mem_desc_addr));
0675 
0676     sysinfo = cvmx_sysinfo_get();
0677     memset(sysinfo, 0, sizeof(*sysinfo));
0678     sysinfo->system_dram_size = octeon_bootinfo->dram_size << 20;
0679     sysinfo->phy_mem_desc_addr = (u64)phys_to_virt(octeon_bootinfo->phy_mem_desc_addr);
0680 
0681     if ((octeon_bootinfo->major_version > 1) ||
0682         (octeon_bootinfo->major_version == 1 &&
0683          octeon_bootinfo->minor_version >= 4))
0684         cvmx_coremask_copy(&sysinfo->core_mask,
0685                    &octeon_bootinfo->ext_core_mask);
0686     else
0687         cvmx_coremask_set64(&sysinfo->core_mask,
0688                     octeon_bootinfo->core_mask);
0689 
0690     /* Some broken u-boot pass garbage in upper bits, clear them out */
0691     if (!OCTEON_IS_MODEL(OCTEON_CN78XX))
0692         for (i = 512; i < 1024; i++)
0693             cvmx_coremask_clear_core(&sysinfo->core_mask, i);
0694 
0695     sysinfo->exception_base_addr = octeon_bootinfo->exception_base_addr;
0696     sysinfo->cpu_clock_hz = octeon_bootinfo->eclock_hz;
0697     sysinfo->dram_data_rate_hz = octeon_bootinfo->dclock_hz * 2;
0698     sysinfo->board_type = octeon_bootinfo->board_type;
0699     sysinfo->board_rev_major = octeon_bootinfo->board_rev_major;
0700     sysinfo->board_rev_minor = octeon_bootinfo->board_rev_minor;
0701     memcpy(sysinfo->mac_addr_base, octeon_bootinfo->mac_addr_base,
0702            sizeof(sysinfo->mac_addr_base));
0703     sysinfo->mac_addr_count = octeon_bootinfo->mac_addr_count;
0704     memcpy(sysinfo->board_serial_number,
0705            octeon_bootinfo->board_serial_number,
0706            sizeof(sysinfo->board_serial_number));
0707     sysinfo->compact_flash_common_base_addr =
0708         octeon_bootinfo->compact_flash_common_base_addr;
0709     sysinfo->compact_flash_attribute_base_addr =
0710         octeon_bootinfo->compact_flash_attribute_base_addr;
0711     sysinfo->led_display_base_addr = octeon_bootinfo->led_display_base_addr;
0712     sysinfo->dfa_ref_clock_hz = octeon_bootinfo->dfa_ref_clock_hz;
0713     sysinfo->bootloader_config_flags = octeon_bootinfo->config_flags;
0714 
0715     if (OCTEON_IS_OCTEON2()) {
0716         /* I/O clock runs at a different rate than the CPU. */
0717         union cvmx_mio_rst_boot rst_boot;
0718         rst_boot.u64 = cvmx_read_csr(CVMX_MIO_RST_BOOT);
0719         octeon_io_clock_rate = 50000000 * rst_boot.s.pnr_mul;
0720     } else if (OCTEON_IS_OCTEON3()) {
0721         /* I/O clock runs at a different rate than the CPU. */
0722         union cvmx_rst_boot rst_boot;
0723         rst_boot.u64 = cvmx_read_csr(CVMX_RST_BOOT);
0724         octeon_io_clock_rate = 50000000 * rst_boot.s.pnr_mul;
0725     } else {
0726         octeon_io_clock_rate = sysinfo->cpu_clock_hz;
0727     }
0728 
0729     t = read_c0_cvmctl();
0730     if ((t & (1ull << 27)) == 0) {
0731         /*
0732          * Setup the multiplier save/restore code if
0733          * CvmCtl[NOMUL] clear.
0734          */
0735         void *save;
0736         void *save_end;
0737         void *restore;
0738         void *restore_end;
0739         int save_len;
0740         int restore_len;
0741         int save_max = (char *)octeon_mult_save_end -
0742             (char *)octeon_mult_save;
0743         int restore_max = (char *)octeon_mult_restore_end -
0744             (char *)octeon_mult_restore;
0745         if (current_cpu_data.cputype == CPU_CAVIUM_OCTEON3) {
0746             save = octeon_mult_save3;
0747             save_end = octeon_mult_save3_end;
0748             restore = octeon_mult_restore3;
0749             restore_end = octeon_mult_restore3_end;
0750         } else {
0751             save = octeon_mult_save2;
0752             save_end = octeon_mult_save2_end;
0753             restore = octeon_mult_restore2;
0754             restore_end = octeon_mult_restore2_end;
0755         }
0756         save_len = (char *)save_end - (char *)save;
0757         restore_len = (char *)restore_end - (char *)restore;
0758         if (!WARN_ON(save_len > save_max ||
0759                 restore_len > restore_max)) {
0760             memcpy(octeon_mult_save, save, save_len);
0761             memcpy(octeon_mult_restore, restore, restore_len);
0762         }
0763     }
0764 
0765     /*
0766      * Only enable the LED controller if we're running on a CN38XX, CN58XX,
0767      * or CN56XX. The CN30XX and CN31XX don't have an LED controller.
0768      */
0769     if (!octeon_is_simulation() &&
0770         octeon_has_feature(OCTEON_FEATURE_LED_CONTROLLER)) {
0771         cvmx_write_csr(CVMX_LED_EN, 0);
0772         cvmx_write_csr(CVMX_LED_PRT, 0);
0773         cvmx_write_csr(CVMX_LED_DBG, 0);
0774         cvmx_write_csr(CVMX_LED_PRT_FMT, 0);
0775         cvmx_write_csr(CVMX_LED_UDD_CNTX(0), 32);
0776         cvmx_write_csr(CVMX_LED_UDD_CNTX(1), 32);
0777         cvmx_write_csr(CVMX_LED_UDD_DATX(0), 0);
0778         cvmx_write_csr(CVMX_LED_UDD_DATX(1), 0);
0779         cvmx_write_csr(CVMX_LED_EN, 1);
0780     }
0781 
0782     /*
0783      * We need to temporarily allocate all memory in the reserve32
0784      * region. This makes sure the kernel doesn't allocate this
0785      * memory when it is getting memory from the
0786      * bootloader. Later, after the memory allocations are
0787      * complete, the reserve32 will be freed.
0788      *
0789      * Allocate memory for RESERVED32 aligned on 2MB boundary. This
0790      * is in case we later use hugetlb entries with it.
0791      */
0792     if (CONFIG_CAVIUM_RESERVE32) {
0793         int64_t addr =
0794             cvmx_bootmem_phy_named_block_alloc(CONFIG_CAVIUM_RESERVE32 << 20,
0795                                0, 0, 2 << 20,
0796                                "CAVIUM_RESERVE32", 0);
0797         if (addr < 0)
0798             pr_err("Failed to allocate CAVIUM_RESERVE32 memory area\n");
0799         else
0800             octeon_reserve32_memory = addr;
0801     }
0802 
0803 #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2
0804     if (cvmx_read_csr(CVMX_L2D_FUS3) & (3ull << 34)) {
0805         pr_info("Skipping L2 locking due to reduced L2 cache size\n");
0806     } else {
0807         uint32_t __maybe_unused ebase = read_c0_ebase() & 0x3ffff000;
0808 #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_TLB
0809         /* TLB refill */
0810         cvmx_l2c_lock_mem_region(ebase, 0x100);
0811 #endif
0812 #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_EXCEPTION
0813         /* General exception */
0814         cvmx_l2c_lock_mem_region(ebase + 0x180, 0x80);
0815 #endif
0816 #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_LOW_LEVEL_INTERRUPT
0817         /* Interrupt handler */
0818         cvmx_l2c_lock_mem_region(ebase + 0x200, 0x80);
0819 #endif
0820 #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_INTERRUPT
0821         cvmx_l2c_lock_mem_region(__pa_symbol(handle_int), 0x100);
0822         cvmx_l2c_lock_mem_region(__pa_symbol(plat_irq_dispatch), 0x80);
0823 #endif
0824 #ifdef CONFIG_CAVIUM_OCTEON_LOCK_L2_MEMCPY
0825         cvmx_l2c_lock_mem_region(__pa_symbol(memcpy), 0x480);
0826 #endif
0827     }
0828 #endif
0829 
0830     octeon_check_cpu_bist();
0831 
0832     octeon_uart = octeon_get_boot_uart();
0833 
0834 #ifdef CONFIG_SMP
0835     octeon_write_lcd("LinuxSMP");
0836 #else
0837     octeon_write_lcd("Linux");
0838 #endif
0839 
0840     octeon_setup_delays();
0841 
0842     /*
0843      * BIST should always be enabled when doing a soft reset. L2
0844      * Cache locking for instance is not cleared unless BIST is
0845      * enabled.  Unfortunately due to a chip errata G-200 for
0846      * Cn38XX and CN31XX, BIST must be disabled on these parts.
0847      */
0848     if (OCTEON_IS_MODEL(OCTEON_CN38XX_PASS2) ||
0849         OCTEON_IS_MODEL(OCTEON_CN31XX))
0850         cvmx_write_csr(CVMX_CIU_SOFT_BIST, 0);
0851     else
0852         cvmx_write_csr(CVMX_CIU_SOFT_BIST, 1);
0853 
0854     /* Default to 64MB in the simulator to speed things up */
0855     if (octeon_is_simulation())
0856         max_memory = 64ull << 20;
0857 
0858     arg = strstr(arcs_cmdline, "mem=");
0859     if (arg) {
0860         max_memory = memparse(arg + 4, &p);
0861         if (max_memory == 0)
0862             max_memory = 32ull << 30;
0863         if (*p == '@')
0864             reserve_low_mem = memparse(p + 1, &p);
0865     }
0866 
0867     arcs_cmdline[0] = 0;
0868     argc = octeon_boot_desc_ptr->argc;
0869     for (i = 0; i < argc; i++) {
0870         const char *arg =
0871             cvmx_phys_to_ptr(octeon_boot_desc_ptr->argv[i]);
0872         if ((strncmp(arg, "MEM=", 4) == 0) ||
0873             (strncmp(arg, "mem=", 4) == 0)) {
0874             max_memory = memparse(arg + 4, &p);
0875             if (max_memory == 0)
0876                 max_memory = 32ull << 30;
0877             if (*p == '@')
0878                 reserve_low_mem = memparse(p + 1, &p);
0879 #ifdef CONFIG_KEXEC
0880         } else if (strncmp(arg, "crashkernel=", 12) == 0) {
0881             crashk_size = memparse(arg+12, &p);
0882             if (*p == '@')
0883                 crashk_base = memparse(p+1, &p);
0884             strcat(arcs_cmdline, " ");
0885             strcat(arcs_cmdline, arg);
0886             /*
0887              * To do: switch parsing to new style, something like:
0888              * parse_crashkernel(arg, sysinfo->system_dram_size,
0889              *        &crashk_size, &crashk_base);
0890              */
0891 #endif
0892         } else if (strlen(arcs_cmdline) + strlen(arg) + 1 <
0893                sizeof(arcs_cmdline) - 1) {
0894             strcat(arcs_cmdline, " ");
0895             strcat(arcs_cmdline, arg);
0896         }
0897     }
0898 
0899     if (strstr(arcs_cmdline, "console=") == NULL) {
0900         if (octeon_uart == 1)
0901             strcat(arcs_cmdline, " console=ttyS1,115200");
0902         else
0903             strcat(arcs_cmdline, " console=ttyS0,115200");
0904     }
0905 
0906     mips_hpt_frequency = octeon_get_clock_rate();
0907 
0908     octeon_init_cvmcount();
0909 
0910     _machine_restart = octeon_restart;
0911     _machine_halt = octeon_halt;
0912 
0913 #ifdef CONFIG_KEXEC
0914     _machine_kexec_shutdown = octeon_shutdown;
0915     _machine_crash_shutdown = octeon_crash_shutdown;
0916     _machine_kexec_prepare = octeon_kexec_prepare;
0917 #ifdef CONFIG_SMP
0918     _crash_smp_send_stop = octeon_crash_smp_send_stop;
0919 #endif
0920 #endif
0921 
0922     octeon_user_io_init();
0923     octeon_setup_smp();
0924 }
0925 
0926 /* Exclude a single page from the regions obtained in plat_mem_setup. */
0927 #ifndef CONFIG_CRASH_DUMP
0928 static __init void memory_exclude_page(u64 addr, u64 *mem, u64 *size)
0929 {
0930     if (addr > *mem && addr < *mem + *size) {
0931         u64 inc = addr - *mem;
0932         memblock_add(*mem, inc);
0933         *mem += inc;
0934         *size -= inc;
0935     }
0936 
0937     if (addr == *mem && *size > PAGE_SIZE) {
0938         *mem += PAGE_SIZE;
0939         *size -= PAGE_SIZE;
0940     }
0941 }
0942 #endif /* CONFIG_CRASH_DUMP */
0943 
0944 void __init fw_init_cmdline(void)
0945 {
0946     int i;
0947 
0948     octeon_boot_desc_ptr = (struct octeon_boot_descriptor *)fw_arg3;
0949     for (i = 0; i < octeon_boot_desc_ptr->argc; i++) {
0950         const char *arg =
0951             cvmx_phys_to_ptr(octeon_boot_desc_ptr->argv[i]);
0952         if (strlen(arcs_cmdline) + strlen(arg) + 1 <
0953                sizeof(arcs_cmdline) - 1) {
0954             strcat(arcs_cmdline, " ");
0955             strcat(arcs_cmdline, arg);
0956         }
0957     }
0958 }
0959 
0960 void __init *plat_get_fdt(void)
0961 {
0962     octeon_bootinfo =
0963         cvmx_phys_to_ptr(octeon_boot_desc_ptr->cvmx_desc_vaddr);
0964     return phys_to_virt(octeon_bootinfo->fdt_addr);
0965 }
0966 
0967 void __init plat_mem_setup(void)
0968 {
0969     uint64_t mem_alloc_size;
0970     uint64_t total;
0971     uint64_t crashk_end;
0972 #ifndef CONFIG_CRASH_DUMP
0973     int64_t memory;
0974 #endif
0975 
0976     total = 0;
0977     crashk_end = 0;
0978 
0979     /*
0980      * The Mips memory init uses the first memory location for
0981      * some memory vectors. When SPARSEMEM is in use, it doesn't
0982      * verify that the size is big enough for the final
0983      * vectors. Making the smallest chuck 4MB seems to be enough
0984      * to consistently work.
0985      */
0986     mem_alloc_size = 4 << 20;
0987     if (mem_alloc_size > max_memory)
0988         mem_alloc_size = max_memory;
0989 
0990 /* Crashkernel ignores bootmem list. It relies on mem=X@Y option */
0991 #ifdef CONFIG_CRASH_DUMP
0992     memblock_add(reserve_low_mem, max_memory);
0993     total += max_memory;
0994 #else
0995 #ifdef CONFIG_KEXEC
0996     if (crashk_size > 0) {
0997         memblock_add(crashk_base, crashk_size);
0998         crashk_end = crashk_base + crashk_size;
0999     }
1000 #endif
1001     /*
1002      * When allocating memory, we want incrementing addresses,
1003      * which is handled by memblock
1004      */
1005     cvmx_bootmem_lock();
1006     while (total < max_memory) {
1007         memory = cvmx_bootmem_phy_alloc(mem_alloc_size,
1008                         __pa_symbol(&_end), -1,
1009                         0x100000,
1010                         CVMX_BOOTMEM_FLAG_NO_LOCKING);
1011         if (memory >= 0) {
1012             u64 size = mem_alloc_size;
1013 #ifdef CONFIG_KEXEC
1014             uint64_t end;
1015 #endif
1016 
1017             /*
1018              * exclude a page at the beginning and end of
1019              * the 256MB PCIe 'hole' so the kernel will not
1020              * try to allocate multi-page buffers that
1021              * span the discontinuity.
1022              */
1023             memory_exclude_page(CVMX_PCIE_BAR1_PHYS_BASE,
1024                         &memory, &size);
1025             memory_exclude_page(CVMX_PCIE_BAR1_PHYS_BASE +
1026                         CVMX_PCIE_BAR1_PHYS_SIZE,
1027                         &memory, &size);
1028 #ifdef CONFIG_KEXEC
1029             end = memory + mem_alloc_size;
1030 
1031             /*
1032              * This function automatically merges address regions
1033              * next to each other if they are received in
1034              * incrementing order
1035              */
1036             if (memory < crashk_base && end >  crashk_end) {
1037                 /* region is fully in */
1038                 memblock_add(memory, crashk_base - memory);
1039                 total += crashk_base - memory;
1040                 memblock_add(crashk_end, end - crashk_end);
1041                 total += end - crashk_end;
1042                 continue;
1043             }
1044 
1045             if (memory >= crashk_base && end <= crashk_end)
1046                 /*
1047                  * Entire memory region is within the new
1048                  *  kernel's memory, ignore it.
1049                  */
1050                 continue;
1051 
1052             if (memory > crashk_base && memory < crashk_end &&
1053                 end > crashk_end) {
1054                 /*
1055                  * Overlap with the beginning of the region,
1056                  * reserve the beginning.
1057                   */
1058                 mem_alloc_size -= crashk_end - memory;
1059                 memory = crashk_end;
1060             } else if (memory < crashk_base && end > crashk_base &&
1061                    end < crashk_end)
1062                 /*
1063                  * Overlap with the beginning of the region,
1064                  * chop of end.
1065                  */
1066                 mem_alloc_size -= end - crashk_base;
1067 #endif
1068             memblock_add(memory, mem_alloc_size);
1069             total += mem_alloc_size;
1070             /* Recovering mem_alloc_size */
1071             mem_alloc_size = 4 << 20;
1072         } else {
1073             break;
1074         }
1075     }
1076     cvmx_bootmem_unlock();
1077 #endif /* CONFIG_CRASH_DUMP */
1078 
1079     /*
1080      * Now that we've allocated the kernel memory it is safe to
1081      * free the reserved region. We free it here so that builtin
1082      * drivers can use the memory.
1083      */
1084     if (octeon_reserve32_memory)
1085         cvmx_bootmem_free_named("CAVIUM_RESERVE32");
1086 
1087     if (total == 0)
1088         panic("Unable to allocate memory from "
1089               "cvmx_bootmem_phy_alloc");
1090 }
1091 
1092 /*
1093  * Emit one character to the boot UART.  Exported for use by the
1094  * watchdog timer.
1095  */
1096 void prom_putchar(char c)
1097 {
1098     uint64_t lsrval;
1099 
1100     /* Spin until there is room */
1101     do {
1102         lsrval = cvmx_read_csr(CVMX_MIO_UARTX_LSR(octeon_uart));
1103     } while ((lsrval & 0x20) == 0);
1104 
1105     /* Write the byte */
1106     cvmx_write_csr(CVMX_MIO_UARTX_THR(octeon_uart), c & 0xffull);
1107 }
1108 EXPORT_SYMBOL(prom_putchar);
1109 
1110 void __init prom_free_prom_memory(void)
1111 {
1112     if (OCTEON_IS_MODEL(OCTEON_CN6XXX)) {
1113         /* Check for presence of Core-14449 fix.  */
1114         u32 insn;
1115         u32 *foo;
1116 
1117         foo = &insn;
1118 
1119         asm volatile("# before" : : : "memory");
1120         prefetch(foo);
1121         asm volatile(
1122             ".set push\n\t"
1123             ".set noreorder\n\t"
1124             "bal 1f\n\t"
1125             "nop\n"
1126             "1:\tlw %0,-12($31)\n\t"
1127             ".set pop\n\t"
1128             : "=r" (insn) : : "$31", "memory");
1129 
1130         if ((insn >> 26) != 0x33)
1131             panic("No PREF instruction at Core-14449 probe point.");
1132 
1133         if (((insn >> 16) & 0x1f) != 28)
1134             panic("OCTEON II DCache prefetch workaround not in place (%04x).\n"
1135                   "Please build kernel with proper options (CONFIG_CAVIUM_CN63XXP1).",
1136                   insn);
1137     }
1138 }
1139 
1140 void __init octeon_fill_mac_addresses(void);
1141 
1142 void __init device_tree_init(void)
1143 {
1144     const void *fdt;
1145     bool do_prune;
1146     bool fill_mac;
1147 
1148 #ifdef CONFIG_MIPS_ELF_APPENDED_DTB
1149     if (!fdt_check_header(&__appended_dtb)) {
1150         fdt = &__appended_dtb;
1151         do_prune = false;
1152         fill_mac = true;
1153         pr_info("Using appended Device Tree.\n");
1154     } else
1155 #endif
1156     if (octeon_bootinfo->minor_version >= 3 && octeon_bootinfo->fdt_addr) {
1157         fdt = phys_to_virt(octeon_bootinfo->fdt_addr);
1158         if (fdt_check_header(fdt))
1159             panic("Corrupt Device Tree passed to kernel.");
1160         do_prune = false;
1161         fill_mac = false;
1162         pr_info("Using passed Device Tree.\n");
1163     } else if (OCTEON_IS_MODEL(OCTEON_CN68XX)) {
1164         fdt = &__dtb_octeon_68xx_begin;
1165         do_prune = true;
1166         fill_mac = true;
1167     } else {
1168         fdt = &__dtb_octeon_3xxx_begin;
1169         do_prune = true;
1170         fill_mac = true;
1171     }
1172 
1173     initial_boot_params = (void *)fdt;
1174 
1175     if (do_prune) {
1176         octeon_prune_device_tree();
1177         pr_info("Using internal Device Tree.\n");
1178     }
1179     if (fill_mac)
1180         octeon_fill_mac_addresses();
1181     unflatten_and_copy_device_tree();
1182     init_octeon_system_type();
1183 }
1184 
1185 static int __initdata disable_octeon_edac_p;
1186 
1187 static int __init disable_octeon_edac(char *str)
1188 {
1189     disable_octeon_edac_p = 1;
1190     return 0;
1191 }
1192 early_param("disable_octeon_edac", disable_octeon_edac);
1193 
1194 static char *edac_device_names[] = {
1195     "octeon_l2c_edac",
1196     "octeon_pc_edac",
1197 };
1198 
1199 static int __init edac_devinit(void)
1200 {
1201     struct platform_device *dev;
1202     int i, err = 0;
1203     int num_lmc;
1204     char *name;
1205 
1206     if (disable_octeon_edac_p)
1207         return 0;
1208 
1209     for (i = 0; i < ARRAY_SIZE(edac_device_names); i++) {
1210         name = edac_device_names[i];
1211         dev = platform_device_register_simple(name, -1, NULL, 0);
1212         if (IS_ERR(dev)) {
1213             pr_err("Registration of %s failed!\n", name);
1214             err = PTR_ERR(dev);
1215         }
1216     }
1217 
1218     num_lmc = OCTEON_IS_MODEL(OCTEON_CN68XX) ? 4 :
1219         (OCTEON_IS_MODEL(OCTEON_CN56XX) ? 2 : 1);
1220     for (i = 0; i < num_lmc; i++) {
1221         dev = platform_device_register_simple("octeon_lmc_edac",
1222                               i, NULL, 0);
1223         if (IS_ERR(dev)) {
1224             pr_err("Registration of octeon_lmc_edac %d failed!\n", i);
1225             err = PTR_ERR(dev);
1226         }
1227     }
1228 
1229     return err;
1230 }
1231 device_initcall(edac_devinit);
1232 
1233 static void __initdata *octeon_dummy_iospace;
1234 
1235 static int __init octeon_no_pci_init(void)
1236 {
1237     /*
1238      * Initially assume there is no PCI. The PCI/PCIe platform code will
1239      * later re-initialize these to correct values if they are present.
1240      */
1241     octeon_dummy_iospace = vzalloc(IO_SPACE_LIMIT);
1242     set_io_port_base((unsigned long)octeon_dummy_iospace);
1243     ioport_resource.start = MAX_RESOURCE;
1244     ioport_resource.end = 0;
1245     return 0;
1246 }
1247 core_initcall(octeon_no_pci_init);
1248 
1249 static int __init octeon_no_pci_release(void)
1250 {
1251     /*
1252      * Release the allocated memory if a real IO space is there.
1253      */
1254     if ((unsigned long)octeon_dummy_iospace != mips_io_port_base)
1255         vfree(octeon_dummy_iospace);
1256     return 0;
1257 }
1258 late_initcall(octeon_no_pci_release);