2 Header file for IDE Bus Driver.
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
14 #include <FrameworkDxe.h>
16 #include <Protocol/IdeControllerInit.h>
17 #include <Protocol/BlockIo.h>
18 #include <Protocol/PciIo.h>
19 #include <Protocol/DiskInfo.h>
20 #include <Protocol/DevicePath.h>
22 #include <Library/DebugLib.h>
23 #include <Library/UefiDriverEntryPoint.h>
24 #include <Library/BaseLib.h>
25 #include <Library/UefiLib.h>
26 #include <Library/BaseMemoryLib.h>
27 #include <Library/ReportStatusCodeLib.h>
28 #include <Library/MemoryAllocationLib.h>
29 #include <Library/PerformanceLib.h>
30 #include <Library/UefiBootServicesTableLib.h>
31 #include <Library/UefiRuntimeServicesTableLib.h>
32 #include <Library/DevicePathLib.h>
34 #include <Guid/EventGroup.h>
36 #include <IndustryStandard/Pci.h>
42 extern EFI_DRIVER_BINDING_PROTOCOL gIDEBusDriverBinding
;
43 extern EFI_DRIVER_DIAGNOSTICS_PROTOCOL gIDEBusDriverDiagnostics
;
44 extern EFI_DRIVER_DIAGNOSTICS2_PROTOCOL gIDEBusDriverDiagnostics2
;
47 // Extra Definition to porting
49 #define MAX_IDE_DEVICE 4
50 #define MAX_IDE_CHANNELS 2
51 #define MAX_IDE_DRIVES 2
53 #define INVALID_DEVICE_TYPE 0xff
54 #define ATA_DEVICE_TYPE 0x00
55 #define ATAPI_DEVICE_TYPE 0x01
58 BOOLEAN HaveScannedDevice
[MAX_IDE_DEVICE
];
59 BOOLEAN DeviceFound
[MAX_IDE_DEVICE
];
60 BOOLEAN DeviceProcessed
[MAX_IDE_DEVICE
];
61 } IDE_BUS_DRIVER_PRIVATE_DATA
;
63 #define IDE_BLK_IO_DEV_SIGNATURE SIGNATURE_32 ('i', 'b', 'i', 'd')
69 EFI_BLOCK_IO_PROTOCOL BlkIo
;
70 EFI_BLOCK_IO_MEDIA BlkMedia
;
71 EFI_DISK_INFO_PROTOCOL DiskInfo
;
72 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
73 EFI_PCI_IO_PROTOCOL
*PciIo
;
74 IDE_BUS_DRIVER_PRIVATE_DATA
*IdeBusDriverPrivateData
;
77 // Local Data for IDE interface goes here
79 EFI_IDE_CHANNEL Channel
;
80 EFI_IDE_DEVICE Device
;
84 IDE_BASE_REGISTERS
*IoPort
;
87 ATAPI_INQUIRY_DATA
*InquiryData
;
88 EFI_IDENTIFY_DATA
*IdData
;
90 EFI_ATA_MODE UdmaMode
;
92 ATAPI_REQUEST_SENSE_DATA
*SenseData
;
93 UINT8 SenseDataNumber
;
97 // ExitBootService Event, it is used to clear pending IDE interrupt
99 EFI_EVENT ExitBootServiceEvent
;
101 EFI_UNICODE_STRING_TABLE
*ControllerNameTable
;
104 #include "ComponentName.h"
106 #define IDE_BLOCK_IO_DEV_FROM_THIS(a) CR (a, IDE_BLK_IO_DEV, BlkIo, IDE_BLK_IO_DEV_SIGNATURE)
107 #define IDE_BLOCK_IO_DEV_FROM_DISK_INFO_THIS(a) CR (a, IDE_BLK_IO_DEV, DiskInfo, IDE_BLK_IO_DEV_SIGNATURE)
113 Supported function of Driver Binding protocol for this driver.
115 @param This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
116 @param ControllerHandle The handle of the controller to test.
117 @param RemainingDevicePath A pointer to the remaining portion of a device path.
119 @retval EFI_SUCCESS Driver loaded.
120 @retval other Driver not loaded.
125 IDEBusDriverBindingSupported (
126 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
127 IN EFI_HANDLE Controller
,
128 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
132 Start function of Driver binding protocol which start this driver on Controller
133 by detecting all disks and installing BlockIo protocol on them.
135 @param This Protocol instance pointer.
136 @param Controller Handle of device to bind driver to.
137 @param RemainingDevicePath produce all possible children.
139 @retval EFI_SUCCESS This driver is added to ControllerHandle.
140 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle.
141 @retval other This driver does not support this device.
146 IDEBusDriverBindingStart (
147 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
148 IN EFI_HANDLE Controller
,
149 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
153 Stop function of Driver Binding Protocol which is to stop the driver on Controller Handle and all
154 child handle attached to the controller handle if there are.
156 @param This Protocol instance pointer.
157 @param Controller Handle of device to stop driver on
158 @param NumberOfChildren Not used
159 @param ChildHandleBuffer Not used
161 @retval EFI_SUCCESS This driver is removed DeviceHandle
162 @retval other This driver was not removed from this device
167 IDEBusDriverBindingStop (
168 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
169 IN EFI_HANDLE Controller
,
170 IN UINTN NumberOfChildren
,
171 IN EFI_HANDLE
*ChildHandleBuffer
175 // EFI Driver Configuration Functions
182 // EFI Driver Diagnostics Functions
185 Runs diagnostics on a controller.
187 @param This A pointer to the EFI_DRIVER_DIAGNOSTICS_PROTOCOLinstance.
188 @param ControllerHandle The handle of the controller to run diagnostics on.
189 @param ChildHandle The handle of the child controller to run diagnostics on
190 This is an optional parameter that may be NULL. It will
191 be NULL for device drivers. It will also be NULL for a
192 bus drivers that wish to run diagnostics on the bus controller.
193 It will not be NULL for a bus driver that wishes to run
194 diagnostics on one of its child controllers.
195 @param DiagnosticType Indicates type of diagnostics to perform on the controller
196 specified by ControllerHandle and ChildHandle.
197 @param Language A pointer to a three character ISO 639-2 language identifier.
198 This is the language in which the optional error message should
199 be returned in Buffer, and it must match one of the languages
200 specified in SupportedLanguages. The number of languages supported by
201 a driver is up to the driver writer.
202 @param ErrorType A GUID that defines the format of the data returned in Buffer.
203 @param BufferSize The size, in bytes, of the data returned in Buffer.
204 @param Buffer A buffer that contains a Null-terminated Unicode string
205 plus some additional data whose format is defined by ErrorType.
206 Buffer is allocated by this function with AllocatePool(), and
207 it is the caller's responsibility to free it with a call to FreePool().
209 @retval EFI_SUCCESS The controller specified by ControllerHandle and ChildHandle passed
211 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
212 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid EFI_HANDLE.
213 @retval EFI_INVALID_PARAMETER Language is NULL.
214 @retval EFI_INVALID_PARAMETER ErrorType is NULL.
215 @retval EFI_INVALID_PARAMETER BufferType is NULL.
216 @retval EFI_INVALID_PARAMETER Buffer is NULL.
217 @retval EFI_UNSUPPORTED The driver specified by This does not support running
218 diagnostics for the controller specified by ControllerHandle
220 @retval EFI_UNSUPPORTED The driver specified by This does not support the
221 type of diagnostic specified by DiagnosticType.
222 @retval EFI_UNSUPPORTED The driver specified by This does not support the language
223 specified by Language.
224 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to complete the
226 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to return the
227 status information in ErrorType, BufferSize,and Buffer.
228 @retval EFI_DEVICE_ERROR The controller specified by ControllerHandle and ChildHandle
229 did not pass the diagnostic.
233 IDEBusDriverDiagnosticsRunDiagnostics (
234 IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL
*This
,
235 IN EFI_HANDLE ControllerHandle
,
236 IN EFI_HANDLE ChildHandle OPTIONAL
,
237 IN EFI_DRIVER_DIAGNOSTIC_TYPE DiagnosticType
,
239 OUT EFI_GUID
**ErrorType
,
240 OUT UINTN
*BufferSize
,
245 issue ATA or ATAPI command to reset a block IO device.
246 @param This Block IO protocol instance pointer.
247 @param ExtendedVerification If FALSE,for ATAPI device, driver will only invoke ATAPI reset method
248 If TRUE, for ATAPI device, driver need invoke ATA reset method after
249 invoke ATAPI reset method
251 @retval EFI_DEVICE_ERROR When the device is neighther ATA device or ATAPI device.
252 @retval EFI_SUCCESS The device reset successfully
258 IN EFI_BLOCK_IO_PROTOCOL
*This
,
259 IN BOOLEAN ExtendedVerification
263 Read data from a block IO device.
265 @param This Block IO protocol instance pointer.
266 @param MediaId The media ID of the device
267 @param Lba Starting LBA address to read data
268 @param BufferSize The size of data to be read
269 @param Buffer Caller supplied buffer to save data
271 @retval EFI_DEVICE_ERROR unknown device type
272 @retval EFI_SUCCESS read the data successfully.
278 IN EFI_BLOCK_IO_PROTOCOL
*This
,
286 Write data to block io device
288 @param This Protocol instance pointer.
289 @param MediaId The media ID of the device
290 @param Lba Starting LBA address to write data
291 @param BufferSize The size of data to be written
292 @param Buffer Caller supplied buffer to save data
294 @retval EFI_DEVICE_ERROR unknown device type
295 @retval other write data status
300 IDEBlkIoWriteBlocks (
301 IN EFI_BLOCK_IO_PROTOCOL
*This
,
309 Flushes all modified data to a physical block devices
311 @param This Indicates a pointer to the calling context which to sepcify a
312 sepcific block device
314 @retval EFI_SUCCESS Always return success.
318 IDEBlkIoFlushBlocks (
319 IN EFI_BLOCK_IO_PROTOCOL
*This
322 This function is used by the IDE bus driver to get inquiry data.
323 Data format of Identify data is defined by the Interface GUID.
325 @param This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
326 @param InquiryData Pointer to a buffer for the inquiry data.
327 @param InquiryDataSize Pointer to the value for the inquiry data size.
329 @retval EFI_SUCCESS The command was accepted without any errors.
330 @retval EFI_NOT_FOUND Device does not support this data class
331 @retval EFI_DEVICE_ERROR Error reading InquiryData from device
332 @retval EFI_BUFFER_TOO_SMALL IntquiryDataSize not big enough
338 IN EFI_DISK_INFO_PROTOCOL
*This
,
339 IN OUT VOID
*InquiryData
,
340 IN OUT UINT32
*InquiryDataSize
344 This function is used by the IDE bus driver to get identify data.
345 Data format of Identify data is defined by the Interface GUID.
347 @param This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
348 @param IdentifyData Pointer to a buffer for the identify data.
349 @param IdentifyDataSize Pointer to the value for the identify data size.
351 @retval EFI_SUCCESS The command was accepted without any errors.
352 @retval EFI_NOT_FOUND Device does not support this data class
353 @retval EFI_DEVICE_ERROR Error reading IdentifyData from device
354 @retval EFI_BUFFER_TOO_SMALL IdentifyDataSize not big enough
359 IDEDiskInfoIdentify (
360 IN EFI_DISK_INFO_PROTOCOL
*This
,
361 IN OUT VOID
*IdentifyData
,
362 IN OUT UINT32
*IdentifyDataSize
366 This function is used by the IDE bus driver to get sense data.
367 Data format of Sense data is defined by the Interface GUID.
369 @param This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
370 @param SenseData Pointer to the SenseData.
371 @param SenseDataSize Size of SenseData in bytes.
372 @param SenseDataNumber Pointer to the value for the identify data size.
374 @retval EFI_SUCCESS The command was accepted without any errors.
375 @retval EFI_NOT_FOUND Device does not support this data class
376 @retval EFI_DEVICE_ERROR Error reading InquiryData from device
377 @retval EFI_BUFFER_TOO_SMALL SenseDataSize not big enough
382 IDEDiskInfoSenseData (
383 IN EFI_DISK_INFO_PROTOCOL
*This
,
384 IN OUT VOID
*SenseData
,
385 IN OUT UINT32
*SenseDataSize
,
386 OUT UINT8
*SenseDataNumber
390 This function is used by the IDE bus driver to get controller information.
392 @param This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
393 @param IdeChannel Pointer to the Ide Channel number. Primary or secondary.
394 @param IdeDevice Pointer to the Ide Device number. Master or slave.
396 @retval EFI_SUCCESS IdeChannel and IdeDevice are valid
397 @retval EFI_UNSUPPORTED This is not an IDE device
402 IDEDiskInfoWhichIde (
403 IN EFI_DISK_INFO_PROTOCOL
*This
,
404 OUT UINT32
*IdeChannel
,
405 OUT UINT32
*IdeDevice
408 The is an event(generally the event is exitBootService event) call back function.
409 Clear pending IDE interrupt before OS loader/kernel take control of the IDE device.
411 @param Event Pointer to this event
412 @param Context Event handler private data