Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

virtio-mmio: use byte to byte in read/write config when length != 1,2,4,8 #11485

Merged
merged 1 commit into from
Jan 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 22 additions & 20 deletions drivers/virtio/virtio-mmio.c
Original file line number Diff line number Diff line change
Expand Up @@ -553,16 +553,9 @@ static void virtio_mmio_write_config(FAR struct virtio_device *vdev,
uint16_t u16data;
uint8_t u8data;

if (vdev->id.version == VIRTIO_MMIO_VERSION_1 || length > 8)
if (vdev->id.version == VIRTIO_MMIO_VERSION_1)
{
FAR char *s = src;
int i;
for (i = 0; i < length; i++)
{
metal_io_write8(&vmdev->cfg_io, write_offset + i, s[i]);
}

return;
goto byte_write;
}

switch (length)
Expand All @@ -587,7 +580,15 @@ static void virtio_mmio_write_config(FAR struct virtio_device *vdev,
u32data);
break;
default:
DEBUGASSERT(0);
byte_write:
{
FAR char *s = src;
int i;
for (i = 0; i < length; i++)
{
metal_io_write8(&vmdev->cfg_io, write_offset + i, s[i]);
}
}
}
}

Expand All @@ -606,16 +607,9 @@ static void virtio_mmio_read_config(FAR struct virtio_device *vdev,
uint16_t u16data;
uint8_t u8data;

if (vdev->id.version == VIRTIO_MMIO_VERSION_1 || length > 8)
if (vdev->id.version == VIRTIO_MMIO_VERSION_1)
{
FAR char *d = dst;
int i;
for (i = 0; i < length; i++)
{
d[i] = metal_io_read8(&vmdev->cfg_io, read_offset + i);
}

return;
goto byte_read;
}

switch (length)
Expand All @@ -640,7 +634,15 @@ static void virtio_mmio_read_config(FAR struct virtio_device *vdev,
memcpy(dst + sizeof(u32data), &u32data, sizeof(u32data));
break;
default:
DEBUGASSERT(0);
byte_read:
{
FAR char *d = dst;
int i;
for (i = 0; i < length; i++)
{
d[i] = metal_io_read8(&vmdev->cfg_io, read_offset + i);
}
}
}
}

Expand Down