3 Copyright (c) 1999 - 2011, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions
7 of the BSD License which accompanies this distribution. The
8 full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #ifndef _BIOS_BLOCK_IO_H_
17 #define _BIOS_BLOCK_IO_H_
21 #include <Protocol/BlockIo.h>
22 #include <Protocol/PciIo.h>
23 #include <Protocol/LegacyBios.h>
24 #include <Protocol/DevicePath.h>
25 #include <Guid/LegacyBios.h>
26 #include <Guid/BlockIoVendor.h>
28 #include <Library/UefiDriverEntryPoint.h>
29 #include <Library/DebugLib.h>
30 #include <Library/BaseMemoryLib.h>
31 #include <Library/UefiBootServicesTableLib.h>
32 #include <Library/UefiLib.h>
33 #include <Library/DevicePathLib.h>
34 #include <Library/MemoryAllocationLib.h>
36 #include <IndustryStandard/Pci.h>
43 extern EFI_COMPONENT_NAME_PROTOCOL gBiosBlockIoComponentName
;
44 extern EFI_COMPONENT_NAME2_PROTOCOL gBiosBlockIoComponentName2
;
48 // Define the I2O class code
50 #define PCI_BASE_CLASS_INTELLIGENT 0x0e
51 #define PCI_SUB_CLASS_INTELLIGENT 0x00
54 // Number of pages needed for our buffer under 1MB
56 #define BLOCK_IO_BUFFER_PAGE_SIZE (((sizeof (EDD_DEVICE_ADDRESS_PACKET) + sizeof (BIOS_LEGACY_DRIVE) + MAX_EDD11_XFER) / EFI_PAGE_SIZE) + 1 \
60 // Driver Binding Protocol functions
64 Check whether the driver supports this device.
66 @param This The Udriver binding protocol.
67 @param Controller The controller handle to check.
68 @param RemainingDevicePath The remaining device path.
70 @retval EFI_SUCCESS The driver supports this controller.
71 @retval other This device isn't supported.
76 BiosBlockIoDriverBindingSupported (
77 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
78 IN EFI_HANDLE Controller
,
79 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
84 Starts the device with this driver.
86 @param This The driver binding instance.
87 @param Controller Handle of device to bind driver to.
88 @param RemainingDevicePath Optional parameter use to pick a specific child
91 @retval EFI_SUCCESS The controller is controlled by the driver.
92 @retval Other This controller cannot be started.
97 BiosBlockIoDriverBindingStart (
98 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
99 IN EFI_HANDLE Controller
,
100 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
104 Stop the device handled by this driver.
106 @param This The driver binding protocol.
107 @param Controller The controller to release.
108 @param NumberOfChildren The number of handles in ChildHandleBuffer.
109 @param ChildHandleBuffer The array of child handle.
111 @retval EFI_SUCCESS The device was stopped.
112 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
113 @retval Others Fail to uninstall protocols attached on the device.
118 BiosBlockIoDriverBindingStop (
119 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
120 IN EFI_HANDLE Controller
,
121 IN UINTN NumberOfChildren
,
122 IN EFI_HANDLE
*ChildHandleBuffer
126 // Other internal functions
130 Build device path for EDD 3.0.
132 @param BaseDevicePath Base device path.
133 @param Drive Legacy drive.
134 @param DevicePath Device path for output.
136 @retval EFI_SUCCESS The device path is built successfully.
137 @retval EFI_UNSUPPORTED It is failed to built device path.
141 BuildEdd30DevicePath (
142 IN EFI_DEVICE_PATH_PROTOCOL
*BaseDevicePath
,
143 IN BIOS_LEGACY_DRIVE
*Drive
,
144 IN EFI_DEVICE_PATH_PROTOCOL
**DevicePath
148 Initialize block I/O device instance
150 @param Dev Instance of block I/O device instance
152 @retval TRUE Initialization succeeds.
153 @retval FALSE Initialization fails.
158 IN BIOS_BLOCK_IO_DEV
*Dev
162 Read BufferSize bytes from Lba into Buffer.
164 @param This Indicates a pointer to the calling context.
165 @param MediaId Id of the media, changes every time the media is replaced.
166 @param Lba The starting Logical Block Address to read from
167 @param BufferSize Size of Buffer, must be a multiple of device block size.
168 @param Buffer A pointer to the destination buffer for the data. The caller is
169 responsible for either having implicit or explicit ownership of the buffer.
171 @retval EFI_SUCCESS The data was read correctly from the device.
172 @retval EFI_DEVICE_ERROR The device reported an error while performing the read.
173 @retval EFI_NO_MEDIA There is no media in the device.
174 @retval EFI_MEDIA_CHANGED The MediaId does not matched the current device.
175 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
176 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,
177 or the buffer is not on proper alignment.
182 Edd30BiosReadBlocks (
183 IN EFI_BLOCK_IO_PROTOCOL
*This
,
191 Write BufferSize bytes from Lba into Buffer.
193 @param This Indicates a pointer to the calling context.
194 @param MediaId The media ID that the write request is for.
195 @param Lba The starting logical block address to be written. The caller is
196 responsible for writing to only legitimate locations.
197 @param BufferSize Size of Buffer, must be a multiple of device block size.
198 @param Buffer A pointer to the source buffer for the data.
200 @retval EFI_SUCCESS The data was written correctly to the device.
201 @retval EFI_WRITE_PROTECTED The device can not be written to.
202 @retval EFI_DEVICE_ERROR The device reported an error while performing the write.
203 @retval EFI_NO_MEDIA There is no media in the device.
204 @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.
205 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
206 @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,
207 or the buffer is not on proper alignment.
212 Edd30BiosWriteBlocks (
213 IN EFI_BLOCK_IO_PROTOCOL
*This
,
221 Flush the Block Device.
223 @param This Indicates a pointer to the calling context.
225 @retval EFI_SUCCESS All outstanding data was written to the device
226 @retval EFI_DEVICE_ERROR The device reported an error while writting back the data
227 @retval EFI_NO_MEDIA There is no media in the device.
232 BiosBlockIoFlushBlocks (
233 IN EFI_BLOCK_IO_PROTOCOL
*This
237 Reset the Block Device.
239 @param This Indicates a pointer to the calling context.
240 @param ExtendedVerification Driver may perform diagnostics on reset.
242 @retval EFI_SUCCESS The device was reset.
243 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
250 IN EFI_BLOCK_IO_PROTOCOL
*This
,
251 IN BOOLEAN ExtendedVerification
255 Read BufferSize bytes from Lba into Buffer.
257 @param This Indicates a pointer to the calling context.
258 @param MediaId Id of the media, changes every time the media is replaced.
259 @param Lba The starting Logical Block Address to read from
260 @param BufferSize Size of Buffer, must be a multiple of device block size.
261 @param Buffer A pointer to the destination buffer for the data. The caller is
262 responsible for either having implicit or explicit ownership of the buffer.
264 @retval EFI_SUCCESS The data was read correctly from the device.
265 @retval EFI_DEVICE_ERROR The device reported an error while performing the read.
266 @retval EFI_NO_MEDIA There is no media in the device.
267 @retval EFI_MEDIA_CHANGED The MediaId does not matched the current device.
268 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
269 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,
270 or the buffer is not on proper alignment.
275 Edd11BiosReadBlocks (
276 IN EFI_BLOCK_IO_PROTOCOL
*This
,
284 Write BufferSize bytes from Lba into Buffer.
286 @param This Indicates a pointer to the calling context.
287 @param MediaId The media ID that the write request is for.
288 @param Lba The starting logical block address to be written. The caller is
289 responsible for writing to only legitimate locations.
290 @param BufferSize Size of Buffer, must be a multiple of device block size.
291 @param Buffer A pointer to the source buffer for the data.
293 @retval EFI_SUCCESS The data was written correctly to the device.
294 @retval EFI_WRITE_PROTECTED The device can not be written to.
295 @retval EFI_DEVICE_ERROR The device reported an error while performing the write.
296 @retval EFI_NO_MEDIA There is no media in the device.
297 @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.
298 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
299 @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,
300 or the buffer is not on proper alignment.
305 Edd11BiosWriteBlocks (
306 IN EFI_BLOCK_IO_PROTOCOL
*This
,
314 Read BufferSize bytes from Lba into Buffer.
316 @param This Indicates a pointer to the calling context.
317 @param MediaId Id of the media, changes every time the media is replaced.
318 @param Lba The starting Logical Block Address to read from
319 @param BufferSize Size of Buffer, must be a multiple of device block size.
320 @param Buffer A pointer to the destination buffer for the data. The caller is
321 responsible for either having implicit or explicit ownership of the buffer.
323 @retval EFI_SUCCESS The data was read correctly from the device.
324 @retval EFI_DEVICE_ERROR The device reported an error while performing the read.
325 @retval EFI_NO_MEDIA There is no media in the device.
326 @retval EFI_MEDIA_CHANGED The MediaId does not matched the current device.
327 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
328 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,
329 or the buffer is not on proper alignment.
334 BiosReadLegacyDrive (
335 IN EFI_BLOCK_IO_PROTOCOL
*This
,
343 Write BufferSize bytes from Lba into Buffer.
345 @param This Indicates a pointer to the calling context.
346 @param MediaId The media ID that the write request is for.
347 @param Lba The starting logical block address to be written. The caller is
348 responsible for writing to only legitimate locations.
349 @param BufferSize Size of Buffer, must be a multiple of device block size.
350 @param Buffer A pointer to the source buffer for the data.
352 @retval EFI_SUCCESS The data was written correctly to the device.
353 @retval EFI_WRITE_PROTECTED The device can not be written to.
354 @retval EFI_DEVICE_ERROR The device reported an error while performing the write.
355 @retval EFI_NO_MEDIA There is no media in the device.
356 @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.
357 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
358 @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,
359 or the buffer is not on proper alignment.
364 BiosWriteLegacyDrive (
365 IN EFI_BLOCK_IO_PROTOCOL
*This
,
373 Gets parameters of block I/O device.
375 @param BiosBlockIoDev Instance of block I/O device.
376 @param Drive Legacy drive.
378 @return Result of device parameter retrieval.
382 Int13GetDeviceParameters (
383 IN BIOS_BLOCK_IO_DEV
*BiosBlockIoDev
,
384 IN BIOS_LEGACY_DRIVE
*Drive
388 Extension of INT13 call.
390 @param BiosBlockIoDev Instance of block I/O device.
391 @param Drive Legacy drive.
393 @return Result of this extension.
398 IN BIOS_BLOCK_IO_DEV
*BiosBlockIoDev
,
399 IN BIOS_LEGACY_DRIVE
*Drive
403 Gets parameters of legacy drive.
405 @param BiosBlockIoDev Instance of block I/O device.
406 @param Drive Legacy drive.
408 @return Result of drive parameter retrieval.
413 IN BIOS_BLOCK_IO_DEV
*BiosBlockIoDev
,
414 IN BIOS_LEGACY_DRIVE
*Drive
418 Build device path for device.
420 @param BaseDevicePath Base device path.
421 @param Drive Legacy drive.
422 @param DevicePath Device path for output.
426 SetBiosInitBlockIoDevicePath (
427 IN EFI_DEVICE_PATH_PROTOCOL
*BaseDevicePath
,
428 IN BIOS_LEGACY_DRIVE
*Drive
,
429 OUT EFI_DEVICE_PATH_PROTOCOL
**DevicePath