setup.c 9.6 KB
Newer Older
L
Linus Torvalds 已提交
1
/*
2
 *  Maple (970 eval board) setup code
L
Linus Torvalds 已提交
3 4 5 6 7 8 9 10 11 12 13
 *
 *  (c) Copyright 2004 Benjamin Herrenschmidt (benh@kernel.crashing.org),
 *                     IBM Corp. 
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License
 *  as published by the Free Software Foundation; either version
 *  2 of the License, or (at your option) any later version.
 *
 */

14
#undef DEBUG
L
Linus Torvalds 已提交
15 16 17 18 19

#include <linux/init.h>
#include <linux/errno.h>
#include <linux/sched.h>
#include <linux/kernel.h>
20
#include <linux/export.h>
L
Linus Torvalds 已提交
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
#include <linux/mm.h>
#include <linux/stddef.h>
#include <linux/unistd.h>
#include <linux/ptrace.h>
#include <linux/user.h>
#include <linux/tty.h>
#include <linux/string.h>
#include <linux/delay.h>
#include <linux/ioport.h>
#include <linux/major.h>
#include <linux/initrd.h>
#include <linux/vt_kern.h>
#include <linux/console.h>
#include <linux/pci.h>
#include <linux/adb.h>
#include <linux/cuda.h>
#include <linux/pmu.h>
#include <linux/irq.h>
#include <linux/seq_file.h>
#include <linux/root_dev.h>
#include <linux/serial.h>
#include <linux/smp.h>
J
Jiri Slaby 已提交
43
#include <linux/bitops.h>
44
#include <linux/of_device.h>
Y
Yinghai Lu 已提交
45
#include <linux/memblock.h>
L
Linus Torvalds 已提交
46 47 48 49 50 51 52 53 54 55 56 57

#include <asm/processor.h>
#include <asm/sections.h>
#include <asm/prom.h>
#include <asm/pgtable.h>
#include <asm/io.h>
#include <asm/pci-bridge.h>
#include <asm/iommu.h>
#include <asm/machdep.h>
#include <asm/dma.h>
#include <asm/cputable.h>
#include <asm/time.h>
58
#include <asm/mpic.h>
59
#include <asm/rtas.h>
60
#include <asm/udbg.h>
N
Nathan Lynch 已提交
61
#include <asm/nvram.h>
L
Linus Torvalds 已提交
62

63 64
#include "maple.h"

L
Linus Torvalds 已提交
65 66 67 68 69 70
#ifdef DEBUG
#define DBG(fmt...) udbg_printf(fmt)
#else
#define DBG(fmt...)
#endif

71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
static unsigned long maple_find_nvram_base(void)
{
	struct device_node *rtcs;
	unsigned long result = 0;

	/* find NVRAM device */
	rtcs = of_find_compatible_node(NULL, "nvram", "AMD8111");
	if (rtcs) {
		struct resource r;
		if (of_address_to_resource(rtcs, 0, &r)) {
			printk(KERN_EMERG "Maple: Unable to translate NVRAM"
			       " address\n");
			goto bail;
		}
		if (!(r.flags & IORESOURCE_IO)) {
			printk(KERN_EMERG "Maple: NVRAM address isn't PIO!\n");
			goto bail;
		}
		result = r.start;
	} else
		printk(KERN_EMERG "Maple: Unable to find NVRAM\n");
 bail:
	of_node_put(rtcs);
	return result;
}

