]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Bus/Pci/IdeBus/Dxe/DriverDiagnostics.c
Add ReadMe.txt to specify that the EFI image FatBinPkg provides does not contain...
[mirror_edk2.git] / IntelFrameworkModulePkg / Bus / Pci / IdeBus / Dxe / DriverDiagnostics.c
1 /** @file
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
7
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.
10
11 **/
12
13
14 #include "idebus.h"
15
16 #define IDE_BUS_DIAGNOSTIC_ERROR L"PCI IDE/ATAPI Driver Diagnostics Failed"
17
18 //
19 // EFI Driver Diagnostics Protocol
20 //
21 EFI_DRIVER_DIAGNOSTICS_PROTOCOL gIDEBusDriverDiagnostics = {
22 IDEBusDriverDiagnosticsRunDiagnostics,
23 "eng"
24 };
25
26 /**
27 Runs diagnostics on a controller.
28
29 @param This A pointer to the EFI_DRIVER_DIAGNOSTICS_PROTOCOL
30 instance.
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
38 controllers.
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
42 types.
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
50 Buffer.
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().
57
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
62 EFI_HANDLE.
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
75 the diagnostics.
76 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to return
77 the status information in ErrorType, BufferSize,
78 and Buffer.
79 @retval EFI_DEVICE_ERROR The controller specified by ControllerHandle and
80 ChildHandle did not pass the diagnostic.
81
82 **/
83 EFI_STATUS
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,
89 IN CHAR8 *Language,
90 OUT EFI_GUID **ErrorType,
91 OUT UINTN *BufferSize,
92 OUT CHAR16 **Buffer
93 )
94 {
95 EFI_STATUS Status;
96 EFI_PCI_IO_PROTOCOL *PciIo;
97 EFI_BLOCK_IO_PROTOCOL *BlkIo;
98 IDE_BLK_IO_DEV *IdeBlkIoDevice;
99 UINT32 VendorDeviceId;
100 VOID *BlockBuffer;
101
102 *ErrorType = NULL;
103 *BufferSize = 0;
104
105 if (ChildHandle == NULL) {
106 Status = gBS->OpenProtocol (
107 ControllerHandle,
108 &gEfiCallerIdGuid,
109 NULL,
110 gIDEBusDriverBinding.DriverBindingHandle,
111 ControllerHandle,
112 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
113 );
114 if (EFI_ERROR (Status)) {
115 return EFI_UNSUPPORTED;
116 }
117
118 Status = gBS->OpenProtocol (
119 ControllerHandle,
120 &gEfiPciIoProtocolGuid,
121 (VOID **) &PciIo,
122 gIDEBusDriverBinding.DriverBindingHandle,
123 ControllerHandle,
124 EFI_OPEN_PROTOCOL_GET_PROTOCOL
125 );
126 if (EFI_ERROR (Status)) {
127 return EFI_DEVICE_ERROR;
128 }
129
130 //
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
134 // diagnostics.
135 //
136
137 Status = PciIo->Pci.Read (PciIo, EfiPciIoWidthUint32, 0, 1, &VendorDeviceId);
138 if (EFI_ERROR (Status) || VendorDeviceId == 0xffffffff) {
139 return EFI_DEVICE_ERROR;
140 }
141
142 return EFI_SUCCESS;
143 }
144
145 Status = gBS->OpenProtocol (
146 ChildHandle,
147 &gEfiBlockIoProtocolGuid,
148 (VOID **) &BlkIo,
149 gIDEBusDriverBinding.DriverBindingHandle,
150 ChildHandle,
151 EFI_OPEN_PROTOCOL_GET_PROTOCOL
152 );
153 if (EFI_ERROR (Status)) {
154 return EFI_UNSUPPORTED;
155 }
156
157 IdeBlkIoDevice = IDE_BLOCK_IO_DEV_FROM_THIS (BlkIo);
158
159 //
160 // Use services available from IdeBlkIoDevice to test the IDE/ATAPI device
161 //
162 Status = gBS->AllocatePool (
163 EfiBootServicesData,
164 IdeBlkIoDevice->BlkMedia.BlockSize,
165 (VOID **) &BlockBuffer
166 );
167 if (EFI_ERROR (Status)) {
168 return Status;
169 }
170
171 Status = IdeBlkIoDevice->BlkIo.ReadBlocks (
172 &IdeBlkIoDevice->BlkIo,
173 IdeBlkIoDevice->BlkMedia.MediaId,
174 0,
175 IdeBlkIoDevice->BlkMedia.BlockSize,
176 BlockBuffer
177 );
178
179 if (EFI_ERROR (Status)) {
180 *ErrorType = &gEfiCallerIdGuid;
181 *BufferSize = sizeof (IDE_BUS_DIAGNOSTIC_ERROR);
182
183 Status = gBS->AllocatePool (
184 EfiBootServicesData,
185 (UINTN) (*BufferSize),
186 (VOID **) Buffer
187 );
188 if (EFI_ERROR (Status)) {
189 return Status;
190 }
191
192 CopyMem (*Buffer, IDE_BUS_DIAGNOSTIC_ERROR, *BufferSize);
193
194 Status = EFI_DEVICE_ERROR;
195 }
196
197 gBS->FreePool (BlockBuffer);
198
199 return Status;
200 }