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