L
Linus Torvalds 已提交
97 98
static void maple_restart(char *cmd)
{
D
David Gibson 已提交
99
	unsigned int maple_nvram_base;
100
	const unsigned int *maple_nvram_offset, *maple_nvram_command;
101
	struct device_node *sp;
D
David Gibson 已提交
102

103 104 105
	maple_nvram_base = maple_find_nvram_base();
	if (maple_nvram_base == 0)
		goto fail;
D
David Gibson 已提交
106 107

	/* find service processor device */
108 109
	sp = of_find_node_by_name(NULL, "service-processor");
	if (!sp) {
D
David Gibson 已提交
110
		printk(KERN_EMERG "Maple: Unable to find Service Processor\n");
111
		goto fail;
D
David Gibson 已提交
112
	}
113 114
	maple_nvram_offset = of_get_property(sp, "restart-addr", NULL);
	maple_nvram_command = of_get_property(sp, "restart-value", NULL);
115
	of_node_put(sp);
D
David Gibson 已提交
116 117

	/* send command */
118
	outb_p(*maple_nvram_command, maple_nvram_base + *maple_nvram_offset);
D
David Gibson 已提交
119
	for (;;) ;
120 121
 fail:
	printk(KERN_EMERG "Maple: Manual Restart Required\n");
L
Linus Torvalds 已提交
122 123 124 125
}

static void maple_power_off(void)
{
D
David Gibson 已提交
126
	unsigned int maple_nvram_base;
127
	const unsigned int *maple_nvram_offset, *maple_nvram_command;
128
	struct device_node *sp;
D
David Gibson 已提交
129

130 131 132
	maple_nvram_base = maple_find_nvram_base();
	if (maple_nvram_base == 0)
		goto fail;
D
David Gibson 已提交
133 134

	/* find service processor device */
135 136
	sp = of_find_node_by_name(NULL, "service-processor");
	if (!sp) {
D
David Gibson 已提交
137
		printk(KERN_EMERG "Maple: Unable to find Service Processor\n");
138
		goto fail;
D
David Gibson 已提交
139
	}
140 141
	maple_nvram_offset = of_get_property(sp, "power-off-addr", NULL);
	maple_nvram_command = of_get_property(sp, "power-off-value", NULL);
142
	of_node_put(sp);
D
David Gibson 已提交
143 144

	/* send command */
145
	outb_p(*maple_nvram_command, maple_nvram_base + *maple_nvram_offset);
D
David Gibson 已提交
146
	for (;;) ;
147 148
 fail:
	printk(KERN_EMERG "Maple: Manual Power-Down Required\n");
L
Linus Torvalds 已提交
149 150 151 152
}

static void maple_halt(void)
{
D
David Gibson 已提交
153
	maple_power_off();
L
Linus Torvalds 已提交
154 155 156 157 158 159 160 161 162 163 164 165 166
}

#ifdef CONFIG_SMP
struct smp_ops_t maple_smp_ops = {
	.probe		= smp_mpic_probe,
	.message_pass	= smp_mpic_message_pass,
	.kick_cpu	= smp_generic_kick_cpu,
	.setup_cpu	= smp_mpic_setup_cpu,
	.give_timebase	= smp_generic_give_timebase,
	.take_timebase	= smp_generic_take_timebase,
};
#endif /* CONFIG_SMP */

167 168 169 170 171
static void __init maple_use_rtas_reboot_and_halt_if_present(void)
{
	if (rtas_service_present("system-reboot") &&
	    rtas_service_present("power-off")) {
		ppc_md.restart = rtas_restart;
172
		pm_power_off = rtas_power_off;
173 174 175 176
		ppc_md.halt = rtas_halt;
	}
}

L
Linus Torvalds 已提交
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
void __init maple_setup_arch(void)
{
	/* init to some ~sane value until calibrate_delay() runs */
	loops_per_jiffy = 50000000;

	/* Setup SMP callback */
#ifdef CONFIG_SMP
	smp_ops = &maple_smp_ops;
#endif
	/* Lookup PCI hosts */
       	maple_pci_init();

#ifdef CONFIG_DUMMY_CONSOLE
	conswitchp = &dummy_con;
#endif
192
	maple_use_rtas_reboot_and_halt_if_present();
193

194
	printk(KERN_DEBUG "Using native/NAP idle loop\n");
N
Nathan Lynch 已提交
195 196

	mmio_nvram_init();
L
Linus Torvalds 已提交
197 198 199 200 201 202 203 204 205
}

