setup_visws.c 7.7 KB

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