]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - EdkUnixPkg/Dxe/UnixThunk/Bus/BlockIo/DriverDiagnostics.c
Unix version of EFI emulator
[mirror_edk2.git] / EdkUnixPkg / Dxe / UnixThunk / Bus / BlockIo / DriverDiagnostics.c
... / ...
CommitLineData
1/*++\r
2\r
3Copyright (c) 2004 - 2005, Intel Corporation \r
4All rights reserved. This program and the accompanying materials \r
5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11\r
12Module Name:\r
13\r
14 DriverDiagnostics.c\r
15\r
16Abstract:\r
17\r
18--*/\r
19\r
20#include "UnixBlockIo.h"\r
21\r
22//\r
23// EFI Driver Diagnostics Functions\r
24//\r
25EFI_STATUS\r
26EFIAPI\r
27UnixBlockIoDriverDiagnosticsRunDiagnostics (\r
28 IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL *This,\r
29 IN EFI_HANDLE ControllerHandle,\r
30 IN EFI_HANDLE ChildHandle OPTIONAL,\r
31 IN EFI_DRIVER_DIAGNOSTIC_TYPE DiagnosticType,\r
32 IN CHAR8 *Language,\r
33 OUT EFI_GUID **ErrorType,\r
34 OUT UINTN *BufferSize,\r
35 OUT CHAR16 **Buffer\r
36 );\r
37\r
38//\r
39// EFI Driver Diagnostics Protocol\r
40//\r
41EFI_DRIVER_DIAGNOSTICS_PROTOCOL gUnixBlockIoDriverDiagnostics = {\r
42 UnixBlockIoDriverDiagnosticsRunDiagnostics,\r
43 LANGUAGESUPPORTED\r
44};\r
45\r
46EFI_STATUS\r
47EFIAPI\r
48UnixBlockIoDriverDiagnosticsRunDiagnostics (\r
49 IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL *This,\r
50 IN EFI_HANDLE ControllerHandle,\r
51 IN EFI_HANDLE ChildHandle OPTIONAL,\r
52 IN EFI_DRIVER_DIAGNOSTIC_TYPE DiagnosticType,\r
53 IN CHAR8 *Language,\r
54 OUT EFI_GUID **ErrorType,\r
55 OUT UINTN *BufferSize,\r
56 OUT CHAR16 **Buffer\r
57 )\r
58/*++\r
59\r
60 Routine Description:\r
61 Runs diagnostics on a controller.\r
62\r
63 Arguments:\r
64 This - A pointer to the EFI_DRIVER_DIAGNOSTICS_PROTOCOL instance.\r
65 ControllerHandle - The handle of the controller to run diagnostics on.\r
66 ChildHandle - The handle of the child controller to run diagnostics on \r
67 This is an optional parameter that may be NULL. It will \r
68 be NULL for device drivers. It will also be NULL for a \r
69 bus drivers that wish to run diagnostics on the bus \r
70 controller. It will not be NULL for a bus driver that \r
71 wishes to run diagnostics on one of its child controllers.\r
72 DiagnosticType - Indicates type of diagnostics to perform on the controller \r
73 specified by ControllerHandle and ChildHandle. See \r
74 "Related Definitions" for the list of supported types.\r
75 Language - A pointer to a three character ISO 639-2 language \r
76 identifier. This is the language in which the optional \r
77 error message should be returned in Buffer, and it must \r
78 match one of the languages specified in SupportedLanguages.\r
79 The number of languages supported by a driver is up to \r
80 the driver writer. \r
81 ErrorType - A GUID that defines the format of the data returned in \r
82 Buffer. \r
83 BufferSize - The size, in bytes, of the data returned in Buffer. \r
84 Buffer - A buffer that contains a Null-terminated Unicode string \r
85 plus some additional data whose format is defined by \r
86 ErrorType. Buffer is allocated by this function with \r
87 AllocatePool(), and it is the caller's responsibility \r
88 to free it with a call to FreePool(). \r
89\r
90 Returns:\r
91 EFI_SUCCESS - The controller specified by ControllerHandle and \r
92 ChildHandle passed the diagnostic.\r
93 EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.\r
94 EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid \r
95 EFI_HANDLE.\r
96 EFI_INVALID_PARAMETER - Language is NULL.\r
97 EFI_INVALID_PARAMETER - ErrorType is NULL.\r
98 EFI_INVALID_PARAMETER - BufferType is NULL.\r
99 EFI_INVALID_PARAMETER - Buffer is NULL.\r
100 EFI_UNSUPPORTED - The driver specified by This does not support \r
101 running diagnostics for the controller specified \r
102 by ControllerHandle and ChildHandle.\r
103 EFI_UNSUPPORTED - The driver specified by This does not support the \r
104 type of diagnostic specified by DiagnosticType.\r
105 EFI_UNSUPPORTED - The driver specified by This does not support the \r
106 language specified by Language.\r
107 EFI_OUT_OF_RESOURCES - There are not enough resources available to complete\r
108 the diagnostics.\r
109 EFI_OUT_OF_RESOURCES - There are not enough resources available to return\r
110 the status information in ErrorType, BufferSize, \r
111 and Buffer.\r
112 EFI_DEVICE_ERROR - The controller specified by ControllerHandle and \r
113 ChildHandle did not pass the diagnostic.\r
114\r
115--*/\r
116{\r
117 EFI_STATUS Status;\r
118 EFI_BLOCK_IO_PROTOCOL *BlockIo;\r
119 CHAR8 *SupportedLanguage;\r
120\r
121 if (Language == NULL ||\r
122 ErrorType == NULL ||\r
123 Buffer == NULL ||\r
124 ControllerHandle == NULL ||\r
125 BufferSize == NULL) {\r
126\r
127 return EFI_INVALID_PARAMETER;\r
128 }\r
129\r
130 SupportedLanguage = This->SupportedLanguages;\r
131\r
132 Status = EFI_UNSUPPORTED;\r
133 while (*SupportedLanguage != 0) {\r
134 if (AsciiStrnCmp (Language, SupportedLanguage, 3)) {\r
135 Status = EFI_SUCCESS;\r
136 break;\r
137 }\r
138\r
139 SupportedLanguage += 3;\r
140 }\r
141\r
142 if (EFI_ERROR (Status)) {\r
143 return EFI_UNSUPPORTED;\r
144 }\r
145\r
146 *ErrorType = NULL;\r
147 *BufferSize = 0;\r
148 if (DiagnosticType != EfiDriverDiagnosticTypeStandard) {\r
149 *ErrorType = &gEfiBlockIoProtocolGuid;\r
150 *BufferSize = 0x60;\r
151 gBS->AllocatePool (EfiBootServicesData, (UINTN) (*BufferSize),
152 (void *)Buffer);\r
153 CopyMem (*Buffer, L"Unix Block I/O Driver Diagnostics Failed\n", *BufferSize);\r
154 return EFI_DEVICE_ERROR;\r
155 }\r
156\r
157 //\r
158 // Validate controller handle\r
159 //\r
160 Status = gBS->OpenProtocol (\r
161 ControllerHandle,\r
162 &gEfiUnixIoProtocolGuid,\r
163 (void *)&BlockIo,\r
164 gUnixBlockIoDriverBinding.DriverBindingHandle,\r
165 ControllerHandle,\r
166 EFI_OPEN_PROTOCOL_BY_DRIVER\r
167 );\r
168\r
169 if (!EFI_ERROR (Status)) {\r
170 gBS->CloseProtocol (\r
171 ControllerHandle,\r
172 &gEfiUnixIoProtocolGuid,\r
173 gUnixBlockIoDriverBinding.DriverBindingHandle,\r
174 ControllerHandle\r
175 );\r
176\r
177 return EFI_UNSUPPORTED;\r
178 }\r
179\r
180 if (Status == EFI_UNSUPPORTED) {\r
181 return Status;\r
182 } else if (Status != EFI_ALREADY_STARTED) {\r
183 return EFI_INVALID_PARAMETER;\r
184 }\r
185\r
186 return EFI_SUCCESS;\r
187}\r