setup.c 15.7 KB
Newer Older
1
/*
2
 *  Powermac setup and early boot code plus other random bits.
3 4 5 6 7
 *
 *  PowerPC version
 *    Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
 *
 *  Adapted for Power Macintosh by Paul Mackerras
8
 *    Copyright (C) 1996 Paul Mackerras (paulus@samba.org)
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
 *
 *  Derived from "arch/alpha/kernel/setup.c"
 *    Copyright (C) 1995 Linus Torvalds
 *
 *  Maintained by Benjamin Herrenschmidt (benh@kernel.crashing.org)
 *
 *  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.
 *
 */

/*
 * bootup setup stuff..
 */

#include <linux/init.h>
#include <linux/errno.h>
#include <linux/sched.h>
#include <linux/kernel.h>
#include <linux/mm.h>
#include <linux/stddef.h>
#include <linux/unistd.h>
#include <linux/ptrace.h>
34
#include <linux/export.h>
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
#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/bitops.h>
#include <linux/suspend.h>
53 54
#include <linux/of_device.h>
#include <linux/of_platform.h>
Y
Yinghai Lu 已提交
55
#include <linux/memblock.h>
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71

#include <asm/reg.h>
#include <asm/sections.h>
#include <asm/prom.h>
#include <asm/pgtable.h>
#include <asm/io.h>
#include <asm/pci-bridge.h>
#include <asm/ohare.h>
#include <asm/mediabay.h>
#include <asm/machdep.h>
#include <asm/dma.h>
#include <asm/cputable.h>
#include <asm/btext.h>
#include <asm/pmac_feature.h>
#include <asm/time.h>
#include <asm/mmu_context.h>
72 73 74
#include <asm/iommu.h>
#include <asm/smu.h>
#include <asm/pmc.h>
75
#include <asm/udbg.h>
76

77
#include "pmac.h"
78 79 80 81 82 83 84

#undef SHOW_GATWICK_IRQS

int ppc_override_l2cr = 0;
int ppc_override_l2cr_value;
int has_l2cache = 0;

85
int pmac_newworld;
86

87 88
static int current_root_goodness = -1;

89
extern struct machdep_calls pmac_md;
90 91 92

#define DEFAULT_ROOT_DEVICE Root_SDA1	/* sda1 - slightly silly choice */

93 94
#ifdef CONFIG_PPC64
int sccdbg;
95 96 97
#endif

sys_ctrler_t sys_ctrler = SYS_CTRLER_UNKNOWN;
98 99 100 101 102 103
EXPORT_SYMBOL(sys_ctrler);

#ifdef CONFIG_PMAC_SMU
unsigned long smu_cmdbuf_abs;
EXPORT_SYMBOL(smu_cmdbuf_abs);
#endif
104

