voyager_basic.c 7.8 KB

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