]> git.proxmox.com Git - mirror_edk2.git/blob - EdkNt32Pkg/Dxe/WinNtThunk/Bus/Uga/WinNtUgaDriver.c
a270ec7b0d0a1806a6d539f2e2f3fdc2dbd0a96a
[mirror_edk2.git] / EdkNt32Pkg / Dxe / WinNtThunk / Bus / Uga / WinNtUgaDriver.c
1 /*++
2
3 Copyright (c) 2006, 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 = NULL;
141 Status = gBS->AllocatePool (
142 EfiBootServicesData,
143 sizeof (UGA_PRIVATE_DATA),
144 &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->WinNtThunk = WinNtIo->WinNtThunk;
155
156 Private->ControllerNameTable = NULL;
157
158 AddUnicodeString (
159 "eng",
160 gWinNtUgaComponentName.SupportedLanguages,
161 &Private->ControllerNameTable,
162 WinNtIo->EnvString
163 );
164
165 Private->WindowName = WinNtIo->EnvString;
166
167 Status = WinNtUgaConstructor (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 NULL
181 );
182
183 Done:
184 if (EFI_ERROR (Status)) {
185
186 gBS->CloseProtocol (
187 Handle,
188 &gEfiWinNtIoProtocolGuid,
189 This->DriverBindingHandle,
190 Handle
191 );
192
193 if (Private != NULL) {
194 //
195 // On Error Free back private data
196 //
197 if (Private->ControllerNameTable != NULL) {
198 FreeUnicodeStringTable (Private->ControllerNameTable);
199 }
200
201 gBS->FreePool (Private);
202 }
203 }
204
205 return Status;
206 }
207
208 EFI_STATUS
209 EFIAPI
210 WinNtUgaDriverBindingStop (
211 IN EFI_DRIVER_BINDING_PROTOCOL *This,
212 IN EFI_HANDLE Handle,
213 IN UINTN NumberOfChildren,
214 IN EFI_HANDLE *ChildHandleBuffer
215 )
216 /*++
217
218 Routine Description:
219
220 Arguments:
221
222 Returns:
223
224 None
225
226 --*/
227 // TODO: This - add argument and description to function comment
228 // TODO: Handle - add argument and description to function comment
229 // TODO: NumberOfChildren - add argument and description to function comment
230 // TODO: ChildHandleBuffer - add argument and description to function comment
231 // TODO: EFI_NOT_STARTED - add return value to function comment
232 // TODO: EFI_DEVICE_ERROR - add return value to function comment
233 {
234 EFI_UGA_DRAW_PROTOCOL *UgaDraw;
235 EFI_STATUS Status;
236 UGA_PRIVATE_DATA *Private;
237
238 Status = gBS->OpenProtocol (
239 Handle,
240 &gEfiUgaDrawProtocolGuid,
241 &UgaDraw,
242 This->DriverBindingHandle,
243 Handle,
244 EFI_OPEN_PROTOCOL_GET_PROTOCOL
245 );
246 if (EFI_ERROR (Status)) {
247 //
248 // If the UGA interface does not exist the driver is not started
249 //
250 return EFI_NOT_STARTED;
251 }
252
253 //
254 // Get our private context information
255 //
256 Private = UGA_DRAW_PRIVATE_DATA_FROM_THIS (UgaDraw);
257
258 //
259 // Remove the SGO interface from the system
260 //
261 Status = gBS->UninstallMultipleProtocolInterfaces (
262 Private->Handle,
263 &gEfiUgaDrawProtocolGuid,
264 &Private->UgaDraw,
265 &gEfiSimpleTextInProtocolGuid,
266 &Private->SimpleTextIn,
267 NULL
268 );
269 if (!EFI_ERROR (Status)) {
270 //
271 // Shutdown the hardware
272 //
273 Status = WinNtUgaDestructor (Private);
274 if (EFI_ERROR (Status)) {
275 return EFI_DEVICE_ERROR;
276 }
277
278 gBS->CloseProtocol (
279 Handle,
280 &gEfiWinNtIoProtocolGuid,
281 This->DriverBindingHandle,
282 Handle
283 );
284
285 //
286 // Free our instance data
287 //
288 FreeUnicodeStringTable (Private->ControllerNameTable);
289
290 gBS->FreePool (Private);
291
292 }
293
294 return Status;
295 }
296
297 UINTN
298 Atoi (
299 CHAR16 *String
300 )
301 /*++
302
303 Routine Description:
304
305 Convert a unicode string to a UINTN
306
307 Arguments:
308
309 String - Unicode string.
310
311 Returns:
312
313 UINTN of the number represented by String.
314
315 --*/
316 {
317 UINTN Number;
318 CHAR16 *Str;
319
320 //
321 // skip preceeding white space
322 //
323 Str = String;
324 while ((*Str) && (*Str == ' ' || *Str == '"')) {
325 Str++;
326 }
327
328 //
329 // Convert ot a Number
330 //
331 Number = 0;
332 while (*Str != '\0') {
333 if ((*Str >= '0') && (*Str <= '9')) {
334 Number = (Number * 10) +*Str - '0';
335 } else {
336 break;
337 }
338
339 Str++;
340 }
341
342 return Number;
343 }