105
static void pmac_show_cpuinfo(struct seq_file *m)
106 107
{
	struct device_node *np;
108
	const char *pp;
109
	int plen;
110 111
	int mbmodel;
	unsigned int mbflags;
112 113
	char* mbname;

114 115 116 117 118 119
	mbmodel = pmac_call_feature(PMAC_FTR_GET_MB_INFO, NULL,
				    PMAC_MB_INFO_MODEL, 0);
	mbflags = pmac_call_feature(PMAC_FTR_GET_MB_INFO, NULL,
				    PMAC_MB_INFO_FLAGS, 0);
	if (pmac_call_feature(PMAC_FTR_GET_MB_INFO, NULL, PMAC_MB_INFO_NAME,
			      (long) &mbname) != 0)
120 121 122 123
		mbname = "Unknown";

	/* find motherboard type */
	seq_printf(m, "machine\t\t: ");
124
	np = of_find_node_by_path("/");
125
	if (np != NULL) {
126
		pp = of_get_property(np, "model", NULL);
127 128 129 130
		if (pp != NULL)
			seq_printf(m, "%s\n", pp);
		else
			seq_printf(m, "PowerMac\n");
131
		pp = of_get_property(np, "compatible", &plen);
132 133 134 135 136 137 138 139 140 141
		if (pp != NULL) {
			seq_printf(m, "motherboard\t:");
			while (plen > 0) {
				int l = strlen(pp) + 1;
				seq_printf(m, " %s", pp);
				plen -= l;
				pp += l;
			}
			seq_printf(m, "\n");
		}
142
		of_node_put(np);
143 144 145 146 147 148 149 150
	} else
		seq_printf(m, "PowerMac\n");

	/* print parsed model */
	seq_printf(m, "detected as\t: %d (%s)\n", mbmodel, mbname);
	seq_printf(m, "pmac flags\t: %08x\n", mbflags);

	/* find l2 cache info */
151 152 153 154
	np = of_find_node_by_name(NULL, "l2-cache");
	if (np == NULL)
		np = of_find_node_by_type(NULL, "cache");
	if (np != NULL) {
155 156 157 158
		const unsigned int *ic =
			of_get_property(np, "i-cache-size", NULL);
		const unsigned int *dc =
			of_get_property(np, "d-cache-size", NULL);
159 160
		seq_printf(m, "L2 cache\t:");
		has_l2cache = 1;
161
		if (of_get_property(np, "cache-unified", NULL) != 0 && dc) {
162 163 164 165 166 167 168 169
			seq_printf(m, " %dK unified", *dc / 1024);
		} else {
			if (ic)
				seq_printf(m, " %dK instruction", *ic / 1024);
			if (dc)
				seq_printf(m, "%s %dK data",
					   (ic? " +": ""), *dc / 1024);
		}
170
		pp = of_get_property(np, "ram-type", NULL);
171 172 173
		if (pp)
			seq_printf(m, " %s", pp);
		seq_printf(m, "\n");
174
		of_node_put(np);
175 176 177 178 179 180 181
	}

	/* Indicate newworld/oldworld */
	seq_printf(m, "pmac-generation\t: %s\n",
		   pmac_newworld ? "NewWorld" : "OldWorld");
}

182 183 184
#ifndef CONFIG_ADB_CUDA
int find_via_cuda(void)
{
185 186 187
	struct device_node *dn = of_find_node_by_name(NULL, "via-cuda");

	if (!dn)
188
		return 0;
189
	of_node_put(dn);
190 191 192 193 194
	printk("WARNING ! Your machine is CUDA-based but your kernel\n");
	printk("          wasn't compiled with CONFIG_ADB_CUDA option !\n");
	return 0;
}
#endif
195

196 197
#ifndef CONFIG_ADB_PMU
int find_via_pmu(void)
198
{
199 200 201
	struct device_node *dn = of_find_node_by_name(NULL, "via-pmu");

	if (!dn)
202
		return 0;
203
	of_node_put(dn);
204 205
	printk("WARNING ! Your machine is PMU-based but your kernel\n");
	printk("          wasn't compiled with CONFIG_ADB_PMU option !\n");
P
Paul Mackerras 已提交
206
	return 0;
207 208
}
#endif
209

210 211 212 213 214 215 216
#ifndef CONFIG_PMAC_SMU
int smu_init(void)
{
	/* should check and warn if SMU is present */
	return 0;
}
#endif
217

218 219
#ifdef CONFIG_PPC32
static volatile u32 *sysctrl_regs;
220

221 222
static void __init ohare_init(void)
{
223 224
	struct device_node *dn;

225 226 227 228
	/* this area has the CPU identification register
	   and some registers used by smp boards */
	sysctrl_regs = (volatile u32 *) ioremap(0xf8000000, 0x1000);

229 230 231 232 233
	/*
	 * Turn on the L2 cache.
	 * We assume that we have a PSX memory controller iff
	 * we have an ohare I/O controller.
	 */
234 235 236
	dn = of_find_node_by_name(NULL, "ohare");
	if (dn) {
		of_node_put(dn);
237 238 239 240 241 242 243 244 245 246
		if (((sysctrl_regs[2] >> 24) & 0xf) >= 3) {
			if (sysctrl_regs[4] & 0x10)
				sysctrl_regs[4] |= 0x04000020;
			else
				sysctrl_regs[4] |= 0x04000000;
			if(has_l2cache)
				printk(KERN_INFO "Level 2 cache enabled\n");
		}
	}
}
247

