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