vgamga2164w.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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. vgalinearaddr(scr, p->mem[1].bar&~0x0F, 8*MB);
  52. }else{
  53. scr->mmio = vmap(p->mem[1].bar&~0x0F, p->mem[1].size);
  54. if(scr->mmio == nil)
  55. return;
  56. vgalinearaddr(scr, p->mem[0].bar&~0x0F, 16*MB);
  57. }
  58. if(scr->paddr)
  59. addvgaseg("mga2164wscreen", scr->paddr, scr->apsize);
  60. }
  61. enum {
  62. Index = 0x00, /* Index */
  63. Data = 0x0A, /* Data */
  64. CaddrW = 0x04, /* Colour Write Address */
  65. Cdata = 0x05, /* Colour Data */
  66. Cctl = 0x09, /* Direct Cursor Control */
  67. Cram = 0x0B, /* Cursor Ram Data */
  68. Cxlsb = 0x0C, /* Cursor X LSB */
  69. Cxmsb = 0x0D, /* Cursor X MSB */
  70. Cylsb = 0x0E, /* Cursor Y LSB */
  71. Cymsb = 0x0F, /* Cursor Y MSB */
  72. Icctl = 0x06, /* Indirect Cursor Control */
  73. };
  74. static void
  75. tvp3026disable(VGAscr* scr)
  76. {
  77. uchar *tvp3026;
  78. if(scr->mmio == 0)
  79. return;
  80. tvp3026 = (uchar*)scr->mmio+0x3C00;
  81. /*
  82. * Make sure cursor is off
  83. * and direct control enabled.
  84. */
  85. *(tvp3026+Index) = Icctl;
  86. *(tvp3026+Data) = 0x90;
  87. *(tvp3026+Cctl) = 0x00;
  88. }
  89. static void
  90. tvp3026load(VGAscr* scr, Cursor* curs)
  91. {
  92. int x, y;
  93. uchar *tvp3026;
  94. if(scr->mmio == 0)
  95. return;
  96. tvp3026 = (uchar*)scr->mmio+0x3C00;
  97. /*
  98. * Make sure cursor is off by initialising the cursor
  99. * control to defaults.
  100. * Write to the indirect control register to make sure
  101. * direct register is enabled and upper 2 bits of cursor
  102. * RAM address are 0.
  103. * Put 0 in index register for lower 8 bits of cursor RAM address.
  104. */
  105. tvp3026disable(scr);
  106. *(tvp3026+Index) = 0;
  107. /*
  108. * Initialise the 64x64 cursor RAM array. There are 2 planes,
  109. * p0 and p1. Data is written 8 pixels per byte, with p0 in the
  110. * first 512 bytes of the array and p1 in the second.
  111. * The cursor is set in 3-colour mode which gives the following
  112. * truth table:
  113. * p1 p0 colour
  114. * 0 0 transparent
  115. * 0 1 cursor colour 0
  116. * 1 0 cursor colour 1
  117. * 1 1 cursor colour 2
  118. * Put the cursor into the top-left of the 64x64 array.
  119. * The 0,0 cursor point is bottom-right, so positioning will
  120. * have to take that into account.
  121. */
  122. for(y = 0; y < 64; y++){
  123. for(x = 0; x < 64/8; x++){
  124. if(x < 16/8 && y < 16)
  125. *(tvp3026+Cram) = curs->clr[x+y*2];
  126. else
  127. *(tvp3026+Cram) = 0x00;
  128. }
  129. }
  130. for(y = 0; y < 64; y++){
  131. for(x = 0; x < 64/8; x++){
  132. if(x < 16/8 && y < 16)
  133. *(tvp3026+Cram) = curs->set[x+y*2];
  134. else
  135. *(tvp3026+Cram) = 0x00;
  136. }
  137. }
  138. /*
  139. * Initialise the cursor hotpoint
  140. * and enable the cursor in 3-colour mode.
  141. */
  142. scr->offset.x = 64+curs->offset.x;
  143. scr->offset.y = 64+curs->offset.y;
  144. *(tvp3026+Cctl) = 0x01;
  145. }
  146. static int
  147. tvp3026move(VGAscr* scr, Point p)
  148. {
  149. int x, y;
  150. uchar *tvp3026;
  151. if(scr->mmio == 0)
  152. return 1;
  153. tvp3026 = (uchar*)scr->mmio+0x3C00;
  154. x = p.x+scr->offset.x;
  155. y = p.y+scr->offset.y;
  156. *(tvp3026+Cxlsb) = x & 0xFF;
  157. *(tvp3026+Cxmsb) = (x>>8) & 0x0F;
  158. *(tvp3026+Cylsb) = y & 0xFF;
  159. *(tvp3026+Cymsb) = (y>>8) & 0x0F;
  160. return 0;
  161. }
  162. static void
  163. tvp3026enable(VGAscr* scr)
  164. {
  165. int i;
  166. uchar *tvp3026;
  167. if(scr->mmio == 0)
  168. return;
  169. tvp3026 = (uchar*)scr->mmio+0x3C00;
  170. tvp3026disable(scr);
  171. /*
  172. * Overscan colour,
  173. * cursor colour 1 (white),
  174. * cursor colour 2, 3 (black).
  175. */
  176. *(tvp3026+CaddrW) = 0x00;
  177. for(i = 0; i < 6; i++)
  178. *(tvp3026+Cdata) = Pwhite;
  179. for(i = 0; i < 6; i++)
  180. *(tvp3026+Cdata) = Pblack;
  181. /*
  182. * Load, locate and enable the
  183. * 64x64 cursor in 3-colour mode.
  184. */
  185. tvp3026load(scr, &arrow);
  186. tvp3026move(scr, ZP);
  187. *(tvp3026+Cctl) = 0x01;
  188. }
  189. VGAdev vgamga2164wdev = {
  190. "mga2164w",
  191. mga2164wenable, /* enable */
  192. 0, /* disable */
  193. 0, /* page */
  194. 0, /* linear */
  195. };
  196. VGAcur vgamga2164wcur = {
  197. "mga2164whwgc",
  198. tvp3026enable,
  199. tvp3026disable,
  200. tvp3026load,
  201. tvp3026move,
  202. };