1 | /* $Id: DriverDiagnostics.c 48674 2013-09-25 08:26:15Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * DriverDiagnostics.c
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2009-2010 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * The contents of this file may alternatively be used under the terms
|
---|
18 | * of the Common Development and Distribution License Version 1.0
|
---|
19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | * CDDL are applicable instead of those of the GPL.
|
---|
22 | *
|
---|
23 | * You may elect to license modified versions of this file under the
|
---|
24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | */
|
---|
26 |
|
---|
27 | /** @file
|
---|
28 | Implementation of UEFI driver Diagnostics protocol which to perform diagnostic on the IDE
|
---|
29 | Bus controller.
|
---|
30 |
|
---|
31 | Copyright (c) 2006 - 2008, Intel Corporation
|
---|
32 | All rights reserved. This program and the accompanying materials
|
---|
33 | are licensed and made available under the terms and conditions of the BSD License
|
---|
34 | which accompanies this distribution. The full text of the license may be found at
|
---|
35 | http://opensource.org/licenses/bsd-license.php
|
---|
36 |
|
---|
37 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
---|
38 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
---|
39 |
|
---|
40 | **/
|
---|
41 |
|
---|
42 |
|
---|
43 | #include "IdeBus.h"
|
---|
44 |
|
---|
45 | #define IDE_BUS_DIAGNOSTIC_ERROR L"PCI IDE/ATAPI Driver Diagnostics Failed"
|
---|
46 |
|
---|
47 | //
|
---|
48 | // EFI Driver Diagnostics Protocol
|
---|
49 | //
|
---|
50 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_DRIVER_DIAGNOSTICS_PROTOCOL gIDEBusDriverDiagnostics = {
|
---|
51 | IDEBusDriverDiagnosticsRunDiagnostics,
|
---|
52 | "eng"
|
---|
53 | };
|
---|
54 |
|
---|
55 | //
|
---|
56 | // EFI Driver Diagnostics 2 Protocol
|
---|
57 | //
|
---|
58 | GLOBAL_REMOVE_IF_UNREFERENCED EFI_DRIVER_DIAGNOSTICS2_PROTOCOL gIDEBusDriverDiagnostics2 = {
|
---|
59 | (EFI_DRIVER_DIAGNOSTICS2_RUN_DIAGNOSTICS) IDEBusDriverDiagnosticsRunDiagnostics,
|
---|
60 | "en"
|
---|
61 | };
|
---|
62 |
|
---|
63 | /**
|
---|
64 | Runs diagnostics on a controller.
|
---|
65 |
|
---|
66 | @param This A pointer to the EFI_DRIVER_DIAGNOSTICS_PROTOCOLinstance.
|
---|
67 | @param ControllerHandle The handle of the controller to run diagnostics on.
|
---|
68 | @param ChildHandle The handle of the child controller to run diagnostics on
|
---|
69 | This is an optional parameter that may be NULL. It will
|
---|
70 | be NULL for device drivers. It will also be NULL for a
|
---|
71 | bus drivers that wish to run diagnostics on the bus controller.
|
---|
72 | It will not be NULL for a bus driver that wishes to run
|
---|
73 | diagnostics on one of its child controllers.
|
---|
74 | @param DiagnosticType Indicates type of diagnostics to perform on the controller
|
---|
75 | specified by ControllerHandle and ChildHandle.
|
---|
76 | @param Language A pointer to a three character ISO 639-2 language identifier.
|
---|
77 | This is the language in which the optional error message should
|
---|
78 | be returned in Buffer, and it must match one of the languages
|
---|
79 | specified in SupportedLanguages. The number of languages supported by
|
---|
80 | a driver is up to the driver writer.
|
---|
81 | @param ErrorType A GUID that defines the format of the data returned in Buffer.
|
---|
82 | @param BufferSize The size, in bytes, of the data returned in Buffer.
|
---|
83 | @param Buffer A buffer that contains a Null-terminated Unicode string
|
---|
84 | plus some additional data whose format is defined by ErrorType.
|
---|
85 | Buffer is allocated by this function with AllocatePool(), and
|
---|
86 | it is the caller's responsibility to free it with a call to FreePool().
|
---|
87 |
|
---|
88 | @retval EFI_SUCCESS The controller specified by ControllerHandle and ChildHandle passed
|
---|
89 | the diagnostic.
|
---|
90 | @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
|
---|
91 | @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid EFI_HANDLE.
|
---|
92 | @retval EFI_INVALID_PARAMETER Language is NULL.
|
---|
93 | @retval EFI_INVALID_PARAMETER ErrorType is NULL.
|
---|
94 | @retval EFI_INVALID_PARAMETER BufferType is NULL.
|
---|
95 | @retval EFI_INVALID_PARAMETER Buffer is NULL.
|
---|
96 | @retval EFI_UNSUPPORTED The driver specified by This does not support running
|
---|
97 | diagnostics for the controller specified by ControllerHandle
|
---|
98 | and ChildHandle.
|
---|
99 | @retval EFI_UNSUPPORTED The driver specified by This does not support the
|
---|
100 | type of diagnostic specified by DiagnosticType.
|
---|
101 | @retval EFI_UNSUPPORTED The driver specified by This does not support the language
|
---|
102 | specified by Language.
|
---|
103 | @retval EFI_OUT_OF_RESOURCES There are not enough resources available to complete the
|
---|
104 | diagnostics.
|
---|
105 | @retval EFI_OUT_OF_RESOURCES There are not enough resources available to return the
|
---|
106 | status information in ErrorType, BufferSize,and Buffer.
|
---|
107 | @retval EFI_DEVICE_ERROR The controller specified by ControllerHandle and ChildHandle
|
---|
108 | did not pass the diagnostic.
|
---|
109 | **/
|
---|
110 | EFI_STATUS
|
---|
111 | EFIAPI
|
---|
112 | IDEBusDriverDiagnosticsRunDiagnostics (
|
---|
113 | IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL *This,
|
---|
114 | IN EFI_HANDLE ControllerHandle,
|
---|
115 | IN EFI_HANDLE ChildHandle OPTIONAL,
|
---|
116 | IN EFI_DRIVER_DIAGNOSTIC_TYPE DiagnosticType,
|
---|
117 | IN CHAR8 *Language,
|
---|
118 | OUT EFI_GUID **ErrorType,
|
---|
119 | OUT UINTN *BufferSize,
|
---|
120 | OUT CHAR16 **Buffer
|
---|
121 | )
|
---|
122 | {
|
---|
123 | EFI_STATUS Status;
|
---|
124 | EFI_PCI_IO_PROTOCOL *PciIo;
|
---|
125 | EFI_BLOCK_IO_PROTOCOL *BlkIo;
|
---|
126 | IDE_BLK_IO_DEV *IdeBlkIoDevice;
|
---|
127 | UINT32 VendorDeviceId;
|
---|
128 | VOID *BlockBuffer;
|
---|
129 | CHAR8 *SupportedLanguages;
|
---|
130 | BOOLEAN Iso639Language;
|
---|
131 | BOOLEAN Found;
|
---|
132 | UINTN Index;
|
---|
133 |
|
---|
134 | if (Language == NULL ||
|
---|
135 | ErrorType == NULL ||
|
---|
136 | Buffer == NULL ||
|
---|
137 | ControllerHandle == NULL ||
|
---|
138 | BufferSize == NULL) {
|
---|
139 |
|
---|
140 | return EFI_INVALID_PARAMETER;
|
---|
141 | }
|
---|
142 |
|
---|
143 | SupportedLanguages = This->SupportedLanguages;
|
---|
144 | Iso639Language = (BOOLEAN)(This == &gIDEBusDriverDiagnostics);
|
---|
145 | //
|
---|
146 | // Make sure Language is in the set of Supported Languages
|
---|
147 | //
|
---|
148 | Found = FALSE;
|
---|
149 | while (*SupportedLanguages != 0) {
|
---|
150 | if (Iso639Language) {
|
---|
151 | if (CompareMem (Language, SupportedLanguages, 3) == 0) {
|
---|
152 | Found = TRUE;
|
---|
153 | break;
|
---|
154 | }
|
---|
155 | SupportedLanguages += 3;
|
---|
156 | } else {
|
---|
157 | for (Index = 0; SupportedLanguages[Index] != 0 && SupportedLanguages[Index] != ';'; Index++);
|
---|
158 | if ((AsciiStrnCmp(SupportedLanguages, Language, Index) == 0) && (Language[Index] == 0)) {
|
---|
159 | Found = TRUE;
|
---|
160 | break;
|
---|
161 | }
|
---|
162 | SupportedLanguages += Index;
|
---|
163 | for (; *SupportedLanguages != 0 && *SupportedLanguages == ';'; SupportedLanguages++);
|
---|
164 | }
|
---|
165 | }
|
---|
166 | //
|
---|
167 | // If Language is not a member of SupportedLanguages, then return EFI_UNSUPPORTED
|
---|
168 | //
|
---|
169 | if (!Found) {
|
---|
170 | return EFI_UNSUPPORTED;
|
---|
171 | }
|
---|
172 |
|
---|
173 | *ErrorType = NULL;
|
---|
174 | *BufferSize = 0;
|
---|
175 |
|
---|
176 | if (ChildHandle == NULL) {
|
---|
177 | Status = gBS->OpenProtocol (
|
---|
178 | ControllerHandle,
|
---|
179 | &gEfiCallerIdGuid,
|
---|
180 | NULL,
|
---|
181 | gIDEBusDriverBinding.DriverBindingHandle,
|
---|
182 | ControllerHandle,
|
---|
183 | EFI_OPEN_PROTOCOL_TEST_PROTOCOL
|
---|
184 | );
|
---|
185 | if (EFI_ERROR (Status)) {
|
---|
186 | return Status;
|
---|
187 | }
|
---|
188 |
|
---|
189 | Status = gBS->OpenProtocol (
|
---|
190 | ControllerHandle,
|
---|
191 | &gEfiPciIoProtocolGuid,
|
---|
192 | (VOID **) &PciIo,
|
---|
193 | gIDEBusDriverBinding.DriverBindingHandle,
|
---|
194 | ControllerHandle,
|
---|
195 | EFI_OPEN_PROTOCOL_GET_PROTOCOL
|
---|
196 | );
|
---|
197 | if (EFI_ERROR (Status)) {
|
---|
198 | return EFI_DEVICE_ERROR;
|
---|
199 | }
|
---|
200 |
|
---|
201 | //
|
---|
202 | // Use services of PCI I/O Protocol to test the PCI IDE/ATAPI Controller
|
---|
203 | // The following test simply reads the Device ID and Vendor ID.
|
---|
204 | // It should never fail. A real test would perform more advanced
|
---|
205 | // diagnostics.
|
---|
206 | //
|
---|
207 |
|
---|
208 | Status = PciIo->Pci.Read (PciIo, EfiPciIoWidthUint32, 0, 1, &VendorDeviceId);
|
---|
209 | if (EFI_ERROR (Status) || VendorDeviceId == 0xffffffff) {
|
---|
210 | return EFI_DEVICE_ERROR;
|
---|
211 | }
|
---|
212 |
|
---|
213 | return EFI_SUCCESS;
|
---|
214 | }
|
---|
215 |
|
---|
216 | Status = gBS->OpenProtocol (
|
---|
217 | ChildHandle,
|
---|
218 | &gEfiBlockIoProtocolGuid,
|
---|
219 | (VOID **) &BlkIo,
|
---|
220 | gIDEBusDriverBinding.DriverBindingHandle,
|
---|
221 | ChildHandle,
|
---|
222 | EFI_OPEN_PROTOCOL_GET_PROTOCOL
|
---|
223 | );
|
---|
224 | if (EFI_ERROR (Status)) {
|
---|
225 | return Status;
|
---|
226 | }
|
---|
227 |
|
---|
228 | IdeBlkIoDevice = IDE_BLOCK_IO_DEV_FROM_THIS (BlkIo);
|
---|
229 |
|
---|
230 | //
|
---|
231 | // Use services available from IdeBlkIoDevice to test the IDE/ATAPI device
|
---|
232 | //
|
---|
233 | Status = gBS->AllocatePool (
|
---|
234 | EfiBootServicesData,
|
---|
235 | IdeBlkIoDevice->BlkMedia.BlockSize,
|
---|
236 | (VOID **) &BlockBuffer
|
---|
237 | );
|
---|
238 | if (EFI_ERROR (Status)) {
|
---|
239 | return Status;
|
---|
240 | }
|
---|
241 |
|
---|
242 | Status = IdeBlkIoDevice->BlkIo.ReadBlocks (
|
---|
243 | &IdeBlkIoDevice->BlkIo,
|
---|
244 | IdeBlkIoDevice->BlkMedia.MediaId,
|
---|
245 | 0,
|
---|
246 | IdeBlkIoDevice->BlkMedia.BlockSize,
|
---|
247 | BlockBuffer
|
---|
248 | );
|
---|
249 |
|
---|
250 | if (EFI_ERROR (Status)) {
|
---|
251 | *ErrorType = &gEfiCallerIdGuid;
|
---|
252 | *BufferSize = sizeof (IDE_BUS_DIAGNOSTIC_ERROR);
|
---|
253 |
|
---|
254 | Status = gBS->AllocatePool (
|
---|
255 | EfiBootServicesData,
|
---|
256 | (UINTN) (*BufferSize),
|
---|
257 | (VOID **) Buffer
|
---|
258 | );
|
---|
259 | if (EFI_ERROR (Status)) {
|
---|
260 | return Status;
|
---|
261 | }
|
---|
262 |
|
---|
263 | CopyMem (*Buffer, IDE_BUS_DIAGNOSTIC_ERROR, *BufferSize);
|
---|
264 |
|
---|
265 | Status = EFI_DEVICE_ERROR;
|
---|
266 | }
|
---|
267 |
|
---|
268 | gBS->FreePool (BlockBuffer);
|
---|
269 |
|
---|
270 | return Status;
|
---|
271 | }
|
---|