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