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 Functions
21 IDEBusDriverDiagnosticsRunDiagnostics (
22 IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL
*This
,
23 IN EFI_HANDLE ControllerHandle
,
24 IN EFI_HANDLE ChildHandle OPTIONAL
,
25 IN EFI_DRIVER_DIAGNOSTIC_TYPE DiagnosticType
,
27 OUT EFI_GUID
**ErrorType
,
28 OUT UINTN
*BufferSize
,
33 // EFI Driver Diagnostics Protocol
35 EFI_DRIVER_DIAGNOSTICS_PROTOCOL gIDEBusDriverDiagnostics
= {
36 IDEBusDriverDiagnosticsRunDiagnostics
,
41 Runs diagnostics on a controller.
43 @param This A pointer to the EFI_DRIVER_DIAGNOSTICS_PROTOCOL
45 @param ControllerHandle The handle of the controller to run diagnostics on.
46 @param ChildHandle The handle of the child controller to run diagnostics on
47 This is an optional parameter that may be NULL. It will
48 be NULL for device drivers. It will also be NULL for a
49 bus drivers that wish to run diagnostics on the bus
50 controller. It will not be NULL for a bus driver that
51 wishes to run diagnostics on one of its child
53 @param DiagnosticType Indicates type of diagnostics to perform on the
54 controller specified by ControllerHandle and ChildHandle.
55 See "Related Definitions" for the list of supported
57 @param Language A pointer to a three character ISO 639-2 language
58 identifier. This is the language in which the optional
59 error message should be returned in Buffer, and it must
60 match one of the languages specified in
61 SupportedLanguages. The number of languages supported by
62 a driver is up to the driver writer.
63 @param ErrorType A GUID that defines the format of the data returned in
65 @param BufferSize The size, in bytes, of the data returned in Buffer.
66 @param Buffer A buffer that contains a Null-terminated Unicode string
67 plus some additional data whose format is defined by
68 ErrorType. Buffer is allocated by this function with
69 AllocatePool(), and it is the caller's responsibility
70 to free it with a call to FreePool().
72 @retval EFI_SUCCESS The controller specified by ControllerHandle and
73 ChildHandle passed the diagnostic.
74 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
75 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
77 @retval EFI_INVALID_PARAMETER Language is NULL.
78 @retval EFI_INVALID_PARAMETER ErrorType is NULL.
79 @retval EFI_INVALID_PARAMETER BufferType is NULL.
80 @retval EFI_INVALID_PARAMETER Buffer is NULL.
81 @retval EFI_UNSUPPORTED The driver specified by This does not support
82 running diagnostics for the controller specified
83 by ControllerHandle and ChildHandle.
84 @retval EFI_UNSUPPORTED The driver specified by This does not support the
85 type of diagnostic specified by DiagnosticType.
86 @retval EFI_UNSUPPORTED The driver specified by This does not support the
87 language specified by Language.
88 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to complete
90 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to return
91 the status information in ErrorType, BufferSize,
93 @retval EFI_DEVICE_ERROR The controller specified by ControllerHandle and
94 ChildHandle did not pass the diagnostic.
98 IDEBusDriverDiagnosticsRunDiagnostics (
99 IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL
*This
,
100 IN EFI_HANDLE ControllerHandle
,
101 IN EFI_HANDLE ChildHandle OPTIONAL
,
102 IN EFI_DRIVER_DIAGNOSTIC_TYPE DiagnosticType
,
104 OUT EFI_GUID
**ErrorType
,
105 OUT UINTN
*BufferSize
,
110 EFI_PCI_IO_PROTOCOL
*PciIo
;
111 EFI_BLOCK_IO_PROTOCOL
*BlkIo
;
112 IDE_BLK_IO_DEV
*IdeBlkIoDevice
;
113 UINT32 VendorDeviceId
;
119 if (ChildHandle
== NULL
) {
120 Status
= gBS
->OpenProtocol (
124 gIDEBusDriverBinding
.DriverBindingHandle
,
126 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
128 if (EFI_ERROR (Status
)) {
129 return EFI_UNSUPPORTED
;
132 Status
= gBS
->OpenProtocol (
134 &gEfiPciIoProtocolGuid
,
136 gIDEBusDriverBinding
.DriverBindingHandle
,
138 EFI_OPEN_PROTOCOL_GET_PROTOCOL
140 if (EFI_ERROR (Status
)) {
141 return EFI_DEVICE_ERROR
;
145 // Use services of PCI I/O Protocol to test the PCI IDE/ATAPI Controller
146 // The following test simply reads the Device ID and Vendor ID.
147 // It should never fail. A real test would perform more advanced
151 Status
= PciIo
->Pci
.Read (PciIo
, EfiPciIoWidthUint32
, 0, 1, &VendorDeviceId
);
152 if (EFI_ERROR (Status
) || VendorDeviceId
== 0xffffffff) {
153 return EFI_DEVICE_ERROR
;
159 Status
= gBS
->OpenProtocol (
161 &gEfiBlockIoProtocolGuid
,
163 gIDEBusDriverBinding
.DriverBindingHandle
,
165 EFI_OPEN_PROTOCOL_GET_PROTOCOL
167 if (EFI_ERROR (Status
)) {
168 return EFI_UNSUPPORTED
;
171 IdeBlkIoDevice
= IDE_BLOCK_IO_DEV_FROM_THIS (BlkIo
);
174 // Use services available from IdeBlkIoDevice to test the IDE/ATAPI device
176 Status
= gBS
->AllocatePool (
178 IdeBlkIoDevice
->BlkMedia
.BlockSize
,
179 (VOID
**) &BlockBuffer
181 if (EFI_ERROR (Status
)) {
185 Status
= IdeBlkIoDevice
->BlkIo
.ReadBlocks (
186 &IdeBlkIoDevice
->BlkIo
,
187 IdeBlkIoDevice
->BlkMedia
.MediaId
,
189 IdeBlkIoDevice
->BlkMedia
.BlockSize
,
193 if (EFI_ERROR (Status
)) {
194 *ErrorType
= &gEfiCallerIdGuid
;
195 *BufferSize
= sizeof (IDE_BUS_DIAGNOSTIC_ERROR
);
197 Status
= gBS
->AllocatePool (
199 (UINTN
) (*BufferSize
),
202 if (EFI_ERROR (Status
)) {
206 EfiCopyMem (*Buffer
, IDE_BUS_DIAGNOSTIC_ERROR
, *BufferSize
);
208 Status
= EFI_DEVICE_ERROR
;
211 gBS
->FreePool (BlockBuffer
);