]> git.proxmox.com Git - mirror_edk2.git/blame - EdkModulePkg/Bus/Pci/IdeBus/Dxe/DriverConfiguration.c
Partially make EdkModulePkg pass intel IPF compiler with /W4 /WX switched on.
[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
1cc8ee78 67STATIC\r
878ddf1f 68EFI_STATUS\r
69GetResponse (\r
70 VOID\r
71 )\r
878ddf1f 72{\r
73 EFI_STATUS Status;\r
74 EFI_INPUT_KEY Key;\r
75\r
76 while (TRUE) {\r
77 Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
78 if (!EFI_ERROR (Status)) {\r
79 if (Key.ScanCode == SCAN_ESC) {\r
80 return EFI_ABORTED;\r
81 }\r
82\r
83 switch (Key.UnicodeChar) {\r
84\r
85 //\r
86 // fall through\r
87 //\r
88 case L'y':\r
89 case L'Y':\r
90 gST->ConOut->OutputString (gST->ConOut, L"Y\n");\r
91 return EFI_SUCCESS;\r
92\r
93 //\r
94 // fall through\r
95 //\r
96 case L'n':\r
97 case L'N':\r
98 gST->ConOut->OutputString (gST->ConOut, L"N\n");\r
99 return EFI_NOT_FOUND;\r
100 }\r
101\r
102 }\r
103 }\r
104}\r
105\r
ed72955c 106/**\r
107 Allows the user to set controller specific options for a controller that a \r
108 driver is currently managing.\r
109\r
110 @param This A pointer to the EFI_DRIVER_CONFIGURATION_ PROTOCOL\r
111 instance.\r
112 @param ControllerHandle The handle of the controller to set options on.\r
113 @param ChildHandle The handle of the child controller to set options on.\r
114 This is an optional parameter that may be NULL.\r
115 It will be NULL for device drivers, and for a bus drivers\r
116 that wish to set options for the bus controller.\r
117 It will not be NULL for a bus driver that wishes to set\r
118 options for one of its child controllers.\r
119 @param Language A pointer to a three character ISO 639-2 language\r
120 identifier. This is the language of the user interface\r
121 that should be presented to the user, and it must match\r
122 one of the languages specified in SupportedLanguages.\r
123 The number of languages supported by a driver is up to\r
124 the driver writer.\r
125 @param ActionRequired A pointer to the action that the calling agent is\r
126 required to perform when this function returns.\r
127 See "Related Definitions" for a list of the actions that\r
128 the calling agent is required to perform prior to\r
129 accessing ControllerHandle again.\r
130\r
131 @retval EFI_SUCCESS The driver specified by This successfully set the\r
132 configuration options for the controller specified\r
133 by ControllerHandle..\r
134 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.\r
135 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a\r
136 valid EFI_HANDLE.\r
137 @retval EFI_INVALID_PARAMETER ActionRequired is NULL.\r
138 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
139 setting configuration options for the controller\r
140 specified by ControllerHandle and ChildHandle.\r
141 @retval EFI_UNSUPPORTED The driver specified by This does not support the\r
142 language specified by Language.\r
143 @retval EFI_DEVICE_ERROR A device error occurred while attempt to set the\r
144 configuration options for the controller specified\r
145 by ControllerHandle and ChildHandle.\r
146 @retval EFI_OUT_RESOURCES There are not enough resources available to set the\r
147 configuration options for the controller specified\r
148 by ControllerHandle and ChildHandle.\r
149\r
150**/\r
878ddf1f 151EFI_STATUS\r
152IDEBusDriverConfigurationSetOptions (\r
153 IN EFI_DRIVER_CONFIGURATION_PROTOCOL *This,\r
154 IN EFI_HANDLE ControllerHandle,\r
155 IN EFI_HANDLE ChildHandle OPTIONAL,\r
156 IN CHAR8 *Language,\r
157 OUT EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED *ActionRequired\r
158 )\r
878ddf1f 159{\r
160 EFI_STATUS Status;\r
161 UINT8 Value;\r
162 UINT8 NewValue;\r
163 UINTN DataSize;\r
164 UINTN Index;\r
878ddf1f 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
6874dbd0 176 NULL,\r
878ddf1f 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
1cc8ee78 194 NewValue = (UINT8) (NewValue | (1 << Index));\r
878ddf1f 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
878ddf1f 258\r
259 if (ChildHandle != NULL) {\r
260 return EFI_UNSUPPORTED;\r
261 }\r
262\r
263 DataSize = sizeof (Value);\r
264 Status = gRT->GetVariable (\r
265 L"Configuration",\r
266 &gEfiCallerIdGuid,\r
6874dbd0 267 NULL,\r
878ddf1f 268 &DataSize,\r
269 &Value\r
270 );\r
271 if (EFI_ERROR (Status) || Value > 0x0f) {\r
272 return EFI_DEVICE_ERROR;\r
273 }\r
274\r
275 return EFI_SUCCESS;\r
276}\r
277\r
ed72955c 278/**\r
279 Forces a driver to set the default configuration options for a controller.\r
280\r
281 @param This A pointer to the EFI_DRIVER_CONFIGURATION_ PROTOCOL\r
282 instance.\r
283 @param ControllerHandle The handle of the controller to force default\r
284 configuration options on.\r
285 @param ChildHandle The handle of the child controller to force default\r
286 configuration options on This is an optional parameter\r
287 that may be NULL. It will be NULL for device drivers.\r
288 It will also be NULL for a bus drivers that wish to\r
289 force default configuration options for the bus\r
290 controller. It will not be NULL for a bus driver that\r
291 wishes to force default configuration options for one\r
292 of its child controllers.\r
293 @param DefaultType The type of default configuration options to force on\r
294 the controller specified by ControllerHandle and\r
295 ChildHandle. See Table 9-1 for legal values.\r
296 A DefaultType of 0x00000000 must be supported\r
297 by this protocol.\r
298 @param ActionRequired A pointer to the action that the calling agent\r
299 is required to perform when this function returns.\r
300\r
301 @retval EFI_SUCCESS The driver specified by This successfully forced\r
302 the default configuration options on the\r
303 controller specified by ControllerHandle and\r
304 ChildHandle.\r
305 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.\r
306 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a\r
307 valid EFI_HANDLE.\r
308 @retval EFI_INVALID_PARAMETER ActionRequired is NULL.\r
309 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
310 forcing the default configuration options on\r
311 the controller specified by ControllerHandle\r
312 and ChildHandle.\r
313 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
314 the configuration type specified by DefaultType.\r
315 @retval EFI_DEVICE_ERROR A device error occurred while attempt to force\r
316 the default configuration options on the controller\r
317 specified by ControllerHandle and ChildHandle.\r
318 @retval EFI_OUT_RESOURCES There are not enough resources available to force\r
319 the default configuration options on the controller\r
320 specified by ControllerHandle and ChildHandle.\r
321\r
322**/\r
878ddf1f 323EFI_STATUS\r
324IDEBusDriverConfigurationForceDefaults (\r
325 IN EFI_DRIVER_CONFIGURATION_PROTOCOL *This,\r
326 IN EFI_HANDLE ControllerHandle,\r
327 IN EFI_HANDLE ChildHandle OPTIONAL,\r
328 IN UINT32 DefaultType,\r
329 OUT EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED *ActionRequired\r
330 )\r
878ddf1f 331{\r
332 UINT8 Value;\r
333\r
334 if (ChildHandle != NULL) {\r
335 return EFI_UNSUPPORTED;\r
336 }\r
337\r
338 Value = 0x0f;\r
339 gRT->SetVariable (\r
340 L"Configuration",\r
341 &gEfiCallerIdGuid,\r
342 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
343 sizeof (Value),\r
344 &Value\r
345 );\r
346 *ActionRequired = EfiDriverConfigurationActionRestartController;\r
347 return EFI_SUCCESS;\r
348}\r