2 Implementation of UEFI driver Dialnostics protocol which to perform diagnostic on the IDE
5 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
13 #define IDE_BUS_DIAGNOSTIC_ERROR L"PCI IDE/ATAPI Driver Diagnostics Failed"
16 // EFI Driver Diagnostics Protocol
18 GLOBAL_REMOVE_IF_UNREFERENCED EFI_DRIVER_DIAGNOSTICS_PROTOCOL gIDEBusDriverDiagnostics
= {
19 IDEBusDriverDiagnosticsRunDiagnostics
,
24 // EFI Driver Diagnostics 2 Protocol
26 GLOBAL_REMOVE_IF_UNREFERENCED EFI_DRIVER_DIAGNOSTICS2_PROTOCOL gIDEBusDriverDiagnostics2
= {
27 (EFI_DRIVER_DIAGNOSTICS2_RUN_DIAGNOSTICS
) IDEBusDriverDiagnosticsRunDiagnostics
,
32 Runs diagnostics on a controller.
34 @param This A pointer to the EFI_DRIVER_DIAGNOSTICS_PROTOCOLinstance.
35 @param ControllerHandle The handle of the controller to run diagnostics on.
36 @param ChildHandle The handle of the child controller to run diagnostics on
37 This is an optional parameter that may be NULL. It will
38 be NULL for device drivers. It will also be NULL for a
39 bus drivers that wish to run diagnostics on the bus controller.
40 It will not be NULL for a bus driver that wishes to run
41 diagnostics on one of its child controllers.
42 @param DiagnosticType Indicates type of diagnostics to perform on the controller
43 specified by ControllerHandle and ChildHandle.
44 @param Language A pointer to a three character ISO 639-2 language identifier.
45 This is the language in which the optional error message should
46 be returned in Buffer, and it must match one of the languages
47 specified in SupportedLanguages. The number of languages supported by
48 a driver is up to the driver writer.
49 @param ErrorType A GUID that defines the format of the data returned in Buffer.
50 @param BufferSize The size, in bytes, of the data returned in Buffer.
51 @param Buffer A buffer that contains a Null-terminated Unicode string
52 plus some additional data whose format is defined by ErrorType.
53 Buffer is allocated by this function with AllocatePool(), and
54 it is the caller's responsibility to free it with a call to FreePool().
56 @retval EFI_SUCCESS The controller specified by ControllerHandle and ChildHandle passed
58 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
59 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid EFI_HANDLE.
60 @retval EFI_INVALID_PARAMETER Language is NULL.
61 @retval EFI_INVALID_PARAMETER ErrorType is NULL.
62 @retval EFI_INVALID_PARAMETER BufferType is NULL.
63 @retval EFI_INVALID_PARAMETER Buffer is NULL.
64 @retval EFI_UNSUPPORTED The driver specified by This does not support running
65 diagnostics for the controller specified by ControllerHandle
67 @retval EFI_UNSUPPORTED The driver specified by This does not support the
68 type of diagnostic specified by DiagnosticType.
69 @retval EFI_UNSUPPORTED The driver specified by This does not support the language
70 specified by Language.
71 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to complete the
73 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to return the
74 status information in ErrorType, BufferSize,and Buffer.
75 @retval EFI_DEVICE_ERROR The controller specified by ControllerHandle and ChildHandle
76 did not pass the diagnostic.
80 IDEBusDriverDiagnosticsRunDiagnostics (
81 IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL
*This
,
82 IN EFI_HANDLE ControllerHandle
,
83 IN EFI_HANDLE ChildHandle OPTIONAL
,
84 IN EFI_DRIVER_DIAGNOSTIC_TYPE DiagnosticType
,
86 OUT EFI_GUID
**ErrorType
,
87 OUT UINTN
*BufferSize
,
92 EFI_PCI_IO_PROTOCOL
*PciIo
;
93 EFI_BLOCK_IO_PROTOCOL
*BlkIo
;
94 IDE_BLK_IO_DEV
*IdeBlkIoDevice
;
95 UINT32 VendorDeviceId
;
97 CHAR8
*SupportedLanguages
;
98 BOOLEAN Iso639Language
;
102 if (Language
== NULL
||
105 ControllerHandle
== NULL
||
106 BufferSize
== NULL
) {
108 return EFI_INVALID_PARAMETER
;
111 SupportedLanguages
= This
->SupportedLanguages
;
112 Iso639Language
= (BOOLEAN
)(This
== &gIDEBusDriverDiagnostics
);
114 // Make sure Language is in the set of Supported Languages
117 while (*SupportedLanguages
!= 0) {
118 if (Iso639Language
) {
119 if (CompareMem (Language
, SupportedLanguages
, 3) == 0) {
123 SupportedLanguages
+= 3;
125 for (Index
= 0; SupportedLanguages
[Index
] != 0 && SupportedLanguages
[Index
] != ';'; Index
++);
126 if ((AsciiStrnCmp(SupportedLanguages
, Language
, Index
) == 0) && (Language
[Index
] == 0)) {
130 SupportedLanguages
+= Index
;
131 for (; *SupportedLanguages
!= 0 && *SupportedLanguages
== ';'; SupportedLanguages
++);
135 // If Language is not a member of SupportedLanguages, then return EFI_UNSUPPORTED
138 return EFI_UNSUPPORTED
;
144 if (ChildHandle
== NULL
) {
145 Status
= gBS
->OpenProtocol (
149 gIDEBusDriverBinding
.DriverBindingHandle
,
151 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
153 if (EFI_ERROR (Status
)) {
157 Status
= gBS
->OpenProtocol (
159 &gEfiPciIoProtocolGuid
,
161 gIDEBusDriverBinding
.DriverBindingHandle
,
163 EFI_OPEN_PROTOCOL_GET_PROTOCOL
165 if (EFI_ERROR (Status
)) {
166 return EFI_DEVICE_ERROR
;
170 // Use services of PCI I/O Protocol to test the PCI IDE/ATAPI Controller
171 // The following test simply reads the Device ID and Vendor ID.
172 // It should never fail. A real test would perform more advanced
176 Status
= PciIo
->Pci
.Read (PciIo
, EfiPciIoWidthUint32
, 0, 1, &VendorDeviceId
);
177 if (EFI_ERROR (Status
) || VendorDeviceId
== 0xffffffff) {
178 return EFI_DEVICE_ERROR
;
184 Status
= gBS
->OpenProtocol (
186 &gEfiBlockIoProtocolGuid
,
188 gIDEBusDriverBinding
.DriverBindingHandle
,
190 EFI_OPEN_PROTOCOL_GET_PROTOCOL
192 if (EFI_ERROR (Status
)) {
196 IdeBlkIoDevice
= IDE_BLOCK_IO_DEV_FROM_THIS (BlkIo
);
199 // Use services available from IdeBlkIoDevice to test the IDE/ATAPI device
201 Status
= gBS
->AllocatePool (
203 IdeBlkIoDevice
->BlkMedia
.BlockSize
,
204 (VOID
**) &BlockBuffer
206 if (EFI_ERROR (Status
)) {
210 Status
= IdeBlkIoDevice
->BlkIo
.ReadBlocks (
211 &IdeBlkIoDevice
->BlkIo
,
212 IdeBlkIoDevice
->BlkMedia
.MediaId
,
214 IdeBlkIoDevice
->BlkMedia
.BlockSize
,
218 if (EFI_ERROR (Status
)) {
219 *ErrorType
= &gEfiCallerIdGuid
;
220 *BufferSize
= sizeof (IDE_BUS_DIAGNOSTIC_ERROR
);
222 Status
= gBS
->AllocatePool (
224 (UINTN
) (*BufferSize
),
227 if (EFI_ERROR (Status
)) {
231 CopyMem (*Buffer
, IDE_BUS_DIAGNOSTIC_ERROR
, *BufferSize
);
233 Status
= EFI_DEVICE_ERROR
;
236 gBS
->FreePool (BlockBuffer
);