2 Copyright (c) 2006, 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.
15 #define IDE_BUS_DIAGNOSTIC_ERROR L"PCI IDE/ATAPI Driver Diagnostics Failed"
18 // EFI Driver Diagnostics Protocol
20 EFI_DRIVER_DIAGNOSTICS_PROTOCOL gIDEBusDriverDiagnostics
= {
21 IDEBusDriverDiagnosticsRunDiagnostics
,
26 Runs diagnostics on a controller.
28 @param This A pointer to the EFI_DRIVER_DIAGNOSTICS_PROTOCOL
30 @param ControllerHandle The handle of the controller to run diagnostics on.
31 @param ChildHandle The handle of the child controller to run diagnostics on
32 This is an optional parameter that may be NULL. It will
33 be NULL for device drivers. It will also be NULL for a
34 bus drivers that wish to run diagnostics on the bus
35 controller. It will not be NULL for a bus driver that
36 wishes to run diagnostics on one of its child
38 @param DiagnosticType Indicates type of diagnostics to perform on the
39 controller specified by ControllerHandle and ChildHandle.
40 See "Related Definitions" for the list of supported
42 @param Language A pointer to a three character ISO 639-2 language
43 identifier. This is the language in which the optional
44 error message should be returned in Buffer, and it must
45 match one of the languages specified in
46 SupportedLanguages. The number of languages supported by
47 a driver is up to the driver writer.
48 @param ErrorType A GUID that defines the format of the data returned in
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
53 ErrorType. Buffer is allocated by this function with
54 AllocatePool(), and it is the caller's responsibility
55 to free it with a call to FreePool().
57 @retval EFI_SUCCESS The controller specified by ControllerHandle and
58 ChildHandle passed the diagnostic.
59 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
60 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
62 @retval EFI_INVALID_PARAMETER Language is NULL.
63 @retval EFI_INVALID_PARAMETER ErrorType is NULL.
64 @retval EFI_INVALID_PARAMETER BufferType is NULL.
65 @retval EFI_INVALID_PARAMETER Buffer is NULL.
66 @retval EFI_UNSUPPORTED The driver specified by This does not support
67 running diagnostics for the controller specified
68 by ControllerHandle and ChildHandle.
69 @retval EFI_UNSUPPORTED The driver specified by This does not support the
70 type of diagnostic specified by DiagnosticType.
71 @retval EFI_UNSUPPORTED The driver specified by This does not support the
72 language specified by Language.
73 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to complete
75 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to return
76 the status information in ErrorType, BufferSize,
78 @retval EFI_DEVICE_ERROR The controller specified by ControllerHandle and
79 ChildHandle did not pass the diagnostic.
83 IDEBusDriverDiagnosticsRunDiagnostics (
84 IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL
*This
,
85 IN EFI_HANDLE ControllerHandle
,
86 IN EFI_HANDLE ChildHandle OPTIONAL
,
87 IN EFI_DRIVER_DIAGNOSTIC_TYPE DiagnosticType
,
89 OUT EFI_GUID
**ErrorType
,
90 OUT UINTN
*BufferSize
,
95 EFI_PCI_IO_PROTOCOL
*PciIo
;
96 EFI_BLOCK_IO_PROTOCOL
*BlkIo
;
97 IDE_BLK_IO_DEV
*IdeBlkIoDevice
;
98 UINT32 VendorDeviceId
;
104 if (ChildHandle
== NULL
) {
105 Status
= gBS
->OpenProtocol (
109 gIDEBusDriverBinding
.DriverBindingHandle
,
111 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
113 if (EFI_ERROR (Status
)) {
114 return EFI_UNSUPPORTED
;
117 Status
= gBS
->OpenProtocol (
119 &gEfiPciIoProtocolGuid
,
121 gIDEBusDriverBinding
.DriverBindingHandle
,
123 EFI_OPEN_PROTOCOL_GET_PROTOCOL
125 if (EFI_ERROR (Status
)) {
126 return EFI_DEVICE_ERROR
;
130 // Use services of PCI I/O Protocol to test the PCI IDE/ATAPI Controller
131 // The following test simply reads the Device ID and Vendor ID.
132 // It should never fail. A real test would perform more advanced
136 Status
= PciIo
->Pci
.Read (PciIo
, EfiPciIoWidthUint32
, 0, 1, &VendorDeviceId
);
137 if (EFI_ERROR (Status
) || VendorDeviceId
== 0xffffffff) {
138 return EFI_DEVICE_ERROR
;
144 Status
= gBS
->OpenProtocol (
146 &gEfiBlockIoProtocolGuid
,
148 gIDEBusDriverBinding
.DriverBindingHandle
,
150 EFI_OPEN_PROTOCOL_GET_PROTOCOL
152 if (EFI_ERROR (Status
)) {
153 return EFI_UNSUPPORTED
;
156 IdeBlkIoDevice
= IDE_BLOCK_IO_DEV_FROM_THIS (BlkIo
);
159 // Use services available from IdeBlkIoDevice to test the IDE/ATAPI device
161 Status
= gBS
->AllocatePool (
163 IdeBlkIoDevice
->BlkMedia
.BlockSize
,
164 (VOID
**) &BlockBuffer
166 if (EFI_ERROR (Status
)) {
170 Status
= IdeBlkIoDevice
->BlkIo
.ReadBlocks (
171 &IdeBlkIoDevice
->BlkIo
,
172 IdeBlkIoDevice
->BlkMedia
.MediaId
,
174 IdeBlkIoDevice
->BlkMedia
.BlockSize
,
178 if (EFI_ERROR (Status
)) {
179 *ErrorType
= &gEfiCallerIdGuid
;
180 *BufferSize
= sizeof (IDE_BUS_DIAGNOSTIC_ERROR
);
182 Status
= gBS
->AllocatePool (
184 (UINTN
) (*BufferSize
),
187 if (EFI_ERROR (Status
)) {
191 CopyMem (*Buffer
, IDE_BUS_DIAGNOSTIC_ERROR
, *BufferSize
);
193 Status
= EFI_DEVICE_ERROR
;
196 gBS
->FreePool (BlockBuffer
);