Plan 9 from Bell Labs’s /usr/web/sources/extra/9hist/pc/vgavmware.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


## diffname pc/vgavmware.c 2001/0822
## diff -e /dev/null /n/emeliedump/2001/0822/sys/src/9/pc/vgavmware.c
0a
#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 <draw.h>
#include <memdraw.h>
#include <cursor.h>
#include "screen.h"

enum {
	PCIVMWARE	= 0x15AD,	/* PCI VID */

	VMWARE1		= 0x0710,	/* PCI DID */
	VMWARE2		= 0x0405,
};

enum {
	Rid = 0,
	Renable,
	Rwidth,
	Rheight,
	Rmaxwidth,
	Rmaxheight,
	Rdepth,
	Rbpp,
	Rpseudocolor,
	Rrmask,
	Rgmask,
	Rbmask,
	Rbpl,
	Rfbstart,
	Rfboffset,
	Rfbmaxsize,
	Rfbsize,
	Rcap,
	Rmemstart,
	Rmemsize,
	Rconfigdone,
	Rsync,
	Rbusy,
	Rguestid,
	Rcursorid,
	Rcursorx,
	Rcursory,
	Rcursoron,
	Nreg,

	Rpalette = 1024,
};

typedef struct Vmware	Vmware;
struct Vmware {
	ulong	mmio;
	ulong	fb;

	ulong	ra;
	ulong	rd;

	ulong	r[Nreg];

	char	chan[32];
	int	depth;
};

Vmware xvm;
Vmware *vm=&xvm;

static ulong
vmrd(Vmware *vm, int i)
{
	outl(vm->ra, i);
	return inl(vm->rd);
}

static void
vmwr(Vmware *vm, int i, ulong v)
{
	outl(vm->ra, i);
	outl(vm->rd, v);
}

static ulong
vmwarelinear(VGAscr* scr, int* size, int* align)
{
	char err[64];
	ulong aperture, oaperture;
	int osize, oapsize, wasupamem;
	Pcidev *p;
	Physseg seg;

	osize = *size;
	oaperture = scr->aperture;
	oapsize = scr->apsize;
	wasupamem = scr->isupamem;

	p = pcimatch(nil, PCIVMWARE, 0);
	if(p == nil)
		error("no vmware card found");

	switch(p->did){
	default:
		snprint(err, sizeof err, "unknown vmware id %.4ux", p->did);
		error(err);
		
	case VMWARE1:
		vm->ra = 0x4560;
		vm->rd = 0x4560+4;
		break;

	case VMWARE2:
		vm->ra = p->mem[0].bar&~3;
		vm->rd = vm->ra + 1;
	}

	aperture = (ulong)(vmrd(vm, Rfbstart));
	*size = vmrd(vm, Rfbsize);

	if(wasupamem)
		upafree(oaperture, oapsize);
	scr->isupamem = 0;

	aperture = upamalloc(aperture, *size, *align);
	if(aperture == 0){
		if(wasupamem && upamalloc(oaperture, oapsize, 0))
			scr->isupamem = 1;
	}else
		scr->isupamem = 1;

	if(oaperture)
		print("warning (BUG): redefinition of aperture does not change vmwarescreen segment\n");
	memset(&seg, 0, sizeof(seg));
	seg.attr = SG_PHYSICAL;
	seg.name = smalloc(32);
	snprint(seg.name, 32, "vmwarescreen");
	seg.pa = aperture;
	seg.size = osize;
	addphysseg(&seg);
	return aperture;
}

static void
vmwaredisable(VGAscr*)
{
}

static void
vmwareload(VGAscr*, Cursor*)
{
}

static int
vmwaremove(VGAscr*, Point)
{
	return 0;
}

static void
vmwareenable(VGAscr*)
{
}

static void
vmwareblank(int)
{
}

static void
vmwaredrawinit(VGAscr*)
{
}

VGAdev vgavmwaredev = {
	"vmware",

	0,
	0,
	0,
	vmwarelinear,
	vmwaredrawinit,
};

VGAcur vgavmwarecur = {
	"vmwarehwgc",

	vmwareenable,
	vmwaredisable,
	vmwareload,
	vmwaremove,
};
.
## diffname pc/vgavmware.c 2001/0908
## diff -e /n/emeliedump/2001/0822/sys/src/9/pc/vgavmware.c /n/emeliedump/2001/0908/sys/src/9/pc/vgavmware.c
136,142c
	addvgaseg("vmwarescreen", aperture, osize);
