3 Internal definitions for the virtio-blk driver, which produces Block I/O
4 Protocol instances for virtio-blk devices.
6 Copyright (C) 2012, Red Hat, Inc.
8 SPDX-License-Identifier: BSD-2-Clause-Patent
12 #ifndef _VIRTIO_BLK_DXE_H_
13 #define _VIRTIO_BLK_DXE_H_
15 #include <Protocol/BlockIo.h>
16 #include <Protocol/ComponentName.h>
17 #include <Protocol/DriverBinding.h>
19 #include <IndustryStandard/Virtio.h>
22 #define VBLK_SIG SIGNATURE_32 ('V', 'B', 'L', 'K')
26 // Parts of this structure are initialized / torn down in various functions
27 // at various call depths. The table to the right should make it easier to
30 // field init function init dpth
31 // --------------------- ------------------ ---------
32 UINT32 Signature
; // DriverBindingStart 0
33 VIRTIO_DEVICE_PROTOCOL
*VirtIo
; // DriverBindingStart 0
34 EFI_EVENT ExitBoot
; // DriverBindingStart 0
35 VRING Ring
; // VirtioRingInit 2
36 EFI_BLOCK_IO_PROTOCOL BlockIo
; // VirtioBlkInit 1
37 EFI_BLOCK_IO_MEDIA BlockIoMedia
; // VirtioBlkInit 1
38 VOID
*RingMap
; // VirtioRingMap 2
41 #define VIRTIO_BLK_FROM_BLOCK_IO(BlockIoPointer) \
42 CR (BlockIoPointer, VBLK_DEV, BlockIo, VBLK_SIG)
47 Device probe function for this driver.
49 The DXE core calls this function for any given device in order to see if the
50 driver can drive the device.
52 Specs relevant in the general sense:
54 - UEFI Spec 2.3.1 + Errata C:
55 - 6.3 Protocol Handler Services -- for accessing the underlying device
56 - 10.1 EFI Driver Binding Protocol -- for exporting ourselves
58 - Driver Writer's Guide for UEFI 2.3.1 v1.01:
59 - 5.1.3.4 OpenProtocol() and CloseProtocol() -- for accessing the
61 - 9 Driver Binding Protocol -- for exporting ourselves
63 @param[in] This The EFI_DRIVER_BINDING_PROTOCOL object
64 incorporating this driver (independently of
67 @param[in] DeviceHandle The device to probe.
69 @param[in] RemainingDevicePath Relevant only for bus drivers, ignored.
72 @retval EFI_SUCCESS The driver supports the device being probed.
74 @retval EFI_UNSUPPORTED Based on virtio-blk discovery, we do not support
77 @return Error codes from the OpenProtocol() boot service.
83 VirtioBlkDriverBindingSupported (
84 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
85 IN EFI_HANDLE DeviceHandle
,
86 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
92 After we've pronounced support for a specific device in
93 DriverBindingSupported(), we start managing said device (passed in by the
94 Driver Execution Environment) with the following service.
96 See DriverBindingSupported() for specification references.
98 @param[in] This The EFI_DRIVER_BINDING_PROTOCOL object
99 incorporating this driver (independently of
102 @param[in] DeviceHandle The supported device to drive.
104 @param[in] RemainingDevicePath Relevant only for bus drivers, ignored.
107 @retval EFI_SUCCESS Driver instance has been created and
108 initialized for the virtio-blk device, it
109 is now accessible via EFI_BLOCK_IO_PROTOCOL.
111 @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
113 @return Error codes from the OpenProtocol() boot
114 service, VirtioBlkInit(), or the
115 InstallProtocolInterface() boot service.
121 VirtioBlkDriverBindingStart (
122 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
123 IN EFI_HANDLE DeviceHandle
,
124 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
130 Stop driving a virtio-blk device and remove its BlockIo interface.
132 This function replays the success path of DriverBindingStart() in reverse.
133 The host side virtio-blk device is reset, so that the OS boot loader or the
134 OS may reinitialize it.
136 @param[in] This The EFI_DRIVER_BINDING_PROTOCOL object
137 incorporating this driver (independently of any
140 @param[in] DeviceHandle Stop driving this device.
142 @param[in] NumberOfChildren Since this function belongs to a device driver
143 only (as opposed to a bus driver), the caller
144 environment sets NumberOfChildren to zero, and
147 @param[in] ChildHandleBuffer Ignored (corresponding to NumberOfChildren).
153 VirtioBlkDriverBindingStop (
154 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
155 IN EFI_HANDLE DeviceHandle
,
156 IN UINTN NumberOfChildren
,
157 IN EFI_HANDLE
*ChildHandleBuffer
162 // UEFI Spec 2.3.1 + Errata C, 12.8 EFI Block I/O Protocol
163 // Driver Writer's Guide for UEFI 2.3.1 v1.01,
164 // 24.2 Block I/O Protocol Implementations
169 IN EFI_BLOCK_IO_PROTOCOL
*This
,
170 IN BOOLEAN ExtendedVerification
176 ReadBlocks() operation for virtio-blk.
179 - UEFI Spec 2.3.1 + Errata C, 12.8 EFI Block I/O Protocol, 12.8 EFI Block I/O
180 Protocol, EFI_BLOCK_IO_PROTOCOL.ReadBlocks().
181 - Driver Writer's Guide for UEFI 2.3.1 v1.01, 24.2.2. ReadBlocks() and
182 ReadBlocksEx() Implementation.
184 Parameter checks and conformant return values are implemented in
185 VerifyReadWriteRequest() and SynchronousRequest().
187 A zero BufferSize doesn't seem to be prohibited, so do nothing in that case,
194 VirtioBlkReadBlocks (
195 IN EFI_BLOCK_IO_PROTOCOL
*This
,
205 WriteBlocks() operation for virtio-blk.
208 - UEFI Spec 2.3.1 + Errata C, 12.8 EFI Block I/O Protocol, 12.8 EFI Block I/O
209 Protocol, EFI_BLOCK_IO_PROTOCOL.WriteBlocks().
210 - Driver Writer's Guide for UEFI 2.3.1 v1.01, 24.2.3 WriteBlocks() and
211 WriteBlockEx() Implementation.
213 Parameter checks and conformant return values are implemented in
214 VerifyReadWriteRequest() and SynchronousRequest().
216 A zero BufferSize doesn't seem to be prohibited, so do nothing in that case,
223 VirtioBlkWriteBlocks (
224 IN EFI_BLOCK_IO_PROTOCOL
*This
,
234 FlushBlocks() operation for virtio-blk.
237 - UEFI Spec 2.3.1 + Errata C, 12.8 EFI Block I/O Protocol, 12.8 EFI Block I/O
238 Protocol, EFI_BLOCK_IO_PROTOCOL.FlushBlocks().
239 - Driver Writer's Guide for UEFI 2.3.1 v1.01, 24.2.4 FlushBlocks() and
240 FlushBlocksEx() Implementation.
242 If the underlying virtio-blk device doesn't support flushing (ie.
243 write-caching), then this function should not be called by higher layers,
244 according to EFI_BLOCK_IO_MEDIA characteristics set in VirtioBlkInit().
245 Should they do nonetheless, we do nothing, successfully.
251 VirtioBlkFlushBlocks (
252 IN EFI_BLOCK_IO_PROTOCOL
*This
257 // The purpose of the following scaffolding (EFI_COMPONENT_NAME_PROTOCOL and
258 // EFI_COMPONENT_NAME2_PROTOCOL implementation) is to format the driver's name
259 // in English, for display on standard console devices. This is recommended for
260 // UEFI drivers that follow the UEFI Driver Model. Refer to the Driver Writer's
261 // Guide for UEFI 2.3.1 v1.01, 11 UEFI Driver and Controller Names.
263 // Device type names ("Virtio Block Device") are not formatted because the
264 // driver supports only that device type. Therefore the driver name suffices
265 // for unambiguous identification.
270 VirtioBlkGetDriverName (
271 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
273 OUT CHAR16
**DriverName
278 VirtioBlkGetDeviceName (
279 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
280 IN EFI_HANDLE DeviceHandle
,
281 IN EFI_HANDLE ChildHandle
,
283 OUT CHAR16
**ControllerName
286 #endif // _VIRTIO_BLK_DXE_H_