setup.c 10.7 KB
Newer Older
1
/*
O
Olof Johansson 已提交
2
 * Copyright (C) 2006-2007 PA Semi, Inc
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
 *
 * Authors: Kip Walker, PA Semi
 *	    Olof Johansson, PA Semi
 *
 * Maintained by: Olof Johansson <olof@lixom.net>
 *
 * Based on arch/powerpc/platforms/maple/setup.c
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 */

#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/delay.h>
#include <linux/console.h>
29
#include <linux/pci.h>
30
#include <linux/of_platform.h>
31 32 33 34 35 36 37 38

#include <asm/prom.h>
#include <asm/system.h>
#include <asm/iommu.h>
#include <asm/machdep.h>
#include <asm/mpic.h>
#include <asm/smp.h>
#include <asm/time.h>
39
#include <asm/mmu.h>
40

41 42 43 44
#include <pcmcia/ss.h>
#include <pcmcia/cistpl.h>
#include <pcmcia/ds.h>

45 46
#include "pasemi.h"

47
/* SDC reset register, must be pre-mapped at reset time */
48
static void __iomem *reset_reg;
49

50 51 52 53 54 55 56 57 58 59
/* Various error status registers, must be pre-mapped at MCE time */

#define MAX_MCE_REGS	32
struct mce_regs {
	char *name;
	void __iomem *addr;
};

static struct mce_regs mce_regs[MAX_MCE_REGS];
static int num_mce_regs;
60
static int nmi_virq = NO_IRQ;
61 62


63
static void pas_restart(char *cmd)
64
{
65 66 67
	/* Need to put others cpu in hold loop so they're not sleeping */
	smp_send_stop();
	udelay(10000);
68 69 70
	printk("Restarting...\n");
	while (1)
		out_le32(reset_reg, 0x6000000);
71 72 73
}

#ifdef CONFIG_SMP
74
static raw_spinlock_t timebase_lock;
75
static unsigned long timebase;
76 77 78

static void __devinit pas_give_timebase(void)
{
79 80 81 82 83
	unsigned long flags;

	local_irq_save(flags);
	hard_irq_disable();
	__raw_spin_lock(&timebase_lock);
84
	mtspr(SPRN_TBCTL, TBCTL_FREEZE);
85 86
	isync();
	timebase = get_tb();
87
	__raw_spin_unlock(&timebase_lock);
88 89 90 91

	while (timebase)
		barrier();
	mtspr(SPRN_TBCTL, TBCTL_RESTART);
92
	local_irq_restore(flags);
93 94 95 96
}

static void __devinit pas_take_timebase(void)
{
97 98 99
	while (!timebase)
		smp_rmb();

100
	__raw_spin_lock(&timebase_lock);
101 102
	set_tb(timebase >> 32, timebase & 0xffffffff);
	timebase = 0;
103
	__raw_spin_unlock(&timebase_lock);
104 105
}

106 107 108 109 110
struct smp_ops_t pas_smp_ops = {
	.probe		= smp_mpic_probe,
	.message_pass	= smp_mpic_message_pass,
	.kick_cpu	= smp_generic_kick_cpu,
	.setup_cpu	= smp_mpic_setup_cpu,
111 112
	.give_timebase	= pas_give_timebase,
	.take_timebase	= pas_take_timebase,
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
};
#endif /* CONFIG_SMP */

void __init pas_setup_arch(void)
{
#ifdef CONFIG_SMP
	/* Setup SMP callback */
	smp_ops = &pas_smp_ops;
#endif
	/* Lookup PCI hosts */
	pas_pci_init();

#ifdef CONFIG_DUMMY_CONSOLE
	conswitchp = &dummy_con;
#endif

129 130 131
	/* Remap SDC register for doing reset */
	/* XXXOJN This should maybe come out of the device tree */
	reset_reg = ioremap(0xfc101100, 4);
132 133
}

134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
static int __init pas_setup_mce_regs(void)
{
	struct pci_dev *dev;
	int reg;

	/* Remap various SoC status registers for use by the MCE handler */

	reg = 0;

	dev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa00a, NULL);
	while (dev && reg < MAX_MCE_REGS) {
		mce_regs[reg].name = kasprintf(GFP_KERNEL,
						"mc%d_mcdebug_errsta", reg);
		mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0x730);
		dev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa00a, dev);
		reg++;
	}

	dev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa001, NULL);
	if (dev && reg+4 < MAX_MCE_REGS) {
		mce_regs[reg].name = "iobdbg_IntStatus1";
		mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0x438);
		reg++;
		mce_regs[reg].name = "iobdbg_IOCTbusIntDbgReg";
		mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0x454);
		reg++;
		mce_regs[reg].name = "iobiom_IntStatus";
		mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0xc10);
		reg++;
		mce_regs[reg].name = "iobiom_IntDbgReg";
		mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0xc1c);
		reg++;
	}

	dev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa009, NULL);
	if (dev && reg+2 < MAX_MCE_REGS) {
		mce_regs[reg].name = "l2csts_IntStatus";
		mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0x200);
		reg++;
		mce_regs[reg].name = "l2csts_Cnt";
		mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0x214);
		reg++;
	}

	num_mce_regs = reg;

	return 0;
}
182
machine_device_initcall(pasemi, pas_setup_mce_regs);
183

