setup.c 8.63 KB
Newer Older
Linus Torvalds's avatar
Linus Torvalds committed
1
/*
2
 *  Maple (970 eval board) setup code
Linus Torvalds's avatar
Linus Torvalds committed
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
Linus Torvalds's avatar
Linus Torvalds committed
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52

#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>
#include <linux/slab.h>
#include <linux/user.h>
#include <linux/a.out.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/ide.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>

#include <asm/processor.h>
#include <asm/sections.h>
#include <asm/prom.h>
#include <asm/system.h>
#include <asm/pgtable.h>
#include <asm/bitops.h>
#include <asm/io.h>
53
#include <asm/kexec.h>
Linus Torvalds's avatar
Linus Torvalds committed
54
55
56
57
58
59
60
61
#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>
#include <asm/of_device.h>
#include <asm/lmb.h>
62
#include <asm/mpic.h>
63
#include <asm/rtas.h>
64
#include <asm/udbg.h>
Nathan Lynch's avatar
Nathan Lynch committed
65
#include <asm/nvram.h>
Linus Torvalds's avatar
Linus Torvalds committed
66

67
68
#include "maple.h"

Linus Torvalds's avatar
Linus Torvalds committed
69
70
71
72
73
74
#ifdef DEBUG
#define DBG(fmt...) udbg_printf(fmt)
#else
#define DBG(fmt...)
#endif

75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
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;
}

Linus Torvalds's avatar
Linus Torvalds committed
101
102
static void maple_restart(char *cmd)
{
David Gibson's avatar
David Gibson committed
103
	unsigned int maple_nvram_base;
104
	const unsigned int *maple_nvram_offset, *maple_nvram_command;
105
	struct device_node *sp;
David Gibson's avatar
David Gibson committed
106

107
108
109
	maple_nvram_base = maple_find_nvram_base();
	if (maple_nvram_base == 0)
		goto fail;
David Gibson's avatar
David Gibson committed
110
111

	/* find service processor device */
112
113
	sp = of_find_node_by_name(NULL, "service-processor");
	if (!sp) {
David Gibson's avatar
David Gibson committed
114
		printk(KERN_EMERG "Maple: Unable to find Service Processor\n");
115
		goto fail;
David Gibson's avatar
David Gibson committed
116
	}
117
118
	maple_nvram_offset = get_property(sp, "restart-addr", NULL);
	maple_nvram_command = get_property(sp, "restart-value", NULL);
119
	of_node_put(sp);
David Gibson's avatar
David Gibson committed
120
121

	/* send command */
122
	outb_p(*maple_nvram_command, maple_nvram_base + *maple_nvram_offset);
David Gibson's avatar
David Gibson committed
123
	for (;;) ;
124
125
 fail:
	printk(KERN_EMERG "Maple: Manual Restart Required\n");
Linus Torvalds's avatar
Linus Torvalds committed
126
127
128
129
}

static void maple_power_off(void)
{
David Gibson's avatar
David Gibson committed
130
	unsigned int maple_nvram_base;
131
	const unsigned int *maple_nvram_offset, *maple_nvram_command;
132
	struct device_node *sp;
David Gibson's avatar
David Gibson committed
133

134
135
136
	maple_nvram_base = maple_find_nvram_base();
	if (maple_nvram_base == 0)
		goto fail;
David Gibson's avatar
David Gibson committed
137
138

	/* find service processor device */
139
140
	sp = of_find_node_by_name(NULL, "service-processor");
	if (!sp) {
David Gibson's avatar
David Gibson committed
141
		printk(KERN_EMERG "Maple: Unable to find Service Processor\n");
142
		goto fail;
David Gibson's avatar
David Gibson committed
143
	}
144
145
	maple_nvram_offset = get_property(sp, "power-off-addr", NULL);
	maple_nvram_command = get_property(sp, "power-off-value", NULL);
146
	of_node_put(sp);
David Gibson's avatar
David Gibson committed
147
148

	/* send command */
149
	outb_p(*maple_nvram_command, maple_nvram_base + *maple_nvram_offset);
David Gibson's avatar
David Gibson committed
150
	for (;;) ;
151
152
 fail:
	printk(KERN_EMERG "Maple: Manual Power-Down Required\n");
Linus Torvalds's avatar
Linus Torvalds committed
153
154
155
156
}

static void maple_halt(void)
{
David Gibson's avatar
David Gibson committed
157
	maple_power_off();
Linus Torvalds's avatar
Linus Torvalds committed
158
159
160
161
162
163
164
165
166
167
168
169
170
}

#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 */

171
172
173
174
175
176
177
178
179
180
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;
		ppc_md.power_off = rtas_power_off;
		ppc_md.halt = rtas_halt;
	}
}

Linus Torvalds's avatar
Linus Torvalds committed
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
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
196
	maple_use_rtas_reboot_and_halt_if_present();
197

198
	printk(KERN_DEBUG "Using native/NAP idle loop\n");
Nathan Lynch's avatar
Nathan Lynch committed
199
200

	mmio_nvram_init();
Linus Torvalds's avatar
Linus Torvalds committed
201
202
203
204
205
206
207
208
209
}

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

210
	iommu_init_early_dart();
Linus Torvalds's avatar
Linus Torvalds committed
211
212
213
214

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

215
216
217
218
219
220
/*
 * 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)
Linus Torvalds's avatar
Linus Torvalds committed
221
{
222
	struct device_node *root, *np, *mpic_node = NULL;
223
	const unsigned int *opprop;
224
225
	unsigned long openpic_addr = 0;
	int naddr, n, i, opplen, has_isus = 0;
Linus Torvalds's avatar
Linus Torvalds committed
226
	struct mpic *mpic;
227
	unsigned int flags = MPIC_PRIMARY;
Linus Torvalds's avatar
Linus Torvalds committed
228

229
230
231
232
	/* 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
	 */
233
234
235
236
237
238
239
240
241
242
243

	for_each_node_by_type(np, "interrupt-controller")
		if (device_is_compatible(np, "open-pic")) {
			mpic_node = np;
			break;
		}
	if (mpic_node == NULL)
		for_each_node_by_type(np, "open-pic") {
			mpic_node = np;
			break;
		}
244
245
246
247
248
	if (mpic_node == NULL) {
		printk(KERN_ERR
		       "Failed to locate the MPIC interrupt controller\n");
		return;
	}
Linus Torvalds's avatar
Linus Torvalds committed
249

250
	/* Find address list in /platform-open-pic */
Linus Torvalds's avatar
Linus Torvalds committed
251
	root = of_find_node_by_path("/");
252
	naddr = prom_n_addr_cells(root);
253
	opprop = get_property(root, "platform-open-pic", &opplen);
254
255
256
257
258
259
	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);
	}
Linus Torvalds's avatar
Linus Torvalds committed
260

261
	BUG_ON(openpic_addr == 0);
Linus Torvalds's avatar
Linus Torvalds committed
262

263
264
265
266
267
268
	/* Check for a big endian MPIC */
	if (get_property(np, "big-endian", NULL) != NULL)
		flags |= MPIC_BIG_ENDIAN;

	/* XXX Maple specific bits */
	flags |= MPIC_BROKEN_U3 | MPIC_WANTS_RESET;
269
270
	/* All U3/U4 are big-endian, older SLOF firmware doesn't encode this */
	flags |= MPIC_BIG_ENDIAN;
271
272
273
274
275
276
277

	/* 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     ");
Linus Torvalds's avatar
Linus Torvalds committed
278
279
	BUG_ON(mpic == NULL);

280
281
282
283
284
285
286
287
288
289
290
291
	/* 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);
Linus Torvalds's avatar
Linus Torvalds committed
292
293
294
295
296
297
298
299
300
301
302
}

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
 */
303
static int __init maple_probe(void)
Linus Torvalds's avatar
Linus Torvalds committed
304
{
305
	unsigned long root = of_get_flat_dt_root();
306
307
308

	if (!of_flat_dt_is_compatible(root, "Momentum,Maple") &&
	    !of_flat_dt_is_compatible(root, "Momentum,Apache"))
Linus Torvalds's avatar
Linus Torvalds committed
309
310
311
312
313
314
315
		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
	 */
316
	alloc_dart_table();
Linus Torvalds's avatar
Linus Torvalds committed
317

318
319
	hpte_init_native();

Linus Torvalds's avatar
Linus Torvalds committed
320
321
322
	return 1;
}

323
324
define_machine(maple_md) {
	.name			= "Maple",
Linus Torvalds's avatar
Linus Torvalds committed
325
326
327
328
	.probe			= maple_probe,
	.setup_arch		= maple_setup_arch,
	.init_early		= maple_init_early,
	.init_IRQ		= maple_init_IRQ,
329
	.pci_irq_fixup		= maple_pci_irq_fixup,
Linus Torvalds's avatar
Linus Torvalds committed
330
331
332
333
334
335
336
	.pci_get_legacy_ide_irq	= maple_pci_get_legacy_ide_irq,
	.restart		= maple_restart,
	.power_off		= maple_power_off,
	.halt			= maple_halt,
       	.get_boot_time		= maple_get_boot_time,
       	.set_rtc_time		= maple_set_rtc_time,
       	.get_rtc_time		= maple_get_rtc_time,
337
      	.calibrate_decr		= generic_calibrate_decr,
Linus Torvalds's avatar
Linus Torvalds committed
338
	.progress		= maple_progress,
339
	.power_save		= power4_idle,
340
341
342
#ifdef CONFIG_KEXEC
	.machine_kexec		= default_machine_kexec,
	.machine_kexec_prepare	= default_machine_kexec_prepare,
343
	.machine_crash_shutdown	= default_machine_crash_shutdown,
344
#endif
Linus Torvalds's avatar
Linus Torvalds committed
345
};