248 249
static void __init l2cr_init(void)
{
250 251
	/* Checks "l2cr-value" property in the registry */
	if (cpu_has_feature(CPU_FTR_L2CR)) {
252
		struct device_node *np = of_find_node_by_name(NULL, "cpus");
253
		if (np == 0)
254
			np = of_find_node_by_type(NULL, "cpu");
255
		if (np != 0) {
256
			const unsigned int *l2cr =
257
				of_get_property(np, "l2cr-value", NULL);
258 259 260 261 262 263
			if (l2cr != 0) {
				ppc_override_l2cr = 1;
				ppc_override_l2cr_value = *l2cr;
				_set_L2CR(0);
				_set_L2CR(ppc_override_l2cr_value);
			}
264
			of_node_put(np);
265 266 267 268
		}
	}

	if (ppc_override_l2cr)
269 270 271 272
		printk(KERN_INFO "L2CR overridden (0x%x), "
		       "backside cache is %s\n",
		       ppc_override_l2cr_value,
		       (ppc_override_l2cr_value & 0x80000000)
273
				? "enabled" : "disabled");
274 275 276
}
#endif

277
static void __init pmac_setup_arch(void)
278
{
P
Paul Mackerras 已提交
279
	struct device_node *cpu, *ic;
280
	const int *fp;
281 282 283 284 285 286 287 288 289
	unsigned long pvr;

	pvr = PVR_VER(mfspr(SPRN_PVR));

	/* Set loops_per_jiffy to a half-way reasonable value,
	   for use until calibrate_delay gets called. */
	loops_per_jiffy = 50000000 / HZ;
	cpu = of_find_node_by_type(NULL, "cpu");
	if (cpu != NULL) {
290
		fp = of_get_property(cpu, "clock-frequency", NULL);
291 292 293 294 295 296 297 298 299 300 301 302 303 304
		if (fp != NULL) {
			if (pvr >= 0x30 && pvr < 0x80)
				/* PPC970 etc. */
				loops_per_jiffy = *fp / (3 * HZ);
			else if (pvr == 4 || pvr >= 8)
				/* 604, G3, G4 etc. */
				loops_per_jiffy = *fp / HZ;
			else
				/* 601, 603, etc. */
				loops_per_jiffy = *fp / (2 * HZ);
		}
		of_node_put(cpu);
	}

P
Paul Mackerras 已提交
305
	/* See if newworld or oldworld */
306
	ic = of_find_node_with_property(NULL, "interrupt-controller");
307 308
	if (ic) {
		pmac_newworld = 1;
P
Paul Mackerras 已提交
309
		of_node_put(ic);
310
	}
P
Paul Mackerras 已提交
311

312 313 314 315 316 317 318 319
	/* Lookup PCI hosts */
	pmac_pci_init();

#ifdef CONFIG_PPC32
	ohare_init();
	l2cr_init();
#endif /* CONFIG_PPC32 */

320 321
	find_via_cuda();
	find_via_pmu();
322 323
	smu_init();

324 325
#if defined(CONFIG_NVRAM) || defined(CONFIG_NVRAM_MODULE) || \
    defined(CONFIG_PPC64)
326 327
	pmac_nvram_init();
#endif
328 329

#ifdef CONFIG_PPC32
330 331 332 333 334 335
#ifdef CONFIG_BLK_DEV_INITRD
	if (initrd_start)
		ROOT_DEV = Root_RAM0;
	else
#endif
		ROOT_DEV = DEFAULT_ROOT_DEVICE;
336
#endif
337

338
#ifdef CONFIG_ADB
339
	if (strstr(boot_command_line, "adb_sync")) {
340 341 342 343
		extern int __adb_probe_sync;
		__adb_probe_sync = 1;
	}
#endif /* CONFIG_ADB */
344 345 346
}

