]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkModulePkg/Bus/Pci/IdeBusDxe/DriverDiagnostics.c
Clean up HiiLib.
[mirror_edk2.git] / IntelFrameworkModulePkg / Bus / Pci / IdeBusDxe / DriverDiagnostics.c
CommitLineData
ead42efc 1/** @file\r
2 Copyright (c) 2006, Intel Corporation \r
3 All rights reserved. This program and the accompanying materials \r
4 are licensed and made available under the terms and conditions of the BSD License \r
5 which accompanies this distribution. The full text of the license may be found at \r
6 http://opensource.org/licenses/bsd-license.php \r
7\r
8 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
9 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
10\r
11**/\r
12\r
13\r
14#include "idebus.h"\r
15\r
16#define IDE_BUS_DIAGNOSTIC_ERROR L"PCI IDE/ATAPI Driver Diagnostics Failed"\r
17\r
18//\r
19// EFI Driver Diagnostics Protocol\r
20//\r
dfc48464 21GLOBAL_REMOVE_IF_UNREFERENCED EFI_DRIVER_DIAGNOSTICS_PROTOCOL gIDEBusDriverDiagnostics = {\r
ead42efc 22 IDEBusDriverDiagnosticsRunDiagnostics,\r
23 "eng"\r
24};\r
25\r
dfc48464 26//\r
27// EFI Driver Diagnostics 2 Protocol\r
28//\r
29GLOBAL_REMOVE_IF_UNREFERENCED EFI_DRIVER_DIAGNOSTICS2_PROTOCOL gIDEBusDriverDiagnostics2 = {\r
30 (EFI_DRIVER_DIAGNOSTICS2_RUN_DIAGNOSTICS) IDEBusDriverDiagnosticsRunDiagnostics,\r
31 "en"\r
32};\r
33\r
ead42efc 34/**\r
35 Runs diagnostics on a controller.\r
36\r
37 @param This A pointer to the EFI_DRIVER_DIAGNOSTICS_PROTOCOL\r
38 instance.\r
39 @param ControllerHandle The handle of the controller to run diagnostics on.\r
40 @param ChildHandle The handle of the child controller to run diagnostics on\r
41 This is an optional parameter that may be NULL. It will\r
42 be NULL for device drivers. It will also be NULL for a\r
43 bus drivers that wish to run diagnostics on the bus\r
44 controller. It will not be NULL for a bus driver that\r
45 wishes to run diagnostics on one of its child\r
46 controllers.\r
47 @param DiagnosticType Indicates type of diagnostics to perform on the\r
48 controller specified by ControllerHandle and ChildHandle.\r
49 See "Related Definitions" for the list of supported\r
50 types.\r
51 @param Language A pointer to a three character ISO 639-2 language\r
52 identifier. This is the language in which the optional\r
53 error message should be returned in Buffer, and it must\r
54 match one of the languages specified in\r
55 SupportedLanguages. The number of languages supported by\r
56 a driver is up to the driver writer.\r
57 @param ErrorType A GUID that defines the format of the data returned in\r
58 Buffer.\r
59 @param BufferSize The size, in bytes, of the data returned in Buffer.\r
60 @param Buffer A buffer that contains a Null-terminated Unicode string\r
61 plus some additional data whose format is defined by\r
62 ErrorType. Buffer is allocated by this function with\r
63 AllocatePool(), and it is the caller's responsibility\r
64 to free it with a call to FreePool().\r
65\r
66 @retval EFI_SUCCESS The controller specified by ControllerHandle and\r
67 ChildHandle passed the diagnostic.\r
68 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.\r
69 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r
70 EFI_HANDLE.\r
71 @retval EFI_INVALID_PARAMETER Language is NULL.\r
72 @retval EFI_INVALID_PARAMETER ErrorType is NULL.\r
73 @retval EFI_INVALID_PARAMETER BufferType is NULL.\r
74 @retval EFI_INVALID_PARAMETER Buffer is NULL.\r
75 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
76 running diagnostics for the controller specified\r
77 by ControllerHandle and ChildHandle.\r
78 @retval EFI_UNSUPPORTED The driver specified by This does not support the\r
79 type of diagnostic specified by DiagnosticType.\r
80 @retval EFI_UNSUPPORTED The driver specified by This does not support the\r
81 language specified by Language.\r
82 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to complete\r
83 the diagnostics.\r
84 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to return\r
85 the status information in ErrorType, BufferSize,\r
86 and Buffer.\r
87 @retval EFI_DEVICE_ERROR The controller specified by ControllerHandle and\r
88 ChildHandle did not pass the diagnostic.\r
89\r
90**/\r
91EFI_STATUS\r
92IDEBusDriverDiagnosticsRunDiagnostics (\r
93 IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL *This,\r
94 IN EFI_HANDLE ControllerHandle,\r
95 IN EFI_HANDLE ChildHandle OPTIONAL,\r
96 IN EFI_DRIVER_DIAGNOSTIC_TYPE DiagnosticType,\r
97 IN CHAR8 *Language,\r
98 OUT EFI_GUID **ErrorType,\r
99 OUT UINTN *BufferSize,\r
100 OUT CHAR16 **Buffer\r
101 )\r
102{\r
103 EFI_STATUS Status;\r
104 EFI_PCI_IO_PROTOCOL *PciIo;\r
105 EFI_BLOCK_IO_PROTOCOL *BlkIo;\r
106 IDE_BLK_IO_DEV *IdeBlkIoDevice;\r
107 UINT32 VendorDeviceId;\r
108 VOID *BlockBuffer;\r
dfc48464 109 CHAR8 *SupportedLanguages;\r
110 BOOLEAN Iso639Language;\r
111 BOOLEAN Found;\r
112 UINTN Index;\r
113\r
114 if (Language == NULL ||\r
115 ErrorType == NULL ||\r
116 Buffer == NULL ||\r
117 ControllerHandle == NULL ||\r
118 BufferSize == NULL) {\r
119\r
120 return EFI_INVALID_PARAMETER;\r
121 }\r
122\r
123 SupportedLanguages = This->SupportedLanguages;\r
124 Iso639Language = (BOOLEAN)(This == &gIDEBusDriverDiagnostics);\r
125 //\r
126 // Make sure Language is in the set of Supported Languages\r
127 //\r
128 Found = FALSE;\r
129 while (*SupportedLanguages != 0) {\r
130 if (Iso639Language) {\r
131 if (CompareMem (Language, SupportedLanguages, 3) == 0) {\r
132 Found = TRUE;\r
133 break;\r
134 }\r
135 SupportedLanguages += 3;\r
136 } else {\r
137 for (Index = 0; SupportedLanguages[Index] != 0 && SupportedLanguages[Index] != ';'; Index++);\r
5127b471 138 if ((AsciiStrnCmp(SupportedLanguages, Language, Index) == 0) && (Language[Index] == 0)) {\r
dfc48464 139 Found = TRUE;\r
140 break;\r
141 }\r
142 SupportedLanguages += Index;\r
143 for (; *SupportedLanguages != 0 && *SupportedLanguages == ';'; SupportedLanguages++);\r
144 }\r
145 }\r
146 //\r
147 // If Language is not a member of SupportedLanguages, then return EFI_UNSUPPORTED\r
148 //\r
149 if (!Found) {\r
150 return EFI_UNSUPPORTED;\r
151 }\r
ead42efc 152\r
153 *ErrorType = NULL;\r
154 *BufferSize = 0;\r
155\r
156 if (ChildHandle == NULL) {\r
157 Status = gBS->OpenProtocol (\r
158 ControllerHandle,\r
159 &gEfiCallerIdGuid,\r
160 NULL,\r
161 gIDEBusDriverBinding.DriverBindingHandle,\r
162 ControllerHandle,\r
163 EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
164 );\r
165 if (EFI_ERROR (Status)) {\r
23f642e8 166 return Status;\r
ead42efc 167 }\r
168\r
169 Status = gBS->OpenProtocol (\r
170 ControllerHandle,\r
171 &gEfiPciIoProtocolGuid,\r
172 (VOID **) &PciIo,\r
173 gIDEBusDriverBinding.DriverBindingHandle,\r
174 ControllerHandle,\r
175 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
176 );\r
177 if (EFI_ERROR (Status)) {\r
178 return EFI_DEVICE_ERROR;\r
179 }\r
180\r
181 //\r
182 // Use services of PCI I/O Protocol to test the PCI IDE/ATAPI Controller\r
183 // The following test simply reads the Device ID and Vendor ID.\r
184 // It should never fail. A real test would perform more advanced\r
185 // diagnostics.\r
186 //\r
187\r
188 Status = PciIo->Pci.Read (PciIo, EfiPciIoWidthUint32, 0, 1, &VendorDeviceId);\r
189 if (EFI_ERROR (Status) || VendorDeviceId == 0xffffffff) {\r
190 return EFI_DEVICE_ERROR;\r
191 }\r
192\r
193 return EFI_SUCCESS;\r
194 }\r
195\r
196 Status = gBS->OpenProtocol (\r
197 ChildHandle,\r
198 &gEfiBlockIoProtocolGuid,\r
199 (VOID **) &BlkIo,\r
200 gIDEBusDriverBinding.DriverBindingHandle,\r
201 ChildHandle,\r
202 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
203 );\r
204 if (EFI_ERROR (Status)) {\r
23f642e8 205 return Status;\r
ead42efc 206 }\r
207\r
208 IdeBlkIoDevice = IDE_BLOCK_IO_DEV_FROM_THIS (BlkIo);\r
209\r
210 //\r
211 // Use services available from IdeBlkIoDevice to test the IDE/ATAPI device\r
212 //\r
213 Status = gBS->AllocatePool (\r
214 EfiBootServicesData,\r
215 IdeBlkIoDevice->BlkMedia.BlockSize,\r
216 (VOID **) &BlockBuffer\r
217 );\r
218 if (EFI_ERROR (Status)) {\r
219 return Status;\r
220 }\r
221\r
222 Status = IdeBlkIoDevice->BlkIo.ReadBlocks (\r
223 &IdeBlkIoDevice->BlkIo,\r
224 IdeBlkIoDevice->BlkMedia.MediaId,\r
225 0,\r
226 IdeBlkIoDevice->BlkMedia.BlockSize,\r
227 BlockBuffer\r
228 );\r
229\r
230 if (EFI_ERROR (Status)) {\r
231 *ErrorType = &gEfiCallerIdGuid;\r
232 *BufferSize = sizeof (IDE_BUS_DIAGNOSTIC_ERROR);\r
233\r
234 Status = gBS->AllocatePool (\r
235 EfiBootServicesData,\r
236 (UINTN) (*BufferSize),\r
237 (VOID **) Buffer\r
238 );\r
239 if (EFI_ERROR (Status)) {\r
240 return Status;\r
241 }\r
242\r
243 CopyMem (*Buffer, IDE_BUS_DIAGNOSTIC_ERROR, *BufferSize);\r
244\r
245 Status = EFI_DEVICE_ERROR;\r
246 }\r
247\r
248 gBS->FreePool (BlockBuffer);\r
249\r
250 return Status;\r
251}\r