@@ 107,6 107,7 @@ neomagicenable(VGAscr* scr)
if(scr->io == 0)
return;
addvgaseg("neomagicmmio", scr->io, p->mem[1].size);
+ scr->mmio = KADDR(scr->io);
/*
* Find a place for the cursor data in display memory.
@@ 260,6 261,264 @@ neomagiccurenable(VGAscr* scr)
cursornm->enable = 1;
}
+static int neomagicbltflags;
+
+/* registers */
+enum {
+ BltStat = 0,
+ BltCntl = 1,
+ XPColor = 2,
+ FGColor = 3,
+ BGColor = 4,
+ Pitch = 5,
+ ClipLT = 6,
+ ClipRB = 7,
+ SrcBitOff = 8,
+ SrcStartOff = 9,
+
+ DstStartOff = 11,
+ XYExt = 12,
+
+ PageCntl = 20,
+ PageBase,
+ PostBase,
+ PostPtr,
+ DataPtr,
+};
+
+/* flags */
+enum {
+ NEO_BS0_BLT_BUSY = 0x00000001,
+ NEO_BS0_FIFO_AVAIL = 0x00000002,
+ NEO_BS0_FIFO_PEND = 0x00000004,
+
+ NEO_BC0_DST_Y_DEC = 0x00000001,
+ NEO_BC0_X_DEC = 0x00000002,
+ NEO_BC0_SRC_TRANS = 0x00000004,
+ NEO_BC0_SRC_IS_FG = 0x00000008,
+ NEO_BC0_SRC_Y_DEC = 0x00000010,
+ NEO_BC0_FILL_PAT = 0x00000020,
+ NEO_BC0_SRC_MONO = 0x00000040,
+ NEO_BC0_SYS_TO_VID = 0x00000080,
+
+ NEO_BC1_DEPTH8 = 0x00000100,
+ NEO_BC1_DEPTH16 = 0x00000200,
+ NEO_BC1_DEPTH24 = 0x00000300,
+ NEO_BC1_X_320 = 0x00000400,
+ NEO_BC1_X_640 = 0x00000800,
+ NEO_BC1_X_800 = 0x00000c00,
+ NEO_BC1_X_1024 = 0x00001000,
+ NEO_BC1_X_1152 = 0x00001400,
+ NEO_BC1_X_1280 = 0x00001800,
+ NEO_BC1_X_1600 = 0x00001c00,
+ NEO_BC1_DST_TRANS = 0x00002000,
+ NEO_BC1_MSTR_BLT = 0x00004000,
+ NEO_BC1_FILTER_Z = 0x00008000,
+
+ NEO_BC2_WR_TR_DST = 0x00800000,
+
+ NEO_BC3_SRC_XY_ADDR = 0x01000000,
+ NEO_BC3_DST_XY_ADDR = 0x02000000,
+ NEO_BC3_CLIP_ON = 0x04000000,
+ NEO_BC3_FIFO_EN = 0x08000000,
+ NEO_BC3_BLT_ON_ADDR = 0x10000000,
+ NEO_BC3_SKIP_MAPPING = 0x80000000,
+
+ NEO_MODE1_DEPTH8 = 0x0100,
+ NEO_MODE1_DEPTH16 = 0x0200,
+ NEO_MODE1_DEPTH24 = 0x0300,
+ NEO_MODE1_X_320 = 0x0400,
+ NEO_MODE1_X_640 = 0x0800,
+ NEO_MODE1_X_800 = 0x0c00,
+ NEO_MODE1_X_1024 = 0x1000,
+ NEO_MODE1_X_1152 = 0x1400,
+ NEO_MODE1_X_1280 = 0x1800,
+ NEO_MODE1_X_1600 = 0x1c00,
+ NEO_MODE1_BLT_ON_ADDR = 0x2000,
+};
+
+/* Raster Operations */
+enum {
+ GXclear = 0x000000, /* 0x0000 */
+ GXand = 0x080000, /* 0x1000 */
+ GXandReverse = 0x040000, /* 0x0100 */
+ GXcopy = 0x0c0000, /* 0x1100 */
+ GXandInvert = 0x020000, /* 0x0010 */
+ GXnoop = 0x0a0000, /* 0x1010 */
+ GXxor = 0x060000, /* 0x0110 */
+ GXor = 0x0e0000, /* 0x1110 */
+ GXnor = 0x010000, /* 0x0001 */
+ GXequiv = 0x090000, /* 0x1001 */
+ GXinvert = 0x050000, /* 0x0101 */
+ GXorReverse = 0x0d0000, /* 0x1101 */
+ GXcopyInvert = 0x030000, /* 0x0011 */
+ GXorInverted = 0x0b0000, /* 0x1011 */
+ GXnand = 0x070000, /* 0x0111 */
+ GXset = 0x0f0000, /* 0x1111 */
+};
+
+static void
+waitforidle(VGAscr *scr)
+{
+ ulong *mmio;
+ long x;
+
+ mmio = scr->mmio;
+ x = 0;
+ while((mmio[BltStat] & NEO_BS0_BLT_BUSY) && x++ < 1000000)
+ ;
+ //if(x >= 1000000)
+ // iprint("idle stat %lud scrmmio %.8lux scr %p pc %luX\n", mmio[BltStat], scr->mmio, scr, getcallerpc(&scr));
+}
+
+static void
+waitforfifo(VGAscr *scr, int entries)
+{
+ ulong *mmio;
+ long x;
+
+ mmio = scr->mmio;
+ x = 0;
+ while(((mmio[BltStat]>>8) < entries) && x++ < 1000000)
+ ;
+ //if(x >= 1000000)
+ // iprint("fifo stat %d scrmmio %.8lux scr %p pc %luX\n", mmio[BltStat]>>8, scr->mmio, scr, getcallerpc(&scr));
+ /* DirectFB says the above doesn't work. if so... */
+ /* waitforidle(scr); */
+}
+
+static int
+neomagichwfill(VGAscr *scr, Rectangle r, ulong sval)
+{
+ ulong *mmio;
+
+ mmio = scr->mmio;
+
+ waitforfifo(scr, 1);
+ mmio[FGColor] = sval;
+ waitforfifo(scr, 3);
+ mmio[BltCntl] = neomagicbltflags
+ | NEO_BC3_FIFO_EN
+ | NEO_BC0_SRC_IS_FG
+ | NEO_BC3_SKIP_MAPPING
+ | GXcopy;
+ mmio[DstStartOff] = scr->aperture
+ + r.min.y*scr->gscreen->width*BY2WD
+ + r.min.x*scr->gscreen->depth/BI2BY;
+ mmio[XYExt] = (Dy(r) << 16) | (Dx(r) & 0xffff);
+ waitforidle(scr);
+ return 1;
+}
+
+static int
+neomagichwscroll(VGAscr *scr, Rectangle r, Rectangle sr)
+{
+ ulong *mmio;
+ int pitch, pixel;
+
+ mmio = scr->mmio;
+
+ pitch = scr->gscreen->width*BY2WD;
+ pixel = scr->gscreen->depth/BI2BY;
+
+ waitforfifo(scr, 4);
+ if (r.min.y < sr.min.y || (r.min.y == sr.min.y && r.min.x < sr.min.x)) {
+ /* start from upper-left */
+ mmio[BltCntl] = neomagicbltflags
+ | NEO_BC3_FIFO_EN
+ | NEO_BC3_SKIP_MAPPING
+ | GXcopy;
+ mmio[SrcStartOff] = scr->aperture
+ + sr.min.y*pitch + sr.min.x*pixel;
+ mmio[DstStartOff] = scr->aperture
+ + r.min.y*pitch + r.min.x*pixel;
+ } else {
+ /* start from lower-right */
+ mmio[BltCntl] = neomagicbltflags
+ | NEO_BC0_X_DEC
+ | NEO_BC0_DST_Y_DEC
+ | NEO_BC0_SRC_Y_DEC
+ | NEO_BC3_FIFO_EN
+ | NEO_BC3_SKIP_MAPPING
+ | GXcopy;
+ mmio[SrcStartOff] = scr->aperture
+ + (sr.max.y-1)*pitch + (sr.max.x-1)*pixel;
+ mmio[DstStartOff] = scr->aperture
+ + (r.max.y-1)*pitch + (r.max.x-1)*pixel;
+ }
+ mmio[XYExt] = (Dy(r) << 16) | (Dx(r) & 0xffff);
+ waitforidle(scr);
+ return 1;
+}
+
+static void
+neomagicdrawinit(VGAscr *scr)
+{
+ ulong *mmio;
+ uint bltmode, pitch;
+
+ mmio = scr->mmio;
+
+ pitch = scr->gscreen->width*BY2WD;
+
+ neomagicbltflags = bltmode = 0;
+
+ switch(scr->gscreen->depth) {
+ case 8:
+ bltmode |= NEO_MODE1_DEPTH8;
+ neomagicbltflags |= NEO_BC1_DEPTH8;
+ break;
+ case 16:
+ bltmode |= NEO_MODE1_DEPTH16;
+ neomagicbltflags |= NEO_BC1_DEPTH16;
+ break;
+ case 24: /* I can't get it to work, and XFree86 doesn't either. */
+ default: /* give up */
+ return;
+ }
+
+ switch(Dx(scr->gscreen->r)) {
+ case 320:
+ bltmode |= NEO_MODE1_X_320;
+ neomagicbltflags |= NEO_BC1_X_320;
+ break;
+ case 640:
+ bltmode |= NEO_MODE1_X_640;
+ neomagicbltflags |= NEO_BC1_X_640;
+ break;
+ case 800:
+ bltmode |= NEO_MODE1_X_800;
+ neomagicbltflags |= NEO_BC1_X_800;
+ break;
+ case 1024:
+ bltmode |= NEO_MODE1_X_1024;
+ neomagicbltflags |= NEO_BC1_X_1024;
+ break;
+ case 1152:
+ bltmode |= NEO_MODE1_X_1152;
+ neomagicbltflags |= NEO_BC1_X_1152;
+ break;
+ case 1280:
+ bltmode |= NEO_MODE1_X_1280;
+ neomagicbltflags |= NEO_BC1_X_1280;
+ break;
+ case 1600:
+ bltmode |= NEO_MODE1_X_1600;
+ neomagicbltflags |= NEO_BC1_X_1600;
+ break;
+ default:
+ /* don't worry about it */
+ break;
+ }
+
+ waitforidle(scr);
+ mmio[BltStat] = bltmode << 16;
+ mmio[Pitch] = (pitch << 16) | (pitch & 0xffff);
+
+ scr->fill = neomagichwfill;
+ scr->scroll = neomagichwscroll;
+}
+
VGAdev vganeomagicdev = {
"neomagic",
@@ 267,6 526,7 @@ VGAdev vganeomagicdev = {
nil,
nil,
neomagiclinear,
+ neomagicdrawinit,
};
VGAcur vganeomagiccur = {
@@ 277,3 537,4 @@ VGAcur vganeomagiccur = {
neomagiccurload,
neomagiccurmove,
};
+
@@ 36,6 36,13 @@ struct Mntrpc
Mntrpc* flushed; /* message this one flushes */
};
+enum
+{
+ TAGSHIFT = 5, /* ulong has to be 32 bits */
+ TAGMASK = (1<<TAGSHIFT)-1,
+ NMASK = (64*1024)>>TAGSHIFT,
+};
+
struct Mntalloc
{
Lock;
@@ 45,7 52,7 @@ struct Mntalloc
int nrpcfree;
int nrpcused;
ulong id;
- int rpctag;
+ ulong tagmask[NMASK];
}mntalloc;
void mattach(Mnt*, Chan*, char*);
@@ 69,21 76,18 @@ Chan* mntchan(void);
char Esbadstat[] = "invalid directory entry received from server";
char Enoversion[] = "version not established for mount channel";
-void (*mntstats)(int, Chan*, uvlong, ulong);
-enum
-{
- Tagspace = 1,
-};
+void (*mntstats)(int, Chan*, uvlong, ulong);
static void
mntreset(void)
{
mntalloc.id = 1;
- mntalloc.rpctag = Tagspace;
+ mntalloc.tagmask[0] = 1; /* don't allow 0 as a tag */
+ mntalloc.tagmask[NMASK-1] = 0x80000000UL; /* don't allow NOTAG */
fmtinstall('F', fcallfmt);
fmtinstall('D', dirfmt);
-/* fmtinstall('M', dirmodefmt); No! Clashes with eipfmt [sape] */
+/* We can't install %M since eipfmt does and is used in the kernel [sape] */
cinit();
}
@@ 997,6 1001,32 @@ mntflushfree(Mnt *m, Mntrpc *r)
}
}
+int
+alloctag(void)
+{
+ int i, j;
+ ulong v;
+
+ for(i = 0; i < NMASK; i++){
+ v = mntalloc.tagmask[i];
+ if(v == ~0UL)
+ continue;
+ for(j = 0; j < 1<<TAGSHIFT; j++)
+ if((v & (1<<j)) == 0){
+ mntalloc.tagmask[i] |= 1<<j;
+ return (i<<TAGSHIFT) + j;
+ }
+ }
+ panic("no friggin tags left");
+ return NOTAG;
+}
+
+void
+freetag(int t)
+{
+ mntalloc.tagmask[t>>TAGSHIFT] &= ~(1<<(t&TAGMASK));
+}
+
Mntrpc*
mntralloc(Chan *c, ulong msize)
{
@@ 1021,7 1051,7 @@ mntralloc(Chan *c, ulong msize)
exhausted("mount rpc buffer");
}
new->rpclen = msize;
- new->request.tag = mntalloc.rpctag++;
+ new->request.tag = alloctag();
}
else {
mntalloc.rpcfree = new->list;
@@ 1056,6 1086,7 @@ mntfree(Mntrpc *r)
if(mntalloc.nrpcfree >= 10){
free(r->rpc);
free(r);
+ freetag(r->request.tag);
}
else{
r->list = mntalloc.rpcfree;