#ifdef CONFIG_SCSI
347
void note_scsi_host(struct device_node *node, void *host)
348 349
{
}
350
EXPORT_SYMBOL(note_scsi_host);
351 352
#endif

353 354
static int initializing = 1;

355 356 357 358 359
static int pmac_late_init(void)
{
	initializing = 0;
	return 0;
}
360
machine_late_initcall(powermac, pmac_late_init);
361

362 363 364 365 366 367 368
/*
 * This is __init_refok because we check for "initializing" before
 * touching any of the __init sensitive things and "initializing"
 * will be false after __init time. This can't be __init because it
 * can be called whenever a disk is first accessed.
 */
void __init_refok note_bootable_part(dev_t dev, int part, int goodness)
369 370 371 372 373 374 375 376
{
	char *p;

	if (!initializing)
		return;
	if ((goodness <= current_root_goodness) &&
	    ROOT_DEV != DEFAULT_ROOT_DEVICE)
		return;
377 378
	p = strstr(boot_command_line, "root=");
	if (p != NULL && (p == boot_command_line || p[-1] == ' '))
379 380
		return;

381 382
	ROOT_DEV = dev + part;
	current_root_goodness = goodness;
383 384 385
}

#ifdef CONFIG_ADB_CUDA
386 387
static void cuda_restart(void)
{
388 389
	struct adb_request req;

390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420
	cuda_request(&req, NULL, 2, CUDA_PACKET, CUDA_RESET_SYSTEM);
	for (;;)
		cuda_poll();
}

static void cuda_shutdown(void)
{
	struct adb_request req;

	cuda_request(&req, NULL, 2, CUDA_PACKET, CUDA_POWERDOWN);
	for (;;)
		cuda_poll();
}

#else
#define cuda_restart()
#define cuda_shutdown()
#endif

#ifndef CONFIG_ADB_PMU
#define pmu_restart()
#define pmu_shutdown()
#endif

#ifndef CONFIG_PMAC_SMU
#define smu_restart()
#define smu_shutdown()
#endif

static void pmac_restart(char *cmd)
{
421 422
	switch (sys_ctrler) {
	case SYS_CTRLER_CUDA:
423
		cuda_restart();
424 425 426 427
		break;
	case SYS_CTRLER_PMU:
		pmu_restart();
		break;
428 429 430
	case SYS_CTRLER_SMU:
		smu_restart();
		break;
431 432 433 434
	default: ;
	}
}

435
static void pmac_power_off(void)
436 437 438
{
	switch (sys_ctrler) {
	case SYS_CTRLER_CUDA:
439
		cuda_shutdown();
440 441 442 443
		break;
	case SYS_CTRLER_PMU:
		pmu_shutdown();
		break;
444 445 446
	case SYS_CTRLER_SMU:
		smu_shutdown();
		break;
447 448 449 450 451 452 453 454 455 456
	default: ;
	}
}

static void
pmac_halt(void)
{
	pmac_power_off();
}

457 458 459 460 461
/* 
 * Early initialization.
 */
static void __init pmac_init_early(void)
{
462
	/* Enable early btext debug if requested */
463
	if (strstr(boot_command_line, "btextdbg")) {
464 465
		udbg_adb_init_early();
		register_early_udbg_console();
466 467
	}

468 469 470 471
	/* Probe motherboard chipset */
	pmac_feature_init();

	/* Initialize debug stuff */
472 473
	udbg_scc_init(!!strstr(boot_command_line, "sccdbg"));
	udbg_adb_init(!!strstr(boot_command_line, "btextdbg"));
474 475

#ifdef CONFIG_PPC64
476
	iommu_init_early_dart();
477
#endif
478 479

	/* SMP Init has to be done early as we need to patch up
480
	 * cpu_possible_mask before interrupt stacks are allocated
481 482 483 484 485
	 * or kaboom...
	 */
#ifdef CONFIG_SMP
	pmac_setup_smp();
#endif
486 487 488
}

