VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Firmware2/VBoxPkg/VBoxIdeBusDxe/DriverConfiguration.c@ 33540

Last change on this file since 33540 was 33540, checked in by vboxsync, 14 years ago

*: spelling fixes, thanks Timeless!

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.5 KB
Line 
1/* $Id: DriverConfiguration.c 33540 2010-10-28 09:27:05Z vboxsync $ */
2/** @file
3 * DriverConfiguration.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 Configuration Protocol for IDE bus driver which
20 provides ability to set IDE bus controller specific options.
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
36CHAR16 *OptionString[4] = {
37 L"Enable Primary Master (Y/N)? -->",
38 L"Enable Primary Slave (Y/N)? -->",
39 L"Enable Secondary Master (Y/N)? -->",
40 L"Enable Secondary Slave (Y/N)? -->"
41};
42
43//
44// EFI Driver Configuration Protocol
45//
46EFI_DRIVER_CONFIGURATION_PROTOCOL gIDEBusDriverConfiguration = {
47 IDEBusDriverConfigurationSetOptions,
48 IDEBusDriverConfigurationOptionsValid,
49 IDEBusDriverConfigurationForceDefaults,
50 "eng"
51};
52
53/**
54 Interpret keyboard input.
55
56 @retval EFI_ABORTED Get an 'ESC' key inputted.
57 @retval EFI_SUCCESS Get an 'Y' or 'y' inputted.
58 @retval EFI_NOT_FOUND Get an 'N' or 'n' inputted..
59
60**/
61EFI_STATUS
62GetResponse (
63 VOID
64 )
65{
66 EFI_STATUS Status;
67 EFI_INPUT_KEY Key;
68
69 while (TRUE) {
70 Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
71 if (!EFI_ERROR (Status)) {
72 if (Key.ScanCode == SCAN_ESC) {
73 return EFI_ABORTED;
74 }
75
76 switch (Key.UnicodeChar) {
77
78 //
79 // fall through
80 //
81 case L'y':
82 case L'Y':
83 gST->ConOut->OutputString (gST->ConOut, L"Y\n");
84 return EFI_SUCCESS;
85
86 //
87 // fall through
88 //
89 case L'n':
90 case L'N':
91 gST->ConOut->OutputString (gST->ConOut, L"N\n");
92 return EFI_NOT_FOUND;
93 }
94
95 }
96 }
97}
98
99/**
100 Allows the user to set controller specific options for a controller that a
101 driver is currently managing.
102
103 @param This A pointer to the EFI_DRIVER_CONFIGURATION_ PROTOCOL instance.
104 @param ControllerHandle The handle of the controller to set options on.
105 @param ChildHandle The handle of the child controller to set options on.
106 This is an optional parameter that may be NULL.
107 It will be NULL for device drivers, and for a bus drivers
108 that wish to set options for the bus controller.
109 It will not be NULL for a bus driver that wishes to set
110 options for one of its child controllers.
111 @param Language A pointer to a three character ISO 639-2 language identifier.
112 This is the language of the user interface that should be presented
113 to the user, and it must match one of the languages specified in
114 SupportedLanguages. The number of languages supported by a driver is up to
115 the driver writer.
116 @param ActionRequired A pointer to the action that the calling agent is required
117 to perform when this function returns.
118
119
120 @retval EFI_SUCCESS The driver specified by This successfully set the configuration
121 options for the controller specified by ControllerHandle..
122 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
123 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid EFI_HANDLE.
124 @retval EFI_INVALID_PARAMETER ActionRequired is NULL.
125 @retval EFI_UNSUPPORTED The driver specified by This does not support setting configuration options for
126 the controller specified by ControllerHandle and ChildHandle.
127 @retval EFI_UNSUPPORTED The driver specified by This does not support the language specified by Language.
128 @retval EFI_DEVICE_ERROR A device error occurred while attempt to set the configuration options for the
129 controller specified by ControllerHandle and ChildHandle.
130 @retval EFI_OUT_RESOURCES There are not enough resources available to set the configuration options for the
131 controller specified by ControllerHandle and ChildHandle
132**/
133EFI_STATUS
134EFIAPI
135IDEBusDriverConfigurationSetOptions (
136 IN EFI_DRIVER_CONFIGURATION_PROTOCOL *This,
137 IN EFI_HANDLE ControllerHandle,
138 IN EFI_HANDLE ChildHandle OPTIONAL,
139 IN CHAR8 *Language,
140 OUT EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED *ActionRequired
141 )
142{
143 EFI_STATUS Status;
144 UINT8 Value;
145 UINT8 NewValue;
146 UINTN DataSize;
147 UINTN Index;
148
149 if (ChildHandle != NULL) {
150 return EFI_UNSUPPORTED;
151 }
152
153 *ActionRequired = EfiDriverConfigurationActionNone;
154
155 DataSize = sizeof (Value);
156 Status = gRT->GetVariable (
157 L"Configuration",
158 &gEfiCallerIdGuid,
159 NULL,
160 &DataSize,
161 &Value
162 );
163
164 gST->ConOut->OutputString (gST->ConOut, L"IDE Bus Driver Configuration\n");
165 gST->ConOut->OutputString (gST->ConOut, L"===============================\n");
166
167 NewValue = 0;
168 for (Index = 0; Index < 4; Index++) {
169 gST->ConOut->OutputString (gST->ConOut, OptionString[Index]);
170
171 Status = GetResponse ();
172 if (Status == EFI_ABORTED) {
173 return EFI_SUCCESS;
174 }
175
176 if (!EFI_ERROR (Status)) {
177 NewValue = (UINT8) (NewValue | (1 << Index));
178 }
179 }
180
181 if (EFI_ERROR (Status) || (NewValue != Value)) {
182 gRT->SetVariable (
183 L"Configuration",
184 &gEfiCallerIdGuid,
185 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
186 sizeof (NewValue),
187 &NewValue
188 );
189
190 *ActionRequired = EfiDriverConfigurationActionRestartController;
191 } else {
192 *ActionRequired = EfiDriverConfigurationActionNone;
193 }
194
195 return EFI_SUCCESS;
196}
197
198/**
199 Tests to see if a controller's current configuration options are valid.
200
201 @param This A pointer to the EFI_DRIVER_CONFIGURATION_PROTOCOL instance.
202 @param ControllerHandle The handle of the controller to test if it's current configuration options
203 are valid.
204 @param ChildHandle The handle of the child controller to test if it's current configuration
205 options are valid. This is an optional parameter that may be NULL. It will
206 be NULL for device drivers. It will also be NULL for a bus drivers that
207 wish to test the configuration options for the bus controller. It will
208 not be NULL for a bus driver that wishes to test configuration options for
209 one of its child controllers.
210 @retval EFI_SUCCESS The controller specified by ControllerHandle and ChildHandle that is being
211 managed by the driver specified by This has a valid set of configuration
212 options.
213 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
214 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid EFI_HANDLE.
215 @retval EFI_UNSUPPORTED The driver specified by This is not currently managing the controller
216 specified by ControllerHandle and ChildHandle.
217 @retval EFI_DEVICE_ERROR The controller specified by ControllerHandle and ChildHandle that is being
218 managed by the driver specified by This has an invalid set of configuration
219 options.
220**/
221EFI_STATUS
222EFIAPI
223IDEBusDriverConfigurationOptionsValid (
224 IN EFI_DRIVER_CONFIGURATION_PROTOCOL *This,
225 IN EFI_HANDLE ControllerHandle,
226 IN EFI_HANDLE ChildHandle OPTIONAL
227 )
228{
229 EFI_STATUS Status;
230 UINT8 Value;
231 UINTN DataSize;
232
233 if (ChildHandle != NULL) {
234 return EFI_UNSUPPORTED;
235 }
236
237 DataSize = sizeof (Value);
238 Status = gRT->GetVariable (
239 L"Configuration",
240 &gEfiCallerIdGuid,
241 NULL,
242 &DataSize,
243 &Value
244 );
245 if (EFI_ERROR (Status) || Value > 0x0f) {
246 return EFI_DEVICE_ERROR;
247 }
248
249 return EFI_SUCCESS;
250}
251/**
252 Forces a driver to set the default configuration options for a controller.
253
254 @param This A pointer to the EFI_DRIVER_CONFIGURATION_ PROTOCOL instance.
255 @param ControllerHandle The handle of the controller to force default configuration options on.
256 @param ChildHandle The handle of the child controller to force default configuration
257 options on This is an optional parameter that may be NULL. It
258 will be NULL for device drivers. It will also be NULL for a bus
259 drivers that wish to force default configuration options for the bus
260 controller. It will not be NULL for a bus driver that wishes to force
261 default configuration options for one of its child controllers.
262 @param DefaultType The type of default configuration options to force on the controller
263 specified by ControllerHandle and ChildHandle.
264 @param ActionRequired A pointer to the action that the calling agent is required to perform
265 when this function returns.
266
267 @retval EFI_SUCCESS The driver specified by This successfully forced the
268 default configuration options on the controller specified by
269 ControllerHandle and ChildHandle.
270 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
271 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid EFI_HANDLE.
272 @retval EFI_INVALID_PARAMETER ActionRequired is NULL.
273 @retval EFI_UNSUPPORTED The driver specified by This does not support forcing the default
274 configuration options on the controller specified by ControllerHandle
275 and ChildHandle.
276 @retval EFI_UNSUPPORTED The driver specified by This does not support the configuration type
277 specified by DefaultType.
278 @retval EFI_DEVICE_ERROR A device error occurred while attempt to force the default configuration
279 options on the controller specified by ControllerHandle and ChildHandle.
280 @retval EFI_OUT_RESOURCES There are not enough resources available to force the default configuration
281 options on the controller specified by ControllerHandle and ChildHandle.
282**/
283EFI_STATUS
284EFIAPI
285IDEBusDriverConfigurationForceDefaults (
286 IN EFI_DRIVER_CONFIGURATION_PROTOCOL *This,
287 IN EFI_HANDLE ControllerHandle,
288 IN EFI_HANDLE ChildHandle OPTIONAL,
289 IN UINT32 DefaultType,
290 OUT EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED *ActionRequired
291 )
292{
293 UINT8 Value;
294
295 if (ChildHandle != NULL) {
296 return EFI_UNSUPPORTED;
297 }
298
299 Value = 0x0f;
300 gRT->SetVariable (
301 L"Configuration",
302 &gEfiCallerIdGuid,
303 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
304 sizeof (Value),
305 &Value
306 );
307 *ActionRequired = EfiDriverConfigurationActionRestartController;
308 return EFI_SUCCESS;
309}
Note: See TracBrowser for help on using the repository browser.

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