]> git.proxmox.com Git - mirror_edk2.git/blob - UnixPkg/UnixUgaDxe/UnixUgaDriver.c
Update for NetworkPkg.
[mirror_edk2.git] / UnixPkg / UnixUgaDxe / UnixUgaDriver.c
1 /*++
2
3 Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13
14 UnixUgaDriver.c
15
16 Abstract:
17
18 This file implements the EFI 1.1 Device Driver model requirements for UGA
19
20 UGA is short hand for Universal Graphics Abstraction protocol.
21
22 This file is a verision of UgaIo the uses UnixThunk system calls as an IO
23 abstraction. For a PCI device UnixIo would be replaced with
24 a PCI IO abstraction that abstracted a specific PCI device.
25
26 --*/
27
28 #include "UnixUga.h"
29
30 EFI_DRIVER_BINDING_PROTOCOL gUnixUgaDriverBinding = {
31 UnixUgaDriverBindingSupported,
32 UnixUgaDriverBindingStart,
33 UnixUgaDriverBindingStop,
34 0xa,
35 NULL,
36 NULL
37 };
38
39
40 EFI_STATUS
41 EFIAPI
42 UnixUgaDriverBindingSupported (
43 IN EFI_DRIVER_BINDING_PROTOCOL *This,
44 IN EFI_HANDLE Handle,
45 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
46 )
47 /*++
48
49 Routine Description:
50
51 Arguments:
52
53 Returns:
54
55 None
56
57 --*/
58 // TODO: This - add argument and description to function comment
59 // TODO: Handle - add argument and description to function comment
60 // TODO: RemainingDevicePath - add argument and description to function comment
61 {
62 EFI_STATUS Status;
63 EFI_UNIX_IO_PROTOCOL *UnixIo;
64
65 //
66 // Open the IO Abstraction(s) needed to perform the supported test
67 //
68 Status = gBS->OpenProtocol (
69 Handle,
70 &gEfiUnixIoProtocolGuid,
71 (VOID **)&UnixIo,
72 This->DriverBindingHandle,
73 Handle,
74 EFI_OPEN_PROTOCOL_BY_DRIVER
75 );
76 if (EFI_ERROR (Status)) {
77 return Status;
78 }
79
80 Status = UnixUgaSupported (UnixIo);
81
82 //
83 // Close the I/O Abstraction(s) used to perform the supported test
84 //
85 gBS->CloseProtocol (
86 Handle,
87 &gEfiUnixIoProtocolGuid,
88 This->DriverBindingHandle,
89 Handle
90 );
91
92 return Status;
93 }
94
95 EFI_STATUS
96 EFIAPI
97 UnixUgaDriverBindingStart (
98 IN EFI_DRIVER_BINDING_PROTOCOL *This,
99 IN EFI_HANDLE Handle,
100 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
101 )
102 /*++
103
104 Routine Description:
105
106 Arguments:
107
108 Returns:
109
110 None
111
112 --*/
113 // TODO: This - add argument and description to function comment
114 // TODO: Handle - add argument and description to function comment
115 // TODO: RemainingDevicePath - add argument and description to function comment
116 // TODO: EFI_UNSUPPORTED - add return value to function comment
117 {
118 EFI_UNIX_IO_PROTOCOL *UnixIo;
119 EFI_STATUS Status;
120 UGA_PRIVATE_DATA *Private;
121
122 //
123 // Grab the protocols we need
124 //
125 Status = gBS->OpenProtocol (
126 Handle,
127 &gEfiUnixIoProtocolGuid,
128 (VOID **)&UnixIo,
129 This->DriverBindingHandle,
130 Handle,
131 EFI_OPEN_PROTOCOL_BY_DRIVER
132 );
133 if (EFI_ERROR (Status)) {
134 return EFI_UNSUPPORTED;
135 }
136
137 //
138 // Allocate Private context data for SGO inteface.
139 //
140 Private = NULL;
141 Status = gBS->AllocatePool (
142 EfiBootServicesData,
143 sizeof (UGA_PRIVATE_DATA),
144 (VOID **)&Private
145 );
146 if (EFI_ERROR (Status)) {
147 goto Done;
148 }
149 //
150 // Set up context record
151 //
152 Private->Signature = UGA_PRIVATE_DATA_SIGNATURE;
153 Private->Handle = Handle;
154 Private->UnixThunk = UnixIo->UnixThunk;
155
156 Private->ControllerNameTable = NULL;
157
158 AddUnicodeString (
159 "eng",
160 gUnixUgaComponentName.SupportedLanguages,
161 &Private->ControllerNameTable,
162 UnixIo->EnvString
163 );
164
165 Private->WindowName = UnixIo->EnvString;
166
167 Status = UnixUgaConstructor (Private);
168 if (EFI_ERROR (Status)) {
169 goto Done;
170 }
171 //
172 // Publish the Uga interface to the world
173 //
174 Status = gBS->InstallMultipleProtocolInterfaces (
175 &Private->Handle,
176 &gEfiUgaDrawProtocolGuid,
177 &Private->UgaDraw,
178 &gEfiSimpleTextInProtocolGuid,
179 &Private->SimpleTextIn,
180 &gEfiSimplePointerProtocolGuid,
181 &Private->SimplePointer,
182 NULL
183 );
184
185 Done:
186 if (EFI_ERROR (Status)) {
187
188 gBS->CloseProtocol (
189 Handle,
190 &gEfiUnixIoProtocolGuid,
191 This->DriverBindingHandle,
192 Handle
193 );
194
195 if (Private != NULL) {
196 //
197 // On Error Free back private data
198 //
199 if (Private->ControllerNameTable != NULL) {
200 FreeUnicodeStringTable (Private->ControllerNameTable);
201 }
202
203 gBS->FreePool (Private);
204 }
205 }
206
207 return Status;
208 }
209
210 EFI_STATUS
211 EFIAPI
212 UnixUgaDriverBindingStop (
213 IN EFI_DRIVER_BINDING_PROTOCOL *This,
214 IN EFI_HANDLE Handle,
215 IN UINTN NumberOfChildren,
216 IN EFI_HANDLE *ChildHandleBuffer
217 )
218 /*++
219
220 Routine Description:
221
222 Arguments:
223
224 Returns:
225
226 None
227
228 --*/
229 // TODO: This - add argument and description to function comment
230 // TODO: Handle - add argument and description to function comment
231 // TODO: NumberOfChildren - add argument and description to function comment
232 // TODO: ChildHandleBuffer - add argument and description to function comment
233 // TODO: EFI_NOT_STARTED - add return value to function comment
234 // TODO: EFI_DEVICE_ERROR - add return value to function comment
235 {
236 EFI_UGA_DRAW_PROTOCOL *UgaDraw;
237 EFI_STATUS Status;
238 UGA_PRIVATE_DATA *Private;
239
240 Status = gBS->OpenProtocol (
241 Handle,
242 &gEfiUgaDrawProtocolGuid,
243 (VOID **)&UgaDraw,
244 This->DriverBindingHandle,
245 Handle,
246 EFI_OPEN_PROTOCOL_GET_PROTOCOL
247 );
248 if (EFI_ERROR (Status)) {
249 //
250 // If the UGA interface does not exist the driver is not started
251 //
252 return EFI_NOT_STARTED;
253 }
254
255 //
256 // Get our private context information
257 //
258 Private = UGA_DRAW_PRIVATE_DATA_FROM_THIS (UgaDraw);
259
260 //
261 // Remove the SGO interface from the system
262 //
263 Status = gBS->UninstallMultipleProtocolInterfaces (
264 Private->Handle,
265 &gEfiUgaDrawProtocolGuid,
266 &Private->UgaDraw,
267 &gEfiSimpleTextInProtocolGuid,
268 &Private->SimpleTextIn,
269 &gEfiSimplePointerProtocolGuid,
270 &Private->SimplePointer,
271 NULL
272 );
273 if (!EFI_ERROR (Status)) {
274 //
275 // Shutdown the hardware
276 //
277 Status = UnixUgaDestructor (Private);
278 if (EFI_ERROR (Status)) {
279 return EFI_DEVICE_ERROR;
280 }
281
282 gBS->CloseProtocol (
283 Handle,
284 &gEfiUnixIoProtocolGuid,
285 This->DriverBindingHandle,
286 Handle
287 );
288
289 //
290 // Free our instance data
291 //
292 FreeUnicodeStringTable (Private->ControllerNameTable);
293
294 gBS->FreePool (Private);
295
296 }
297
298 return Status;
299 }
300