voyager_basic.c 7.9 KB

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