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