shithub: riscv

Download patch

ref: 25a9cc3adbf9f9af8e71dc6125fc32a9a17ab839
parent: 6a3b9012d551fecf4ba40d79dff8adbe54842835
author: cinap_lenrek <[email protected]>
date: Sat Dec 13 01:23:23 EST 2014

pc, pc64: untangle embedded controller (ec) dependency from devarch

--- a/sys/src/9/pc/devarch.c
+++ b/sys/src/9/pc/devarch.c
@@ -34,7 +34,6 @@
 	Qiow,
 	Qiol,
 	Qmsr,
-	Qec,
 	Qbase,
 
 	Qmax = 16,
@@ -64,7 +63,6 @@
 	"iow",		{ Qiow, 0 },		0,	0660,
 	"iol",		{ Qiol, 0 },		0,	0660,
 	"msr",		{ Qmsr, 0 },		0,	0660,
-	"ec",		{ Qec, 0 },		0,	0660,
 };
 Lock archwlock;	/* the lock is only for changing archdir */
 int narchdir = Qbase;
@@ -363,7 +361,7 @@
 archread(Chan *c, void *a, long n, vlong offset)
 {
 	char *buf, *p;
-	int port, v;
+	int port;
 	ushort *sp;
 	ulong *lp;
 	vlong *vp;
@@ -409,19 +407,6 @@
 				error(Ebadarg);
 		return n;
 
-	case Qec:
-		if(offset >= 256)
-			error(Ebadarg);
-		if(offset+n > 256)
-			n = 256 - offset;
-		p = a;
-		for(port = offset; port < offset+n; port++){
-			if((v = ecread(port)) < 0)
-				error(Eio);
-			*p++ = v;
-		}
-		return n;
-
 	case Qioalloc:
 		break;
 
@@ -499,15 +484,6 @@
 		for(port = offset; port < offset+n; port += 8)
 			if(wrmsr(port, *vp++) < 0)
 				error(Ebadarg);
-		return n;
-
-	case Qec:
-		if(offset+n > 256)
-			error(Ebadarg);
-		p = a;
-		for(port = offset; port < offset+n; port++)
-			if(ecwrite(port, *p++) < 0)
-				error(Eio);
 		return n;
 
 	default:
--- a/sys/src/9/pc/ec.c
+++ b/sys/src/9/pc/ec.c
@@ -64,30 +64,6 @@
 }
 
 int
-ecinit(int cmdport, int dataport)
-{
-	print("ec: cmd %X, data %X\n", cmdport, dataport);
-
-	if(ioalloc(cmdport, 1, 0, "ec.sc") < 0){
-		print("ec: cant allocate cmd port %X\n", cmdport);
-		return -1;
-	}
-	if(ioalloc(dataport, 1, 0, "ec.data") < 0){
-		print("ec: cant allocate data port %X\n", dataport);
-		iofree(cmdport);
-		return -1;
-	}
-
-	lock(&ec);
-	ec.port[EC_SC] = cmdport;
-	ec.port[EC_DATA] = dataport;
-	ec.init = 1;
-	unlock(&ec);
-
-	return 0;
-}
-
-int
 ecread(uchar addr)
 {
 	int r;
@@ -135,4 +111,64 @@
 out:
 	unlock(&ec);
 	return r;
+}
+
+static long
+ecarchread(Chan*, void *a, long n, vlong off)
+{
+	int port, v;
+	uchar *p;
+
+	if(off < 0 || off >= 256)
+		return 0;
+	if(off+n > 256)
+		n = 256 - off;
+	p = a;
+	for(port = off; port < off+n; port++){
+		if((v = ecread(port)) < 0)
+			error(Eio);
+		*p++ = v;
+	}
+	return n;
+}
+
+static long
+ecarchwrite(Chan*, void *a, long n, vlong off)
+{
+	int port;
+	uchar *p;
+
+	if(off < 0 || off+n > 256)
+		error(Ebadarg);
+	p = a;
+	for(port = off; port < off+n; port++)
+		if(ecwrite(port, *p++) < 0)
+			error(Eio);
+	return n;
+}
+
+int
+ecinit(int cmdport, int dataport)
+{
+	print("ec: cmd %X, data %X\n", cmdport, dataport);
+
+	if(ioalloc(cmdport, 1, 0, "ec.sc") < 0){
+		print("ec: cant allocate cmd port %X\n", cmdport);
+		return -1;
+	}
+	if(ioalloc(dataport, 1, 0, "ec.data") < 0){
+		print("ec: cant allocate data port %X\n", dataport);
+		iofree(cmdport);
+		return -1;
+	}
+
+	lock(&ec);
+	ec.port[EC_SC] = cmdport;
+	ec.port[EC_DATA] = dataport;
+	ec.init = 1;
+	unlock(&ec);
+
+	addarchfile("ec", 0660, ecarchread, ecarchwrite);
+
+	return 0;
 }
--- a/sys/src/9/pc/pccpuf
+++ b/sys/src/9/pc/pccpuf
@@ -70,6 +70,7 @@
 	etherwavelan	wavelan devi82365 cis pci
 	etheriwl	pci wifi
 	etherrt2860	pci wifi
+	ethervirtio	pci
 	ethermedium
 	netdevmedium
 	loopbackmedium
--- a/sys/src/9/pc/pcf
+++ b/sys/src/9/pc/pcf
@@ -85,10 +85,9 @@
 	audiohda
 
 misc
-	archacpi	mp apic squidboy
+	archacpi	mp apic squidboy ec
 	archmp		mp apic squidboy
 	mtrr
-	ec
 
 	sdaoe
 	sdide		pci sdscsi
--- a/sys/src/9/pc64/pc64
+++ b/sys/src/9/pc64/pc64
@@ -83,10 +83,9 @@
 	audiohda
 
 misc
-	archacpi	mp apic squidboy
+	archacpi	mp apic squidboy ec
 	archmp		mp apic squidboy
 	mtrr
-	ec
 
 #	sdaoe
 	sdide		pci sdscsi
--- a/sys/src/9/pc64/pccpu64
+++ b/sys/src/9/pc64/pccpu64
@@ -69,6 +69,7 @@
 #	etherwavelan	wavelan devi82365 cis pci
 	etheriwl	pci wifi
 #	etherrt2860	pci wifi
+	ethervirtio	pci
 	ethermedium
 #	pcmciamodem
 	netdevmedium
@@ -82,7 +83,7 @@
 	audiohda
 
 misc
-	archacpi	mp apic squidboy
+	archacpi	mp apic squidboy ec
 	archmp		mp apic squidboy
 	mtrr
 
@@ -96,7 +97,7 @@
 #	sdmmc		pci pmmc
 #	sdloop
 
-#	uarti8250
+	uarti8250
 #	uartisa
 #	uartpci		pci