3 Copyright (c) 2004 - 2005, 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.
20 #include "UnixBlockIo.h"
23 // EFI Driver Diagnostics Functions
27 UnixBlockIoDriverDiagnosticsRunDiagnostics (
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 gUnixBlockIoDriverDiagnostics
= {
42 UnixBlockIoDriverDiagnosticsRunDiagnostics
,
48 UnixBlockIoDriverDiagnosticsRunDiagnostics (
49 IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL
*This
,
50 IN EFI_HANDLE ControllerHandle
,
51 IN EFI_HANDLE ChildHandle OPTIONAL
,
52 IN EFI_DRIVER_DIAGNOSTIC_TYPE DiagnosticType
,
54 OUT EFI_GUID
**ErrorType
,
55 OUT UINTN
*BufferSize
,
61 Runs diagnostics on a controller.
64 This - A pointer to the EFI_DRIVER_DIAGNOSTICS_PROTOCOL instance.
65 ControllerHandle - The handle of the controller to run diagnostics on.
66 ChildHandle - The handle of the child controller to run diagnostics on
67 This is an optional parameter that may be NULL. It will
68 be NULL for device drivers. It will also be NULL for a
69 bus drivers that wish to run diagnostics on the bus
70 controller. It will not be NULL for a bus driver that
71 wishes to run diagnostics on one of its child controllers.
72 DiagnosticType - Indicates type of diagnostics to perform on the controller
73 specified by ControllerHandle and ChildHandle. See
74 "Related Definitions" for the list of supported types.
75 Language - A pointer to a three character ISO 639-2 language
76 identifier. This is the language in which the optional
77 error message should be returned in Buffer, and it must
78 match one of the languages specified in SupportedLanguages.
79 The number of languages supported by a driver is up to
81 ErrorType - A GUID that defines the format of the data returned in
83 BufferSize - The size, in bytes, of the data returned in Buffer.
84 Buffer - A buffer that contains a Null-terminated Unicode string
85 plus some additional data whose format is defined by
86 ErrorType. Buffer is allocated by this function with
87 AllocatePool(), and it is the caller's responsibility
88 to free it with a call to FreePool().
91 EFI_SUCCESS - The controller specified by ControllerHandle and
92 ChildHandle passed the diagnostic.
93 EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.
94 EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid
96 EFI_INVALID_PARAMETER - Language is NULL.
97 EFI_INVALID_PARAMETER - ErrorType is NULL.
98 EFI_INVALID_PARAMETER - BufferType is NULL.
99 EFI_INVALID_PARAMETER - Buffer is NULL.
100 EFI_UNSUPPORTED - The driver specified by This does not support
101 running diagnostics for the controller specified
102 by ControllerHandle and ChildHandle.
103 EFI_UNSUPPORTED - The driver specified by This does not support the
104 type of diagnostic specified by DiagnosticType.
105 EFI_UNSUPPORTED - The driver specified by This does not support the
106 language specified by Language.
107 EFI_OUT_OF_RESOURCES - There are not enough resources available to complete
109 EFI_OUT_OF_RESOURCES - There are not enough resources available to return
110 the status information in ErrorType, BufferSize,
112 EFI_DEVICE_ERROR - The controller specified by ControllerHandle and
113 ChildHandle did not pass the diagnostic.
118 EFI_BLOCK_IO_PROTOCOL
*BlockIo
;
119 CHAR8
*SupportedLanguage
;
121 if (Language
== NULL
||
124 ControllerHandle
== NULL
||
125 BufferSize
== NULL
) {
127 return EFI_INVALID_PARAMETER
;
130 SupportedLanguage
= This
->SupportedLanguages
;
132 Status
= EFI_UNSUPPORTED
;
133 while (*SupportedLanguage
!= 0) {
134 if (AsciiStrnCmp (Language
, SupportedLanguage
, 3)) {
135 Status
= EFI_SUCCESS
;
139 SupportedLanguage
+= 3;
142 if (EFI_ERROR (Status
)) {
143 return EFI_UNSUPPORTED
;
148 if (DiagnosticType
!= EfiDriverDiagnosticTypeStandard
) {
149 *ErrorType
= &gEfiBlockIoProtocolGuid
;
151 gBS
->AllocatePool (EfiBootServicesData
, (UINTN
) (*BufferSize
),
153 CopyMem (*Buffer
, L
"Unix Block I/O Driver Diagnostics Failed\n", *BufferSize
);
154 return EFI_DEVICE_ERROR
;
158 // Validate controller handle
160 Status
= gBS
->OpenProtocol (
162 &gEfiUnixIoProtocolGuid
,
164 gUnixBlockIoDriverBinding
.DriverBindingHandle
,
166 EFI_OPEN_PROTOCOL_BY_DRIVER
169 if (!EFI_ERROR (Status
)) {
172 &gEfiUnixIoProtocolGuid
,
173 gUnixBlockIoDriverBinding
.DriverBindingHandle
,
177 return EFI_UNSUPPORTED
;
180 if (Status
== EFI_UNSUPPORTED
) {
182 } else if (Status
!= EFI_ALREADY_STARTED
) {
183 return EFI_INVALID_PARAMETER
;