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.
16 #define IDE_BUS_DIAGNOSTIC_ERROR L"PCI IDE/ATAPI Driver Diagnostics Failed"
19 // EFI Driver Diagnostics Protocol
21 EFI_DRIVER_DIAGNOSTICS_PROTOCOL gIDEBusDriverDiagnostics
= {
22 IDEBusDriverDiagnosticsRunDiagnostics
,
27 Runs diagnostics on a controller.
29 @param This A pointer to the EFI_DRIVER_DIAGNOSTICS_PROTOCOL
31 @param ControllerHandle The handle of the controller to run diagnostics on.
32 @param ChildHandle The handle of the child controller to run diagnostics on
33 This is an optional parameter that may be NULL. It will
34 be NULL for device drivers. It will also be NULL for a
35 bus drivers that wish to run diagnostics on the bus
36 controller. It will not be NULL for a bus driver that
37 wishes to run diagnostics on one of its child
39 @param DiagnosticType Indicates type of diagnostics to perform on the
40 controller specified by ControllerHandle and ChildHandle.
41 See "Related Definitions" for the list of supported
43 @param Language A pointer to a three character ISO 639-2 language
44 identifier. This is the language in which the optional
45 error message should be returned in Buffer, and it must
46 match one of the languages specified in
47 SupportedLanguages. The number of languages supported by
48 a driver is up to the driver writer.
49 @param ErrorType A GUID that defines the format of the data returned in
51 @param BufferSize The size, in bytes, of the data returned in Buffer.
52 @param Buffer A buffer that contains a Null-terminated Unicode string
53 plus some additional data whose format is defined by
54 ErrorType. Buffer is allocated by this function with
55 AllocatePool(), and it is the caller's responsibility
56 to free it with a call to FreePool().
58 @retval EFI_SUCCESS The controller specified by ControllerHandle and
59 ChildHandle passed the diagnostic.
60 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
61 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
63 @retval EFI_INVALID_PARAMETER Language is NULL.
64 @retval EFI_INVALID_PARAMETER ErrorType is NULL.
65 @retval EFI_INVALID_PARAMETER BufferType is NULL.
66 @retval EFI_INVALID_PARAMETER Buffer is NULL.
67 @retval EFI_UNSUPPORTED The driver specified by This does not support
68 running diagnostics for the controller specified
69 by ControllerHandle and ChildHandle.
70 @retval EFI_UNSUPPORTED The driver specified by This does not support the
71 type of diagnostic specified by DiagnosticType.
72 @retval EFI_UNSUPPORTED The driver specified by This does not support the
73 language specified by Language.
74 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to complete
76 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to return
77 the status information in ErrorType, BufferSize,
79 @retval EFI_DEVICE_ERROR The controller specified by ControllerHandle and
80 ChildHandle did not pass the diagnostic.
84 IDEBusDriverDiagnosticsRunDiagnostics (
85 IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL
*This
,
86 IN EFI_HANDLE ControllerHandle
,
87 IN EFI_HANDLE ChildHandle OPTIONAL
,
88 IN EFI_DRIVER_DIAGNOSTIC_TYPE DiagnosticType
,
90 OUT EFI_GUID
**ErrorType
,
91 OUT UINTN
*BufferSize
,
96 EFI_PCI_IO_PROTOCOL
*PciIo
;
97 EFI_BLOCK_IO_PROTOCOL
*BlkIo
;
98 IDE_BLK_IO_DEV
*IdeBlkIoDevice
;
99 UINT32 VendorDeviceId
;
105 if (ChildHandle
== NULL
) {
106 Status
= gBS
->OpenProtocol (
110 gIDEBusDriverBinding
.DriverBindingHandle
,
112 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
114 if (EFI_ERROR (Status
)) {
115 return EFI_UNSUPPORTED
;
118 Status
= gBS
->OpenProtocol (
120 &gEfiPciIoProtocolGuid
,
122 gIDEBusDriverBinding
.DriverBindingHandle
,
124 EFI_OPEN_PROTOCOL_GET_PROTOCOL
126 if (EFI_ERROR (Status
)) {
127 return EFI_DEVICE_ERROR
;
131 // Use services of PCI I/O Protocol to test the PCI IDE/ATAPI Controller
132 // The following test simply reads the Device ID and Vendor ID.
133 // It should never fail. A real test would perform more advanced
137 Status
= PciIo
->Pci
.Read (PciIo
, EfiPciIoWidthUint32
, 0, 1, &VendorDeviceId
);
138 if (EFI_ERROR (Status
) || VendorDeviceId
== 0xffffffff) {
139 return EFI_DEVICE_ERROR
;
145 Status
= gBS
->OpenProtocol (
147 &gEfiBlockIoProtocolGuid
,
149 gIDEBusDriverBinding
.DriverBindingHandle
,
151 EFI_OPEN_PROTOCOL_GET_PROTOCOL
153 if (EFI_ERROR (Status
)) {
154 return EFI_UNSUPPORTED
;
157 IdeBlkIoDevice
= IDE_BLOCK_IO_DEV_FROM_THIS (BlkIo
);
160 // Use services available from IdeBlkIoDevice to test the IDE/ATAPI device
162 Status
= gBS
->AllocatePool (
164 IdeBlkIoDevice
->BlkMedia
.BlockSize
,
165 (VOID
**) &BlockBuffer
167 if (EFI_ERROR (Status
)) {
171 Status
= IdeBlkIoDevice
->BlkIo
.ReadBlocks (
172 &IdeBlkIoDevice
->BlkIo
,
173 IdeBlkIoDevice
->BlkMedia
.MediaId
,
175 IdeBlkIoDevice
->BlkMedia
.BlockSize
,
179 if (EFI_ERROR (Status
)) {
180 *ErrorType
= &gEfiCallerIdGuid
;
181 *BufferSize
= sizeof (IDE_BUS_DIAGNOSTIC_ERROR
);
183 Status
= gBS
->AllocatePool (
185 (UINTN
) (*BufferSize
),
188 if (EFI_ERROR (Status
)) {
192 CopyMem (*Buffer
, IDE_BUS_DIAGNOSTIC_ERROR
, *BufferSize
);
194 Status
= EFI_DEVICE_ERROR
;
197 gBS
->FreePool (BlockBuffer
);