]>
Commit | Line | Data |
---|---|---|
1e17c2c1 AG |
1 | /* |
2 | * Virtio driver bits | |
3 | * | |
4 | * Copyright (c) 2013 Alexander Graf <agraf@suse.de> | |
5 | * | |
6 | * This work is licensed under the terms of the GNU GPL, version 2 or (at | |
7 | * your option) any later version. See the COPYING file in the top-level | |
8 | * directory. | |
9 | */ | |
10 | ||
11 | #ifndef VIRTIO_H | |
12 | #define VIRTIO_H | |
13 | ||
14 | #include "s390-ccw.h" | |
15 | ||
16 | /* Status byte for guest to report progress, and synchronize features. */ | |
17 | /* We have seen device and processed generic fields (VIRTIO_CONFIG_F_VIRTIO) */ | |
18 | #define VIRTIO_CONFIG_S_ACKNOWLEDGE 1 | |
19 | /* We have found a driver for the device. */ | |
20 | #define VIRTIO_CONFIG_S_DRIVER 2 | |
21 | /* Driver has used its parts of the config, and is happy */ | |
22 | #define VIRTIO_CONFIG_S_DRIVER_OK 4 | |
23 | /* We've given up on this device. */ | |
24 | #define VIRTIO_CONFIG_S_FAILED 0x80 | |
25 | ||
26 | enum virtio_dev_type { | |
27 | VIRTIO_ID_NET = 1, | |
28 | VIRTIO_ID_BLOCK = 2, | |
29 | VIRTIO_ID_CONSOLE = 3, | |
30 | VIRTIO_ID_BALLOON = 5, | |
31 | }; | |
32 | ||
33 | struct virtio_dev_header { | |
34 | enum virtio_dev_type type : 8; | |
35 | u8 num_vq; | |
36 | u8 feature_len; | |
37 | u8 config_len; | |
38 | u8 status; | |
39 | u8 vqconfig[]; | |
40 | } __attribute__((packed)); | |
41 | ||
42 | struct virtio_vqconfig { | |
43 | u64 token; | |
44 | u64 address; | |
45 | u16 num; | |
46 | u8 pad[6]; | |
47 | } __attribute__((packed)); | |
48 | ||
49 | struct vq_info_block { | |
50 | u64 queue; | |
51 | u32 align; | |
52 | u16 index; | |
53 | u16 num; | |
54 | } __attribute__((packed)); | |
55 | ||
56 | struct virtio_dev { | |
57 | struct virtio_dev_header *header; | |
58 | struct virtio_vqconfig *vqconfig; | |
59 | char *host_features; | |
60 | char *guest_features; | |
61 | char *config; | |
62 | }; | |
63 | ||
64 | #define KVM_S390_VIRTIO_RING_ALIGN 4096 | |
65 | ||
66 | #define VRING_USED_F_NO_NOTIFY 1 | |
67 | ||
68 | /* This marks a buffer as continuing via the next field. */ | |
69 | #define VRING_DESC_F_NEXT 1 | |
70 | /* This marks a buffer as write-only (otherwise read-only). */ | |
71 | #define VRING_DESC_F_WRITE 2 | |
72 | /* This means the buffer contains a list of buffer descriptors. */ | |
73 | #define VRING_DESC_F_INDIRECT 4 | |
74 | ||
75 | /* Internal flag to mark follow-up segments as such */ | |
76 | #define VRING_HIDDEN_IS_CHAIN 256 | |
77 | ||
78 | /* Virtio ring descriptors: 16 bytes. These can chain together via "next". */ | |
79 | struct vring_desc { | |
80 | /* Address (guest-physical). */ | |
81 | u64 addr; | |
82 | /* Length. */ | |
83 | u32 len; | |
84 | /* The flags as indicated above. */ | |
85 | u16 flags; | |
86 | /* We chain unused descriptors via this, too */ | |
87 | u16 next; | |
88 | } __attribute__((packed)); | |
89 | ||
90 | struct vring_avail { | |
91 | u16 flags; | |
92 | u16 idx; | |
93 | u16 ring[]; | |
94 | } __attribute__((packed)); | |
95 | ||
96 | /* u32 is used here for ids for padding reasons. */ | |
97 | struct vring_used_elem { | |
98 | /* Index of start of used descriptor chain. */ | |
99 | u32 id; | |
100 | /* Total length of the descriptor chain which was used (written to) */ | |
101 | u32 len; | |
102 | } __attribute__((packed)); | |
103 | ||
104 | struct vring_used { | |
105 | u16 flags; | |
106 | u16 idx; | |
107 | struct vring_used_elem ring[]; | |
108 | } __attribute__((packed)); | |
109 | ||
110 | struct vring { | |
111 | unsigned int num; | |
112 | int next_idx; | |
113 | struct vring_desc *desc; | |
114 | struct vring_avail *avail; | |
115 | struct vring_used *used; | |
116 | struct subchannel_id schid; | |
117 | }; | |
118 | ||
119 | ||
120 | /*********************************************** | |
121 | * Virtio block * | |
122 | ***********************************************/ | |
123 | ||
124 | /* | |
125 | * Command types | |
126 | * | |
127 | * Usage is a bit tricky as some bits are used as flags and some are not. | |
128 | * | |
129 | * Rules: | |
130 | * VIRTIO_BLK_T_OUT may be combined with VIRTIO_BLK_T_SCSI_CMD or | |
131 | * VIRTIO_BLK_T_BARRIER. VIRTIO_BLK_T_FLUSH is a command of its own | |
132 | * and may not be combined with any of the other flags. | |
133 | */ | |
134 | ||
135 | /* These two define direction. */ | |
136 | #define VIRTIO_BLK_T_IN 0 | |
137 | #define VIRTIO_BLK_T_OUT 1 | |
138 | ||
139 | /* This bit says it's a scsi command, not an actual read or write. */ | |
140 | #define VIRTIO_BLK_T_SCSI_CMD 2 | |
141 | ||
142 | /* Cache flush command */ | |
143 | #define VIRTIO_BLK_T_FLUSH 4 | |
144 | ||
145 | /* Barrier before this op. */ | |
146 | #define VIRTIO_BLK_T_BARRIER 0x80000000 | |
147 | ||
148 | /* This is the first element of the read scatter-gather list. */ | |
149 | struct virtio_blk_outhdr { | |
150 | /* VIRTIO_BLK_T* */ | |
151 | u32 type; | |
152 | /* io priority. */ | |
153 | u32 ioprio; | |
154 | /* Sector (ie. 512 byte offset) */ | |
155 | u64 sector; | |
156 | }; | |
157 | ||
158 | #endif /* VIRTIO_H */ |