3 Copyright (c) 2006 - 2007, Intel Corporation
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
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.
18 This file implements the UEFI Device Driver model requirements for GOP
20 GOP is short hand for Graphics Output Protocol.
26 // The package level header files this module uses
31 // The protocols, PPI and GUID defintions for this module
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>
40 // The Library classes this module consumes
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>
52 EFI_DRIVER_BINDING_PROTOCOL gWinNtGopDriverBinding
= {
53 WinNtGopDriverBindingSupported
,
54 WinNtGopDriverBindingStart
,
55 WinNtGopDriverBindingStop
,
62 The user Entry Point for module WinNtGop. The user code starts with this function.
64 @param[in] ImageHandle The firmware allocated handle for the EFI image.
65 @param[in] SystemTable A pointer to the EFI System Table.
67 @retval EFI_SUCCESS The entry point is executed successfully.
68 @retval other Some error occurs when executing this entry point.
74 IN EFI_HANDLE ImageHandle
,
75 IN EFI_SYSTEM_TABLE
*SystemTable
81 // Install driver model protocol(s).
83 Status
= EfiLibInstallDriverBindingComponentName2 (
86 &gWinNtGopDriverBinding
,
88 &gWinNtGopComponentName
,
89 &gWinNtGopComponentName2
91 ASSERT_EFI_ERROR (Status
);
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
108 WinNtGopDriverBindingSupported (
109 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
110 IN EFI_HANDLE Handle
,
111 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
115 EFI_WIN_NT_IO_PROTOCOL
*WinNtIo
;
118 // Open the IO Abstraction(s) needed to perform the supported test
120 Status
= gBS
->OpenProtocol (
122 &gEfiWinNtIoProtocolGuid
,
124 This
->DriverBindingHandle
,
126 EFI_OPEN_PROTOCOL_BY_DRIVER
128 if (EFI_ERROR (Status
)) {
132 Status
= WinNtGopSupported (WinNtIo
);
135 // Close the I/O Abstraction(s) used to perform the supported test
139 &gEfiWinNtIoProtocolGuid
,
140 This
->DriverBindingHandle
,
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
160 WinNtGopDriverBindingStart (
161 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
162 IN EFI_HANDLE Handle
,
163 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
166 EFI_WIN_NT_IO_PROTOCOL
*WinNtIo
;
168 GOP_PRIVATE_DATA
*Private
;
171 // Grab the protocols we need
173 Status
= gBS
->OpenProtocol (
175 &gEfiWinNtIoProtocolGuid
,
177 This
->DriverBindingHandle
,
179 EFI_OPEN_PROTOCOL_BY_DRIVER
181 if (EFI_ERROR (Status
)) {
182 return EFI_UNSUPPORTED
;
186 // Allocate Private context data for SGO inteface.
189 Private
= AllocatePool (sizeof (GOP_PRIVATE_DATA
));
190 if (Private
== NULL
) {
194 // Set up context record
196 Private
->Signature
= GOP_PRIVATE_DATA_SIGNATURE
;
197 Private
->Handle
= Handle
;
198 Private
->WinNtThunk
= WinNtIo
->WinNtThunk
;
200 Private
->ControllerNameTable
= NULL
;
204 gWinNtGopComponentName
.SupportedLanguages
,
205 &Private
->ControllerNameTable
,
211 gWinNtGopComponentName2
.SupportedLanguages
,
212 &Private
->ControllerNameTable
,
218 Private
->WindowName
= WinNtIo
->EnvString
;
220 Status
= WinNtGopConstructor (Private
);
221 if (EFI_ERROR (Status
)) {
225 // Publish the Gop interface to the world
227 Status
= gBS
->InstallMultipleProtocolInterfaces (
229 &gEfiGraphicsOutputProtocolGuid
,
230 &Private
->GraphicsOutput
,
231 &gEfiSimpleTextInProtocolGuid
,
232 &Private
->SimpleTextIn
,
237 if (EFI_ERROR (Status
)) {
241 &gEfiWinNtIoProtocolGuid
,
242 This
->DriverBindingHandle
,
246 if (Private
!= NULL
) {
248 // On Error Free back private data
250 if (Private
->ControllerNameTable
!= NULL
) {
251 FreeUnicodeStringTable (Private
->ControllerNameTable
);
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
276 WinNtGopDriverBindingStop (
277 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
278 IN EFI_HANDLE Handle
,
279 IN UINTN NumberOfChildren
,
280 IN EFI_HANDLE
*ChildHandleBuffer
283 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
285 GOP_PRIVATE_DATA
*Private
;
287 Status
= gBS
->OpenProtocol (
289 &gEfiGraphicsOutputProtocolGuid
,
291 This
->DriverBindingHandle
,
293 EFI_OPEN_PROTOCOL_GET_PROTOCOL
295 if (EFI_ERROR (Status
)) {
297 // If the GOP interface does not exist the driver is not started
299 return EFI_NOT_STARTED
;
303 // Get our private context information
305 Private
= GOP_PRIVATE_DATA_FROM_THIS (GraphicsOutput
);
308 // Remove the SGO interface from the system
310 Status
= gBS
->UninstallMultipleProtocolInterfaces (
312 &gEfiGraphicsOutputProtocolGuid
,
313 &Private
->GraphicsOutput
,
314 &gEfiSimpleTextInProtocolGuid
,
315 &Private
->SimpleTextIn
,
318 if (!EFI_ERROR (Status
)) {
320 // Shutdown the hardware
322 Status
= WinNtGopDestructor (Private
);
323 if (EFI_ERROR (Status
)) {
324 return EFI_DEVICE_ERROR
;
329 &gEfiWinNtIoProtocolGuid
,
330 This
->DriverBindingHandle
,
335 // Free our instance data
337 FreeUnicodeStringTable (Private
->ControllerNameTable
);