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.
93 IDEBusDriverDiagnosticsRunDiagnostics (
94 IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL
*This
,
95 IN EFI_HANDLE ControllerHandle
,
96 IN EFI_HANDLE ChildHandle OPTIONAL
,
97 IN EFI_DRIVER_DIAGNOSTIC_TYPE DiagnosticType
,
99 OUT EFI_GUID
**ErrorType
,
100 OUT UINTN
*BufferSize
,
105 EFI_PCI_IO_PROTOCOL
*PciIo
;
106 EFI_BLOCK_IO_PROTOCOL
*BlkIo
;
107 IDE_BLK_IO_DEV
*IdeBlkIoDevice
;
108 UINT32 VendorDeviceId
;
110 CHAR8
*SupportedLanguages
;
111 BOOLEAN Iso639Language
;
115 if (Language
== NULL
||
118 ControllerHandle
== NULL
||
119 BufferSize
== NULL
) {
121 return EFI_INVALID_PARAMETER
;
124 SupportedLanguages
= This
->SupportedLanguages
;
125 Iso639Language
= (BOOLEAN
)(This
== &gIDEBusDriverDiagnostics
);
127 // Make sure Language is in the set of Supported Languages
130 while (*SupportedLanguages
!= 0) {
131 if (Iso639Language
) {
132 if (CompareMem (Language
, SupportedLanguages
, 3) == 0) {
136 SupportedLanguages
+= 3;
138 for (Index
= 0; SupportedLanguages
[Index
] != 0 && SupportedLanguages
[Index
] != ';'; Index
++);
139 if ((AsciiStrnCmp(SupportedLanguages
, Language
, Index
) == 0) && (Language
[Index
] == 0)) {
143 SupportedLanguages
+= Index
;
144 for (; *SupportedLanguages
!= 0 && *SupportedLanguages
== ';'; SupportedLanguages
++);
148 // If Language is not a member of SupportedLanguages, then return EFI_UNSUPPORTED
151 return EFI_UNSUPPORTED
;
157 if (ChildHandle
== NULL
) {
158 Status
= gBS
->OpenProtocol (
162 gIDEBusDriverBinding
.DriverBindingHandle
,
164 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
166 if (EFI_ERROR (Status
)) {
170 Status
= gBS
->OpenProtocol (
172 &gEfiPciIoProtocolGuid
,
174 gIDEBusDriverBinding
.DriverBindingHandle
,
176 EFI_OPEN_PROTOCOL_GET_PROTOCOL
178 if (EFI_ERROR (Status
)) {
179 return EFI_DEVICE_ERROR
;
183 // Use services of PCI I/O Protocol to test the PCI IDE/ATAPI Controller
184 // The following test simply reads the Device ID and Vendor ID.
185 // It should never fail. A real test would perform more advanced
189 Status
= PciIo
->Pci
.Read (PciIo
, EfiPciIoWidthUint32
, 0, 1, &VendorDeviceId
);
190 if (EFI_ERROR (Status
) || VendorDeviceId
== 0xffffffff) {
191 return EFI_DEVICE_ERROR
;
197 Status
= gBS
->OpenProtocol (
199 &gEfiBlockIoProtocolGuid
,
201 gIDEBusDriverBinding
.DriverBindingHandle
,
203 EFI_OPEN_PROTOCOL_GET_PROTOCOL
205 if (EFI_ERROR (Status
)) {
209 IdeBlkIoDevice
= IDE_BLOCK_IO_DEV_FROM_THIS (BlkIo
);
212 // Use services available from IdeBlkIoDevice to test the IDE/ATAPI device
214 Status
= gBS
->AllocatePool (
216 IdeBlkIoDevice
->BlkMedia
.BlockSize
,
217 (VOID
**) &BlockBuffer
219 if (EFI_ERROR (Status
)) {
223 Status
= IdeBlkIoDevice
->BlkIo
.ReadBlocks (
224 &IdeBlkIoDevice
->BlkIo
,
225 IdeBlkIoDevice
->BlkMedia
.MediaId
,
227 IdeBlkIoDevice
->BlkMedia
.BlockSize
,
231 if (EFI_ERROR (Status
)) {
232 *ErrorType
= &gEfiCallerIdGuid
;
233 *BufferSize
= sizeof (IDE_BUS_DIAGNOSTIC_ERROR
);
235 Status
= gBS
->AllocatePool (
237 (UINTN
) (*BufferSize
),
240 if (EFI_ERROR (Status
)) {
244 CopyMem (*Buffer
, IDE_BUS_DIAGNOSTIC_ERROR
, *BufferSize
);
246 Status
= EFI_DEVICE_ERROR
;
249 gBS
->FreePool (BlockBuffer
);