Olof Johansson | 1e76875 | 2006-09-06 14:42:08 -0500 | [diff] [blame] | 1 | /* |
Olof Johansson | 31c56d8 | 2007-02-04 16:36:55 -0600 | [diff] [blame] | 2 | * Copyright (C) 2006-2007 PA Semi, Inc |
Olof Johansson | 1e76875 | 2006-09-06 14:42:08 -0500 | [diff] [blame] | 3 | * |
| 4 | * Authors: Kip Walker, PA Semi |
| 5 | * Olof Johansson, PA Semi |
| 6 | * |
| 7 | * Maintained by: Olof Johansson <olof@lixom.net> |
| 8 | * |
| 9 | * Based on arch/powerpc/platforms/maple/setup.c |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License version 2 as |
| 13 | * published by the Free Software Foundation. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 23 | */ |
| 24 | |
Olof Johansson | 1e76875 | 2006-09-06 14:42:08 -0500 | [diff] [blame] | 25 | #include <linux/errno.h> |
| 26 | #include <linux/kernel.h> |
| 27 | #include <linux/delay.h> |
| 28 | #include <linux/console.h> |
Benjamin Herrenschmidt | 12d04ee | 2006-11-11 17:25:02 +1100 | [diff] [blame] | 29 | #include <linux/pci.h> |
Olof Johansson | 1e76875 | 2006-09-06 14:42:08 -0500 | [diff] [blame] | 30 | |
| 31 | #include <asm/prom.h> |
| 32 | #include <asm/system.h> |
| 33 | #include <asm/iommu.h> |
| 34 | #include <asm/machdep.h> |
| 35 | #include <asm/mpic.h> |
| 36 | #include <asm/smp.h> |
| 37 | #include <asm/time.h> |
Olof Johansson | 952418c | 2007-04-25 04:01:34 +1000 | [diff] [blame] | 38 | #include <asm/of_platform.h> |
Olof Johansson | 1e76875 | 2006-09-06 14:42:08 -0500 | [diff] [blame] | 39 | |
| 40 | #include "pasemi.h" |
| 41 | |
Olof Johansson | f620be9 | 2007-02-04 16:36:52 -0600 | [diff] [blame] | 42 | static void __iomem *reset_reg; |
| 43 | |
Olof Johansson | 1e76875 | 2006-09-06 14:42:08 -0500 | [diff] [blame] | 44 | static void pas_restart(char *cmd) |
| 45 | { |
Olof Johansson | f620be9 | 2007-02-04 16:36:52 -0600 | [diff] [blame] | 46 | printk("Restarting...\n"); |
| 47 | while (1) |
| 48 | out_le32(reset_reg, 0x6000000); |
Olof Johansson | 1e76875 | 2006-09-06 14:42:08 -0500 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | #ifdef CONFIG_SMP |
Olof Johansson | c388cfe | 2007-02-04 16:36:53 -0600 | [diff] [blame] | 52 | static DEFINE_SPINLOCK(timebase_lock); |
Olof Johansson | dc559f7 | 2007-08-22 12:26:43 +1000 | [diff] [blame] | 53 | static unsigned long timebase; |
Olof Johansson | c388cfe | 2007-02-04 16:36:53 -0600 | [diff] [blame] | 54 | |
| 55 | static void __devinit pas_give_timebase(void) |
| 56 | { |
Olof Johansson | c388cfe | 2007-02-04 16:36:53 -0600 | [diff] [blame] | 57 | spin_lock(&timebase_lock); |
| 58 | mtspr(SPRN_TBCTL, TBCTL_FREEZE); |
Olof Johansson | dc559f7 | 2007-08-22 12:26:43 +1000 | [diff] [blame] | 59 | isync(); |
| 60 | timebase = get_tb(); |
Olof Johansson | c388cfe | 2007-02-04 16:36:53 -0600 | [diff] [blame] | 61 | spin_unlock(&timebase_lock); |
Olof Johansson | dc559f7 | 2007-08-22 12:26:43 +1000 | [diff] [blame] | 62 | |
| 63 | while (timebase) |
| 64 | barrier(); |
| 65 | mtspr(SPRN_TBCTL, TBCTL_RESTART); |
Olof Johansson | c388cfe | 2007-02-04 16:36:53 -0600 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | static void __devinit pas_take_timebase(void) |
| 69 | { |
Olof Johansson | dc559f7 | 2007-08-22 12:26:43 +1000 | [diff] [blame] | 70 | while (!timebase) |
| 71 | smp_rmb(); |
| 72 | |
| 73 | spin_lock(&timebase_lock); |
| 74 | set_tb(timebase >> 32, timebase & 0xffffffff); |
| 75 | timebase = 0; |
| 76 | spin_unlock(&timebase_lock); |
Olof Johansson | c388cfe | 2007-02-04 16:36:53 -0600 | [diff] [blame] | 77 | } |
| 78 | |
Olof Johansson | 1e76875 | 2006-09-06 14:42:08 -0500 | [diff] [blame] | 79 | struct smp_ops_t pas_smp_ops = { |
| 80 | .probe = smp_mpic_probe, |
| 81 | .message_pass = smp_mpic_message_pass, |
| 82 | .kick_cpu = smp_generic_kick_cpu, |
| 83 | .setup_cpu = smp_mpic_setup_cpu, |
Olof Johansson | c388cfe | 2007-02-04 16:36:53 -0600 | [diff] [blame] | 84 | .give_timebase = pas_give_timebase, |
| 85 | .take_timebase = pas_take_timebase, |
Olof Johansson | 1e76875 | 2006-09-06 14:42:08 -0500 | [diff] [blame] | 86 | }; |
| 87 | #endif /* CONFIG_SMP */ |
| 88 | |
| 89 | void __init pas_setup_arch(void) |
| 90 | { |
| 91 | #ifdef CONFIG_SMP |
| 92 | /* Setup SMP callback */ |
| 93 | smp_ops = &pas_smp_ops; |
| 94 | #endif |
| 95 | /* Lookup PCI hosts */ |
| 96 | pas_pci_init(); |
| 97 | |
| 98 | #ifdef CONFIG_DUMMY_CONSOLE |
| 99 | conswitchp = &dummy_con; |
| 100 | #endif |
| 101 | |
Olof Johansson | f620be9 | 2007-02-04 16:36:52 -0600 | [diff] [blame] | 102 | /* Remap SDC register for doing reset */ |
| 103 | /* XXXOJN This should maybe come out of the device tree */ |
| 104 | reset_reg = ioremap(0xfc101100, 4); |
| 105 | |
Olof Johansson | 1199919 | 2007-02-04 16:36:51 -0600 | [diff] [blame] | 106 | pasemi_idle_init(); |
Olof Johansson | 1e76875 | 2006-09-06 14:42:08 -0500 | [diff] [blame] | 107 | } |
| 108 | |
Olof Johansson | 1e76875 | 2006-09-06 14:42:08 -0500 | [diff] [blame] | 109 | static __init void pas_init_IRQ(void) |
| 110 | { |
| 111 | struct device_node *np; |
| 112 | struct device_node *root, *mpic_node; |
| 113 | unsigned long openpic_addr; |
| 114 | const unsigned int *opprop; |
| 115 | int naddr, opplen; |
| 116 | struct mpic *mpic; |
| 117 | |
| 118 | mpic_node = NULL; |
| 119 | |
| 120 | for_each_node_by_type(np, "interrupt-controller") |
Stephen Rothwell | 55b61fe | 2007-05-03 17:26:52 +1000 | [diff] [blame] | 121 | if (of_device_is_compatible(np, "open-pic")) { |
Olof Johansson | 1e76875 | 2006-09-06 14:42:08 -0500 | [diff] [blame] | 122 | mpic_node = np; |
| 123 | break; |
| 124 | } |
| 125 | if (!mpic_node) |
| 126 | for_each_node_by_type(np, "open-pic") { |
| 127 | mpic_node = np; |
| 128 | break; |
| 129 | } |
| 130 | if (!mpic_node) { |
| 131 | printk(KERN_ERR |
| 132 | "Failed to locate the MPIC interrupt controller\n"); |
| 133 | return; |
| 134 | } |
| 135 | |
| 136 | /* Find address list in /platform-open-pic */ |
| 137 | root = of_find_node_by_path("/"); |
Stephen Rothwell | a8bda5d | 2007-04-03 10:56:50 +1000 | [diff] [blame] | 138 | naddr = of_n_addr_cells(root); |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 139 | opprop = of_get_property(root, "platform-open-pic", &opplen); |
Olof Johansson | 1e76875 | 2006-09-06 14:42:08 -0500 | [diff] [blame] | 140 | if (!opprop) { |
| 141 | printk(KERN_ERR "No platform-open-pic property.\n"); |
| 142 | of_node_put(root); |
| 143 | return; |
| 144 | } |
| 145 | openpic_addr = of_read_number(opprop, naddr); |
| 146 | printk(KERN_DEBUG "OpenPIC addr: %lx\n", openpic_addr); |
Olof Johansson | 1e76875 | 2006-09-06 14:42:08 -0500 | [diff] [blame] | 147 | |
Olof Johansson | 7df2457 | 2007-01-28 23:33:18 -0600 | [diff] [blame] | 148 | mpic = mpic_alloc(mpic_node, openpic_addr, |
Olof Johansson | 7e8bddf | 2007-04-16 16:28:38 +1000 | [diff] [blame] | 149 | MPIC_PRIMARY|MPIC_LARGE_VECTORS|MPIC_WANTS_RESET, |
Olof Johansson | 7df2457 | 2007-01-28 23:33:18 -0600 | [diff] [blame] | 150 | 0, 0, " PAS-OPIC "); |
Olof Johansson | 1e76875 | 2006-09-06 14:42:08 -0500 | [diff] [blame] | 151 | BUG_ON(!mpic); |
| 152 | |
| 153 | mpic_assign_isu(mpic, 0, openpic_addr + 0x10000); |
| 154 | mpic_init(mpic); |
| 155 | of_node_put(mpic_node); |
| 156 | of_node_put(root); |
| 157 | } |
| 158 | |
| 159 | static void __init pas_progress(char *s, unsigned short hex) |
| 160 | { |
| 161 | printk("[%04x] : %s\n", hex, s ? s : ""); |
| 162 | } |
| 163 | |
| 164 | |
Olof Johansson | bfed9d3 | 2007-02-04 16:36:50 -0600 | [diff] [blame] | 165 | static int pas_machine_check_handler(struct pt_regs *regs) |
| 166 | { |
| 167 | int cpu = smp_processor_id(); |
| 168 | unsigned long srr0, srr1, dsisr; |
| 169 | |
| 170 | srr0 = regs->nip; |
| 171 | srr1 = regs->msr; |
| 172 | dsisr = mfspr(SPRN_DSISR); |
| 173 | printk(KERN_ERR "Machine Check on CPU %d\n", cpu); |
| 174 | printk(KERN_ERR "SRR0 0x%016lx SRR1 0x%016lx\n", srr0, srr1); |
| 175 | printk(KERN_ERR "DSISR 0x%016lx DAR 0x%016lx\n", dsisr, regs->dar); |
| 176 | printk(KERN_ERR "Cause:\n"); |
| 177 | |
| 178 | if (srr1 & 0x200000) |
| 179 | printk(KERN_ERR "Signalled by SDC\n"); |
| 180 | if (srr1 & 0x100000) { |
| 181 | printk(KERN_ERR "Load/Store detected error:\n"); |
| 182 | if (dsisr & 0x8000) |
| 183 | printk(KERN_ERR "D-cache ECC double-bit error or bus error\n"); |
| 184 | if (dsisr & 0x4000) |
| 185 | printk(KERN_ERR "LSU snoop response error\n"); |
| 186 | if (dsisr & 0x2000) |
| 187 | printk(KERN_ERR "MMU SLB multi-hit or invalid B field\n"); |
| 188 | if (dsisr & 0x1000) |
| 189 | printk(KERN_ERR "Recoverable Duptags\n"); |
| 190 | if (dsisr & 0x800) |
| 191 | printk(KERN_ERR "Recoverable D-cache parity error count overflow\n"); |
| 192 | if (dsisr & 0x400) |
| 193 | printk(KERN_ERR "TLB parity error count overflow\n"); |
| 194 | } |
| 195 | if (srr1 & 0x80000) |
| 196 | printk(KERN_ERR "Bus Error\n"); |
| 197 | if (srr1 & 0x40000) |
| 198 | printk(KERN_ERR "I-side SLB multiple hit\n"); |
| 199 | if (srr1 & 0x20000) |
| 200 | printk(KERN_ERR "I-cache parity error hit\n"); |
| 201 | |
| 202 | /* SRR1[62] is from MSR[62] if recoverable, so pass that back */ |
| 203 | return !!(srr1 & 0x2); |
| 204 | } |
| 205 | |
Olof Johansson | 31c56d8 | 2007-02-04 16:36:55 -0600 | [diff] [blame] | 206 | static void __init pas_init_early(void) |
| 207 | { |
| 208 | iommu_init_early_pasemi(); |
| 209 | } |
| 210 | |
Olof Johansson | b97d279 | 2007-04-18 16:39:54 +1000 | [diff] [blame] | 211 | static struct of_device_id pasemi_bus_ids[] = { |
| 212 | { .type = "sdc", }, |
| 213 | {}, |
| 214 | }; |
| 215 | |
| 216 | static int __init pasemi_publish_devices(void) |
| 217 | { |
Olof Johansson | 90f7afe | 2007-05-01 14:43:39 +1000 | [diff] [blame] | 218 | if (!machine_is(pasemi)) |
| 219 | return 0; |
| 220 | |
| 221 | /* Publish OF platform devices for SDC and other non-PCI devices */ |
Olof Johansson | b97d279 | 2007-04-18 16:39:54 +1000 | [diff] [blame] | 222 | of_platform_bus_probe(NULL, pasemi_bus_ids, NULL); |
| 223 | |
| 224 | return 0; |
| 225 | } |
| 226 | device_initcall(pasemi_publish_devices); |
| 227 | |
Olof Johansson | bfed9d3 | 2007-02-04 16:36:50 -0600 | [diff] [blame] | 228 | |
Olof Johansson | 1e76875 | 2006-09-06 14:42:08 -0500 | [diff] [blame] | 229 | /* |
| 230 | * Called very early, MMU is off, device-tree isn't unflattened |
| 231 | */ |
| 232 | static int __init pas_probe(void) |
| 233 | { |
| 234 | unsigned long root = of_get_flat_dt_root(); |
| 235 | |
| 236 | if (!of_flat_dt_is_compatible(root, "PA6T-1682M")) |
| 237 | return 0; |
| 238 | |
| 239 | hpte_init_native(); |
| 240 | |
Olof Johansson | 31c56d8 | 2007-02-04 16:36:55 -0600 | [diff] [blame] | 241 | alloc_iobmap_l2(); |
| 242 | |
Olof Johansson | 1e76875 | 2006-09-06 14:42:08 -0500 | [diff] [blame] | 243 | return 1; |
| 244 | } |
| 245 | |
Olof Johansson | d4875a2 | 2007-07-06 00:49:04 +1000 | [diff] [blame] | 246 | define_machine(pasemi) { |
Olof Johansson | 1e76875 | 2006-09-06 14:42:08 -0500 | [diff] [blame] | 247 | .name = "PA Semi PA6T-1682M", |
| 248 | .probe = pas_probe, |
| 249 | .setup_arch = pas_setup_arch, |
Olof Johansson | 31c56d8 | 2007-02-04 16:36:55 -0600 | [diff] [blame] | 250 | .init_early = pas_init_early, |
Olof Johansson | 1e76875 | 2006-09-06 14:42:08 -0500 | [diff] [blame] | 251 | .init_IRQ = pas_init_IRQ, |
| 252 | .get_irq = mpic_get_irq, |
Olof Johansson | 1e76875 | 2006-09-06 14:42:08 -0500 | [diff] [blame] | 253 | .restart = pas_restart, |
Olof Johansson | 1e76875 | 2006-09-06 14:42:08 -0500 | [diff] [blame] | 254 | .get_boot_time = pas_get_boot_time, |
| 255 | .calibrate_decr = generic_calibrate_decr, |
Olof Johansson | 1e76875 | 2006-09-06 14:42:08 -0500 | [diff] [blame] | 256 | .progress = pas_progress, |
Olof Johansson | bfed9d3 | 2007-02-04 16:36:50 -0600 | [diff] [blame] | 257 | .machine_check_exception = pas_machine_check_handler, |
Olof Johansson | 1e76875 | 2006-09-06 14:42:08 -0500 | [diff] [blame] | 258 | }; |