2 Copyright (c) 2006 - 2008, Intel Corporation
3 All rights reserved. This program and the accompanying materials
4 are licensed and made available under the terms and conditions of the BSD License
5 which accompanies this distribution. The full text of the license may be found at
6 http://opensource.org/licenses/bsd-license.php
8 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
9 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #define IDE_BUS_DIAGNOSTIC_ERROR L"PCI IDE/ATAPI Driver Diagnostics Failed"
19 // EFI Driver Diagnostics Protocol
21 GLOBAL_REMOVE_IF_UNREFERENCED EFI_DRIVER_DIAGNOSTICS_PROTOCOL gIDEBusDriverDiagnostics
= {
22 IDEBusDriverDiagnosticsRunDiagnostics
,
27 // EFI Driver Diagnostics 2 Protocol
29 GLOBAL_REMOVE_IF_UNREFERENCED EFI_DRIVER_DIAGNOSTICS2_PROTOCOL gIDEBusDriverDiagnostics2
= {
30 (EFI_DRIVER_DIAGNOSTICS2_RUN_DIAGNOSTICS
) IDEBusDriverDiagnosticsRunDiagnostics
,
35 Runs diagnostics on a controller.
37 @param This A pointer to the EFI_DRIVER_DIAGNOSTICS_PROTOCOL
39 @param ControllerHandle The handle of the controller to run diagnostics on.
40 @param ChildHandle The handle of the child controller to run diagnostics on
41 This is an optional parameter that may be NULL. It will
42 be NULL for device drivers. It will also be NULL for a
43 bus drivers that wish to run diagnostics on the bus
44 controller. It will not be NULL for a bus driver that
45 wishes to run diagnostics on one of its child
47 @param DiagnosticType Indicates type of diagnostics to perform on the
48 controller specified by ControllerHandle and ChildHandle.
49 See "Related Definitions" for the list of supported
51 @param Language A pointer to a three character ISO 639-2 language
52 identifier. This is the language in which the optional
53 error message should be returned in Buffer, and it must
54 match one of the languages specified in
55 SupportedLanguages. The number of languages supported by
56 a driver is up to the driver writer.
57 @param ErrorType A GUID that defines the format of the data returned in
59 @param BufferSize The size, in bytes, of the data returned in Buffer.
60 @param Buffer A buffer that contains a Null-terminated Unicode string
61 plus some additional data whose format is defined by
62 ErrorType. Buffer is allocated by this function with
63 AllocatePool(), and it is the caller's responsibility
64 to free it with a call to FreePool().
66 @retval EFI_SUCCESS The controller specified by ControllerHandle and
67 ChildHandle passed the diagnostic.
68 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
69 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
71 @retval EFI_INVALID_PARAMETER Language is NULL.
72 @retval EFI_INVALID_PARAMETER ErrorType is NULL.
73 @retval EFI_INVALID_PARAMETER BufferType is NULL.
74 @retval EFI_INVALID_PARAMETER Buffer is NULL.
75 @retval EFI_UNSUPPORTED The driver specified by This does not support
76 running diagnostics for the controller specified
77 by ControllerHandle and ChildHandle.
78 @retval EFI_UNSUPPORTED The driver specified by This does not support the
79 type of diagnostic specified by DiagnosticType.
80 @retval EFI_UNSUPPORTED The driver specified by This does not support the
81 language specified by Language.
82 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to complete
84 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to return
85 the status information in ErrorType, BufferSize,
87 @retval EFI_DEVICE_ERROR The controller specified by ControllerHandle and
88 ChildHandle did not pass the diagnostic.
92 IDEBusDriverDiagnosticsRunDiagnostics (
93 IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL
*This
,
94 IN EFI_HANDLE ControllerHandle
,
95 IN EFI_HANDLE ChildHandle OPTIONAL
,
96 IN EFI_DRIVER_DIAGNOSTIC_TYPE DiagnosticType
,
98 OUT EFI_GUID
**ErrorType
,
99 OUT UINTN
*BufferSize
,
104 EFI_PCI_IO_PROTOCOL
*PciIo
;
105 EFI_BLOCK_IO_PROTOCOL
*BlkIo
;
106 IDE_BLK_IO_DEV
*IdeBlkIoDevice
;
107 UINT32 VendorDeviceId
;
109 CHAR8
*SupportedLanguages
;
110 BOOLEAN Iso639Language
;
114 if (Language
== NULL
||
117 ControllerHandle
== NULL
||
118 BufferSize
== NULL
) {
120 return EFI_INVALID_PARAMETER
;
123 SupportedLanguages
= This
->SupportedLanguages
;
124 Iso639Language
= (BOOLEAN
)(This
== &gIDEBusDriverDiagnostics
);
126 // Make sure Language is in the set of Supported Languages
129 while (*SupportedLanguages
!= 0) {
130 if (Iso639Language
) {
131 if (CompareMem (Language
, SupportedLanguages
, 3) == 0) {
135 SupportedLanguages
+= 3;
137 for (Index
= 0; SupportedLanguages
[Index
] != 0 && SupportedLanguages
[Index
] != ';'; Index
++);
138 if ((AsciiStrnCmp(SupportedLanguages
, Language
, Index
) == 0) && (Language
[Index
] == 0)) {
142 SupportedLanguages
+= Index
;
143 for (; *SupportedLanguages
!= 0 && *SupportedLanguages
== ';'; SupportedLanguages
++);
147 // If Language is not a member of SupportedLanguages, then return EFI_UNSUPPORTED
150 return EFI_UNSUPPORTED
;
156 if (ChildHandle
== NULL
) {
157 Status
= gBS
->OpenProtocol (
161 gIDEBusDriverBinding
.DriverBindingHandle
,
163 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
165 if (EFI_ERROR (Status
)) {
169 Status
= gBS
->OpenProtocol (
171 &gEfiPciIoProtocolGuid
,
173 gIDEBusDriverBinding
.DriverBindingHandle
,
175 EFI_OPEN_PROTOCOL_GET_PROTOCOL
177 if (EFI_ERROR (Status
)) {
178 return EFI_DEVICE_ERROR
;
182 // Use services of PCI I/O Protocol to test the PCI IDE/ATAPI Controller
183 // The following test simply reads the Device ID and Vendor ID.
184 // It should never fail. A real test would perform more advanced
188 Status
= PciIo
->Pci
.Read (PciIo
, EfiPciIoWidthUint32
, 0, 1, &VendorDeviceId
);
189 if (EFI_ERROR (Status
) || VendorDeviceId
== 0xffffffff) {
190 return EFI_DEVICE_ERROR
;
196 Status
= gBS
->OpenProtocol (
198 &gEfiBlockIoProtocolGuid
,
200 gIDEBusDriverBinding
.DriverBindingHandle
,
202 EFI_OPEN_PROTOCOL_GET_PROTOCOL
204 if (EFI_ERROR (Status
)) {
208 IdeBlkIoDevice
= IDE_BLOCK_IO_DEV_FROM_THIS (BlkIo
);
211 // Use services available from IdeBlkIoDevice to test the IDE/ATAPI device
213 Status
= gBS
->AllocatePool (
215 IdeBlkIoDevice
->BlkMedia
.BlockSize
,
216 (VOID
**) &BlockBuffer
218 if (EFI_ERROR (Status
)) {
222 Status
= IdeBlkIoDevice
->BlkIo
.ReadBlocks (
223 &IdeBlkIoDevice
->BlkIo
,
224 IdeBlkIoDevice
->BlkMedia
.MediaId
,
226 IdeBlkIoDevice
->BlkMedia
.BlockSize
,
230 if (EFI_ERROR (Status
)) {
231 *ErrorType
= &gEfiCallerIdGuid
;
232 *BufferSize
= sizeof (IDE_BUS_DIAGNOSTIC_ERROR
);
234 Status
= gBS
->AllocatePool (
236 (UINTN
) (*BufferSize
),
239 if (EFI_ERROR (Status
)) {
243 CopyMem (*Buffer
, IDE_BUS_DIAGNOSTIC_ERROR
, *BufferSize
);
245 Status
= EFI_DEVICE_ERROR
;
248 gBS
->FreePool (BlockBuffer
);