3 Copyright (c) 2006 Intel Corporation. All rights reserved
4 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.
14 #include "VgaMiniPort.h"
17 // EFI Driver Binding Protocol Instance
19 // This driver has a version value of 0x00000000. This is the
20 // lowest possible priority for a driver. This is done on purpose to help
21 // the developers of UGA drivers. This driver can bind if no UGA driver
22 // is present, so a console is available. Then, when a UGA driver is loaded
23 // this driver can be disconnected, and the UGA driver can be connected.
24 // As long as the UGA driver has a version value greater than 0x00000000, it
25 // will be connected first and will block this driver from connecting.
27 EFI_DRIVER_BINDING_PROTOCOL gPciVgaMiniPortDriverBinding
= {
28 PciVgaMiniPortDriverBindingSupported
,
29 PciVgaMiniPortDriverBindingStart
,
30 PciVgaMiniPortDriverBindingStop
,
37 Driver entry point for VgaMiniPort driver.
39 @param ImageHandle Driver image handle
40 @param SystemTable Point to EFI_SYSTEM_TABLE
42 @retval Status of install driver binding protocol.
46 PciVgaMiniPortDriverEntryPoint (
47 IN EFI_HANDLE ImageHandle
,
48 IN EFI_SYSTEM_TABLE
*SystemTable
51 return EfiLibInstallDriverBindingComponentName2 (
54 &gPciVgaMiniPortDriverBinding
,
56 &gPciVgaMiniPortComponentName
,
57 &gPciVgaMiniPortComponentName2
65 (Standard DriverBinding Protocol Supported() function)
72 PciVgaMiniPortDriverBindingSupported (
73 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
74 IN EFI_HANDLE Controller
,
75 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
79 EFI_PCI_IO_PROTOCOL
*PciIo
;
83 // Open the IO Abstraction(s) needed to perform the supported test
85 Status
= gBS
->OpenProtocol (
87 &gEfiPciIoProtocolGuid
,
89 This
->DriverBindingHandle
,
91 EFI_OPEN_PROTOCOL_BY_DRIVER
93 if (EFI_ERROR (Status
)) {
97 // See if this is a PCI VGA Controller by looking at the Command register and
98 // Class Code Register
100 Status
= PciIo
->Pci
.Read (
104 sizeof (Pci
) / sizeof (UINT32
),
107 if (EFI_ERROR (Status
)) {
111 Status
= EFI_UNSUPPORTED
;
113 // See if the device is an enabled VGA device.
114 // Most systems can only have on VGA device on at a time.
116 if (((Pci
.Hdr
.Command
& 0x03) == 0x03) && IS_PCI_VGA (&Pci
)) {
117 Status
= EFI_SUCCESS
;
123 &gEfiPciIoProtocolGuid
,
124 This
->DriverBindingHandle
,
133 Install VGA Mini Port Protocol onto VGA device handles
135 (Standard DriverBinding Protocol Start() function)
142 PciVgaMiniPortDriverBindingStart (
143 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
144 IN EFI_HANDLE Controller
,
145 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
149 EFI_PCI_IO_PROTOCOL
*PciIo
;
150 PCI_VGA_MINI_PORT_DEV
*PciVgaMiniPortPrivate
;
152 PciVgaMiniPortPrivate
= NULL
;
155 // Open the IO Abstraction(s) needed
157 Status
= gBS
->OpenProtocol (
159 &gEfiPciIoProtocolGuid
,
161 This
->DriverBindingHandle
,
163 EFI_OPEN_PROTOCOL_BY_DRIVER
165 if (EFI_ERROR (Status
)) {
169 // Allocate the private device structure
171 Status
= gBS
->AllocatePool (
173 sizeof (PCI_VGA_MINI_PORT_DEV
),
174 (VOID
**) &PciVgaMiniPortPrivate
176 if (EFI_ERROR (Status
)) {
180 ZeroMem (PciVgaMiniPortPrivate
, sizeof (PCI_VGA_MINI_PORT_DEV
));
183 // Initialize the private device structure
185 PciVgaMiniPortPrivate
->Signature
= PCI_VGA_MINI_PORT_DEV_SIGNATURE
;
186 PciVgaMiniPortPrivate
->Handle
= Controller
;
187 PciVgaMiniPortPrivate
->PciIo
= PciIo
;
189 PciVgaMiniPortPrivate
->VgaMiniPort
.SetMode
= PciVgaMiniPortSetMode
;
190 PciVgaMiniPortPrivate
->VgaMiniPort
.VgaMemoryOffset
= 0xb8000;
191 PciVgaMiniPortPrivate
->VgaMiniPort
.CrtcAddressRegisterOffset
= 0x3d4;
192 PciVgaMiniPortPrivate
->VgaMiniPort
.CrtcDataRegisterOffset
= 0x3d5;
193 PciVgaMiniPortPrivate
->VgaMiniPort
.VgaMemoryBar
= EFI_PCI_IO_PASS_THROUGH_BAR
;
194 PciVgaMiniPortPrivate
->VgaMiniPort
.CrtcAddressRegisterBar
= EFI_PCI_IO_PASS_THROUGH_BAR
;
195 PciVgaMiniPortPrivate
->VgaMiniPort
.CrtcDataRegisterBar
= EFI_PCI_IO_PASS_THROUGH_BAR
;
196 PciVgaMiniPortPrivate
->VgaMiniPort
.MaxMode
= 1;
199 // Install Vga Mini Port Protocol
201 Status
= gBS
->InstallMultipleProtocolInterfaces (
203 &gEfiVgaMiniPortProtocolGuid
,
204 &PciVgaMiniPortPrivate
->VgaMiniPort
,
208 if (EFI_ERROR (Status
)) {
211 &gEfiPciIoProtocolGuid
,
212 This
->DriverBindingHandle
,
215 if (PciVgaMiniPortPrivate
) {
216 gBS
->FreePool (PciVgaMiniPortPrivate
);
227 (Standard DriverBinding Protocol Stop() function)
234 PciVgaMiniPortDriverBindingStop (
235 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
236 IN EFI_HANDLE Controller
,
237 IN UINTN NumberOfChildren
,
238 IN EFI_HANDLE
*ChildHandleBuffer
242 EFI_VGA_MINI_PORT_PROTOCOL
*VgaMiniPort
;
243 PCI_VGA_MINI_PORT_DEV
*PciVgaMiniPortPrivate
;
245 Status
= gBS
->OpenProtocol (
247 &gEfiVgaMiniPortProtocolGuid
,
248 (VOID
**) &VgaMiniPort
,
249 This
->DriverBindingHandle
,
251 EFI_OPEN_PROTOCOL_GET_PROTOCOL
253 if (EFI_ERROR (Status
)) {
257 PciVgaMiniPortPrivate
= PCI_VGA_MINI_PORT_DEV_FROM_THIS (VgaMiniPort
);
259 Status
= gBS
->UninstallProtocolInterface (
261 &gEfiVgaMiniPortProtocolGuid
,
262 &PciVgaMiniPortPrivate
->VgaMiniPort
264 if (EFI_ERROR (Status
)) {
270 &gEfiPciIoProtocolGuid
,
271 This
->DriverBindingHandle
,
275 gBS
->FreePool (PciVgaMiniPortPrivate
);
280 // VGA Mini Port Protocol Functions
284 Thunk function of EFI_VGA_MINI_PORT_SET_MODE
286 @param This Point to instance of EFI_VGA_MINI_PORT_PROTOCOL
287 @param ModeNumber Mode number
289 @retval EFI_UNSUPPORTED Invalid mode number
290 @retval EFI_SUCCESS Success
295 PciVgaMiniPortSetMode (
296 IN EFI_VGA_MINI_PORT_PROTOCOL
*This
,
300 if (ModeNumber
> This
->MaxMode
) {
301 return EFI_UNSUPPORTED
;