shithub: riscv

Download patch

ref: 9aec87c46c483ca1cf560e0e8a929cdf72447371
parent: 7848fe597006ecc6ee0605341ada08b7dea42f2a
author: cinap_lenrek <[email protected]>
date: Fri Jan 2 10:29:15 EST 2015

vgavesa: get rid of the vesa kproc

in 9front, screen blanking is always initiated from process context,
so there is no need for a kproc anymore.

care has been taken for the race between vesadisable() and vesablank()
by acquiering the drawlock prior calling scr->dev->enable() and
scr->dev->disable(). this also has the side effect of accelerated
fills and scrolls not being called during device disable.

--- a/sys/src/9/pc/devvga.c
+++ b/sys/src/9/pc/devvga.c
@@ -309,6 +309,11 @@
 		for(i = 0; vgadev[i]; i++){
 			if(strcmp(cb->f[1], vgadev[i]->name))
 				continue;
+			qlock(&drawlock);
+			if(waserror()){
+				qunlock(&drawlock);
+				nexterror();
+			}
 			if(scr->dev){
 				if(scr->dev->disable)
 					scr->dev->disable(scr);
@@ -319,6 +324,8 @@
 			scr->dev = vgadev[i];
 			if(scr->dev->enable)
 				scr->dev->enable(scr);
+			qunlock(&drawlock);
+			poperror();
 			return;
 		}
 		break;
--- a/sys/src/9/pc/vgavesa.c
+++ b/sys/src/9/pc/vgavesa.c
@@ -20,18 +20,11 @@
 #include "screen.h"
 
 enum {
-	Cdisable = 0,
-	Cenable,
-	Cblank,
-
 	RealModeBuf = 0x9000,
 };
 
 static uchar modebuf[0x1000];
 static Chan *creg, *cmem;
-static QLock vesaq;
-static Rendez vesar;
-static int vesactl;
 
 #define WORD(p) ((p)[0] | ((p)[1]<<8))
 #define LONG(p) ((p)[0] | ((p)[1]<<8) | ((p)[2]<<16) | ((p)[3]<<24))
@@ -165,59 +158,9 @@
 	scr->softscreen = 1;
 }
 
-static int
-gotctl(void *arg)
-{
-	return vesactl != *((int*)arg);
-}
-
 static void
-vesaproc(void*)
-{
-	Ureg386 u;
-	int ctl;
-
-	ctl = Cenable;
-	while(ctl != Cdisable){
-		if(!waserror()){
-			sleep(&vesar, gotctl, &ctl);
-			ctl = vesactl;
-
-			vbesetup(&u, 0x4f10);
-			if(ctl == Cblank)
-				u.bx = 0x0101;
-			else	
-				u.bx = 0x0001;
-
-			/*
-			 * dont wait forever here. some BIOS get stuck
-			 * in i/o poll loop after blank/unblank for some
-			 * reason. (Thinkpad A22p)
-			 */
-			procalarm(10000);
-			vbecall(&u);
-
-			poperror();
-		}
-		procalarm(0);
-		up->notepending = 0;
-	}
-	cclose(cmem);
-	cclose(creg);
-	cmem = creg = nil;
-	qunlock(&vesaq);
-
-	pexit("", 1);
-}
-
-static void
 vesaenable(VGAscr *)
 {
-	eqlock(&vesaq);
-	if(waserror()){
-		qunlock(&vesaq);
-		nexterror();
-	}
 	cmem = namec("/dev/realmodemem", Aopen, ORDWR, 0);
 	if(waserror()){
 		cclose(cmem);
@@ -226,29 +169,42 @@
 	}
 	creg = namec("/dev/realmode", Aopen, ORDWR, 0);
 	poperror();
-	poperror();
-
-	vesactl = Cenable;
-	kproc("vesa", vesaproc, nil);
 }
 
 static void
 vesadisable(VGAscr *)
 {
-	vesactl = Cdisable;
-	wakeup(&vesar);
-
-	/* wait for vesaproc to finish */
-	qlock(&vesaq);
-	qunlock(&vesaq);
+	if(cmem != nil)
+		cclose(cmem);
+	if(creg != nil)
+		cclose(creg);
+	cmem = creg = nil;
 }
 
 static void
 vesablank(VGAscr *, int blank)
 {
-	if(vesactl != Cdisable){
-		vesactl = blank ? Cblank : Cenable;
-		wakeup(&vesar);
+	Ureg386 u;
+
+	vbesetup(&u, 0x4f10);
+	u.bx = blank ? 0x0101 : 0x0001;
+
+	/*
+	 * dont wait forever when called from mouse kproc.
+	 * some BIOS get stuck in i/o poll loop after
+	 * blank/unblank for some reason. (Thinkpad A22p)
+	 */
+	if(up->kp)
+		procalarm(10000);
+
+	if(!waserror()){
+		vbecall(&u);
+		poperror();
+	}
+
+	if(up->kp){
+		procalarm(0);
+		up->notepending = 0;
 	}
 }