]> git.proxmox.com Git - mirror_edk2.git/blame - InOsEmuPkg/EmuBlockIoDxe/DriverDiagnostics.c
Clarify the requirements for the Destination parameter of UnicodeStrToAsciiStr.
[mirror_edk2.git] / InOsEmuPkg / EmuBlockIoDxe / DriverDiagnostics.c
CommitLineData
d59326d3 1/**@file\r
2\r
3Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved.<BR>\r
4This program and the accompanying materials \r
5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11\r
12Module Name:\r
13\r
14 DriverDiagnostics.c\r
15\r
16Abstract:\r
17\r
18**/\r
19\r
20#include "EmuBlockIo.h"\r
21\r
22//\r
23// EFI Driver Diagnostics Functions\r
24//\r
25EFI_STATUS\r
26EFIAPI\r
27EmuBlockIoDriverDiagnosticsRunDiagnostics (\r
28 IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL *This,\r
29 IN EFI_HANDLE ControllerHandle,\r
30 IN EFI_HANDLE ChildHandle OPTIONAL,\r
31 IN EFI_DRIVER_DIAGNOSTIC_TYPE DiagnosticType,\r
32 IN CHAR8 *Language,\r
33 OUT EFI_GUID **ErrorType,\r
34 OUT UINTN *BufferSize,\r
35 OUT CHAR16 **Buffer\r
36 );\r
37\r
38//\r
39// EFI Driver Diagnostics Protocol\r
40//\r
41EFI_DRIVER_DIAGNOSTICS_PROTOCOL gEmuBlockIoDriverDiagnostics = {\r
42 EmuBlockIoDriverDiagnosticsRunDiagnostics,\r
43 "eng"\r
44};\r
45\r
46//\r
47// EFI Driver Diagnostics 2 Protocol\r
48//\r
49GLOBAL_REMOVE_IF_UNREFERENCED EFI_DRIVER_DIAGNOSTICS2_PROTOCOL gEmuBlockIoDriverDiagnostics2 = {\r
50 (EFI_DRIVER_DIAGNOSTICS2_RUN_DIAGNOSTICS) EmuBlockIoDriverDiagnosticsRunDiagnostics,\r
51 "en"\r
52};\r
53\r
54EFI_STATUS\r
55EFIAPI\r
56EmuBlockIoDriverDiagnosticsRunDiagnostics (\r
57 IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL *This,\r
58 IN EFI_HANDLE ControllerHandle,\r
59 IN EFI_HANDLE ChildHandle OPTIONAL,\r
60 IN EFI_DRIVER_DIAGNOSTIC_TYPE DiagnosticType,\r
61 IN CHAR8 *Language,\r
62 OUT EFI_GUID **ErrorType,\r
63 OUT UINTN *BufferSize,\r
64 OUT CHAR16 **Buffer\r
65 )\r
66/*++\r
67\r
68 Routine Description:\r
69 Runs diagnostics on a controller.\r
70\r
71 Arguments:\r
72 This - A pointer to the EFI_DRIVER_DIAGNOSTICS_PROTOCOL instance.\r
73 ControllerHandle - The handle of the controller to run diagnostics on.\r
74 ChildHandle - The handle of the child controller to run diagnostics on \r
75 This is an optional parameter that may be NULL. It will \r
76 be NULL for device drivers. It will also be NULL for a \r
77 bus drivers that wish to run diagnostics on the bus \r
78 controller. It will not be NULL for a bus driver that \r
79 wishes to run diagnostics on one of its child controllers.\r
80 DiagnosticType - Indicates type of diagnostics to perform on the controller \r
81 specified by ControllerHandle and ChildHandle. See \r
82 "Related Definitions" for the list of supported types.\r
83 Language - A pointer to a three character ISO 639-2 language \r
84 identifier or a Null-terminated ASCII string array indicating\r
85 the language. This is the language in which the optional\r
86 error message should be returned in Buffer, and it must \r
87 match one of the languages specified in SupportedLanguages.\r
88 The number of languages supported by a driver is up to \r
89 the driver writer. \r
90 ErrorType - A GUID that defines the format of the data returned in \r
91 Buffer. \r
92 BufferSize - The size, in bytes, of the data returned in Buffer. \r
93 Buffer - A buffer that contains a Null-terminated Unicode string \r
94 plus some additional data whose format is defined by \r
95 ErrorType. Buffer is allocated by this function with \r
96 AllocatePool(), and it is the caller's responsibility \r
97 to free it with a call to FreePool(). \r
98\r
99 Returns:\r
100 EFI_SUCCESS - The controller specified by ControllerHandle and \r
101 ChildHandle passed the diagnostic.\r
102 EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.\r
103 EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid \r
104 EFI_HANDLE.\r
105 EFI_INVALID_PARAMETER - Language is NULL.\r
106 EFI_INVALID_PARAMETER - ErrorType is NULL.\r
107 EFI_INVALID_PARAMETER - BufferType is NULL.\r
108 EFI_INVALID_PARAMETER - Buffer is NULL.\r
109 EFI_UNSUPPORTED - The driver specified by This does not support \r
110 running diagnostics for the controller specified \r
111 by ControllerHandle and ChildHandle.\r
112 EFI_UNSUPPORTED - The driver specified by This does not support the \r
113 type of diagnostic specified by DiagnosticType.\r
114 EFI_UNSUPPORTED - The driver specified by This does not support the \r
115 language specified by Language.\r
116 EFI_OUT_OF_RESOURCES - There are not enough resources available to complete\r
117 the diagnostics.\r
118 EFI_OUT_OF_RESOURCES - There are not enough resources available to return\r
119 the status information in ErrorType, BufferSize, \r
120 and Buffer.\r
121 EFI_DEVICE_ERROR - The controller specified by ControllerHandle and \r
122 ChildHandle did not pass the diagnostic.\r
123\r
124--*/\r
125{\r
126 EFI_STATUS Status;\r
127 EFI_BLOCK_IO_PROTOCOL *BlockIo;\r
128 CHAR8 *SupportedLanguages;\r
129 BOOLEAN Iso639Language;\r
130 BOOLEAN Found;\r
131 UINTN Index;\r
132\r
133 if (Language == NULL ||\r
134 ErrorType == NULL ||\r
135 Buffer == NULL ||\r
136 ControllerHandle == NULL ||\r
137 BufferSize == NULL) {\r
138\r
139 return EFI_INVALID_PARAMETER;\r
140 }\r
141\r
142 SupportedLanguages = This->SupportedLanguages;\r
143 Iso639Language = (BOOLEAN)(This == &gEmuBlockIoDriverDiagnostics);\r
144 //\r
145 // Make sure Language is in the set of Supported Languages\r
146 //\r
147 Found = FALSE;\r
148 while (*SupportedLanguages != 0) {\r
149 if (Iso639Language) {\r
150 if (CompareMem (Language, SupportedLanguages, 3) == 0) {\r
151 Found = TRUE;\r
152 break;\r
153 }\r
154 SupportedLanguages += 3;\r
155 } else {\r
156 for (Index = 0; SupportedLanguages[Index] != 0 && SupportedLanguages[Index] != ';'; Index++);\r
157 if ((AsciiStrnCmp(SupportedLanguages, Language, Index) == 0) && (Language[Index] == 0)) {\r
158 Found = TRUE;\r
159 break;\r
160 }\r
161 SupportedLanguages += Index;\r
162 for (; *SupportedLanguages != 0 && *SupportedLanguages == ';'; SupportedLanguages++);\r
163 }\r
164 }\r
165 //\r
166 // If Language is not a member of SupportedLanguages, then return EFI_UNSUPPORTED\r
167 //\r
168 if (!Found) {\r
169 return EFI_UNSUPPORTED;\r
170 }\r
171\r
172 *ErrorType = NULL;\r
173 *BufferSize = 0;\r
174 if (DiagnosticType != EfiDriverDiagnosticTypeStandard) {\r
175 *ErrorType = &gEfiBlockIoProtocolGuid;\r
176 *BufferSize = 0x60;\r
177 Buffer = AllocatePool ((UINTN) (*BufferSize));\r
178 CopyMem (*Buffer, L"Windows Block I/O Driver Diagnostics Failed\n", *BufferSize);\r
179 return EFI_DEVICE_ERROR;\r
180 }\r
181\r
182 //\r
183 // This is a device driver, so ChildHandle must be NULL.\r
184 //\r
185 if (ChildHandle != NULL) {\r
186 return EFI_UNSUPPORTED;\r
187 }\r
188\r
189 //\r
190 // Validate controller handle\r
191 //\r
192 Status = gBS->OpenProtocol (\r
193 ControllerHandle,\r
194 &gEmuIoThunkProtocolGuid,\r
195 (VOID **)&BlockIo,\r
196 gEmuBlockIoDriverBinding.DriverBindingHandle,\r
197 ControllerHandle,\r
198 EFI_OPEN_PROTOCOL_BY_DRIVER\r
199 );\r
200\r
201 if (!EFI_ERROR (Status)) {\r
202 gBS->CloseProtocol (\r
203 ControllerHandle,\r
204 &gEmuIoThunkProtocolGuid,\r
205 gEmuBlockIoDriverBinding.DriverBindingHandle,\r
206 ControllerHandle\r
207 );\r
208\r
209 return EFI_UNSUPPORTED;\r
210 }\r
211\r
212 if (Status == EFI_UNSUPPORTED) {\r
213 return Status;\r
214 } else if (Status != EFI_ALREADY_STARTED) {\r
215 return EFI_INVALID_PARAMETER;\r
216 }\r
217\r
218 return EFI_SUCCESS;\r
219}\r