]>
Commit | Line | Data |
---|---|---|
d59326d3 | 1 | /**@file\r |
2 | \r | |
3 | Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved.<BR>\r | |
d18d8a1d | 4 | This program and the accompanying materials\r |
5 | are licensed and made available under the terms and conditions of the BSD License\r | |
6 | which accompanies this distribution. The full text of the license may be found at\r | |
7 | http://opensource.org/licenses/bsd-license.php\r | |
8 | \r | |
9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
d59326d3 | 11 | \r |
12 | Module Name:\r | |
13 | \r | |
14 | DriverDiagnostics.c\r | |
15 | \r | |
16 | Abstract:\r | |
17 | \r | |
18 | **/\r | |
19 | \r | |
20 | #include "EmuBlockIo.h"\r | |
21 | \r | |
22 | //\r | |
23 | // EFI Driver Diagnostics Functions\r | |
24 | //\r | |
25 | EFI_STATUS\r | |
26 | EFIAPI\r | |
27 | EmuBlockIoDriverDiagnosticsRunDiagnostics (\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 | |
41 | EFI_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 | |
49 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_DRIVER_DIAGNOSTICS2_PROTOCOL gEmuBlockIoDriverDiagnostics2 = {\r | |
50 | (EFI_DRIVER_DIAGNOSTICS2_RUN_DIAGNOSTICS) EmuBlockIoDriverDiagnosticsRunDiagnostics,\r | |
51 | "en"\r | |
52 | };\r | |
53 | \r | |
54 | EFI_STATUS\r | |
55 | EFIAPI\r | |
56 | EmuBlockIoDriverDiagnosticsRunDiagnostics (\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 | |
d18d8a1d | 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 | |
d59326d3 | 79 | wishes to run diagnostics on one of its child controllers.\r |
d18d8a1d | 80 | DiagnosticType - Indicates type of diagnostics to perform on the controller\r |
81 | specified by ControllerHandle and ChildHandle. See\r | |
d59326d3 | 82 | "Related Definitions" for the list of supported types.\r |
d18d8a1d | 83 | Language - A pointer to a three character ISO 639-2 language\r |
d59326d3 | 84 | identifier or a Null-terminated ASCII string array indicating\r |
85 | the language. This is the language in which the optional\r | |
d18d8a1d | 86 | error message should be returned in Buffer, and it must\r |
d59326d3 | 87 | match one of the languages specified in SupportedLanguages.\r |
d18d8a1d | 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 | |
d59326d3 | 98 | \r |
99 | Returns:\r | |
d18d8a1d | 100 | EFI_SUCCESS - The controller specified by ControllerHandle and\r |
d59326d3 | 101 | ChildHandle passed the diagnostic.\r |
102 | EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.\r | |
d18d8a1d | 103 | EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid\r |
d59326d3 | 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 | |
d18d8a1d | 109 | EFI_UNSUPPORTED - The driver specified by This does not support\r |
110 | running diagnostics for the controller specified\r | |
d59326d3 | 111 | by ControllerHandle and ChildHandle.\r |
d18d8a1d | 112 | EFI_UNSUPPORTED - The driver specified by This does not support the\r |
d59326d3 | 113 | type of diagnostic specified by DiagnosticType.\r |
d18d8a1d | 114 | EFI_UNSUPPORTED - The driver specified by This does not support the\r |
d59326d3 | 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 | |
d18d8a1d | 119 | the status information in ErrorType, BufferSize,\r |
d59326d3 | 120 | and Buffer.\r |
d18d8a1d | 121 | EFI_DEVICE_ERROR - The controller specified by ControllerHandle and\r |
d59326d3 | 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 |