xref: /kvm-unit-tests/lib/virtio-mmio.h (revision 43402ba5fa2dc06e12855a04f6003f1b3f838070)
1 #ifndef _VIRTIO_MMIO_H_
2 #define _VIRTIO_MMIO_H_
3 /*
4  * A minimal implementation of virtio-mmio. Adapted from the Linux Kernel.
5  *
6  * Copyright (C) 2014, Red Hat Inc, Andrew Jones <drjones@redhat.com>
7  *
8  * This work is licensed under the terms of the GNU LGPL, version 2.
9  */
10 #include "libcflat.h"
11 #include "virtio.h"
12 
13 #define VIRTIO_MMIO_MAGIC_VALUE		0x000
14 #define VIRTIO_MMIO_VERSION		0x004
15 #define VIRTIO_MMIO_DEVICE_ID		0x008
16 #define VIRTIO_MMIO_VENDOR_ID		0x00c
17 #define VIRTIO_MMIO_HOST_FEATURES	0x010
18 #define VIRTIO_MMIO_HOST_FEATURES_SEL	0x014
19 #define VIRTIO_MMIO_GUEST_FEATURES	0x020
20 #define VIRTIO_MMIO_GUEST_FEATURES_SEL	0x024
21 #define VIRTIO_MMIO_GUEST_PAGE_SIZE	0x028
22 #define VIRTIO_MMIO_QUEUE_SEL		0x030
23 #define VIRTIO_MMIO_QUEUE_NUM_MAX	0x034
24 #define VIRTIO_MMIO_QUEUE_NUM		0x038
25 #define VIRTIO_MMIO_QUEUE_ALIGN		0x03c
26 #define VIRTIO_MMIO_QUEUE_PFN		0x040
27 #define VIRTIO_MMIO_QUEUE_NOTIFY	0x050
28 #define VIRTIO_MMIO_INTERRUPT_STATUS	0x060
29 #define VIRTIO_MMIO_INTERRUPT_ACK	0x064
30 #define VIRTIO_MMIO_STATUS		0x070
31 #define VIRTIO_MMIO_CONFIG		0x100
32 
33 #define VIRTIO_MMIO_INT_VRING		(1 << 0)
34 #define VIRTIO_MMIO_INT_CONFIG		(1 << 1)
35 
36 
37 #define to_virtio_mmio_device(vdev_ptr) \
38 	container_of(vdev_ptr, struct virtio_mmio_device, vdev)
39 
40 struct virtio_mmio_device {
41 	struct virtio_device vdev;
42 	void *base;
43 };
44 
45 extern struct virtio_device *virtio_mmio_bind(u32 devid);
46 
47 #endif /* _VIRTIO_MMIO_H_ */
48