WinNtGopDriver.c revision e6e53c97c943d7a93c17871668ee18a900e8da05
1/** @file
2
3Copyright (c) 2006 - 2007, 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//
26// The package level header files this module uses
27//
28#include <Uefi.h>
29#include <WinNtDxe.h>
30//
31// The protocols, PPI and GUID defintions for this module
32//
33#include <Guid/EventGroup.h>
34#include <Protocol/WinNtIo.h>
35#include <Protocol/ComponentName.h>
36#include <Protocol/SimpleTextIn.h>
37#include <Protocol/DriverBinding.h>
38#include <Protocol/GraphicsOutput.h>
39//
40// The Library classes this module consumes
41//
42#include <Library/DebugLib.h>
43#include <Library/BaseLib.h>
44#include <Library/UefiDriverEntryPoint.h>
45#include <Library/UefiLib.h>
46#include <Library/BaseMemoryLib.h>
47#include <Library/UefiBootServicesTableLib.h>
48#include <Library/MemoryAllocationLib.h>
49
50#include "WinNtGop.h"
51
52EFI_DRIVER_BINDING_PROTOCOL gWinNtGopDriverBinding = {
53  WinNtGopDriverBindingSupported,
54  WinNtGopDriverBindingStart,
55  WinNtGopDriverBindingStop,
56  0xa,
57  NULL,
58  NULL
59};
60
61/**
62  The user Entry Point for module WinNtGop. The user code starts with this function.
63
64  @param[in] ImageHandle    The firmware allocated handle for the EFI image.
65  @param[in] SystemTable    A pointer to the EFI System Table.
66
67  @retval EFI_SUCCESS       The entry point is executed successfully.
68  @retval other             Some error occurs when executing this entry point.
69
70**/
71EFI_STATUS
72EFIAPI
73InitializeWinNtGop(
74  IN EFI_HANDLE           ImageHandle,
75  IN EFI_SYSTEM_TABLE     *SystemTable
76  )
77{
78  EFI_STATUS              Status;
79
80  //
81  // Install driver model protocol(s).
82  //
83  Status = EfiLibInstallDriverBindingComponentName2 (
84             ImageHandle,
85             SystemTable,
86             &gWinNtGopDriverBinding,
87             ImageHandle,
88             &gWinNtGopComponentName,
89             &gWinNtGopComponentName2
90             );
91  ASSERT_EFI_ERROR (Status);
92
93
94  return Status;
95}
96
97/**
98
99
100  @return None
101
102**/
103// TODO:    This - add argument and description to function comment
104// TODO:    Handle - add argument and description to function comment
105// TODO:    RemainingDevicePath - add argument and description to function comment
106EFI_STATUS
107EFIAPI
108WinNtGopDriverBindingSupported (
109  IN  EFI_DRIVER_BINDING_PROTOCOL     *This,
110  IN  EFI_HANDLE                      Handle,
111  IN  EFI_DEVICE_PATH_PROTOCOL        *RemainingDevicePath
112  )
113{
114  EFI_STATUS              Status;
115  EFI_WIN_NT_IO_PROTOCOL  *WinNtIo;
116
117  //
118  // Open the IO Abstraction(s) needed to perform the supported test
119  //
120  Status = gBS->OpenProtocol (
121                  Handle,
122                  &gEfiWinNtIoProtocolGuid,
123                  &WinNtIo,
124                  This->DriverBindingHandle,
125                  Handle,
126                  EFI_OPEN_PROTOCOL_BY_DRIVER
127                  );
128  if (EFI_ERROR (Status)) {
129    return Status;
130  }
131
132  Status = WinNtGopSupported (WinNtIo);
133
134  //
135  // Close the I/O Abstraction(s) used to perform the supported test
136  //
137  gBS->CloseProtocol (
138        Handle,
139        &gEfiWinNtIoProtocolGuid,
140        This->DriverBindingHandle,
141        Handle
142        );
143
144  return Status;
145}
146
147
148/**
149
150
151  @return None
152
153**/
154// TODO:    This - add argument and description to function comment
155// TODO:    Handle - add argument and description to function comment
156// TODO:    RemainingDevicePath - add argument and description to function comment
157// TODO:    EFI_UNSUPPORTED - add return value to function comment
158EFI_STATUS
159EFIAPI
160WinNtGopDriverBindingStart (
161  IN  EFI_DRIVER_BINDING_PROTOCOL     *This,
162  IN  EFI_HANDLE                      Handle,
163  IN  EFI_DEVICE_PATH_PROTOCOL        *RemainingDevicePath
164  )
165{
166  EFI_WIN_NT_IO_PROTOCOL  *WinNtIo;
167  EFI_STATUS              Status;
168  GOP_PRIVATE_DATA        *Private;
169
170  //
171  // Grab the protocols we need
172  //
173  Status = gBS->OpenProtocol (
174                  Handle,
175                  &gEfiWinNtIoProtocolGuid,
176                  &WinNtIo,
177                  This->DriverBindingHandle,
178                  Handle,
179                  EFI_OPEN_PROTOCOL_BY_DRIVER
180                  );
181  if (EFI_ERROR (Status)) {
182    return EFI_UNSUPPORTED;
183  }
184
185  //
186  // Allocate Private context data for SGO inteface.
187  //
188  Private = NULL;
189  Private = AllocatePool (sizeof (GOP_PRIVATE_DATA));
190  if (Private == NULL) {
191    goto Done;
192  }
193  //
194  // Set up context record
195  //
196  Private->Signature            = GOP_PRIVATE_DATA_SIGNATURE;
197  Private->Handle               = Handle;
198  Private->WinNtThunk           = WinNtIo->WinNtThunk;
199
200  Private->ControllerNameTable  = NULL;
201
202  AddUnicodeString2 (
203    "eng",
204    gWinNtGopComponentName.SupportedLanguages,
205    &Private->ControllerNameTable,
206    WinNtIo->EnvString,
207    TRUE
208    );
209  AddUnicodeString2 (
210    "en",
211    gWinNtGopComponentName2.SupportedLanguages,
212    &Private->ControllerNameTable,
213    WinNtIo->EnvString,
214    FALSE
215    );
216
217
218  Private->WindowName = WinNtIo->EnvString;
219
220  Status              = WinNtGopConstructor (Private);
221  if (EFI_ERROR (Status)) {
222    goto Done;
223  }
224  //
225  // Publish the Gop interface to the world
226  //
227  Status = gBS->InstallMultipleProtocolInterfaces (
228                  &Private->Handle,
229                  &gEfiGraphicsOutputProtocolGuid,
230                  &Private->GraphicsOutput,
231                  &gEfiSimpleTextInProtocolGuid,
232                  &Private->SimpleTextIn,
233                  NULL
234                  );
235
236Done:
237  if (EFI_ERROR (Status)) {
238
239    gBS->CloseProtocol (
240          Handle,
241          &gEfiWinNtIoProtocolGuid,
242          This->DriverBindingHandle,
243          Handle
244          );
245
246    if (Private != NULL) {
247      //
248      // On Error Free back private data
249      //
250      if (Private->ControllerNameTable != NULL) {
251        FreeUnicodeStringTable (Private->ControllerNameTable);
252      }
253
254      FreePool (Private);
255    }
256  }
257
258  return Status;
259}
260
261
262/**
263
264
265  @return None
266
267**/
268// TODO:    This - add argument and description to function comment
269// TODO:    Handle - add argument and description to function comment
270// TODO:    NumberOfChildren - add argument and description to function comment
271// TODO:    ChildHandleBuffer - add argument and description to function comment
272// TODO:    EFI_NOT_STARTED - add return value to function comment
273// TODO:    EFI_DEVICE_ERROR - add return value to function comment
274EFI_STATUS
275EFIAPI
276WinNtGopDriverBindingStop (
277  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,
278  IN  EFI_HANDLE                   Handle,
279  IN  UINTN                        NumberOfChildren,
280  IN  EFI_HANDLE                   *ChildHandleBuffer
281  )
282{
283  EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
284  EFI_STATUS                   Status;
285  GOP_PRIVATE_DATA             *Private;
286
287  Status = gBS->OpenProtocol (
288                  Handle,
289                  &gEfiGraphicsOutputProtocolGuid,
290                  &GraphicsOutput,
291                  This->DriverBindingHandle,
292                  Handle,
293                  EFI_OPEN_PROTOCOL_GET_PROTOCOL
294                  );
295  if (EFI_ERROR (Status)) {
296    //
297    // If the GOP interface does not exist the driver is not started
298    //
299    return EFI_NOT_STARTED;
300  }
301
302  //
303  // Get our private context information
304  //
305  Private = GOP_PRIVATE_DATA_FROM_THIS (GraphicsOutput);
306
307  //
308  // Remove the SGO interface from the system
309  //
310  Status = gBS->UninstallMultipleProtocolInterfaces (
311                  Private->Handle,
312                  &gEfiGraphicsOutputProtocolGuid,
313                  &Private->GraphicsOutput,
314                  &gEfiSimpleTextInProtocolGuid,
315                  &Private->SimpleTextIn,
316                  NULL
317                  );
318  if (!EFI_ERROR (Status)) {
319    //
320    // Shutdown the hardware
321    //
322    Status = WinNtGopDestructor (Private);
323    if (EFI_ERROR (Status)) {
324      return EFI_DEVICE_ERROR;
325    }
326
327    gBS->CloseProtocol (
328          Handle,
329          &gEfiWinNtIoProtocolGuid,
330          This->DriverBindingHandle,
331          Handle
332          );
333
334    //
335    // Free our instance data
336    //
337    FreeUnicodeStringTable (Private->ControllerNameTable);
338
339    FreePool (Private);
340
341  }
342
343  return Status;
344}
345
346