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