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