VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Firmware2/VBoxPkg/VBoxIdeBusDxe/DriverDiagnostics.c@ 33110

Last change on this file since 33110 was 33027, checked in by vboxsync, 15 years ago

EFI: legal notes.

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette