blob: 6761d294f2605f12fdb8528f55af4352da3429c3 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* Copyright (C) 1999,2001
2 *
3 * Author: J.E.J.Bottomley@HansenPartnership.com
4 *
5 * linux/arch/i386/kernel/voyager.c
6 *
7 * This file contains all the voyager specific routines for getting
8 * initialisation of the architecture to function. For additional
9 * features see:
10 *
11 * voyager_cat.c - Voyager CAT bus interface
12 * voyager_smp.c - Voyager SMP hal (emulates linux smp.c)
13 */
14
15#include <linux/config.h>
16#include <linux/module.h>
17#include <linux/types.h>
18#include <linux/sched.h>
19#include <linux/ptrace.h>
20#include <linux/ioport.h>
21#include <linux/interrupt.h>
22#include <linux/init.h>
23#include <linux/delay.h>
24#include <linux/reboot.h>
25#include <linux/sysrq.h>
James Bottomley8d5c8222006-02-24 13:04:10 -080026#include <linux/smp.h>
27#include <linux/nodemask.h>
28#include <asm/cpu.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <asm/io.h>
30#include <asm/voyager.h>
31#include <asm/vic.h>
32#include <linux/pm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <asm/tlbflush.h>
34#include <asm/arch_hooks.h>
Ingo Molnar306e4402005-06-30 02:58:55 -070035#include <asm/i8253.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37/*
38 * Power off function, if any
39 */
40void (*pm_power_off)(void);
James Bottomley153f8052005-07-13 09:38:05 -040041EXPORT_SYMBOL(pm_power_off);
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43int voyager_level = 0;
44
45struct voyager_SUS *voyager_SUS = NULL;
46
47#ifdef CONFIG_SMP
48static void
49voyager_dump(int dummy1, struct pt_regs *dummy2, struct tty_struct *dummy3)
50{
51 /* get here via a sysrq */
52 voyager_smp_dump();
53}
54
55static struct sysrq_key_op sysrq_voyager_dump_op = {
56 .handler = voyager_dump,
57 .help_msg = "Voyager",
58 .action_msg = "Dump Voyager Status",
59};
60#endif
61
62void
63voyager_detect(struct voyager_bios_info *bios)
64{
65 if(bios->len != 0xff) {
66 int class = (bios->class_1 << 8)
67 | (bios->class_2 & 0xff);
68
69 printk("Voyager System detected.\n"
70 " Class %x, Revision %d.%d\n",
71 class, bios->major, bios->minor);
72 if(class == VOYAGER_LEVEL4)
73 voyager_level = 4;
74 else if(class < VOYAGER_LEVEL5_AND_ABOVE)
75 voyager_level = 3;
76 else
77 voyager_level = 5;
78 printk(" Architecture Level %d\n", voyager_level);
79 if(voyager_level < 4)
80 printk("\n**WARNING**: Voyager HAL only supports Levels 4 and 5 Architectures at the moment\n\n");
81 /* install the power off handler */
82 pm_power_off = voyager_power_off;
83#ifdef CONFIG_SMP
84 register_sysrq_key('v', &sysrq_voyager_dump_op);
85#endif
86 } else {
87 printk("\n\n**WARNING**: No Voyager Subsystem Found\n");
88 }
89}
90
91void
92voyager_system_interrupt(int cpl, void *dev_id, struct pt_regs *regs)
93{
94 printk("Voyager: detected system interrupt\n");
95}
96
97/* Routine to read information from the extended CMOS area */
98__u8
99voyager_extended_cmos_read(__u16 addr)
100{
101 outb(addr & 0xff, 0x74);
102 outb((addr >> 8) & 0xff, 0x75);
103 return inb(0x76);
104}
105
106/* internal definitions for the SUS Click Map of memory */
107
108#define CLICK_ENTRIES 16
109#define CLICK_SIZE 4096 /* click to byte conversion for Length */
110
111typedef struct ClickMap {
112 struct Entry {
113 __u32 Address;
114 __u32 Length;
115 } Entry[CLICK_ENTRIES];
116} ClickMap_t;
117
118
119/* This routine is pretty much an awful hack to read the bios clickmap by
120 * mapping it into page 0. There are usually three regions in the map:
121 * Base Memory
122 * Extended Memory
123 * zero length marker for end of map
124 *
125 * Returns are 0 for failure and 1 for success on extracting region.
126 */
127int __init
128voyager_memory_detect(int region, __u32 *start, __u32 *length)
129{
130 int i;
131 int retval = 0;
132 __u8 cmos[4];
133 ClickMap_t *map;
134 unsigned long map_addr;
135 unsigned long old;
136
137 if(region >= CLICK_ENTRIES) {
138 printk("Voyager: Illegal ClickMap region %d\n", region);
139 return 0;
140 }
141
142 for(i = 0; i < sizeof(cmos); i++)
143 cmos[i] = voyager_extended_cmos_read(VOYAGER_MEMORY_CLICKMAP + i);
144
145 map_addr = *(unsigned long *)cmos;
146
147 /* steal page 0 for this */
148 old = pg0[0];
149 pg0[0] = ((map_addr & PAGE_MASK) | _PAGE_RW | _PAGE_PRESENT);
150 local_flush_tlb();
151 /* now clear everything out but page 0 */
152 map = (ClickMap_t *)(map_addr & (~PAGE_MASK));
153
154 /* zero length is the end of the clickmap */
155 if(map->Entry[region].Length != 0) {
156 *length = map->Entry[region].Length * CLICK_SIZE;
157 *start = map->Entry[region].Address;
158 retval = 1;
159 }
160
161 /* replace the mapping */
162 pg0[0] = old;
163 local_flush_tlb();
164 return retval;
165}
166
167/* voyager specific handling code for timer interrupts. Used to hand
168 * off the timer tick to the SMP code, since the VIC doesn't have an
169 * internal timer (The QIC does, but that's another story). */
170void
171voyager_timer_interrupt(struct pt_regs *regs)
172{
173 if((jiffies & 0x3ff) == 0) {
174
175 /* There seems to be something flaky in either
176 * hardware or software that is resetting the timer 0
177 * count to something much higher than it should be
178 * This seems to occur in the boot sequence, just
179 * before root is mounted. Therefore, every 10
180 * seconds or so, we sanity check the timer zero count
181 * and kick it back to where it should be.
182 *
183 * FIXME: This is the most awful hack yet seen. I
184 * should work out exactly what is interfering with
185 * the timer count settings early in the boot sequence
186 * and swiftly introduce it to something sharp and
187 * pointy. */
188 __u16 val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189
190 spin_lock(&i8253_lock);
191
192 outb_p(0x00, 0x43);
193 val = inb_p(0x40);
194 val |= inb(0x40) << 8;
195 spin_unlock(&i8253_lock);
196
197 if(val > LATCH) {
198 printk("\nVOYAGER: countdown timer value too high (%d), resetting\n\n", val);
199 spin_lock(&i8253_lock);
200 outb(0x34,0x43);
201 outb_p(LATCH & 0xff , 0x40); /* LSB */
202 outb(LATCH >> 8 , 0x40); /* MSB */
203 spin_unlock(&i8253_lock);
204 }
205 }
206#ifdef CONFIG_SMP
207 smp_vic_timer_interrupt(regs);
208#endif
209}
210
211void
212voyager_power_off(void)
213{
214 printk("VOYAGER Power Off\n");
215
216 if(voyager_level == 5) {
217 voyager_cat_power_off();
218 } else if(voyager_level == 4) {
219 /* This doesn't apparently work on most L4 machines,
220 * but the specs say to do this to get automatic power
221 * off. Unfortunately, if it doesn't power off the
222 * machine, it ends up doing a cold restart, which
223 * isn't really intended, so comment out the code */
224#if 0
225 int port;
226
227
228 /* enable the voyager Configuration Space */
229 outb((inb(VOYAGER_MC_SETUP) & 0xf0) | 0x8,
230 VOYAGER_MC_SETUP);
231 /* the port for the power off flag is an offset from the
232 floating base */
233 port = (inb(VOYAGER_SSPB_RELOCATION_PORT) << 8) + 0x21;
234 /* set the power off flag */
235 outb(inb(port) | 0x1, port);
236#endif
237 }
238 /* and wait for it to happen */
Zachary Amsdenf2ab4462005-09-03 15:56:42 -0700239 local_irq_disable();
240 for(;;)
241 halt();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242}
243
244/* copied from process.c */
245static inline void
246kb_wait(void)
247{
248 int i;
249
250 for (i=0; i<0x10000; i++)
251 if ((inb_p(0x64) & 0x02) == 0)
252 break;
253}
254
255void
Eric W. Biederman094528a2005-08-06 13:42:45 -0600256machine_shutdown(void)
257{
258 /* Architecture specific shutdown needed before a kexec */
259}
260
261void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262machine_restart(char *cmd)
263{
264 printk("Voyager Warm Restart\n");
265 kb_wait();
266
267 if(voyager_level == 5) {
268 /* write magic values to the RTC to inform system that
269 * shutdown is beginning */
270 outb(0x8f, 0x70);
271 outb(0x5 , 0x71);
272
273 udelay(50);
274 outb(0xfe,0x64); /* pull reset low */
275 } else if(voyager_level == 4) {
276 __u16 catbase = inb(VOYAGER_SSPB_RELOCATION_PORT)<<8;
277 __u8 basebd = inb(VOYAGER_MC_SETUP);
278
279 outb(basebd | 0x08, VOYAGER_MC_SETUP);
280 outb(0x02, catbase + 0x21);
281 }
Zachary Amsdenf2ab4462005-09-03 15:56:42 -0700282 local_irq_disable();
283 for(;;)
284 halt();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285}
286
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287void
James Bottomleye6cb9942005-08-05 11:59:34 -0700288machine_emergency_restart(void)
289{
290 /*for now, just hook this to a warm restart */
291 machine_restart(NULL);
292}
293
294void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295mca_nmi_hook(void)
296{
297 __u8 dumpval __attribute__((unused)) = inb(0xf823);
298 __u8 swnmi __attribute__((unused)) = inb(0xf813);
299
300 /* FIXME: assume dump switch pressed */
301 /* check to see if the dump switch was pressed */
302 VDEBUG(("VOYAGER: dumpval = 0x%x, swnmi = 0x%x\n", dumpval, swnmi));
303 /* clear swnmi */
304 outb(0xff, 0xf813);
305 /* tell SUS to ignore dump */
306 if(voyager_level == 5 && voyager_SUS != NULL) {
307 if(voyager_SUS->SUS_mbox == VOYAGER_DUMP_BUTTON_NMI) {
308 voyager_SUS->kernel_mbox = VOYAGER_NO_COMMAND;
309 voyager_SUS->kernel_flags |= VOYAGER_OS_IN_PROGRESS;
310 udelay(1000);
311 voyager_SUS->kernel_mbox = VOYAGER_IGNORE_DUMP;
312 voyager_SUS->kernel_flags &= ~VOYAGER_OS_IN_PROGRESS;
313 }
314 }
315 printk(KERN_ERR "VOYAGER: Dump switch pressed, printing CPU%d tracebacks\n", smp_processor_id());
316 show_stack(NULL, NULL);
317 show_state();
318}
319
320
321
322void
323machine_halt(void)
324{
325 /* treat a halt like a power off */
326 machine_power_off();
327}
328
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329void machine_power_off(void)
330{
331 if (pm_power_off)
332 pm_power_off();
333}
334
James Bottomley8d5c8222006-02-24 13:04:10 -0800335static struct i386_cpu cpu_devices[NR_CPUS];
336
337static int __init topology_init(void)
338{
339 int i;
340
341 for_each_present_cpu(i)
342 register_cpu(&cpu_devices[i].cpu, i, NULL);
343 return 0;
344}
345
346subsys_initcall(topology_init);