xref: /openbsd-src/sys/dev/pci/virtio_pcireg.h (revision d8499287995aa7782ab7c2281bcd1ad4f7cb0a47)
1fbc65ea9Ssf /*
2fbc65ea9Ssf  * Copyright (c) 2019 Stefan Fritsch <sf@openbsd.org>
3fbc65ea9Ssf  *
4fbc65ea9Ssf  * Permission to use, copy, modify, and distribute this software for any
5fbc65ea9Ssf  * purpose with or without fee is hereby granted, provided that the above
6fbc65ea9Ssf  * copyright notice and this permission notice appear in all copies.
7fbc65ea9Ssf  *
8fbc65ea9Ssf  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9fbc65ea9Ssf  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10fbc65ea9Ssf  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11fbc65ea9Ssf  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12fbc65ea9Ssf  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13fbc65ea9Ssf  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14fbc65ea9Ssf  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15fbc65ea9Ssf  */
16fbc65ea9Ssf 
17fbc65ea9Ssf #ifndef _DEV_PCI_VIRTIO_PCIREG_H_
18fbc65ea9Ssf #define _DEV_PCI_VIRTIO_PCIREG_H_
19fbc65ea9Ssf 
20fbc65ea9Ssf /* Virtio 0.9 config space */
21fbc65ea9Ssf #define VIRTIO_CONFIG_DEVICE_FEATURES		0 /* 32bit */
22fbc65ea9Ssf #define VIRTIO_CONFIG_GUEST_FEATURES		4 /* 32bit */
23fbc65ea9Ssf #define VIRTIO_CONFIG_QUEUE_ADDRESS		8 /* 32bit */
24fbc65ea9Ssf #define VIRTIO_CONFIG_QUEUE_SIZE		12 /* 16bit */
25fbc65ea9Ssf #define VIRTIO_CONFIG_QUEUE_SELECT		14 /* 16bit */
26fbc65ea9Ssf #define VIRTIO_CONFIG_QUEUE_NOTIFY		16 /* 16bit */
27fbc65ea9Ssf #define VIRTIO_CONFIG_DEVICE_STATUS		18 /* 8bit */
28fbc65ea9Ssf #define VIRTIO_CONFIG_ISR_STATUS		19 /* 8bit */
29fbc65ea9Ssf #define  VIRTIO_CONFIG_ISR_CONFIG_CHANGE	2
30fbc65ea9Ssf #define VIRTIO_CONFIG_DEVICE_CONFIG_NOMSI	20
31fbc65ea9Ssf /* Only if MSIX is enabled: */
32fbc65ea9Ssf #define VIRTIO_MSI_CONFIG_VECTOR		20 /* 16bit, optional */
33fbc65ea9Ssf #define VIRTIO_MSI_QUEUE_VECTOR			22 /* 16bit, optional */
34fbc65ea9Ssf #define VIRTIO_CONFIG_DEVICE_CONFIG_MSI		24
35fbc65ea9Ssf 
36fbc65ea9Ssf #define VIRTIO_MSI_NO_VECTOR			0xffff
37fbc65ea9Ssf 
38*d8499287Ssf /*
39*d8499287Ssf  * Virtio 1.0 specific
40*d8499287Ssf  */
41*d8499287Ssf 
42*d8499287Ssf struct virtio_pci_cap {
43*d8499287Ssf 	uint8_t cap_vndr;	/* Generic PCI field: PCI_CAP_ID_VNDR */
44*d8499287Ssf 	uint8_t cap_next;	/* Generic PCI field: next ptr. */
45*d8499287Ssf 	uint8_t cap_len;	/* Generic PCI field: capability length */
46*d8499287Ssf 	uint8_t cfg_type;	/* Identifies the structure. */
47*d8499287Ssf 	uint8_t bar;		/* Where to find it. */
48*d8499287Ssf 	uint8_t padding[3];	/* Pad to full dword. */
49*d8499287Ssf 	uint32_t offset;	/* Offset within bar. */
50*d8499287Ssf 	uint32_t length;	/* Length of the structure, in bytes. */
51*d8499287Ssf } __packed;
52*d8499287Ssf 
53*d8499287Ssf /* Common configuration */
54*d8499287Ssf #define VIRTIO_PCI_CAP_COMMON_CFG	1
55*d8499287Ssf /* Notifications */
56*d8499287Ssf #define VIRTIO_PCI_CAP_NOTIFY_CFG	2
57*d8499287Ssf /* ISR Status */
58*d8499287Ssf #define VIRTIO_PCI_CAP_ISR_CFG		3
59*d8499287Ssf /* Device specific configuration */
60*d8499287Ssf #define VIRTIO_PCI_CAP_DEVICE_CFG	4
61*d8499287Ssf /* PCI configuration access */
62*d8499287Ssf #define VIRTIO_PCI_CAP_PCI_CFG		5
63*d8499287Ssf 
64*d8499287Ssf struct virtio_pci_notify_cap {
65*d8499287Ssf 	struct virtio_pci_cap cap;
66*d8499287Ssf 	uint32_t notify_off_multiplier;	/* Multiplier for queue_notify_off. */
67*d8499287Ssf } __packed;
68*d8499287Ssf 
69*d8499287Ssf struct virtio_pci_cfg_cap {
70*d8499287Ssf 	struct virtio_pci_cap cap;
71*d8499287Ssf 	uint8_t pci_cfg_data[4];	/* Data for BAR access. */
72*d8499287Ssf } __packed;
73*d8499287Ssf 
74*d8499287Ssf struct virtio_pci_common_cfg {
75*d8499287Ssf 	/* About the whole device. */
76*d8499287Ssf 	uint32_t device_feature_select;	/* read-write */
77*d8499287Ssf 	uint32_t device_feature;	/* read-only for driver */
78*d8499287Ssf 	uint32_t driver_feature_select;	/* read-write */
79*d8499287Ssf 	uint32_t driver_feature;	/* read-write */
80*d8499287Ssf 	uint16_t config_msix_vector;	/* read-write */
81*d8499287Ssf 	uint16_t num_queues;		/* read-only for driver */
82*d8499287Ssf 	uint8_t device_status;		/* read-write */
83*d8499287Ssf 	uint8_t config_generation;	/* read-only for driver */
84*d8499287Ssf 
85*d8499287Ssf 	/* About a specific virtqueue. */
86*d8499287Ssf 	uint16_t queue_select;		/* read-write */
87*d8499287Ssf 	uint16_t queue_size;		/* read-write, power of 2, or 0. */
88*d8499287Ssf 	uint16_t queue_msix_vector;	/* read-write */
89*d8499287Ssf 	uint16_t queue_enable;		/* read-write */
90*d8499287Ssf 	uint16_t queue_notify_off;	/* read-only for driver */
91*d8499287Ssf 	uint64_t queue_desc;		/* read-write */
92*d8499287Ssf 	uint64_t queue_avail;		/* read-write */
93*d8499287Ssf 	uint64_t queue_used;		/* read-write */
94*d8499287Ssf } __packed;
95fbc65ea9Ssf 
96fbc65ea9Ssf #endif /* _DEV_PCI_VIRTIO_PCIREG_H_ */
97