3 Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
20 #include "EmuBlockIo.h"
23 // EFI Driver Diagnostics Functions
27 EmuBlockIoDriverDiagnosticsRunDiagnostics (
28 IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL
*This
,
29 IN EFI_HANDLE ControllerHandle
,
30 IN EFI_HANDLE ChildHandle OPTIONAL
,
31 IN EFI_DRIVER_DIAGNOSTIC_TYPE DiagnosticType
,
33 OUT EFI_GUID
**ErrorType
,
34 OUT UINTN
*BufferSize
,
39 // EFI Driver Diagnostics Protocol
41 EFI_DRIVER_DIAGNOSTICS_PROTOCOL gEmuBlockIoDriverDiagnostics
= {
42 EmuBlockIoDriverDiagnosticsRunDiagnostics
,
47 // EFI Driver Diagnostics 2 Protocol
49 GLOBAL_REMOVE_IF_UNREFERENCED EFI_DRIVER_DIAGNOSTICS2_PROTOCOL gEmuBlockIoDriverDiagnostics2
= {
50 (EFI_DRIVER_DIAGNOSTICS2_RUN_DIAGNOSTICS
) EmuBlockIoDriverDiagnosticsRunDiagnostics
,
56 EmuBlockIoDriverDiagnosticsRunDiagnostics (
57 IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL
*This
,
58 IN EFI_HANDLE ControllerHandle
,
59 IN EFI_HANDLE ChildHandle OPTIONAL
,
60 IN EFI_DRIVER_DIAGNOSTIC_TYPE DiagnosticType
,
62 OUT EFI_GUID
**ErrorType
,
63 OUT UINTN
*BufferSize
,
69 Runs diagnostics on a controller.
72 This - A pointer to the EFI_DRIVER_DIAGNOSTICS_PROTOCOL instance.
73 ControllerHandle - The handle of the controller to run diagnostics on.
74 ChildHandle - The handle of the child controller to run diagnostics on
75 This is an optional parameter that may be NULL. It will
76 be NULL for device drivers. It will also be NULL for a
77 bus drivers that wish to run diagnostics on the bus
78 controller. It will not be NULL for a bus driver that
79 wishes to run diagnostics on one of its child controllers.
80 DiagnosticType - Indicates type of diagnostics to perform on the controller
81 specified by ControllerHandle and ChildHandle. See
82 "Related Definitions" for the list of supported types.
83 Language - A pointer to a three character ISO 639-2 language
84 identifier or a Null-terminated ASCII string array indicating
85 the language. This is the language in which the optional
86 error message should be returned in Buffer, and it must
87 match one of the languages specified in SupportedLanguages.
88 The number of languages supported by a driver is up to
90 ErrorType - A GUID that defines the format of the data returned in
92 BufferSize - The size, in bytes, of the data returned in Buffer.
93 Buffer - A buffer that contains a Null-terminated Unicode string
94 plus some additional data whose format is defined by
95 ErrorType. Buffer is allocated by this function with
96 AllocatePool(), and it is the caller's responsibility
97 to free it with a call to FreePool().
100 EFI_SUCCESS - The controller specified by ControllerHandle and
101 ChildHandle passed the diagnostic.
102 EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.
103 EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid
105 EFI_INVALID_PARAMETER - Language is NULL.
106 EFI_INVALID_PARAMETER - ErrorType is NULL.
107 EFI_INVALID_PARAMETER - BufferType is NULL.
108 EFI_INVALID_PARAMETER - Buffer is NULL.
109 EFI_UNSUPPORTED - The driver specified by This does not support
110 running diagnostics for the controller specified
111 by ControllerHandle and ChildHandle.
112 EFI_UNSUPPORTED - The driver specified by This does not support the
113 type of diagnostic specified by DiagnosticType.
114 EFI_UNSUPPORTED - The driver specified by This does not support the
115 language specified by Language.
116 EFI_OUT_OF_RESOURCES - There are not enough resources available to complete
118 EFI_OUT_OF_RESOURCES - There are not enough resources available to return
119 the status information in ErrorType, BufferSize,
121 EFI_DEVICE_ERROR - The controller specified by ControllerHandle and
122 ChildHandle did not pass the diagnostic.
127 EFI_BLOCK_IO_PROTOCOL
*BlockIo
;
128 CHAR8
*SupportedLanguages
;
129 BOOLEAN Iso639Language
;
133 if (Language
== NULL
||
136 ControllerHandle
== NULL
||
137 BufferSize
== NULL
) {
139 return EFI_INVALID_PARAMETER
;
142 SupportedLanguages
= This
->SupportedLanguages
;
143 Iso639Language
= (BOOLEAN
)(This
== &gEmuBlockIoDriverDiagnostics
);
145 // Make sure Language is in the set of Supported Languages
148 while (*SupportedLanguages
!= 0) {
149 if (Iso639Language
) {
150 if (CompareMem (Language
, SupportedLanguages
, 3) == 0) {
154 SupportedLanguages
+= 3;
156 for (Index
= 0; SupportedLanguages
[Index
] != 0 && SupportedLanguages
[Index
] != ';'; Index
++);
157 if ((AsciiStrnCmp(SupportedLanguages
, Language
, Index
) == 0) && (Language
[Index
] == 0)) {
161 SupportedLanguages
+= Index
;
162 for (; *SupportedLanguages
!= 0 && *SupportedLanguages
== ';'; SupportedLanguages
++);
166 // If Language is not a member of SupportedLanguages, then return EFI_UNSUPPORTED
169 return EFI_UNSUPPORTED
;
174 if (DiagnosticType
!= EfiDriverDiagnosticTypeStandard
) {
175 *ErrorType
= &gEfiBlockIoProtocolGuid
;
177 Buffer
= AllocatePool ((UINTN
) (*BufferSize
));
178 CopyMem (*Buffer
, L
"Windows Block I/O Driver Diagnostics Failed\n", *BufferSize
);
179 return EFI_DEVICE_ERROR
;
183 // This is a device driver, so ChildHandle must be NULL.
185 if (ChildHandle
!= NULL
) {
186 return EFI_UNSUPPORTED
;
190 // Validate controller handle
192 Status
= gBS
->OpenProtocol (
194 &gEmuIoThunkProtocolGuid
,
196 gEmuBlockIoDriverBinding
.DriverBindingHandle
,
198 EFI_OPEN_PROTOCOL_BY_DRIVER
201 if (!EFI_ERROR (Status
)) {
204 &gEmuIoThunkProtocolGuid
,
205 gEmuBlockIoDriverBinding
.DriverBindingHandle
,
209 return EFI_UNSUPPORTED
;
212 if (Status
== EFI_UNSUPPORTED
) {
214 } else if (Status
!= EFI_ALREADY_STARTED
) {
215 return EFI_INVALID_PARAMETER
;