]> git.proxmox.com Git - mirror_edk2.git/blame - EdkNt32Pkg/Dxe/WinNtThunk/Bus/Gop/WinNtGopDriver.c
Fix component name bugs when input Controller Name is invalid
[mirror_edk2.git] / EdkNt32Pkg / Dxe / WinNtThunk / Bus / Gop / WinNtGopDriver.c
CommitLineData
72b695f3 1/** @file
2
3Copyright (c) 2006, Intel Corporation
4All rights reserved. This program and the accompanying materials
5are licensed and made available under the terms and conditions of the BSD License
6which accompanies this distribution. The full text of the license may be found at
7http://opensource.org/licenses/bsd-license.php
8
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12Module Name:
13
14 WinNtGopDriver.c
15
16Abstract:
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
27EFI_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
45EFI_STATUS
46EFIAPI
47WinNtGopDriverBindingSupported (
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
97EFI_STATUS
98EFIAPI
99WinNtGopDriverBindingStart (
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;
128 Status = gBS->AllocatePool (
129 EfiBootServicesData,
130 sizeof (GOP_PRIVATE_DATA),
131 &Private
132 );
133 if (EFI_ERROR (Status)) {
134 goto Done;
135 }
136 //
137 // Set up context record
138 //
139 Private->Signature = GOP_PRIVATE_DATA_SIGNATURE;
140 Private->Handle = Handle;
141 Private->WinNtThunk = WinNtIo->WinNtThunk;
142
143 Private->ControllerNameTable = NULL;
144
145 AddUnicodeString (
146 "eng",
147 gWinNtGopComponentName.SupportedLanguages,
148 &Private->ControllerNameTable,
149 WinNtIo->EnvString
150 );
151
152 Private->WindowName = WinNtIo->EnvString;
153
154 Status = WinNtGopConstructor (Private);
155 if (EFI_ERROR (Status)) {
156 goto Done;
157 }
158 //
159 // Publish the Gop interface to the world
160 //
161 Status = gBS->InstallMultipleProtocolInterfaces (
162 &Private->Handle,
163 &gEfiGraphicsOutputProtocolGuid,
164 &Private->GraphicsOutput,
165 &gEfiSimpleTextInProtocolGuid,
166 &Private->SimpleTextIn,
167 NULL
168 );
169
170Done:
171 if (EFI_ERROR (Status)) {
172
173 gBS->CloseProtocol (
174 Handle,
175 &gEfiWinNtIoProtocolGuid,
176 This->DriverBindingHandle,
177 Handle
178 );
179
180 if (Private != NULL) {
181 //
182 // On Error Free back private data
183 //
184 if (Private->ControllerNameTable != NULL) {
185 FreeUnicodeStringTable (Private->ControllerNameTable);
186 }
187
188 gBS->FreePool (Private);
189 }
190 }
191
192 return Status;
193}
194
195
196/**
197
198
199 @return None
200
201**/
202// TODO: This - add argument and description to function comment
203// TODO: Handle - add argument and description to function comment
204// TODO: NumberOfChildren - add argument and description to function comment
205// TODO: ChildHandleBuffer - add argument and description to function comment
206// TODO: EFI_NOT_STARTED - add return value to function comment
207// TODO: EFI_DEVICE_ERROR - add return value to function comment
208EFI_STATUS
209EFIAPI
210WinNtGopDriverBindingStop (
211 IN EFI_DRIVER_BINDING_PROTOCOL *This,
212 IN EFI_HANDLE Handle,
213 IN UINTN NumberOfChildren,
214 IN EFI_HANDLE *ChildHandleBuffer
215 )
216{
217 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
218 EFI_STATUS Status;
219 GOP_PRIVATE_DATA *Private;
220
221 Status = gBS->OpenProtocol (
222 Handle,
223 &gEfiGraphicsOutputProtocolGuid,
224 &GraphicsOutput,
225 This->DriverBindingHandle,
226 Handle,
227 EFI_OPEN_PROTOCOL_GET_PROTOCOL
228 );
229 if (EFI_ERROR (Status)) {
230 //
231 // If the GOP interface does not exist the driver is not started
232 //
233 return EFI_NOT_STARTED;
234 }
235
236 //
237 // Get our private context information
238 //
239 Private = GOP_PRIVATE_DATA_FROM_THIS (GraphicsOutput);
240
241 //
242 // Remove the SGO interface from the system
243 //
244 Status = gBS->UninstallMultipleProtocolInterfaces (
245 Private->Handle,
246 &gEfiGraphicsOutputProtocolGuid,
247 &Private->GraphicsOutput,
248 &gEfiSimpleTextInProtocolGuid,
249 &Private->SimpleTextIn,
250 NULL
251 );
252 if (!EFI_ERROR (Status)) {
253 //
254 // Shutdown the hardware
255 //
256 Status = WinNtGopDestructor (Private);
257 if (EFI_ERROR (Status)) {
258 return EFI_DEVICE_ERROR;
259 }
260
261 gBS->CloseProtocol (
262 Handle,
263 &gEfiWinNtIoProtocolGuid,
264 This->DriverBindingHandle,
265 Handle
266 );
267
268 //
269 // Free our instance data
270 //
271 FreeUnicodeStringTable (Private->ControllerNameTable);
272
273 gBS->FreePool (Private);
274
275 }
276
277 return Status;
278}
279
280
281/**
282 Convert a unicode string to a UINTN
283
284 @param String Unicode string.
285
286 @return UINTN of the number represented by String.
287
288**/
289UINTN
290Atoi (
291 CHAR16 *String
292 )
293{
294 UINTN Number;
295 CHAR16 *Str;
296
297 //
298 // skip preceeding white space
299 //
300 Str = String;
301 while ((*Str) && (*Str == ' ' || *Str == '"')) {
302 Str++;
303 }
304
305 //
306 // Convert ot a Number
307 //
308 Number = 0;
309 while (*Str != '\0') {
310 if ((*Str >= '0') && (*Str <= '9')) {
311 Number = (Number * 10) +*Str - '0';
312 } else {
313 break;
314 }
315
316 Str++;
317 }
318
319 return Number;
320}