]>
Commit | Line | Data |
---|---|---|
72b695f3 | 1 | /** @file |
2 | ||
fa332de7 | 3 | Copyright (c) 2006 - 2007, Intel Corporation |
72b695f3 | 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 | WinNtGopDriver.c | |
15 | ||
16 | Abstract: | |
17 | ||
18 | This file implements the UEFI Device Driver model requirements for GOP | |
19 | ||
20 | GOP is short hand for Graphics Output Protocol. | |
21 | ||
22 | ||
23 | **/ | |
24 | ||
25 | #include "WinNtGop.h" | |
26 | ||
27 | EFI_DRIVER_BINDING_PROTOCOL gWinNtGopDriverBinding = { | |
28 | WinNtGopDriverBindingSupported, | |
29 | WinNtGopDriverBindingStart, | |
30 | WinNtGopDriverBindingStop, | |
8b018de6 | 31 | 0xa, |
72b695f3 | 32 | NULL, |
33 | NULL | |
34 | }; | |
35 | ||
36 | /** | |
37 | ||
38 | ||
39 | @return None | |
40 | ||
41 | **/ | |
42 | // TODO: This - add argument and description to function comment | |
43 | // TODO: Handle - add argument and description to function comment | |
44 | // TODO: RemainingDevicePath - add argument and description to function comment | |
45 | EFI_STATUS | |
46 | EFIAPI | |
47 | WinNtGopDriverBindingSupported ( | |
48 | IN EFI_DRIVER_BINDING_PROTOCOL *This, | |
49 | IN EFI_HANDLE Handle, | |
50 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath | |
51 | ) | |
52 | { | |
53 | EFI_STATUS Status; | |
54 | EFI_WIN_NT_IO_PROTOCOL *WinNtIo; | |
55 | ||
56 | // | |
57 | // Open the IO Abstraction(s) needed to perform the supported test | |
58 | // | |
59 | Status = gBS->OpenProtocol ( | |
60 | Handle, | |
61 | &gEfiWinNtIoProtocolGuid, | |
62 | &WinNtIo, | |
63 | This->DriverBindingHandle, | |
64 | Handle, | |
65 | EFI_OPEN_PROTOCOL_BY_DRIVER | |
66 | ); | |
67 | if (EFI_ERROR (Status)) { | |
68 | return Status; | |
69 | } | |
70 | ||
71 | Status = WinNtGopSupported (WinNtIo); | |
72 | ||
73 | // | |
74 | // Close the I/O Abstraction(s) used to perform the supported test | |
75 | // | |
76 | gBS->CloseProtocol ( | |
77 | Handle, | |
78 | &gEfiWinNtIoProtocolGuid, | |
79 | This->DriverBindingHandle, | |
80 | Handle | |
81 | ); | |
82 | ||
83 | return Status; | |
84 | } | |
85 | ||
86 | ||
87 | /** | |
88 | ||
89 | ||
90 | @return None | |
91 | ||
92 | **/ | |
93 | // TODO: This - add argument and description to function comment | |
94 | // TODO: Handle - add argument and description to function comment | |
95 | // TODO: RemainingDevicePath - add argument and description to function comment | |
96 | // TODO: EFI_UNSUPPORTED - add return value to function comment | |
97 | EFI_STATUS | |
98 | EFIAPI | |
99 | WinNtGopDriverBindingStart ( | |
100 | IN EFI_DRIVER_BINDING_PROTOCOL *This, | |
101 | IN EFI_HANDLE Handle, | |
102 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath | |
103 | ) | |
104 | { | |
105 | EFI_WIN_NT_IO_PROTOCOL *WinNtIo; | |
106 | EFI_STATUS Status; | |
107 | GOP_PRIVATE_DATA *Private; | |
108 | ||
109 | // | |
110 | // Grab the protocols we need | |
111 | // | |
112 | Status = gBS->OpenProtocol ( | |
113 | Handle, | |
114 | &gEfiWinNtIoProtocolGuid, | |
115 | &WinNtIo, | |
116 | This->DriverBindingHandle, | |
117 | Handle, | |
118 | EFI_OPEN_PROTOCOL_BY_DRIVER | |
119 | ); | |
120 | if (EFI_ERROR (Status)) { | |
121 | return EFI_UNSUPPORTED; | |
122 | } | |
123 | ||
124 | // | |
125 | // Allocate Private context data for SGO inteface. | |
126 | // | |
127 | Private = NULL; | |
fa332de7 | 128 | Private = AllocatePool (sizeof (GOP_PRIVATE_DATA)); |
129 | if (Private == NULL) { | |
72b695f3 | 130 | goto Done; |
131 | } | |
132 | // | |
133 | // Set up context record | |
134 | // | |
135 | Private->Signature = GOP_PRIVATE_DATA_SIGNATURE; | |
136 | Private->Handle = Handle; | |
137 | Private->WinNtThunk = WinNtIo->WinNtThunk; | |
138 | ||
139 | Private->ControllerNameTable = NULL; | |
140 | ||
141 | AddUnicodeString ( | |
142 | "eng", | |
143 | gWinNtGopComponentName.SupportedLanguages, | |
144 | &Private->ControllerNameTable, | |
145 | WinNtIo->EnvString | |
146 | ); | |
147 | ||
148 | Private->WindowName = WinNtIo->EnvString; | |
149 | ||
150 | Status = WinNtGopConstructor (Private); | |
151 | if (EFI_ERROR (Status)) { | |
152 | goto Done; | |
153 | } | |
154 | // | |
155 | // Publish the Gop interface to the world | |
156 | // | |
157 | Status = gBS->InstallMultipleProtocolInterfaces ( | |
158 | &Private->Handle, | |
159 | &gEfiGraphicsOutputProtocolGuid, | |
160 | &Private->GraphicsOutput, | |
161 | &gEfiSimpleTextInProtocolGuid, | |
162 | &Private->SimpleTextIn, | |
163 | NULL | |
164 | ); | |
165 | ||
166 | Done: | |
167 | if (EFI_ERROR (Status)) { | |
168 | ||
169 | gBS->CloseProtocol ( | |
170 | Handle, | |
171 | &gEfiWinNtIoProtocolGuid, | |
172 | This->DriverBindingHandle, | |
173 | Handle | |
174 | ); | |
175 | ||
176 | if (Private != NULL) { | |
177 | // | |
178 | // On Error Free back private data | |
179 | // | |
180 | if (Private->ControllerNameTable != NULL) { | |
181 | FreeUnicodeStringTable (Private->ControllerNameTable); | |
182 | } | |
183 | ||
fa332de7 | 184 | FreePool (Private); |
72b695f3 | 185 | } |
186 | } | |
187 | ||
188 | return Status; | |
189 | } | |
190 | ||
191 | ||
192 | /** | |
193 | ||
194 | ||
195 | @return None | |
196 | ||
197 | **/ | |
198 | // TODO: This - add argument and description to function comment | |
199 | // TODO: Handle - add argument and description to function comment | |
200 | // TODO: NumberOfChildren - add argument and description to function comment | |
201 | // TODO: ChildHandleBuffer - add argument and description to function comment | |
202 | // TODO: EFI_NOT_STARTED - add return value to function comment | |
203 | // TODO: EFI_DEVICE_ERROR - add return value to function comment | |
204 | EFI_STATUS | |
205 | EFIAPI | |
206 | WinNtGopDriverBindingStop ( | |
207 | IN EFI_DRIVER_BINDING_PROTOCOL *This, | |
208 | IN EFI_HANDLE Handle, | |
209 | IN UINTN NumberOfChildren, | |
210 | IN EFI_HANDLE *ChildHandleBuffer | |
211 | ) | |
212 | { | |
213 | EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput; | |
214 | EFI_STATUS Status; | |
215 | GOP_PRIVATE_DATA *Private; | |
216 | ||
217 | Status = gBS->OpenProtocol ( | |
218 | Handle, | |
219 | &gEfiGraphicsOutputProtocolGuid, | |
220 | &GraphicsOutput, | |
221 | This->DriverBindingHandle, | |
222 | Handle, | |
223 | EFI_OPEN_PROTOCOL_GET_PROTOCOL | |
224 | ); | |
225 | if (EFI_ERROR (Status)) { | |
226 | // | |
227 | // If the GOP interface does not exist the driver is not started | |
228 | // | |
229 | return EFI_NOT_STARTED; | |
230 | } | |
231 | ||
232 | // | |
233 | // Get our private context information | |
234 | // | |
235 | Private = GOP_PRIVATE_DATA_FROM_THIS (GraphicsOutput); | |
236 | ||
237 | // | |
238 | // Remove the SGO interface from the system | |
239 | // | |
240 | Status = gBS->UninstallMultipleProtocolInterfaces ( | |
241 | Private->Handle, | |
242 | &gEfiGraphicsOutputProtocolGuid, | |
243 | &Private->GraphicsOutput, | |
244 | &gEfiSimpleTextInProtocolGuid, | |
245 | &Private->SimpleTextIn, | |
246 | NULL | |
247 | ); | |
248 | if (!EFI_ERROR (Status)) { | |
249 | // | |
250 | // Shutdown the hardware | |
251 | // | |
252 | Status = WinNtGopDestructor (Private); | |
253 | if (EFI_ERROR (Status)) { | |
254 | return EFI_DEVICE_ERROR; | |
255 | } | |
256 | ||
257 | gBS->CloseProtocol ( | |
258 | Handle, | |
259 | &gEfiWinNtIoProtocolGuid, | |
260 | This->DriverBindingHandle, | |
261 | Handle | |
262 | ); | |
263 | ||
264 | // | |
265 | // Free our instance data | |
266 | // | |
267 | FreeUnicodeStringTable (Private->ControllerNameTable); | |
268 | ||
fa332de7 | 269 | FreePool (Private); |
72b695f3 | 270 | |
271 | } | |
272 | ||
273 | return Status; | |
274 | } | |
275 | ||
276 | ||
277 | /** | |
278 | Convert a unicode string to a UINTN | |
279 | ||
280 | @param String Unicode string. | |
281 | ||
282 | @return UINTN of the number represented by String. | |
283 | ||
284 | **/ | |
285 | UINTN | |
286 | Atoi ( | |
287 | CHAR16 *String | |
288 | ) | |
289 | { | |
290 | UINTN Number; | |
291 | CHAR16 *Str; | |
292 | ||
293 | // | |
294 | // skip preceeding white space | |
295 | // | |
296 | Str = String; | |
297 | while ((*Str) && (*Str == ' ' || *Str == '"')) { | |
298 | Str++; | |
299 | } | |
300 | ||
301 | // | |
302 | // Convert ot a Number | |
303 | // | |
304 | Number = 0; | |
305 | while (*Str != '\0') { | |
306 | if ((*Str >= '0') && (*Str <= '9')) { | |
307 | Number = (Number * 10) +*Str - '0'; | |
308 | } else { | |
309 | break; | |
310 | } | |
311 | ||
312 | Str++; | |
313 | } | |
314 | ||
315 | return Number; | |
316 | } |