es7000_32.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  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 <mach_mpparse.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. #ifdef CONFIG_ES7000_CLUSTERED_APIC
  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 int __init es7000_update_genapic(void)
  154. {
  155. genapic->wakeup_cpu = wakeup_secondary_cpu_via_mip;
  156. return 0;
  157. }
  158. #endif
  159. void __init
  160. setup_unisys(void)
  161. {
  162. /*
  163. * Determine the generation of the ES7000 currently running.
  164. *
  165. * es7000_plat = 1 if the machine is a 5xx ES7000 box
  166. * es7000_plat = 2 if the machine is a x86_64 ES7000 box
  167. *
  168. */
  169. if (!(boot_cpu_data.x86 <= 15 && boot_cpu_data.x86_model <= 2))
  170. es7000_plat = ES7000_ZORRO;
  171. else
  172. es7000_plat = ES7000_CLASSIC;
  173. ioapic_renumber_irq = es7000_rename_gsi;
  174. #ifdef CONFIG_ES7000_CLUSTERED_APIC
  175. x86_quirks->update_genapic = es7000_update_genapic;
  176. #endif
  177. }
  178. /*
  179. * Parse the OEM Table
  180. */
  181. int __init
  182. parse_unisys_oem (char *oemptr)
  183. {
  184. int i;
  185. int success = 0;
  186. unsigned char type, size;
  187. unsigned long val;
  188. char *tp = NULL;
  189. struct psai *psaip = NULL;
  190. struct mip_reg_info *mi;
  191. struct mip_reg *host, *mip;
  192. tp = oemptr;
  193. tp += 8;
  194. for (i=0; i <= 6; i++) {
  195. type = *tp++;
  196. size = *tp++;
  197. tp -= 2;
  198. switch (type) {
  199. case MIP_REG:
  200. mi = (struct mip_reg_info *)tp;
  201. val = MIP_RD_LO(mi->host_reg);
  202. host_addr = val;
  203. host = (struct mip_reg *)val;
  204. host_reg = __va(host);
  205. val = MIP_RD_LO(mi->mip_reg);
  206. mip_port = MIP_PORT(mi->mip_info);
  207. mip_addr = val;
  208. mip = (struct mip_reg *)val;
  209. mip_reg = __va(mip);
  210. pr_debug("es7000_mipcfg: host_reg = 0x%lx \n",
  211. (unsigned long)host_reg);
  212. pr_debug("es7000_mipcfg: mip_reg = 0x%lx \n",
  213. (unsigned long)mip_reg);
  214. success++;
  215. break;
  216. case MIP_PSAI_REG:
  217. psaip = (struct psai *)tp;
  218. if (tp != NULL) {
  219. if (psaip->addr)
  220. psai = __va(psaip->addr);
  221. else
  222. psai = NULL;
  223. success++;
  224. }
  225. break;
  226. default:
  227. break;
  228. }
  229. tp += size;
  230. }
  231. if (success < 2) {
  232. es7000_plat = NON_UNISYS;
  233. } else
  234. setup_unisys();
  235. return es7000_plat;
  236. }
  237. #ifdef CONFIG_ACPI
  238. static unsigned long oem_addrX;
  239. static unsigned long oem_size;
  240. int __init find_unisys_acpi_oem_table(unsigned long *oem_addr)
  241. {
  242. struct acpi_table_header *header = NULL;
  243. int i = 0;
  244. acpi_size tbl_size;
  245. while (ACPI_SUCCESS(acpi_get_table_with_size("OEM1", i++, &header, &tbl_size))) {
  246. if (!memcmp((char *) &header->oem_id, "UNISYS", 6)) {
  247. struct oem_table *t = (struct oem_table *)header;
  248. oem_addrX = t->OEMTableAddr;
  249. oem_size = t->OEMTableSize;
  250. early_acpi_os_unmap_memory(header, tbl_size);
  251. *oem_addr = (unsigned long)__acpi_map_table(oem_addrX,
  252. oem_size);
  253. return 0;
  254. }
  255. early_acpi_os_unmap_memory(header, tbl_size);
  256. }
  257. return -1;
  258. }
  259. void __init unmap_unisys_acpi_oem_table(unsigned long oem_addr)
  260. {
  261. if (!oem_addr)
  262. return;
  263. __acpi_unmap_table((char *)oem_addr, oem_size);
  264. }
  265. #endif
  266. static void
  267. es7000_spin(int n)
  268. {
  269. int i = 0;
  270. while (i++ < n)
  271. rep_nop();
  272. }
  273. static int __init
  274. es7000_mip_write(struct mip_reg *mip_reg)
  275. {
  276. int status = 0;
  277. int spin;
  278. spin = MIP_SPIN;
  279. while (((unsigned long long)host_reg->off_38 &
  280. (unsigned long long)MIP_VALID) != 0) {
  281. if (--spin <= 0) {
  282. printk("es7000_mip_write: Timeout waiting for Host Valid Flag");
  283. return -1;
  284. }
  285. es7000_spin(MIP_SPIN);
  286. }
  287. memcpy(host_reg, mip_reg, sizeof(struct mip_reg));
  288. outb(1, mip_port);
  289. spin = MIP_SPIN;
  290. while (((unsigned long long)mip_reg->off_38 &
  291. (unsigned long long)MIP_VALID) == 0) {
  292. if (--spin <= 0) {
  293. printk("es7000_mip_write: Timeout waiting for MIP Valid Flag");
  294. return -1;
  295. }
  296. es7000_spin(MIP_SPIN);
  297. }
  298. status = ((unsigned long long)mip_reg->off_0 &
  299. (unsigned long long)0xffff0000000000ULL) >> 48;
  300. mip_reg->off_38 = ((unsigned long long)mip_reg->off_38 &
  301. (unsigned long long)~MIP_VALID);
  302. return status;
  303. }
  304. void __init
  305. es7000_sw_apic(void)
  306. {
  307. if (es7000_plat) {
  308. int mip_status;
  309. struct mip_reg es7000_mip_reg;
  310. printk("ES7000: Enabling APIC mode.\n");
  311. memset(&es7000_mip_reg, 0, sizeof(struct mip_reg));
  312. es7000_mip_reg.off_0 = MIP_SW_APIC;
  313. es7000_mip_reg.off_38 = (MIP_VALID);
  314. while ((mip_status = es7000_mip_write(&es7000_mip_reg)) != 0)
  315. printk("es7000_sw_apic: command failed, status = %x\n",
  316. mip_status);
  317. return;
  318. }
  319. }