arch164.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. /*
  2. * EB164 and similar
  3. * CPU: 21164
  4. * Core Logic: 21172 CIA or 21174 PYXIS
  5. */
  6. #include "u.h"
  7. #include "../port/lib.h"
  8. #include "mem.h"
  9. #include "dat.h"
  10. #include "fns.h"
  11. #include "io.h"
  12. static ulong *core;
  13. static ulong *wind;
  14. static ulong windsave[16];
  15. static ulong coresave[1];
  16. ulong iobase0;
  17. ulong iobase1;
  18. #define iobase(p) (iobase0+(p))
  19. static int
  20. ident(void)
  21. {
  22. return 0; /* bug! */
  23. }
  24. static uvlong* sgmap;
  25. static void
  26. sginit(void)
  27. {
  28. ulong pa;
  29. uvlong *pte;
  30. sgmap = xspanalloc(BY2PG, BY2PG, 0);
  31. memset(sgmap, 0, BY2PG);
  32. /*
  33. * Prepare scatter-gather map for 0-8MB.
  34. */
  35. pte = sgmap;
  36. for(pa = 0; pa < 8*1024*1024; pa += BY2PG)
  37. *pte++ = ((pa>>PGSHIFT)<<1)|1;
  38. /*
  39. * Set up a map for ISA DMA accesses to physical memory.
  40. * Addresses presented by an ISA device between ISAWINDOW
  41. * and ISAWINDOW+8MB will be translated to between 0 and
  42. * 0+8MB of physical memory.
  43. */
  44. wind[0x400/4] = ISAWINDOW|2|1; /* window base */
  45. wind[0x440/4] = 0x00700000; /* window mask */
  46. wind[0x480/4] = PADDR(sgmap)>>2; /* <33:10> of sg map */
  47. wind[0x100/4] = 3; /* invalidate tlb cache */
  48. }
  49. static void *
  50. kmapio(ulong space, ulong offset, int size)
  51. {
  52. return kmapv(((uvlong)space<<32LL)|offset, size);
  53. }
  54. static void
  55. coreinit(void)
  56. {
  57. int i;
  58. core = kmapio(0x87, 0x40000000, 0x10000);
  59. wind = kmapio(0x87, 0x60000000, 0x1000);
  60. iobase0 = (ulong)kmapio(0x89, 0, 0x20000);
  61. /* hae_io = core[0x440/4];
  62. iobase1 = (ulong)kmapio(0x89, hae_io, 0x10000); */
  63. /* save critical parts of hardware memory mapping */
  64. for (i = 4; i < 8; i++) {
  65. windsave[4*(i-4)+0] = wind[(i*0x100+0x00)/4];
  66. windsave[4*(i-4)+1] = wind[(i*0x100+0x40)/4];
  67. windsave[4*(i-4)+2] = wind[(i*0x100+0x80)/4];
  68. }
  69. coresave[0] = core[0x140/4];
  70. /* disable windows */
  71. wind[0x400/4] = 0;
  72. wind[0x500/4] = 0;
  73. wind[0x600/4] = 0;
  74. wind[0x700/4] = 0;
  75. sginit();
  76. /*
  77. * Set up a map for PCI DMA accesses to physical memory.
  78. * Addresses presented by a PCI device between PCIWINDOW
  79. * and PCIWINDOW+1GB will be translated to between 0 and
  80. * 0+1GB of physical memory.
  81. */
  82. wind[0x500/4] = PCIWINDOW|1;
  83. wind[0x540/4] = 0x3ff00000;
  84. wind[0x580/4] = 0;
  85. /* clear error state */
  86. core[0x8200/4] = 0x7ff;
  87. /* set config: byte/word enable, no monster window, etc. */
  88. core[0x140/4] = 0x21;
  89. /* turn off mcheck on master abort. now we can probe PCI space. */
  90. core[0x8280/4] &= ~(1<<7);
  91. /* set up interrupts. */
  92. i8259init();
  93. cserve(52, 4); /* enable SIO interrupt */
  94. }
  95. void
  96. ciaerror(void)
  97. {
  98. print("cia error 0x%luX\n", core[0x8200/4]);
  99. }
  100. static void
  101. corehello(void)
  102. {
  103. print("cpu%d: CIA revision %ld; cnfg %lux cntrl %lux\n",
  104. 0, /* BUG */
  105. core[0x80/4] & 0x7f, core[0x140/4], core[0x100/4]);
  106. print("cpu%d: HAE_IO %lux\n", 0, core[0x440/4]);
  107. print("\n");
  108. }
  109. static void
  110. coredetach(void)
  111. {
  112. int i;
  113. for (i = 4; i < 8; i++) {
  114. wind[(i*0x100+0x00)/4] = windsave[4*(i-4)+0];
  115. wind[(i*0x100+0x40)/4] = windsave[4*(i-4)+1];
  116. wind[(i*0x100+0x80)/4] = windsave[4*(i-4)+2];
  117. }
  118. core[0x140/4] = coresave[0];
  119. /* for (i = 0; i < 4; i++)
  120. if (i != 4)
  121. cserve(53, i); /* disable interrupts */
  122. }
  123. static Lock pcicfgl;
  124. static ulong pcimap[256];
  125. static void*
  126. pcicfg2117x(int tbdf, int rno)
  127. {
  128. int space, bus;
  129. ulong base;
  130. bus = BUSBNO(tbdf);
  131. lock(&pcicfgl);
  132. base = pcimap[bus];
  133. if (base == 0) {
  134. if(bus)
  135. space = 0x8B;
  136. else
  137. space = 0x8A;
  138. pcimap[bus] = base = (ulong)kmapio(space, MKBUS(0, bus, 0, 0), (1<<16));
  139. }
  140. unlock(&pcicfgl);
  141. return (void*)(base + BUSDF(tbdf) + rno);
  142. }
  143. static void*
  144. pcimem2117x(int addr, int len)
  145. {
  146. return kmapio(0x88, addr, len);
  147. }
  148. static int
  149. intrenable164(Vctl *v)
  150. {
  151. int vec, irq;
  152. irq = v->irq;
  153. if(irq > MaxIrqPIC) {
  154. print("intrenable: irq %d out of range\n", v->irq);
  155. return -1;
  156. }
  157. if(BUSTYPE(v->tbdf) == BusPCI) {
  158. vec = irq+VectorPCI;
  159. cserve(52, irq);
  160. }
  161. else {
  162. vec = irq+VectorPIC;
  163. if(i8259enable(irq, v->tbdf, v) == -1)
  164. return -1;
  165. }
  166. return vec;
  167. }
  168. /*
  169. * I have a function pointer in PCArch for every one of these, because on
  170. * some Alphas we have to use sparse mode, but on others we can use
  171. * MOVB et al. Additionally, the PC164 documentation threatened us
  172. * with the lie that the SIO is in region B, but everything else in region A.
  173. * This turned out not to be the case. Given the cost of this solution, it
  174. * may be better just to use sparse mode for I/O space on all platforms.
  175. */
  176. int
  177. inb2117x(int port)
  178. {
  179. mb();
  180. return *(uchar*)(iobase(port));
  181. }
  182. ushort
  183. ins2117x(int port)
  184. {
  185. mb();
  186. return *(ushort*)(iobase(port));
  187. }
  188. ulong
  189. inl2117x(int port)
  190. {
  191. mb();
  192. return *(ulong*)(iobase(port));
  193. }
  194. void
  195. outb2117x(int port, int val)
  196. {
  197. mb();
  198. *(uchar*)(iobase(port)) = val;
  199. mb();
  200. }
  201. void
  202. outs2117x(int port, ushort val)
  203. {
  204. mb();
  205. *(ushort*)(iobase(port)) = val;
  206. mb();
  207. }
  208. void
  209. outl2117x(int port, ulong val)
  210. {
  211. mb();
  212. *(ulong*)(iobase(port)) = val;
  213. mb();
  214. }
  215. void
  216. insb2117x(int port, void *buf, int len)
  217. {
  218. int i;
  219. uchar *p, *q;
  220. p = (uchar*)iobase(port);
  221. q = buf;
  222. for(i = 0; i < len; i++){
  223. mb();
  224. *q++ = *p;
  225. }
  226. }
  227. void
  228. inss2117x(int port, void *buf, int len)
  229. {
  230. int i;
  231. ushort *p, *q;
  232. p = (ushort*)iobase(port);
  233. q = buf;
  234. for(i = 0; i < len; i++){
  235. mb();
  236. *q++ = *p;
  237. }
  238. }
  239. void
  240. insl2117x(int port, void *buf, int len)
  241. {
  242. int i;
  243. ulong *p, *q;
  244. p = (ulong*)iobase(port);
  245. q = buf;
  246. for(i = 0; i < len; i++){
  247. mb();
  248. *q++ = *p;
  249. }
  250. }
  251. void
  252. outsb2117x(int port, void *buf, int len)
  253. {
  254. int i;
  255. uchar *p, *q;
  256. p = (uchar*)iobase(port);
  257. q = buf;
  258. for(i = 0; i < len; i++){
  259. mb();
  260. *p = *q++;
  261. }
  262. }
  263. void
  264. outss2117x(int port, void *buf, int len)
  265. {
  266. int i;
  267. ushort *p, *q;
  268. p = (ushort*)iobase(port);
  269. q = buf;
  270. for(i = 0; i < len; i++){
  271. mb();
  272. *p = *q++;
  273. }
  274. }
  275. void
  276. outsl2117x(int port, void *buf, int len)
  277. {
  278. int i;
  279. ulong *p, *q;
  280. p = (ulong*)iobase(port);
  281. q = buf;
  282. for(i = 0; i < len; i++){
  283. mb();
  284. *p = *q++;
  285. }
  286. }
  287. PCArch arch164 = {
  288. "EB164",
  289. ident,
  290. coreinit,
  291. corehello,
  292. coredetach,
  293. pcicfg2117x,
  294. pcimem2117x,
  295. intrenable164,
  296. nil,
  297. nil,
  298. inb2117x,
  299. ins2117x,
  300. inl2117x,
  301. outb2117x,
  302. outs2117x,
  303. outl2117x,
  304. insb2117x,
  305. inss2117x,
  306. insl2117x,
  307. outsb2117x,
  308. outss2117x,
  309. outsl2117x,
  310. };