]>
Commit | Line | Data |
---|---|---|
878ddf1f | 1 | /*++\r |
2 | \r | |
fa332de7 | 3 | Copyright (c) 2006 - 2007, Intel Corporation\r |
4 | All rights reserved. This program and the accompanying materials\r | |
5 | are licensed and made available under the terms and conditions of the BSD License\r | |
6 | which accompanies this distribution. The full text of the license may be found at\r | |
7 | http://opensource.org/licenses/bsd-license.php\r | |
8 | \r | |
9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
878ddf1f | 11 | \r |
12 | Module Name:\r | |
13 | \r | |
14 | WinNtUgaDriver.c\r | |
15 | \r | |
16 | Abstract:\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 | |
fa332de7 | 22 | This file is a verision of UgaIo the uses WinNtThunk system calls as an IO\r |
878ddf1f | 23 | abstraction. For a PCI device WinNtIo would be replaced with\r |
fa332de7 | 24 | a PCI IO abstraction that abstracted a specific PCI device.\r |
878ddf1f | 25 | \r |
26 | --*/\r | |
27 | \r | |
28 | #include "WinNtUga.h"\r | |
29 | \r | |
30 | EFI_DRIVER_BINDING_PROTOCOL gWinNtUgaDriverBinding = {\r | |
31 | WinNtUgaDriverBindingSupported,\r | |
32 | WinNtUgaDriverBindingStart,\r | |
33 | WinNtUgaDriverBindingStop,\r | |
8b018de6 | 34 | 0xa,\r |
878ddf1f | 35 | NULL,\r |
36 | NULL\r | |
37 | };\r | |
38 | \r | |
39 | \r | |
40 | EFI_STATUS\r | |
41 | EFIAPI\r | |
42 | WinNtUgaDriverBindingSupported (\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 | |
49 | Routine Description:\r | |
50 | \r | |
51 | Arguments:\r | |
52 | \r | |
53 | Returns:\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 | |
95 | EFI_STATUS\r | |
96 | EFIAPI\r | |
97 | WinNtUgaDriverBindingStart (\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 | |
104 | Routine Description:\r | |
105 | \r | |
106 | Arguments:\r | |
107 | \r | |
108 | Returns:\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 | |
fa332de7 | 140 | Private = AllocatePool (sizeof (UGA_PRIVATE_DATA));\r |
141 | if (Private == NULL) {\r | |
878ddf1f | 142 | goto Done;\r |
143 | }\r | |
144 | //\r | |
145 | // Set up context record\r | |
146 | //\r | |
147 | Private->Signature = UGA_PRIVATE_DATA_SIGNATURE;\r | |
148 | Private->Handle = Handle;\r | |
149 | Private->WinNtThunk = WinNtIo->WinNtThunk;\r | |
150 | \r | |
151 | Private->ControllerNameTable = NULL;\r | |
152 | \r | |
153 | AddUnicodeString (\r | |
154 | "eng",\r | |
155 | gWinNtUgaComponentName.SupportedLanguages,\r | |
156 | &Private->ControllerNameTable,\r | |
157 | WinNtIo->EnvString\r | |
158 | );\r | |
159 | \r | |
160 | Private->WindowName = WinNtIo->EnvString;\r | |
161 | \r | |
162 | Status = WinNtUgaConstructor (Private);\r | |
163 | if (EFI_ERROR (Status)) {\r | |
164 | goto Done;\r | |
165 | }\r | |
166 | //\r | |
167 | // Publish the Uga interface to the world\r | |
168 | //\r | |
169 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
170 | &Private->Handle,\r | |
171 | &gEfiUgaDrawProtocolGuid,\r | |
172 | &Private->UgaDraw,\r | |
173 | &gEfiSimpleTextInProtocolGuid,\r | |
174 | &Private->SimpleTextIn,\r | |
175 | NULL\r | |
176 | );\r | |
177 | \r | |
178 | Done:\r | |
179 | if (EFI_ERROR (Status)) {\r | |
180 | \r | |
181 | gBS->CloseProtocol (\r | |
182 | Handle,\r | |
183 | &gEfiWinNtIoProtocolGuid,\r | |
184 | This->DriverBindingHandle,\r | |
185 | Handle\r | |
186 | );\r | |
187 | \r | |
188 | if (Private != NULL) {\r | |
189 | //\r | |
190 | // On Error Free back private data\r | |
191 | //\r | |
192 | if (Private->ControllerNameTable != NULL) {\r | |
193 | FreeUnicodeStringTable (Private->ControllerNameTable);\r | |
194 | }\r | |
195 | \r | |
fa332de7 | 196 | FreePool (Private);\r |
878ddf1f | 197 | }\r |
198 | }\r | |
199 | \r | |
200 | return Status;\r | |
201 | }\r | |
202 | \r | |
203 | EFI_STATUS\r | |
204 | EFIAPI\r | |
205 | WinNtUgaDriverBindingStop (\r | |
206 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
207 | IN EFI_HANDLE Handle,\r | |
208 | IN UINTN NumberOfChildren,\r | |
209 | IN EFI_HANDLE *ChildHandleBuffer\r | |
210 | )\r | |
211 | /*++\r | |
212 | \r | |
213 | Routine Description:\r | |
214 | \r | |
215 | Arguments:\r | |
216 | \r | |
217 | Returns:\r | |
218 | \r | |
219 | None\r | |
220 | \r | |
221 | --*/\r | |
222 | // TODO: This - add argument and description to function comment\r | |
223 | // TODO: Handle - add argument and description to function comment\r | |
224 | // TODO: NumberOfChildren - add argument and description to function comment\r | |
225 | // TODO: ChildHandleBuffer - add argument and description to function comment\r | |
226 | // TODO: EFI_NOT_STARTED - add return value to function comment\r | |
227 | // TODO: EFI_DEVICE_ERROR - add return value to function comment\r | |
228 | {\r | |
229 | EFI_UGA_DRAW_PROTOCOL *UgaDraw;\r | |
230 | EFI_STATUS Status;\r | |
231 | UGA_PRIVATE_DATA *Private;\r | |
232 | \r | |
233 | Status = gBS->OpenProtocol (\r | |
234 | Handle,\r | |
235 | &gEfiUgaDrawProtocolGuid,\r | |
236 | &UgaDraw,\r | |
237 | This->DriverBindingHandle,\r | |
238 | Handle,\r | |
239 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
240 | );\r | |
241 | if (EFI_ERROR (Status)) {\r | |
242 | //\r | |
243 | // If the UGA interface does not exist the driver is not started\r | |
244 | //\r | |
245 | return EFI_NOT_STARTED;\r | |
246 | }\r | |
247 | \r | |
248 | //\r | |
249 | // Get our private context information\r | |
250 | //\r | |
251 | Private = UGA_DRAW_PRIVATE_DATA_FROM_THIS (UgaDraw);\r | |
252 | \r | |
253 | //\r | |
254 | // Remove the SGO interface from the system\r | |
255 | //\r | |
256 | Status = gBS->UninstallMultipleProtocolInterfaces (\r | |
257 | Private->Handle,\r | |
258 | &gEfiUgaDrawProtocolGuid,\r | |
259 | &Private->UgaDraw,\r | |
260 | &gEfiSimpleTextInProtocolGuid,\r | |
261 | &Private->SimpleTextIn,\r | |
262 | NULL\r | |
263 | );\r | |
264 | if (!EFI_ERROR (Status)) {\r | |
265 | //\r | |
266 | // Shutdown the hardware\r | |
267 | //\r | |
268 | Status = WinNtUgaDestructor (Private);\r | |
269 | if (EFI_ERROR (Status)) {\r | |
270 | return EFI_DEVICE_ERROR;\r | |
271 | }\r | |
272 | \r | |
273 | gBS->CloseProtocol (\r | |
274 | Handle,\r | |
275 | &gEfiWinNtIoProtocolGuid,\r | |
276 | This->DriverBindingHandle,\r | |
277 | Handle\r | |
278 | );\r | |
279 | \r | |
280 | //\r | |
281 | // Free our instance data\r | |
282 | //\r | |
283 | FreeUnicodeStringTable (Private->ControllerNameTable);\r | |
284 | \r | |
fa332de7 | 285 | FreePool (Private);\r |
878ddf1f | 286 | \r |
287 | }\r | |
288 | \r | |
289 | return Status;\r | |
290 | }\r | |
291 | \r | |
292 | UINTN\r | |
293 | Atoi (\r | |
294 | CHAR16 *String\r | |
295 | )\r | |
296 | /*++\r | |
297 | \r | |
298 | Routine Description:\r | |
299 | \r | |
300 | Convert a unicode string to a UINTN\r | |
301 | \r | |
302 | Arguments:\r | |
303 | \r | |
304 | String - Unicode string.\r | |
305 | \r | |
fa332de7 | 306 | Returns:\r |
878ddf1f | 307 | \r |
fa332de7 | 308 | UINTN of the number represented by String.\r |
878ddf1f | 309 | \r |
310 | --*/\r | |
311 | {\r | |
312 | UINTN Number;\r | |
313 | CHAR16 *Str;\r | |
314 | \r | |
315 | //\r | |
316 | // skip preceeding white space\r | |
317 | //\r | |
318 | Str = String;\r | |
319 | while ((*Str) && (*Str == ' ' || *Str == '"')) {\r | |
320 | Str++;\r | |
321 | }\r | |
322 | \r | |
323 | //\r | |
324 | // Convert ot a Number\r | |
325 | //\r | |
326 | Number = 0;\r | |
327 | while (*Str != '\0') {\r | |
328 | if ((*Str >= '0') && (*Str <= '9')) {\r | |
329 | Number = (Number * 10) +*Str - '0';\r | |
330 | } else {\r | |
331 | break;\r | |
332 | }\r | |
333 | \r | |
334 | Str++;\r | |
335 | }\r | |
336 | \r | |
337 | return Number;\r | |
338 | }\r |