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