VServer 1.9.2 (patch-2.6.8.1-vs1.9.2.diff)
[linux-2.6.git] / arch / i386 / mach-voyager / voyager_basic.c
1 /* 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>
26 #include <asm/io.h>
27 #include <asm/voyager.h>
28 #include <asm/vic.h>
29 #include <linux/pm.h>
30 #include <linux/irq.h>
31 #include <asm/tlbflush.h>
32 #include <asm/arch_hooks.h>
33
34 /*
35  * Power off function, if any
36  */
37 void (*pm_power_off)(void);
38
39 int reboot_thru_bios;
40
41 int voyager_level = 0;
42
43 struct voyager_SUS *voyager_SUS = NULL;
44
45 #ifdef CONFIG_SMP
46 static void
47 voyager_dump(int dummy1, struct pt_regs *dummy2, struct tty_struct *dummy3)
48 {
49         /* get here via a sysrq */
50         voyager_smp_dump();
51 }
52
53 static struct sysrq_key_op sysrq_voyager_dump_op = {
54         .handler        = voyager_dump,
55         .help_msg       = "Voyager",
56         .action_msg     = "Dump Voyager Status\n",
57 };
58 #endif
59
60 void
61 voyager_detect(struct voyager_bios_info *bios)
62 {
63         if(bios->len != 0xff) {
64                 int class = (bios->class_1 << 8) 
65                         | (bios->class_2 & 0xff);
66
67                 printk("Voyager System detected.\n"
68                        "        Class %x, Revision %d.%d\n",
69                        class, bios->major, bios->minor);
70                 if(class == VOYAGER_LEVEL4) 
71                         voyager_level = 4;
72                 else if(class < VOYAGER_LEVEL5_AND_ABOVE)
73                         voyager_level = 3;
74                 else
75                         voyager_level = 5;
76                 printk("        Architecture Level %d\n", voyager_level);
77                 if(voyager_level < 4)
78                         printk("\n**WARNING**: Voyager HAL only supports Levels 4 and 5 Architectures at the moment\n\n");
79                 /* install the power off handler */
80                 pm_power_off = voyager_power_off;
81 #ifdef CONFIG_SMP
82                 register_sysrq_key('v', &sysrq_voyager_dump_op);
83 #endif
84         } else {
85                 printk("\n\n**WARNING**: No Voyager Subsystem Found\n");
86         }
87 }
88
89 void
90 voyager_system_interrupt(int cpl, void *dev_id, struct pt_regs *regs)
91 {
92         printk("Voyager: detected system interrupt\n");
93 }
94
95 /* Routine to read information from the extended CMOS area */
96 __u8
97 voyager_extended_cmos_read(__u16 addr)
98 {
99         outb(addr & 0xff, 0x74);
100         outb((addr >> 8) & 0xff, 0x75);
101         return inb(0x76);
102 }
103
104 /* internal definitions for the SUS Click Map of memory */
105
106 #define CLICK_ENTRIES   16
107 #define CLICK_SIZE      4096    /* click to byte conversion for Length */
108
109 typedef struct ClickMap {
110         struct Entry {
111                 __u32   Address;
112                 __u32   Length;
113         } Entry[CLICK_ENTRIES];
114 } ClickMap_t;
115
116
117 /* This routine is pretty much an awful hack to read the bios clickmap by
118  * mapping it into page 0.  There are usually three regions in the map:
119  *      Base Memory
120  *      Extended Memory
121  *      zero length marker for end of map
122  *
123  * Returns are 0 for failure and 1 for success on extracting region.
124  */
125 int __init
126 voyager_memory_detect(int region, __u32 *start, __u32 *length)
127 {
128         int i;
129         int retval = 0;
130         __u8 cmos[4];
131         ClickMap_t *map;
132         unsigned long map_addr;
133         unsigned long old;
134
135         if(region >= CLICK_ENTRIES) {
136                 printk("Voyager: Illegal ClickMap region %d\n", region);
137                 return 0;
138         }
139
140         for(i = 0; i < sizeof(cmos); i++)
141                 cmos[i] = voyager_extended_cmos_read(VOYAGER_MEMORY_CLICKMAP + i);
142
143         map_addr = *(unsigned long *)cmos;
144
145         /* steal page 0 for this */
146         old = pg0[0];
147         pg0[0] = ((map_addr & PAGE_MASK) | _PAGE_RW | _PAGE_PRESENT);
148         local_flush_tlb();
149         /* now clear everything out but page 0 */
150         map = (ClickMap_t *)(map_addr & (~PAGE_MASK));
151
152         /* zero length is the end of the clickmap */
153         if(map->Entry[region].Length != 0) {
154                 *length = map->Entry[region].Length * CLICK_SIZE;
155                 *start = map->Entry[region].Address;
156                 retval = 1;
157         }
158
159         /* replace the mapping */
160         pg0[0] = old;
161         local_flush_tlb();
162         return retval;
163 }
164
165 /* voyager specific handling code for timer interrupts.  Used to hand
166  * off the timer tick to the SMP code, since the VIC doesn't have an
167  * internal timer (The QIC does, but that's another story). */
168 void
169 voyager_timer_interrupt(struct pt_regs *regs)
170 {
171         if((jiffies & 0x3ff) == 0) {
172
173                 /* There seems to be something flaky in either
174                  * hardware or software that is resetting the timer 0
175                  * count to something much higher than it should be
176                  * This seems to occur in the boot sequence, just
177                  * before root is mounted.  Therefore, every 10
178                  * seconds or so, we sanity check the timer zero count
179                  * and kick it back to where it should be.
180                  *
181                  * FIXME: This is the most awful hack yet seen.  I
182                  * should work out exactly what is interfering with
183                  * the timer count settings early in the boot sequence
184                  * and swiftly introduce it to something sharp and
185                  * pointy.  */
186                 __u16 val;
187                 extern spinlock_t i8253_lock;
188
189                 spin_lock(&i8253_lock);
190                 
191                 outb_p(0x00, 0x43);
192                 val = inb_p(0x40);
193                 val |= inb(0x40) << 8;
194                 spin_unlock(&i8253_lock);
195
196                 if(val > LATCH) {
197                         printk("\nVOYAGER: countdown timer value too high (%d), resetting\n\n", val);
198                         spin_lock(&i8253_lock);
199                         outb(0x34,0x43);
200                         outb_p(LATCH & 0xff , 0x40);    /* LSB */
201                         outb(LATCH >> 8 , 0x40);        /* MSB */
202                         spin_unlock(&i8253_lock);
203                 }
204         }
205 #ifdef CONFIG_SMP
206         smp_vic_timer_interrupt(regs);
207 #endif
208 }
209
210 void
211 voyager_power_off(void)
212 {
213         printk("VOYAGER Power Off\n");
214
215         if(voyager_level == 5) {
216                 voyager_cat_power_off();
217         } else if(voyager_level == 4) {
218                 /* This doesn't apparently work on most L4 machines,
219                  * but the specs say to do this to get automatic power
220                  * off.  Unfortunately, if it doesn't power off the
221                  * machine, it ends up doing a cold restart, which
222                  * isn't really intended, so comment out the code */
223 #if 0
224                 int port;
225
226           
227                 /* enable the voyager Configuration Space */
228                 outb((inb(VOYAGER_MC_SETUP) & 0xf0) | 0x8, 
229                      VOYAGER_MC_SETUP);
230                 /* the port for the power off flag is an offset from the
231                    floating base */
232                 port = (inb(VOYAGER_SSPB_RELOCATION_PORT) << 8) + 0x21;
233                 /* set the power off flag */
234                 outb(inb(port) | 0x1, port);
235 #endif
236         }
237         /* and wait for it to happen */
238         for(;;) {
239                 __asm("cli");
240                 __asm("hlt");
241         }
242 }
243
244 /* copied from process.c */
245 static inline void
246 kb_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
255 void
256 machine_restart(char *cmd)
257 {
258         printk("Voyager Warm Restart\n");
259         kb_wait();
260
261         if(voyager_level == 5) {
262                 /* write magic values to the RTC to inform system that
263                  * shutdown is beginning */
264                 outb(0x8f, 0x70);
265                 outb(0x5 , 0x71);
266                 
267                 udelay(50);
268                 outb(0xfe,0x64);         /* pull reset low */
269         } else if(voyager_level == 4) {
270                 __u16 catbase = inb(VOYAGER_SSPB_RELOCATION_PORT)<<8;
271                 __u8 basebd = inb(VOYAGER_MC_SETUP);
272                 
273                 outb(basebd | 0x08, VOYAGER_MC_SETUP);
274                 outb(0x02, catbase + 0x21);
275         }
276         for(;;) {
277                 asm("cli");
278                 asm("hlt");
279         }
280 }
281
282 EXPORT_SYMBOL(machine_restart);
283
284 void
285 mca_nmi_hook(void)
286 {
287         __u8 dumpval __attribute__((unused)) = inb(0xf823);
288         __u8 swnmi __attribute__((unused)) = inb(0xf813);
289
290         /* FIXME: assume dump switch pressed */
291         /* check to see if the dump switch was pressed */
292         VDEBUG(("VOYAGER: dumpval = 0x%x, swnmi = 0x%x\n", dumpval, swnmi));
293         /* clear swnmi */
294         outb(0xff, 0xf813);
295         /* tell SUS to ignore dump */
296         if(voyager_level == 5 && voyager_SUS != NULL) {
297                 if(voyager_SUS->SUS_mbox == VOYAGER_DUMP_BUTTON_NMI) {
298                         voyager_SUS->kernel_mbox = VOYAGER_NO_COMMAND;
299                         voyager_SUS->kernel_flags |= VOYAGER_OS_IN_PROGRESS;
300                         udelay(1000);
301                         voyager_SUS->kernel_mbox = VOYAGER_IGNORE_DUMP;
302                         voyager_SUS->kernel_flags &= ~VOYAGER_OS_IN_PROGRESS;
303                 }
304         }
305         printk(KERN_ERR "VOYAGER: Dump switch pressed, printing CPU%d tracebacks\n", smp_processor_id());
306         show_stack(NULL, NULL);
307         show_state();
308 }
309
310
311
312 void
313 machine_halt(void)
314 {
315         /* treat a halt like a power off */
316         machine_power_off();
317 }
318
319 EXPORT_SYMBOL(machine_halt);
320
321 void machine_power_off(void)
322 {
323         if (pm_power_off)
324                 pm_power_off();
325 }
326
327 EXPORT_SYMBOL(machine_power_off);