/* 
 * Early initialization.
 */
static void __init maple_init_early(void)
{
	DBG(" -> maple_init_early\n");

206
	iommu_init_early_dart();
L
Linus Torvalds 已提交
207 208 209 210

	DBG(" <- maple_init_early\n");
}

211 212 213 214 215 216
/*
 * This is almost identical to pSeries and CHRP. We need to make that
 * code generic at one point, with appropriate bits in the device-tree to
 * identify the presence of an HT APIC
 */
static void __init maple_init_IRQ(void)
L
Linus Torvalds 已提交
217
{
218
	struct device_node *root, *np, *mpic_node = NULL;
219
	const unsigned int *opprop;
220 221
	unsigned long openpic_addr = 0;
	int naddr, n, i, opplen, has_isus = 0;
L
Linus Torvalds 已提交
222
	struct mpic *mpic;
223
	unsigned int flags = 0;
L
Linus Torvalds 已提交
224

225 226 227 228
	/* Locate MPIC in the device-tree. Note that there is a bug
	 * in Maple device-tree where the type of the controller is
	 * open-pic and not interrupt-controller
	 */
229 230

	for_each_node_by_type(np, "interrupt-controller")
231
		if (of_device_is_compatible(np, "open-pic")) {
232 233 234 235 236 237 238 239
			mpic_node = np;
			break;
		}
	if (mpic_node == NULL)
		for_each_node_by_type(np, "open-pic") {
			mpic_node = np;
			break;
		}
240 241 242 243 244
	if (mpic_node == NULL) {
		printk(KERN_ERR
		       "Failed to locate the MPIC interrupt controller\n");
		return;
	}
L
Linus Torvalds 已提交
245

246
	/* Find address list in /platform-open-pic */
L
Linus Torvalds 已提交
247
	root = of_find_node_by_path("/");
248
	naddr = of_n_addr_cells(root);
249
	opprop = of_get_property(root, "platform-open-pic", &opplen);
250 251 252 253 254 255
	if (opprop != 0) {
		openpic_addr = of_read_number(opprop, naddr);
		has_isus = (opplen > naddr);
		printk(KERN_DEBUG "OpenPIC addr: %lx, has ISUs: %d\n",
		       openpic_addr, has_isus);
	}
L
Linus Torvalds 已提交
256

257
	BUG_ON(openpic_addr == 0);
L
Linus Torvalds 已提交
258

259
	/* Check for a big endian MPIC */
260
	if (of_get_property(np, "big-endian", NULL) != NULL)
261 262 263
		flags |= MPIC_BIG_ENDIAN;

	/* XXX Maple specific bits */
264
	flags |= MPIC_U3_HT_IRQS;
265 266
	/* All U3/U4 are big-endian, older SLOF firmware doesn't encode this */
	flags |= MPIC_BIG_ENDIAN;
267 268 269 270 271 272 273

	/* Setup the openpic driver. More device-tree junks, we hard code no
	 * ISUs for now. I'll have to revisit some stuffs with the folks doing
	 * the firmware for those
	 */
	mpic = mpic_alloc(mpic_node, openpic_addr, flags,
			  /*has_isus ? 16 :*/ 0, 0, " MPIC     ");
L
Linus Torvalds 已提交
274 275
	BUG_ON(mpic == NULL);

276 277 278 279 280 281 282 283 284 285 286 287
	/* Add ISUs */
	opplen /= sizeof(u32);
	for (n = 0, i = naddr; i < opplen; i += naddr, n++) {
		unsigned long isuaddr = of_read_number(opprop + i, naddr);
		mpic_assign_isu(mpic, n, isuaddr);
	}

	/* All ISUs are setup, complete initialization */
	mpic_init(mpic);
	ppc_md.get_irq = mpic_get_irq;
	of_node_put(mpic_node);
	of_node_put(root);
L
Linus Torvalds 已提交
288 289 290 291 292 293 294 295 296 297 298
}

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


