]> git.proxmox.com Git - mirror_edk2.git/blob - EdkNt32Pkg/Dxe/WinNtThunk/Bus/Uga/WinNtUgaDriver.c
Remove all blanks lines to avoid build errors.
[mirror_edk2.git] / EdkNt32Pkg / Dxe / WinNtThunk / Bus / Uga / WinNtUgaDriver.c
1 /*++
2
3 Copyright (c) 2006 - 2007, Intel Corporation
4 All rights reserved. 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 WinNtUgaDriver.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 WinNtThunk system calls as an IO
23 abstraction. For a PCI device WinNtIo would be replaced with
24 a PCI IO abstraction that abstracted a specific PCI device.
25
26 --*/
27
28 #include "WinNtUga.h"
29
30 EFI_DRIVER_BINDING_PROTOCOL gWinNtUgaDriverBinding = {
31 WinNtUgaDriverBindingSupported,
32 WinNtUgaDriverBindingStart,
33 WinNtUgaDriverBindingStop,
34 0xa,
35 NULL,
36 NULL
37 };
38
39
40 EFI_STATUS
41 EFIAPI
42 WinNtUgaDriverBindingSupported (
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_WIN_NT_IO_PROTOCOL *WinNtIo;
64
65 //
66 // Open the IO Abstraction(s) needed to perform the supported test
67 //
68 Status = gBS->OpenProtocol (
69 Handle,
70 &gEfiWinNtIoProtocolGuid,
71 &WinNtIo,
72 This->DriverBindingHandle,
73 Handle,
74 EFI_OPEN_PROTOCOL_BY_DRIVER
75 );
76 if (EFI_ERROR (Status)) {
77 return Status;
78 }
79
80 Status = WinNtUgaSupported (WinNtIo);
81
82 //
83 // Close the I/O Abstraction(s) used to perform the supported test
84 //
85 gBS->CloseProtocol (
86 Handle,
87 &gEfiWinNtIoProtocolGuid,
88 This->DriverBindingHandle,
89 Handle
90 );
91
92 return Status;
93 }
94
95 EFI_STATUS
96 EFIAPI
97 WinNtUgaDriverBindingStart (
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_WIN_NT_IO_PROTOCOL *WinNtIo;
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 &gEfiWinNtIoProtocolGuid,
128 &WinNtIo,
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 = AllocatePool (sizeof (UGA_PRIVATE_DATA));
141 if (Private == NULL) {
142 goto Done;
143 }
144 //
145 // Set up context record
146 //
147 Private->Signature = UGA_PRIVATE_DATA_SIGNATURE;
148 Private->Handle = Handle;
149 Private->WinNtThunk = WinNtIo->WinNtThunk;
150
151 Private->ControllerNameTable = NULL;
152
153 AddUnicodeString (
154 "eng",
155 gWinNtUgaComponentName.SupportedLanguages,
156 &Private->ControllerNameTable,
157 WinNtIo->EnvString
158 );
159
160 Private->WindowName = WinNtIo->EnvString;
161
162 Status = WinNtUgaConstructor (Private);
163 if (EFI_ERROR (Status)) {
164 goto Done;
165 }
166 //
167 // Publish the Uga interface to the world
168 //
169 Status = gBS->InstallMultipleProtocolInterfaces (
170 &Private->Handle,
171 &gEfiUgaDrawProtocolGuid,
172 &Private->UgaDraw,
173 &gEfiSimpleTextInProtocolGuid,
174 &Private->SimpleTextIn,
175 NULL
176 );
177
178 Done:
179 if (EFI_ERROR (Status)) {
180
181 gBS->CloseProtocol (
182 Handle,
183 &gEfiWinNtIoProtocolGuid,
184 This->DriverBindingHandle,
185 Handle
186 );
187
188 if (Private != NULL) {
189 //
190 // On Error Free back private data
191 //
192 if (Private->ControllerNameTable != NULL) {
193 FreeUnicodeStringTable (Private->ControllerNameTable);
194 }
195
196 FreePool (Private);
197 }
198 }
199
200 return Status;
201 }
202
203 EFI_STATUS
204 EFIAPI
205 WinNtUgaDriverBindingStop (
206 IN EFI_DRIVER_BINDING_PROTOCOL *This,
207 IN EFI_HANDLE Handle,
208 IN UINTN NumberOfChildren,
209 IN EFI_HANDLE *ChildHandleBuffer
210 )
211 /*++
212
213 Routine Description:
214
215 Arguments:
216
217 Returns:
218
219 None
220
221 --*/
222 // TODO: This - add argument and description to function comment
223 // TODO: Handle - add argument and description to function comment
224 // TODO: NumberOfChildren - add argument and description to function comment
225 // TODO: ChildHandleBuffer - add argument and description to function comment
226 // TODO: EFI_NOT_STARTED - add return value to function comment
227 // TODO: EFI_DEVICE_ERROR - add return value to function comment
228 {
229 EFI_UGA_DRAW_PROTOCOL *UgaDraw;
230 EFI_STATUS Status;
231 UGA_PRIVATE_DATA *Private;
232
233 Status = gBS->OpenProtocol (
234 Handle,
235 &gEfiUgaDrawProtocolGuid,
236 &UgaDraw,
237 This->DriverBindingHandle,
238 Handle,
239 EFI_OPEN_PROTOCOL_GET_PROTOCOL
240 );
241 if (EFI_ERROR (Status)) {
242 //
243 // If the UGA interface does not exist the driver is not started
244 //
245 return EFI_NOT_STARTED;
246 }
247
248 //
249 // Get our private context information
250 //
251 Private = UGA_DRAW_PRIVATE_DATA_FROM_THIS (UgaDraw);
252
253 //
254 // Remove the SGO interface from the system
255 //
256 Status = gBS->UninstallMultipleProtocolInterfaces (
257 Private->Handle,
258 &gEfiUgaDrawProtocolGuid,
259 &Private->UgaDraw,
260 &gEfiSimpleTextInProtocolGuid,
261 &Private->SimpleTextIn,
262 NULL
263 );
264 if (!EFI_ERROR (Status)) {
265 //
266 // Shutdown the hardware
267 //
268 Status = WinNtUgaDestructor (Private);
269 if (EFI_ERROR (Status)) {
270 return EFI_DEVICE_ERROR;
271 }
272
273 gBS->CloseProtocol (
274 Handle,
275 &gEfiWinNtIoProtocolGuid,
276 This->DriverBindingHandle,
277 Handle
278 );
279
280 //
281 // Free our instance data
282 //
283 FreeUnicodeStringTable (Private->ControllerNameTable);
284
285 FreePool (Private);
286
287 }
288
289 return Status;
290 }
291
292 UINTN
293 Atoi (
294 CHAR16 *String
295 )
296 /*++
297
298 Routine Description:
299
300 Convert a unicode string to a UINTN
301
302 Arguments:
303
304 String - Unicode string.
305
306 Returns:
307
308 UINTN of the number represented by String.
309
310 --*/
311 {
312 UINTN Number;
313 CHAR16 *Str;
314
315 //
316 // skip preceeding white space
317 //
318 Str = String;
319 while ((*Str) && (*Str == ' ' || *Str == '"')) {
320 Str++;
321 }
322
323 //
324 // Convert ot a Number
325 //
326 Number = 0;
327 while (*Str != '\0') {
328 if ((*Str >= '0') && (*Str <= '9')) {
329 Number = (Number * 10) +*Str - '0';
330 } else {
331 break;
332 }
333
334 Str++;
335 }
336
337 return Number;
338 }