blob: 1d0c3a621a38b578e7fd1db7e32f22b3744e00ff [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>
Paul Gortmaker66b15db2011-05-27 10:46:24 -040029#include <linux/export.h>
Benjamin Herrenschmidt12d04ee2006-11-11 17:25:02 +110030#include <linux/pci.h>
Jon Loeliger5f867dc2007-11-14 04:13:03 +110031#include <linux/of_platform.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090032#include <linux/gfp.h>
Olof Johansson1e768752006-09-06 14:42:08 -050033
34#include <asm/prom.h>
Olof Johansson1e768752006-09-06 14:42:08 -050035#include <asm/iommu.h>
36#include <asm/machdep.h>
37#include <asm/mpic.h>
38#include <asm/smp.h>
39#include <asm/time.h>
Michael Neuling584f8b72007-12-06 17:24:48 +110040#include <asm/mmu.h>
David Howellsae3a1972012-03-28 18:30:02 +010041#include <asm/debug.h>
Olof Johansson1e768752006-09-06 14:42:08 -050042
Olof Johansson2b571a02007-10-16 23:26:20 -070043#include <pcmcia/ss.h>
44#include <pcmcia/cistpl.h>
45#include <pcmcia/ds.h>
46
Olof Johansson1e768752006-09-06 14:42:08 -050047#include "pasemi.h"
48
Olof Johanssoncd783412007-09-05 12:09:23 +100049/* SDC reset register, must be pre-mapped at reset time */
Olof Johanssonf620be92007-02-04 16:36:52 -060050static void __iomem *reset_reg;
51
Olof Johanssoncd783412007-09-05 12:09:23 +100052/* Various error status registers, must be pre-mapped at MCE time */
53
54#define MAX_MCE_REGS 32
55struct mce_regs {
56 char *name;
57 void __iomem *addr;
58};
59
60static struct mce_regs mce_regs[MAX_MCE_REGS];
61static int num_mce_regs;
Olof Johanssonf3653552007-12-20 13:11:18 -060062static int nmi_virq = NO_IRQ;
Olof Johanssoncd783412007-09-05 12:09:23 +100063
64
Daniel Axtens95ec77c2016-07-12 10:54:52 +100065static void __noreturn pas_restart(char *cmd)
Olof Johansson1e768752006-09-06 14:42:08 -050066{
Olof Johansson32e2b552007-11-07 09:31:06 -060067 /* Need to put others cpu in hold loop so they're not sleeping */
68 smp_send_stop();
69 udelay(10000);
Olof Johanssonf620be92007-02-04 16:36:52 -060070 printk("Restarting...\n");
71 while (1)
72 out_le32(reset_reg, 0x6000000);
Olof Johansson1e768752006-09-06 14:42:08 -050073}
74
75#ifdef CONFIG_SMP
Thomas Gleixner445c8952009-12-02 19:49:50 +010076static arch_spinlock_t timebase_lock;
Olof Johanssondc559f72007-08-22 12:26:43 +100077static unsigned long timebase;
Olof Johanssonc388cfe2007-02-04 16:36:53 -060078
Greg Kroah-Hartmancad5cef2012-12-21 14:04:10 -080079static void pas_give_timebase(void)
Olof Johanssonc388cfe2007-02-04 16:36:53 -060080{
Benjamin Herrenschmidt6893ce62009-06-16 16:42:51 +000081 unsigned long flags;
82
83 local_irq_save(flags);
84 hard_irq_disable();
Thomas Gleixner0199c4e2009-12-02 20:01:25 +010085 arch_spin_lock(&timebase_lock);
Olof Johanssonc388cfe2007-02-04 16:36:53 -060086 mtspr(SPRN_TBCTL, TBCTL_FREEZE);
Olof Johanssondc559f72007-08-22 12:26:43 +100087 isync();
88 timebase = get_tb();
Thomas Gleixner0199c4e2009-12-02 20:01:25 +010089 arch_spin_unlock(&timebase_lock);
Olof Johanssondc559f72007-08-22 12:26:43 +100090
91 while (timebase)
92 barrier();
93 mtspr(SPRN_TBCTL, TBCTL_RESTART);
Benjamin Herrenschmidt6893ce62009-06-16 16:42:51 +000094 local_irq_restore(flags);
Olof Johanssonc388cfe2007-02-04 16:36:53 -060095}
96
Greg Kroah-Hartmancad5cef2012-12-21 14:04:10 -080097static void pas_take_timebase(void)
Olof Johanssonc388cfe2007-02-04 16:36:53 -060098{
Olof Johanssondc559f72007-08-22 12:26:43 +100099 while (!timebase)
100 smp_rmb();
101
Thomas Gleixner0199c4e2009-12-02 20:01:25 +0100102 arch_spin_lock(&timebase_lock);
Olof Johanssondc559f72007-08-22 12:26:43 +1000103 set_tb(timebase >> 32, timebase & 0xffffffff);
104 timebase = 0;
Thomas Gleixner0199c4e2009-12-02 20:01:25 +0100105 arch_spin_unlock(&timebase_lock);
Olof Johanssonc388cfe2007-02-04 16:36:53 -0600106}
107
Daniel Axtens7c98bd72016-09-06 15:32:40 +1000108static struct smp_ops_t pas_smp_ops = {
Olof Johansson1e768752006-09-06 14:42:08 -0500109 .probe = smp_mpic_probe,
110 .message_pass = smp_mpic_message_pass,
111 .kick_cpu = smp_generic_kick_cpu,
112 .setup_cpu = smp_mpic_setup_cpu,
Olof Johanssonc388cfe2007-02-04 16:36:53 -0600113 .give_timebase = pas_give_timebase,
114 .take_timebase = pas_take_timebase,
Olof Johansson1e768752006-09-06 14:42:08 -0500115};
116#endif /* CONFIG_SMP */
117
Daniel Axtens7c98bd72016-09-06 15:32:40 +1000118static void __init pas_setup_arch(void)
Olof Johansson1e768752006-09-06 14:42:08 -0500119{
120#ifdef CONFIG_SMP
121 /* Setup SMP callback */
122 smp_ops = &pas_smp_ops;
123#endif
124 /* Lookup PCI hosts */
125 pas_pci_init();
126
127#ifdef CONFIG_DUMMY_CONSOLE
128 conswitchp = &dummy_con;
129#endif
130
Olof Johanssonf620be92007-02-04 16:36:52 -0600131 /* Remap SDC register for doing reset */
132 /* XXXOJN This should maybe come out of the device tree */
133 reset_reg = ioremap(0xfc101100, 4);
Olof Johansson1e768752006-09-06 14:42:08 -0500134}
135
Olof Johanssoncd783412007-09-05 12:09:23 +1000136static int __init pas_setup_mce_regs(void)
137{
138 struct pci_dev *dev;
139 int reg;
140
Olof Johanssoncd783412007-09-05 12:09:23 +1000141 /* Remap various SoC status registers for use by the MCE handler */
142
143 reg = 0;
144
145 dev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa00a, NULL);
146 while (dev && reg < MAX_MCE_REGS) {
147 mce_regs[reg].name = kasprintf(GFP_KERNEL,
148 "mc%d_mcdebug_errsta", reg);
149 mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0x730);
150 dev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa00a, dev);
151 reg++;
152 }
153
154 dev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa001, NULL);
155 if (dev && reg+4 < MAX_MCE_REGS) {
156 mce_regs[reg].name = "iobdbg_IntStatus1";
157 mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0x438);
158 reg++;
159 mce_regs[reg].name = "iobdbg_IOCTbusIntDbgReg";
160 mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0x454);
161 reg++;
162 mce_regs[reg].name = "iobiom_IntStatus";
163 mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0xc10);
164 reg++;
165 mce_regs[reg].name = "iobiom_IntDbgReg";
166 mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0xc1c);
167 reg++;
168 }
169
170 dev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa009, NULL);
171 if (dev && reg+2 < MAX_MCE_REGS) {
172 mce_regs[reg].name = "l2csts_IntStatus";
173 mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0x200);
174 reg++;
175 mce_regs[reg].name = "l2csts_Cnt";
176 mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0x214);
177 reg++;
178 }
179
180 num_mce_regs = reg;
181
182 return 0;
183}
Grant Likelybdddec42008-01-02 12:32:28 -0700184machine_device_initcall(pasemi, pas_setup_mce_regs);
Olof Johanssoncd783412007-09-05 12:09:23 +1000185
Olof Johansson1e768752006-09-06 14:42:08 -0500186static __init void pas_init_IRQ(void)
187{
188 struct device_node *np;
189 struct device_node *root, *mpic_node;
190 unsigned long openpic_addr;
191 const unsigned int *opprop;
192 int naddr, opplen;
Olof Johanssonf3653552007-12-20 13:11:18 -0600193 int mpic_flags;
194 const unsigned int *nmiprop;
Olof Johansson1e768752006-09-06 14:42:08 -0500195 struct mpic *mpic;
196
197 mpic_node = NULL;
198
199 for_each_node_by_type(np, "interrupt-controller")
Stephen Rothwell55b61fe2007-05-03 17:26:52 +1000200 if (of_device_is_compatible(np, "open-pic")) {
Olof Johansson1e768752006-09-06 14:42:08 -0500201 mpic_node = np;
202 break;
203 }
204 if (!mpic_node)
205 for_each_node_by_type(np, "open-pic") {
206 mpic_node = np;
207 break;
208 }
209 if (!mpic_node) {
210 printk(KERN_ERR
211 "Failed to locate the MPIC interrupt controller\n");
212 return;
213 }
214
215 /* Find address list in /platform-open-pic */
216 root = of_find_node_by_path("/");
Stephen Rothwella8bda5d2007-04-03 10:56:50 +1000217 naddr = of_n_addr_cells(root);
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000218 opprop = of_get_property(root, "platform-open-pic", &opplen);
Olof Johansson1e768752006-09-06 14:42:08 -0500219 if (!opprop) {
220 printk(KERN_ERR "No platform-open-pic property.\n");
221 of_node_put(root);
222 return;
223 }
224 openpic_addr = of_read_number(opprop, naddr);
225 printk(KERN_DEBUG "OpenPIC addr: %lx\n", openpic_addr);
Olof Johansson1e768752006-09-06 14:42:08 -0500226
Kyle Moffette55d7f72011-12-22 10:19:14 +0000227 mpic_flags = MPIC_LARGE_VECTORS | MPIC_NO_BIAS | MPIC_NO_RESET;
Olof Johanssonf3653552007-12-20 13:11:18 -0600228
229 nmiprop = of_get_property(mpic_node, "nmi-source", NULL);
230 if (nmiprop)
231 mpic_flags |= MPIC_ENABLE_MCK;
232
Olof Johansson7df24572007-01-28 23:33:18 -0600233 mpic = mpic_alloc(mpic_node, openpic_addr,
Olof Johanssonf3653552007-12-20 13:11:18 -0600234 mpic_flags, 0, 0, "PASEMI-OPIC");
Olof Johansson1e768752006-09-06 14:42:08 -0500235 BUG_ON(!mpic);
236
Kyle Moffette7a98672011-12-02 06:28:01 +0000237 mpic_assign_isu(mpic, 0, mpic->paddr + 0x10000);
Olof Johansson1e768752006-09-06 14:42:08 -0500238 mpic_init(mpic);
Olof Johanssonf3653552007-12-20 13:11:18 -0600239 /* The NMI/MCK source needs to be prio 15 */
240 if (nmiprop) {
241 nmi_virq = irq_create_mapping(NULL, *nmiprop);
242 mpic_irq_set_priority(nmi_virq, 15);
Thomas Gleixnerec775d02011-03-25 16:45:20 +0100243 irq_set_irq_type(nmi_virq, IRQ_TYPE_EDGE_RISING);
Lennert Buytenhek835c05532011-03-08 22:26:43 +0000244 mpic_unmask_irq(irq_get_irq_data(nmi_virq));
Olof Johanssonf3653552007-12-20 13:11:18 -0600245 }
246
Olof Johansson1e768752006-09-06 14:42:08 -0500247 of_node_put(mpic_node);
248 of_node_put(root);
249}
250
251static void __init pas_progress(char *s, unsigned short hex)
252{
253 printk("[%04x] : %s\n", hex, s ? s : "");
254}
255
256
Olof Johanssonbfed9d32007-02-04 16:36:50 -0600257static int pas_machine_check_handler(struct pt_regs *regs)
258{
259 int cpu = smp_processor_id();
260 unsigned long srr0, srr1, dsisr;
Olof Johanssoncd783412007-09-05 12:09:23 +1000261 int dump_slb = 0;
262 int i;
Olof Johanssonbfed9d32007-02-04 16:36:50 -0600263
264 srr0 = regs->nip;
265 srr1 = regs->msr;
Olof Johanssonf3653552007-12-20 13:11:18 -0600266
Olof Johanssonf0d45772008-01-02 12:35:50 -0600267 if (nmi_virq != NO_IRQ && mpic_get_mcirq() == nmi_virq) {
Olof Johanssonf3653552007-12-20 13:11:18 -0600268 printk(KERN_ERR "NMI delivered\n");
269 debugger(regs);
Lennert Buytenhek835c05532011-03-08 22:26:43 +0000270 mpic_end_irq(irq_get_irq_data(nmi_virq));
Olof Johanssonf3653552007-12-20 13:11:18 -0600271 goto out;
272 }
273
Olof Johanssonbfed9d32007-02-04 16:36:50 -0600274 dsisr = mfspr(SPRN_DSISR);
275 printk(KERN_ERR "Machine Check on CPU %d\n", cpu);
Olof Johanssoncd783412007-09-05 12:09:23 +1000276 printk(KERN_ERR "SRR0 0x%016lx SRR1 0x%016lx\n", srr0, srr1);
277 printk(KERN_ERR "DSISR 0x%016lx DAR 0x%016lx\n", dsisr, regs->dar);
278 printk(KERN_ERR "BER 0x%016lx MER 0x%016lx\n", mfspr(SPRN_PA6T_BER),
279 mfspr(SPRN_PA6T_MER));
280 printk(KERN_ERR "IER 0x%016lx DER 0x%016lx\n", mfspr(SPRN_PA6T_IER),
281 mfspr(SPRN_PA6T_DER));
Olof Johanssonbfed9d32007-02-04 16:36:50 -0600282 printk(KERN_ERR "Cause:\n");
283
284 if (srr1 & 0x200000)
285 printk(KERN_ERR "Signalled by SDC\n");
Olof Johanssoncd783412007-09-05 12:09:23 +1000286
Olof Johanssonbfed9d32007-02-04 16:36:50 -0600287 if (srr1 & 0x100000) {
288 printk(KERN_ERR "Load/Store detected error:\n");
289 if (dsisr & 0x8000)
290 printk(KERN_ERR "D-cache ECC double-bit error or bus error\n");
291 if (dsisr & 0x4000)
292 printk(KERN_ERR "LSU snoop response error\n");
Olof Johanssoncd783412007-09-05 12:09:23 +1000293 if (dsisr & 0x2000) {
Olof Johanssonbfed9d32007-02-04 16:36:50 -0600294 printk(KERN_ERR "MMU SLB multi-hit or invalid B field\n");
Olof Johanssoncd783412007-09-05 12:09:23 +1000295 dump_slb = 1;
296 }
Olof Johanssonbfed9d32007-02-04 16:36:50 -0600297 if (dsisr & 0x1000)
298 printk(KERN_ERR "Recoverable Duptags\n");
299 if (dsisr & 0x800)
300 printk(KERN_ERR "Recoverable D-cache parity error count overflow\n");
301 if (dsisr & 0x400)
302 printk(KERN_ERR "TLB parity error count overflow\n");
303 }
Olof Johanssoncd783412007-09-05 12:09:23 +1000304
Olof Johanssonbfed9d32007-02-04 16:36:50 -0600305 if (srr1 & 0x80000)
306 printk(KERN_ERR "Bus Error\n");
Olof Johanssoncd783412007-09-05 12:09:23 +1000307
308 if (srr1 & 0x40000) {
Olof Johanssonbfed9d32007-02-04 16:36:50 -0600309 printk(KERN_ERR "I-side SLB multiple hit\n");
Olof Johanssoncd783412007-09-05 12:09:23 +1000310 dump_slb = 1;
311 }
312
Olof Johanssonbfed9d32007-02-04 16:36:50 -0600313 if (srr1 & 0x20000)
314 printk(KERN_ERR "I-cache parity error hit\n");
315
Olof Johanssoncd783412007-09-05 12:09:23 +1000316 if (num_mce_regs == 0)
317 printk(KERN_ERR "No MCE registers mapped yet, can't dump\n");
318 else
319 printk(KERN_ERR "SoC debug registers:\n");
320
321 for (i = 0; i < num_mce_regs; i++)
322 printk(KERN_ERR "%s: 0x%08x\n", mce_regs[i].name,
323 in_le32(mce_regs[i].addr));
324
325 if (dump_slb) {
326 unsigned long e, v;
327 int i;
328
329 printk(KERN_ERR "slb contents:\n");
Michael Neuling584f8b72007-12-06 17:24:48 +1100330 for (i = 0; i < mmu_slb_size; i++) {
Olof Johanssoncd783412007-09-05 12:09:23 +1000331 asm volatile("slbmfee %0,%1" : "=r" (e) : "r" (i));
332 asm volatile("slbmfev %0,%1" : "=r" (v) : "r" (i));
333 printk(KERN_ERR "%02d %016lx %016lx\n", i, e, v);
334 }
335 }
336
Olof Johanssonf3653552007-12-20 13:11:18 -0600337out:
Olof Johanssonbfed9d32007-02-04 16:36:50 -0600338 /* SRR1[62] is from MSR[62] if recoverable, so pass that back */
339 return !!(srr1 & 0x2);
340}
341
Olof Johansson2b571a02007-10-16 23:26:20 -0700342#ifdef CONFIG_PCMCIA
343static int pcmcia_notify(struct notifier_block *nb, unsigned long action,
344 void *data)
345{
346 struct device *dev = data;
347 struct device *parent;
348 struct pcmcia_device *pdev = to_pcmcia_dev(dev);
349
350 /* We are only intereted in device addition */
351 if (action != BUS_NOTIFY_ADD_DEVICE)
352 return 0;
353
354 parent = pdev->socket->dev.parent;
355
356 /* We know electra_cf devices will always have of_node set, since
357 * electra_cf is an of_platform driver.
358 */
Grant Likely58f9b0b2010-04-13 16:12:56 -0700359 if (!parent->of_node)
Olof Johansson2b571a02007-10-16 23:26:20 -0700360 return 0;
361
Grant Likely58f9b0b2010-04-13 16:12:56 -0700362 if (!of_device_is_compatible(parent->of_node, "electra-cf"))
Olof Johansson2b571a02007-10-16 23:26:20 -0700363 return 0;
364
365 /* We use the direct ops for localbus */
366 dev->archdata.dma_ops = &dma_direct_ops;
367
368 return 0;
369}
370
371static struct notifier_block pcmcia_notifier = {
372 .notifier_call = pcmcia_notify,
373};
374
375static inline void pasemi_pcmcia_init(void)
376{
377 extern struct bus_type pcmcia_bus_type;
378
379 bus_register_notifier(&pcmcia_bus_type, &pcmcia_notifier);
380}
381
382#else
383
384static inline void pasemi_pcmcia_init(void)
385{
386}
387
388#endif
389
390
Uwe Kleine-Königce6d73c2014-09-10 21:56:38 +0200391static const struct of_device_id pasemi_bus_ids[] = {
Olof Johansson0d08a842007-11-04 20:57:45 -0600392 /* Unfortunately needed for legacy firmwares */
Olof Johansson2b571a02007-10-16 23:26:20 -0700393 { .type = "localbus", },
Olof Johanssonb97d2792007-04-18 16:39:54 +1000394 { .type = "sdc", },
Olof Johansson0d08a842007-11-04 20:57:45 -0600395 /* These are the proper entries, which newer firmware uses */
396 { .compatible = "pasemi,localbus", },
397 { .compatible = "pasemi,sdc", },
Olof Johanssonb97d2792007-04-18 16:39:54 +1000398 {},
399};
400
401static int __init pasemi_publish_devices(void)
402{
Olof Johansson2b571a02007-10-16 23:26:20 -0700403 pasemi_pcmcia_init();
404
Olof Johansson90f7afe2007-05-01 14:43:39 +1000405 /* Publish OF platform devices for SDC and other non-PCI devices */
Olof Johanssonb97d2792007-04-18 16:39:54 +1000406 of_platform_bus_probe(NULL, pasemi_bus_ids, NULL);
407
408 return 0;
409}
Grant Likelybdddec42008-01-02 12:32:28 -0700410machine_device_initcall(pasemi, pasemi_publish_devices);
Olof Johanssonb97d2792007-04-18 16:39:54 +1000411
Olof Johanssonbfed9d32007-02-04 16:36:50 -0600412
Olof Johansson1e768752006-09-06 14:42:08 -0500413/*
414 * Called very early, MMU is off, device-tree isn't unflattened
415 */
416static int __init pas_probe(void)
417{
Benjamin Herrenschmidt406b0b62016-07-05 15:04:00 +1000418 if (!of_machine_is_compatible("PA6T-1682M") &&
419 !of_machine_is_compatible("pasemi,pwrficient"))
Olof Johansson1e768752006-09-06 14:42:08 -0500420 return 0;
421
Benjamin Herrenschmidtf2d57692016-07-05 15:04:06 +1000422 iommu_init_early_pasemi();
423
Olof Johansson1e768752006-09-06 14:42:08 -0500424 return 1;
425}
426
Olof Johanssond4875a22007-07-06 00:49:04 +1000427define_machine(pasemi) {
Olof Johansson0d08a842007-11-04 20:57:45 -0600428 .name = "PA Semi PWRficient",
Olof Johansson1e768752006-09-06 14:42:08 -0500429 .probe = pas_probe,
430 .setup_arch = pas_setup_arch,
Olof Johansson1e768752006-09-06 14:42:08 -0500431 .init_IRQ = pas_init_IRQ,
432 .get_irq = mpic_get_irq,
Olof Johansson1e768752006-09-06 14:42:08 -0500433 .restart = pas_restart,
Olof Johansson1e768752006-09-06 14:42:08 -0500434 .get_boot_time = pas_get_boot_time,
435 .calibrate_decr = generic_calibrate_decr,
Olof Johansson1e768752006-09-06 14:42:08 -0500436 .progress = pas_progress,
Olof Johanssonbfed9d32007-02-04 16:36:50 -0600437 .machine_check_exception = pas_machine_check_handler,
Olof Johansson1e768752006-09-06 14:42:08 -0500438};