3 Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved.<BR>
4 SPDX-License-Identifier: BSD-2-Clause-Patent
14 #include "EmuBlockIo.h"
17 // EFI Driver Diagnostics Functions
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
,
27 OUT EFI_GUID
**ErrorType
,
28 OUT UINTN
*BufferSize
,
33 // EFI Driver Diagnostics Protocol
35 EFI_DRIVER_DIAGNOSTICS_PROTOCOL gEmuBlockIoDriverDiagnostics
= {
36 EmuBlockIoDriverDiagnosticsRunDiagnostics
,
41 // EFI Driver Diagnostics 2 Protocol
43 GLOBAL_REMOVE_IF_UNREFERENCED EFI_DRIVER_DIAGNOSTICS2_PROTOCOL gEmuBlockIoDriverDiagnostics2
= {
44 (EFI_DRIVER_DIAGNOSTICS2_RUN_DIAGNOSTICS
) EmuBlockIoDriverDiagnosticsRunDiagnostics
,
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
,
56 OUT EFI_GUID
**ErrorType
,
57 OUT UINTN
*BufferSize
,
63 Runs diagnostics on a controller.
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
84 ErrorType - A GUID that defines the format of the data returned in
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().
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
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
112 EFI_OUT_OF_RESOURCES - There are not enough resources available to return
113 the status information in ErrorType, BufferSize,
115 EFI_DEVICE_ERROR - The controller specified by ControllerHandle and
116 ChildHandle did not pass the diagnostic.
121 EFI_BLOCK_IO_PROTOCOL
*BlockIo
;
122 CHAR8
*SupportedLanguages
;
123 BOOLEAN Iso639Language
;
127 if (Language
== NULL
||
130 ControllerHandle
== NULL
||
131 BufferSize
== NULL
) {
133 return EFI_INVALID_PARAMETER
;
136 SupportedLanguages
= This
->SupportedLanguages
;
137 Iso639Language
= (BOOLEAN
)(This
== &gEmuBlockIoDriverDiagnostics
);
139 // Make sure Language is in the set of Supported Languages
142 while (*SupportedLanguages
!= 0) {
143 if (Iso639Language
) {
144 if (CompareMem (Language
, SupportedLanguages
, 3) == 0) {
148 SupportedLanguages
+= 3;
150 for (Index
= 0; SupportedLanguages
[Index
] != 0 && SupportedLanguages
[Index
] != ';'; Index
++);
151 if ((AsciiStrnCmp(SupportedLanguages
, Language
, Index
) == 0) && (Language
[Index
] == 0)) {
155 SupportedLanguages
+= Index
;
156 for (; *SupportedLanguages
!= 0 && *SupportedLanguages
== ';'; SupportedLanguages
++);
160 // If Language is not a member of SupportedLanguages, then return EFI_UNSUPPORTED
163 return EFI_UNSUPPORTED
;
168 if (DiagnosticType
!= EfiDriverDiagnosticTypeStandard
) {
169 *ErrorType
= &gEfiBlockIoProtocolGuid
;
171 Buffer
= AllocatePool ((UINTN
) (*BufferSize
));
172 CopyMem (*Buffer
, L
"Windows Block I/O Driver Diagnostics Failed\n", *BufferSize
);
173 return EFI_DEVICE_ERROR
;
177 // This is a device driver, so ChildHandle must be NULL.
179 if (ChildHandle
!= NULL
) {
180 return EFI_UNSUPPORTED
;
184 // Validate controller handle
186 Status
= gBS
->OpenProtocol (
188 &gEmuIoThunkProtocolGuid
,
190 gEmuBlockIoDriverBinding
.DriverBindingHandle
,
192 EFI_OPEN_PROTOCOL_BY_DRIVER
195 if (!EFI_ERROR (Status
)) {
198 &gEmuIoThunkProtocolGuid
,
199 gEmuBlockIoDriverBinding
.DriverBindingHandle
,
203 return EFI_UNSUPPORTED
;
206 if (Status
== EFI_UNSUPPORTED
) {
208 } else if (Status
!= EFI_ALREADY_STARTED
) {
209 return EFI_INVALID_PARAMETER
;