diff options
author | Gerd Hoffmann <kraxel@redhat.com> | 2020-03-06 14:34:18 +0100 |
---|---|---|
committer | Gerd Hoffmann <kraxel@redhat.com> | 2020-05-15 13:34:29 +0200 |
commit | 69f65a4e8967a72076f39d9dfce1da0dc9aedfc1 (patch) | |
tree | e55cb251adf4d0a0850e42196da54ddbe5eabe63 /src/hw/virtio-mmio.c | |
parent | 51c6fc699e5a42343ff1f2884f67fee1ae12eac8 (diff) | |
download | seabios-69f65a4e8967a72076f39d9dfce1da0dc9aedfc1.tar.gz |
virtio-mmio: device probing and initialization.
Add virtio_mmio_setup_one() to setup virtio mmio devices. Add
vp_init_mmio() to initialize device struct. Because virtio-pci and
virtio-mmio are quite simliar we reuse the infrastructure we already
have for virtio-pci and just setup struct vp_cap for virtio-mmio.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Diffstat (limited to 'src/hw/virtio-mmio.c')
-rw-r--r-- | src/hw/virtio-mmio.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/hw/virtio-mmio.c b/src/hw/virtio-mmio.c new file mode 100644 index 00000000..0d6ef6e2 --- /dev/null +++ b/src/hw/virtio-mmio.c @@ -0,0 +1,58 @@ +#include "config.h" // CONFIG_DEBUG_LEVEL +#include "malloc.h" // free +#include "output.h" // dprintf +#include "stacks.h" // run_thread +#include "string.h" // memset +#include "virtio-pci.h" +#include "virtio-ring.h" +#include "virtio-mmio.h" + +void virtio_mmio_setup_one(u64 addr) +{ + u32 magic, version, devid; + void *mmio; + + if (addr >= 0x100000000) { + dprintf(1, "virtio-mmio: %llx: above 4G\n", addr); + return; + } + + mmio = (void*)(u32)(addr); + magic = readl(mmio); + if (magic != 0x74726976) { + dprintf(1, "virtio-mmio: %llx: magic mismatch\n", addr); + return; + } + version = readl(mmio+4); + if (version != 1 /* legacy */ && + version != 2 /* 1.0 */) { + dprintf(1, "virtio-mmio: %llx: unknown version %d\n", addr, version); + return; + } + devid = readl(mmio+8); + dprintf(1, "virtio-mmio: %llx: device id %x%s\n", + addr, devid, version == 1 ? " (legacy)" : ""); + switch (devid) { + case 2: /* blk */ + /* TODO */ + break; + case 8: /* scsi */ + /* TODO */ + break; + default: + break; + } +} + +void vp_init_mmio(struct vp_device *vp, void *mmio) +{ + memset(vp, 0, sizeof(*vp)); + vp->use_mmio = 1; + vp->common.mode = VP_ACCESS_MMIO; + vp->common.memaddr = mmio; + vp->device.mode = VP_ACCESS_MMIO; + vp->device.memaddr = mmio + 0x100; + vp_reset(vp); + vp_set_status(vp, VIRTIO_CONFIG_S_ACKNOWLEDGE | + VIRTIO_CONFIG_S_DRIVER); +} |