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