es7000_32.c 7.2 KB

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