vgamga2164w.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. #include "u.h"
  2. #include "../port/lib.h"
  3. #include "mem.h"
  4. #include "dat.h"
  5. #include "fns.h"
  6. #include "io.h"
  7. #include "../port/error.h"
  8. #define Image IMAGE
  9. #include <draw.h>
  10. #include <memdraw.h>
  11. #include <cursor.h>
  12. #include "screen.h"
  13. /*
  14. * Matrox Millennium and Matrox Millennium II.
  15. * Matrox MGA-2064W, MGA-2164W 3D graphics accelerators.
  16. * Texas Instruments Tvp3026 RAMDAC.
  17. */
  18. enum {
  19. /* pci chip manufacturer */
  20. MATROX = 0x102B,
  21. /* pci chip device ids */
  22. MGA2064 = 0x0519,
  23. MGA2164 = 0x051B,
  24. MGA2164AGP = 0x051F
  25. };
  26. static Pcidev*
  27. mgapcimatch(void)
  28. {
  29. Pcidev *p;
  30. p = pcimatch(nil, MATROX, MGA2164AGP);
  31. if(p == nil) {
  32. p = pcimatch(nil, MATROX, MGA2164);
  33. if(p == nil)
  34. p = pcimatch(nil, MATROX, MGA2064);
  35. }
  36. return p;
  37. }
  38. static void
  39. mga2164wenable(VGAscr* scr)
  40. {
  41. Pcidev *p;
  42. if(scr->mmio)
  43. return;
  44. p = mgapcimatch();
  45. if(p == nil)
  46. return;
  47. if(p->did == MGA2064){
  48. scr->mmio = vmap(p->mem[0].bar&~0x0F, p->mem[0].size);
  49. if(scr->mmio == nil)
  50. return;
  51. addvgaseg("mga2164wmmio", p->mem[0].bar&~0x0F, p->mem[0].size);
  52. vgalinearaddr(scr, p->mem[1].bar&~0x0F, 8*MB);
  53. }else{
  54. scr->mmio = vmap(p->mem[1].bar&~0x0F, p->mem[1].size);
  55. if(scr->mmio == nil)
  56. return;
  57. addvgaseg("mga2164wmmio", p->mem[1].bar&~0x0F, p->mem[1].size);
  58. vgalinearaddr(scr, p->mem[0].bar&~0x0F, 16*MB);
  59. }
  60. if(scr->paddr)
  61. addvgaseg("mga2164wscreen", scr->paddr, scr->apsize);
  62. }
  63. enum {
  64. Index = 0x00, /* Index */
  65. Data = 0x0A, /* Data */
  66. CaddrW = 0x04, /* Colour Write Address */
  67. Cdata = 0x05, /* Colour Data */
  68. Cctl = 0x09, /* Direct Cursor Control */
  69. Cram = 0x0B, /* Cursor Ram Data */
  70. Cxlsb = 0x0C, /* Cursor X LSB */
  71. Cxmsb = 0x0D, /* Cursor X MSB */
  72. Cylsb = 0x0E, /* Cursor Y LSB */
  73. Cymsb = 0x0F, /* Cursor Y MSB */
  74. Icctl = 0x06, /* Indirect Cursor Control */
  75. };
  76. static void
  77. tvp3026disable(VGAscr* scr)
  78. {
  79. uchar *tvp3026;
  80. if(scr->mmio == 0)
  81. return;
  82. tvp3026 = (uchar*)scr->mmio+0x3C00;
  83. /*
  84. * Make sure cursor is off
  85. * and direct control enabled.
  86. */
  87. *(tvp3026+Index) = Icctl;
  88. *(tvp3026+Data) = 0x90;
  89. *(tvp3026+Cctl) = 0x00;
  90. }
  91. static void
  92. tvp3026load(VGAscr* scr, Cursor* curs)
  93. {
  94. int x, y;
  95. uchar *tvp3026;
  96. if(scr->mmio == 0)
  97. return;
  98. tvp3026 = (uchar*)scr->mmio+0x3C00;
  99. /*
  100. * Make sure cursor is off by initialising the cursor
  101. * control to defaults.
  102. * Write to the indirect control register to make sure
  103. * direct register is enabled and upper 2 bits of cursor
  104. * RAM address are 0.
  105. * Put 0 in index register for lower 8 bits of cursor RAM address.
  106. */
  107. tvp3026disable(scr);
  108. *(tvp3026+Index) = 0;
  109. /*
  110. * Initialise the 64x64 cursor RAM array. There are 2 planes,
  111. * p0 and p1. Data is written 8 pixels per byte, with p0 in the
  112. * first 512 bytes of the array and p1 in the second.
  113. * The cursor is set in 3-colour mode which gives the following
  114. * truth table:
  115. * p1 p0 colour
  116. * 0 0 transparent
  117. * 0 1 cursor colour 0
  118. * 1 0 cursor colour 1
  119. * 1 1 cursor colour 2
  120. * Put the cursor into the top-left of the 64x64 array.
  121. * The 0,0 cursor point is bottom-right, so positioning will
  122. * have to take that into account.
  123. */
  124. for(y = 0; y < 64; y++){
  125. for(x = 0; x < 64/8; x++){
  126. if(x < 16/8 && y < 16)
  127. *(tvp3026+Cram) = curs->clr[x+y*2];
  128. else
  129. *(tvp3026+Cram) = 0x00;
  130. }
  131. }
  132. for(y = 0; y < 64; y++){
  133. for(x = 0; x < 64/8; x++){
  134. if(x < 16/8 && y < 16)
  135. *(tvp3026+Cram) = curs->set[x+y*2];
  136. else
  137. *(tvp3026+Cram) = 0x00;
  138. }
  139. }
  140. /*
  141. * Initialise the cursor hotpoint
  142. * and enable the cursor in 3-colour mode.
  143. */
  144. scr->offset.x = 64+curs->offset.x;
  145. scr->offset.y = 64+curs->offset.y;
  146. *(tvp3026+Cctl) = 0x01;
  147. }
  148. static int
  149. tvp3026move(VGAscr* scr, Point p)
  150. {
  151. int x, y;
  152. uchar *tvp3026;
  153. if(scr->mmio == 0)
  154. return 1;
  155. tvp3026 = (uchar*)scr->mmio+0x3C00;
  156. x = p.x+scr->offset.x;
  157. y = p.y+scr->offset.y;
  158. *(tvp3026+Cxlsb) = x & 0xFF;
  159. *(tvp3026+Cxmsb) = (x>>8) & 0x0F;
  160. *(tvp3026+Cylsb) = y & 0xFF;
  161. *(tvp3026+Cymsb) = (y>>8) & 0x0F;
  162. return 0;
  163. }
  164. static void
  165. tvp3026enable(VGAscr* scr)
  166. {
  167. int i;
  168. uchar *tvp3026;
  169. if(scr->mmio == 0)
  170. return;
  171. tvp3026 = (uchar*)scr->mmio+0x3C00;
  172. tvp3026disable(scr);
  173. /*
  174. * Overscan colour,
  175. * cursor colour 1 (white),
  176. * cursor colour 2, 3 (black).
  177. */
  178. *(tvp3026+CaddrW) = 0x00;
  179. for(i = 0; i < 6; i++)
  180. *(tvp3026+Cdata) = Pwhite;
  181. for(i = 0; i < 6; i++)
  182. *(tvp3026+Cdata) = Pblack;
  183. /*
  184. * Load, locate and enable the
  185. * 64x64 cursor in 3-colour mode.
  186. */
  187. tvp3026load(scr, &arrow);
  188. tvp3026move(scr, ZP);
  189. *(tvp3026+Cctl) = 0x01;
  190. }
  191. VGAdev vgamga2164wdev = {
  192. "mga2164w",
  193. mga2164wenable, /* enable */
  194. 0, /* disable */
  195. 0, /* page */
  196. 0, /* linear */
  197. };
  198. VGAcur vgamga2164wcur = {
  199. "mga2164whwgc",
  200. tvp3026enable,
  201. tvp3026disable,
  202. tvp3026load,
  203. tvp3026move,
  204. };