static int __init pmac_declare_of_platform_devices(void)
489
{
490
	struct device_node *np;
491

492 493 494
	if (machine_is(chrp))
		return -1;

495
	np = of_find_node_by_name(NULL, "valkyrie");
496
	if (np) {
497
		of_platform_device_create(np, "valkyrie", NULL);
498 499
		of_node_put(np);
	}
500
	np = of_find_node_by_name(NULL, "platinum");
501
	if (np) {
502
		of_platform_device_create(np, "platinum", NULL);
503 504
		of_node_put(np);
	}
505 506 507 508 509
        np = of_find_node_by_type(NULL, "smu");
        if (np) {
		of_platform_device_create(np, "smu", NULL);
		of_node_put(np);
	}
510 511 512 513 514 515 516 517 518
	np = of_find_node_by_type(NULL, "fcu");
	if (np == NULL) {
		/* Some machines have strangely broken device-tree */
		np = of_find_node_by_path("/u3@0,f8000000/i2c@f8001000/fan@15e");
	}
	if (np) {
		of_platform_device_create(np, "temperature", NULL);
		of_node_put(np);
	}
519 520 521

	return 0;
}
522
machine_device_initcall(powermac, pmac_declare_of_platform_devices);
523

524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595
#ifdef CONFIG_SERIAL_PMACZILOG_CONSOLE
/*
 * This is called very early, as part of console_init() (typically just after
 * time_init()). This function is respondible for trying to find a good
 * default console on serial ports. It tries to match the open firmware
 * default output with one of the available serial console drivers.
 */
static int __init check_pmac_serial_console(void)
{
	struct device_node *prom_stdout = NULL;
	int offset = 0;
	const char *name;
#ifdef CONFIG_SERIAL_PMACZILOG_TTYS
	char *devname = "ttyS";
#else
	char *devname = "ttyPZ";
#endif

	pr_debug(" -> check_pmac_serial_console()\n");

	/* The user has requested a console so this is already set up. */
	if (strstr(boot_command_line, "console=")) {
		pr_debug(" console was specified !\n");
		return -EBUSY;
	}

	if (!of_chosen) {
		pr_debug(" of_chosen is NULL !\n");
		return -ENODEV;
	}

	/* We are getting a weird phandle from OF ... */
	/* ... So use the full path instead */
	name = of_get_property(of_chosen, "linux,stdout-path", NULL);
	if (name == NULL) {
		pr_debug(" no linux,stdout-path !\n");
		return -ENODEV;
	}
	prom_stdout = of_find_node_by_path(name);
	if (!prom_stdout) {
		pr_debug(" can't find stdout package %s !\n", name);
		return -ENODEV;
	}
	pr_debug("stdout is %s\n", prom_stdout->full_name);

	name = of_get_property(prom_stdout, "name", NULL);
	if (!name) {
		pr_debug(" stdout package has no name !\n");
		goto not_found;
	}

	if (strcmp(name, "ch-a") == 0)
		offset = 0;
	else if (strcmp(name, "ch-b") == 0)
		offset = 1;
	else
		goto not_found;
	of_node_put(prom_stdout);

	pr_debug("Found serial console at %s%d\n", devname, offset);

	return add_preferred_console(devname, offset, NULL);

 not_found:
	pr_debug("No preferred console found !\n");
	of_node_put(prom_stdout);
	return -ENODEV;
}
console_initcall(check_pmac_serial_console);

#endif /* CONFIG_SERIAL_PMACZILOG_CONSOLE */