184 185 186 187 188 189 190
static __init void pas_init_IRQ(void)
{
	struct device_node *np;
	struct device_node *root, *mpic_node;
	unsigned long openpic_addr;
	const unsigned int *opprop;
	int naddr, opplen;
191 192
	int mpic_flags;
	const unsigned int *nmiprop;
193 194 195 196 197
	struct mpic *mpic;

	mpic_node = NULL;

	for_each_node_by_type(np, "interrupt-controller")
198
		if (of_device_is_compatible(np, "open-pic")) {
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
			mpic_node = np;
			break;
		}
	if (!mpic_node)
		for_each_node_by_type(np, "open-pic") {
			mpic_node = np;
			break;
		}
	if (!mpic_node) {
		printk(KERN_ERR
			"Failed to locate the MPIC interrupt controller\n");
		return;
	}

	/* Find address list in /platform-open-pic */
	root = of_find_node_by_path("/");
215
	naddr = of_n_addr_cells(root);
216
	opprop = of_get_property(root, "platform-open-pic", &opplen);
217 218 219 220 221 222 223 224
	if (!opprop) {
		printk(KERN_ERR "No platform-open-pic property.\n");
		of_node_put(root);
		return;
	}
	openpic_addr = of_read_number(opprop, naddr);
	printk(KERN_DEBUG "OpenPIC addr: %lx\n", openpic_addr);

225
	mpic_flags = MPIC_PRIMARY | MPIC_LARGE_VECTORS | MPIC_NO_BIAS;
226 227 228 229 230

	nmiprop = of_get_property(mpic_node, "nmi-source", NULL);
	if (nmiprop)
		mpic_flags |= MPIC_ENABLE_MCK;

231
	mpic = mpic_alloc(mpic_node, openpic_addr,
232
			  mpic_flags, 0, 0, "PASEMI-OPIC");
233 234 235 236
	BUG_ON(!mpic);

	mpic_assign_isu(mpic, 0, openpic_addr + 0x10000);
	mpic_init(mpic);
237 238 239 240 241 242 243 244
	/* The NMI/MCK source needs to be prio 15 */
	if (nmiprop) {
		nmi_virq = irq_create_mapping(NULL, *nmiprop);
		mpic_irq_set_priority(nmi_virq, 15);
		set_irq_type(nmi_virq, IRQ_TYPE_EDGE_RISING);
		mpic_unmask_irq(nmi_virq);
	}

245 246 247 248 249 250 251 252 253 254
	of_node_put(mpic_node);
	of_node_put(root);
}

static void __init pas_progress(char *s, unsigned short hex)
{
	printk("[%04x] : %s\n", hex, s ? s : "");
}


255 256 257 258
static int pas_machine_check_handler(struct pt_regs *regs)
{
	int cpu = smp_processor_id();
	unsigned long srr0, srr1, dsisr;
259 260
	int dump_slb = 0;
	int i;
261 262 263

	srr0 = regs->nip;
	srr1 = regs->msr;
264

265
	if (nmi_virq != NO_IRQ && mpic_get_mcirq() == nmi_virq) {
266 267 268 269 270 271
		printk(KERN_ERR "NMI delivered\n");
		debugger(regs);
		mpic_end_irq(nmi_virq);
		goto out;
	}

272 273
	dsisr = mfspr(SPRN_DSISR);
	printk(KERN_ERR "Machine Check on CPU %d\n", cpu);
274 275 276 277 278 279
	printk(KERN_ERR "SRR0  0x%016lx SRR1 0x%016lx\n", srr0, srr1);
	printk(KERN_ERR "DSISR 0x%016lx DAR  0x%016lx\n", dsisr, regs->dar);
	printk(KERN_ERR "BER   0x%016lx MER  0x%016lx\n", mfspr(SPRN_PA6T_BER),
		mfspr(SPRN_PA6T_MER));
	printk(KERN_ERR "IER   0x%016lx DER  0x%016lx\n", mfspr(SPRN_PA6T_IER),
		mfspr(SPRN_PA6T_DER));
280 281 282 283
	printk(KERN_ERR "Cause:\n");

	if (srr1 & 0x200000)
		printk(KERN_ERR "Signalled by SDC\n");
284

285 286 287 288 289 290
	if (srr1 & 0x100000) {
		printk(KERN_ERR "Load/Store detected error:\n");
		if (dsisr & 0x8000)
			printk(KERN_ERR "D-cache ECC double-bit error or bus error\n");
		if (dsisr & 0x4000)
			printk(KERN_ERR "LSU snoop response error\n");
291
		if (dsisr & 0x2000) {
292
			printk(KERN_ERR "MMU SLB multi-hit or invalid B field\n");
293 294
			dump_slb = 1;
		}
295 296 297 298 299 300 301
		if (dsisr & 0x1000)
			printk(KERN_ERR "Recoverable Duptags\n");
		if (dsisr & 0x800)
			printk(KERN_ERR "Recoverable D-cache parity error count overflow\n");
		if (dsisr & 0x400)
			printk(KERN_ERR "TLB parity error count overflow\n");
	}
302

303 304
	if (srr1 & 0x80000)
		printk(KERN_ERR "Bus Error\n");
305 306

	if (srr1 & 0x40000) {
307
		printk(KERN_ERR "I-side SLB multiple hit\n");
308 309 310
		dump_slb = 1;
	}

311 312 313
	if (srr1 & 0x20000)
		printk(KERN_ERR "I-cache parity error hit\n");

314 315 316 317 318 319 320 321 322 323 324 325 326 327
	if (num_mce_regs == 0)
		printk(KERN_ERR "No MCE registers mapped yet, can't dump\n");
	else
		printk(KERN_ERR "SoC debug registers:\n");

	for (i = 0; i < num_mce_regs; i++)
		printk(KERN_ERR "%s: 0x%08x\n", mce_regs[i].name,
			in_le32(mce_regs[i].addr));

	if (dump_slb) {
		unsigned long e, v;
		int i;

		printk(KERN_ERR "slb contents:\n");
328
		for (i = 0; i < mmu_slb_size; i++) {
329 330 331 332 333 334
			asm volatile("slbmfee  %0,%1" : "=r" (e) : "r" (i));
			asm volatile("slbmfev  %0,%1" : "=r" (v) : "r" (i));
			printk(KERN_ERR "%02d %016lx %016lx\n", i, e, v);
		}
	}

335
out:
336 337 338 339
	/* SRR1[62] is from MSR[62] if recoverable, so pass that back */
	return !!(srr1 & 0x2);
}

