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