.
134c
	if(oaperture && aperture != oaperture)
.
94d
## diffname pc/vgavmware.c 2002/0404
## diff -e /n/emeliedump/2001/0908/sys/src/9/pc/vgavmware.c /n/emeliedump/2002/0404/sys/src/9/pc/vgavmware.c
177a
	0,
	0,
	0,
	vmwareflush,
.
167a
	ulong mmiobase, mmiosize;

extern int iprintscreenputs;
	iprintscreenputs = 0;

	if(scr->mmio==nil){
		mmiobase = vmrd(vm, Rmemstart);
		if(mmiobase == 0){
			iprint("mmiobase 0\n");
			return;
		}
		mmiosize = vmrd(vm, Rmemsize);
		scr->mmio = KADDR(upamalloc(mmiobase, mmiosize, 0));
iprint("mmio %p\n", scr->mmio);
		vm->mmio = scr->mmio;
		vm->mmiosize = mmiosize;
		if(scr->mmio == nil)
			return;
		addvgaseg("vmwaremmio", mmiobase, mmiosize);
	}

	scr->mmio[FifoMin] = 4*sizeof(ulong);
	scr->mmio[FifoMax] = vm->mmiosize;
	scr->mmio[FifoNextCmd] = 4*sizeof(ulong);
	scr->mmio[FifoStop] = 4*sizeof(ulong);
	vmwr(vm, Rconfigdone, 1);

	scr->scroll = vmwarescroll;
	scr->fill = vmwarefill;
.
166c
vmwaredrawinit(VGAscr *scr)
.
164a
static int
vmwarescroll(VGAscr*, Rectangle r, Rectangle sr)
{
	if(vm->mmio == nil)
		return 0;
	vmfifowr(vm, Xrectropcopy);
	vmfifowr(vm, r.max.x);
	vmfifowr(vm, r.max.y);
	vmfifowr(vm, r.min.x);
	vmfifowr(vm, r.min.y);
	vmfifowr(vm, sr.min.x - r.min.x);
	vmfifowr(vm, sr.min.y - r.min.y);
	vmfifowr(vm, 3);	/* code for copy */
	vmwait(vm);
	return 1;
}

static int
vmwarefill(VGAscr*, Rectangle r, ulong sval)
{
	if(vm->mmio == nil)
		return 0;
	vmfifowr(vm, Xrectfill);
	vmfifowr(vm, sval);
	vmfifowr(vm, r.min.x);
	vmfifowr(vm, r.min.y);
	vmfifowr(vm, r.max.x-r.min.x);
	vmfifowr(vm, r.max.y-r.min.y);
	vmwait(vm);
	return 1;
}

.
157a
	vmwr(vm, Rcursorid, 1);
	vmwr(vm, Rcursoron, CursorOnShow);
.
155a
vmwaredisable(VGAscr*)
{
	vmwr(vm, Rcursorid, 1);
	vmwr(vm, Rcursoron, CursorOnHide);
}

static void
.
151a
	vmwr(vm, Rcursorid, 1);
	vmwr(vm, Rcursorx, p.x);
	vmwr(vm, Rcursory, p.y);
	vmwr(vm, Rcursoron, CursorOnShow);
.
150c
vmwaremove(VGAscr*, Point p)
.
148a
static void
vmwareload(VGAscr*, Cursor *c)
{
	int i;
	ulong clr, set;
	ulong and[16];
	ulong xor[16];

	if(vm->mmio == nil)
		return;
	vmfifowr(vm, Xdefinecursor);
	vmfifowr(vm, 1);	/* cursor id */
	vmfifowr(vm, -c->offset.x);
	vmfifowr(vm, -c->offset.y);

	vmfifowr(vm, 16);	/* width */
	vmfifowr(vm, 16);	/* height */
	vmfifowr(vm, 1);	/* depth for and mask */
	vmfifowr(vm, 1);	/* depth for xor mask */

	for(i=0; i<16; i++){
		clr = (c->clr[i*2+1]<<8) | c->clr[i*2];
		set = (c->set[i*2+1]<<8) | c->set[i*2];
		and[i] = ~(clr|set);	/* clr and set pixels => black */
		xor[i] = clr&~set;		/* clr pixels => white */
	}
	for(i=0; i<16; i++)
		vmfifowr(vm, and[i]);
	for(i=0; i<16; i++)
		vmfifowr(vm, xor[i]);

	vmwait(vm);
}

