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