3 Copyright (c) 2006 - 2007, Intel Corporation
4 All rights reserved. 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.
21 #include <Protocol/BlockIo.h>
22 #include <Protocol/ComponentName.h>
23 #include <Protocol/DriverBinding.h>
25 #include "WinNtBlockIo.h"
28 // EFI Driver Diagnostics Functions
32 WinNtBlockIoDriverDiagnosticsRunDiagnostics (
33 IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL
*This
,
34 IN EFI_HANDLE ControllerHandle
,
35 IN EFI_HANDLE ChildHandle OPTIONAL
,
36 IN EFI_DRIVER_DIAGNOSTIC_TYPE DiagnosticType
,
38 OUT EFI_GUID
**ErrorType
,
39 OUT UINTN
*BufferSize
,
44 // EFI Driver Diagnostics Protocol
46 EFI_DRIVER_DIAGNOSTICS_PROTOCOL gWinNtBlockIoDriverDiagnostics
= {
47 WinNtBlockIoDriverDiagnosticsRunDiagnostics
,
53 WinNtBlockIoDriverDiagnosticsRunDiagnostics (
54 IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL
*This
,
55 IN EFI_HANDLE ControllerHandle
,
56 IN EFI_HANDLE ChildHandle OPTIONAL
,
57 IN EFI_DRIVER_DIAGNOSTIC_TYPE DiagnosticType
,
59 OUT EFI_GUID
**ErrorType
,
60 OUT UINTN
*BufferSize
,
66 Runs diagnostics on a controller.
69 This - A pointer to the EFI_DRIVER_DIAGNOSTICS_PROTOCOL instance.
70 ControllerHandle - The handle of the controller to run diagnostics on.
71 ChildHandle - The handle of the child controller to run diagnostics on
72 This is an optional parameter that may be NULL. It will
73 be NULL for device drivers. It will also be NULL for a
74 bus drivers that wish to run diagnostics on the bus
75 controller. It will not be NULL for a bus driver that
76 wishes to run diagnostics on one of its child controllers.
77 DiagnosticType - Indicates type of diagnostics to perform on the controller
78 specified by ControllerHandle and ChildHandle. See
79 "Related Definitions" for the list of supported types.
80 Language - A pointer to a three character ISO 639-2 language
81 identifier. This is the language in which the optional
82 error message should be returned in Buffer, and it must
83 match one of the languages specified in SupportedLanguages.
84 The number of languages supported by a driver is up to
86 ErrorType - A GUID that defines the format of the data returned in
88 BufferSize - The size, in bytes, of the data returned in Buffer.
89 Buffer - A buffer that contains a Null-terminated Unicode string
90 plus some additional data whose format is defined by
91 ErrorType. Buffer is allocated by this function with
92 AllocatePool(), and it is the caller's responsibility
93 to free it with a call to FreePool().
96 EFI_SUCCESS - The controller specified by ControllerHandle and
97 ChildHandle passed the diagnostic.
98 EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.
99 EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid
101 EFI_INVALID_PARAMETER - Language is NULL.
102 EFI_INVALID_PARAMETER - ErrorType is NULL.
103 EFI_INVALID_PARAMETER - BufferType is NULL.
104 EFI_INVALID_PARAMETER - Buffer is NULL.
105 EFI_UNSUPPORTED - The driver specified by This does not support
106 running diagnostics for the controller specified
107 by ControllerHandle and ChildHandle.
108 EFI_UNSUPPORTED - The driver specified by This does not support the
109 type of diagnostic specified by DiagnosticType.
110 EFI_UNSUPPORTED - The driver specified by This does not support the
111 language specified by Language.
112 EFI_OUT_OF_RESOURCES - There are not enough resources available to complete
114 EFI_OUT_OF_RESOURCES - There are not enough resources available to return
115 the status information in ErrorType, BufferSize,
117 EFI_DEVICE_ERROR - The controller specified by ControllerHandle and
118 ChildHandle did not pass the diagnostic.
123 EFI_BLOCK_IO_PROTOCOL
*BlockIo
;
124 CHAR8
*SupportedLanguage
;
126 if (Language
== NULL
||
129 ControllerHandle
== NULL
||
130 BufferSize
== NULL
) {
132 return EFI_INVALID_PARAMETER
;
135 SupportedLanguage
= This
->SupportedLanguages
;
137 Status
= EFI_UNSUPPORTED
;
138 while (*SupportedLanguage
!= 0) {
139 if (AsciiStrnCmp (Language
, SupportedLanguage
, 3) == 0) {
140 Status
= EFI_SUCCESS
;
144 SupportedLanguage
+= 3;
147 if (EFI_ERROR (Status
)) {
148 return EFI_UNSUPPORTED
;
153 if (DiagnosticType
!= EfiDriverDiagnosticTypeStandard
) {
154 *ErrorType
= &gEfiBlockIoProtocolGuid
;
156 Buffer
= AllocatePool ((UINTN
) (*BufferSize
));
157 CopyMem (*Buffer
, L
"Windows Block I/O Driver Diagnostics Failed\n", *BufferSize
);
158 return EFI_DEVICE_ERROR
;
162 // Validate controller handle
164 Status
= gBS
->OpenProtocol (
166 &gEfiWinNtIoProtocolGuid
,
168 gWinNtBlockIoDriverBinding
.DriverBindingHandle
,
170 EFI_OPEN_PROTOCOL_BY_DRIVER
173 if (!EFI_ERROR (Status
)) {
176 &gEfiWinNtIoProtocolGuid
,
177 gWinNtBlockIoDriverBinding
.DriverBindingHandle
,
181 return EFI_UNSUPPORTED
;
184 if (Status
== EFI_UNSUPPORTED
) {
186 } else if (Status
!= EFI_ALREADY_STARTED
) {
187 return EFI_INVALID_PARAMETER
;