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