voyager_basic.c 7.8 KB

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