2 #include "../port/lib.h"
7 #include "../port/pci.h"
8 #include "../port/error.h"
16 typedef struct CursorNM CursorNM;
27 neomagicenable(VGAscr* scr)
30 int bar, curoff, vmsize;
35 * scr->mmio holds the virtual address of the cursor registers
36 * in the MMIO space. This may need to change for older chips
37 * which have the MMIO space offset in the framebuffer region.
39 * scr->io holds the offset into mmio of the CursorNM struct.
44 if(p == nil || p->vid != 0x10C8)
48 case 0x0003: /* MagicGraph 128ZV */
50 if(p->mem[bar].bar & 1)
52 ioaddr = (p->mem[bar].bar & ~0x0F) + 0x200000;
57 case 0x0083: /* MagicGraph 128ZV+ */
61 case 0x0004: /* MagicGraph 128XD */
65 case 0x0005: /* MagicMedia 256AV */
69 case 0x0006: /* MagicMedia 256ZX */
73 case 0x0016: /* MagicMedia 256XL+ */
75 /* Vaio VESA BIOS says 6080, but then hwgc doesn't work */
81 if(p->mem[bar].bar & 1)
83 ioaddr = p->mem[bar].bar & ~0x0F;
84 iosize = p->mem[bar].size;
86 scr->mmio = vmap(ioaddr, iosize);
89 addvgaseg("neomagicmmio", ioaddr, iosize);
92 * Find a place for the cursor data in display memory.
93 * 2 cursor images might be needed, 1KB each so use the
94 * last 2KB of the framebuffer.
96 scr->storage = vmsize-2*1024;
100 addvgaseg("neomagicscreen", scr->paddr, scr->apsize);
104 neomagiccurdisable(VGAscr* scr)
110 cursornm = (void*)((char*)scr->mmio + scr->io);
111 cursornm->enable = 0;
115 neomagicinitcursor(VGAscr* scr, int xo, int yo, int index)
121 p = (uchar*)scr->vaddr;
122 p += scr->storage + index*1024;
124 for(y = yo; y < 16; y++){
126 p1 = scr->set[2*y+1];
128 p0 = (p0<<xo)|(p1>>(8-xo));
134 for(x = 16; x < 64; x += 8)
137 p0 = scr->clr[2*y]|scr->set[2*y];
138 p1 = scr->clr[2*y+1]|scr->set[2*y+1];
140 p0 = (p0<<xo)|(p1>>(8-xo));
146 for(x = 16; x < 64; x += 8)
150 for(x = 0; x < 64; x += 8){
159 neomagiccurload(VGAscr* scr, Cursor* curs)
165 cursornm = (void*)((char*)scr->mmio + scr->io);
167 cursornm->enable = 0;
168 memmove(&scr->Cursor, curs, sizeof(Cursor));
169 neomagicinitcursor(scr, 0, 0, 0);
170 cursornm->enable = 1;
174 neomagiccurmove(VGAscr* scr, Point p)
177 int addr, index, x, xo, y, yo;
181 cursornm = (void*)((char*)scr->mmio + scr->io);
184 if((x = p.x+scr->offset.x) < 0){
190 if((y = p.y+scr->offset.y) < 0){
199 neomagicinitcursor(scr, xo, yo, index);
201 addr = ((scr->storage+(1024*index))>>10) & 0xFFF;
202 addr = ((addr & 0x00F)<<8)|((addr>>4) & 0xFF);
203 if(cursornm->addr != addr)
204 cursornm->addr = addr;
213 neomagiccurenable(VGAscr* scr)
220 cursornm = (void*)((char*)scr->mmio + scr->io);
221 cursornm->enable = 0;
226 cursornm->colour1 = (Pblack<<16)|(Pblack<<8)|Pblack;
227 cursornm->colour2 = (Pwhite<<16)|(Pwhite<<8)|Pwhite;
230 * Load, locate and enable the 64x64 cursor.
232 neomagiccurload(scr, &cursor);
233 neomagiccurmove(scr, ZP);
234 cursornm->enable = 1;
237 static int neomagicbltflags;
264 NEO_BS0_BLT_BUSY = 0x00000001,
265 NEO_BS0_FIFO_AVAIL = 0x00000002,
266 NEO_BS0_FIFO_PEND = 0x00000004,
268 NEO_BC0_DST_Y_DEC = 0x00000001,
269 NEO_BC0_X_DEC = 0x00000002,
270 NEO_BC0_SRC_TRANS = 0x00000004,
271 NEO_BC0_SRC_IS_FG = 0x00000008,
272 NEO_BC0_SRC_Y_DEC = 0x00000010,
273 NEO_BC0_FILL_PAT = 0x00000020,
274 NEO_BC0_SRC_MONO = 0x00000040,
275 NEO_BC0_SYS_TO_VID = 0x00000080,
277 NEO_BC1_DEPTH8 = 0x00000100,
278 NEO_BC1_DEPTH16 = 0x00000200,
279 NEO_BC1_DEPTH24 = 0x00000300,
280 NEO_BC1_X_320 = 0x00000400,
281 NEO_BC1_X_640 = 0x00000800,
282 NEO_BC1_X_800 = 0x00000c00,
283 NEO_BC1_X_1024 = 0x00001000,
284 NEO_BC1_X_1152 = 0x00001400,
285 NEO_BC1_X_1280 = 0x00001800,
286 NEO_BC1_X_1600 = 0x00001c00,
287 NEO_BC1_DST_TRANS = 0x00002000,
288 NEO_BC1_MSTR_BLT = 0x00004000,
289 NEO_BC1_FILTER_Z = 0x00008000,
291 NEO_BC2_WR_TR_DST = 0x00800000,
293 NEO_BC3_SRC_XY_ADDR = 0x01000000,
294 NEO_BC3_DST_XY_ADDR = 0x02000000,
295 NEO_BC3_CLIP_ON = 0x04000000,
296 NEO_BC3_FIFO_EN = 0x08000000,
297 NEO_BC3_BLT_ON_ADDR = 0x10000000,
298 NEO_BC3_SKIP_MAPPING = 0x80000000,
300 NEO_MODE1_DEPTH8 = 0x0100,
301 NEO_MODE1_DEPTH16 = 0x0200,
302 NEO_MODE1_DEPTH24 = 0x0300,
303 NEO_MODE1_X_320 = 0x0400,
304 NEO_MODE1_X_640 = 0x0800,
305 NEO_MODE1_X_800 = 0x0c00,
306 NEO_MODE1_X_1024 = 0x1000,
307 NEO_MODE1_X_1152 = 0x1400,
308 NEO_MODE1_X_1280 = 0x1800,
309 NEO_MODE1_X_1600 = 0x1c00,
310 NEO_MODE1_BLT_ON_ADDR = 0x2000,
313 /* Raster Operations */
315 GXclear = 0x000000, /* 0x0000 */
316 GXand = 0x080000, /* 0x1000 */
317 GXandReverse = 0x040000, /* 0x0100 */
318 GXcopy = 0x0c0000, /* 0x1100 */
319 GXandInvert = 0x020000, /* 0x0010 */
320 GXnoop = 0x0a0000, /* 0x1010 */
321 GXxor = 0x060000, /* 0x0110 */
322 GXor = 0x0e0000, /* 0x1110 */
323 GXnor = 0x010000, /* 0x0001 */
324 GXequiv = 0x090000, /* 0x1001 */
325 GXinvert = 0x050000, /* 0x0101 */
326 GXorReverse = 0x0d0000, /* 0x1101 */
327 GXcopyInvert = 0x030000, /* 0x0011 */
328 GXorInverted = 0x0b0000, /* 0x1011 */
329 GXnand = 0x070000, /* 0x0111 */
330 GXset = 0x0f0000, /* 0x1111 */
334 waitforidle(VGAscr *scr)
341 while((mmio[BltStat] & NEO_BS0_BLT_BUSY) && x++ < 1000000)
344 // iprint("idle stat %lud scrmmio %#.8lux scr %#p pc %#p\n", mmio[BltStat], scr->mmio, scr, getcallerpc(&scr));
348 waitforfifo(VGAscr *scr, int entries)
355 while(((mmio[BltStat]>>8) < entries) && x++ < 1000000)
358 // iprint("fifo stat %d scrmmio %#.8lux scr %#p pc %#p\n", mmio[BltStat]>>8, scr->mmio, scr, getcallerpc(&scr));
359 /* DirectFB says the above doesn't work. if so... */
360 /* waitforidle(scr); */
364 neomagichwfill(VGAscr *scr, Rectangle r, ulong sval)
371 mmio[FGColor] = sval;
373 mmio[BltCntl] = neomagicbltflags
376 | NEO_BC3_SKIP_MAPPING
378 mmio[DstStartOff] = scr->paddr
379 + r.min.y*scr->gscreen->width*sizeof(ulong)
380 + r.min.x*scr->gscreen->depth/BI2BY;
381 mmio[XYExt] = (Dy(r) << 16) | (Dx(r) & 0xffff);
387 neomagichwscroll(VGAscr *scr, Rectangle r, Rectangle sr)
394 pitch = scr->gscreen->width*sizeof(ulong);
395 pixel = scr->gscreen->depth/BI2BY;
398 if (r.min.y < sr.min.y || (r.min.y == sr.min.y && r.min.x < sr.min.x)) {
399 /* start from upper-left */
400 mmio[BltCntl] = neomagicbltflags
402 | NEO_BC3_SKIP_MAPPING
404 mmio[SrcStartOff] = scr->paddr
405 + sr.min.y*pitch + sr.min.x*pixel;
406 mmio[DstStartOff] = scr->paddr
407 + r.min.y*pitch + r.min.x*pixel;
409 /* start from lower-right */
410 mmio[BltCntl] = neomagicbltflags
415 | NEO_BC3_SKIP_MAPPING
417 mmio[SrcStartOff] = scr->paddr
418 + (sr.max.y-1)*pitch + (sr.max.x-1)*pixel;
419 mmio[DstStartOff] = scr->paddr
420 + (r.max.y-1)*pitch + (r.max.x-1)*pixel;
422 mmio[XYExt] = (Dy(r) << 16) | (Dx(r) & 0xffff);
428 neomagicdrawinit(VGAscr *scr)
435 pitch = scr->gscreen->width*sizeof(ulong);
437 neomagicbltflags = bltmode = 0;
439 switch(scr->gscreen->depth) {
441 bltmode |= NEO_MODE1_DEPTH8;
442 neomagicbltflags |= NEO_BC1_DEPTH8;
445 bltmode |= NEO_MODE1_DEPTH16;
446 neomagicbltflags |= NEO_BC1_DEPTH16;
448 case 24: /* I can't get it to work, and XFree86 doesn't either. */
449 default: /* give up */
453 switch(Dx(scr->gscreen->r)) {
455 bltmode |= NEO_MODE1_X_320;
456 neomagicbltflags |= NEO_BC1_X_320;
459 bltmode |= NEO_MODE1_X_640;
460 neomagicbltflags |= NEO_BC1_X_640;
463 bltmode |= NEO_MODE1_X_800;
464 neomagicbltflags |= NEO_BC1_X_800;
467 bltmode |= NEO_MODE1_X_1024;
468 neomagicbltflags |= NEO_BC1_X_1024;
471 bltmode |= NEO_MODE1_X_1152;
472 neomagicbltflags |= NEO_BC1_X_1152;
475 bltmode |= NEO_MODE1_X_1280;
476 neomagicbltflags |= NEO_BC1_X_1280;
479 bltmode |= NEO_MODE1_X_1600;
480 neomagicbltflags |= NEO_BC1_X_1600;
483 /* don't worry about it */
488 mmio[BltStat] = bltmode << 16;
489 mmio[Pitch] = (pitch << 16) | (pitch & 0xffff);
491 scr->fill = neomagichwfill;
492 scr->scroll = neomagichwscroll;
495 VGAdev vganeomagicdev = {
505 VGAcur vganeomagiccur = {