setup_visws.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. /*
  2. * Unmaintained SGI Visual Workstation support.
  3. * Split out from setup.c by davej@suse.de
  4. */
  5. #include <linux/interrupt.h>
  6. #include <linux/module.h>
  7. #include <linux/init.h>
  8. #include <linux/smp.h>
  9. #include <asm/visws/cobalt.h>
  10. #include <asm/visws/piix4.h>
  11. #include <asm/arch_hooks.h>
  12. #include <asm/fixmap.h>
  13. #include <asm/reboot.h>
  14. #include <asm/setup.h>
  15. #include <asm/e820.h>
  16. #include <asm/smp.h>
  17. #include <asm/io.h>
  18. #include <mach_ipi.h>
  19. #include "mach_apic.h"
  20. #include <linux/init.h>
  21. #include <linux/smp.h>
  22. char visws_board_type = -1;
  23. char visws_board_rev = -1;
  24. int is_visws_box(void)
  25. {
  26. return visws_board_type >= 0;
  27. }
  28. static int __init visws_time_init_quirk(void)
  29. {
  30. printk(KERN_INFO "Starting Cobalt Timer system clock\n");
  31. /* Set the countdown value */
  32. co_cpu_write(CO_CPU_TIMEVAL, CO_TIME_HZ/HZ);
  33. /* Start the timer */
  34. co_cpu_write(CO_CPU_CTRL, co_cpu_read(CO_CPU_CTRL) | CO_CTRL_TIMERUN);
  35. /* Enable (unmask) the timer interrupt */
  36. co_cpu_write(CO_CPU_CTRL, co_cpu_read(CO_CPU_CTRL) & ~CO_CTRL_TIMEMASK);
  37. /*
  38. * Zero return means the generic timer setup code will set up
  39. * the standard vector:
  40. */
  41. return 0;
  42. }
  43. static int __init visws_pre_intr_init_quirk(void)
  44. {
  45. init_VISWS_APIC_irqs();
  46. /*
  47. * We dont want ISA irqs to be set up by the generic code:
  48. */
  49. return 1;
  50. }
  51. /* Quirk for machine specific memory setup. */
  52. #define MB (1024 * 1024)
  53. unsigned long sgivwfb_mem_phys;
  54. unsigned long sgivwfb_mem_size;
  55. EXPORT_SYMBOL(sgivwfb_mem_phys);
  56. EXPORT_SYMBOL(sgivwfb_mem_size);
  57. long long mem_size __initdata = 0;
  58. static char * __init visws_memory_setup_quirk(void)
  59. {
  60. long long gfx_mem_size = 8 * MB;
  61. mem_size = boot_params.alt_mem_k;
  62. if (!mem_size) {
  63. printk(KERN_WARNING "Bootloader didn't set memory size, upgrade it !\n");
  64. mem_size = 128 * MB;
  65. }
  66. /*
  67. * this hardcodes the graphics memory to 8 MB
  68. * it really should be sized dynamically (or at least
  69. * set as a boot param)
  70. */
  71. if (!sgivwfb_mem_size) {
  72. printk(KERN_WARNING "Defaulting to 8 MB framebuffer size\n");
  73. sgivwfb_mem_size = 8 * MB;
  74. }
  75. /*
  76. * Trim to nearest MB
  77. */
  78. sgivwfb_mem_size &= ~((1 << 20) - 1);
  79. sgivwfb_mem_phys = mem_size - gfx_mem_size;
  80. e820_add_region(0, LOWMEMSIZE(), E820_RAM);
  81. e820_add_region(HIGH_MEMORY, mem_size - sgivwfb_mem_size - HIGH_MEMORY, E820_RAM);
  82. e820_add_region(sgivwfb_mem_phys, sgivwfb_mem_size, E820_RESERVED);
  83. return "PROM";
  84. }
  85. static void visws_machine_emergency_restart(void)
  86. {
  87. /*
  88. * Visual Workstations restart after this
  89. * register is poked on the PIIX4
  90. */
  91. outb(PIIX4_RESET_VAL, PIIX4_RESET_PORT);
  92. }
  93. static void visws_machine_power_off(void)
  94. {
  95. unsigned short pm_status;
  96. /* extern unsigned int pci_bus0; */
  97. while ((pm_status = inw(PMSTS_PORT)) & 0x100)
  98. outw(pm_status, PMSTS_PORT);
  99. outw(PM_SUSPEND_ENABLE, PMCNTRL_PORT);
  100. mdelay(10);
  101. #define PCI_CONF1_ADDRESS(bus, devfn, reg) \
  102. (0x80000000 | (bus << 16) | (devfn << 8) | (reg & ~3))
  103. /* outl(PCI_CONF1_ADDRESS(pci_bus0, SPECIAL_DEV, SPECIAL_REG), 0xCF8); */
  104. outl(PIIX_SPECIAL_STOP, 0xCFC);
  105. }
  106. static int __init visws_get_smp_config_quirk(unsigned int early)
  107. {
  108. /*
  109. * Prevent MP-table parsing by the generic code:
  110. */
  111. return 1;
  112. }
  113. extern unsigned int __cpuinitdata maxcpus;
  114. /*
  115. * The Visual Workstation is Intel MP compliant in the hardware
  116. * sense, but it doesn't have a BIOS(-configuration table).
  117. * No problem for Linux.
  118. */
  119. static void __init MP_processor_info (struct mpc_config_processor *m)
  120. {
  121. int ver, logical_apicid;
  122. physid_mask_t apic_cpus;
  123. if (!(m->mpc_cpuflag & CPU_ENABLED))
  124. return;
  125. logical_apicid = m->mpc_apicid;
  126. printk(KERN_INFO "%sCPU #%d %u:%u APIC version %d\n",
  127. m->mpc_cpuflag & CPU_BOOTPROCESSOR ? "Bootup " : "",
  128. m->mpc_apicid,
  129. (m->mpc_cpufeature & CPU_FAMILY_MASK) >> 8,
  130. (m->mpc_cpufeature & CPU_MODEL_MASK) >> 4,
  131. m->mpc_apicver);
  132. if (m->mpc_cpuflag & CPU_BOOTPROCESSOR)
  133. boot_cpu_physical_apicid = m->mpc_apicid;
  134. ver = m->mpc_apicver;
  135. if ((ver >= 0x14 && m->mpc_apicid >= 0xff) || m->mpc_apicid >= 0xf) {
  136. printk(KERN_ERR "Processor #%d INVALID. (Max ID: %d).\n",
  137. m->mpc_apicid, MAX_APICS);
  138. return;
  139. }
  140. apic_cpus = apicid_to_cpu_present(m->mpc_apicid);
  141. physids_or(phys_cpu_present_map, phys_cpu_present_map, apic_cpus);
  142. /*
  143. * Validate version
  144. */
  145. if (ver == 0x0) {
  146. printk(KERN_ERR "BIOS bug, APIC version is 0 for CPU#%d! "
  147. "fixing up to 0x10. (tell your hw vendor)\n",
  148. m->mpc_apicid);
  149. ver = 0x10;
  150. }
  151. apic_version[m->mpc_apicid] = ver;
  152. }
  153. int __init visws_find_smp_config_quirk(unsigned int reserve)
  154. {
  155. struct mpc_config_processor *mp = phys_to_virt(CO_CPU_TAB_PHYS);
  156. unsigned short ncpus = readw(phys_to_virt(CO_CPU_NUM_PHYS));
  157. if (ncpus > CO_CPU_MAX) {
  158. printk(KERN_WARNING "find_visws_smp: got cpu count of %d at %p\n",
  159. ncpus, mp);
  160. ncpus = CO_CPU_MAX;
  161. }
  162. if (ncpus > maxcpus)
  163. ncpus = maxcpus;
  164. #ifdef CONFIG_X86_LOCAL_APIC
  165. smp_found_config = 1;
  166. #endif
  167. while (ncpus--)
  168. MP_processor_info(mp++);
  169. mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
  170. return 1;
  171. }
  172. extern int visws_trap_init_quirk(void);
  173. void __init visws_early_detect(void)
  174. {
  175. int raw;
  176. visws_board_type = (char)(inb_p(PIIX_GPI_BD_REG) & PIIX_GPI_BD_REG)
  177. >> PIIX_GPI_BD_SHIFT;
  178. if (visws_board_type < 0)
  179. return;
  180. /*
  181. * Install special quirks for timer, interrupt and memory setup:
  182. */
  183. arch_time_init_quirk = visws_time_init_quirk;
  184. arch_pre_intr_init_quirk = visws_pre_intr_init_quirk;
  185. arch_memory_setup_quirk = visws_memory_setup_quirk;
  186. /*
  187. * Fall back to generic behavior for traps:
  188. */
  189. arch_intr_init_quirk = NULL;
  190. arch_trap_init_quirk = visws_trap_init_quirk;
  191. /*
  192. * Install reboot quirks:
  193. */
  194. pm_power_off = visws_machine_power_off;
  195. machine_ops.emergency_restart = visws_machine_emergency_restart;
  196. /*
  197. * Do not use broadcast IPIs:
  198. */
  199. no_broadcast = 0;
  200. /*
  201. * Override generic MP-table parsing:
  202. */
  203. mach_get_smp_config_quirk = visws_get_smp_config_quirk;
  204. mach_find_smp_config_quirk = visws_find_smp_config_quirk;
  205. /*
  206. * Get Board rev.
  207. * First, we have to initialize the 307 part to allow us access
  208. * to the GPIO registers. Let's map them at 0x0fc0 which is right
  209. * after the PIIX4 PM section.
  210. */
  211. outb_p(SIO_DEV_SEL, SIO_INDEX);
  212. outb_p(SIO_GP_DEV, SIO_DATA); /* Talk to GPIO regs. */
  213. outb_p(SIO_DEV_MSB, SIO_INDEX);
  214. outb_p(SIO_GP_MSB, SIO_DATA); /* MSB of GPIO base address */
  215. outb_p(SIO_DEV_LSB, SIO_INDEX);
  216. outb_p(SIO_GP_LSB, SIO_DATA); /* LSB of GPIO base address */
  217. outb_p(SIO_DEV_ENB, SIO_INDEX);
  218. outb_p(1, SIO_DATA); /* Enable GPIO registers. */
  219. /*
  220. * Now, we have to map the power management section to write
  221. * a bit which enables access to the GPIO registers.
  222. * What lunatic came up with this shit?
  223. */
  224. outb_p(SIO_DEV_SEL, SIO_INDEX);
  225. outb_p(SIO_PM_DEV, SIO_DATA); /* Talk to GPIO regs. */
  226. outb_p(SIO_DEV_MSB, SIO_INDEX);
  227. outb_p(SIO_PM_MSB, SIO_DATA); /* MSB of PM base address */
  228. outb_p(SIO_DEV_LSB, SIO_INDEX);
  229. outb_p(SIO_PM_LSB, SIO_DATA); /* LSB of PM base address */
  230. outb_p(SIO_DEV_ENB, SIO_INDEX);
  231. outb_p(1, SIO_DATA); /* Enable PM registers. */
  232. /*
  233. * Now, write the PM register which enables the GPIO registers.
  234. */
  235. outb_p(SIO_PM_FER2, SIO_PM_INDEX);
  236. outb_p(SIO_PM_GP_EN, SIO_PM_DATA);
  237. /*
  238. * Now, initialize the GPIO registers.
  239. * We want them all to be inputs which is the
  240. * power on default, so let's leave them alone.
  241. * So, let's just read the board rev!
  242. */
  243. raw = inb_p(SIO_GP_DATA1);
  244. raw &= 0x7f; /* 7 bits of valid board revision ID. */
  245. if (visws_board_type == VISWS_320) {
  246. if (raw < 0x6) {
  247. visws_board_rev = 4;
  248. } else if (raw < 0xc) {
  249. visws_board_rev = 5;
  250. } else {
  251. visws_board_rev = 6;
  252. }
  253. } else if (visws_board_type == VISWS_540) {
  254. visws_board_rev = 2;
  255. } else {
  256. visws_board_rev = raw;
  257. }
  258. printk(KERN_INFO "Silicon Graphics Visual Workstation %s (rev %d) detected\n",
  259. (visws_board_type == VISWS_320 ? "320" :
  260. (visws_board_type == VISWS_540 ? "540" :
  261. "unknown")), visws_board_rev);
  262. }