596 597 598
/*
 * Called very early, MMU is off, device-tree isn't unflattened
 */
599
static int __init pmac_probe(void)
600
{
601 602 603 604
	unsigned long root = of_get_flat_dt_root();

	if (!of_flat_dt_is_compatible(root, "Power Macintosh") &&
	    !of_flat_dt_is_compatible(root, "MacRISC"))
605 606
		return 0;

607
#ifdef CONFIG_PPC64
608 609 610 611 612 613
	/*
	 * 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
	 */
614
	alloc_dart_table();
615 616

	hpte_init_native();
617 618
#endif

619 620 621 622 623 624 625
#ifdef CONFIG_PPC32
	/* isa_io_base gets set in pmac_pci_init */
	ISA_DMA_THRESHOLD = ~0L;
	DMA_MODE_READ = 1;
	DMA_MODE_WRITE = 2;
#endif /* CONFIG_PPC32 */

626 627 628 629 630 631
#ifdef CONFIG_PMAC_SMU
	/*
	 * SMU based G5s need some memory below 2Gb, at least the current
	 * driver needs that. We have to allocate it now. We allocate 4k
	 * (1 small page) for now.
	 */
Y
Yinghai Lu 已提交
632
	smu_cmdbuf_abs = memblock_alloc_base(4096, 4096, 0x80000000UL);
633 634
#endif /* CONFIG_PMAC_SMU */

635 636
	pm_power_off = pmac_power_off;

637 638 639 640
	return 1;
}

#ifdef CONFIG_PPC64
641 642
/* Move that to pci.c */
static int pmac_pci_probe_mode(struct pci_bus *bus)
643
{
644
	struct device_node *node = pci_bus_to_OF_node(bus);
645 646

	/* We need to use normal PCI probing for the AGP bus,
647
	 * since the device for the AGP bridge isn't in the tree.
648
	 * Same for the PCIe host on U4 and the HT host bridge.
649
	 */
650
	if (bus->self == NULL && (of_device_is_compatible(node, "u3-agp") ||
651 652
				  of_device_is_compatible(node, "u4-pcie") ||
				  of_device_is_compatible(node, "u3-ht")))
653 654 655
		return PCI_PROBE_NORMAL;
	return PCI_PROBE_DEVTREE;
}
656
#endif /* CONFIG_PPC64 */
657

658 659
define_machine(powermac) {
	.name			= "PowerMac",
660 661 662 663 664
	.probe			= pmac_probe,
	.setup_arch		= pmac_setup_arch,
	.init_early		= pmac_init_early,
	.show_cpuinfo		= pmac_show_cpuinfo,
	.init_IRQ		= pmac_pic_init,
665
	.get_irq		= NULL,	/* changed later */
666
	.pci_irq_fixup		= pmac_pci_irq_fixup,
667 668 669 670 671 672 673 674
	.restart		= pmac_restart,
	.halt			= pmac_halt,
	.time_init		= pmac_time_init,
	.get_boot_time		= pmac_get_boot_time,
	.set_rtc_time		= pmac_set_rtc_time,
	.get_rtc_time		= pmac_get_rtc_time,
	.calibrate_decr		= pmac_calibrate_decr,
	.feature_call		= pmac_do_feature_call,
675
	.progress		= udbg_progress,
676
#ifdef CONFIG_PPC64
677
	.pci_probe_mode		= pmac_pci_probe_mode,
678
	.power_save		= power4_idle,
679
	.enable_pmcs		= power4_enable_pmcs,
M
Michael Ellerman 已提交
680
#endif /* CONFIG_PPC64 */
681 682 683 684 685 686
#ifdef CONFIG_PPC32
	.pcibios_enable_device_hook = pmac_pci_enable_device_hook,
	.pcibios_after_init	= pmac_pcibios_after_init,
	.phys_mem_access_prot	= pci_phys_mem_access_prot,
#endif
};