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 This program and the accompanying materials are licensed and made available
9 under the terms and conditions of the BSD License which accompanies this
10 distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
14 WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 #include <Protocol/BlockIo.h>
19 #include <Protocol/ComponentName.h>
20 #include <Protocol/DriverBinding.h>
21 #include <Protocol/PciIo.h>
26 #define VBLK_SIG SIGNATURE_32 ('V', 'B', 'L', 'K')
30 // Parts of this structure are initialized / torn down in various functions
31 // at various call depths. The table to the right should make it easier to
34 // field init function init dpth
35 // ---------------------- ------------------ ---------
36 UINT32 Signature
; // DriverBindingStart 0
37 EFI_PCI_IO_PROTOCOL
*PciIo
; // DriverBindingStart 0
38 UINT64 OriginalPciAttributes
; // DriverBindingStart 0
39 VRING Ring
; // VirtioRingInit 2
40 EFI_BLOCK_IO_PROTOCOL BlockIo
; // VirtioBlkInit 1
41 EFI_BLOCK_IO_MEDIA BlockIoMedia
; // VirtioBlkInit 1
44 #define VIRTIO_BLK_FROM_BLOCK_IO(BlockIoPointer) \
45 CR (BlockIoPointer, VBLK_DEV, BlockIo, VBLK_SIG)
50 Device probe function for this driver.
52 The DXE core calls this function for any given device in order to see if the
53 driver can drive the device.
55 Specs relevant in the general sense:
57 - UEFI Spec 2.3.1 + Errata C:
58 - 6.3 Protocol Handler Services -- for accessing the underlying device
59 - 10.1 EFI Driver Binding Protocol -- for exporting ourselves
61 - Driver Writer's Guide for UEFI 2.3.1 v1.01:
62 - 5.1.3.4 OpenProtocol() and CloseProtocol() -- for accessing the
64 - 9 Driver Binding Protocol -- for exporting ourselves
66 Specs relevant in the specific sense:
67 - UEFI Spec 2.3.1 + Errata C, 13.4 EFI PCI I/O Protocol
68 - Driver Writer's Guide for UEFI 2.3.1 v1.01, 18 PCI Driver Design
69 Guidelines, 18.3 PCI drivers.
71 @param[in] This The EFI_DRIVER_BINDING_PROTOCOL object
72 incorporating this driver (independently of
75 @param[in] DeviceHandle The device to probe.
77 @param[in] RemainingDevicePath Relevant only for bus drivers, ignored.
80 @retval EFI_SUCCESS The driver supports the device being probed.
82 @retval EFI_UNSUPPORTED Based on virtio-blk PCI discovery, we do not support
85 @return Error codes from the OpenProtocol() boot service or
92 VirtioBlkDriverBindingSupported (
93 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
94 IN EFI_HANDLE DeviceHandle
,
95 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
101 After we've pronounced support for a specific device in
102 DriverBindingSupported(), we start managing said device (passed in by the
103 Driver Exeuction Environment) with the following service.
105 See DriverBindingSupported() for specification references.
107 @param[in] This The EFI_DRIVER_BINDING_PROTOCOL object
108 incorporating this driver (independently of
111 @param[in] DeviceHandle The supported device to drive.
113 @param[in] RemainingDevicePath Relevant only for bus drivers, ignored.
116 @retval EFI_SUCCESS Driver instance has been created and
117 initialized for the virtio-blk PCI device, it
118 is now accessibla via EFI_BLOCK_IO_PROTOCOL.
120 @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
122 @return Error codes from the OpenProtocol() boot
123 service, the PciIo protocol, VirtioBlkInit(),
124 or the InstallProtocolInterface() boot service.
130 VirtioBlkDriverBindingStart (
131 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
132 IN EFI_HANDLE DeviceHandle
,
133 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
139 Stop driving a virtio-blk device and remove its BlockIo interface.
141 This function replays the success path of DriverBindingStart() in reverse.
142 The host side virtio-blk device is reset, so that the OS boot loader or the
143 OS may reinitialize it.
145 @param[in] This The EFI_DRIVER_BINDING_PROTOCOL object
146 incorporating this driver (independently of any
149 @param[in] DeviceHandle Stop driving this device.
151 @param[in] NumberOfChildren Since this function belongs to a device driver
152 only (as opposed to a bus driver), the caller
153 environment sets NumberOfChildren to zero, and
156 @param[in] ChildHandleBuffer Ignored (corresponding to NumberOfChildren).
162 VirtioBlkDriverBindingStop (
163 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
164 IN EFI_HANDLE DeviceHandle
,
165 IN UINTN NumberOfChildren
,
166 IN EFI_HANDLE
*ChildHandleBuffer
171 // UEFI Spec 2.3.1 + Errata C, 12.8 EFI Block I/O Protocol
172 // Driver Writer's Guide for UEFI 2.3.1 v1.01,
173 // 24.2 Block I/O Protocol Implementations
178 IN EFI_BLOCK_IO_PROTOCOL
*This
,
179 IN BOOLEAN ExtendedVerification
185 ReadBlocks() operation for virtio-blk.
188 - UEFI Spec 2.3.1 + Errata C, 12.8 EFI Block I/O Protocol, 12.8 EFI Block I/O
189 Protocol, EFI_BLOCK_IO_PROTOCOL.ReadBlocks().
190 - Driver Writer's Guide for UEFI 2.3.1 v1.01, 24.2.2. ReadBlocks() and
191 ReadBlocksEx() Implementation.
193 Parameter checks and conformant return values are implemented in
194 VerifyReadWriteRequest() and SynchronousRequest().
196 A zero BufferSize doesn't seem to be prohibited, so do nothing in that case,
203 VirtioBlkReadBlocks (
204 IN EFI_BLOCK_IO_PROTOCOL
*This
,
214 WriteBlocks() operation for virtio-blk.
217 - UEFI Spec 2.3.1 + Errata C, 12.8 EFI Block I/O Protocol, 12.8 EFI Block I/O
218 Protocol, EFI_BLOCK_IO_PROTOCOL.WriteBlocks().
219 - Driver Writer's Guide for UEFI 2.3.1 v1.01, 24.2.3 WriteBlocks() and
220 WriteBlockEx() Implementation.
222 Parameter checks and conformant return values are implemented in
223 VerifyReadWriteRequest() and SynchronousRequest().
225 A zero BufferSize doesn't seem to be prohibited, so do nothing in that case,
232 VirtioBlkWriteBlocks (
233 IN EFI_BLOCK_IO_PROTOCOL
*This
,
243 FlushBlocks() operation for virtio-blk.
246 - UEFI Spec 2.3.1 + Errata C, 12.8 EFI Block I/O Protocol, 12.8 EFI Block I/O
247 Protocol, EFI_BLOCK_IO_PROTOCOL.FlushBlocks().
248 - Driver Writer's Guide for UEFI 2.3.1 v1.01, 24.2.4 FlushBlocks() and
249 FlushBlocksEx() Implementation.
251 If the underlying virtio-blk device doesn't support flushing (ie.
252 write-caching), then this function should not be called by higher layers,
253 according to EFI_BLOCK_IO_MEDIA characteristics set in VirtioBlkInit().
254 Should they do nonetheless, we do nothing, successfully.
260 VirtioBlkFlushBlocks (
261 IN EFI_BLOCK_IO_PROTOCOL
*This
266 // The purpose of the following scaffolding (EFI_COMPONENT_NAME_PROTOCOL and
267 // EFI_COMPONENT_NAME2_PROTOCOL implementation) is to format the driver's name
268 // in English, for display on standard console devices. This is recommended for
269 // UEFI drivers that follow the UEFI Driver Model. Refer to the Driver Writer's
270 // Guide for UEFI 2.3.1 v1.01, 11 UEFI Driver and Controller Names.
272 // Device type names ("Virtio Block Device") are not formatted because the
273 // driver supports only that device type. Therefore the driver name suffices
274 // for unambiguous identification.
279 VirtioBlkGetDriverName (
280 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
282 OUT CHAR16
**DriverName
287 VirtioBlkGetDeviceName (
288 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
289 IN EFI_HANDLE DeviceHandle
,
290 IN EFI_HANDLE ChildHandle
,
292 OUT CHAR16
**ControllerName