2 Header file for IDE Bus Driver.
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
20 #include <FrameworkDxe.h>
22 #include <Protocol/IdeControllerInit.h>
23 #include <Protocol/BlockIo.h>
24 #include <Protocol/PciIo.h>
25 #include <Protocol/DiskInfo.h>
26 #include <Protocol/DevicePath.h>
28 #include <Library/DebugLib.h>
29 #include <Library/UefiDriverEntryPoint.h>
30 #include <Library/BaseLib.h>
31 #include <Library/UefiLib.h>
32 #include <Library/BaseMemoryLib.h>
33 #include <Library/ReportStatusCodeLib.h>
34 #include <Library/MemoryAllocationLib.h>
35 #include <Library/PerformanceLib.h>
36 #include <Library/UefiBootServicesTableLib.h>
37 #include <Library/UefiRuntimeServicesTableLib.h>
38 #include <Library/DevicePathLib.h>
40 #include <Guid/EventGroup.h>
42 #include <IndustryStandard/Pci.h>
48 extern EFI_DRIVER_BINDING_PROTOCOL gIDEBusDriverBinding
;
49 extern EFI_DRIVER_DIAGNOSTICS_PROTOCOL gIDEBusDriverDiagnostics
;
50 extern EFI_DRIVER_DIAGNOSTICS2_PROTOCOL gIDEBusDriverDiagnostics2
;
53 // Extra Definition to porting
55 #define MAX_IDE_DEVICE 4
56 #define MAX_IDE_CHANNELS 2
57 #define MAX_IDE_DRIVES 2
59 #define INVALID_DEVICE_TYPE 0xff
60 #define ATA_DEVICE_TYPE 0x00
61 #define ATAPI_DEVICE_TYPE 0x01
64 BOOLEAN HaveScannedDevice
[MAX_IDE_DEVICE
];
65 BOOLEAN DeviceFound
[MAX_IDE_DEVICE
];
66 BOOLEAN DeviceProcessed
[MAX_IDE_DEVICE
];
67 } IDE_BUS_DRIVER_PRIVATE_DATA
;
69 #define IDE_BLK_IO_DEV_SIGNATURE SIGNATURE_32 ('i', 'b', 'i', 'd')
75 EFI_BLOCK_IO_PROTOCOL BlkIo
;
76 EFI_BLOCK_IO_MEDIA BlkMedia
;
77 EFI_DISK_INFO_PROTOCOL DiskInfo
;
78 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
79 EFI_PCI_IO_PROTOCOL
*PciIo
;
80 IDE_BUS_DRIVER_PRIVATE_DATA
*IdeBusDriverPrivateData
;
83 // Local Data for IDE interface goes here
85 EFI_IDE_CHANNEL Channel
;
86 EFI_IDE_DEVICE Device
;
90 IDE_BASE_REGISTERS
*IoPort
;
93 ATAPI_INQUIRY_DATA
*InquiryData
;
94 EFI_IDENTIFY_DATA
*IdData
;
96 EFI_ATA_MODE UdmaMode
;
98 ATAPI_REQUEST_SENSE_DATA
*SenseData
;
99 UINT8 SenseDataNumber
;
103 // ExitBootService Event, it is used to clear pending IDE interrupt
105 EFI_EVENT ExitBootServiceEvent
;
107 EFI_UNICODE_STRING_TABLE
*ControllerNameTable
;
110 #include "ComponentName.h"
112 #define IDE_BLOCK_IO_DEV_FROM_THIS(a) CR (a, IDE_BLK_IO_DEV, BlkIo, IDE_BLK_IO_DEV_SIGNATURE)
113 #define IDE_BLOCK_IO_DEV_FROM_DISK_INFO_THIS(a) CR (a, IDE_BLK_IO_DEV, DiskInfo, IDE_BLK_IO_DEV_SIGNATURE)
119 Supported function of Driver Binding protocol for this driver.
121 @param This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
122 @param ControllerHandle The handle of the controller to test.
123 @param RemainingDevicePath A pointer to the remaining portion of a device path.
125 @retval EFI_SUCCESS Driver loaded.
126 @retval other Driver not loaded.
131 IDEBusDriverBindingSupported (
132 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
133 IN EFI_HANDLE Controller
,
134 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
138 Start function of Driver binding protocol which start this driver on Controller
139 by detecting all disks and installing BlockIo protocol on them.
141 @param This Protocol instance pointer.
142 @param Controller Handle of device to bind driver to.
143 @param RemainingDevicePath produce all possible children.
145 @retval EFI_SUCCESS This driver is added to ControllerHandle.
146 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle.
147 @retval other This driver does not support this device.
152 IDEBusDriverBindingStart (
153 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
154 IN EFI_HANDLE Controller
,
155 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
159 Stop function of Driver Binding Protocol which is to stop the driver on Controller Handle and all
160 child handle attached to the controller handle if there are.
162 @param This Protocol instance pointer.
163 @param Controller Handle of device to stop driver on
164 @param NumberOfChildren Not used
165 @param ChildHandleBuffer Not used
167 @retval EFI_SUCCESS This driver is removed DeviceHandle
168 @retval other This driver was not removed from this device
173 IDEBusDriverBindingStop (
174 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
175 IN EFI_HANDLE Controller
,
176 IN UINTN NumberOfChildren
,
177 IN EFI_HANDLE
*ChildHandleBuffer
181 // EFI Driver Configuration Functions
188 // EFI Driver Diagnostics Functions
191 Runs diagnostics on a controller.
193 @param This A pointer to the EFI_DRIVER_DIAGNOSTICS_PROTOCOLinstance.
194 @param ControllerHandle The handle of the controller to run diagnostics on.
195 @param ChildHandle The handle of the child controller to run diagnostics on
196 This is an optional parameter that may be NULL. It will
197 be NULL for device drivers. It will also be NULL for a
198 bus drivers that wish to run diagnostics on the bus controller.
199 It will not be NULL for a bus driver that wishes to run
200 diagnostics on one of its child controllers.
201 @param DiagnosticType Indicates type of diagnostics to perform on the controller
202 specified by ControllerHandle and ChildHandle.
203 @param Language A pointer to a three character ISO 639-2 language identifier.
204 This is the language in which the optional error message should
205 be returned in Buffer, and it must match one of the languages
206 specified in SupportedLanguages. The number of languages supported by
207 a driver is up to the driver writer.
208 @param ErrorType A GUID that defines the format of the data returned in Buffer.
209 @param BufferSize The size, in bytes, of the data returned in Buffer.
210 @param Buffer A buffer that contains a Null-terminated Unicode string
211 plus some additional data whose format is defined by ErrorType.
212 Buffer is allocated by this function with AllocatePool(), and
213 it is the caller's responsibility to free it with a call to FreePool().
215 @retval EFI_SUCCESS The controller specified by ControllerHandle and ChildHandle passed
217 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
218 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid EFI_HANDLE.
219 @retval EFI_INVALID_PARAMETER Language is NULL.
220 @retval EFI_INVALID_PARAMETER ErrorType is NULL.
221 @retval EFI_INVALID_PARAMETER BufferType is NULL.
222 @retval EFI_INVALID_PARAMETER Buffer is NULL.
223 @retval EFI_UNSUPPORTED The driver specified by This does not support running
224 diagnostics for the controller specified by ControllerHandle
226 @retval EFI_UNSUPPORTED The driver specified by This does not support the
227 type of diagnostic specified by DiagnosticType.
228 @retval EFI_UNSUPPORTED The driver specified by This does not support the language
229 specified by Language.
230 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to complete the
232 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to return the
233 status information in ErrorType, BufferSize,and Buffer.
234 @retval EFI_DEVICE_ERROR The controller specified by ControllerHandle and ChildHandle
235 did not pass the diagnostic.
239 IDEBusDriverDiagnosticsRunDiagnostics (
240 IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL
*This
,
241 IN EFI_HANDLE ControllerHandle
,
242 IN EFI_HANDLE ChildHandle OPTIONAL
,
243 IN EFI_DRIVER_DIAGNOSTIC_TYPE DiagnosticType
,
245 OUT EFI_GUID
**ErrorType
,
246 OUT UINTN
*BufferSize
,
251 issue ATA or ATAPI command to reset a block IO device.
252 @param This Block IO protocol instance pointer.
253 @param ExtendedVerification If FALSE,for ATAPI device, driver will only invoke ATAPI reset method
254 If TRUE, for ATAPI device, driver need invoke ATA reset method after
255 invoke ATAPI reset method
257 @retval EFI_DEVICE_ERROR When the device is neighther ATA device or ATAPI device.
258 @retval EFI_SUCCESS The device reset successfully
264 IN EFI_BLOCK_IO_PROTOCOL
*This
,
265 IN BOOLEAN ExtendedVerification
269 Read data from a block IO device.
271 @param This Block IO protocol instance pointer.
272 @param MediaId The media ID of the device
273 @param Lba Starting LBA address to read data
274 @param BufferSize The size of data to be read
275 @param Buffer Caller supplied buffer to save data
277 @retval EFI_DEVICE_ERROR unknown device type
278 @retval EFI_SUCCESS read the data successfully.
284 IN EFI_BLOCK_IO_PROTOCOL
*This
,
292 Write data to block io device
294 @param This Protocol instance pointer.
295 @param MediaId The media ID of the device
296 @param Lba Starting LBA address to write data
297 @param BufferSize The size of data to be written
298 @param Buffer Caller supplied buffer to save data
300 @retval EFI_DEVICE_ERROR unknown device type
301 @retval other write data status
306 IDEBlkIoWriteBlocks (
307 IN EFI_BLOCK_IO_PROTOCOL
*This
,
315 Flushes all modified data to a physical block devices
317 @param This Indicates a pointer to the calling context which to sepcify a
318 sepcific block device
320 @retval EFI_SUCCESS Always return success.
324 IDEBlkIoFlushBlocks (
325 IN EFI_BLOCK_IO_PROTOCOL
*This
328 This function is used by the IDE bus driver to get inquiry data.
329 Data format of Identify data is defined by the Interface GUID.
331 @param This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
332 @param InquiryData Pointer to a buffer for the inquiry data.
333 @param InquiryDataSize Pointer to the value for the inquiry data size.
335 @retval EFI_SUCCESS The command was accepted without any errors.
336 @retval EFI_NOT_FOUND Device does not support this data class
337 @retval EFI_DEVICE_ERROR Error reading InquiryData from device
338 @retval EFI_BUFFER_TOO_SMALL IntquiryDataSize not big enough
344 IN EFI_DISK_INFO_PROTOCOL
*This
,
345 IN OUT VOID
*InquiryData
,
346 IN OUT UINT32
*InquiryDataSize
350 This function is used by the IDE bus driver to get identify data.
351 Data format of Identify data is defined by the Interface GUID.
353 @param This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
354 @param IdentifyData Pointer to a buffer for the identify data.
355 @param IdentifyDataSize Pointer to the value for the identify data size.
357 @retval EFI_SUCCESS The command was accepted without any errors.
358 @retval EFI_NOT_FOUND Device does not support this data class
359 @retval EFI_DEVICE_ERROR Error reading IdentifyData from device
360 @retval EFI_BUFFER_TOO_SMALL IdentifyDataSize not big enough
365 IDEDiskInfoIdentify (
366 IN EFI_DISK_INFO_PROTOCOL
*This
,
367 IN OUT VOID
*IdentifyData
,
368 IN OUT UINT32
*IdentifyDataSize
372 This function is used by the IDE bus driver to get sense data.
373 Data format of Sense data is defined by the Interface GUID.
375 @param This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
376 @param SenseData Pointer to the SenseData.
377 @param SenseDataSize Size of SenseData in bytes.
378 @param SenseDataNumber Pointer to the value for the identify data size.
380 @retval EFI_SUCCESS The command was accepted without any errors.
381 @retval EFI_NOT_FOUND Device does not support this data class
382 @retval EFI_DEVICE_ERROR Error reading InquiryData from device
383 @retval EFI_BUFFER_TOO_SMALL SenseDataSize not big enough
388 IDEDiskInfoSenseData (
389 IN EFI_DISK_INFO_PROTOCOL
*This
,
390 IN OUT VOID
*SenseData
,
391 IN OUT UINT32
*SenseDataSize
,
392 OUT UINT8
*SenseDataNumber
396 This function is used by the IDE bus driver to get controller information.
398 @param This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
399 @param IdeChannel Pointer to the Ide Channel number. Primary or secondary.
400 @param IdeDevice Pointer to the Ide Device number. Master or slave.
402 @retval EFI_SUCCESS IdeChannel and IdeDevice are valid
403 @retval EFI_UNSUPPORTED This is not an IDE device
408 IDEDiskInfoWhichIde (
409 IN EFI_DISK_INFO_PROTOCOL
*This
,
410 OUT UINT32
*IdeChannel
,
411 OUT UINT32
*IdeDevice
414 The is an event(generally the event is exitBootService event) call back function.
415 Clear pending IDE interrupt before OS loader/kernel take control of the IDE device.
417 @param Event Pointer to this event
418 @param Context Event handler private data