PageRenderTime 31ms CodeModel.GetById 18ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/arch/i386/mach-voyager/voyager_basic.c

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