voyager_basic.c 7.8 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/* Copyright (C) 1999,2001 
 *
 * Author: J.E.J.Bottomley@HansenPartnership.com
 *
 * This file contains all the voyager specific routines for getting
 * initialisation of the architecture to function.  For additional
 * features see:
 *
 *	voyager_cat.c - Voyager CAT bus interface
 *	voyager_smp.c - Voyager SMP hal (emulates linux smp.c)
 */

#include <linux/module.h>
#include <linux/types.h>
#include <linux/sched.h>
#include <linux/ptrace.h>
#include <linux/ioport.h>
#include <linux/interrupt.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/reboot.h>
#include <linux/sysrq.h>
23 24
#include <linux/smp.h>
#include <linux/nodemask.h>
L
Linus Torvalds 已提交
25 26 27 28 29 30
#include <asm/io.h>
#include <asm/voyager.h>
#include <asm/vic.h>
#include <linux/pm.h>
#include <asm/tlbflush.h>
#include <asm/arch_hooks.h>
31
#include <asm/i8253.h>
L
Linus Torvalds 已提交
32 33 34 35

/*
 * Power off function, if any
 */
I
Ingo Molnar 已提交
36
void (*pm_power_off) (void);
37
EXPORT_SYMBOL(pm_power_off);
L
Linus Torvalds 已提交
38 39 40 41 42 43

int voyager_level = 0;

struct voyager_SUS *voyager_SUS = NULL;

#ifdef CONFIG_SMP
I
Ingo Molnar 已提交
44
static void voyager_dump(int dummy1, struct tty_struct *dummy3)
L
Linus Torvalds 已提交
45 46 47 48 49 50
{
	/* get here via a sysrq */
	voyager_smp_dump();
}

static struct sysrq_key_op sysrq_voyager_dump_op = {
I
Ingo Molnar 已提交
51 52 53
	.handler = voyager_dump,
	.help_msg = "Voyager",
	.action_msg = "Dump Voyager Status",
L
Linus Torvalds 已提交
54 55 56
};
#endif

I
Ingo Molnar 已提交
57
void voyager_detect(struct voyager_bios_info *bios)
L
Linus Torvalds 已提交
58
{
I
Ingo Molnar 已提交
59 60 61
	if (bios->len != 0xff) {
		int class = (bios->class_1 << 8)
		    | (bios->class_2 & 0xff);
L
Linus Torvalds 已提交
62 63 64 65

		printk("Voyager System detected.\n"
		       "        Class %x, Revision %d.%d\n",
		       class, bios->major, bios->minor);
I
Ingo Molnar 已提交
66
		if (class == VOYAGER_LEVEL4)
L
Linus Torvalds 已提交
67
			voyager_level = 4;
I
Ingo Molnar 已提交
68
		else if (class < VOYAGER_LEVEL5_AND_ABOVE)
L
Linus Torvalds 已提交
69 70 71 72
			voyager_level = 3;
		else
			voyager_level = 5;
		printk("        Architecture Level %d\n", voyager_level);
I
Ingo Molnar 已提交
73 74 75
		if (voyager_level < 4)
			printk
			    ("\n**WARNING**: Voyager HAL only supports Levels 4 and 5 Architectures at the moment\n\n");
L
Linus Torvalds 已提交
76 77 78 79 80 81 82 83 84 85
		/* install the power off handler */
		pm_power_off = voyager_power_off;
#ifdef CONFIG_SMP
		register_sysrq_key('v', &sysrq_voyager_dump_op);
#endif
	} else {
		printk("\n\n**WARNING**: No Voyager Subsystem Found\n");
	}
}

I
Ingo Molnar 已提交
86
void voyager_system_interrupt(int cpl, void *dev_id)
L
Linus Torvalds 已提交
87 88 89 90 91
{
	printk("Voyager: detected system interrupt\n");
}

/* Routine to read information from the extended CMOS area */
I
Ingo Molnar 已提交
92
__u8 voyager_extended_cmos_read(__u16 addr)
L
Linus Torvalds 已提交
93 94 95 96 97 98 99 100 101 102 103 104 105
{
	outb(addr & 0xff, 0x74);
	outb((addr >> 8) & 0xff, 0x75);
	return inb(0x76);
}

/* internal definitions for the SUS Click Map of memory */

#define CLICK_ENTRIES	16
#define CLICK_SIZE	4096	/* click to byte conversion for Length */

typedef struct ClickMap {
	struct Entry {
I
Ingo Molnar 已提交
106 107
		__u32 Address;
		__u32 Length;
L
Linus Torvalds 已提交
108 109 110 111 112 113 114 115 116 117 118
	} Entry[CLICK_ENTRIES];
} ClickMap_t;

/* This routine is pretty much an awful hack to read the bios clickmap by
 * mapping it into page 0.  There are usually three regions in the map:
 * 	Base Memory
 * 	Extended Memory
 *	zero length marker for end of map
 *
 * Returns are 0 for failure and 1 for success on extracting region.
 */
