es7000_32.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  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/atomic.h>
  41. #include <asm/apicdef.h>
  42. #include <mach_mpparse.h>
  43. #include <asm/genapic.h>
  44. #include <asm/setup.h>
  45. /*
  46. * ES7000 chipsets
  47. */
  48. #define NON_UNISYS 0
  49. #define ES7000_CLASSIC 1
  50. #define ES7000_ZORRO 2
  51. #define MIP_REG 1
  52. #define MIP_PSAI_REG 4
  53. #define MIP_BUSY 1
  54. #define MIP_SPIN 0xf0000
  55. #define MIP_VALID 0x0100000000000000ULL
  56. #define MIP_PORT(VALUE) ((VALUE >> 32) & 0xffff)
  57. #define MIP_RD_LO(VALUE) (VALUE & 0xffffffff)
  58. struct mip_reg_info {
  59. unsigned long long mip_info;
  60. unsigned long long delivery_info;
  61. unsigned long long host_reg;
  62. unsigned long long mip_reg;
  63. };
  64. struct part_info {
  65. unsigned char type;
  66. unsigned char length;
  67. unsigned char part_id;
  68. unsigned char apic_mode;
  69. unsigned long snum;
  70. char ptype[16];
  71. char sname[64];
  72. char pname[64];
  73. };
  74. struct psai {
  75. unsigned long long entry_type;
  76. unsigned long long addr;
  77. unsigned long long bep_addr;
  78. };
  79. struct es7000_mem_info {
  80. unsigned char type;
  81. unsigned char length;
  82. unsigned char resv[6];
  83. unsigned long long start;
  84. unsigned long long size;
  85. };
  86. struct es7000_oem_table {
  87. unsigned long long hdr;
  88. struct mip_reg_info mip;
  89. struct part_info pif;
  90. struct es7000_mem_info shm;
  91. struct psai psai;
  92. };
  93. #ifdef CONFIG_ACPI
  94. struct oem_table {
  95. struct acpi_table_header Header;
  96. u32 OEMTableAddr;
  97. u32 OEMTableSize;
  98. };
  99. extern int find_unisys_acpi_oem_table(unsigned long *oem_addr);
  100. extern void unmap_unisys_acpi_oem_table(unsigned long oem_addr);
  101. #endif
  102. struct mip_reg {
  103. unsigned long long off_0;
  104. unsigned long long off_8;
  105. unsigned long long off_10;
  106. unsigned long long off_18;
  107. unsigned long long off_20;
  108. unsigned long long off_28;
  109. unsigned long long off_30;
  110. unsigned long long off_38;
  111. };
  112. #define MIP_SW_APIC 0x1020b
  113. #define MIP_FUNC(VALUE) (VALUE & 0xff)
  114. /*
  115. * ES7000 Globals
  116. */
  117. static volatile unsigned long *psai = NULL;
  118. static struct mip_reg *mip_reg;
  119. static struct mip_reg *host_reg;
  120. static int mip_port;
  121. static unsigned long mip_addr, host_addr;
  122. int es7000_plat;
  123. /*
  124. * GSI override for ES7000 platforms.
  125. */
  126. static unsigned int base;
  127. static int
  128. es7000_rename_gsi(int ioapic, int gsi)
  129. {
  130. if (es7000_plat == ES7000_ZORRO)
  131. return gsi;
  132. if (!base) {
  133. int i;
  134. for (i = 0; i < nr_ioapics; i++)
  135. base += nr_ioapic_registers[i];
  136. }
  137. if (!ioapic && (gsi < 16))
  138. gsi += base;
  139. return gsi;
  140. }
  141. static int wakeup_secondary_cpu_via_mip(int cpu, unsigned long eip)
  142. {
  143. unsigned long vect = 0, psaival = 0;
  144. if (psai == NULL)
  145. return -1;
  146. vect = ((unsigned long)__pa(eip)/0x1000) << 16;
  147. psaival = (0x1000000 | vect | cpu);
  148. while (*psai & 0x1000000)
  149. ;
  150. *psai = psaival;
  151. return 0;
  152. }
  153. static void noop_wait_for_deassert(atomic_t *deassert_not_used)
  154. {
  155. }
  156. static int __init es7000_update_genapic(void)
  157. {
  158. genapic->wakeup_cpu = wakeup_secondary_cpu_via_mip;
  159. /* MPENTIUMIII */
  160. if (boot_cpu_data.x86 == 6 &&
  161. (boot_cpu_data.x86_model >= 7 || boot_cpu_data.x86_model <= 11)) {
  162. es7000_update_genapic_to_cluster();
  163. genapic->wait_for_init_deassert = noop_wait_for_deassert;
  164. genapic->wakeup_cpu = wakeup_secondary_cpu_via_mip;
  165. }
  166. return 0;
  167. }
  168. void __init
  169. setup_unisys(void)
  170. {
  171. /*
  172. * Determine the generation of the ES7000 currently running.
  173. *
  174. * es7000_plat = 1 if the machine is a 5xx ES7000 box
  175. * es7000_plat = 2 if the machine is a x86_64 ES7000 box
  176. *
  177. */
  178. if (!(boot_cpu_data.x86 <= 15 && boot_cpu_data.x86_model <= 2))
  179. es7000_plat = ES7000_ZORRO;
  180. else
  181. es7000_plat = ES7000_CLASSIC;
  182. ioapic_renumber_irq = es7000_rename_gsi;
  183. x86_quirks->update_genapic = es7000_update_genapic;
  184. }
  185. /*
  186. * Parse the OEM Table
  187. */
  188. int __init
  189. parse_unisys_oem (char *oemptr)
  190. {
  191. int i;
  192. int success = 0;
  193. unsigned char type, size;
  194. unsigned long val;
  195. char *tp = NULL;
  196. struct psai *psaip = NULL;
  197. struct mip_reg_info *mi;
  198. struct mip_reg *host, *mip;
  199. tp = oemptr;
  200. tp += 8;
  201. for (i=0; i <= 6; i++) {
  202. type = *tp++;
  203. size = *tp++;
  204. tp -= 2;
  205. switch (type) {
  206. case MIP_REG:
  207. mi = (struct mip_reg_info *)tp;
  208. val = MIP_RD_LO(mi->host_reg);
  209. host_addr = val;
  210. host = (struct mip_reg *)val;
  211. host_reg = __va(host);
  212. val = MIP_RD_LO(mi->mip_reg);
  213. mip_port = MIP_PORT(mi->mip_info);
  214. mip_addr = val;
  215. mip = (struct mip_reg *)val;
  216. mip_reg = __va(mip);
  217. pr_debug("es7000_mipcfg: host_reg = 0x%lx \n",
  218. (unsigned long)host_reg);
  219. pr_debug("es7000_mipcfg: mip_reg = 0x%lx \n",
  220. (unsigned long)mip_reg);
  221. success++;
  222. break;
  223. case MIP_PSAI_REG:
  224. psaip = (struct psai *)tp;
  225. if (tp != NULL) {
  226. if (psaip->addr)
  227. psai = __va(psaip->addr);
  228. else
  229. psai = NULL;
  230. success++;
  231. }
  232. break;
  233. default:
  234. break;
  235. }
  236. tp += size;
  237. }
  238. if (success < 2) {
  239. es7000_plat = NON_UNISYS;
  240. } else
  241. setup_unisys();
  242. return es7000_plat;
  243. }
  244. #ifdef CONFIG_ACPI
  245. static unsigned long oem_addrX;
  246. static unsigned long oem_size;
  247. int __init find_unisys_acpi_oem_table(unsigned long *oem_addr)
  248. {
  249. struct acpi_table_header *header = NULL;
  250. int i = 0;
  251. while (ACPI_SUCCESS(acpi_get_table("OEM1", i++, &header))) {
  252. if (!memcmp((char *) &header->oem_id, "UNISYS", 6)) {
  253. struct oem_table *t = (struct oem_table *)header;
  254. oem_addrX = t->OEMTableAddr;
  255. oem_size = t->OEMTableSize;
  256. *oem_addr = (unsigned long)__acpi_map_table(oem_addrX,
  257. oem_size);
  258. return 0;
  259. }
  260. }
  261. return -1;
  262. }
  263. void __init unmap_unisys_acpi_oem_table(unsigned long oem_addr)
  264. {
  265. }
  266. #endif
  267. static void
  268. es7000_spin(int n)
  269. {
  270. int i = 0;
  271. while (i++ < n)
  272. rep_nop();
  273. }
  274. static int __init
  275. es7000_mip_write(struct mip_reg *mip_reg)
  276. {
  277. int status = 0;
  278. int spin;
  279. spin = MIP_SPIN;
  280. while (((unsigned long long)host_reg->off_38 &
  281. (unsigned long long)MIP_VALID) != 0) {
  282. if (--spin <= 0) {
  283. printk("es7000_mip_write: Timeout waiting for Host Valid Flag");
  284. return -1;
  285. }
  286. es7000_spin(MIP_SPIN);
  287. }
  288. memcpy(host_reg, mip_reg, sizeof(struct mip_reg));
  289. outb(1, mip_port);
  290. spin = MIP_SPIN;
  291. while (((unsigned long long)mip_reg->off_38 &
  292. (unsigned long long)MIP_VALID) == 0) {
  293. if (--spin <= 0) {
  294. printk("es7000_mip_write: Timeout waiting for MIP Valid Flag");
  295. return -1;
  296. }
  297. es7000_spin(MIP_SPIN);
  298. }
  299. status = ((unsigned long long)mip_reg->off_0 &
  300. (unsigned long long)0xffff0000000000ULL) >> 48;
  301. mip_reg->off_38 = ((unsigned long long)mip_reg->off_38 &
  302. (unsigned long long)~MIP_VALID);
  303. return status;
  304. }
  305. void __init
  306. es7000_sw_apic(void)
  307. {
  308. if (es7000_plat) {
  309. int mip_status;
  310. struct mip_reg es7000_mip_reg;
  311. printk("ES7000: Enabling APIC mode.\n");
  312. memset(&es7000_mip_reg, 0, sizeof(struct mip_reg));
  313. es7000_mip_reg.off_0 = MIP_SW_APIC;
  314. es7000_mip_reg.off_38 = (MIP_VALID);
  315. while ((mip_status = es7000_mip_write(&es7000_mip_reg)) != 0)
  316. printk("es7000_sw_apic: command failed, status = %x\n",
  317. mip_status);
  318. return;
  319. }
  320. }