1 /*
2  * Copyright (c) 2014 Travis Geiselbrecht
3  *
4  * Use of this source code is governed by a MIT-style
5  * license that can be found in the LICENSE file or at
6  * https://opensource.org/licenses/MIT
7  */
8 #pragma once
9 
10 #include <lk/compiler.h>
11 #include <stdint.h>
12 
13 // V1 config
14 struct virtio_mmio_config {
15     /* 0x00 */
16     uint32_t magic;
17     uint32_t version;
18     uint32_t device_id;
19     uint32_t vendor_id;
20     /* 0x10 */
21     uint32_t host_features;
22     uint32_t host_features_sel;
23     uint32_t __reserved0[2];
24     /* 0x20 */
25     uint32_t guest_features;
26     uint32_t guest_features_sel;
27     uint32_t guest_page_size;
28     uint32_t __reserved1[1];
29     /* 0x30 */
30     uint32_t queue_sel;
31     uint32_t queue_num_max;
32     uint32_t queue_num;
33     uint32_t queue_align;
34     /* 0x40 */
35     uint32_t queue_pfn;
36     uint32_t __reserved2[3];
37     /* 0x50 */
38     uint32_t queue_notify;
39     uint32_t __reserved3[3];
40     /* 0x60 */
41     uint32_t interrupt_status;
42     uint32_t interrupt_ack;
43     uint32_t __reserved4[2];
44     /* 0x70 */
45     uint32_t status;
46     uint8_t __reserved5[0x8c];
47     /* 0x100 */
48     uint32_t config[0];
49 };
50 
51 STATIC_ASSERT(sizeof(struct virtio_mmio_config) == 0x100);
52 
53 #define VIRTIO_MMIO_MAGIC 0x74726976 // 'virt'
54 
55 #define VIRTIO_STATUS_ACKNOWLEDGE (1<<0)
56 #define VIRTIO_STATUS_DRIVER      (1<<1)
57 #define VIRTIO_STATUS_DRIVER_OK   (1<<2)
58 #define VIRTIO_STATUS_FEATURES_OK (1<<3)
59 #define VIRTIO_STATUS_DEVICE_NEEDS_RESET (1<<6)
60 #define VIRTIO_STATUS_FAILED      (1<<7)
61