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