Skip to content

Commit

Permalink
virtio: Add virtio version check
Browse files Browse the repository at this point in the history
In the source code of qemu or linux, there is a check for the virtio version
/* Check device version */
priv->version = readl(priv->base + VIRTIO_MMIO_VERSION);
if (priv->version < 1 || priv->version > 2) {
	debug("(%s): version %d not supported!\n",
	udev->name, priv->version);
	return 0;
}
/* Check device ID */
uc_priv->device = readl(priv->base + VIRTIO_MMIO_DEVICE_ID);
if (uc_priv->device == 0) {
	/*
	* virtio-mmio device with an ID 0 is a (dummy) placeholder
	* with no function. End probing now with no error reported.
	*/
	return 0;
}

Signed-off-by: wangmingrong1 <[email protected]>
  • Loading branch information
W-M-R authored and xiaoxiang781216 committed Dec 4, 2024
1 parent 6e8375f commit eed302b
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions drivers/virtio/virtio-mmio.c
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,12 @@ static int virtio_mmio_init_device(FAR struct virtio_mmio_device_s *vmdev,
}

vdev->id.version = metal_io_read32(&vmdev->cfg_io, VIRTIO_MMIO_VERSION);
if (vdev->id.version < 1 || vdev->id.version > 2)
{
vrterr("Version %d not supported!\n", vdev->id.version);
return -ENODEV;
}

vdev->id.device = metal_io_read32(&vmdev->cfg_io, VIRTIO_MMIO_DEVICE_ID);
if (vdev->id.device == 0)
{
Expand Down

0 comments on commit eed302b

Please sign in to comment.