blob: c64fb5bfb37e3598ea6b44a64332210bc0bf5c8a [file] [log] [blame]
Olof Johansson1e768752006-09-06 14:42:08 -05001/*
Olof Johansson31c56d82007-02-04 16:36:55 -06002 * Copyright (C) 2006-2007 PA Semi, Inc
Olof Johansson1e768752006-09-06 14:42:08 -05003 *
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 Johansson1e768752006-09-06 14:42:08 -050025#include <linux/errno.h>
26#include <linux/kernel.h>
27#include <linux/delay.h>
28#include <linux/console.h>
Benjamin Herrenschmidt12d04ee2006-11-11 17:25:02 +110029#include <linux/pci.h>
Jon Loeliger5f867dc2007-11-14 04:13:03 +110030#include <linux/of_platform.h>
Olof Johansson1e768752006-09-06 14:42:08 -050031
32#include <asm/prom.h>
33#include <asm/system.h>
34#include <asm/iommu.h>
35#include <asm/machdep.h>
36#include <asm/mpic.h>
37#include <asm/smp.h>
38#include <asm/time.h>
Michael Neuling584f8b72007-12-06 17:24:48 +110039#include <asm/mmu.h>
Olof Johansson1e768752006-09-06 14:42:08 -050040
Olof Johansson2b571a02007-10-16 23:26:20 -070041#include <pcmcia/ss.h>
42#include <pcmcia/cistpl.h>
43#include <pcmcia/ds.h>
44
Olof Johansson1e768752006-09-06 14:42:08 -050045#include "pasemi.h"
46
Olof Johansson32e2b552007-11-07 09:31:06 -060047#if !defined(CONFIG_SMP)
48static void smp_send_stop(void) {}
49#endif
50
Olof Johanssoncd783412007-09-05 12:09:23 +100051/* SDC reset register, must be pre-mapped at reset time */
Olof Johanssonf620be92007-02-04 16:36:52 -060052static void __iomem *reset_reg;
53
Olof Johanssoncd783412007-09-05 12:09:23 +100054/* Various error status registers, must be pre-mapped at MCE time */
55
56#define MAX_MCE_REGS 32
57struct mce_regs {
58 char *name;
59 void __iomem *addr;
60};
61
62static struct mce_regs mce_regs[MAX_MCE_REGS];
63static int num_mce_regs;
Olof Johanssonf3653552007-12-20 13:11:18 -060064static int nmi_virq = NO_IRQ;
Olof Johanssoncd783412007-09-05 12:09:23 +100065
66
Olof Johansson1e768752006-09-06 14:42:08 -050067static void pas_restart(char *cmd)
68{
Olof Johansson32e2b552007-11-07 09:31:06 -060069 /* Need to put others cpu in hold loop so they're not sleeping */
70 smp_send_stop();
71 udelay(10000);
Olof Johanssonf620be92007-02-04 16:36:52 -060072 printk("Restarting...\n");
73 while (1)
74 out_le32(reset_reg, 0x6000000);
Olof Johansson1e768752006-09-06 14:42:08 -050075}
76
77#ifdef CONFIG_SMP
Olof Johanssonc388cfe2007-02-04 16:36:53 -060078static DEFINE_SPINLOCK(timebase_lock);
Olof Johanssondc559f72007-08-22 12:26:43 +100079static unsigned long timebase;
Olof Johanssonc388cfe2007-02-04 16:36:53 -060080
81static void __devinit pas_give_timebase(void)
82{
Olof Johanssonc388cfe2007-02-04 16:36:53 -060083 spin_lock(&timebase_lock);
84 mtspr(SPRN_TBCTL, TBCTL_FREEZE);
Olof Johanssondc559f72007-08-22 12:26:43 +100085 isync();
86 timebase = get_tb();
Olof Johanssonc388cfe2007-02-04 16:36:53 -060087 spin_unlock(&timebase_lock);
Olof Johanssondc559f72007-08-22 12:26:43 +100088
89 while (timebase)
90 barrier();
91 mtspr(SPRN_TBCTL, TBCTL_RESTART);
Olof Johanssonc388cfe2007-02-04 16:36:53 -060092}
93
94static void __devinit pas_take_timebase(void)
95{
Olof Johanssondc559f72007-08-22 12:26:43 +100096 while (!timebase)
97 smp_rmb();
98
99 spin_lock(&timebase_lock);
100 set_tb(timebase >> 32, timebase & 0xffffffff);
101 timebase = 0;
102 spin_unlock(&timebase_lock);
Olof Johanssonc388cfe2007-02-04 16:36:53 -0600103}
104
Olof Johansson1e768752006-09-06 14:42:08 -0500105struct smp_ops_t pas_smp_ops = {
106 .probe = smp_mpic_probe,
107 .message_pass = smp_mpic_message_pass,
108 .kick_cpu = smp_generic_kick_cpu,
109 .setup_cpu = smp_mpic_setup_cpu,
Olof Johanssonc388cfe2007-02-04 16:36:53 -0600110 .give_timebase = pas_give_timebase,
111 .take_timebase = pas_take_timebase,
Olof Johansson1e768752006-09-06 14:42:08 -0500112};
113#endif /* CONFIG_SMP */
114
115void __init pas_setup_arch(void)
116{
117#ifdef CONFIG_SMP
118 /* Setup SMP callback */
119 smp_ops = &pas_smp_ops;
120#endif
121 /* Lookup PCI hosts */
122 pas_pci_init();
123
124#ifdef CONFIG_DUMMY_CONSOLE
125 conswitchp = &dummy_con;
126#endif
127
Olof Johanssonf620be92007-02-04 16:36:52 -0600128 /* Remap SDC register for doing reset */
129 /* XXXOJN This should maybe come out of the device tree */
130 reset_reg = ioremap(0xfc101100, 4);
Olof Johansson1e768752006-09-06 14:42:08 -0500131}
132
Olof Johanssoncd783412007-09-05 12:09:23 +1000133static int __init pas_setup_mce_regs(void)
134{
135 struct pci_dev *dev;
136 int reg;
137
Olof Johanssoncd783412007-09-05 12:09:23 +1000138 /* Remap various SoC status registers for use by the MCE handler */
139
140 reg = 0;
141
142 dev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa00a, NULL);
143 while (dev && reg < MAX_MCE_REGS) {
144 mce_regs[reg].name = kasprintf(GFP_KERNEL,
145 "mc%d_mcdebug_errsta", reg);
146 mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0x730);
147 dev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa00a, dev);
148 reg++;
149 }
150
151 dev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa001, NULL);
152 if (dev && reg+4 < MAX_MCE_REGS) {
153 mce_regs[reg].name = "iobdbg_IntStatus1";
154 mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0x438);
155 reg++;
156 mce_regs[reg].name = "iobdbg_IOCTbusIntDbgReg";
157 mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0x454);
158 reg++;
159 mce_regs[reg].name = "iobiom_IntStatus";
160 mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0xc10);
161 reg++;
162 mce_regs[reg].name = "iobiom_IntDbgReg";
163 mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0xc1c);
164 reg++;
165 }
166
167 dev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa009, NULL);
168 if (dev && reg+2 < MAX_MCE_REGS) {
169 mce_regs[reg].name = "l2csts_IntStatus";
170 mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0x200);
171 reg++;
172 mce_regs[reg].name = "l2csts_Cnt";
173 mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0x214);
174 reg++;
175 }
176
177 num_mce_regs = reg;
178
179 return 0;
180}
Grant Likelybdddec42008-01-02 12:32:28 -0700181machine_device_initcall(pasemi, pas_setup_mce_regs);
Olof Johanssoncd783412007-09-05 12:09:23 +1000182
Olof Johansson1e768752006-09-06 14:42:08 -0500183static __init void pas_init_IRQ(void)
184{
185 struct device_node *np;
186 struct device_node *root, *mpic_node;
187 unsigned long openpic_addr;
188 const unsigned int *opprop;
189 int naddr, opplen;
Olof Johanssonf3653552007-12-20 13:11:18 -0600190 int mpic_flags;
191 const unsigned int *nmiprop;
Olof Johansson1e768752006-09-06 14:42:08 -0500192 struct mpic *mpic;
193
194 mpic_node = NULL;
195
196 for_each_node_by_type(np, "interrupt-controller")
Stephen Rothwell55b61fe2007-05-03 17:26:52 +1000197 if (of_device_is_compatible(np, "open-pic")) {
Olof Johansson1e768752006-09-06 14:42:08 -0500198 mpic_node = np;
199 break;
200 }
201 if (!mpic_node)
202 for_each_node_by_type(np, "open-pic") {
203 mpic_node = np;
204 break;
205 }
206 if (!mpic_node) {
207 printk(KERN_ERR
208 "Failed to locate the MPIC interrupt controller\n");
209 return;
210 }
211
212 /* Find address list in /platform-open-pic */
213 root = of_find_node_by_path("/");
Stephen Rothwella8bda5d2007-04-03 10:56:50 +1000214 naddr = of_n_addr_cells(root);
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000215 opprop = of_get_property(root, "platform-open-pic", &opplen);
Olof Johansson1e768752006-09-06 14:42:08 -0500216 if (!opprop) {
217 printk(KERN_ERR "No platform-open-pic property.\n");
218 of_node_put(root);
219 return;
220 }
221 openpic_addr = of_read_number(opprop, naddr);
222 printk(KERN_DEBUG "OpenPIC addr: %lx\n", openpic_addr);
Olof Johansson1e768752006-09-06 14:42:08 -0500223
Olof Johanssond87bf3b2007-12-27 22:16:29 -0600224 mpic_flags = MPIC_PRIMARY | MPIC_LARGE_VECTORS | MPIC_NO_BIAS;
Olof Johanssonf3653552007-12-20 13:11:18 -0600225
226 nmiprop = of_get_property(mpic_node, "nmi-source", NULL);
227 if (nmiprop)
228 mpic_flags |= MPIC_ENABLE_MCK;
229
Olof Johansson7df24572007-01-28 23:33:18 -0600230 mpic = mpic_alloc(mpic_node, openpic_addr,
Olof Johanssonf3653552007-12-20 13:11:18 -0600231 mpic_flags, 0, 0, "PASEMI-OPIC");
Olof Johansson1e768752006-09-06 14:42:08 -0500232 BUG_ON(!mpic);
233
234 mpic_assign_isu(mpic, 0, openpic_addr + 0x10000);
235 mpic_init(mpic);
Olof Johanssonf3653552007-12-20 13:11:18 -0600236 /* The NMI/MCK source needs to be prio 15 */
237 if (nmiprop) {
238 nmi_virq = irq_create_mapping(NULL, *nmiprop);
239 mpic_irq_set_priority(nmi_virq, 15);
240 set_irq_type(nmi_virq, IRQ_TYPE_EDGE_RISING);
241 mpic_unmask_irq(nmi_virq);
242 }
243
Olof Johansson1e768752006-09-06 14:42:08 -0500244 of_node_put(mpic_node);
245 of_node_put(root);
246}
247
248static void __init pas_progress(char *s, unsigned short hex)
249{
250 printk("[%04x] : %s\n", hex, s ? s : "");
251}
252
253
Olof Johanssonbfed9d32007-02-04 16:36:50 -0600254static int pas_machine_check_handler(struct pt_regs *regs)
255{
256 int cpu = smp_processor_id();
257 unsigned long srr0, srr1, dsisr;
Olof Johanssoncd783412007-09-05 12:09:23 +1000258 int dump_slb = 0;
259 int i;
Olof Johanssonbfed9d32007-02-04 16:36:50 -0600260
261 srr0 = regs->nip;
262 srr1 = regs->msr;
Olof Johanssonf3653552007-12-20 13:11:18 -0600263
Olof Johanssonf0d45772008-01-02 12:35:50 -0600264 if (nmi_virq != NO_IRQ && mpic_get_mcirq() == nmi_virq) {
Olof Johanssonf3653552007-12-20 13:11:18 -0600265 printk(KERN_ERR "NMI delivered\n");
266 debugger(regs);
267 mpic_end_irq(nmi_virq);
268 goto out;
269 }
270
Olof Johanssonbfed9d32007-02-04 16:36:50 -0600271 dsisr = mfspr(SPRN_DSISR);
272 printk(KERN_ERR "Machine Check on CPU %d\n", cpu);
Olof Johanssoncd783412007-09-05 12:09:23 +1000273 printk(KERN_ERR "SRR0 0x%016lx SRR1 0x%016lx\n", srr0, srr1);
274 printk(KERN_ERR "DSISR 0x%016lx DAR 0x%016lx\n", dsisr, regs->dar);
275 printk(KERN_ERR "BER 0x%016lx MER 0x%016lx\n", mfspr(SPRN_PA6T_BER),
276 mfspr(SPRN_PA6T_MER));
277 printk(KERN_ERR "IER 0x%016lx DER 0x%016lx\n", mfspr(SPRN_PA6T_IER),
278 mfspr(SPRN_PA6T_DER));
Olof Johanssonbfed9d32007-02-04 16:36:50 -0600279 printk(KERN_ERR "Cause:\n");
280
281 if (srr1 & 0x200000)
282 printk(KERN_ERR "Signalled by SDC\n");
Olof Johanssoncd783412007-09-05 12:09:23 +1000283
Olof Johanssonbfed9d32007-02-04 16:36:50 -0600284 if (srr1 & 0x100000) {
285 printk(KERN_ERR "Load/Store detected error:\n");
286 if (dsisr & 0x8000)
287 printk(KERN_ERR "D-cache ECC double-bit error or bus error\n");
288 if (dsisr & 0x4000)
289 printk(KERN_ERR "LSU snoop response error\n");
Olof Johanssoncd783412007-09-05 12:09:23 +1000290 if (dsisr & 0x2000) {
Olof Johanssonbfed9d32007-02-04 16:36:50 -0600291 printk(KERN_ERR "MMU SLB multi-hit or invalid B field\n");
Olof Johanssoncd783412007-09-05 12:09:23 +1000292 dump_slb = 1;
293 }
Olof Johanssonbfed9d32007-02-04 16:36:50 -0600294 if (dsisr & 0x1000)
295 printk(KERN_ERR "Recoverable Duptags\n");
296 if (dsisr & 0x800)
297 printk(KERN_ERR "Recoverable D-cache parity error count overflow\n");
298 if (dsisr & 0x400)
299 printk(KERN_ERR "TLB parity error count overflow\n");
300 }
Olof Johanssoncd783412007-09-05 12:09:23 +1000301
Olof Johanssonbfed9d32007-02-04 16:36:50 -0600302 if (srr1 & 0x80000)
303 printk(KERN_ERR "Bus Error\n");
Olof Johanssoncd783412007-09-05 12:09:23 +1000304
305 if (srr1 & 0x40000) {
Olof Johanssonbfed9d32007-02-04 16:36:50 -0600306 printk(KERN_ERR "I-side SLB multiple hit\n");
Olof Johanssoncd783412007-09-05 12:09:23 +1000307 dump_slb = 1;
308 }
309
Olof Johanssonbfed9d32007-02-04 16:36:50 -0600310 if (srr1 & 0x20000)
311 printk(KERN_ERR "I-cache parity error hit\n");
312
Olof Johanssoncd783412007-09-05 12:09:23 +1000313 if (num_mce_regs == 0)
314 printk(KERN_ERR "No MCE registers mapped yet, can't dump\n");
315 else
316 printk(KERN_ERR "SoC debug registers:\n");
317
318 for (i = 0; i < num_mce_regs; i++)
319 printk(KERN_ERR "%s: 0x%08x\n", mce_regs[i].name,
320 in_le32(mce_regs[i].addr));
321
322 if (dump_slb) {
323 unsigned long e, v;
324 int i;
325
326 printk(KERN_ERR "slb contents:\n");
Michael Neuling584f8b72007-12-06 17:24:48 +1100327 for (i = 0; i < mmu_slb_size; i++) {
Olof Johanssoncd783412007-09-05 12:09:23 +1000328 asm volatile("slbmfee %0,%1" : "=r" (e) : "r" (i));
329 asm volatile("slbmfev %0,%1" : "=r" (v) : "r" (i));
330 printk(KERN_ERR "%02d %016lx %016lx\n", i, e, v);
331 }
332 }
333
Olof Johanssonf3653552007-12-20 13:11:18 -0600334out:
Olof Johanssonbfed9d32007-02-04 16:36:50 -0600335 /* SRR1[62] is from MSR[62] if recoverable, so pass that back */
336 return !!(srr1 & 0x2);
337}
338
Olof Johansson31c56d82007-02-04 16:36:55 -0600339static void __init pas_init_early(void)
340{
341 iommu_init_early_pasemi();
342}
343
Olof Johansson2b571a02007-10-16 23:26:20 -0700344#ifdef CONFIG_PCMCIA
345static int pcmcia_notify(struct notifier_block *nb, unsigned long action,
346 void *data)
347{
348 struct device *dev = data;
349 struct device *parent;
350 struct pcmcia_device *pdev = to_pcmcia_dev(dev);
351
352 /* We are only intereted in device addition */
353 if (action != BUS_NOTIFY_ADD_DEVICE)
354 return 0;
355
356 parent = pdev->socket->dev.parent;
357
358 /* We know electra_cf devices will always have of_node set, since
359 * electra_cf is an of_platform driver.
360 */
361 if (!parent->archdata.of_node)
362 return 0;
363
364 if (!of_device_is_compatible(parent->archdata.of_node, "electra-cf"))
365 return 0;
366
367 /* We use the direct ops for localbus */
368 dev->archdata.dma_ops = &dma_direct_ops;
369
370 return 0;
371}
372
373static struct notifier_block pcmcia_notifier = {
374 .notifier_call = pcmcia_notify,
375};
376
377static inline void pasemi_pcmcia_init(void)
378{
379 extern struct bus_type pcmcia_bus_type;
380
381 bus_register_notifier(&pcmcia_bus_type, &pcmcia_notifier);
382}
383
384#else
385
386static inline void pasemi_pcmcia_init(void)
387{
388}
389
390#endif
391
392
Olof Johanssonb97d2792007-04-18 16:39:54 +1000393static struct of_device_id pasemi_bus_ids[] = {
Olof Johansson0d08a842007-11-04 20:57:45 -0600394 /* Unfortunately needed for legacy firmwares */
Olof Johansson2b571a02007-10-16 23:26:20 -0700395 { .type = "localbus", },
Olof Johanssonb97d2792007-04-18 16:39:54 +1000396 { .type = "sdc", },
Olof Johansson0d08a842007-11-04 20:57:45 -0600397 /* These are the proper entries, which newer firmware uses */
398 { .compatible = "pasemi,localbus", },
399 { .compatible = "pasemi,sdc", },
Olof Johanssonb97d2792007-04-18 16:39:54 +1000400 {},
401};
402
403static int __init pasemi_publish_devices(void)
404{
Olof Johansson2b571a02007-10-16 23:26:20 -0700405 pasemi_pcmcia_init();
406
Olof Johansson90f7afe2007-05-01 14:43:39 +1000407 /* Publish OF platform devices for SDC and other non-PCI devices */
Olof Johanssonb97d2792007-04-18 16:39:54 +1000408 of_platform_bus_probe(NULL, pasemi_bus_ids, NULL);
409
410 return 0;
411}
Grant Likelybdddec42008-01-02 12:32:28 -0700412machine_device_initcall(pasemi, pasemi_publish_devices);
Olof Johanssonb97d2792007-04-18 16:39:54 +1000413
Olof Johanssonbfed9d32007-02-04 16:36:50 -0600414
Olof Johansson1e768752006-09-06 14:42:08 -0500415/*
416 * Called very early, MMU is off, device-tree isn't unflattened
417 */
418static int __init pas_probe(void)
419{
420 unsigned long root = of_get_flat_dt_root();
421
Olof Johansson0d08a842007-11-04 20:57:45 -0600422 if (!of_flat_dt_is_compatible(root, "PA6T-1682M") &&
423 !of_flat_dt_is_compatible(root, "pasemi,pwrficient"))
Olof Johansson1e768752006-09-06 14:42:08 -0500424 return 0;
425
426 hpte_init_native();
427
Olof Johansson31c56d82007-02-04 16:36:55 -0600428 alloc_iobmap_l2();
429
Olof Johansson1e768752006-09-06 14:42:08 -0500430 return 1;
431}
432
Olof Johanssond4875a22007-07-06 00:49:04 +1000433define_machine(pasemi) {
Olof Johansson0d08a842007-11-04 20:57:45 -0600434 .name = "PA Semi PWRficient",
Olof Johansson1e768752006-09-06 14:42:08 -0500435 .probe = pas_probe,
436 .setup_arch = pas_setup_arch,
Olof Johansson31c56d82007-02-04 16:36:55 -0600437 .init_early = pas_init_early,
Olof Johansson1e768752006-09-06 14:42:08 -0500438 .init_IRQ = pas_init_IRQ,
439 .get_irq = mpic_get_irq,
Olof Johansson1e768752006-09-06 14:42:08 -0500440 .restart = pas_restart,
Olof Johansson1e768752006-09-06 14:42:08 -0500441 .get_boot_time = pas_get_boot_time,
442 .calibrate_decr = generic_calibrate_decr,
Olof Johansson1e768752006-09-06 14:42:08 -0500443 .progress = pas_progress,
Olof Johanssonbfed9d32007-02-04 16:36:50 -0600444 .machine_check_exception = pas_machine_check_handler,
Olof Johansson1e768752006-09-06 14:42:08 -0500445};