.
146a
	if(vm->mmio == nil)
		return;

	vmfifowr(vm, Xupdate);
	vmfifowr(vm, r.min.x);
	vmfifowr(vm, r.min.y);
	vmfifowr(vm, r.max.x-r.min.x);
	vmfifowr(vm, r.max.y-r.min.y);
	vmwait(vm);
.
145c
vmwareflush(VGAscr*, Rectangle r)
.
141a
	ulong *mm;

	mm = vm->mmio;
	if(mm == nil){
		iprint("!");
		return;
	}

	if(mm[FifoNextCmd]+sizeof(ulong) == mm[FifoStop]
	|| (mm[FifoNextCmd]+sizeof(ulong) == mm[FifoMax]
	    && mm[FifoStop] == mm[FifoMin]))
		vmwait(vm);

	mm[mm[FifoNextCmd]/sizeof(ulong)] = v;
	mm[FifoNextCmd] += sizeof(ulong);
	if(mm[FifoNextCmd]==mm[FifoMax])
		mm[FifoNextCmd] = mm[FifoMin];
.
140c
vmfifowr(Vmware *vm, ulong v)
.
135a

.
132a
iprint("aperture %lux size %lux\n", aperture, *size);
.
131a
}
.
130a
{
memset((void*)KADDR(aperture), 0x7F, 1048576);
.
99a
iprint("osize %d oaperture %.8lux oapsize %d wasupamem %d\n", osize, oaperture, oapsize, wasupamem);
.
86a
static void
vmwait(Vmware *vm)
{
	vmwr(vm, Rsync, 1);
	while(vmrd(vm, Rbusy))
		;
}

.
64a
	ulong	*mmio;
	ulong	mmiosize;
.
58d
52a
	Crectfill = 1<<0,
	Crectcopy = 1<<1,
	Crectpatfill = 1<<2,
	Coffscreen = 1<<3,
	Crasterop = 1<<4,
	Ccursor = 1<<5,
	Ccursorbypass = 1<<6,
	Ccursorbypass2 = 1<<7,
	C8bitemulation = 1<<8,
	Calphacursor = 1<<9,

	FifoMin = 0,
	FifoMax = 1,
	FifoNextCmd = 2,
	FifoStop = 3,
	FifoUser = 4,

	Xupdate = 1,
	Xrectfill = 2,
	Xrectcopy = 3,
	Xdefinebitmap = 4,
	Xdefinebitmapscanline = 5,
	Xdefinepixmap = 6,
	Xdefinepixmapscanline = 7,
	Xrectbitmapfill = 8,
	Xrectpixmapfill = 9,
	Xrectbitmapcopy = 10,
	Xrectpixmapcopy = 11,
	Xfreeobject = 12,
	Xrectropfill = 13,
	Xrectropcopy = 14,
	Xrectropbitmapfill = 15,
	Xrectroppixmapfill = 16,
	Xrectropbitmapcopy = 17,
	Xrectroppixmapcopy = 18,
	Xdefinecursor = 19,
	Xdisplaycursor = 20,
	Xmovecursor = 21,
	Xdefinealphacursor = 22,
	Xcmdmax = 23,

	CursorOnHide = 0,
	CursorOnShow = 1,
	CursorOnRemoveFromFb = 2,
	CursorOnRestoreToFb = 3,

.
47a

.
42a

.
37a

.
32a

.
27a

.
## diffname pc/vgavmware.c 2002/0405
## diff -e /n/emeliedump/2002/0404/sys/src/9/pc/vgavmware.c /n/emeliedump/2002/0405/sys/src/9/pc/vgavmware.c
352d
349d
346,347c
		if(mmiobase == 0)
.
341,343d
314,316c
	vmfifowr(vm, Dx(r));
	vmfifowr(vm, Dy(r));
.
309,311c
	vmfifowr(vm, Xrectcopy);
	vmfifowr(vm, sr.min.x);
	vmfifowr(vm, sr.min.y);
.
197d
195d
192,193d
160d
## diffname pc/vgavmware.c 2002/0501
## diff -e /n/emeliedump/2002/0405/sys/src/9/pc/vgavmware.c /n/emeliedump/2002/0501/sys/src/9/pc/vgavmware.c
355a

	offset = vmrd(vm, Rfboffset);
	scr->gscreendata->bdata += offset;
.
332a
	ulong offset;
.

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].