xref: /openbmc/u-boot/drivers/virtio/virtio_mmio.h (revision 5396b2a9)
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * Copyright (C) 2018, Tuomas Tynkkynen <tuomas.tynkkynen@iki.fi>
4  * Copyright (C) 2018, Bin Meng <bmeng.cn@gmail.com>
5  *
6  * From Linux kernel include/uapi/linux/virtio_mmio.h
7  */
8 
9 #ifndef _LINUX_VIRTIO_MMIO_H
10 #define _LINUX_VIRTIO_MMIO_H
11 
12 /* Control registers */
13 
14 /* Magic value ("virt" string) - Read Only */
15 #define VIRTIO_MMIO_MAGIC_VALUE		0x000
16 
17 /* Virtio device version - Read Only */
18 #define VIRTIO_MMIO_VERSION		0x004
19 
20 /* Virtio device ID - Read Only */
21 #define VIRTIO_MMIO_DEVICE_ID		0x008
22 
23 /* Virtio vendor ID - Read Only */
24 #define VIRTIO_MMIO_VENDOR_ID		0x00c
25 
26 /*
27  * Bitmask of the features supported by the device (host)
28  * (32 bits per set) - Read Only
29  */
30 #define VIRTIO_MMIO_DEVICE_FEATURES	0x010
31 
32 /* Device (host) features set selector - Write Only */
33 #define VIRTIO_MMIO_DEVICE_FEATURES_SEL	0x014
34 
35 /*
36  * Bitmask of features activated by the driver (guest)
37  * (32 bits per set) - Write Only
38  */
39 #define VIRTIO_MMIO_DRIVER_FEATURES	0x020
40 
41 /* Activated features set selector - Write Only */
42 #define VIRTIO_MMIO_DRIVER_FEATURES_SEL	0x024
43 
44 #ifndef VIRTIO_MMIO_NO_LEGACY /* LEGACY DEVICES ONLY! */
45 
46 /* Guest's memory page size in bytes - Write Only */
47 #define VIRTIO_MMIO_GUEST_PAGE_SIZE	0x028
48 
49 #endif
50 
51 /* Queue selector - Write Only */
52 #define VIRTIO_MMIO_QUEUE_SEL		0x030
53 
54 /* Maximum size of the currently selected queue - Read Only */
55 #define VIRTIO_MMIO_QUEUE_NUM_MAX	0x034
56 
57 /* Queue size for the currently selected queue - Write Only */
58 #define VIRTIO_MMIO_QUEUE_NUM		0x038
59 
60 #ifndef VIRTIO_MMIO_NO_LEGACY /* LEGACY DEVICES ONLY! */
61 
62 /* Used Ring alignment for the currently selected queue - Write Only */
63 #define VIRTIO_MMIO_QUEUE_ALIGN		0x03c
64 
65 /* Guest's PFN for the currently selected queue - Read Write */
66 #define VIRTIO_MMIO_QUEUE_PFN		0x040
67 
68 #endif
69 
70 /* Ready bit for the currently selected queue - Read Write */
71 #define VIRTIO_MMIO_QUEUE_READY		0x044
72 
73 /* Queue notifier - Write Only */
74 #define VIRTIO_MMIO_QUEUE_NOTIFY	0x050
75 
76 /* Interrupt status - Read Only */
77 #define VIRTIO_MMIO_INTERRUPT_STATUS	0x060
78 
79 /* Interrupt acknowledge - Write Only */
80 #define VIRTIO_MMIO_INTERRUPT_ACK	0x064
81 
82 /* Device status register - Read Write */
83 #define VIRTIO_MMIO_STATUS		0x070
84 
85 /* Selected queue's Descriptor Table address, 64 bits in two halves */
86 #define VIRTIO_MMIO_QUEUE_DESC_LOW	0x080
87 #define VIRTIO_MMIO_QUEUE_DESC_HIGH	0x084
88 
89 /* Selected queue's Available Ring address, 64 bits in two halves */
90 #define VIRTIO_MMIO_QUEUE_AVAIL_LOW	0x090
91 #define VIRTIO_MMIO_QUEUE_AVAIL_HIGH	0x094
92 
93 /* Selected queue's Used Ring address, 64 bits in two halves */
94 #define VIRTIO_MMIO_QUEUE_USED_LOW	0x0a0
95 #define VIRTIO_MMIO_QUEUE_USED_HIGH	0x0a4
96 
97 /* Configuration atomicity value */
98 #define VIRTIO_MMIO_CONFIG_GENERATION	0x0fc
99 
100 /*
101  * The config space is defined by each driver as
102  * the per-driver configuration space - Read Write
103  */
104 #define VIRTIO_MMIO_CONFIG		0x100
105 
106 /* Interrupt flags (re: interrupt status & acknowledge registers) */
107 
108 #define VIRTIO_MMIO_INT_VRING		BIT(0)
109 #define VIRTIO_MMIO_INT_CONFIG		BIT(1)
110 
111 /*
112  * The alignment to use between consumer and producer parts of vring.
113  * Currently hardcoded to the page size.
114  */
115 #define PAGE_SHIFT			12
116 #define VIRTIO_MMIO_VRING_ALIGN		PAGE_SIZE
117 
118 /**
119  * virtio mmio transport driver private data
120  *
121  * @base:		mmio transport device register base
122  * @version:		mmio transport device version
123  */
124 struct virtio_mmio_priv {
125 	void __iomem *base;
126 	u32 version;
127 };
128 
129 #endif /* _LINUX_VIRTIO_MMIO_H */
130