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