Minor improvements to virtio (allow irqs, allocate page aligned).
authorKevin O'Connor <kevin@koconnor.net>
Sun, 16 May 2010 15:34:38 +0000 (11:34 -0400)
committerKevin O'Connor <kevin@koconnor.net>
Sun, 16 May 2010 15:34:38 +0000 (11:34 -0400)
Allow irqs to be handled while waiting for virtio reads to complete.

Use native page aligned allocations instead of manually aligning the
data.  This reduces the amount of low memory virtio requires.

Also, some minor white space cleanups.

src/virtio-blk.c
src/virtio-ring.h

index 6c3f8a5aff57bbbfbee49df973e646d7df26e048..7cc2edbf75dd0b5bc647210b72d8a307e924c8b7 100644 (file)
@@ -58,7 +58,7 @@ virtio_blk_read(struct disk_op_s *op)
 
     /* Wait for reply */
     while (!vring_more_used(vq))
-        udelay(5);
+        usleep(5);
 
     /* Reclaim virtqueue element */
     vring_get_buf(vq, NULL);
@@ -104,7 +104,7 @@ virtio_blk_setup(void)
                 pci_bdf_to_dev(bdf));
         char *desc = malloc_tmphigh(MAXDESCSIZE);
         struct virtiodrive_s *vdrive_g = malloc_fseg(sizeof(*vdrive_g));
-        struct vring_virtqueue *vq = malloc_low(sizeof(*vq));
+        struct vring_virtqueue *vq = memalign_low(PAGE_SIZE, sizeof(*vq));
         if (!vdrive_g || !desc || !vq) {
             free(vdrive_g);
             free(desc);
@@ -131,7 +131,7 @@ virtio_blk_setup(void)
             free(desc);
             free(vq);
             dprintf(1, "fail to find vq for virtio-blk %x:%x\n",
-                    pci_bdf_to_bus (bdf), pci_bdf_to_dev(bdf));
+                    pci_bdf_to_bus(bdf), pci_bdf_to_dev(bdf));
             continue;
         }
 
@@ -141,7 +141,7 @@ virtio_blk_setup(void)
         vdrive_g->drive.blksize = cfg.blk_size;
         vdrive_g->drive.sectors = cfg.capacity;
         dprintf(3, "virtio-blk %x:%x blksize=%d sectors=%u\n",
-                pci_bdf_to_bus (bdf), pci_bdf_to_dev(bdf),
+                pci_bdf_to_bus(bdf), pci_bdf_to_dev(bdf),
                 vdrive_g->drive.blksize, (u32)vdrive_g->drive.sectors);
 
         vdrive_g->drive.pchs.cylinders = cfg.cylinders;
@@ -160,4 +160,3 @@ virtio_blk_setup(void)
                       VIRTIO_CONFIG_S_DRIVER | VIRTIO_CONFIG_S_DRIVER_OK);
     }
 }
-
index 95ae85b5055bde3dd2607cb1e1d3d3edb3dfd3fb..3fb86fe4f6d07ba3b77fb5bf57ae5ba1f6b465f1 100644 (file)
@@ -72,7 +72,7 @@ struct vring {
          + PAGE_MASK) & ~PAGE_MASK) + \
          (sizeof(struct vring_used) + sizeof(struct vring_used_elem) * num))
 
-typedef unsigned char virtio_queue_t[PAGE_MASK + vring_size(MAX_QUEUE_NUM)];
+typedef unsigned char virtio_queue_t[vring_size(MAX_QUEUE_NUM)];
 
 struct vring_virtqueue {
    virtio_queue_t queue;