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. #include <asm/i8253.h>
  33. /*
  34. * Power off function, if any
  35. */
  36. void (*pm_power_off)(void);
  37. int voyager_level = 0;
  38. struct voyager_SUS *voyager_SUS = NULL;
  39. #ifdef CONFIG_SMP
  40. static void
  41. voyager_dump(int dummy1, struct pt_regs *dummy2, 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
  53. voyager_detect(struct voyager_bios_info *bios)
  54. {
  55. if(bios->len != 0xff) {
  56. int class = (bios->class_1 << 8)
  57. | (bios->class_2 & 0xff);
  58. printk("Voyager System detected.\n"
  59. " Class %x, Revision %d.%d\n",
  60. class, bios->major, bios->minor);
  61. if(class == VOYAGER_LEVEL4)
  62. voyager_level = 4;
  63. else if(class < VOYAGER_LEVEL5_AND_ABOVE)
  64. voyager_level = 3;
  65. else
  66. voyager_level = 5;
  67. printk(" Architecture Level %d\n", voyager_level);
  68. if(voyager_level < 4)
  69. printk("\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
  80. voyager_system_interrupt(int cpl, void *dev_id, struct pt_regs *regs)
  81. {
  82. printk("Voyager: detected system interrupt\n");
  83. }
  84. /* Routine to read information from the extended CMOS area */
  85. __u8
  86. voyager_extended_cmos_read(__u16 addr)
  87. {
  88. outb(addr & 0xff, 0x74);
  89. outb((addr >> 8) & 0xff, 0x75);
  90. return inb(0x76);
  91. }
  92. /* internal definitions for the SUS Click Map of memory */
  93. #define CLICK_ENTRIES 16
  94. #define CLICK_SIZE 4096 /* click to byte conversion for Length */
  95. typedef struct ClickMap {
  96. struct Entry {
  97. __u32 Address;
  98. __u32 Length;
  99. } Entry[CLICK_ENTRIES];
  100. } ClickMap_t;
  101. /* This routine is pretty much an awful hack to read the bios clickmap by
  102. * mapping it into page 0. There are usually three regions in the map:
  103. * Base Memory
  104. * Extended Memory
  105. * zero length marker for end of map
  106. *
  107. * Returns are 0 for failure and 1 for success on extracting region.
  108. */
  109. int __init
  110. voyager_memory_detect(int region, __u32 *start, __u32 *length)
  111. {
  112. int i;
  113. int retval = 0;
  114. __u8 cmos[4];
  115. ClickMap_t *map;
  116. unsigned long map_addr;
  117. unsigned long old;
  118. if(region >= CLICK_ENTRIES) {
  119. printk("Voyager: Illegal ClickMap region %d\n", region);
  120. return 0;
  121. }
  122. for(i = 0; i < sizeof(cmos); i++)
  123. cmos[i] = voyager_extended_cmos_read(VOYAGER_MEMORY_CLICKMAP + i);
  124. map_addr = *(unsigned long *)cmos;
  125. /* steal page 0 for this */
  126. old = pg0[0];
  127. pg0[0] = ((map_addr & PAGE_MASK) | _PAGE_RW | _PAGE_PRESENT);
  128. local_flush_tlb();
  129. /* now clear everything out but page 0 */
  130. map = (ClickMap_t *)(map_addr & (~PAGE_MASK));
  131. /* zero length is the end of the clickmap */
  132. if(map->Entry[region].Length != 0) {
  133. *length = map->Entry[region].Length * CLICK_SIZE;
  134. *start = map->Entry[region].Address;
  135. retval = 1;
  136. }
  137. /* replace the mapping */
  138. pg0[0] = old;
  139. local_flush_tlb();
  140. return retval;
  141. }
  142. /* voyager specific handling code for timer interrupts. Used to hand
  143. * off the timer tick to the SMP code, since the VIC doesn't have an
  144. * internal timer (The QIC does, but that's another story). */
  145. void
  146. voyager_timer_interrupt(struct pt_regs *regs)
  147. {
  148. if((jiffies & 0x3ff) == 0) {
  149. /* There seems to be something flaky in either
  150. * hardware or software that is resetting the timer 0
  151. * count to something much higher than it should be
  152. * This seems to occur in the boot sequence, just
  153. * before root is mounted. Therefore, every 10
  154. * seconds or so, we sanity check the timer zero count
  155. * and kick it back to where it should be.
  156. *
  157. * FIXME: This is the most awful hack yet seen. I
  158. * should work out exactly what is interfering with
  159. * the timer count settings early in the boot sequence
  160. * and swiftly introduce it to something sharp and
  161. * pointy. */
  162. __u16 val;
  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);