O
Olof Johansson 已提交
340 341 342 343 344
static void __init pas_init_early(void)
{
	iommu_init_early_pasemi();
}

345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393
#ifdef CONFIG_PCMCIA
static int pcmcia_notify(struct notifier_block *nb, unsigned long action,
			 void *data)
{
	struct device *dev = data;
	struct device *parent;
	struct pcmcia_device *pdev = to_pcmcia_dev(dev);

	/* We are only intereted in device addition */
	if (action != BUS_NOTIFY_ADD_DEVICE)
		return 0;

	parent = pdev->socket->dev.parent;

	/* We know electra_cf devices will always have of_node set, since
	 * electra_cf is an of_platform driver.
	 */
	if (!parent->archdata.of_node)
		return 0;

	if (!of_device_is_compatible(parent->archdata.of_node, "electra-cf"))
		return 0;

	/* We use the direct ops for localbus */
	dev->archdata.dma_ops = &dma_direct_ops;

	return 0;
}

static struct notifier_block pcmcia_notifier = {
	.notifier_call = pcmcia_notify,
};

static inline void pasemi_pcmcia_init(void)
{
	extern struct bus_type pcmcia_bus_type;

	bus_register_notifier(&pcmcia_bus_type, &pcmcia_notifier);
}

#else

static inline void pasemi_pcmcia_init(void)
{
}

#endif


394
static struct of_device_id pasemi_bus_ids[] = {
395
	/* Unfortunately needed for legacy firmwares */
396
	{ .type = "localbus", },
397
	{ .type = "sdc", },
398 399 400
	/* These are the proper entries, which newer firmware uses */
	{ .compatible = "pasemi,localbus", },
	{ .compatible = "pasemi,sdc", },
401 402 403 404 405
	{},
};

static int __init pasemi_publish_devices(void)
{
406 407
	pasemi_pcmcia_init();

408
	/* Publish OF platform devices for SDC and other non-PCI devices */
409 410 411 412
	of_platform_bus_probe(NULL, pasemi_bus_ids, NULL);

	return 0;
}
413
machine_device_initcall(pasemi, pasemi_publish_devices);
414

415

416 417 418 419 420 421 422
/*
 * Called very early, MMU is off, device-tree isn't unflattened
 */
static int __init pas_probe(void)
{
	unsigned long root = of_get_flat_dt_root();

423 424
	if (!of_flat_dt_is_compatible(root, "PA6T-1682M") &&
	    !of_flat_dt_is_compatible(root, "pasemi,pwrficient"))
425 426 427 428
		return 0;

	hpte_init_native();

O
Olof Johansson 已提交
429 430
	alloc_iobmap_l2();

431 432 433
	return 1;
}

434
define_machine(pasemi) {
435
	.name			= "PA Semi PWRficient",
436 437
	.probe			= pas_probe,
	.setup_arch		= pas_setup_arch,
O
Olof Johansson 已提交
438
	.init_early		= pas_init_early,
439 440 441 442 443 444
	.init_IRQ		= pas_init_IRQ,
	.get_irq		= mpic_get_irq,
	.restart		= pas_restart,
	.get_boot_time		= pas_get_boot_time,
	.calibrate_decr		= generic_calibrate_decr,
	.progress		= pas_progress,
445
	.machine_check_exception = pas_machine_check_handler,
446
};