blob: 6a949e4edde8f17758fbb5fc9ff004eff0b4d286 [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/module.h>
16#include <linux/types.h>
17#include <linux/sched.h>
18#include <linux/ptrace.h>
19#include <linux/ioport.h>
20#include <linux/interrupt.h>
21#include <linux/init.h>
22#include <linux/delay.h>
23#include <linux/reboot.h>
24#include <linux/sysrq.h>
James Bottomley8d5c8222006-02-24 13:04:10 -080025#include <linux/smp.h>
26#include <linux/nodemask.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <asm/io.h>
28#include <asm/voyager.h>
29#include <asm/vic.h>
30#include <linux/pm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <asm/tlbflush.h>
32#include <asm/arch_hooks.h>
Ingo Molnar306e4402005-06-30 02:58:55 -070033#include <asm/i8253.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
35/*
36 * Power off function, if any
37 */
Ingo Molnara4ec1ef2008-01-30 13:30:10 +010038void (*pm_power_off) (void);
James Bottomley153f8052005-07-13 09:38:05 -040039EXPORT_SYMBOL(pm_power_off);
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
41int voyager_level = 0;
42
43struct voyager_SUS *voyager_SUS = NULL;
44
45#ifdef CONFIG_SMP
Ingo Molnara4ec1ef2008-01-30 13:30:10 +010046static void voyager_dump(int dummy1, struct tty_struct *dummy3)
Linus Torvalds1da177e2005-04-16 15:20:36 -070047{
48 /* get here via a sysrq */
49 voyager_smp_dump();
50}
51
52static struct sysrq_key_op sysrq_voyager_dump_op = {
Ingo Molnara4ec1ef2008-01-30 13:30:10 +010053 .handler = voyager_dump,
54 .help_msg = "Voyager",
55 .action_msg = "Dump Voyager Status",
Linus Torvalds1da177e2005-04-16 15:20:36 -070056};
57#endif
58
Ingo Molnara4ec1ef2008-01-30 13:30:10 +010059void voyager_detect(struct voyager_bios_info *bios)
Linus Torvalds1da177e2005-04-16 15:20:36 -070060{
Ingo Molnara4ec1ef2008-01-30 13:30:10 +010061 if (bios->len != 0xff) {
62 int class = (bios->class_1 << 8)
63 | (bios->class_2 & 0xff);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
65 printk("Voyager System detected.\n"
66 " Class %x, Revision %d.%d\n",
67 class, bios->major, bios->minor);
Ingo Molnara4ec1ef2008-01-30 13:30:10 +010068 if (class == VOYAGER_LEVEL4)
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 voyager_level = 4;
Ingo Molnara4ec1ef2008-01-30 13:30:10 +010070 else if (class < VOYAGER_LEVEL5_AND_ABOVE)
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 voyager_level = 3;
72 else
73 voyager_level = 5;
74 printk(" Architecture Level %d\n", voyager_level);
Ingo Molnara4ec1ef2008-01-30 13:30:10 +010075 if (voyager_level < 4)
76 printk
77 ("\n**WARNING**: Voyager HAL only supports Levels 4 and 5 Architectures at the moment\n\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 /* install the power off handler */
79 pm_power_off = voyager_power_off;
80#ifdef CONFIG_SMP
81 register_sysrq_key('v', &sysrq_voyager_dump_op);
82#endif
83 } else {
84 printk("\n\n**WARNING**: No Voyager Subsystem Found\n");
85 }
86}
87
Ingo Molnara4ec1ef2008-01-30 13:30:10 +010088void voyager_system_interrupt(int cpl, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070089{
90 printk("Voyager: detected system interrupt\n");
91}
92
93/* Routine to read information from the extended CMOS area */
Ingo Molnara4ec1ef2008-01-30 13:30:10 +010094__u8 voyager_extended_cmos_read(__u16 addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070095{
96 outb(addr & 0xff, 0x74);
97 outb((addr >> 8) & 0xff, 0x75);
98 return inb(0x76);
99}
100
101/* internal definitions for the SUS Click Map of memory */
102
103#define CLICK_ENTRIES 16
104#define CLICK_SIZE 4096 /* click to byte conversion for Length */
105
106typedef struct ClickMap {
107 struct Entry {
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100108 __u32 Address;
109 __u32 Length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 } Entry[CLICK_ENTRIES];
111} ClickMap_t;
112
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113/* This routine is pretty much an awful hack to read the bios clickmap by
114 * mapping it into page 0. There are usually three regions in the map:
115 * Base Memory
116 * Extended Memory
117 * zero length marker for end of map
118 *
119 * Returns are 0 for failure and 1 for success on extracting region.
120 */
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100121int __init voyager_memory_detect(int region, __u32 * start, __u32 * length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122{
123 int i;
124 int retval = 0;
125 __u8 cmos[4];
126 ClickMap_t *map;
127 unsigned long map_addr;
128 unsigned long old;
129
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100130 if (region >= CLICK_ENTRIES) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 printk("Voyager: Illegal ClickMap region %d\n", region);
132 return 0;
133 }
134
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100135 for (i = 0; i < sizeof(cmos); i++)
136 cmos[i] =
137 voyager_extended_cmos_read(VOYAGER_MEMORY_CLICKMAP + i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
139 map_addr = *(unsigned long *)cmos;
140
141 /* steal page 0 for this */
142 old = pg0[0];
143 pg0[0] = ((map_addr & PAGE_MASK) | _PAGE_RW | _PAGE_PRESENT);
144 local_flush_tlb();
145 /* now clear everything out but page 0 */
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100146 map = (ClickMap_t *) (map_addr & (~PAGE_MASK));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
148 /* zero length is the end of the clickmap */
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100149 if (map->Entry[region].Length != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 *length = map->Entry[region].Length * CLICK_SIZE;
151 *start = map->Entry[region].Address;
152 retval = 1;
153 }
154
155 /* replace the mapping */
156 pg0[0] = old;
157 local_flush_tlb();
158 return retval;
159}
160
161/* voyager specific handling code for timer interrupts. Used to hand
162 * off the timer tick to the SMP code, since the VIC doesn't have an
163 * internal timer (The QIC does, but that's another story). */
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100164void voyager_timer_interrupt(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165{
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100166 if ((jiffies & 0x3ff) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167
168 /* There seems to be something flaky in either
169 * hardware or software that is resetting the timer 0
170 * count to something much higher than it should be
171 * This seems to occur in the boot sequence, just
172 * before root is mounted. Therefore, every 10
173 * seconds or so, we sanity check the timer zero count
174 * and kick it back to where it should be.
175 *
176 * FIXME: This is the most awful hack yet seen. I
177 * should work out exactly what is interfering with
178 * the timer count settings early in the boot sequence
179 * and swiftly introduce it to something sharp and
180 * pointy. */
181 __u16 val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
183 spin_lock(&i8253_lock);
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100184
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 outb_p(0x00, 0x43);
186 val = inb_p(0x40);
187 val |= inb(0x40) << 8;
188 spin_unlock(&i8253_lock);
189
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100190 if (val > LATCH) {
191 printk
192 ("\nVOYAGER: countdown timer value too high (%d), resetting\n\n",
193 val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 spin_lock(&i8253_lock);
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100195 outb(0x34, 0x43);
196 outb_p(LATCH & 0xff, 0x40); /* LSB */
197 outb(LATCH >> 8, 0x40); /* MSB */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 spin_unlock(&i8253_lock);
199 }
200 }
201#ifdef CONFIG_SMP
James Bottomley81c06b12006-10-12 22:25:03 -0500202 smp_vic_timer_interrupt();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203#endif
204}
205
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100206void voyager_power_off(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207{
208 printk("VOYAGER Power Off\n");
209
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100210 if (voyager_level == 5) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 voyager_cat_power_off();
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100212 } else if (voyager_level == 4) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 /* This doesn't apparently work on most L4 machines,
214 * but the specs say to do this to get automatic power
215 * off. Unfortunately, if it doesn't power off the
216 * machine, it ends up doing a cold restart, which
217 * isn't really intended, so comment out the code */
218#if 0
219 int port;
220
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 /* enable the voyager Configuration Space */
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100222 outb((inb(VOYAGER_MC_SETUP) & 0xf0) | 0x8, VOYAGER_MC_SETUP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 /* the port for the power off flag is an offset from the
224 floating base */
225 port = (inb(VOYAGER_SSPB_RELOCATION_PORT) << 8) + 0x21;
226 /* set the power off flag */
227 outb(inb(port) | 0x1, port);
228#endif
229 }
230 /* and wait for it to happen */
Zachary Amsdenf2ab4462005-09-03 15:56:42 -0700231 local_irq_disable();
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100232 for (;;)
Zachary Amsdenf2ab4462005-09-03 15:56:42 -0700233 halt();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234}
235
236/* copied from process.c */
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100237static inline void kb_wait(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238{
239 int i;
240
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100241 for (i = 0; i < 0x10000; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 if ((inb_p(0x64) & 0x02) == 0)
243 break;
244}
245
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100246void machine_shutdown(void)
Eric W. Biederman094528a2005-08-06 13:42:45 -0600247{
248 /* Architecture specific shutdown needed before a kexec */
249}
250
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100251void machine_restart(char *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252{
253 printk("Voyager Warm Restart\n");
254 kb_wait();
255
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100256 if (voyager_level == 5) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 /* write magic values to the RTC to inform system that
258 * shutdown is beginning */
259 outb(0x8f, 0x70);
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100260 outb(0x5, 0x71);
261
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 udelay(50);
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100263 outb(0xfe, 0x64); /* pull reset low */
264 } else if (voyager_level == 4) {
265 __u16 catbase = inb(VOYAGER_SSPB_RELOCATION_PORT) << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 __u8 basebd = inb(VOYAGER_MC_SETUP);
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100267
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 outb(basebd | 0x08, VOYAGER_MC_SETUP);
269 outb(0x02, catbase + 0x21);
270 }
Zachary Amsdenf2ab4462005-09-03 15:56:42 -0700271 local_irq_disable();
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100272 for (;;)
Zachary Amsdenf2ab4462005-09-03 15:56:42 -0700273 halt();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274}
275
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100276void machine_emergency_restart(void)
James Bottomleye6cb9942005-08-05 11:59:34 -0700277{
278 /*for now, just hook this to a warm restart */
279 machine_restart(NULL);
280}
281
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100282void mca_nmi_hook(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283{
David Rientjesaffd8722007-05-09 02:35:29 -0700284 __u8 dumpval __maybe_unused = inb(0xf823);
285 __u8 swnmi __maybe_unused = inb(0xf813);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
287 /* FIXME: assume dump switch pressed */
288 /* check to see if the dump switch was pressed */
289 VDEBUG(("VOYAGER: dumpval = 0x%x, swnmi = 0x%x\n", dumpval, swnmi));
290 /* clear swnmi */
291 outb(0xff, 0xf813);
292 /* tell SUS to ignore dump */
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100293 if (voyager_level == 5 && voyager_SUS != NULL) {
294 if (voyager_SUS->SUS_mbox == VOYAGER_DUMP_BUTTON_NMI) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 voyager_SUS->kernel_mbox = VOYAGER_NO_COMMAND;
296 voyager_SUS->kernel_flags |= VOYAGER_OS_IN_PROGRESS;
297 udelay(1000);
298 voyager_SUS->kernel_mbox = VOYAGER_IGNORE_DUMP;
299 voyager_SUS->kernel_flags &= ~VOYAGER_OS_IN_PROGRESS;
300 }
301 }
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100302 printk(KERN_ERR
303 "VOYAGER: Dump switch pressed, printing CPU%d tracebacks\n",
304 smp_processor_id());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 show_stack(NULL, NULL);
306 show_state();
307}
308
Ingo Molnara4ec1ef2008-01-30 13:30:10 +0100309void machine_halt(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310{
311 /* treat a halt like a power off */
312 machine_power_off();
313}
314
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315void machine_power_off(void)
316{
317 if (pm_power_off)
318 pm_power_off();
319}