um: virtio: allow devices to be configured for wakeup

With all the IRQ machinery being in place, we can allow virtio
devices to additionally be configured as wakeup sources, in
which case basically any interrupt from them wakes us up. Note
that this requires a call FD because the VQs are all disabled.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
This commit is contained in:
Johannes Berg 2020-12-15 10:52:25 +01:00 committed by Richard Weinberger
parent c8177aba37
commit 1fcf9da389
1 changed files with 16 additions and 3 deletions

View File

@ -55,6 +55,7 @@ struct virtio_uml_device {
u64 protocol_features; u64 protocol_features;
u8 status; u8 status;
u8 registered:1; u8 registered:1;
u8 suspended:1;
u8 config_changed_irq:1; u8 config_changed_irq:1;
uint64_t vq_irq_vq_map; uint64_t vq_irq_vq_map;
@ -390,7 +391,7 @@ static irqreturn_t vu_req_read_message(struct virtio_uml_device *vu_dev,
msg.msg.header.request); msg.msg.header.request);
} }
if (ev) if (ev && !vu_dev->suspended)
time_travel_add_irq_event(ev); time_travel_add_irq_event(ev);
if (msg.msg.header.flags & VHOST_USER_FLAG_NEED_REPLY) if (msg.msg.header.flags & VHOST_USER_FLAG_NEED_REPLY)
@ -1135,6 +1136,8 @@ static int virtio_uml_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, vu_dev); platform_set_drvdata(pdev, vu_dev);
device_set_wakeup_capable(&vu_dev->vdev.dev, true);
rc = register_virtio_device(&vu_dev->vdev); rc = register_virtio_device(&vu_dev->vdev);
if (rc) if (rc)
put_device(&vu_dev->vdev.dev); put_device(&vu_dev->vdev.dev);
@ -1308,9 +1311,14 @@ static int virtio_uml_suspend(struct platform_device *pdev, pm_message_t state)
vhost_user_set_vring_enable(vu_dev, vq->index, false); vhost_user_set_vring_enable(vu_dev, vq->index, false);
} }
if (!device_may_wakeup(&vu_dev->vdev.dev)) {
vu_dev->suspended = true;
return 0; return 0;
} }
return irq_set_irq_wake(vu_dev->irq, 1);
}
static int virtio_uml_resume(struct platform_device *pdev) static int virtio_uml_resume(struct platform_device *pdev)
{ {
struct virtio_uml_device *vu_dev = platform_get_drvdata(pdev); struct virtio_uml_device *vu_dev = platform_get_drvdata(pdev);
@ -1323,7 +1331,12 @@ static int virtio_uml_resume(struct platform_device *pdev)
vhost_user_set_vring_enable(vu_dev, vq->index, true); vhost_user_set_vring_enable(vu_dev, vq->index, true);
} }
vu_dev->suspended = false;
if (!device_may_wakeup(&vu_dev->vdev.dev))
return 0; return 0;
return irq_set_irq_wake(vu_dev->irq, 0);
} }
static struct platform_driver virtio_uml_driver = { static struct platform_driver virtio_uml_driver = {