Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 255289
b: refs/heads/master
c: 3c3ed48
h: refs/heads/master
i:
  255287: f26ce87
v: v3
  • Loading branch information
Rusty Russell committed Jul 22, 2011
1 parent aa1c0c4 commit 92c35d6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 35 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 6d7a5d1ea34495ecb1d608f0e40afba7776ee408
refs/heads/master: 3c3ed482dc077a67903a58c9e1aedba1bb18c18a
25 changes: 6 additions & 19 deletions trunk/Documentation/virtual/lguest/lguest.c
Original file line number Diff line number Diff line change
Expand Up @@ -1095,9 +1095,10 @@ static void update_device_status(struct device *dev)
warnx("Device %s configuration FAILED", dev->name);
if (dev->running)
reset_device(dev);
} else if (dev->desc->status & VIRTIO_CONFIG_S_DRIVER_OK) {
if (!dev->running)
start_device(dev);
} else {
if (dev->running)
err(1, "Device %s features finalized twice", dev->name);
start_device(dev);
}
}

Expand All @@ -1122,25 +1123,11 @@ static void handle_output(unsigned long addr)
return;
}

/*
* Devices *can* be used before status is set to DRIVER_OK.
* The original plan was that they would never do this: they
* would always finish setting up their status bits before
* actually touching the virtqueues. In practice, we allowed
* them to, and they do (eg. the disk probes for partition
* tables as part of initialization).
*
* If we see this, we start the device: once it's running, we
* expect the device to catch all the notifications.
*/
/* Devices should not be used before features are finalized. */
for (vq = i->vq; vq; vq = vq->next) {
if (addr != vq->config.pfn*getpagesize())
continue;
if (i->running)
errx(1, "Notification on running %s", i->name);
/* This just calls create_thread() for each virtqueue */
start_device(i);
return;
errx(1, "Notification on %s before setup!", i->name);
}
}

Expand Down
37 changes: 22 additions & 15 deletions trunk/drivers/lguest/lguest_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,17 @@ static u32 lg_get_features(struct virtio_device *vdev)
return features;
}

/*
* To notify on reset or feature finalization, we (ab)use the NOTIFY
* hypercall, with the descriptor address of the device.
*/
static void status_notify(struct virtio_device *vdev)
{
unsigned long offset = (void *)to_lgdev(vdev)->desc - lguest_devices;

hcall(LHCALL_NOTIFY, (max_pfn << PAGE_SHIFT) + offset, 0, 0, 0);
}

/*
* The virtio core takes the features the Host offers, and copies the ones
* supported by the driver into the vdev->features array. Once that's all
Expand Down Expand Up @@ -135,6 +146,9 @@ static void lg_finalize_features(struct virtio_device *vdev)
if (test_bit(i, vdev->features))
out_features[i / 8] |= (1 << (i % 8));
}

/* Tell Host we've finished with this device's feature negotiation */
status_notify(vdev);
}

/* Once they've found a field, getting a copy of it is easy. */
Expand Down Expand Up @@ -168,28 +182,21 @@ static u8 lg_get_status(struct virtio_device *vdev)
return to_lgdev(vdev)->desc->status;
}

/*
* To notify on status updates, we (ab)use the NOTIFY hypercall, with the
* descriptor address of the device. A zero status means "reset".
*/
static void set_status(struct virtio_device *vdev, u8 status)
{
unsigned long offset = (void *)to_lgdev(vdev)->desc - lguest_devices;

/* We set the status. */
to_lgdev(vdev)->desc->status = status;
hcall(LHCALL_NOTIFY, (max_pfn << PAGE_SHIFT) + offset, 0, 0, 0);
}

static void lg_set_status(struct virtio_device *vdev, u8 status)
{
BUG_ON(!status);
set_status(vdev, status);
to_lgdev(vdev)->desc->status = status;

/* Tell Host immediately if we failed. */
if (status & VIRTIO_CONFIG_S_FAILED)
status_notify(vdev);
}

static void lg_reset(struct virtio_device *vdev)
{
set_status(vdev, 0);
/* 0 status means "reset" */
to_lgdev(vdev)->desc->status = 0;
status_notify(vdev);
}

/*
Expand Down

0 comments on commit 92c35d6

Please sign in to comment.