3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
22 #define IDE_BUS_DIAGNOSTIC_ERROR L"PCI IDE/ATAPI Driver Diagnostics Failed"
25 // EFI Driver Diagnostics Functions
28 IDEBusDriverDiagnosticsRunDiagnostics (
29 IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL
*This
,
30 IN EFI_HANDLE ControllerHandle
,
31 IN EFI_HANDLE ChildHandle OPTIONAL
,
32 IN EFI_DRIVER_DIAGNOSTIC_TYPE DiagnosticType
,
34 OUT EFI_GUID
**ErrorType
,
35 OUT UINTN
*BufferSize
,
40 // EFI Driver Diagnostics Protocol
42 EFI_DRIVER_DIAGNOSTICS_PROTOCOL gIDEBusDriverDiagnostics
= {
43 IDEBusDriverDiagnosticsRunDiagnostics
,
48 IDEBusDriverDiagnosticsRunDiagnostics (
49 IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL
*This
,
50 IN EFI_HANDLE ControllerHandle
,
51 IN EFI_HANDLE ChildHandle OPTIONAL
,
52 IN EFI_DRIVER_DIAGNOSTIC_TYPE DiagnosticType
,
54 OUT EFI_GUID
**ErrorType
,
55 OUT UINTN
*BufferSize
,
61 Runs diagnostics on a controller.
64 This - A pointer to the EFI_DRIVER_DIAGNOSTICS_PROTOCOL
66 ControllerHandle - The handle of the controller to run diagnostics on.
67 ChildHandle - The handle of the child controller to run diagnostics on
68 This is an optional parameter that may be NULL. It will
69 be NULL for device drivers. It will also be NULL for a
70 bus drivers that wish to run diagnostics on the bus
71 controller. It will not be NULL for a bus driver that
72 wishes to run diagnostics on one of its child
74 DiagnosticType - Indicates type of diagnostics to perform on the
75 controller specified by ControllerHandle and ChildHandle.
76 See "Related Definitions" for the list of supported
78 Language - A pointer to a three character ISO 639-2 language
79 identifier. This is the language in which the optional
80 error message should be returned in Buffer, and it must
81 match one of the languages specified in
82 SupportedLanguages. The number of languages supported by
83 a driver is up to the driver writer.
84 ErrorType - A GUID that defines the format of the data returned in
86 BufferSize - The size, in bytes, of the data returned in Buffer.
87 Buffer - A buffer that contains a Null-terminated Unicode string
88 plus some additional data whose format is defined by
89 ErrorType. Buffer is allocated by this function with
90 AllocatePool(), and it is the caller's responsibility
91 to free it with a call to FreePool().
94 EFI_SUCCESS - The controller specified by ControllerHandle and
95 ChildHandle passed the diagnostic.
96 EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.
97 EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid
99 EFI_INVALID_PARAMETER - Language is NULL.
100 EFI_INVALID_PARAMETER - ErrorType is NULL.
101 EFI_INVALID_PARAMETER - BufferType is NULL.
102 EFI_INVALID_PARAMETER - Buffer is NULL.
103 EFI_UNSUPPORTED - The driver specified by This does not support
104 running diagnostics for the controller specified
105 by ControllerHandle and ChildHandle.
106 EFI_UNSUPPORTED - The driver specified by This does not support the
107 type of diagnostic specified by DiagnosticType.
108 EFI_UNSUPPORTED - The driver specified by This does not support the
109 language specified by Language.
110 EFI_OUT_OF_RESOURCES - There are not enough resources available to complete
112 EFI_OUT_OF_RESOURCES - There are not enough resources available to return
113 the status information in ErrorType, BufferSize,
115 EFI_DEVICE_ERROR - The controller specified by ControllerHandle and
116 ChildHandle did not pass the diagnostic.
121 EFI_PCI_IO_PROTOCOL
*PciIo
;
122 EFI_BLOCK_IO_PROTOCOL
*BlkIo
;
123 IDE_BLK_IO_DEV
*IdeBlkIoDevice
;
124 UINT32 VendorDeviceId
;
130 if (ChildHandle
== NULL
) {
131 Status
= gBS
->OpenProtocol (
135 gIDEBusDriverBinding
.DriverBindingHandle
,
137 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
139 if (EFI_ERROR (Status
)) {
140 return EFI_UNSUPPORTED
;
143 Status
= gBS
->OpenProtocol (
145 &gEfiPciIoProtocolGuid
,
147 gIDEBusDriverBinding
.DriverBindingHandle
,
149 EFI_OPEN_PROTOCOL_GET_PROTOCOL
151 if (EFI_ERROR (Status
)) {
152 return EFI_DEVICE_ERROR
;
156 // Use services of PCI I/O Protocol to test the PCI IDE/ATAPI Controller
157 // The following test simply reads the Device ID and Vendor ID.
158 // It should never fail. A real test would perform more advanced
162 Status
= PciIo
->Pci
.Read (PciIo
, EfiPciIoWidthUint32
, 0, 1, &VendorDeviceId
);
163 if (EFI_ERROR (Status
) || VendorDeviceId
== 0xffffffff) {
164 return EFI_DEVICE_ERROR
;
170 Status
= gBS
->OpenProtocol (
172 &gEfiBlockIoProtocolGuid
,
174 gIDEBusDriverBinding
.DriverBindingHandle
,
176 EFI_OPEN_PROTOCOL_GET_PROTOCOL
178 if (EFI_ERROR (Status
)) {
179 return EFI_UNSUPPORTED
;
182 IdeBlkIoDevice
= IDE_BLOCK_IO_DEV_FROM_THIS (BlkIo
);
185 // Use services available from IdeBlkIoDevice to test the IDE/ATAPI device
187 Status
= gBS
->AllocatePool (
189 IdeBlkIoDevice
->BlkMedia
.BlockSize
,
190 (VOID
**) &BlockBuffer
192 if (EFI_ERROR (Status
)) {
196 Status
= IdeBlkIoDevice
->BlkIo
.ReadBlocks (
197 &IdeBlkIoDevice
->BlkIo
,
198 IdeBlkIoDevice
->BlkMedia
.MediaId
,
200 IdeBlkIoDevice
->BlkMedia
.BlockSize
,
204 if (EFI_ERROR (Status
)) {
205 *ErrorType
= &gEfiCallerIdGuid
;
206 *BufferSize
= sizeof (IDE_BUS_DIAGNOSTIC_ERROR
);
208 Status
= gBS
->AllocatePool (
210 (UINTN
) (*BufferSize
),
213 if (EFI_ERROR (Status
)) {
217 EfiCopyMem (*Buffer
, IDE_BUS_DIAGNOSTIC_ERROR
, *BufferSize
);
219 Status
= EFI_DEVICE_ERROR
;
222 gBS
->FreePool (BlockBuffer
);