]> git.lizzy.rs Git - plan9front.git/blobdiff - sys/src/9/pc/sdvirtio.c
kernel: cleanup the software mouse cursor mess
[plan9front.git] / sys / src / 9 / pc / sdvirtio.c
index 17cab9cc30448892b47c07649ef1fdfe447e70d9..57ed15811134212c92874d7de605a23e8f35d8eb 100644 (file)
@@ -217,6 +217,7 @@ viopnpdevs(int typ)
                }
                vd->typ = typ;
                vd->pci = p;
+               pcienable(p);
 
                /* reset */
                outb(vd->port+Status, 0);
@@ -326,7 +327,7 @@ vqio(Vqueue *q, int head)
 static int
 vioblkreq(Vdev *vd, int typ, void *a, long count, long secsize, uvlong lba)
 {
-       int free, head;
+       int need, free, head;
        Vqueue *q;
        Vdesc *d;
 
@@ -337,14 +338,18 @@ vioblkreq(Vdev *vd, int typ, void *a, long count, long secsize, uvlong lba)
                u64int  lba;
        } req;
 
-       status = 0;
+       need = 2;
+       if(a != nil)
+               need = 3;
+
+       status = -1;
        req.typ = typ;
        req.prio = 0;
        req.lba = lba;
 
        q = vd->queue[0];
        ilock(q);
-       while(q->nfree < 3){
+       while(q->nfree < need){
                iunlock(q);
 
                if(!waserror())
@@ -361,10 +366,12 @@ vioblkreq(Vdev *vd, int typ, void *a, long count, long secsize, uvlong lba)
        d->len = sizeof(req);
        d->flags = Next;
 
-       d = &q->desc[free]; free = d->next;
-       d->addr = PADDR(a);
-       d->len = secsize*count;
-       d->flags = typ ? Next : (Write|Next);
+       if(a != nil){
+               d = &q->desc[free]; free = d->next;
+               d->addr = PADDR(a);
+               d->len = secsize*count;
+               d->flags = typ ? Next : (Write|Next);
+       }
 
        d = &q->desc[free]; free = d->next;
        d->addr = PADDR(&status);
@@ -372,7 +379,7 @@ vioblkreq(Vdev *vd, int typ, void *a, long count, long secsize, uvlong lba)
        d->flags = Write;
 
        q->free = free;
-       q->nfree -= 3;
+       q->nfree -= need;
 
        /* queue io, unlock and wait for completion */
        vqio(q, head);
@@ -563,11 +570,31 @@ vioverify(SDunit *u)
 
 SDifc sdvirtioifc;
 
-static void
-vdevenable(Vdev *vd)
+static int
+vioenable(SDev *sd)
 {
-       intrenable(vd->pci->intl, viointerrupt, vd, vd->pci->tbdf, "virtio");
+       char name[32];
+       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);
+       return 1;
+}
+
+static int
+viodisable(SDev *sd)
+{
+       char name[32];
+       Vdev *vd;
+
+       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;
 }
 
 static SDev*
@@ -584,8 +611,6 @@ viopnp(void)
                if(vd->nqueue != 1)
                        continue;
 
-               vdevenable(vd);
-
                if((s = malloc(sizeof(*s))) == nil)
                        break;
                s->ctlr = vd;
@@ -630,8 +655,6 @@ viopnp(void)
                        continue;
                }
                vd->cfg = cfg;
-                       
-               vdevenable(vd);
 
                if((s = malloc(sizeof(*s))) == nil)
                        break;
@@ -654,8 +677,8 @@ SDifc sdvirtioifc = {
 
        viopnp,                         /* pnp */
        nil,                            /* legacy */
-       nil,                            /* enable */
-       nil,                            /* disable */
+       vioenable,                      /* enable */
+       viodisable,                     /* disable */
 
        vioverify,                      /* verify */
        vioonline,                      /* online */