voyager_basic.c 7.9 KB

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