]>
Commit | Line | Data |
---|---|---|
fd51d759 | 1 | /** @file\r |
2 | \r | |
3 | Internal definitions for the virtio-blk driver, which produces Block I/O\r | |
4 | Protocol instances for virtio-blk devices.\r | |
5 | \r | |
6 | Copyright (C) 2012, Red Hat, Inc.\r | |
7 | \r | |
8 | This program and the accompanying materials are licensed and made available\r | |
9 | under the terms and conditions of the BSD License which accompanies this\r | |
10 | distribution. The full text of the license may be found at\r | |
11 | http://opensource.org/licenses/bsd-license.php\r | |
12 | \r | |
13 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT\r | |
14 | WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
15 | \r | |
16 | **/\r | |
17 | \r | |
936e3a5d | 18 | #ifndef _VIRTIO_BLK_DXE_H_\r |
19 | #define _VIRTIO_BLK_DXE_H_\r | |
20 | \r | |
fd51d759 | 21 | #include <Protocol/BlockIo.h>\r |
22 | #include <Protocol/ComponentName.h>\r | |
23 | #include <Protocol/DriverBinding.h>\r | |
fd51d759 | 24 | \r |
045b46e9 | 25 | #include <IndustryStandard/Virtio.h>\r |
fd51d759 | 26 | \r |
27 | \r | |
28 | #define VBLK_SIG SIGNATURE_32 ('V', 'B', 'L', 'K')\r | |
29 | \r | |
30 | typedef struct {\r | |
31 | //\r | |
32 | // Parts of this structure are initialized / torn down in various functions\r | |
33 | // at various call depths. The table to the right should make it easier to\r | |
34 | // track them.\r | |
35 | //\r | |
56f65ed8 OM |
36 | // field init function init dpth\r |
37 | // --------------------- ------------------ ---------\r | |
38 | UINT32 Signature; // DriverBindingStart 0\r | |
39 | VIRTIO_DEVICE_PROTOCOL *VirtIo; // DriverBindingStart 0\r | |
fcb636ea | 40 | EFI_EVENT ExitBoot; // DriverBindingStart 0\r |
56f65ed8 OM |
41 | VRING Ring; // VirtioRingInit 2\r |
42 | EFI_BLOCK_IO_PROTOCOL BlockIo; // VirtioBlkInit 1\r | |
43 | EFI_BLOCK_IO_MEDIA BlockIoMedia; // VirtioBlkInit 1\r | |
fd51d759 | 44 | } VBLK_DEV;\r |
45 | \r | |
46 | #define VIRTIO_BLK_FROM_BLOCK_IO(BlockIoPointer) \\r | |
47 | CR (BlockIoPointer, VBLK_DEV, BlockIo, VBLK_SIG)\r | |
48 | \r | |
49 | \r | |
50 | /**\r | |
51 | \r | |
52 | Device probe function for this driver.\r | |
53 | \r | |
54 | The DXE core calls this function for any given device in order to see if the\r | |
55 | driver can drive the device.\r | |
56 | \r | |
57 | Specs relevant in the general sense:\r | |
58 | \r | |
59 | - UEFI Spec 2.3.1 + Errata C:\r | |
60 | - 6.3 Protocol Handler Services -- for accessing the underlying device\r | |
61 | - 10.1 EFI Driver Binding Protocol -- for exporting ourselves\r | |
62 | \r | |
63 | - Driver Writer's Guide for UEFI 2.3.1 v1.01:\r | |
64 | - 5.1.3.4 OpenProtocol() and CloseProtocol() -- for accessing the\r | |
65 | underlying device\r | |
66 | - 9 Driver Binding Protocol -- for exporting ourselves\r | |
67 | \r | |
fd51d759 | 68 | @param[in] This The EFI_DRIVER_BINDING_PROTOCOL object\r |
69 | incorporating this driver (independently of\r | |
70 | any device).\r | |
71 | \r | |
72 | @param[in] DeviceHandle The device to probe.\r | |
73 | \r | |
74 | @param[in] RemainingDevicePath Relevant only for bus drivers, ignored.\r | |
75 | \r | |
76 | \r | |
77 | @retval EFI_SUCCESS The driver supports the device being probed.\r | |
78 | \r | |
56f65ed8 | 79 | @retval EFI_UNSUPPORTED Based on virtio-blk discovery, we do not support\r |
fd51d759 | 80 | the device.\r |
81 | \r | |
56f65ed8 | 82 | @return Error codes from the OpenProtocol() boot service.\r |
fd51d759 | 83 | \r |
84 | **/\r | |
85 | \r | |
86 | EFI_STATUS\r | |
87 | EFIAPI\r | |
88 | VirtioBlkDriverBindingSupported (\r | |
89 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
90 | IN EFI_HANDLE DeviceHandle,\r | |
91 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
92 | );\r | |
93 | \r | |
94 | \r | |
95 | /**\r | |
96 | \r | |
97 | After we've pronounced support for a specific device in\r | |
98 | DriverBindingSupported(), we start managing said device (passed in by the\r | |
99 | Driver Exeuction Environment) with the following service.\r | |
100 | \r | |
101 | See DriverBindingSupported() for specification references.\r | |
102 | \r | |
103 | @param[in] This The EFI_DRIVER_BINDING_PROTOCOL object\r | |
104 | incorporating this driver (independently of\r | |
105 | any device).\r | |
106 | \r | |
107 | @param[in] DeviceHandle The supported device to drive.\r | |
108 | \r | |
109 | @param[in] RemainingDevicePath Relevant only for bus drivers, ignored.\r | |
110 | \r | |
111 | \r | |
112 | @retval EFI_SUCCESS Driver instance has been created and\r | |
56f65ed8 | 113 | initialized for the virtio-blk device, it\r |
fd51d759 | 114 | is now accessibla via EFI_BLOCK_IO_PROTOCOL.\r |
115 | \r | |
116 | @retval EFI_OUT_OF_RESOURCES Memory allocation failed.\r | |
117 | \r | |
118 | @return Error codes from the OpenProtocol() boot\r | |
56f65ed8 OM |
119 | service, VirtioBlkInit(), or the\r |
120 | InstallProtocolInterface() boot service.\r | |
fd51d759 | 121 | \r |
122 | **/\r | |
123 | \r | |
124 | EFI_STATUS\r | |
125 | EFIAPI\r | |
126 | VirtioBlkDriverBindingStart (\r | |
127 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
128 | IN EFI_HANDLE DeviceHandle,\r | |
129 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
130 | );\r | |
131 | \r | |
132 | \r | |
133 | /**\r | |
134 | \r | |
135 | Stop driving a virtio-blk device and remove its BlockIo interface.\r | |
136 | \r | |
137 | This function replays the success path of DriverBindingStart() in reverse.\r | |
138 | The host side virtio-blk device is reset, so that the OS boot loader or the\r | |
139 | OS may reinitialize it.\r | |
140 | \r | |
141 | @param[in] This The EFI_DRIVER_BINDING_PROTOCOL object\r | |
142 | incorporating this driver (independently of any\r | |
143 | device).\r | |
144 | \r | |
145 | @param[in] DeviceHandle Stop driving this device.\r | |
146 | \r | |
147 | @param[in] NumberOfChildren Since this function belongs to a device driver\r | |
148 | only (as opposed to a bus driver), the caller\r | |
149 | environment sets NumberOfChildren to zero, and\r | |
150 | we ignore it.\r | |
151 | \r | |
152 | @param[in] ChildHandleBuffer Ignored (corresponding to NumberOfChildren).\r | |
153 | \r | |
154 | **/\r | |
155 | \r | |
156 | EFI_STATUS\r | |
157 | EFIAPI\r | |
158 | VirtioBlkDriverBindingStop (\r | |
159 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
160 | IN EFI_HANDLE DeviceHandle,\r | |
161 | IN UINTN NumberOfChildren,\r | |
162 | IN EFI_HANDLE *ChildHandleBuffer\r | |
163 | );\r | |
164 | \r | |
165 | \r | |
166 | //\r | |
167 | // UEFI Spec 2.3.1 + Errata C, 12.8 EFI Block I/O Protocol\r | |
168 | // Driver Writer's Guide for UEFI 2.3.1 v1.01,\r | |
169 | // 24.2 Block I/O Protocol Implementations\r | |
170 | //\r | |
171 | EFI_STATUS\r | |
172 | EFIAPI\r | |
173 | VirtioBlkReset (\r | |
174 | IN EFI_BLOCK_IO_PROTOCOL *This,\r | |
175 | IN BOOLEAN ExtendedVerification\r | |
176 | );\r | |
177 | \r | |
178 | \r | |
179 | /**\r | |
180 | \r | |
181 | ReadBlocks() operation for virtio-blk.\r | |
182 | \r | |
183 | See\r | |
184 | - UEFI Spec 2.3.1 + Errata C, 12.8 EFI Block I/O Protocol, 12.8 EFI Block I/O\r | |
185 | Protocol, EFI_BLOCK_IO_PROTOCOL.ReadBlocks().\r | |
186 | - Driver Writer's Guide for UEFI 2.3.1 v1.01, 24.2.2. ReadBlocks() and\r | |
187 | ReadBlocksEx() Implementation.\r | |
188 | \r | |
189 | Parameter checks and conformant return values are implemented in\r | |
190 | VerifyReadWriteRequest() and SynchronousRequest().\r | |
191 | \r | |
192 | A zero BufferSize doesn't seem to be prohibited, so do nothing in that case,\r | |
193 | successfully.\r | |
194 | \r | |
195 | **/\r | |
196 | \r | |
197 | EFI_STATUS\r | |
198 | EFIAPI\r | |
199 | VirtioBlkReadBlocks (\r | |
200 | IN EFI_BLOCK_IO_PROTOCOL *This,\r | |
201 | IN UINT32 MediaId,\r | |
202 | IN EFI_LBA Lba,\r | |
203 | IN UINTN BufferSize,\r | |
204 | OUT VOID *Buffer\r | |
205 | );\r | |
206 | \r | |
207 | \r | |
208 | /**\r | |
209 | \r | |
210 | WriteBlocks() operation for virtio-blk.\r | |
211 | \r | |
212 | See\r | |
213 | - UEFI Spec 2.3.1 + Errata C, 12.8 EFI Block I/O Protocol, 12.8 EFI Block I/O\r | |
214 | Protocol, EFI_BLOCK_IO_PROTOCOL.WriteBlocks().\r | |
215 | - Driver Writer's Guide for UEFI 2.3.1 v1.01, 24.2.3 WriteBlocks() and\r | |
216 | WriteBlockEx() Implementation.\r | |
217 | \r | |
218 | Parameter checks and conformant return values are implemented in\r | |
219 | VerifyReadWriteRequest() and SynchronousRequest().\r | |
220 | \r | |
221 | A zero BufferSize doesn't seem to be prohibited, so do nothing in that case,\r | |
222 | successfully.\r | |
223 | \r | |
224 | **/\r | |
225 | \r | |
226 | EFI_STATUS\r | |
227 | EFIAPI\r | |
228 | VirtioBlkWriteBlocks (\r | |
229 | IN EFI_BLOCK_IO_PROTOCOL *This,\r | |
230 | IN UINT32 MediaId,\r | |
231 | IN EFI_LBA Lba,\r | |
232 | IN UINTN BufferSize,\r | |
233 | IN VOID *Buffer\r | |
234 | );\r | |
235 | \r | |
236 | \r | |
237 | /**\r | |
238 | \r | |
239 | FlushBlocks() operation for virtio-blk.\r | |
240 | \r | |
241 | See\r | |
242 | - UEFI Spec 2.3.1 + Errata C, 12.8 EFI Block I/O Protocol, 12.8 EFI Block I/O\r | |
243 | Protocol, EFI_BLOCK_IO_PROTOCOL.FlushBlocks().\r | |
244 | - Driver Writer's Guide for UEFI 2.3.1 v1.01, 24.2.4 FlushBlocks() and\r | |
245 | FlushBlocksEx() Implementation.\r | |
246 | \r | |
247 | If the underlying virtio-blk device doesn't support flushing (ie.\r | |
248 | write-caching), then this function should not be called by higher layers,\r | |
249 | according to EFI_BLOCK_IO_MEDIA characteristics set in VirtioBlkInit().\r | |
250 | Should they do nonetheless, we do nothing, successfully.\r | |
251 | \r | |
252 | **/\r | |
253 | \r | |
254 | EFI_STATUS\r | |
255 | EFIAPI\r | |
256 | VirtioBlkFlushBlocks (\r | |
257 | IN EFI_BLOCK_IO_PROTOCOL *This\r | |
258 | );\r | |
259 | \r | |
260 | \r | |
261 | //\r | |
262 | // The purpose of the following scaffolding (EFI_COMPONENT_NAME_PROTOCOL and\r | |
263 | // EFI_COMPONENT_NAME2_PROTOCOL implementation) is to format the driver's name\r | |
264 | // in English, for display on standard console devices. This is recommended for\r | |
265 | // UEFI drivers that follow the UEFI Driver Model. Refer to the Driver Writer's\r | |
266 | // Guide for UEFI 2.3.1 v1.01, 11 UEFI Driver and Controller Names.\r | |
267 | //\r | |
268 | // Device type names ("Virtio Block Device") are not formatted because the\r | |
269 | // driver supports only that device type. Therefore the driver name suffices\r | |
270 | // for unambiguous identification.\r | |
271 | //\r | |
272 | \r | |
273 | EFI_STATUS\r | |
274 | EFIAPI\r | |
275 | VirtioBlkGetDriverName (\r | |
276 | IN EFI_COMPONENT_NAME_PROTOCOL *This,\r | |
277 | IN CHAR8 *Language,\r | |
278 | OUT CHAR16 **DriverName\r | |
279 | );\r | |
280 | \r | |
281 | EFI_STATUS\r | |
282 | EFIAPI\r | |
283 | VirtioBlkGetDeviceName (\r | |
284 | IN EFI_COMPONENT_NAME_PROTOCOL *This,\r | |
285 | IN EFI_HANDLE DeviceHandle,\r | |
286 | IN EFI_HANDLE ChildHandle,\r | |
287 | IN CHAR8 *Language,\r | |
288 | OUT CHAR16 **ControllerName\r | |
289 | );\r | |
936e3a5d | 290 | \r |
291 | #endif // _VIRTIO_BLK_DXE_H_\r |