]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/VirtioBlkDxe/VirtioBlk.h
OvmfPkg: Make the VirtIo devices use the new VIRTIO_DEVICE_PROTOCOL
[mirror_edk2.git] / OvmfPkg / VirtioBlkDxe / VirtioBlk.h
CommitLineData
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
30typedef 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
40 VRING Ring; // VirtioRingInit 2\r
41 EFI_BLOCK_IO_PROTOCOL BlockIo; // VirtioBlkInit 1\r
42 EFI_BLOCK_IO_MEDIA BlockIoMedia; // VirtioBlkInit 1\r
fd51d759 43} VBLK_DEV;\r
44\r
45#define VIRTIO_BLK_FROM_BLOCK_IO(BlockIoPointer) \\r
46 CR (BlockIoPointer, VBLK_DEV, BlockIo, VBLK_SIG)\r
47\r
48\r
49/**\r
50\r
51 Device probe function for this driver.\r
52\r
53 The DXE core calls this function for any given device in order to see if the\r
54 driver can drive the device.\r
55\r
56 Specs relevant in the general sense:\r
57\r
58 - UEFI Spec 2.3.1 + Errata C:\r
59 - 6.3 Protocol Handler Services -- for accessing the underlying device\r
60 - 10.1 EFI Driver Binding Protocol -- for exporting ourselves\r
61\r
62 - Driver Writer's Guide for UEFI 2.3.1 v1.01:\r
63 - 5.1.3.4 OpenProtocol() and CloseProtocol() -- for accessing the\r
64 underlying device\r
65 - 9 Driver Binding Protocol -- for exporting ourselves\r
66\r
fd51d759 67 @param[in] This The EFI_DRIVER_BINDING_PROTOCOL object\r
68 incorporating this driver (independently of\r
69 any device).\r
70\r
71 @param[in] DeviceHandle The device to probe.\r
72\r
73 @param[in] RemainingDevicePath Relevant only for bus drivers, ignored.\r
74\r
75\r
76 @retval EFI_SUCCESS The driver supports the device being probed.\r
77\r
56f65ed8 78 @retval EFI_UNSUPPORTED Based on virtio-blk discovery, we do not support\r
fd51d759 79 the device.\r
80\r
56f65ed8 81 @return Error codes from the OpenProtocol() boot service.\r
fd51d759 82\r
83**/\r
84\r
85EFI_STATUS\r
86EFIAPI\r
87VirtioBlkDriverBindingSupported (\r
88 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
89 IN EFI_HANDLE DeviceHandle,\r
90 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
91 );\r
92\r
93\r
94/**\r
95\r
96 After we've pronounced support for a specific device in\r
97 DriverBindingSupported(), we start managing said device (passed in by the\r
98 Driver Exeuction Environment) with the following service.\r
99\r
100 See DriverBindingSupported() for specification references.\r
101\r
102 @param[in] This The EFI_DRIVER_BINDING_PROTOCOL object\r
103 incorporating this driver (independently of\r
104 any device).\r
105\r
106 @param[in] DeviceHandle The supported device to drive.\r
107\r
108 @param[in] RemainingDevicePath Relevant only for bus drivers, ignored.\r
109\r
110\r
111 @retval EFI_SUCCESS Driver instance has been created and\r
56f65ed8 112 initialized for the virtio-blk device, it\r
fd51d759 113 is now accessibla via EFI_BLOCK_IO_PROTOCOL.\r
114\r
115 @retval EFI_OUT_OF_RESOURCES Memory allocation failed.\r
116\r
117 @return Error codes from the OpenProtocol() boot\r
56f65ed8
OM
118 service, VirtioBlkInit(), or the\r
119 InstallProtocolInterface() boot service.\r
fd51d759 120\r
121**/\r
122\r
123EFI_STATUS\r
124EFIAPI\r
125VirtioBlkDriverBindingStart (\r
126 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
127 IN EFI_HANDLE DeviceHandle,\r
128 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
129 );\r
130\r
131\r
132/**\r
133\r
134 Stop driving a virtio-blk device and remove its BlockIo interface.\r
135\r
136 This function replays the success path of DriverBindingStart() in reverse.\r
137 The host side virtio-blk device is reset, so that the OS boot loader or the\r
138 OS may reinitialize it.\r
139\r
140 @param[in] This The EFI_DRIVER_BINDING_PROTOCOL object\r
141 incorporating this driver (independently of any\r
142 device).\r
143\r
144 @param[in] DeviceHandle Stop driving this device.\r
145\r
146 @param[in] NumberOfChildren Since this function belongs to a device driver\r
147 only (as opposed to a bus driver), the caller\r
148 environment sets NumberOfChildren to zero, and\r
149 we ignore it.\r
150\r
151 @param[in] ChildHandleBuffer Ignored (corresponding to NumberOfChildren).\r
152\r
153**/\r
154\r
155EFI_STATUS\r
156EFIAPI\r
157VirtioBlkDriverBindingStop (\r
158 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
159 IN EFI_HANDLE DeviceHandle,\r
160 IN UINTN NumberOfChildren,\r
161 IN EFI_HANDLE *ChildHandleBuffer\r
162 );\r
163\r
164\r
165//\r
166// UEFI Spec 2.3.1 + Errata C, 12.8 EFI Block I/O Protocol\r
167// Driver Writer's Guide for UEFI 2.3.1 v1.01,\r
168// 24.2 Block I/O Protocol Implementations\r
169//\r
170EFI_STATUS\r
171EFIAPI\r
172VirtioBlkReset (\r
173 IN EFI_BLOCK_IO_PROTOCOL *This,\r
174 IN BOOLEAN ExtendedVerification\r
175 );\r
176\r
177\r
178/**\r
179\r
180 ReadBlocks() operation for virtio-blk.\r
181\r
182 See\r
183 - UEFI Spec 2.3.1 + Errata C, 12.8 EFI Block I/O Protocol, 12.8 EFI Block I/O\r
184 Protocol, EFI_BLOCK_IO_PROTOCOL.ReadBlocks().\r
185 - Driver Writer's Guide for UEFI 2.3.1 v1.01, 24.2.2. ReadBlocks() and\r
186 ReadBlocksEx() Implementation.\r
187\r
188 Parameter checks and conformant return values are implemented in\r
189 VerifyReadWriteRequest() and SynchronousRequest().\r
190\r
191 A zero BufferSize doesn't seem to be prohibited, so do nothing in that case,\r
192 successfully.\r
193\r
194**/\r
195\r
196EFI_STATUS\r
197EFIAPI\r
198VirtioBlkReadBlocks (\r
199 IN EFI_BLOCK_IO_PROTOCOL *This,\r
200 IN UINT32 MediaId,\r
201 IN EFI_LBA Lba,\r
202 IN UINTN BufferSize,\r
203 OUT VOID *Buffer\r
204 );\r
205\r
206\r
207/**\r
208\r
209 WriteBlocks() operation for virtio-blk.\r
210\r
211 See\r
212 - UEFI Spec 2.3.1 + Errata C, 12.8 EFI Block I/O Protocol, 12.8 EFI Block I/O\r
213 Protocol, EFI_BLOCK_IO_PROTOCOL.WriteBlocks().\r
214 - Driver Writer's Guide for UEFI 2.3.1 v1.01, 24.2.3 WriteBlocks() and\r
215 WriteBlockEx() Implementation.\r
216\r
217 Parameter checks and conformant return values are implemented in\r
218 VerifyReadWriteRequest() and SynchronousRequest().\r
219\r
220 A zero BufferSize doesn't seem to be prohibited, so do nothing in that case,\r
221 successfully.\r
222\r
223**/\r
224\r
225EFI_STATUS\r
226EFIAPI\r
227VirtioBlkWriteBlocks (\r
228 IN EFI_BLOCK_IO_PROTOCOL *This,\r
229 IN UINT32 MediaId,\r
230 IN EFI_LBA Lba,\r
231 IN UINTN BufferSize,\r
232 IN VOID *Buffer\r
233 );\r
234\r
235\r
236/**\r
237\r
238 FlushBlocks() operation for virtio-blk.\r
239\r
240 See\r
241 - UEFI Spec 2.3.1 + Errata C, 12.8 EFI Block I/O Protocol, 12.8 EFI Block I/O\r
242 Protocol, EFI_BLOCK_IO_PROTOCOL.FlushBlocks().\r
243 - Driver Writer's Guide for UEFI 2.3.1 v1.01, 24.2.4 FlushBlocks() and\r
244 FlushBlocksEx() Implementation.\r
245\r
246 If the underlying virtio-blk device doesn't support flushing (ie.\r
247 write-caching), then this function should not be called by higher layers,\r
248 according to EFI_BLOCK_IO_MEDIA characteristics set in VirtioBlkInit().\r
249 Should they do nonetheless, we do nothing, successfully.\r
250\r
251**/\r
252\r
253EFI_STATUS\r
254EFIAPI\r
255VirtioBlkFlushBlocks (\r
256 IN EFI_BLOCK_IO_PROTOCOL *This\r
257 );\r
258\r
259\r
260//\r
261// The purpose of the following scaffolding (EFI_COMPONENT_NAME_PROTOCOL and\r
262// EFI_COMPONENT_NAME2_PROTOCOL implementation) is to format the driver's name\r
263// in English, for display on standard console devices. This is recommended for\r
264// UEFI drivers that follow the UEFI Driver Model. Refer to the Driver Writer's\r
265// Guide for UEFI 2.3.1 v1.01, 11 UEFI Driver and Controller Names.\r
266//\r
267// Device type names ("Virtio Block Device") are not formatted because the\r
268// driver supports only that device type. Therefore the driver name suffices\r
269// for unambiguous identification.\r
270//\r
271\r
272EFI_STATUS\r
273EFIAPI\r
274VirtioBlkGetDriverName (\r
275 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
276 IN CHAR8 *Language,\r
277 OUT CHAR16 **DriverName\r
278 );\r
279\r
280EFI_STATUS\r
281EFIAPI\r
282VirtioBlkGetDeviceName (\r
283 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
284 IN EFI_HANDLE DeviceHandle,\r
285 IN EFI_HANDLE ChildHandle,\r
286 IN CHAR8 *Language,\r
287 OUT CHAR16 **ControllerName\r
288 );\r
936e3a5d 289\r
290#endif // _VIRTIO_BLK_DXE_H_\r