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