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