shithub: riscv

Download patch

ref: c458216121d622858916387071cd9c13df31820a
parent: 9fec0e736081cd155afb6a413b7641b93faed519
author: cinap_lenrek <[email protected]>
date: Sun Oct 7 19:38:41 EDT 2018

pc drivers: more pci cleanup

--- a/sys/src/9/pc/ethervirtio.c
+++ b/sys/src/9/pc/ethervirtio.c
@@ -470,6 +470,7 @@
 {
 	Ctlr *ctlr = edev->ctlr;
 	outb(ctlr->port+Qstatus, 0);
+	pciclrbme(ctlr->pcidev);
 }
 
 static void
@@ -577,6 +578,7 @@
 
 		c->typ = typ;
 		c->pcidev = p;
+		pcienable(p);
 		c->id = (p->did<<16)|p->vid;
 
 		/* §3.1.2 Legacy Device Initialization */
@@ -603,6 +605,7 @@
 		}
 		if(i < 2){
 			print("ethervirtio: no queues\n");
+			pcidisable(p);
 			free(c);
 			continue;
 		}
@@ -626,9 +629,8 @@
 	Ctlr *ctlr;
 	int i;
 
-	if(ctlrhead == nil) {
+	if(ctlrhead == nil)
 		ctlrhead = pciprobe(1);
-	}
 
 	for(ctlr = ctlrhead; ctlr != nil; ctlr = ctlr->next){
 		if(ctlr->active)
@@ -668,6 +670,7 @@
 		edev->promiscuous = promiscuous;
 	}
 
+	pcisetbme(ctlr->pcidev);
 	intrenable(edev->irq, interrupt, edev, edev->tbdf, edev->name);
 
 	return 0;
--- a/sys/src/9/pc/etheryuk.c
+++ b/sys/src/9/pc/etheryuk.c
@@ -2129,8 +2129,6 @@
 	Pcidev *p;
 
 	p = c->p;
-	pcienable(p);
-
 	c->io = p->mem[0].bar&~0xf;
 	mem = vmap(c->io, p->mem[0].size);
 	if(mem == nil){
@@ -2137,6 +2135,7 @@
 		print("yuk: cant map %#p\n", c->io);
 		return -1;
 	}
+	pcienable(p);
 	c->p = p;
 	c->reg = (uint*)mem;
 	c->reg8 = (uchar*)mem;
@@ -2159,15 +2158,15 @@
 	c->rx.r = slice(&v, 16*4096, sizeof c->rx.r[0] * c->rx.cnt);
 
 	c->nports = 1;				/* BOTCH */
-	pcisetbme(p);
 	if(reset(c)){
 		print("yuk: cant reset\n");
-		pciclrbme(p);
 		free(c->alloc);
 		vunmap(mem, p->mem[0].size);
+		pcidisable(p);
 		return -1;
 	}
 	macinit(c);
+	pcisetbme(p);
 	return 0;
 }
 
--- a/sys/src/9/pc/sdodin.c
+++ b/sys/src/9/pc/sdodin.c
@@ -2438,6 +2438,7 @@
 //	disable(c->hba);
 	snprint(buf, sizeof buf, "%s (%s)", s->name, s->ifc->name);
 	intrdisable(c->pci->intl, msinterrupt, c, c->pci->tbdf, buf);
+	pciclrbme(c->pci);
 	c->enabled = 0;
 	iunlock(c);
 	return 1;
@@ -2655,6 +2656,7 @@
 			print("sdodin: bar %#p in use\n", c->reg);
 			continue;
 		}
+		pcienable(p);
 		nunit = p->did>>4 & 0xf;
 		s->ifc = &sdodinifc;
 		s->idno = 'a' + nmsctlr;
--- a/sys/src/9/pc/sdvirtio.c
+++ b/sys/src/9/pc/sdvirtio.c
@@ -217,6 +217,7 @@
 		}
 		vd->typ = typ;
 		vd->pci = p;
+		pcienable(p);
 
 		/* reset */
 		outb(vd->port+Status, 0);
@@ -576,6 +577,7 @@
 	Vdev *vd;
 
 	vd = sd->ctlr;
+	pcisetbme(vd->pci);
 	snprint(name, sizeof(name), "%s (%s)", sd->name, sd->ifc->name);
 	intrenable(vd->pci->intl, viointerrupt, vd, vd->pci->tbdf, name);
 	outb(vd->port+Status, inb(vd->port+Status) | DriverOk);
@@ -591,6 +593,7 @@
 	vd = sd->ctlr;
 	snprint(name, sizeof(name), "%s (%s)", sd->name, sd->ifc->name);
 	intrdisable(vd->pci->intl, viointerrupt, vd, vd->pci->tbdf, name);
+	pciclrbme(vd->pci);
 	return 1;
 }