]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkModulePkg/Bus/Pci/IdeBusDxe/DriverDiagnostics.c
Fix some inconsistencies in EFIAPI usage.
[mirror_edk2.git] / IntelFrameworkModulePkg / Bus / Pci / IdeBusDxe / DriverDiagnostics.c
CommitLineData
ead42efc 1/** @file\r
03417d8d 2 Copyright (c) 2006 - 2008, Intel Corporation \r
ead42efc 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
03417d8d 14#include "IdeBus.h"\r
ead42efc 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
6ba0bc7c 92EFIAPI\r
ead42efc 93IDEBusDriverDiagnosticsRunDiagnostics (\r
94 IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL *This,\r
95 IN EFI_HANDLE ControllerHandle,\r
96 IN EFI_HANDLE ChildHandle OPTIONAL,\r
97 IN EFI_DRIVER_DIAGNOSTIC_TYPE DiagnosticType,\r
98 IN CHAR8 *Language,\r
99 OUT EFI_GUID **ErrorType,\r
100 OUT UINTN *BufferSize,\r
101 OUT CHAR16 **Buffer\r
102 )\r
103{\r
104 EFI_STATUS Status;\r
105 EFI_PCI_IO_PROTOCOL *PciIo;\r
106 EFI_BLOCK_IO_PROTOCOL *BlkIo;\r
107 IDE_BLK_IO_DEV *IdeBlkIoDevice;\r
108 UINT32 VendorDeviceId;\r
109 VOID *BlockBuffer;\r
dfc48464 110 CHAR8 *SupportedLanguages;\r
111 BOOLEAN Iso639Language;\r
112 BOOLEAN Found;\r
113 UINTN Index;\r
114\r
115 if (Language == NULL ||\r
116 ErrorType == NULL ||\r
117 Buffer == NULL ||\r
118 ControllerHandle == NULL ||\r
119 BufferSize == NULL) {\r
120\r
121 return EFI_INVALID_PARAMETER;\r
122 }\r
123\r
124 SupportedLanguages = This->SupportedLanguages;\r
125 Iso639Language = (BOOLEAN)(This == &gIDEBusDriverDiagnostics);\r
126 //\r
127 // Make sure Language is in the set of Supported Languages\r
128 //\r
129 Found = FALSE;\r
130 while (*SupportedLanguages != 0) {\r
131 if (Iso639Language) {\r
132 if (CompareMem (Language, SupportedLanguages, 3) == 0) {\r
133 Found = TRUE;\r
134 break;\r
135 }\r
136 SupportedLanguages += 3;\r
137 } else {\r
138 for (Index = 0; SupportedLanguages[Index] != 0 && SupportedLanguages[Index] != ';'; Index++);\r
5127b471 139 if ((AsciiStrnCmp(SupportedLanguages, Language, Index) == 0) && (Language[Index] == 0)) {\r
dfc48464 140 Found = TRUE;\r
141 break;\r
142 }\r
143 SupportedLanguages += Index;\r
144 for (; *SupportedLanguages != 0 && *SupportedLanguages == ';'; SupportedLanguages++);\r
145 }\r
146 }\r
147 //\r
148 // If Language is not a member of SupportedLanguages, then return EFI_UNSUPPORTED\r
149 //\r
150 if (!Found) {\r
151 return EFI_UNSUPPORTED;\r
152 }\r
ead42efc 153\r
154 *ErrorType = NULL;\r
155 *BufferSize = 0;\r
156\r
157 if (ChildHandle == NULL) {\r
158 Status = gBS->OpenProtocol (\r
159 ControllerHandle,\r
160 &gEfiCallerIdGuid,\r
161 NULL,\r
162 gIDEBusDriverBinding.DriverBindingHandle,\r
163 ControllerHandle,\r
164 EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
165 );\r
166 if (EFI_ERROR (Status)) {\r
23f642e8 167 return Status;\r
ead42efc 168 }\r
169\r
170 Status = gBS->OpenProtocol (\r
171 ControllerHandle,\r
172 &gEfiPciIoProtocolGuid,\r
173 (VOID **) &PciIo,\r
174 gIDEBusDriverBinding.DriverBindingHandle,\r
175 ControllerHandle,\r
176 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
177 );\r
178 if (EFI_ERROR (Status)) {\r
179 return EFI_DEVICE_ERROR;\r
180 }\r
181\r
182 //\r
183 // Use services of PCI I/O Protocol to test the PCI IDE/ATAPI Controller\r
184 // The following test simply reads the Device ID and Vendor ID.\r
185 // It should never fail. A real test would perform more advanced\r
186 // diagnostics.\r
187 //\r
188\r
189 Status = PciIo->Pci.Read (PciIo, EfiPciIoWidthUint32, 0, 1, &VendorDeviceId);\r
190 if (EFI_ERROR (Status) || VendorDeviceId == 0xffffffff) {\r
191 return EFI_DEVICE_ERROR;\r
192 }\r
193\r
194 return EFI_SUCCESS;\r
195 }\r
196\r
197 Status = gBS->OpenProtocol (\r
198 ChildHandle,\r
199 &gEfiBlockIoProtocolGuid,\r
200 (VOID **) &BlkIo,\r
201 gIDEBusDriverBinding.DriverBindingHandle,\r
202 ChildHandle,\r
203 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
204 );\r
205 if (EFI_ERROR (Status)) {\r
23f642e8 206 return Status;\r
ead42efc 207 }\r
208\r
209 IdeBlkIoDevice = IDE_BLOCK_IO_DEV_FROM_THIS (BlkIo);\r
210\r
211 //\r
212 // Use services available from IdeBlkIoDevice to test the IDE/ATAPI device\r
213 //\r
214 Status = gBS->AllocatePool (\r
215 EfiBootServicesData,\r
216 IdeBlkIoDevice->BlkMedia.BlockSize,\r
217 (VOID **) &BlockBuffer\r
218 );\r
219 if (EFI_ERROR (Status)) {\r
220 return Status;\r
221 }\r
222\r
223 Status = IdeBlkIoDevice->BlkIo.ReadBlocks (\r
224 &IdeBlkIoDevice->BlkIo,\r
225 IdeBlkIoDevice->BlkMedia.MediaId,\r
226 0,\r
227 IdeBlkIoDevice->BlkMedia.BlockSize,\r
228 BlockBuffer\r
229 );\r
230\r
231 if (EFI_ERROR (Status)) {\r
232 *ErrorType = &gEfiCallerIdGuid;\r
233 *BufferSize = sizeof (IDE_BUS_DIAGNOSTIC_ERROR);\r
234\r
235 Status = gBS->AllocatePool (\r
236 EfiBootServicesData,\r
237 (UINTN) (*BufferSize),\r
238 (VOID **) Buffer\r
239 );\r
240 if (EFI_ERROR (Status)) {\r
241 return Status;\r
242 }\r
243\r
244 CopyMem (*Buffer, IDE_BUS_DIAGNOSTIC_ERROR, *BufferSize);\r
245\r
246 Status = EFI_DEVICE_ERROR;\r
247 }\r
248\r
249 gBS->FreePool (BlockBuffer);\r
250\r
251 return Status;\r
252}\r