es7000plat.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. /*
  2. * Written by: Garry Forsgren, Unisys Corporation
  3. * Natalie Protasevich, Unisys Corporation
  4. * This file contains the code to configure and interface
  5. * with Unisys ES7000 series hardware system manager.
  6. *
  7. * Copyright (c) 2003 Unisys Corporation. All Rights Reserved.
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of version 2 of the GNU General Public License as
  11. * published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it would be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  16. *
  17. * You should have received a copy of the GNU General Public License along
  18. * with this program; if not, write the Free Software Foundation, Inc., 59
  19. * Temple Place - Suite 330, Boston MA 02111-1307, USA.
  20. *
  21. * Contact information: Unisys Corporation, Township Line & Union Meeting
  22. * Roads-A, Unisys Way, Blue Bell, Pennsylvania, 19424, or:
  23. *
  24. * http://www.unisys.com
  25. */
  26. #include <linux/module.h>
  27. #include <linux/types.h>
  28. #include <linux/kernel.h>
  29. #include <linux/smp.h>
  30. #include <linux/string.h>
  31. #include <linux/spinlock.h>
  32. #include <linux/errno.h>
  33. #include <linux/notifier.h>
  34. #include <linux/reboot.h>
  35. #include <linux/init.h>
  36. #include <linux/acpi.h>
  37. #include <asm/io.h>
  38. #include <asm/nmi.h>
  39. #include <asm/smp.h>
  40. #include <asm/apicdef.h>
  41. #include "es7000.h"
  42. #include <mach_mpparse.h>
  43. /*
  44. * ES7000 Globals
  45. */
  46. static volatile unsigned long *psai = NULL;
  47. static struct mip_reg *mip_reg;
  48. static struct mip_reg *host_reg;
  49. static int mip_port;
  50. static unsigned long mip_addr, host_addr;
  51. int es7000_plat;
  52. /*
  53. * GSI override for ES7000 platforms.
  54. */
  55. static unsigned int base;
  56. static int
  57. es7000_rename_gsi(int ioapic, int gsi)
  58. {
  59. if (es7000_plat == ES7000_ZORRO)
  60. return gsi;
  61. if (!base) {
  62. int i;
  63. for (i = 0; i < nr_ioapics; i++)
  64. base += nr_ioapic_registers[i];
  65. }
  66. if (!ioapic && (gsi < 16))
  67. gsi += base;
  68. return gsi;
  69. }
  70. void __init
  71. setup_unisys(void)
  72. {
  73. /*
  74. * Determine the generation of the ES7000 currently running.
  75. *
  76. * es7000_plat = 1 if the machine is a 5xx ES7000 box
  77. * es7000_plat = 2 if the machine is a x86_64 ES7000 box
  78. *
  79. */
  80. if (!(boot_cpu_data.x86 <= 15 && boot_cpu_data.x86_model <= 2))
  81. es7000_plat = ES7000_ZORRO;
  82. else
  83. es7000_plat = ES7000_CLASSIC;
  84. ioapic_renumber_irq = es7000_rename_gsi;
  85. }
  86. /*
  87. * Parse the OEM Table
  88. */
  89. int __init
  90. parse_unisys_oem (char *oemptr)
  91. {
  92. int i;
  93. int success = 0;
  94. unsigned char type, size;
  95. unsigned long val;
  96. char *tp = NULL;
  97. struct psai *psaip = NULL;
  98. struct mip_reg_info *mi;
  99. struct mip_reg *host, *mip;
  100. tp = oemptr;
  101. tp += 8;
  102. for (i=0; i <= 6; i++) {
  103. type = *tp++;
  104. size = *tp++;
  105. tp -= 2;
  106. switch (type) {
  107. case MIP_REG:
  108. mi = (struct mip_reg_info *)tp;
  109. val = MIP_RD_LO(mi->host_reg);
  110. host_addr = val;
  111. host = (struct mip_reg *)val;
  112. host_reg = __va(host);
  113. val = MIP_RD_LO(mi->mip_reg);
  114. mip_port = MIP_PORT(mi->mip_info);
  115. mip_addr = val;
  116. mip = (struct mip_reg *)val;
  117. mip_reg = __va(mip);
  118. Dprintk("es7000_mipcfg: host_reg = 0x%lx \n",
  119. (unsigned long)host_reg);
  120. Dprintk("es7000_mipcfg: mip_reg = 0x%lx \n",
  121. (unsigned long)mip_reg);
  122. success++;
  123. break;
  124. case MIP_PSAI_REG:
  125. psaip = (struct psai *)tp;
  126. if (tp != NULL) {
  127. if (psaip->addr)
  128. psai = __va(psaip->addr);
  129. else
  130. psai = NULL;
  131. success++;
  132. }
  133. break;
  134. default:
  135. break;
  136. }
  137. tp += size;
  138. }
  139. if (success < 2) {
  140. es7000_plat = NON_UNISYS;
  141. } else
  142. setup_unisys();
  143. return es7000_plat;
  144. }
  145. #ifdef CONFIG_ACPI
  146. int __init
  147. find_unisys_acpi_oem_table(unsigned long *oem_addr)
  148. {
  149. struct acpi_table_header *header = NULL;
  150. int i = 0;
  151. while (ACPI_SUCCESS(acpi_get_table("OEM1", i++, &header))) {
  152. if (!memcmp((char *) &header->oem_id, "UNISYS", 6)) {
  153. struct oem_table *t = (struct oem_table *)header;
  154. *oem_addr = (unsigned long)__acpi_map_table(t->OEMTableAddr,
  155. t->OEMTableSize);
  156. return 0;
  157. }
  158. }
  159. return -1;
  160. }
  161. #endif
  162. /*
  163. * This file also gets compiled if CONFIG_X86_GENERICARCH is set. Generic
  164. * arch already has got following function definitions (asm-generic/es7000.c)
  165. * hence no need to define these for that case.
  166. */
  167. #ifndef CONFIG_X86_GENERICARCH
  168. void es7000_sw_apic(void);
  169. void __init enable_apic_mode(void)
  170. {
  171. es7000_sw_apic();
  172. return;
  173. }
  174. __init int mps_oem_check(struct mp_config_table *mpc, char *oem,
  175. char *productid)
  176. {
  177. if (mpc->mpc_oemptr) {
  178. struct mp_config_oemtable *oem_table =
  179. (struct mp_config_oemtable *)mpc->mpc_oemptr;
  180. if (!strncmp(oem, "UNISYS", 6))
  181. return parse_unisys_oem((char *)oem_table);
  182. }
  183. return 0;
  184. }
  185. #ifdef CONFIG_ACPI
  186. /* Hook from generic ACPI tables.c */
  187. int __init acpi_madt_oem_check(char *oem_id, char *oem_table_id)
  188. {
  189. unsigned long oem_addr;
  190. if (!find_unisys_acpi_oem_table(&oem_addr)) {
  191. if (es7000_check_dsdt())
  192. return parse_unisys_oem((char *)oem_addr);
  193. else {
  194. setup_unisys();
  195. return 1;
  196. }
  197. }
  198. return 0;
  199. }
  200. #else
  201. int __init acpi_madt_oem_check(char *oem_id, char *oem_table_id)
  202. {
  203. return 0;
  204. }
  205. #endif
  206. #endif /* COFIG_X86_GENERICARCH */
  207. static void
  208. es7000_spin(int n)
  209. {
  210. int i = 0;
  211. while (i++ < n)
  212. rep_nop();
  213. }
  214. static int __init
  215. es7000_mip_write(struct mip_reg *mip_reg)
  216. {
  217. int status = 0;
  218. int spin;
  219. spin = MIP_SPIN;
  220. while (((unsigned long long)host_reg->off_38 &
  221. (unsigned long long)MIP_VALID) != 0) {
  222. if (--spin <= 0) {
  223. printk("es7000_mip_write: Timeout waiting for Host Valid Flag");
  224. return -1;
  225. }
  226. es7000_spin(MIP_SPIN);
  227. }
  228. memcpy(host_reg, mip_reg, sizeof(struct mip_reg));
  229. outb(1, mip_port);
  230. spin = MIP_SPIN;
  231. while (((unsigned long long)mip_reg->off_38 &
  232. (unsigned long long)MIP_VALID) == 0) {
  233. if (--spin <= 0) {
  234. printk("es7000_mip_write: Timeout waiting for MIP Valid Flag");
  235. return -1;
  236. }
  237. es7000_spin(MIP_SPIN);
  238. }
  239. status = ((unsigned long long)mip_reg->off_0 &
  240. (unsigned long long)0xffff0000000000ULL) >> 48;
  241. mip_reg->off_38 = ((unsigned long long)mip_reg->off_38 &
  242. (unsigned long long)~MIP_VALID);
  243. return status;
  244. }
  245. int
  246. es7000_start_cpu(int cpu, unsigned long eip)
  247. {
  248. unsigned long vect = 0, psaival = 0;
  249. if (psai == NULL)
  250. return -1;
  251. vect = ((unsigned long)__pa(eip)/0x1000) << 16;
  252. psaival = (0x1000000 | vect | cpu);
  253. while (*psai & 0x1000000)
  254. ;
  255. *psai = psaival;
  256. return 0;
  257. }
  258. void __init
  259. es7000_sw_apic(void)
  260. {
  261. if (es7000_plat) {
  262. int mip_status;
  263. struct mip_reg es7000_mip_reg;
  264. printk("ES7000: Enabling APIC mode.\n");
  265. memset(&es7000_mip_reg, 0, sizeof(struct mip_reg));
  266. es7000_mip_reg.off_0 = MIP_SW_APIC;
  267. es7000_mip_reg.off_38 = (MIP_VALID);
  268. while ((mip_status = es7000_mip_write(&es7000_mip_reg)) != 0)
  269. printk("es7000_sw_apic: command failed, status = %x\n",
  270. mip_status);
  271. return;
  272. }
  273. }