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