0001
0002
0003
0004
0005
0006
0007
0008
0009 #undef DEBUG
0010
0011 #include <linux/init.h>
0012 #include <linux/errno.h>
0013 #include <linux/sched.h>
0014 #include <linux/kernel.h>
0015 #include <linux/export.h>
0016 #include <linux/mm.h>
0017 #include <linux/stddef.h>
0018 #include <linux/unistd.h>
0019 #include <linux/ptrace.h>
0020 #include <linux/user.h>
0021 #include <linux/tty.h>
0022 #include <linux/string.h>
0023 #include <linux/delay.h>
0024 #include <linux/ioport.h>
0025 #include <linux/major.h>
0026 #include <linux/initrd.h>
0027 #include <linux/vt_kern.h>
0028 #include <linux/console.h>
0029 #include <linux/pci.h>
0030 #include <linux/adb.h>
0031 #include <linux/cuda.h>
0032 #include <linux/pmu.h>
0033 #include <linux/irq.h>
0034 #include <linux/seq_file.h>
0035 #include <linux/root_dev.h>
0036 #include <linux/serial.h>
0037 #include <linux/smp.h>
0038 #include <linux/bitops.h>
0039 #include <linux/of_address.h>
0040 #include <linux/of_device.h>
0041 #include <linux/memblock.h>
0042
0043 #include <asm/processor.h>
0044 #include <asm/sections.h>
0045 #include <asm/io.h>
0046 #include <asm/pci-bridge.h>
0047 #include <asm/iommu.h>
0048 #include <asm/machdep.h>
0049 #include <asm/dma.h>
0050 #include <asm/cputable.h>
0051 #include <asm/time.h>
0052 #include <asm/mpic.h>
0053 #include <asm/rtas.h>
0054 #include <asm/udbg.h>
0055 #include <asm/nvram.h>
0056
0057 #include "maple.h"
0058
0059 #ifdef DEBUG
0060 #define DBG(fmt...) udbg_printf(fmt)
0061 #else
0062 #define DBG(fmt...)
0063 #endif
0064
0065 static unsigned long maple_find_nvram_base(void)
0066 {
0067 struct device_node *rtcs;
0068 unsigned long result = 0;
0069
0070
0071 rtcs = of_find_compatible_node(NULL, "nvram", "AMD8111");
0072 if (rtcs) {
0073 struct resource r;
0074 if (of_address_to_resource(rtcs, 0, &r)) {
0075 printk(KERN_EMERG "Maple: Unable to translate NVRAM"
0076 " address\n");
0077 goto bail;
0078 }
0079 if (!(r.flags & IORESOURCE_IO)) {
0080 printk(KERN_EMERG "Maple: NVRAM address isn't PIO!\n");
0081 goto bail;
0082 }
0083 result = r.start;
0084 } else
0085 printk(KERN_EMERG "Maple: Unable to find NVRAM\n");
0086 bail:
0087 of_node_put(rtcs);
0088 return result;
0089 }
0090
0091 static void __noreturn maple_restart(char *cmd)
0092 {
0093 unsigned int maple_nvram_base;
0094 const unsigned int *maple_nvram_offset, *maple_nvram_command;
0095 struct device_node *sp;
0096
0097 maple_nvram_base = maple_find_nvram_base();
0098 if (maple_nvram_base == 0)
0099 goto fail;
0100
0101
0102 sp = of_find_node_by_name(NULL, "service-processor");
0103 if (!sp) {
0104 printk(KERN_EMERG "Maple: Unable to find Service Processor\n");
0105 goto fail;
0106 }
0107 maple_nvram_offset = of_get_property(sp, "restart-addr", NULL);
0108 maple_nvram_command = of_get_property(sp, "restart-value", NULL);
0109 of_node_put(sp);
0110
0111
0112 outb_p(*maple_nvram_command, maple_nvram_base + *maple_nvram_offset);
0113 for (;;) ;
0114 fail:
0115 printk(KERN_EMERG "Maple: Manual Restart Required\n");
0116 for (;;) ;
0117 }
0118
0119 static void __noreturn maple_power_off(void)
0120 {
0121 unsigned int maple_nvram_base;
0122 const unsigned int *maple_nvram_offset, *maple_nvram_command;
0123 struct device_node *sp;
0124
0125 maple_nvram_base = maple_find_nvram_base();
0126 if (maple_nvram_base == 0)
0127 goto fail;
0128
0129
0130 sp = of_find_node_by_name(NULL, "service-processor");
0131 if (!sp) {
0132 printk(KERN_EMERG "Maple: Unable to find Service Processor\n");
0133 goto fail;
0134 }
0135 maple_nvram_offset = of_get_property(sp, "power-off-addr", NULL);
0136 maple_nvram_command = of_get_property(sp, "power-off-value", NULL);
0137 of_node_put(sp);
0138
0139
0140 outb_p(*maple_nvram_command, maple_nvram_base + *maple_nvram_offset);
0141 for (;;) ;
0142 fail:
0143 printk(KERN_EMERG "Maple: Manual Power-Down Required\n");
0144 for (;;) ;
0145 }
0146
0147 static void __noreturn maple_halt(void)
0148 {
0149 maple_power_off();
0150 }
0151
0152 #ifdef CONFIG_SMP
0153 static struct smp_ops_t maple_smp_ops = {
0154 .probe = smp_mpic_probe,
0155 .message_pass = smp_mpic_message_pass,
0156 .kick_cpu = smp_generic_kick_cpu,
0157 .setup_cpu = smp_mpic_setup_cpu,
0158 .give_timebase = smp_generic_give_timebase,
0159 .take_timebase = smp_generic_take_timebase,
0160 };
0161 #endif
0162
0163 static void __init maple_use_rtas_reboot_and_halt_if_present(void)
0164 {
0165 if (rtas_service_present("system-reboot") &&
0166 rtas_service_present("power-off")) {
0167 ppc_md.restart = rtas_restart;
0168 pm_power_off = rtas_power_off;
0169 ppc_md.halt = rtas_halt;
0170 }
0171 }
0172
0173 static void __init maple_setup_arch(void)
0174 {
0175
0176 loops_per_jiffy = 50000000;
0177
0178
0179 #ifdef CONFIG_SMP
0180 smp_ops = &maple_smp_ops;
0181 #endif
0182 maple_use_rtas_reboot_and_halt_if_present();
0183
0184 printk(KERN_DEBUG "Using native/NAP idle loop\n");
0185
0186 mmio_nvram_init();
0187 }
0188
0189
0190
0191
0192
0193
0194 static void __init maple_init_IRQ(void)
0195 {
0196 struct device_node *root, *np, *mpic_node = NULL;
0197 const unsigned int *opprop;
0198 unsigned long openpic_addr = 0;
0199 int naddr, n, i, opplen, has_isus = 0;
0200 struct mpic *mpic;
0201 unsigned int flags = 0;
0202
0203
0204
0205
0206
0207
0208 for_each_node_by_type(np, "interrupt-controller")
0209 if (of_device_is_compatible(np, "open-pic")) {
0210 mpic_node = np;
0211 break;
0212 }
0213 if (mpic_node == NULL)
0214 for_each_node_by_type(np, "open-pic") {
0215 mpic_node = np;
0216 break;
0217 }
0218 if (mpic_node == NULL) {
0219 printk(KERN_ERR
0220 "Failed to locate the MPIC interrupt controller\n");
0221 return;
0222 }
0223
0224
0225 root = of_find_node_by_path("/");
0226 naddr = of_n_addr_cells(root);
0227 opprop = of_get_property(root, "platform-open-pic", &opplen);
0228 if (opprop) {
0229 openpic_addr = of_read_number(opprop, naddr);
0230 has_isus = (opplen > naddr);
0231 printk(KERN_DEBUG "OpenPIC addr: %lx, has ISUs: %d\n",
0232 openpic_addr, has_isus);
0233 }
0234
0235 BUG_ON(openpic_addr == 0);
0236
0237
0238 if (of_get_property(np, "big-endian", NULL) != NULL)
0239 flags |= MPIC_BIG_ENDIAN;
0240
0241
0242 flags |= MPIC_U3_HT_IRQS;
0243
0244 flags |= MPIC_BIG_ENDIAN;
0245
0246
0247
0248
0249
0250 mpic = mpic_alloc(mpic_node, openpic_addr, flags,
0251 0, 0, " MPIC ");
0252 BUG_ON(mpic == NULL);
0253
0254
0255 opplen /= sizeof(u32);
0256 for (n = 0, i = naddr; i < opplen; i += naddr, n++) {
0257 unsigned long isuaddr = of_read_number(opprop + i, naddr);
0258 mpic_assign_isu(mpic, n, isuaddr);
0259 }
0260
0261
0262 mpic_init(mpic);
0263 ppc_md.get_irq = mpic_get_irq;
0264 of_node_put(mpic_node);
0265 of_node_put(root);
0266 }
0267
0268 static void __init maple_progress(char *s, unsigned short hex)
0269 {
0270 printk("*** %04x : %s\n", hex, s ? s : "");
0271 }
0272
0273
0274
0275
0276
0277 static int __init maple_probe(void)
0278 {
0279 if (!of_machine_is_compatible("Momentum,Maple") &&
0280 !of_machine_is_compatible("Momentum,Apache"))
0281 return 0;
0282
0283 pm_power_off = maple_power_off;
0284
0285 iommu_init_early_dart(&maple_pci_controller_ops);
0286
0287 return 1;
0288 }
0289
0290 #ifdef CONFIG_EDAC
0291
0292
0293
0294
0295 static int __init maple_cpc925_edac_setup(void)
0296 {
0297 struct platform_device *pdev;
0298 struct device_node *np = NULL;
0299 struct resource r;
0300 int ret;
0301 volatile void __iomem *mem;
0302 u32 rev;
0303
0304 np = of_find_node_by_type(NULL, "memory-controller");
0305 if (!np) {
0306 printk(KERN_ERR "%s: Unable to find memory-controller node\n",
0307 __func__);
0308 return -ENODEV;
0309 }
0310
0311 ret = of_address_to_resource(np, 0, &r);
0312 of_node_put(np);
0313
0314 if (ret < 0) {
0315 printk(KERN_ERR "%s: Unable to get memory-controller reg\n",
0316 __func__);
0317 return -ENODEV;
0318 }
0319
0320 mem = ioremap(r.start, resource_size(&r));
0321 if (!mem) {
0322 printk(KERN_ERR "%s: Unable to map memory-controller memory\n",
0323 __func__);
0324 return -ENOMEM;
0325 }
0326
0327 rev = __raw_readl(mem);
0328 iounmap(mem);
0329
0330 if (rev < 0x34 || rev > 0x3f) {
0331 printk(KERN_ERR "%s: Non-CPC925(U3H) bridge revision: %02x\n",
0332 __func__, rev);
0333 return 0;
0334 }
0335
0336 pdev = platform_device_register_simple("cpc925_edac", 0, &r, 1);
0337 if (IS_ERR(pdev))
0338 return PTR_ERR(pdev);
0339
0340 printk(KERN_INFO "%s: CPC925 platform device created\n", __func__);
0341
0342 return 0;
0343 }
0344 machine_device_initcall(maple, maple_cpc925_edac_setup);
0345 #endif
0346
0347 define_machine(maple) {
0348 .name = "Maple",
0349 .probe = maple_probe,
0350 .setup_arch = maple_setup_arch,
0351 .discover_phbs = maple_pci_init,
0352 .init_IRQ = maple_init_IRQ,
0353 .pci_irq_fixup = maple_pci_irq_fixup,
0354 .pci_get_legacy_ide_irq = maple_pci_get_legacy_ide_irq,
0355 .restart = maple_restart,
0356 .halt = maple_halt,
0357 .get_boot_time = maple_get_boot_time,
0358 .set_rtc_time = maple_set_rtc_time,
0359 .get_rtc_time = maple_get_rtc_time,
0360 .calibrate_decr = generic_calibrate_decr,
0361 .progress = maple_progress,
0362 .power_save = power4_idle,
0363 };