shithub: riscv

Download patch

ref: 5f23d78f068fcc33555705ee43933fc8ed8b4fc0
parent: 48352be82574e39a54e44b5ed38d407dcb66a0bb
author: cinap_lenrek <[email protected]>
date: Mon Jul 31 13:36:56 EDT 2017

usbohci, usbehci, usbxhci: save mmio base address in ctlr, cant PADDR() on 386...

--- a/sys/src/9/pc/usbehci.h
+++ b/sys/src/9/pc/usbehci.h
@@ -170,6 +170,7 @@
 	Lock;			/* for ilock. qh lists and basic ctlr I/O */
 	QLock	portlck;	/* for port resets/enable... (and doorbell) */
 	int	active;		/* in use or not */
+	uintptr	base;
 	Pcidev*	pcidev;
 	Ecapio*	capio;		/* Capability i/o regs */
 	Eopio*	opio;		/* Operational i/o regs */
--- a/sys/src/9/pc/usbehcipc.c
+++ b/sys/src/9/pc/usbehcipc.c
@@ -175,11 +175,9 @@
 		default:
 			continue;
 		}
-		if(io == 0){
-			print("usbehci: %x %x: failed to map registers\n",
-				p->vid, p->did);
+		if(io == 0)
 			continue;
-		}
+
 		print("usbehci: %#x %#x: port %#p size %#x irq %d\n",
 			p->vid, p->did, io, p->mem[0].size, p->intl);
 
@@ -189,6 +187,7 @@
 			continue;
 		}
 		ctlr->pcidev = p;
+		ctlr->base = io;
 		capio = ctlr->capio = vmap(io, p->mem[0].size);
 		ctlr->opio = (Eopio*)((uintptr)capio + (capio->cap & 0xff));
 		pcisetbme(p);
@@ -239,7 +238,7 @@
 	for(i = 0; i < Nhcis && ctlrs[i] != nil; i++){
 		ctlr = ctlrs[i];
 		if(ctlr->active == 0)
-		if(hp->port == 0 || hp->port == PADDR(ctlr->capio)){
+		if(hp->port == 0 || hp->port == ctlr->base){
 			ctlr->active = 1;
 			break;
 		}
@@ -250,7 +249,7 @@
 
 	p = ctlr->pcidev;
 	hp->aux = ctlr;
-	hp->port = PADDR(ctlr->capio);
+	hp->port = ctlr->base;
 	hp->irq = p->intl;
 	hp->tbdf = p->tbdf;
 
--- a/sys/src/9/pc/usbohci.c
+++ b/sys/src/9/pc/usbohci.c
@@ -350,6 +350,7 @@
 	Qtree*	tree;		/* tree for t Ep i/o */
 	int	ntree;		/* number of dummy Eds in tree */
 	Pcidev*	pcidev;
+	uintptr	base;
 };
 
 #define dqprint		if(debug || io && io->debug)print
@@ -2378,7 +2379,7 @@
 static void
 scanpci(void)
 {
-	ulong mem;
+	uintptr io;
 	Ctlr *ctlr;
 	Pcidev *p;
 	int i;
@@ -2392,17 +2393,13 @@
 		/*
 		 * Find Ohci controllers (Programming Interface = 0x10).
 		 */
-		if(p->ccrb != Pcibcserial || p->ccru != Pciscusb ||
-		    p->ccrp != 0x10)
+		if(p->ccrb != Pcibcserial || p->ccru != Pciscusb || p->ccrp != 0x10)
 			continue;
-		mem = p->mem[0].bar & ~0x0F;
-		dprint("ohci: %x/%x port 0x%lux size 0x%x irq %d\n",
-			p->vid, p->did, mem, p->mem[0].size, p->intl);
-		if(mem == 0){
-			print("ohci: failed to map registers\n");
+		io = p->mem[0].bar & ~0x0F;
+		if(io == 0)
 			continue;
-		}
-
+		print("usbohci: %#x %#x: port %#p size %#x irq %d\n",
+			p->vid, p->did, io, p->mem[0].size, p->intl);
 		ctlr = malloc(sizeof(Ctlr));
 		if(ctlr == nil){
 			print("ohci: no memory\n");
@@ -2409,7 +2406,8 @@
 			continue;
 		}
 		ctlr->pcidev = p;
-		ctlr->ohci = vmap(mem, p->mem[0].size);
+		ctlr->base = io;
+		ctlr->ohci = vmap(io, p->mem[0].size);
 		dprint("scanpci: ctlr %#p, ohci %#p\n", ctlr, ctlr->ohci);
 		pcisetbme(p);
 		pcisetpms(p, 0);
@@ -2571,7 +2569,7 @@
 	for(i = 0; i < Nhcis && ctlrs[i] != nil; i++){
 		ctlr = ctlrs[i];
 		if(ctlr->active == 0)
-		if(hp->port == 0 || hp->port == PADDR(ctlr->ohci)){
+		if(hp->port == 0 || hp->port == ctlr->base){
 			ctlr->active = 1;
 			break;
 		}
@@ -2585,7 +2583,7 @@
 
 	p = ctlr->pcidev;
 	hp->aux = ctlr;
-	hp->port = PADDR(ctlr->ohci);
+	hp->port = ctlr->base;
 	hp->irq = p->intl;
 	hp->tbdf = p->tbdf;
 	ctlr->nports = hp->nports = ctlr->ohci->rhdesca & 0xff;
--- a/sys/src/9/pc/usbxhci.c
+++ b/sys/src/9/pc/usbxhci.c
@@ -238,6 +238,7 @@
 	void	(*setrptr)(u32int*, u64int);
 
 	void	*active;
+	uintptr	base;
 };
 
 struct Epio
@@ -1437,6 +1438,8 @@
 		io = p->mem[0].bar & ~0x0f;
 		if(io == 0)
 			continue;
+		print("usbxhci: %#x %#x: port %#p size %#x irq %d\n",
+			p->vid, p->did, io, p->mem[0].size, p->intl);
 		mmio = vmap(io, p->mem[0].size);
 		if(mmio == nil){
 			print("usbxhci: cannot map registers\n");
@@ -1448,8 +1451,7 @@
 			vunmap(mmio, p->mem[0].size);
 			continue;
 		}
-		print("usbxhci: %#x %#x: port %#p size %#x irq %d\n",
-			p->vid, p->did, io, p->mem[0].size, p->intl);
+		ctlr->base = io;
 		ctlr->active = nil;
 		ctlr->pcidev = p;
 		ctlr->mmio = mmio;
@@ -1481,7 +1483,7 @@
 	for(i = 0; i < nelem(ctlrs) && ctlrs[i] != nil; i++){
 		ctlr = ctlrs[i];
 		if(ctlr->active == nil)
-		if(hp->port == 0 || hp->port == PADDR(ctlr->mmio)){
+		if(hp->port == 0 || hp->port == ctlr->base){
 			ctlr->active = hp;
 			goto Found;
 		}
@@ -1490,7 +1492,7 @@
 
 Found:
 	hp->aux = ctlr;
-	hp->port = PADDR(ctlr->mmio);
+	hp->port = ctlr->base;
 	hp->irq = ctlr->pcidev->intl;
 	hp->tbdf = ctlr->pcidev->tbdf;