/* Philippe Anel : philippe.anel@noos.fr */ #include "u.h" #include "../port/lib.h" #include "mem.h" #include "dat.h" #include "fns.h" #include "io.h" #include "../port/error.h" #define Image IMAGE #include #include #include #include "screen.h" /* * Matrox G400 and G450. */ enum { /* pci chip manufacturer */ MATROX = 0x102B, /* agp/pci chip device id */ MGA4xx = 0x0525 }; static Pcidev* mgapcimatch(void) { Pcidev* p; p = pcimatch(nil, MATROX, MGA4xx); if (0 && p) print("MGA 4xx found : rev %d\n", p->rid); return p; } static ulong mga4xxlinear(VGAscr* scr, int* size, int* align) { ulong aperture, oaperture; int oapsize, wasupamem; Pcidev *p; oaperture = scr->aperture; oapsize = scr->apsize; wasupamem = scr->isupamem; if(p = mgapcimatch()){ aperture = p->mem[0].bar & ~0x0F; *size = 32*1024*1024; } else aperture = 0; if(wasupamem) { if(oaperture == aperture) return oaperture; upafree(oaperture, oapsize); } scr->isupamem = 0; aperture = upamalloc(aperture, *size, *align); if(aperture == 0){ if(wasupamem && upamalloc(oaperture, oapsize, 0)) { aperture = oaperture; scr->isupamem = 1; } else scr->isupamem = 0; } else scr->isupamem = 1; return aperture; } static void mga4xxenable(VGAscr* scr) { Pcidev * p; Physseg seg; int size, align; ulong aperture; /* * Only once, can't be disabled for now. * scr->io holds the virtual address of * the MMIO registers. */ if(scr->io) return; p = mgapcimatch(); if(p == nil) return; scr->io = upamalloc(p->mem[1].bar & ~0x0F, 16*1024, 0); if(scr->io == 0) return; memset(&seg, 0, sizeof(seg)); seg.attr = SG_PHYSICAL; seg.name = smalloc(NAMELEN); snprint(seg.name, NAMELEN, "mga4xxmmio"); seg.pa = scr->io; seg.size = p->mem[1].size; addphysseg(&seg); scr->io = (ulong)KADDR(scr->io); /* need to map frame buffer here too, so vga can find memory size */ size = 32*1024*1024; align = 0; aperture = mga4xxlinear(scr, &size, &align); if(aperture) { scr->aperture = aperture; scr->apsize = size; memset(&seg, 0, sizeof(seg)); seg.attr = SG_PHYSICAL; seg.name = smalloc(NAMELEN); snprint(seg.name, NAMELEN, "mga4xxscreen"); seg.pa = aperture; seg.size = size; addphysseg(&seg); } } enum { Index = 0x00, /* Index */ Data = 0x0A, /* Data */ Cxlsb = 0x0C, /* Cursor X LSB */ Cxmsb = 0x0D, /* Cursor X MSB */ Cylsb = 0x0E, /* Cursor Y LSB */ Cymsb = 0x0F, /* Cursor Y MSB */ Icuradrl = 0x04, /* Cursor Base Address Low */ Icuradrh = 0x05, /* Cursor Base Address High */ Icctl = 0x06, /* Indirect Cursor Control */ }; static void dac4xxdisable(VGAscr* scr) { uchar * dac4xx; if(scr->io == 0) return; dac4xx = KADDR(scr->io+0x3C00); *(dac4xx+Index) = Icctl; *(dac4xx+Data) = 0x00; } static void dac4xxload(VGAscr* scr, Cursor* curs) { int x, y; uchar *p; uchar * dac4xx; if(scr->io == 0) return; dac4xx = KADDR(scr->io+0x3C00); dac4xxdisable(scr); p = KADDR(scr->storage); for(y = 0; y < 64; y++){ *p++ = 0; *p++ = 0; *p++ = 0; *p++ = 0; *p++ = 0; *p++ = 0; if(y <16){ *p++ = curs->set[1+y*2]|curs->clr[1+2*y]; *p++ = curs->set[y*2]|curs->clr[2*y]; } else{ *p++ = 0; *p++ = 0; } *p++ = 0; *p++ = 0; *p++ = 0; *p++ = 0; *p++ = 0; *p++ = 0; if(y <16){ *p++ = curs->set[1+y*2]; *p++ = curs->set[y*2]; } else{ *p++ = 0; *p++ = 0; } } scr->offset.x = 64 + curs->offset.x; scr->offset.y = 64 + curs->offset.y; *(dac4xx+Index) = Icctl; *(dac4xx+Data) = 0x03; } static int dac4xxmove(VGAscr* scr, Point p) { int x, y; uchar * dac4xx; if(scr->io == 0) return 1; dac4xx = KADDR(scr->io + 0x3C00); x = p.x + scr->offset.x; y = p.y + scr->offset.y; *(dac4xx+Cxlsb) = x & 0xFF; *(dac4xx+Cxmsb) = (x>>8) & 0x0F; *(dac4xx+Cylsb) = y & 0xFF; *(dac4xx+Cymsb) = (y>>8) & 0x0F; return 0; } static void dac4xxenable(VGAscr* scr) { uchar * dac4xx; ulong storage; if(scr->io == 0) return; dac4xx = KADDR(scr->io+0x3C00); dac4xxdisable(scr); storage = (32*1024*1024 - 4096) & ~0x3ff; *(dac4xx+Index) = Icuradrl; *(dac4xx+Data) = 0xff & (storage >> 10); *(dac4xx+Index) = Icuradrh; *(dac4xx+Data) = 0xff & (storage >> 18); scr->storage = (ulong) KADDR((ulong)scr->aperture + (ulong)storage); /* Show X11-Like Cursor */ *(dac4xx+Index) = Icctl; *(dac4xx+Data) = 0x03; /* Cursor Color 0 : White */ *(dac4xx+Index) = 0x08; *(dac4xx+Data) = 0xff; *(dac4xx+Index) = 0x09; *(dac4xx+Data) = 0xff; *(dac4xx+Index) = 0x0a; *(dac4xx+Data) = 0xff; /* Cursor Color 1 : Black */ *(dac4xx+Index) = 0x0c; *(dac4xx+Data) = 0x00; *(dac4xx+Index) = 0x0d; *(dac4xx+Data) = 0x00; *(dac4xx+Index) = 0x0e; *(dac4xx+Data) = 0x00; /* Cursor Color 2 : Red */ *(dac4xx+Index) = 0x10; *(dac4xx+Data) = 0xff; *(dac4xx+Index) = 0x11; *(dac4xx+Data) = 0x00; *(dac4xx+Index) = 0x12; *(dac4xx+Data) = 0x00; /* * Load, locate and enable the * 64x64 cursor in 3-colour mode. */ dac4xxload(scr, &arrow); dac4xxmove(scr, ZP); } VGAdev vgamga4xxdev = { "mga4xx", mga4xxenable, /* enable */ 0, /* disable */ 0, /* page */ mga4xxlinear, /* linear */ }; VGAcur vgamga4xxcur = { "mga4xxhwgc", dac4xxenable, dac4xxdisable, dac4xxload, dac4xxmove, };