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