]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Bus/Pci/IdeBus/Dxe/DriverConfiguration.c
add SerialPortLib.h
[mirror_edk2.git] / IntelFrameworkModulePkg / Bus / Pci / IdeBus / Dxe / DriverConfiguration.c
1 /** @file
2 Copyright (c) 2006, Intel Corporation
3 All rights reserved. This program and the accompanying materials
4 are licensed and made available under the terms and conditions of the BSD License
5 which accompanies this distribution. The full text of the license may be found at
6 http://opensource.org/licenses/bsd-license.php
7
8 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
9 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
10
11 **/
12
13
14 #include "idebus.h"
15
16 CHAR16 *OptionString[4] = {
17 L"Enable Primary Master (Y/N)? -->",
18 L"Enable Primary Slave (Y/N)? -->",
19 L"Enable Secondary Master (Y/N)? -->",
20 L"Enable Secondary Slave (Y/N)? -->"
21 };
22
23 //
24 // EFI Driver Configuration Protocol
25 //
26 EFI_DRIVER_CONFIGURATION_PROTOCOL gIDEBusDriverConfiguration = {
27 IDEBusDriverConfigurationSetOptions,
28 IDEBusDriverConfigurationOptionsValid,
29 IDEBusDriverConfigurationForceDefaults,
30 "eng"
31 };
32
33 /**
34 TODO: Add function description
35
36 @retval EFI_ABORTED TODO: Add description for return value
37 @retval EFI_SUCCESS TODO: Add description for return value
38 @retval EFI_NOT_FOUND TODO: Add description for return value
39
40 **/
41 STATIC
42 EFI_STATUS
43 GetResponse (
44 VOID
45 )
46 {
47 EFI_STATUS Status;
48 EFI_INPUT_KEY Key;
49
50 while (TRUE) {
51 Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
52 if (!EFI_ERROR (Status)) {
53 if (Key.ScanCode == SCAN_ESC) {
54 return EFI_ABORTED;
55 }
56
57 switch (Key.UnicodeChar) {
58
59 //
60 // fall through
61 //
62 case L'y':
63 case L'Y':
64 gST->ConOut->OutputString (gST->ConOut, L"Y\n");
65 return EFI_SUCCESS;
66
67 //
68 // fall through
69 //
70 case L'n':
71 case L'N':
72 gST->ConOut->OutputString (gST->ConOut, L"N\n");
73 return EFI_NOT_FOUND;
74 }
75
76 }
77 }
78 }
79
80 /**
81 Allows the user to set controller specific options for a controller that a
82 driver is currently managing.
83
84 @param This A pointer to the EFI_DRIVER_CONFIGURATION_ PROTOCOL
85 instance.
86 @param ControllerHandle The handle of the controller to set options on.
87 @param ChildHandle The handle of the child controller to set options on.
88 This is an optional parameter that may be NULL.
89 It will be NULL for device drivers, and for a bus drivers
90 that wish to set options for the bus controller.
91 It will not be NULL for a bus driver that wishes to set
92 options for one of its child controllers.
93 @param Language A pointer to a three character ISO 639-2 language
94 identifier. This is the language of the user interface
95 that should be presented to the user, and it must match
96 one of the languages specified in SupportedLanguages.
97 The number of languages supported by a driver is up to
98 the driver writer.
99 @param ActionRequired A pointer to the action that the calling agent is
100 required to perform when this function returns.
101 See "Related Definitions" for a list of the actions that
102 the calling agent is required to perform prior to
103 accessing ControllerHandle again.
104
105 @retval EFI_SUCCESS The driver specified by This successfully set the
106 configuration options for the controller specified
107 by ControllerHandle..
108 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
109 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a
110 valid EFI_HANDLE.
111 @retval EFI_INVALID_PARAMETER ActionRequired is NULL.
112 @retval EFI_UNSUPPORTED The driver specified by This does not support
113 setting configuration options for the controller
114 specified by ControllerHandle and ChildHandle.
115 @retval EFI_UNSUPPORTED The driver specified by This does not support the
116 language specified by Language.
117 @retval EFI_DEVICE_ERROR A device error occurred while attempt to set the
118 configuration options for the controller specified
119 by ControllerHandle and ChildHandle.
120 @retval EFI_OUT_RESOURCES There are not enough resources available to set the
121 configuration options for the controller specified
122 by ControllerHandle and ChildHandle.
123
124 **/
125 EFI_STATUS
126 IDEBusDriverConfigurationSetOptions (
127 IN EFI_DRIVER_CONFIGURATION_PROTOCOL *This,
128 IN EFI_HANDLE ControllerHandle,
129 IN EFI_HANDLE ChildHandle OPTIONAL,
130 IN CHAR8 *Language,
131 OUT EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED *ActionRequired
132 )
133 {
134 EFI_STATUS Status;
135 UINT8 Value;
136 UINT8 NewValue;
137 UINTN DataSize;
138 UINTN Index;
139
140 if (ChildHandle != NULL) {
141 return EFI_UNSUPPORTED;
142 }
143
144 *ActionRequired = EfiDriverConfigurationActionNone;
145
146 DataSize = sizeof (Value);
147 Status = gRT->GetVariable (
148 L"Configuration",
149 &gEfiCallerIdGuid,
150 NULL,
151 &DataSize,
152 &Value
153 );
154
155 gST->ConOut->OutputString (gST->ConOut, L"IDE Bus Driver Configuration\n");
156 gST->ConOut->OutputString (gST->ConOut, L"===============================\n");
157
158 NewValue = 0;
159 for (Index = 0; Index < 4; Index++) {
160 gST->ConOut->OutputString (gST->ConOut, OptionString[Index]);
161
162 Status = GetResponse ();
163 if (Status == EFI_ABORTED) {
164 return EFI_SUCCESS;
165 }
166
167 if (!EFI_ERROR (Status)) {
168 NewValue = (UINT8) (NewValue | (1 << Index));
169 }
170 }
171
172 if (EFI_ERROR (Status) || (NewValue != Value)) {
173 gRT->SetVariable (
174 L"Configuration",
175 &gEfiCallerIdGuid,
176 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
177 sizeof (NewValue),
178 &NewValue
179 );
180
181 *ActionRequired = EfiDriverConfigurationActionRestartController;
182 } else {
183 *ActionRequired = EfiDriverConfigurationActionNone;
184 }
185
186 return EFI_SUCCESS;
187 }
188
189 /**
190 Tests to see if a controller's current configuration options are valid.
191
192 @param This A pointer to the EFI_DRIVER_CONFIGURATION_PROTOCOL
193 instance.
194 @param ControllerHandle The handle of the controller to test if it's current
195 configuration options are valid.
196 @param ChildHandle The handle of the child controller to test if it's
197 current
198 configuration options are valid. This is an optional
199 parameter that may be NULL. It will be NULL for device
200 drivers. It will also be NULL for a bus drivers that
201 wish to test the configuration options for the bus
202 controller. It will not be NULL for a bus driver that
203 wishes to test configuration options for one of
204 its child controllers.
205
206 @retval EFI_SUCCESS The controller specified by ControllerHandle and
207 ChildHandle that is being managed by the driver
208 specified by This has a valid set of configuration
209 options.
210 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
211 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
212 EFI_HANDLE.
213 @retval EFI_UNSUPPORTED The driver specified by This is not currently
214 managing the controller specified by
215 ControllerHandle and ChildHandle.
216 @retval EFI_DEVICE_ERROR The controller specified by ControllerHandle and
217 ChildHandle that is being managed by the driver
218 specified by This has an invalid set of
219 configuration options.
220
221 **/
222 EFI_STATUS
223 IDEBusDriverConfigurationOptionsValid (
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 /**
253 Forces a driver to set the default configuration options for a controller.
254
255 @param This A pointer to the EFI_DRIVER_CONFIGURATION_ PROTOCOL
256 instance.
257 @param ControllerHandle The handle of the controller to force default
258 configuration options on.
259 @param ChildHandle The handle of the child controller to force default
260 configuration options on This is an optional parameter
261 that may be NULL. It will be NULL for device drivers.
262 It will also be NULL for a bus drivers that wish to
263 force default configuration options for the bus
264 controller. It will not be NULL for a bus driver that
265 wishes to force default configuration options for one
266 of its child controllers.
267 @param DefaultType The type of default configuration options to force on
268 the controller specified by ControllerHandle and
269 ChildHandle. See Table 9-1 for legal values.
270 A DefaultType of 0x00000000 must be supported
271 by this protocol.
272 @param ActionRequired A pointer to the action that the calling agent
273 is required to perform when this function returns.
274
275 @retval EFI_SUCCESS The driver specified by This successfully forced
276 the default configuration options on the
277 controller specified by ControllerHandle and
278 ChildHandle.
279 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
280 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a
281 valid EFI_HANDLE.
282 @retval EFI_INVALID_PARAMETER ActionRequired is NULL.
283 @retval EFI_UNSUPPORTED The driver specified by This does not support
284 forcing the default configuration options on
285 the controller specified by ControllerHandle
286 and ChildHandle.
287 @retval EFI_UNSUPPORTED The driver specified by This does not support
288 the configuration type specified by DefaultType.
289 @retval EFI_DEVICE_ERROR A device error occurred while attempt to force
290 the default configuration options on the controller
291 specified by ControllerHandle and ChildHandle.
292 @retval EFI_OUT_RESOURCES There are not enough resources available to force
293 the default configuration options on the controller
294 specified by ControllerHandle and ChildHandle.
295
296 **/
297 EFI_STATUS
298 IDEBusDriverConfigurationForceDefaults (
299 IN EFI_DRIVER_CONFIGURATION_PROTOCOL *This,
300 IN EFI_HANDLE ControllerHandle,
301 IN EFI_HANDLE ChildHandle OPTIONAL,
302 IN UINT32 DefaultType,
303 OUT EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED *ActionRequired
304 )
305 {
306 UINT8 Value;
307
308 if (ChildHandle != NULL) {
309 return EFI_UNSUPPORTED;
310 }
311
312 Value = 0x0f;
313 gRT->SetVariable (
314 L"Configuration",
315 &gEfiCallerIdGuid,
316 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
317 sizeof (Value),
318 &Value
319 );
320 *ActionRequired = EfiDriverConfigurationActionRestartController;
321 return EFI_SUCCESS;
322 }