voyager_basic.c 7.8 KB

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