2 * Copyright (c) 2014 ETH Zurich.
5 * This file is distributed under the terms in the attached LICENSE file.
6 * If you do not find this file, copies can be found by writing to:
7 * ETH Zurich D-INFK, Universitaetsstrasse 6, CH-8092 Zurich. Attn: Systems Group.
10 #ifndef VIRTIO_VIRTIO_DEVICE_H
11 #define VIRTIO_VIRTIO_DEVICE_H
17 * 2.1 Device Status Field
20 /// The device is in the reset state (not discovered by the guest)
21 #define VIRTIO_DEVICE_STATUS_RESET 0x00
23 /// Guest OS has found the device and recognized it as a valid virtio device.
24 #define VIRTIO_DEVICE_STATUS_ACKNOWLEDGE 0x01
26 /// Guest OS knows how to drive the device i.e. recognized as valid virtio device.
27 #define VIRTIO_DEVICE_STATUS_DRIVER 0x02
29 /// Driver is set up and ready to drive the device.
30 #define VIRTIO_DEVICE_STATUS_DRIVER_OK 0x04
32 /// Driver has acknowledged all the features it understands
33 #define VIRTIO_DEVICE_STATUS_FEATURES_OK 0x08
35 /// Something went wrong in the guest, and it has given up on the device.
36 #define VIRTIO_DEVICE_STATUS_FAILED 0x80
40 * The following device IDs are used to identify different types of virtio
41 * devices. Some device IDs are reserved for devices which are not currently
42 * defined in this standard.
45 /// Invalid device identifier
46 #define VIRTIO_DEVICE_TYPE_INVALID 0x00
48 /// Device type for network interface cards
49 #define VIRTIO_DEVICE_TYPE_NET 0x01
51 /// Device type for block devices
52 #define VIRTIO_DEVICE_TYPE_BLOCK 0x02
54 /// Device type for console devices
55 #define VIRTIO_DEVICE_TYPE_CONSOLE 0x03
57 /// Device type for entorpy devices
58 #define VIRTIO_DEVICE_TYPE_ENTORPY 0x04
60 //#define VIRTIO_DEVICE_TYPE_LEGACY_BALLOON 5
62 /// Device type for IO memory devices
63 #define VIRTIO_DEVICE_TYPE_IOMEM 0x06
65 /// Device type for rpmgs devices
66 #define VIRTIO_DEVICE_TYPE_RPMSG 0x07
68 /// Device type for SCSI host devices
69 #define VIRTIO_DEVICE_TYPE_SCSIHOST 0x08
71 /// Device type for 9P transport devices
72 #define VIRTIO_DEVICE_TYPE_9PTRANSP 0x09
74 /// Device type for MAC 802.11 WLAn devices
75 #define VIRTIO_DEVICE_TYPE_WLAN 0x0A
77 /// Device type for RPROC serial devices
78 #define VIRTIO_DEVICE_TYPE_SERIAL 0x0B
80 /// Device type for virtio CAIF devices
81 #define VIRTIO_DEVICE_TYPE_CAIF 0x0C
83 /// Device type for memory ballooning devices
84 #define VIRTIO_DEVICE_TYPE_BALLOON 0x0D
86 /// Device type for GPU devices
87 #define VIRTIO_DEVICE_TYPE_GPU 0x0E
89 /// Device type for timer / clock devices
90 #define VIRTIO_DEVICE_TYPE_TIMER 0x0F
93 * specifies the possible virtio backends to be used
95 enum virtio_device_backend {
96 VIRTIO_DEVICE_BACKEND_INVALID,
97 VIRTIO_DEVICE_BACKEND_PCI,
98 VIRTIO_DEVICE_BACKEND_MMIO,
102 * 4.1.2 PCI Device Discovery
104 * Any PCI device with Vendor ID 0x1AF4, and Device ID 0x1000 through 0x103F
105 * inclusive is a virtio device. The Subsystem Device ID indicates which virtio
106 * device is supported by the device.
109 #define VIRTIO_PCI_VENDOR_ID 0x1AF4
110 #define VIRTIO_PCI_DEVICE_ID 0x1000
111 #define VIRTIO_PCI_DEVICE_ID2 0x103F
115 * contains necessary values for the device initialization process
117 struct virtio_device_init
119 uint8_t type; ///< expected type of the device
120 enum virtio_device_backend backend; ///< which backend to use
124 * contains function pointers to backend specific functions
126 struct virtio_device_fn
128 errval_t(*virtio_dev_init_t)(struct virtio_device *dev);
132 * represents a virtio device
137 enum virtio_device_backend backend;
138 struct virtio_device_fn *f;
142 * \brief initializes the common part of the virtio device structure
144 * \param dev device structure to initialize
145 * \param init additional information passed for the init process
146 * \param dev_regs memory location of the device registers
148 errval_t virtio_device_init(struct virtio_device **dev,
149 struct virtio_device_init *init,
153 * \brief initializes the common part of the virtio device structure based on
154 * a supplied cap which gets mapped
156 * \param dev device structure to initialize
157 * \param init additional information passed for the init process
158 * \param dev_cap capability representing the device registers
160 errval_t virtio_device_init_with_cap(struct virtio_device **dev,
161 struct capref dev_cap);
164 #endif // VIRTIO_VIRTIO_DEVICE_H