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
= EfiLibInstallAllDriverProtocols (
86 &gWinNtGopDriverBinding
,
88 &gWinNtGopComponentName
,
92 ASSERT_EFI_ERROR (Status
);
104 // TODO: This - add argument and description to function comment
105 // TODO: Handle - add argument and description to function comment
106 // TODO: RemainingDevicePath - add argument and description to function comment
109 WinNtGopDriverBindingSupported (
110 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
111 IN EFI_HANDLE Handle
,
112 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
116 EFI_WIN_NT_IO_PROTOCOL
*WinNtIo
;
119 // Open the IO Abstraction(s) needed to perform the supported test
121 Status
= gBS
->OpenProtocol (
123 &gEfiWinNtIoProtocolGuid
,
125 This
->DriverBindingHandle
,
127 EFI_OPEN_PROTOCOL_BY_DRIVER
129 if (EFI_ERROR (Status
)) {
133 Status
= WinNtGopSupported (WinNtIo
);
136 // Close the I/O Abstraction(s) used to perform the supported test
140 &gEfiWinNtIoProtocolGuid
,
141 This
->DriverBindingHandle
,
155 // TODO: This - add argument and description to function comment
156 // TODO: Handle - add argument and description to function comment
157 // TODO: RemainingDevicePath - add argument and description to function comment
158 // TODO: EFI_UNSUPPORTED - add return value to function comment
161 WinNtGopDriverBindingStart (
162 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
163 IN EFI_HANDLE Handle
,
164 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
167 EFI_WIN_NT_IO_PROTOCOL
*WinNtIo
;
169 GOP_PRIVATE_DATA
*Private
;
172 // Grab the protocols we need
174 Status
= gBS
->OpenProtocol (
176 &gEfiWinNtIoProtocolGuid
,
178 This
->DriverBindingHandle
,
180 EFI_OPEN_PROTOCOL_BY_DRIVER
182 if (EFI_ERROR (Status
)) {
183 return EFI_UNSUPPORTED
;
187 // Allocate Private context data for SGO inteface.
190 Private
= AllocatePool (sizeof (GOP_PRIVATE_DATA
));
191 if (Private
== NULL
) {
195 // Set up context record
197 Private
->Signature
= GOP_PRIVATE_DATA_SIGNATURE
;
198 Private
->Handle
= Handle
;
199 Private
->WinNtThunk
= WinNtIo
->WinNtThunk
;
201 Private
->ControllerNameTable
= NULL
;
205 gWinNtGopComponentName
.SupportedLanguages
,
206 &Private
->ControllerNameTable
,
210 Private
->WindowName
= WinNtIo
->EnvString
;
212 Status
= WinNtGopConstructor (Private
);
213 if (EFI_ERROR (Status
)) {
217 // Publish the Gop interface to the world
219 Status
= gBS
->InstallMultipleProtocolInterfaces (
221 &gEfiGraphicsOutputProtocolGuid
,
222 &Private
->GraphicsOutput
,
223 &gEfiSimpleTextInProtocolGuid
,
224 &Private
->SimpleTextIn
,
229 if (EFI_ERROR (Status
)) {
233 &gEfiWinNtIoProtocolGuid
,
234 This
->DriverBindingHandle
,
238 if (Private
!= NULL
) {
240 // On Error Free back private data
242 if (Private
->ControllerNameTable
!= NULL
) {
243 FreeUnicodeStringTable (Private
->ControllerNameTable
);
260 // TODO: This - add argument and description to function comment
261 // TODO: Handle - add argument and description to function comment
262 // TODO: NumberOfChildren - add argument and description to function comment
263 // TODO: ChildHandleBuffer - add argument and description to function comment
264 // TODO: EFI_NOT_STARTED - add return value to function comment
265 // TODO: EFI_DEVICE_ERROR - add return value to function comment
268 WinNtGopDriverBindingStop (
269 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
270 IN EFI_HANDLE Handle
,
271 IN UINTN NumberOfChildren
,
272 IN EFI_HANDLE
*ChildHandleBuffer
275 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
277 GOP_PRIVATE_DATA
*Private
;
279 Status
= gBS
->OpenProtocol (
281 &gEfiGraphicsOutputProtocolGuid
,
283 This
->DriverBindingHandle
,
285 EFI_OPEN_PROTOCOL_GET_PROTOCOL
287 if (EFI_ERROR (Status
)) {
289 // If the GOP interface does not exist the driver is not started
291 return EFI_NOT_STARTED
;
295 // Get our private context information
297 Private
= GOP_PRIVATE_DATA_FROM_THIS (GraphicsOutput
);
300 // Remove the SGO interface from the system
302 Status
= gBS
->UninstallMultipleProtocolInterfaces (
304 &gEfiGraphicsOutputProtocolGuid
,
305 &Private
->GraphicsOutput
,
306 &gEfiSimpleTextInProtocolGuid
,
307 &Private
->SimpleTextIn
,
310 if (!EFI_ERROR (Status
)) {
312 // Shutdown the hardware
314 Status
= WinNtGopDestructor (Private
);
315 if (EFI_ERROR (Status
)) {
316 return EFI_DEVICE_ERROR
;
321 &gEfiWinNtIoProtocolGuid
,
322 This
->DriverBindingHandle
,
327 // Free our instance data
329 FreeUnicodeStringTable (Private
->ControllerNameTable
);