1 /*
2  * Copyright (c) 2006-2023, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author       Notes
8  * 2021-9-16      GuEe-GUI     the first version
9  * 2021-11-11     GuEe-GUI     modify to virtio common interface
10  */
11 
12 #ifndef __VIRTIO_MMIO_H__
13 #define __VIRTIO_MMIO_H__
14 
15 #include <rtdef.h>
16 
17 struct virtio_mmio_config
18 {
19     rt_uint32_t magic;                  /* [0x00]<RO> Magic value */
20     rt_uint32_t version;                /* [0x04]<RO> Device version number */
21     rt_uint32_t device_id;              /* [0x08]<RO> Virtio Subsystem Device ID */
22     rt_uint32_t vendor_id;              /* [0x0c]<RO> Virtio Subsystem Vendor ID */
23     rt_uint32_t device_features;        /* [0x10]<RO> Flags representing features the device supports */
24     rt_uint32_t device_features_sel;    /* [0x14]<WO> Device (host) features word selection. */
25     rt_uint32_t res0[2];                /* [0x18] */
26     rt_uint32_t driver_features;        /* [0x20]<WO> Device features understood and activated by the driver */
27     rt_uint32_t driver_features_sel;    /* [0x24]<WO> Activated (guest) features word selection */
28     rt_uint32_t guest_page_size;        /* [0x28]<WO> Guest page size, this value should be a power of 2 */
29     rt_uint32_t res1[1];                /* [0x2c] */
30     rt_uint32_t queue_sel;              /* [0x30]<WO> Virtual queue index */
31     rt_uint32_t queue_num_max;          /* [0x34]<RO> Maximum virtual queue size */
32     rt_uint32_t queue_num;              /* [0x38]<WO> Virtual queue size */
33     rt_uint32_t queue_align;            /* [0x3c]<WO> Used Ring alignment in the virtual queue */
34     rt_uint32_t queue_pfn;              /* [0x40]<RW> Guest physical page number of the virtual queue */
35     rt_uint32_t queue_ready;            /* [0x44]<RW> Virtual queue ready bit */
36     rt_uint32_t res2[2];                /* [0x48] */
37     rt_uint32_t queue_notify;           /* [0x50]<WO> Queue notifier */
38     rt_uint32_t res3[3];                /* [0x54] */
39     rt_uint32_t interrupt_status;       /* [0x60]<RO> Interrupt status */
40     rt_uint32_t interrupt_ack;          /* [0x64]<WO> Interrupt acknowledge */
41     rt_uint32_t res4[2];                /* [0x68] */
42     rt_uint32_t status;                 /* [0x70]<RW> Device status */
43     rt_uint32_t res5[3];                /* [0x74] */
44     rt_uint32_t queue_desc_low;         /* [0x80]<WO> Virtual queue’s Descriptor Area 64 bit long physical address */
45     rt_uint32_t queue_desc_high;        /* [0x84]<WO> */
46     rt_uint32_t res6[2];                /* [0x88] */
47     rt_uint32_t queue_driver_low;       /* [0x90]<WO> Virtual queue’s Driver Area 64 bit long physical address */
48     rt_uint32_t queue_driver_high;      /* [0x94]<WO> */
49     rt_uint32_t res7[2];                /* [0x98] */
50     rt_uint32_t queue_device_low;       /* [0xa0]<WO> Virtual queue’s Device Area 64 bit long physical address */
51     rt_uint32_t queue_device_high;      /* [0xa4]<WO> */
52     rt_uint32_t res8[21];               /* [0xa8] */
53     rt_uint32_t config_generation;      /* [0xfc]<RO> Configuration atomicity value */
54     rt_uint32_t config[];               /* [0x100+]<RO> Configuration space */
55 
56 /*
57  * According to the compiler's optimization ways, we should force compiler not
58  * to optimization here, but it will cause some compilers generate memory access
59  * instructions fail. So we allow user to choose a toggle of optimize here.
60  */
61 #ifdef RT_USING_VIRTIO_MMIO_ALIGN
62 } __attribute__((packed));
63 #else
64 };
65 #endif
66 
67 #endif /* __VIRTIO_MMIO_H__ */
68