I
Ingo Molnar 已提交
119
int __init voyager_memory_detect(int region, __u32 * start, __u32 * length)
L
Linus Torvalds 已提交
120 121 122 123 124 125 126 127
{
	int i;
	int retval = 0;
	__u8 cmos[4];
	ClickMap_t *map;
	unsigned long map_addr;
	unsigned long old;

I
Ingo Molnar 已提交
128
	if (region >= CLICK_ENTRIES) {
L
Linus Torvalds 已提交
129 130 131 132
		printk("Voyager: Illegal ClickMap region %d\n", region);
		return 0;
	}

I
Ingo Molnar 已提交
133 134 135
	for (i = 0; i < sizeof(cmos); i++)
		cmos[i] =
		    voyager_extended_cmos_read(VOYAGER_MEMORY_CLICKMAP + i);
L
Linus Torvalds 已提交
136 137 138 139 140 141 142 143

	map_addr = *(unsigned long *)cmos;

	/* steal page 0 for this */
	old = pg0[0];
	pg0[0] = ((map_addr & PAGE_MASK) | _PAGE_RW | _PAGE_PRESENT);
	local_flush_tlb();
	/* now clear everything out but page 0 */
I
Ingo Molnar 已提交
144
	map = (ClickMap_t *) (map_addr & (~PAGE_MASK));
L
Linus Torvalds 已提交
145 146

	/* zero length is the end of the clickmap */
I
Ingo Molnar 已提交
147
	if (map->Entry[region].Length != 0) {
L
Linus Torvalds 已提交
148 149 150 151 152 153 154 155 156 157 158 159 160 161
		*length = map->Entry[region].Length * CLICK_SIZE;
		*start = map->Entry[region].Address;
		retval = 1;
	}

	/* replace the mapping */
	pg0[0] = old;
	local_flush_tlb();
	return retval;
}

/* voyager specific handling code for timer interrupts.  Used to hand
 * off the timer tick to the SMP code, since the VIC doesn't have an
 * internal timer (The QIC does, but that's another story). */
I
Ingo Molnar 已提交
162
void voyager_timer_interrupt(void)
L
Linus Torvalds 已提交
163
{
I
Ingo Molnar 已提交
164
	if ((jiffies & 0x3ff) == 0) {
L
Linus Torvalds 已提交
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181

		/* There seems to be something flaky in either
		 * hardware or software that is resetting the timer 0
		 * count to something much higher than it should be
		 * This seems to occur in the boot sequence, just
		 * before root is mounted.  Therefore, every 10
		 * seconds or so, we sanity check the timer zero count
		 * and kick it back to where it should be.
		 *
		 * FIXME: This is the most awful hack yet seen.  I
		 * should work out exactly what is interfering with
		 * the timer count settings early in the boot sequence
		 * and swiftly introduce it to something sharp and
		 * pointy.  */
		__u16 val;

		spin_lock(&i8253_lock);
I
Ingo Molnar 已提交
182

L
Linus Torvalds 已提交
183 184 185 186 187
		outb_p(0x00, 0x43);
		val = inb_p(0x40);
		val |= inb(0x40) << 8;
		spin_unlock(&i8253_lock);

I
Ingo Molnar 已提交
188 189 190 191
		if (val > LATCH) {
			printk
			    ("\nVOYAGER: countdown timer value too high (%d), resetting\n\n",
			     val);
L
Linus Torvalds 已提交
192
			spin_lock(&i8253_lock);
I
Ingo Molnar 已提交
193 194 195
			outb(0x34, 0x43);
			outb_p(LATCH & 0xff, 0x40);	/* LSB */
			outb(LATCH >> 8, 0x40);	/* MSB */
L
Linus Torvalds 已提交
196 197 198 199
			spin_unlock(&i8253_lock);
		}
	}
#ifdef CONFIG_SMP
200
	smp_vic_timer_interrupt();
L
Linus Torvalds 已提交
201 202 203
#endif
}

I
Ingo Molnar 已提交
204
void voyager_power_off(void)
L
Linus Torvalds 已提交
205 206 207
{
	printk("VOYAGER Power Off\n");

I
Ingo Molnar 已提交
208
	if (voyager_level == 5) {
L
Linus Torvalds 已提交
209
		voyager_cat_power_off();
I
Ingo Molnar 已提交
210
	} else if (voyager_level == 4) {
L
Linus Torvalds 已提交
211 212 213 214 215 216 217 218 219
		/* This doesn't apparently work on most L4 machines,
		 * but the specs say to do this to get automatic power
		 * off.  Unfortunately, if it doesn't power off the
		 * machine, it ends up doing a cold restart, which
		 * isn't really intended, so comment out the code */
#if 0
		int port;

		/* enable the voyager Configuration Space */
I
Ingo Molnar 已提交
220
		outb((inb(VOYAGER_MC_SETUP) & 0xf0) | 0x8, VOYAGER_MC_SETUP);
L
Linus Torvalds 已提交
221 222 223 224 225 226 227 228
		/* the port for the power off flag is an offset from the
		   floating base */
		port = (inb(VOYAGER_SSPB_RELOCATION_PORT) << 8) + 0x21;
		/* set the power off flag */
		outb(inb(port) | 0x1, port);
#endif
	}
	/* and wait for it to happen */
Z
Zachary Amsden 已提交
229
	local_irq_disable();
I
Ingo Molnar 已提交
230
	for (;;)
Z
Zachary Amsden 已提交
231
		halt();
L
Linus Torvalds 已提交
232 233 234
}

/* copied from process.c */
I
Ingo Molnar 已提交
235
static inline void kb_wait(void)
L
Linus Torvalds 已提交
236 237 238
{
	int i;

I
Ingo Molnar 已提交
239
	for (i = 0; i < 0x10000; i++)
L
Linus Torvalds 已提交
240 241 242 243
		if ((inb_p(0x64) & 0x02) == 0)
			break;
}

I
Ingo Molnar 已提交
244
void machine_shutdown(void)
245 246 247 248
{
	/* Architecture specific shutdown needed before a kexec */
}

I
Ingo Molnar 已提交
249
void machine_restart(char *cmd)
L
Linus Torvalds 已提交
250 251 252 253
{
	printk("Voyager Warm Restart\n");
	kb_wait();

I
Ingo Molnar 已提交
254
	if (voyager_level == 5) {
L
Linus Torvalds 已提交
255 256 257
		/* write magic values to the RTC to inform system that
		 * shutdown is beginning */
		outb(0x8f, 0x70);
I
Ingo Molnar 已提交
258 259
		outb(0x5, 0x71);

L
Linus Torvalds 已提交
260
		udelay(50);
I
Ingo Molnar 已提交
261 262 263
		outb(0xfe, 0x64);	/* pull reset low */
	} else if (voyager_level == 4) {
		__u16 catbase = inb(VOYAGER_SSPB_RELOCATION_PORT) << 8;
L
Linus Torvalds 已提交
264
		__u8 basebd = inb(VOYAGER_MC_SETUP);
I
Ingo Molnar 已提交
265

L
Linus Torvalds 已提交
266 267 268
		outb(basebd | 0x08, VOYAGER_MC_SETUP);
		outb(0x02, catbase + 0x21);
	}
Z
Zachary Amsden 已提交
269
	local_irq_disable();
I
Ingo Molnar 已提交
270
	for (;;)
Z
Zachary Amsden 已提交
271
		halt();
L
Linus Torvalds 已提交
272 273
}

I
Ingo Molnar 已提交
274
void machine_emergency_restart(void)
275 276 277 278 279
{
	/*for now, just hook this to a warm restart */
	machine_restart(NULL);
}

I
Ingo Molnar 已提交
280
void mca_nmi_hook(void)
L
Linus Torvalds 已提交
281
{
282 283
	__u8 dumpval __maybe_unused = inb(0xf823);
	__u8 swnmi __maybe_unused = inb(0xf813);
L
Linus Torvalds 已提交
284 285 286 287 288 289 290

	/* FIXME: assume dump switch pressed */
	/* check to see if the dump switch was pressed */
	VDEBUG(("VOYAGER: dumpval = 0x%x, swnmi = 0x%x\n", dumpval, swnmi));
	/* clear swnmi */
	outb(0xff, 0xf813);
	/* tell SUS to ignore dump */
I
Ingo Molnar 已提交
291 292
	if (voyager_level == 5 && voyager_SUS != NULL) {
		if (voyager_SUS->SUS_mbox == VOYAGER_DUMP_BUTTON_NMI) {
L
Linus Torvalds 已提交
293 294 295 296 297 298 299
			voyager_SUS->kernel_mbox = VOYAGER_NO_COMMAND;
			voyager_SUS->kernel_flags |= VOYAGER_OS_IN_PROGRESS;
			udelay(1000);
			voyager_SUS->kernel_mbox = VOYAGER_IGNORE_DUMP;
			voyager_SUS->kernel_flags &= ~VOYAGER_OS_IN_PROGRESS;
		}
	}
I
Ingo Molnar 已提交
300 301 302
	printk(KERN_ERR
	       "VOYAGER: Dump switch pressed, printing CPU%d tracebacks\n",
	       smp_processor_id());
L
Linus Torvalds 已提交
303 304 305 306
	show_stack(NULL, NULL);
	show_state();
}

I
Ingo Molnar 已提交
307
void machine_halt(void)
L
Linus Torvalds 已提交
308 309 310 311 312 313 314 315 316 317
{
	/* treat a halt like a power off */
	machine_power_off();
}

void machine_power_off(void)
{
	if (pm_power_off)
		pm_power_off();
}