]>
Commit | Line | Data |
---|---|---|
1 | /*++ @file\r | |
2 | \r | |
3 | Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>\r | |
4 | Portions copyright (c) 2010,Apple Inc. All rights reserved.<BR>\r | |
5 | This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | \r | |
14 | **/\r | |
15 | \r | |
16 | #include "Gop.h"\r | |
17 | \r | |
18 | \r | |
19 | EFI_STATUS\r | |
20 | FreeNotifyList (\r | |
21 | IN OUT LIST_ENTRY *ListHead\r | |
22 | )\r | |
23 | /*++\r | |
24 | \r | |
25 | Routine Description:\r | |
26 | \r | |
27 | Arguments:\r | |
28 | \r | |
29 | ListHead - The list head\r | |
30 | \r | |
31 | Returns:\r | |
32 | \r | |
33 | EFI_SUCCESS - Free the notify list successfully\r | |
34 | EFI_INVALID_PARAMETER - ListHead is invalid.\r | |
35 | \r | |
36 | **/\r | |
37 | {\r | |
38 | EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY *NotifyNode;\r | |
39 | \r | |
40 | if (ListHead == NULL) {\r | |
41 | return EFI_INVALID_PARAMETER;\r | |
42 | }\r | |
43 | while (!IsListEmpty (ListHead)) {\r | |
44 | NotifyNode = CR (\r | |
45 | ListHead->ForwardLink,\r | |
46 | EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY,\r | |
47 | NotifyEntry,\r | |
48 | EMU_GOP_SIMPLE_TEXTIN_EX_NOTIFY_SIGNATURE\r | |
49 | );\r | |
50 | RemoveEntryList (ListHead->ForwardLink);\r | |
51 | gBS->FreePool (NotifyNode);\r | |
52 | }\r | |
53 | \r | |
54 | return EFI_SUCCESS;\r | |
55 | }\r | |
56 | \r | |
57 | \r | |
58 | /**\r | |
59 | Tests to see if this driver supports a given controller. If a child device is provided,\r | |
60 | it further tests to see if this driver supports creating a handle for the specified child device.\r | |
61 | \r | |
62 | This function checks to see if the driver specified by This supports the device specified by\r | |
63 | ControllerHandle. Drivers will typically use the device path attached to\r | |
64 | ControllerHandle and/or the services from the bus I/O abstraction attached to\r | |
65 | ControllerHandle to determine if the driver supports ControllerHandle. This function\r | |
66 | may be called many times during platform initialization. In order to reduce boot times, the tests\r | |
67 | performed by this function must be very small, and take as little time as possible to execute. This\r | |
68 | function must not change the state of any hardware devices, and this function must be aware that the\r | |
69 | device specified by ControllerHandle may already be managed by the same driver or a\r | |
70 | different driver. This function must match its calls to AllocatePages() with FreePages(),\r | |
71 | AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().\r | |
72 | Because ControllerHandle may have been previously started by the same driver, if a protocol is\r | |
73 | already in the opened state, then it must not be closed with CloseProtocol(). This is required\r | |
74 | to guarantee the state of ControllerHandle is not modified by this function.\r | |
75 | \r | |
76 | @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r | |
77 | @param[in] ControllerHandle The handle of the controller to test. This handle\r | |
78 | must support a protocol interface that supplies\r | |
79 | an I/O abstraction to the driver.\r | |
80 | @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This\r | |
81 | parameter is ignored by device drivers, and is optional for bus\r | |
82 | drivers. For bus drivers, if this parameter is not NULL, then\r | |
83 | the bus driver must determine if the bus controller specified\r | |
84 | by ControllerHandle and the child controller specified\r | |
85 | by RemainingDevicePath are both supported by this\r | |
86 | bus driver.\r | |
87 | \r | |
88 | @retval EFI_SUCCESS The device specified by ControllerHandle and\r | |
89 | RemainingDevicePath is supported by the driver specified by This.\r | |
90 | @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and\r | |
91 | RemainingDevicePath is already being managed by the driver\r | |
92 | specified by This.\r | |
93 | @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and\r | |
94 | RemainingDevicePath is already being managed by a different\r | |
95 | driver or an application that requires exclusive access.\r | |
96 | Currently not implemented.\r | |
97 | @retval EFI_UNSUPPORTED The device specified by ControllerHandle and\r | |
98 | RemainingDevicePath is not supported by the driver specified by This.\r | |
99 | **/\r | |
100 | EFI_STATUS\r | |
101 | EFIAPI\r | |
102 | EmuGopDriverBindingSupported (\r | |
103 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
104 | IN EFI_HANDLE Handle,\r | |
105 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
106 | )\r | |
107 | {\r | |
108 | EFI_STATUS Status;\r | |
109 | EMU_IO_THUNK_PROTOCOL *EmuIoThunk;\r | |
110 | \r | |
111 | //\r | |
112 | // Open the IO Abstraction(s) needed to perform the supported test\r | |
113 | //\r | |
114 | Status = gBS->OpenProtocol (\r | |
115 | Handle,\r | |
116 | &gEmuIoThunkProtocolGuid,\r | |
117 | (VOID **)&EmuIoThunk,\r | |
118 | This->DriverBindingHandle,\r | |
119 | Handle,\r | |
120 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
121 | );\r | |
122 | if (EFI_ERROR (Status)) {\r | |
123 | return Status;\r | |
124 | }\r | |
125 | \r | |
126 | Status = EmuGopSupported (EmuIoThunk);\r | |
127 | \r | |
128 | //\r | |
129 | // Close the I/O Abstraction(s) used to perform the supported test\r | |
130 | //\r | |
131 | gBS->CloseProtocol (\r | |
132 | Handle,\r | |
133 | &gEmuIoThunkProtocolGuid,\r | |
134 | This->DriverBindingHandle,\r | |
135 | Handle\r | |
136 | );\r | |
137 | \r | |
138 | return Status;\r | |
139 | }\r | |
140 | \r | |
141 | \r | |
142 | /**\r | |
143 | Starts a device controller or a bus controller.\r | |
144 | \r | |
145 | The Start() function is designed to be invoked from the EFI boot service ConnectController().\r | |
146 | As a result, much of the error checking on the parameters to Start() has been moved into this\r | |
147 | common boot service. It is legal to call Start() from other locations,\r | |
148 | but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r | |
149 | 1. ControllerHandle must be a valid EFI_HANDLE.\r | |
150 | 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned\r | |
151 | EFI_DEVICE_PATH_PROTOCOL.\r | |
152 | 3. Prior to calling Start(), the Supported() function for the driver specified by This must\r | |
153 | have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.\r | |
154 | \r | |
155 | @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r | |
156 | @param[in] ControllerHandle The handle of the controller to start. This handle\r | |
157 | must support a protocol interface that supplies\r | |
158 | an I/O abstraction to the driver.\r | |
159 | @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This\r | |
160 | parameter is ignored by device drivers, and is optional for bus\r | |
161 | drivers. For a bus driver, if this parameter is NULL, then handles\r | |
162 | for all the children of Controller are created by this driver.\r | |
163 | If this parameter is not NULL and the first Device Path Node is\r | |
164 | not the End of Device Path Node, then only the handle for the\r | |
165 | child device specified by the first Device Path Node of\r | |
166 | RemainingDevicePath is created by this driver.\r | |
167 | If the first Device Path Node of RemainingDevicePath is\r | |
168 | the End of Device Path Node, no child handle is created by this\r | |
169 | driver.\r | |
170 | \r | |
171 | @retval EFI_SUCCESS The device was started.\r | |
172 | @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.\r | |
173 | @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r | |
174 | @retval Others The driver failded to start the device.\r | |
175 | \r | |
176 | **/\r | |
177 | EFI_STATUS\r | |
178 | EFIAPI\r | |
179 | EmuGopDriverBindingStart (\r | |
180 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
181 | IN EFI_HANDLE Handle,\r | |
182 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
183 | )\r | |
184 | {\r | |
185 | EMU_IO_THUNK_PROTOCOL *EmuIoThunk;\r | |
186 | EFI_STATUS Status;\r | |
187 | GOP_PRIVATE_DATA *Private;\r | |
188 | \r | |
189 | //\r | |
190 | // Grab the protocols we need\r | |
191 | //\r | |
192 | Status = gBS->OpenProtocol (\r | |
193 | Handle,\r | |
194 | &gEmuIoThunkProtocolGuid,\r | |
195 | (VOID **)&EmuIoThunk,\r | |
196 | This->DriverBindingHandle,\r | |
197 | Handle,\r | |
198 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
199 | );\r | |
200 | if (EFI_ERROR (Status)) {\r | |
201 | return EFI_UNSUPPORTED;\r | |
202 | }\r | |
203 | \r | |
204 | //\r | |
205 | // Allocate Private context data for SGO inteface.\r | |
206 | //\r | |
207 | Private = NULL;\r | |
208 | Status = gBS->AllocatePool (\r | |
209 | EfiBootServicesData,\r | |
210 | sizeof (GOP_PRIVATE_DATA),\r | |
211 | (VOID **)&Private\r | |
212 | );\r | |
213 | if (EFI_ERROR (Status)) {\r | |
214 | goto Done;\r | |
215 | }\r | |
216 | //\r | |
217 | // Set up context record\r | |
218 | //\r | |
219 | Private->Signature = GOP_PRIVATE_DATA_SIGNATURE;\r | |
220 | Private->Handle = Handle;\r | |
221 | Private->EmuIoThunk = EmuIoThunk;\r | |
222 | Private->WindowName = EmuIoThunk->ConfigString;\r | |
223 | Private->ControllerNameTable = NULL;\r | |
224 | \r | |
225 | AddUnicodeString (\r | |
226 | "eng",\r | |
227 | gEmuGopComponentName.SupportedLanguages,\r | |
228 | &Private->ControllerNameTable,\r | |
229 | EmuIoThunk->ConfigString\r | |
230 | );\r | |
231 | AddUnicodeString2 (\r | |
232 | "en",\r | |
233 | gEmuGopComponentName2.SupportedLanguages,\r | |
234 | &Private->ControllerNameTable,\r | |
235 | EmuIoThunk->ConfigString,\r | |
236 | FALSE\r | |
237 | );\r | |
238 | \r | |
239 | Status = EmuGopConstructor (Private);\r | |
240 | if (EFI_ERROR (Status)) {\r | |
241 | goto Done;\r | |
242 | }\r | |
243 | //\r | |
244 | // Publish the Gop interface to the world\r | |
245 | //\r | |
246 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
247 | &Private->Handle,\r | |
248 | &gEfiGraphicsOutputProtocolGuid, &Private->GraphicsOutput,\r | |
249 | &gEfiSimpleTextInProtocolGuid, &Private->SimpleTextIn,\r | |
250 | &gEfiSimplePointerProtocolGuid, &Private->SimplePointer,\r | |
251 | &gEfiSimpleTextInputExProtocolGuid, &Private->SimpleTextInEx,\r | |
252 | NULL\r | |
253 | );\r | |
254 | \r | |
255 | Done:\r | |
256 | if (EFI_ERROR (Status)) {\r | |
257 | \r | |
258 | gBS->CloseProtocol (\r | |
259 | Handle,\r | |
260 | &gEmuIoThunkProtocolGuid,\r | |
261 | This->DriverBindingHandle,\r | |
262 | Handle\r | |
263 | );\r | |
264 | \r | |
265 | if (Private != NULL) {\r | |
266 | //\r | |
267 | // On Error Free back private data\r | |
268 | //\r | |
269 | if (Private->ControllerNameTable != NULL) {\r | |
270 | FreeUnicodeStringTable (Private->ControllerNameTable);\r | |
271 | }\r | |
272 | if (Private->SimpleTextIn.WaitForKey != NULL) {\r | |
273 | gBS->CloseEvent (Private->SimpleTextIn.WaitForKey);\r | |
274 | }\r | |
275 | if (Private->SimpleTextInEx.WaitForKeyEx != NULL) {\r | |
276 | gBS->CloseEvent (Private->SimpleTextInEx.WaitForKeyEx);\r | |
277 | }\r | |
278 | FreeNotifyList (&Private->NotifyList);\r | |
279 | \r | |
280 | gBS->FreePool (Private);\r | |
281 | }\r | |
282 | }\r | |
283 | \r | |
284 | return Status;\r | |
285 | }\r | |
286 | \r | |
287 | \r | |
288 | \r | |
289 | /**\r | |
290 | Stops a device controller or a bus controller.\r | |
291 | \r | |
292 | The Stop() function is designed to be invoked from the EFI boot service DisconnectController().\r | |
293 | As a result, much of the error checking on the parameters to Stop() has been moved\r | |
294 | into this common boot service. It is legal to call Stop() from other locations,\r | |
295 | but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r | |
296 | 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this\r | |
297 | same driver's Start() function.\r | |
298 | 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid\r | |
299 | EFI_HANDLE. In addition, all of these handles must have been created in this driver's\r | |
300 | Start() function, and the Start() function must have called OpenProtocol() on\r | |
301 | ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r | |
302 | \r | |
303 | @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r | |
304 | @param[in] ControllerHandle A handle to the device being stopped. The handle must\r | |
305 | support a bus specific I/O protocol for the driver\r | |
306 | to use to stop the device.\r | |
307 | @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.\r | |
308 | @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL\r | |
309 | if NumberOfChildren is 0.\r | |
310 | \r | |
311 | @retval EFI_SUCCESS The device was stopped.\r | |
312 | @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.\r | |
313 | \r | |
314 | **/\r | |
315 | EFI_STATUS\r | |
316 | EFIAPI\r | |
317 | EmuGopDriverBindingStop (\r | |
318 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
319 | IN EFI_HANDLE Handle,\r | |
320 | IN UINTN NumberOfChildren,\r | |
321 | IN EFI_HANDLE *ChildHandleBuffer\r | |
322 | )\r | |
323 | {\r | |
324 | EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;\r | |
325 | EFI_STATUS Status;\r | |
326 | GOP_PRIVATE_DATA *Private;\r | |
327 | \r | |
328 | Status = gBS->OpenProtocol (\r | |
329 | Handle,\r | |
330 | &gEfiGraphicsOutputProtocolGuid,\r | |
331 | (VOID **)&GraphicsOutput,\r | |
332 | This->DriverBindingHandle,\r | |
333 | Handle,\r | |
334 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
335 | );\r | |
336 | if (EFI_ERROR (Status)) {\r | |
337 | //\r | |
338 | // If the GOP interface does not exist the driver is not started\r | |
339 | //\r | |
340 | return EFI_NOT_STARTED;\r | |
341 | }\r | |
342 | \r | |
343 | //\r | |
344 | // Get our private context information\r | |
345 | //\r | |
346 | Private = GOP_PRIVATE_DATA_FROM_THIS (GraphicsOutput);\r | |
347 | \r | |
348 | //\r | |
349 | // Remove the SGO interface from the system\r | |
350 | //\r | |
351 | Status = gBS->UninstallMultipleProtocolInterfaces (\r | |
352 | Private->Handle,\r | |
353 | &gEfiGraphicsOutputProtocolGuid, &Private->GraphicsOutput,\r | |
354 | &gEfiSimpleTextInProtocolGuid, &Private->SimpleTextIn,\r | |
355 | &gEfiSimplePointerProtocolGuid, &Private->SimplePointer,\r | |
356 | &gEfiSimpleTextInputExProtocolGuid, &Private->SimpleTextInEx,\r | |
357 | NULL\r | |
358 | );\r | |
359 | if (!EFI_ERROR (Status)) {\r | |
360 | //\r | |
361 | // Shutdown the hardware\r | |
362 | //\r | |
363 | Status = EmuGopDestructor (Private);\r | |
364 | if (EFI_ERROR (Status)) {\r | |
365 | return EFI_DEVICE_ERROR;\r | |
366 | }\r | |
367 | \r | |
368 | gBS->CloseProtocol (\r | |
369 | Handle,\r | |
370 | &gEmuIoThunkProtocolGuid,\r | |
371 | This->DriverBindingHandle,\r | |
372 | Handle\r | |
373 | );\r | |
374 | \r | |
375 | //\r | |
376 | // Free our instance data\r | |
377 | //\r | |
378 | FreeUnicodeStringTable (Private->ControllerNameTable);\r | |
379 | \r | |
380 | Status = gBS->CloseEvent (Private->SimpleTextIn.WaitForKey);\r | |
381 | ASSERT_EFI_ERROR (Status);\r | |
382 | \r | |
383 | Status = gBS->CloseEvent (Private->SimpleTextInEx.WaitForKeyEx);\r | |
384 | ASSERT_EFI_ERROR (Status);\r | |
385 | \r | |
386 | FreeNotifyList (&Private->NotifyList);\r | |
387 | \r | |
388 | gBS->FreePool (Private);\r | |
389 | \r | |
390 | }\r | |
391 | \r | |
392 | return Status;\r | |
393 | }\r | |
394 | \r | |
395 | \r | |
396 | ///\r | |
397 | /// This protocol provides the services required to determine if a driver supports a given controller.\r | |
398 | /// If a controller is supported, then it also provides routines to start and stop the controller.\r | |
399 | ///\r | |
400 | EFI_DRIVER_BINDING_PROTOCOL gEmuGopDriverBinding = {\r | |
401 | EmuGopDriverBindingSupported,\r | |
402 | EmuGopDriverBindingStart,\r | |
403 | EmuGopDriverBindingStop,\r | |
404 | 0xa,\r | |
405 | NULL,\r | |
406 | NULL\r | |
407 | };\r | |
408 | \r | |
409 | \r | |
410 | \r | |
411 | /**\r | |
412 | The user Entry Point for module EmuGop. The user code starts with this function.\r | |
413 | \r | |
414 | @param[in] ImageHandle The firmware allocated handle for the EFI image.\r | |
415 | @param[in] SystemTable A pointer to the EFI System Table.\r | |
416 | \r | |
417 | @retval EFI_SUCCESS The entry point is executed successfully.\r | |
418 | @retval other Some error occurs when executing this entry point.\r | |
419 | \r | |
420 | **/\r | |
421 | EFI_STATUS\r | |
422 | EFIAPI\r | |
423 | InitializeEmuGop (\r | |
424 | IN EFI_HANDLE ImageHandle,\r | |
425 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
426 | )\r | |
427 | {\r | |
428 | EFI_STATUS Status;\r | |
429 | \r | |
430 | Status = EfiLibInstallDriverBindingComponentName2 (\r | |
431 | ImageHandle,\r | |
432 | SystemTable,\r | |
433 | &gEmuGopDriverBinding,\r | |
434 | ImageHandle,\r | |
435 | &gEmuGopComponentName,\r | |
436 | &gEmuGopComponentName2\r | |
437 | );\r | |
438 | ASSERT_EFI_ERROR (Status);\r | |
439 | \r | |
440 | \r | |
441 | return Status;\r | |
442 | }\r | |
443 | \r |