/*
 * Called very early, MMU is off, device-tree isn't unflattened
 */
299
static int __init maple_probe(void)
L
Linus Torvalds 已提交
300
{
301
	unsigned long root = of_get_flat_dt_root();
302 303 304

	if (!of_flat_dt_is_compatible(root, "Momentum,Maple") &&
	    !of_flat_dt_is_compatible(root, "Momentum,Apache"))
L
Linus Torvalds 已提交
305 306 307 308 309 310 311
		return 0;
	/*
	 * On U3, the DART (iommu) must be allocated now since it
	 * has an impact on htab_initialize (due to the large page it
	 * occupies having to be broken up so the DART itself is not
	 * part of the cacheable linar mapping
	 */
312
	alloc_dart_table();
L
Linus Torvalds 已提交
313

314
	hpte_init_native();
315
	pm_power_off = maple_power_off;
316

L
Linus Torvalds 已提交
317 318 319
	return 1;
}

320
define_machine(maple) {
321
	.name			= "Maple",
L
Linus Torvalds 已提交
322 323 324 325
	.probe			= maple_probe,
	.setup_arch		= maple_setup_arch,
	.init_early		= maple_init_early,
	.init_IRQ		= maple_init_IRQ,
326
	.pci_irq_fixup		= maple_pci_irq_fixup,
L
Linus Torvalds 已提交
327 328 329 330 331 332
	.pci_get_legacy_ide_irq	= maple_pci_get_legacy_ide_irq,
	.restart		= maple_restart,
	.halt			= maple_halt,
       	.get_boot_time		= maple_get_boot_time,
       	.set_rtc_time		= maple_set_rtc_time,
       	.get_rtc_time		= maple_get_rtc_time,
333
      	.calibrate_decr		= generic_calibrate_decr,
L
Linus Torvalds 已提交
334
	.progress		= maple_progress,
335
	.power_save		= power4_idle,
L
Linus Torvalds 已提交
336
};
337 338 339 340

#ifdef CONFIG_EDAC
/*
 * Register a platform device for CPC925 memory controller on
341
 * all boards with U3H (CPC925) bridge.
342 343 344 345 346 347 348
 */
static int __init maple_cpc925_edac_setup(void)
{
	struct platform_device *pdev;
	struct device_node *np = NULL;
	struct resource r;
	int ret;
349 350
	volatile void __iomem *mem;
	u32 rev;
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367

	np = of_find_node_by_type(NULL, "memory-controller");
	if (!np) {
		printk(KERN_ERR "%s: Unable to find memory-controller node\n",
			__func__);
		return -ENODEV;
	}

	ret = of_address_to_resource(np, 0, &r);
	of_node_put(np);

	if (ret < 0) {
		printk(KERN_ERR "%s: Unable to get memory-controller reg\n",
			__func__);
		return -ENODEV;
	}

368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383
	mem = ioremap(r.start, resource_size(&r));
	if (!mem) {
		printk(KERN_ERR "%s: Unable to map memory-controller memory\n",
				__func__);
		return -ENOMEM;
	}

	rev = __raw_readl(mem);
	iounmap(mem);

	if (rev < 0x34 || rev > 0x3f) { /* U3H */
		printk(KERN_ERR "%s: Non-CPC925(U3H) bridge revision: %02x\n",
			__func__, rev);
		return 0;
	}

384 385 386 387 388 389 390 391 392 393
	pdev = platform_device_register_simple("cpc925_edac", 0, &r, 1);
	if (IS_ERR(pdev))
		return PTR_ERR(pdev);

	printk(KERN_INFO "%s: CPC925 platform device created\n", __func__);

	return 0;
}
machine_device_initcall(maple, maple_cpc925_edac_setup);
#endif