es7000plat.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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. /*
  43. * ES7000 Globals
  44. */
  45. volatile unsigned long *psai = NULL;
  46. struct mip_reg *mip_reg;
  47. struct mip_reg *host_reg;
  48. int mip_port;
  49. unsigned long mip_addr, host_addr;
  50. #if defined(CONFIG_X86_IO_APIC) && (defined(CONFIG_ACPI_INTERPRETER) || defined(CONFIG_ACPI_BOOT))
  51. /*
  52. * GSI override for ES7000 platforms.
  53. */
  54. static unsigned int base;
  55. static int
  56. es7000_rename_gsi(int ioapic, int gsi)
  57. {
  58. if (!base) {
  59. int i;
  60. for (i = 0; i < nr_ioapics; i++)
  61. base += nr_ioapic_registers[i];
  62. }
  63. if (!ioapic && (gsi < 16))
  64. gsi += base;
  65. return gsi;
  66. }
  67. #endif // (CONFIG_X86_IO_APIC) && (CONFIG_ACPI_INTERPRETER || CONFIG_ACPI_BOOT)
  68. /*
  69. * Parse the OEM Table
  70. */
  71. int __init
  72. parse_unisys_oem (char *oemptr, int oem_entries)
  73. {
  74. int i;
  75. int success = 0;
  76. unsigned char type, size;
  77. unsigned long val;
  78. char *tp = NULL;
  79. struct psai *psaip = NULL;
  80. struct mip_reg_info *mi;
  81. struct mip_reg *host, *mip;
  82. tp = oemptr;
  83. tp += 8;
  84. for (i=0; i <= oem_entries; i++) {
  85. type = *tp++;
  86. size = *tp++;
  87. tp -= 2;
  88. switch (type) {
  89. case MIP_REG:
  90. mi = (struct mip_reg_info *)tp;
  91. val = MIP_RD_LO(mi->host_reg);
  92. host_addr = val;
  93. host = (struct mip_reg *)val;
  94. host_reg = __va(host);
  95. val = MIP_RD_LO(mi->mip_reg);
  96. mip_port = MIP_PORT(mi->mip_info);
  97. mip_addr = val;
  98. mip = (struct mip_reg *)val;
  99. mip_reg = __va(mip);
  100. Dprintk("es7000_mipcfg: host_reg = 0x%lx \n",
  101. (unsigned long)host_reg);
  102. Dprintk("es7000_mipcfg: mip_reg = 0x%lx \n",
  103. (unsigned long)mip_reg);
  104. success++;
  105. break;
  106. case MIP_PSAI_REG:
  107. psaip = (struct psai *)tp;
  108. if (tp != NULL) {
  109. if (psaip->addr)
  110. psai = __va(psaip->addr);
  111. else
  112. psai = NULL;
  113. success++;
  114. }
  115. break;
  116. default:
  117. break;
  118. }
  119. if (i == 6) break;
  120. tp += size;
  121. }
  122. if (success < 2) {
  123. es7000_plat = 0;
  124. } else {
  125. printk("\nEnabling ES7000 specific features...\n");
  126. /*
  127. * Determine the generation of the ES7000 currently running.
  128. *
  129. * es7000_plat = 0 if the machine is NOT a Unisys ES7000 box
  130. * es7000_plat = 1 if the machine is a 5xx ES7000 box
  131. * es7000_plat = 2 if the machine is a x86_64 ES7000 box
  132. *
  133. */
  134. if (!(boot_cpu_data.x86 <= 15 && boot_cpu_data.x86_model <= 2))
  135. es7000_plat = 2;
  136. else
  137. es7000_plat = 1;
  138. ioapic_renumber_irq = es7000_rename_gsi;
  139. }
  140. return es7000_plat;
  141. }
  142. int __init
  143. find_unisys_acpi_oem_table(unsigned long *oem_addr, int *length)
  144. {
  145. struct acpi_table_rsdp *rsdp = NULL;
  146. unsigned long rsdp_phys = 0;
  147. struct acpi_table_header *header = NULL;
  148. int i;
  149. struct acpi_table_sdt sdt;
  150. rsdp_phys = acpi_find_rsdp();
  151. rsdp = __va(rsdp_phys);
  152. if (rsdp->rsdt_address) {
  153. struct acpi_table_rsdt *mapped_rsdt = NULL;
  154. sdt.pa = rsdp->rsdt_address;
  155. header = (struct acpi_table_header *)
  156. __acpi_map_table(sdt.pa, sizeof(struct acpi_table_header));
  157. if (!header)
  158. return -ENODEV;
  159. sdt.count = (header->length - sizeof(struct acpi_table_header)) >> 3;
  160. mapped_rsdt = (struct acpi_table_rsdt *)
  161. __acpi_map_table(sdt.pa, header->length);
  162. if (!mapped_rsdt)
  163. return -ENODEV;
  164. header = &mapped_rsdt->header;
  165. for (i = 0; i < sdt.count; i++)
  166. sdt.entry[i].pa = (unsigned long) mapped_rsdt->entry[i];
  167. };
  168. for (i = 0; i < sdt.count; i++) {
  169. header = (struct acpi_table_header *)
  170. __acpi_map_table(sdt.entry[i].pa,
  171. sizeof(struct acpi_table_header));
  172. if (!header)
  173. continue;
  174. if (!strncmp((char *) &header->signature, "OEM1", 4)) {
  175. if (!strncmp((char *) &header->oem_id, "UNISYS", 6)) {
  176. void *addr;
  177. struct oem_table *t;
  178. acpi_table_print(header, sdt.entry[i].pa);
  179. t = (struct oem_table *) __acpi_map_table(sdt.entry[i].pa, header->length);
  180. addr = (void *) __acpi_map_table(t->OEMTableAddr, t->OEMTableSize);
  181. *length = header->length;
  182. *oem_addr = (unsigned long) addr;
  183. return 0;
  184. }
  185. }
  186. }
  187. Dprintk("ES7000: did not find Unisys ACPI OEM table!\n");
  188. return -1;
  189. }
  190. static void
  191. es7000_spin(int n)
  192. {
  193. int i = 0;
  194. while (i++ < n)
  195. rep_nop();
  196. }
  197. static int __init
  198. es7000_mip_write(struct mip_reg *mip_reg)
  199. {
  200. int status = 0;
  201. int spin;
  202. spin = MIP_SPIN;
  203. while (((unsigned long long)host_reg->off_38 &
  204. (unsigned long long)MIP_VALID) != 0) {
  205. if (--spin <= 0) {
  206. printk("es7000_mip_write: Timeout waiting for Host Valid Flag");
  207. return -1;
  208. }
  209. es7000_spin(MIP_SPIN);
  210. }
  211. memcpy(host_reg, mip_reg, sizeof(struct mip_reg));
  212. outb(1, mip_port);
  213. spin = MIP_SPIN;
  214. while (((unsigned long long)mip_reg->off_38 &
  215. (unsigned long long)MIP_VALID) == 0) {
  216. if (--spin <= 0) {
  217. printk("es7000_mip_write: Timeout waiting for MIP Valid Flag");
  218. return -1;
  219. }
  220. es7000_spin(MIP_SPIN);
  221. }
  222. status = ((unsigned long long)mip_reg->off_0 &
  223. (unsigned long long)0xffff0000000000ULL) >> 48;
  224. mip_reg->off_38 = ((unsigned long long)mip_reg->off_38 &
  225. (unsigned long long)~MIP_VALID);
  226. return status;
  227. }
  228. int
  229. es7000_start_cpu(int cpu, unsigned long eip)
  230. {
  231. unsigned long vect = 0, psaival = 0;
  232. if (psai == NULL)
  233. return -1;
  234. vect = ((unsigned long)__pa(eip)/0x1000) << 16;
  235. psaival = (0x1000000 | vect | cpu);
  236. while (*psai & 0x1000000)
  237. ;
  238. *psai = psaival;
  239. return 0;
  240. }
  241. int
  242. es7000_stop_cpu(int cpu)
  243. {
  244. int startup;
  245. if (psai == NULL)
  246. return -1;
  247. startup= (0x1000000 | cpu);
  248. while ((*psai & 0xff00ffff) != startup)
  249. ;
  250. startup = (*psai & 0xff0000) >> 16;
  251. *psai &= 0xffffff;
  252. return 0;
  253. }
  254. void __init
  255. es7000_sw_apic()
  256. {
  257. if (es7000_plat) {
  258. int mip_status;
  259. struct mip_reg es7000_mip_reg;
  260. printk("ES7000: Enabling APIC mode.\n");
  261. memset(&es7000_mip_reg, 0, sizeof(struct mip_reg));
  262. es7000_mip_reg.off_0 = MIP_SW_APIC;
  263. es7000_mip_reg.off_38 = (MIP_VALID);
  264. while ((mip_status = es7000_mip_write(&es7000_mip_reg)) != 0)
  265. printk("es7000_sw_apic: command failed, status = %x\n",
  266. mip_status);
  267. return;
  268. }
  269. }