summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2021-01-17 11:53:50 +0100
committercinap_lenrek <cinap_lenrek@felloff.net>2021-01-17 11:53:50 +0100
commit3240008dd182a0d88fb2d0d5ffc5e88accdd957f (patch)
treef83b808861b30f5798523b797bc07a444c1d6526
parent87b1d454ed703e6e93e96c40d73388d5220c1a34 (diff)
downloadplan9front-3240008dd182a0d88fb2d0d5ffc5e88accdd957f.tar.xz
usbuhci: remove resetlk, simplify scanpci()
-rw-r--r--sys/src/9/pc/usbuhci.c67
1 files changed, 28 insertions, 39 deletions
diff --git a/sys/src/9/pc/usbuhci.c b/sys/src/9/pc/usbuhci.c
index a5783d546..f1c084371 100644
--- a/sys/src/9/pc/usbuhci.c
+++ b/sys/src/9/pc/usbuhci.c
@@ -144,6 +144,7 @@ struct Ctlr
Lock; /* for ilock. qh lists and basic ctlr I/O */
QLock portlck; /* for port resets/enable... */
Pcidev* pcidev;
+ Ctlr *next;
int active;
int port; /* I/O address */
Qh* qhs; /* list of Qhs for this controller */
@@ -289,8 +290,6 @@ struct Td
#define dqprint if(debug || (qh->io && qh->io->debug))print
#define ddqprint if(debug>1 || (qh->io && qh->io->debug>1))print
-static Ctlr* ctlrs[Nhcis];
-
static Tdpool tdpool;
static Qhpool qhpool;
static int debug;
@@ -533,19 +532,8 @@ xdump(Ctlr *ctlr, int doilock)
Qh *qh;
int i;
- if(doilock){
- if(ctlr == ctlrs[0]){
- lock(&tdpool);
- print("tds: alloc %d = inuse %d + free %d\n",
- tdpool.nalloc, tdpool.ninuse, tdpool.nfree);
- unlock(&tdpool);
- lock(&qhpool);
- print("qhs: alloc %d = inuse %d + free %d\n",
- qhpool.nalloc, qhpool.ninuse, qhpool.nfree);
- unlock(&qhpool);
- }
+ if(doilock)
ilock(ctlr);
- }
print("uhci port %#x frames %#p nintr %d ntdintr %d",
ctlr->port, ctlr->frames, ctlr->nintr, ctlr->ntdintr);
print(" nqhintr %d nisointr %d\n", ctlr->nqhintr, ctlr->nisointr);
@@ -564,8 +552,19 @@ xdump(Ctlr *ctlr, int doilock)
}
}
print("\n");
- if(doilock)
+ if(doilock){
iunlock(ctlr);
+ if(ctlr->next == nil){
+ lock(&tdpool);
+ print("tds: alloc %d = inuse %d + free %d\n",
+ tdpool.nalloc, tdpool.ninuse, tdpool.nfree);
+ unlock(&tdpool);
+ lock(&qhpool);
+ print("qhs: alloc %d = inuse %d + free %d\n",
+ qhpool.nalloc, qhpool.ninuse, qhpool.nfree);
+ unlock(&qhpool);
+ }
+ }
}
static void
@@ -2109,18 +2108,18 @@ portstatus(Hci *hp, int port)
return r;
}
-static void
+static Ctlr*
scanpci(void)
{
- static int already = 0;
- int io;
- int i;
+ static Ctlr *first, **lastp;
Ctlr *ctlr;
Pcidev *p;
+ int io;
+
+ if(lastp != nil)
+ return first;
+ lastp = &first;
- if(already)
- return;
- already = 1;
p = nil;
while(p = pcimatch(p, 0, 0)){
/*
@@ -2158,14 +2157,11 @@ scanpci(void)
}
ctlr->pcidev = p;
ctlr->port = io;
- for(i = 0; i < Nhcis; i++)
- if(ctlrs[i] == nil){
- ctlrs[i] = ctlr;
- break;
- }
- if(i == Nhcis)
- print("usbuhci: bug: no more controllers\n");
+
+ *lastp = ctlr;
+ lastp = &ctlr->next;
}
+ return first;
}
static void
@@ -2293,32 +2289,24 @@ shutdown(Hci *hp)
static int
reset(Hci *hp)
{
- static Lock resetlck;
- int i;
Ctlr *ctlr;
Pcidev *p;
if(getconf("*nousbuhci"))
return -1;
- ilock(&resetlck);
- scanpci();
-
/*
* Any adapter matches if no hp->port is supplied,
* otherwise the ports must match.
*/
- ctlr = nil;
- for(i = 0; i < Nhcis && ctlrs[i] != nil; i++){
- ctlr = ctlrs[i];
+ for(ctlr = scanpci(); ctlr != nil; ctlr = ctlr->next){
if(ctlr->active == 0)
if(hp->port == 0 || hp->port == ctlr->port){
ctlr->active = 1;
break;
}
}
- iunlock(&resetlck);
- if(ctlrs[i] == nil || i == Nhcis)
+ if(ctlr == nil)
return -1;
p = ctlr->pcidev;
@@ -2352,6 +2340,7 @@ reset(Hci *hp)
hp->shutdown = shutdown;
hp->debug = setdebug;
hp->type = "uhci";
+
intrenable(hp->irq, hp->interrupt, hp, hp->tbdf, hp->type);
return 0;