2006-08-07: Patches for the Matrox 4xx driver to support 16 an 24 bits modes (in addition to the existant 8 and 32). Also the G200 cards now work with hardware acceleration. 2006-08-12: Resubmit of the previous patch with corrected indentation, tabs are now used instead of hardcoded space (sorry about that one). Leonardo Valencia Notes: Sat Aug 12 02:30:08 EDT 2006 rsc That was fast! Thanks. Reference: /n/sources/patch/applied/mga4xx-newmodes-resub Date: Sat Aug 12 08:28:34 CES 2006 Signed-off-by: leoval@anixcorp.com Reviewed-by: rsc --- /sys/src/9/pc/vgamga4xx.c Sat Aug 12 08:28:25 2006 +++ /sys/src/9/pc/vgamga4xx.c Sat Aug 12 08:28:24 2006 @@ -2,6 +2,10 @@ /* * Matrox G200, G400 and G450. * Written by Philippe Anel + * + * 2006-08-07 : Minor fix to allow the G200 cards to work fine. YDSTORG is now initialized. + * : Also support for 16 and 24 bit modes is added. + * : by Leonardo Valencia */ #include "u.h" @@ -43,6 +47,7 @@ SRCORG = 0x2cb4, PITCH = 0x1c8c, DSTORG = 0x2cb8, + YDSTORG = 0x1c94, PLNWRT = 0x1c1c, ZORG = 0x1c0c, MACCESS = 0x1c04, @@ -465,18 +470,15 @@ mga4xxdrawinit(VGAscr *scr) { uchar *mga; - Pcidev *p; - - p = mgapcimatch(); - if(p->did == MGA200) - return; if(scr->mmio == 0) return; + mga = (uchar*)scr->mmio; mgawrite32(mga, SRCORG, 0); mgawrite32(mga, DSTORG, 0); + mgawrite32(mga, YDSTORG, 0); mgawrite32(mga, ZORG, 0); mgawrite32(mga, PLNWRT, ~0); mgawrite32(mga, FCOL, 0xffff0000); @@ -487,6 +489,12 @@ switch(scr->gscreen->depth){ case 8: mgawrite32(mga, MACCESS, 0); + break; + case 16: + mgawrite32(mga, MACCESS, 1); + break; + case 24: + mgawrite32(mga, MACCESS, 3); break; case 32: mgawrite32(mga, MACCESS, 2); --- /sys/src/cmd/aux/vga/mga4xx.c Sat Aug 12 08:28:30 2006 +++ /sys/src/cmd/aux/vga/mga4xx.c Sat Aug 12 08:28:28 2006 @@ -9,6 +9,9 @@ - 2001-09-06 : Added Full 2D Accel ! (see drivers in /sys/src/9/pc) - 2001-10-01 : Rid Fix. - 2006-04-01 : Add MGA550 support. + - 2006-08-07 : Add support for 16 and 24bits modes. + HW accel now works for the G200 cards too (see kernel). + by Leonardo Valencia Greets and Acknowledgements go to : - Sylvain Chipaux . @@ -454,7 +457,7 @@ fd = open("#v/vgactl", OWRITE); if(fd < 0) error("mga: can't open vgactl\n"); - + cmd[13] = '0' + depth; if(write(fd, cmd, 14) != 14) error("mga: can't set palette depth to %d\n", depth); @@ -1067,6 +1070,7 @@ Ctlr* c; int i; ulong t; + int bppShift; mga = vga->private; mode = vga->mode; @@ -1075,8 +1079,27 @@ ctlr->flag |= Ulinear; - if ((mode->z != 32) && (mode->z != 8)) + /* + * Set the right bppShitf based on depth + */ + + switch(mode->z) { + case 8: + bppShift = 0; + break; + case 16: + bppShift = 1; + break; + case 24: + bppShift = 0; + break; + case 32: + bppShift = 2; + break; + default: + bppShift = 0; error("depth %d not supported !\n", mode->z); + } if (mode->interlace) error("interlaced mode not supported !\n"); @@ -1138,7 +1161,7 @@ mga->linecomp = mode->y; mga->hsyncsel = 0; /* Do not double lines ... */ mga->startadd = 0; - mga->offset = (vga->virtx * mode->z) / 128; + mga->offset = (mode->z==24) ? (vga->virtx * 3) >> (4 - bppShift) : vga->virtx >> (4-bppShift); /* No Zoom */ mga->maxscan = 0; /* Not used in Power Graphic mode */ @@ -1176,9 +1199,9 @@ mga->crtcrstN = 1; mga->mgamode = 1; - mga->scale = (mode->z == 8) ? 0 : 3; /* 8 or 32 bits mode */ + mga->scale = (mode->z == 24) ? ((1 << bppShift)*3)-1 : (1 << bppShift)-1; - mga->crtcprotect = 1; + mga->crtcprotect = 1; mga->winsize = 0; mga->winfreq = 0; @@ -1523,6 +1546,12 @@ case 8: dacset(mga, Dac_Xmulctrl, _8bitsPerPixel, ColorDepth); break; + case 16: + dacset(mga, Dac_Xmulctrl, _16bitsPerPixel, ColorDepth); + break; + case 24: + dacset(mga, Dac_Xmulctrl, _24bitsPerPixel, ColorDepth); + break; case 32: dacset(mga, Dac_Xmulctrl, _32bitsPerPixel, ColorDepth); break; @@ -1569,11 +1598,12 @@ trace("mga: crtcext MgaMode loaded !\n"); if (ultradebug) Bflush(&stdout); - if (mode->z == 32) { + if (mode->z == 32 || mode->z == 24 ) { /* Initialize Big Endian Mode ! */ mgawrite32(mga, 0x1e54, 0x02 << 16); } + /* Set final misc ... enable mapping ... */ miscset(mga, mga->misc | Misc_rammapen, 0); @@ -1597,7 +1627,13 @@ trace("mga: Loaded [bis]!\n" ); - if (mode->z != 8) { + /* + * TODO: In 16bpp mode, what is the correct palette ? + * in the meantime lets use the default one, + * which has a weird color combination. + */ + + if (mode->z != 8 && mode ->z != 16) { /* Initialize Palette */ mgawrite8(mga, RAMDACIDX, 0); for (i = 0; i < 0x100; i++) { @@ -1606,6 +1642,7 @@ mgawrite8(mga, RAMDACPALDATA, i); } } + trace("mga: Palette initialised !\n"); /* Enable Cursor */