Bin Meng | fdc4aca | 2018-10-15 02:21:02 -0700 | [diff] [blame] | 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 */ |
Simon Glass | cd93d62 | 2020-05-10 11:40:13 -0600 | [diff] [blame^] | 15 | #include <linux/bitops.h> |
Bin Meng | fdc4aca | 2018-10-15 02:21:02 -0700 | [diff] [blame] | 16 | #define VIRTIO_MMIO_MAGIC_VALUE 0x000 |
| 17 | |
| 18 | /* Virtio device version - Read Only */ |
| 19 | #define VIRTIO_MMIO_VERSION 0x004 |
| 20 | |
| 21 | /* Virtio device ID - Read Only */ |
| 22 | #define VIRTIO_MMIO_DEVICE_ID 0x008 |
| 23 | |
| 24 | /* Virtio vendor ID - Read Only */ |
| 25 | #define VIRTIO_MMIO_VENDOR_ID 0x00c |
| 26 | |
| 27 | /* |
| 28 | * Bitmask of the features supported by the device (host) |
| 29 | * (32 bits per set) - Read Only |
| 30 | */ |
| 31 | #define VIRTIO_MMIO_DEVICE_FEATURES 0x010 |
| 32 | |
| 33 | /* Device (host) features set selector - Write Only */ |
| 34 | #define VIRTIO_MMIO_DEVICE_FEATURES_SEL 0x014 |
| 35 | |
| 36 | /* |
| 37 | * Bitmask of features activated by the driver (guest) |
| 38 | * (32 bits per set) - Write Only |
| 39 | */ |
| 40 | #define VIRTIO_MMIO_DRIVER_FEATURES 0x020 |
| 41 | |
| 42 | /* Activated features set selector - Write Only */ |
| 43 | #define VIRTIO_MMIO_DRIVER_FEATURES_SEL 0x024 |
| 44 | |
| 45 | #ifndef VIRTIO_MMIO_NO_LEGACY /* LEGACY DEVICES ONLY! */ |
| 46 | |
| 47 | /* Guest's memory page size in bytes - Write Only */ |
| 48 | #define VIRTIO_MMIO_GUEST_PAGE_SIZE 0x028 |
| 49 | |
| 50 | #endif |
| 51 | |
| 52 | /* Queue selector - Write Only */ |
| 53 | #define VIRTIO_MMIO_QUEUE_SEL 0x030 |
| 54 | |
| 55 | /* Maximum size of the currently selected queue - Read Only */ |
| 56 | #define VIRTIO_MMIO_QUEUE_NUM_MAX 0x034 |
| 57 | |
| 58 | /* Queue size for the currently selected queue - Write Only */ |
| 59 | #define VIRTIO_MMIO_QUEUE_NUM 0x038 |
| 60 | |
| 61 | #ifndef VIRTIO_MMIO_NO_LEGACY /* LEGACY DEVICES ONLY! */ |
| 62 | |
| 63 | /* Used Ring alignment for the currently selected queue - Write Only */ |
| 64 | #define VIRTIO_MMIO_QUEUE_ALIGN 0x03c |
| 65 | |
| 66 | /* Guest's PFN for the currently selected queue - Read Write */ |
| 67 | #define VIRTIO_MMIO_QUEUE_PFN 0x040 |
| 68 | |
| 69 | #endif |
| 70 | |
| 71 | /* Ready bit for the currently selected queue - Read Write */ |
| 72 | #define VIRTIO_MMIO_QUEUE_READY 0x044 |
| 73 | |
| 74 | /* Queue notifier - Write Only */ |
| 75 | #define VIRTIO_MMIO_QUEUE_NOTIFY 0x050 |
| 76 | |
| 77 | /* Interrupt status - Read Only */ |
| 78 | #define VIRTIO_MMIO_INTERRUPT_STATUS 0x060 |
| 79 | |
| 80 | /* Interrupt acknowledge - Write Only */ |
| 81 | #define VIRTIO_MMIO_INTERRUPT_ACK 0x064 |
| 82 | |
| 83 | /* Device status register - Read Write */ |
| 84 | #define VIRTIO_MMIO_STATUS 0x070 |
| 85 | |
| 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 |
| 89 | |
| 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 |
| 93 | |
| 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 |
| 97 | |
| 98 | /* Configuration atomicity value */ |
| 99 | #define VIRTIO_MMIO_CONFIG_GENERATION 0x0fc |
| 100 | |
| 101 | /* |
| 102 | * The config space is defined by each driver as |
| 103 | * the per-driver configuration space - Read Write |
| 104 | */ |
| 105 | #define VIRTIO_MMIO_CONFIG 0x100 |
| 106 | |
| 107 | /* Interrupt flags (re: interrupt status & acknowledge registers) */ |
| 108 | |
| 109 | #define VIRTIO_MMIO_INT_VRING BIT(0) |
| 110 | #define VIRTIO_MMIO_INT_CONFIG BIT(1) |
| 111 | |
| 112 | /* |
| 113 | * The alignment to use between consumer and producer parts of vring. |
| 114 | * Currently hardcoded to the page size. |
| 115 | */ |
| 116 | #define PAGE_SHIFT 12 |
| 117 | #define VIRTIO_MMIO_VRING_ALIGN PAGE_SIZE |
| 118 | |
| 119 | /** |
| 120 | * virtio mmio transport driver private data |
| 121 | * |
| 122 | * @base: mmio transport device register base |
| 123 | * @version: mmio transport device version |
| 124 | */ |
| 125 | struct virtio_mmio_priv { |
| 126 | void __iomem *base; |
| 127 | u32 version; |
| 128 | }; |
| 129 | |
| 130 | #endif /* _LINUX_VIRTIO_MMIO_H */ |