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