]> git.proxmox.com Git - mirror_edk2.git/blame - UnixPkg/UnixGopDxe/UnixGopDriver.c
Update for NetworkPkg.
[mirror_edk2.git] / UnixPkg / UnixGopDxe / UnixGopDriver.c
CommitLineData
2ff79f2e 1/*++\r
2\r
3Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>\r
1b7edf0f 4Portions copyright (c) 2010, Apple, Inc. All rights reserved.<BR>\r
2ff79f2e 5This program and the accompanying materials \r
6are licensed and made available under the terms and conditions of the BSD License \r
7which accompanies this distribution. The full text of the license may be found at \r
8http://opensource.org/licenses/bsd-license.php \r
9 \r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
12\r
13Module Name:\r
14\r
15 UnixGopDriver.c\r
16\r
17Abstract:\r
18\r
19 This file implements the EFI 1.1 Device Driver model requirements for UGA\r
20\r
21 UGA is short hand for Universal Graphics Abstraction protocol.\r
22\r
23 This file is a verision of UgaIo the uses UnixThunk system calls as an IO \r
24 abstraction. For a PCI device UnixIo would be replaced with\r
25 a PCI IO abstraction that abstracted a specific PCI device. \r
26\r
27--*/\r
28\r
29#include "UnixGop.h"\r
30\r
31\r
32EFI_STATUS\r
33FreeNotifyList (\r
34 IN OUT LIST_ENTRY *ListHead\r
35 )\r
36/*++\r
37\r
38Routine Description:\r
39\r
40Arguments:\r
41\r
42 ListHead - The list head\r
43\r
44Returns:\r
45\r
46 EFI_SUCCESS - Free the notify list successfully\r
47 EFI_INVALID_PARAMETER - ListHead is invalid.\r
48\r
49--*/\r
50{\r
51 UNIX_GOP_SIMPLE_TEXTIN_EX_NOTIFY *NotifyNode;\r
52\r
53 if (ListHead == NULL) {\r
54 return EFI_INVALID_PARAMETER;\r
55 }\r
56 while (!IsListEmpty (ListHead)) {\r
57 NotifyNode = CR (\r
58 ListHead->ForwardLink, \r
59 UNIX_GOP_SIMPLE_TEXTIN_EX_NOTIFY, \r
60 NotifyEntry, \r
61 UNIX_GOP_SIMPLE_TEXTIN_EX_NOTIFY_SIGNATURE\r
62 );\r
63 RemoveEntryList (ListHead->ForwardLink);\r
64 gBS->FreePool (NotifyNode);\r
65 }\r
66 \r
67 return EFI_SUCCESS;\r
68}\r
69\r
70\r
71EFI_STATUS\r
72EFIAPI\r
73UnixGopDriverBindingSupported (\r
74 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
75 IN EFI_HANDLE Handle,\r
76 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
77 )\r
78/*++\r
79\r
80Routine Description:\r
81\r
82Arguments:\r
83\r
84Returns:\r
85\r
86 None\r
87\r
88--*/\r
89// TODO: This - add argument and description to function comment\r
90// TODO: Handle - add argument and description to function comment\r
91// TODO: RemainingDevicePath - add argument and description to function comment\r
92{\r
93 EFI_STATUS Status;\r
94 EFI_UNIX_IO_PROTOCOL *UnixIo;\r
95\r
96 //\r
97 // Open the IO Abstraction(s) needed to perform the supported test\r
98 //\r
99 Status = gBS->OpenProtocol (\r
100 Handle,\r
101 &gEfiUnixIoProtocolGuid,\r
102 (VOID **)&UnixIo,\r
103 This->DriverBindingHandle,\r
104 Handle,\r
105 EFI_OPEN_PROTOCOL_BY_DRIVER\r
106 );\r
107 if (EFI_ERROR (Status)) {\r
108 return Status;\r
109 }\r
110\r
111 Status = UnixGopSupported (UnixIo);\r
112\r
113 //\r
114 // Close the I/O Abstraction(s) used to perform the supported test\r
115 //\r
116 gBS->CloseProtocol (\r
117 Handle,\r
118 &gEfiUnixIoProtocolGuid,\r
119 This->DriverBindingHandle,\r
120 Handle\r
121 );\r
122\r
123 return Status;\r
124}\r
125\r
126EFI_STATUS\r
127EFIAPI\r
128UnixGopDriverBindingStart (\r
129 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
130 IN EFI_HANDLE Handle,\r
131 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
132 )\r
133/*++\r
134\r
135Routine Description:\r
136\r
137Arguments:\r
138\r
139Returns:\r
140\r
141 None\r
142\r
143--*/\r
144// TODO: This - add argument and description to function comment\r
145// TODO: Handle - add argument and description to function comment\r
146// TODO: RemainingDevicePath - add argument and description to function comment\r
147// TODO: EFI_UNSUPPORTED - add return value to function comment\r
148{\r
149 EFI_UNIX_IO_PROTOCOL *UnixIo;\r
150 EFI_STATUS Status;\r
151 GOP_PRIVATE_DATA *Private;\r
152\r
153 //\r
154 // Grab the protocols we need\r
155 //\r
156 Status = gBS->OpenProtocol (\r
157 Handle,\r
158 &gEfiUnixIoProtocolGuid,\r
159 (VOID **)&UnixIo,\r
160 This->DriverBindingHandle,\r
161 Handle,\r
162 EFI_OPEN_PROTOCOL_BY_DRIVER\r
163 );\r
164 if (EFI_ERROR (Status)) {\r
165 return EFI_UNSUPPORTED;\r
166 }\r
167\r
168 //\r
169 // Allocate Private context data for SGO inteface.\r
170 //\r
171 Private = NULL;\r
172 Status = gBS->AllocatePool (\r
173 EfiBootServicesData,\r
174 sizeof (GOP_PRIVATE_DATA),\r
175 (VOID **)&Private\r
176 );\r
177 if (EFI_ERROR (Status)) {\r
178 goto Done;\r
179 }\r
180 //\r
181 // Set up context record\r
182 //\r
183 Private->Signature = GOP_PRIVATE_DATA_SIGNATURE;\r
184 Private->Handle = Handle;\r
185 Private->UnixThunk = UnixIo->UnixThunk;\r
186\r
187 Private->ControllerNameTable = NULL;\r
188\r
189 AddUnicodeString (\r
190 "eng",\r
191 gUnixGopComponentName.SupportedLanguages,\r
192 &Private->ControllerNameTable,\r
193 UnixIo->EnvString\r
194 );\r
195 AddUnicodeString2 (\r
196 "en",\r
197 gUnixGopComponentName2.SupportedLanguages,\r
198 &Private->ControllerNameTable,\r
199 UnixIo->EnvString,\r
200 FALSE\r
201 );\r
202\r
203 Private->WindowName = UnixIo->EnvString;\r
204\r
205 Status = UnixGopConstructor (Private);\r
206 if (EFI_ERROR (Status)) {\r
207 goto Done;\r
208 }\r
209 //\r
210 // Publish the Gop interface to the world\r
211 //\r
212 Status = gBS->InstallMultipleProtocolInterfaces (\r
213 &Private->Handle,\r
214 &gEfiGraphicsOutputProtocolGuid, &Private->GraphicsOutput,\r
215 &gEfiSimpleTextInProtocolGuid, &Private->SimpleTextIn,\r
216 &gEfiSimplePointerProtocolGuid, &Private->SimplePointer,\r
217// &gEfiSimpleTextInputExProtocolGuid, &Private->SimpleTextInEx,\r
218 NULL\r
219 );\r
220\r
221Done:\r
222 if (EFI_ERROR (Status)) {\r
223\r
224 gBS->CloseProtocol (\r
225 Handle,\r
226 &gEfiUnixIoProtocolGuid,\r
227 This->DriverBindingHandle,\r
228 Handle\r
229 );\r
230\r
231 if (Private != NULL) {\r
232 //\r
233 // On Error Free back private data\r
234 //\r
235 if (Private->ControllerNameTable != NULL) {\r
236 FreeUnicodeStringTable (Private->ControllerNameTable);\r
237 }\r
238 if (Private->SimpleTextIn.WaitForKey != NULL) {\r
239 gBS->CloseEvent (Private->SimpleTextIn.WaitForKey);\r
240 }\r
241 if (Private->SimpleTextInEx.WaitForKeyEx != NULL) {\r
242 gBS->CloseEvent (Private->SimpleTextInEx.WaitForKeyEx);\r
243 }\r
244 FreeNotifyList (&Private->NotifyList);\r
245\r
246 gBS->FreePool (Private);\r
247 }\r
248 }\r
249\r
250 return Status;\r
251}\r
252\r
253EFI_STATUS\r
254EFIAPI\r
255UnixGopDriverBindingStop (\r
256 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
257 IN EFI_HANDLE Handle,\r
258 IN UINTN NumberOfChildren,\r
259 IN EFI_HANDLE *ChildHandleBuffer\r
260 )\r
261/*++\r
262\r
263Routine Description:\r
264\r
265Arguments:\r
266\r
267Returns:\r
268\r
269 None\r
270\r
271--*/\r
272// TODO: This - add argument and description to function comment\r
273// TODO: Handle - add argument and description to function comment\r
274// TODO: NumberOfChildren - add argument and description to function comment\r
275// TODO: ChildHandleBuffer - add argument and description to function comment\r
276// TODO: EFI_NOT_STARTED - add return value to function comment\r
277// TODO: EFI_DEVICE_ERROR - add return value to function comment\r
278{\r
279 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;\r
280 EFI_STATUS Status;\r
281 GOP_PRIVATE_DATA *Private;\r
282\r
283 Status = gBS->OpenProtocol (\r
284 Handle,\r
285 &gEfiGraphicsOutputProtocolGuid,\r
286 (VOID **)&GraphicsOutput,\r
287 This->DriverBindingHandle,\r
288 Handle,\r
289 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
290 );\r
291 if (EFI_ERROR (Status)) {\r
292 //\r
293 // If the GOP interface does not exist the driver is not started\r
294 //\r
295 return EFI_NOT_STARTED;\r
296 }\r
297\r
298 //\r
299 // Get our private context information\r
300 //\r
301 Private = GOP_PRIVATE_DATA_FROM_THIS (GraphicsOutput);\r
302\r
303 //\r
304 // Remove the SGO interface from the system\r
305 //\r
306 Status = gBS->UninstallMultipleProtocolInterfaces (\r
307 Private->Handle,\r
308 &gEfiGraphicsOutputProtocolGuid, &Private->GraphicsOutput,\r
309 &gEfiSimpleTextInProtocolGuid, &Private->SimpleTextIn,\r
310 &gEfiSimplePointerProtocolGuid, &Private->SimplePointer,\r
311// &gEfiSimpleTextInputExProtocolGuid, &Private->SimpleTextInEx,\r
312 NULL\r
313 );\r
314 if (!EFI_ERROR (Status)) {\r
315 //\r
316 // Shutdown the hardware\r
317 //\r
318 Status = UnixGopDestructor (Private);\r
319 if (EFI_ERROR (Status)) {\r
320 return EFI_DEVICE_ERROR;\r
321 }\r
322\r
323 gBS->CloseProtocol (\r
324 Handle,\r
325 &gEfiUnixIoProtocolGuid,\r
326 This->DriverBindingHandle,\r
327 Handle\r
328 );\r
329\r
330 //\r
331 // Free our instance data\r
332 //\r
333 FreeUnicodeStringTable (Private->ControllerNameTable);\r
334 \r
335 Status = gBS->CloseEvent (Private->SimpleTextIn.WaitForKey);\r
336 ASSERT_EFI_ERROR (Status);\r
337 \r
338 Status = gBS->CloseEvent (Private->SimpleTextInEx.WaitForKeyEx);\r
339 ASSERT_EFI_ERROR (Status);\r
340 \r
341 FreeNotifyList (&Private->NotifyList);\r
342\r
343 gBS->FreePool (Private);\r
344\r
345 }\r
346\r
347 return Status;\r
348}\r
349\r
350\r
351\r
352\r
353EFI_DRIVER_BINDING_PROTOCOL gUnixGopDriverBinding = {\r
354 UnixGopDriverBindingSupported,\r
355 UnixGopDriverBindingStart,\r
356 UnixGopDriverBindingStop,\r
357 0xa,\r
358 NULL,\r
359 NULL\r
360};\r
361\r
362\r
363\r
364/**\r
365 The user Entry Point for module UnixGop. The user code starts with this function.\r
366\r
367 @param[in] ImageHandle The firmware allocated handle for the EFI image. \r
368 @param[in] SystemTable A pointer to the EFI System Table.\r
369 \r
370 @retval EFI_SUCCESS The entry point is executed successfully.\r
371 @retval other Some error occurs when executing this entry point.\r
372\r
373**/\r
374EFI_STATUS\r
375EFIAPI\r
376InitializeUnixGop (\r
377 IN EFI_HANDLE ImageHandle,\r
378 IN EFI_SYSTEM_TABLE *SystemTable\r
379 )\r
380{\r
381 EFI_STATUS Status;\r
382\r
383 Status = EfiLibInstallDriverBindingComponentName2 (\r
384 ImageHandle,\r
385 SystemTable,\r
386 &gUnixGopDriverBinding,\r
387 ImageHandle,\r
388 &gUnixGopComponentName,\r
389 &gUnixGopComponentName2\r
390 );\r
391 ASSERT_EFI_ERROR (Status);\r
392\r
393\r
394 return Status;\r
395}\r
396\r