2 #include "../port/lib.h"
7 #include "../port/error.h"
15 typedef struct CursorNM CursorNM;
26 neomagicenable(VGAscr* scr)
34 * scr->mmio holds the virtual address of the cursor registers
35 * in the MMIO space. This may need to change for older chips
36 * which have the MMIO space offset in the framebuffer region.
38 * scr->io holds the offset into mmio of the CursorNM struct.
42 if(p = pcimatch(nil, 0x10C8, 0)){
44 case 0x0003: /* MagicGraph 128ZV */
47 ioaddr = (p->mem[0].bar & ~0x0F) + 0x200000;
50 case 0x0083: /* MagicGraph 128ZV+ */
53 ioaddr = p->mem[1].bar & ~0x0F;
54 iosize = p->mem[1].size;
56 case 0x0004: /* MagicGraph 128XD */
59 ioaddr = p->mem[1].bar & ~0x0F;
60 iosize = p->mem[1].size;
62 case 0x0005: /* MagicMedia 256AV */
65 ioaddr = p->mem[1].bar & ~0x0F;
66 iosize = p->mem[1].size;
68 case 0x0006: /* MagicMedia 256ZX */
71 ioaddr = p->mem[1].bar & ~0x0F;
72 iosize = p->mem[1].size;
74 case 0x0016: /* MagicMedia 256XL+ */
76 /* Vaio VESA BIOS says 6080, but then hwgc doesn't work */
78 ioaddr = p->mem[1].bar & ~0x0F;
79 iosize = p->mem[1].size;
89 scr->mmio = vmap(ioaddr, iosize);
92 addvgaseg("neomagicmmio", ioaddr, iosize);
95 * Find a place for the cursor data in display memory.
96 * 2 cursor images might be needed, 1KB each so use the
97 * last 2KB of the framebuffer.
99 scr->storage = vmsize-2*1024;
103 addvgaseg("neomagicscreen", scr->paddr, scr->apsize);
107 neomagiccurdisable(VGAscr* scr)
113 cursornm = (void*)((char*)scr->mmio + scr->io);
114 cursornm->enable = 0;
118 neomagicinitcursor(VGAscr* scr, int xo, int yo, int index)
124 p = (uchar*)scr->vaddr;
125 p += scr->storage + index*1024;
127 for(y = yo; y < 16; y++){
129 p1 = scr->set[2*y+1];
131 p0 = (p0<<xo)|(p1>>(8-xo));
137 for(x = 16; x < 64; x += 8)
140 p0 = scr->clr[2*y]|scr->set[2*y];
141 p1 = scr->clr[2*y+1]|scr->set[2*y+1];
143 p0 = (p0<<xo)|(p1>>(8-xo));
149 for(x = 16; x < 64; x += 8)
153 for(x = 0; x < 64; x += 8){
162 neomagiccurload(VGAscr* scr, Cursor* curs)
168 cursornm = (void*)((char*)scr->mmio + scr->io);
170 cursornm->enable = 0;
171 memmove(&scr->Cursor, curs, sizeof(Cursor));
172 neomagicinitcursor(scr, 0, 0, 0);
173 cursornm->enable = 1;
177 neomagiccurmove(VGAscr* scr, Point p)
180 int addr, index, x, xo, y, yo;
184 cursornm = (void*)((char*)scr->mmio + scr->io);
187 if((x = p.x+scr->offset.x) < 0){
193 if((y = p.y+scr->offset.y) < 0){
202 neomagicinitcursor(scr, xo, yo, index);
204 addr = ((scr->storage+(1024*index))>>10) & 0xFFF;
205 addr = ((addr & 0x00F)<<8)|((addr>>4) & 0xFF);
206 if(cursornm->addr != addr)
207 cursornm->addr = addr;
216 neomagiccurenable(VGAscr* scr)
223 cursornm = (void*)((char*)scr->mmio + scr->io);
224 cursornm->enable = 0;
229 cursornm->colour1 = (Pblack<<16)|(Pblack<<8)|Pblack;
230 cursornm->colour2 = (Pwhite<<16)|(Pwhite<<8)|Pwhite;
233 * Load, locate and enable the 64x64 cursor.
235 neomagiccurload(scr, &arrow);
236 neomagiccurmove(scr, ZP);
237 cursornm->enable = 1;
240 static int neomagicbltflags;
267 NEO_BS0_BLT_BUSY = 0x00000001,
268 NEO_BS0_FIFO_AVAIL = 0x00000002,
269 NEO_BS0_FIFO_PEND = 0x00000004,
271 NEO_BC0_DST_Y_DEC = 0x00000001,
272 NEO_BC0_X_DEC = 0x00000002,
273 NEO_BC0_SRC_TRANS = 0x00000004,
274 NEO_BC0_SRC_IS_FG = 0x00000008,
275 NEO_BC0_SRC_Y_DEC = 0x00000010,
276 NEO_BC0_FILL_PAT = 0x00000020,
277 NEO_BC0_SRC_MONO = 0x00000040,
278 NEO_BC0_SYS_TO_VID = 0x00000080,
280 NEO_BC1_DEPTH8 = 0x00000100,
281 NEO_BC1_DEPTH16 = 0x00000200,
282 NEO_BC1_DEPTH24 = 0x00000300,
283 NEO_BC1_X_320 = 0x00000400,
284 NEO_BC1_X_640 = 0x00000800,
285 NEO_BC1_X_800 = 0x00000c00,
286 NEO_BC1_X_1024 = 0x00001000,
287 NEO_BC1_X_1152 = 0x00001400,
288 NEO_BC1_X_1280 = 0x00001800,
289 NEO_BC1_X_1600 = 0x00001c00,
290 NEO_BC1_DST_TRANS = 0x00002000,
291 NEO_BC1_MSTR_BLT = 0x00004000,
292 NEO_BC1_FILTER_Z = 0x00008000,
294 NEO_BC2_WR_TR_DST = 0x00800000,
296 NEO_BC3_SRC_XY_ADDR = 0x01000000,
297 NEO_BC3_DST_XY_ADDR = 0x02000000,
298 NEO_BC3_CLIP_ON = 0x04000000,
299 NEO_BC3_FIFO_EN = 0x08000000,
300 NEO_BC3_BLT_ON_ADDR = 0x10000000,
301 NEO_BC3_SKIP_MAPPING = 0x80000000,
303 NEO_MODE1_DEPTH8 = 0x0100,
304 NEO_MODE1_DEPTH16 = 0x0200,
305 NEO_MODE1_DEPTH24 = 0x0300,
306 NEO_MODE1_X_320 = 0x0400,
307 NEO_MODE1_X_640 = 0x0800,
308 NEO_MODE1_X_800 = 0x0c00,
309 NEO_MODE1_X_1024 = 0x1000,
310 NEO_MODE1_X_1152 = 0x1400,
311 NEO_MODE1_X_1280 = 0x1800,
312 NEO_MODE1_X_1600 = 0x1c00,
313 NEO_MODE1_BLT_ON_ADDR = 0x2000,
316 /* Raster Operations */
318 GXclear = 0x000000, /* 0x0000 */
319 GXand = 0x080000, /* 0x1000 */
320 GXandReverse = 0x040000, /* 0x0100 */
321 GXcopy = 0x0c0000, /* 0x1100 */
322 GXandInvert = 0x020000, /* 0x0010 */
323 GXnoop = 0x0a0000, /* 0x1010 */
324 GXxor = 0x060000, /* 0x0110 */
325 GXor = 0x0e0000, /* 0x1110 */
326 GXnor = 0x010000, /* 0x0001 */
327 GXequiv = 0x090000, /* 0x1001 */
328 GXinvert = 0x050000, /* 0x0101 */
329 GXorReverse = 0x0d0000, /* 0x1101 */
330 GXcopyInvert = 0x030000, /* 0x0011 */
331 GXorInverted = 0x0b0000, /* 0x1011 */
332 GXnand = 0x070000, /* 0x0111 */
333 GXset = 0x0f0000, /* 0x1111 */
337 waitforidle(VGAscr *scr)
344 while((mmio[BltStat] & NEO_BS0_BLT_BUSY) && x++ < 1000000)
347 // iprint("idle stat %lud scrmmio %#.8lux scr %#p pc %#p\n", mmio[BltStat], scr->mmio, scr, getcallerpc(&scr));
351 waitforfifo(VGAscr *scr, int entries)
358 while(((mmio[BltStat]>>8) < entries) && x++ < 1000000)
361 // iprint("fifo stat %d scrmmio %#.8lux scr %#p pc %#p\n", mmio[BltStat]>>8, scr->mmio, scr, getcallerpc(&scr));
362 /* DirectFB says the above doesn't work. if so... */
363 /* waitforidle(scr); */
367 neomagichwfill(VGAscr *scr, Rectangle r, ulong sval)
374 mmio[FGColor] = sval;
376 mmio[BltCntl] = neomagicbltflags
379 | NEO_BC3_SKIP_MAPPING
381 mmio[DstStartOff] = scr->paddr
382 + r.min.y*scr->gscreen->width*BY2WD
383 + r.min.x*scr->gscreen->depth/BI2BY;
384 mmio[XYExt] = (Dy(r) << 16) | (Dx(r) & 0xffff);
390 neomagichwscroll(VGAscr *scr, Rectangle r, Rectangle sr)
397 pitch = scr->gscreen->width*BY2WD;
398 pixel = scr->gscreen->depth/BI2BY;
401 if (r.min.y < sr.min.y || (r.min.y == sr.min.y && r.min.x < sr.min.x)) {
402 /* start from upper-left */
403 mmio[BltCntl] = neomagicbltflags
405 | NEO_BC3_SKIP_MAPPING
407 mmio[SrcStartOff] = scr->paddr
408 + sr.min.y*pitch + sr.min.x*pixel;
409 mmio[DstStartOff] = scr->paddr
410 + r.min.y*pitch + r.min.x*pixel;
412 /* start from lower-right */
413 mmio[BltCntl] = neomagicbltflags
418 | NEO_BC3_SKIP_MAPPING
420 mmio[SrcStartOff] = scr->paddr
421 + (sr.max.y-1)*pitch + (sr.max.x-1)*pixel;
422 mmio[DstStartOff] = scr->paddr
423 + (r.max.y-1)*pitch + (r.max.x-1)*pixel;
425 mmio[XYExt] = (Dy(r) << 16) | (Dx(r) & 0xffff);
431 neomagicdrawinit(VGAscr *scr)
438 pitch = scr->gscreen->width*BY2WD;
440 neomagicbltflags = bltmode = 0;
442 switch(scr->gscreen->depth) {
444 bltmode |= NEO_MODE1_DEPTH8;
445 neomagicbltflags |= NEO_BC1_DEPTH8;
448 bltmode |= NEO_MODE1_DEPTH16;
449 neomagicbltflags |= NEO_BC1_DEPTH16;
451 case 24: /* I can't get it to work, and XFree86 doesn't either. */
452 default: /* give up */
456 switch(Dx(scr->gscreen->r)) {
458 bltmode |= NEO_MODE1_X_320;
459 neomagicbltflags |= NEO_BC1_X_320;
462 bltmode |= NEO_MODE1_X_640;
463 neomagicbltflags |= NEO_BC1_X_640;
466 bltmode |= NEO_MODE1_X_800;
467 neomagicbltflags |= NEO_BC1_X_800;
470 bltmode |= NEO_MODE1_X_1024;
471 neomagicbltflags |= NEO_BC1_X_1024;
474 bltmode |= NEO_MODE1_X_1152;
475 neomagicbltflags |= NEO_BC1_X_1152;
478 bltmode |= NEO_MODE1_X_1280;
479 neomagicbltflags |= NEO_BC1_X_1280;
482 bltmode |= NEO_MODE1_X_1600;
483 neomagicbltflags |= NEO_BC1_X_1600;
486 /* don't worry about it */
491 mmio[BltStat] = bltmode << 16;
492 mmio[Pitch] = (pitch << 16) | (pitch & 0xffff);
494 scr->fill = neomagichwfill;
495 scr->scroll = neomagichwscroll;
498 VGAdev vganeomagicdev = {
508 VGAcur vganeomagiccur = {