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