es7000_32.c 7.9 KB

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