3 Copyright (c) 2006 Intel Corporation. All rights reserved
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.
24 #include "VgaMiniPort.h"
27 // EFI Driver Binding Protocol Instance
29 // This driver has a version value of 0x00000000. This is the
30 // lowest possible priority for a driver. This is done on purpose to help
31 // the developers of UGA drivers. This driver can bind if no UGA driver
32 // is present, so a console is available. Then, when a UGA driver is loaded
33 // this driver can be disconnected, and the UGA driver can be connected.
34 // As long as the UGA driver has a version value greater than 0x00000000, it
35 // will be connected first and will block this driver from connecting.
37 EFI_DRIVER_BINDING_PROTOCOL gPciVgaMiniPortDriverBinding
= {
38 PciVgaMiniPortDriverBindingSupported
,
39 PciVgaMiniPortDriverBindingStart
,
40 PciVgaMiniPortDriverBindingStop
,
49 //@MT: EFI_DRIVER_ENTRY_POINT (PciVgaMiniPortDriverEntryPoint)
53 PciVgaMiniPortDriverEntryPoint (
54 IN EFI_HANDLE ImageHandle
,
55 IN EFI_SYSTEM_TABLE
*SystemTable
63 (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)
69 return EfiLibInstallAllDriverProtocols (
72 &gPciVgaMiniPortDriverBinding
,
74 &gPciVgaMiniPortComponentName
,
84 (Standard DriverBinding Protocol Supported() function)
91 PciVgaMiniPortDriverBindingSupported (
92 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
93 IN EFI_HANDLE Controller
,
94 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
98 EFI_PCI_IO_PROTOCOL
*PciIo
;
102 // Open the IO Abstraction(s) needed to perform the supported test
104 Status
= gBS
->OpenProtocol (
106 &gEfiPciIoProtocolGuid
,
108 This
->DriverBindingHandle
,
110 EFI_OPEN_PROTOCOL_BY_DRIVER
112 if (EFI_ERROR (Status
)) {
116 // See if this is a PCI VGA Controller by looking at the Command register and
117 // Class Code Register
119 Status
= PciIo
->Pci
.Read (
123 sizeof (Pci
) / sizeof (UINT32
),
126 if (EFI_ERROR (Status
)) {
130 Status
= EFI_UNSUPPORTED
;
132 // See if the device is an enabled VGA device.
133 // Most systems can only have on VGA device on at a time.
135 if (((Pci
.Hdr
.Command
& 0x03) == 0x03) && IS_PCI_VGA (&Pci
)) {
136 Status
= EFI_SUCCESS
;
142 &gEfiPciIoProtocolGuid
,
143 This
->DriverBindingHandle
,
152 Install VGA Mini Port Protocol onto VGA device handles
154 (Standard DriverBinding Protocol Start() function)
161 PciVgaMiniPortDriverBindingStart (
162 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
163 IN EFI_HANDLE Controller
,
164 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
168 EFI_PCI_IO_PROTOCOL
*PciIo
;
169 PCI_VGA_MINI_PORT_DEV
*PciVgaMiniPortPrivate
;
171 PciVgaMiniPortPrivate
= NULL
;
174 // Open the IO Abstraction(s) needed
176 Status
= gBS
->OpenProtocol (
178 &gEfiPciIoProtocolGuid
,
180 This
->DriverBindingHandle
,
182 EFI_OPEN_PROTOCOL_BY_DRIVER
184 if (EFI_ERROR (Status
)) {
188 // Allocate the private device structure
190 Status
= gBS
->AllocatePool (
192 sizeof (PCI_VGA_MINI_PORT_DEV
),
193 &PciVgaMiniPortPrivate
195 if (EFI_ERROR (Status
)) {
199 ZeroMem (PciVgaMiniPortPrivate
, sizeof (PCI_VGA_MINI_PORT_DEV
));
202 // Initialize the private device structure
204 PciVgaMiniPortPrivate
->Signature
= PCI_VGA_MINI_PORT_DEV_SIGNATURE
;
205 PciVgaMiniPortPrivate
->Handle
= Controller
;
206 PciVgaMiniPortPrivate
->PciIo
= PciIo
;
208 PciVgaMiniPortPrivate
->VgaMiniPort
.SetMode
= PciVgaMiniPortSetMode
;
209 PciVgaMiniPortPrivate
->VgaMiniPort
.VgaMemoryOffset
= 0xb8000;
210 PciVgaMiniPortPrivate
->VgaMiniPort
.CrtcAddressRegisterOffset
= 0x3d4;
211 PciVgaMiniPortPrivate
->VgaMiniPort
.CrtcDataRegisterOffset
= 0x3d5;
212 PciVgaMiniPortPrivate
->VgaMiniPort
.VgaMemoryBar
= EFI_PCI_IO_PASS_THROUGH_BAR
;
213 PciVgaMiniPortPrivate
->VgaMiniPort
.CrtcAddressRegisterBar
= EFI_PCI_IO_PASS_THROUGH_BAR
;
214 PciVgaMiniPortPrivate
->VgaMiniPort
.CrtcDataRegisterBar
= EFI_PCI_IO_PASS_THROUGH_BAR
;
215 PciVgaMiniPortPrivate
->VgaMiniPort
.MaxMode
= 1;
218 // Install Vga Mini Port Protocol
220 Status
= gBS
->InstallMultipleProtocolInterfaces (
222 &gEfiVgaMiniPortProtocolGuid
,
223 &PciVgaMiniPortPrivate
->VgaMiniPort
,
227 if (EFI_ERROR (Status
)) {
230 &gEfiPciIoProtocolGuid
,
231 This
->DriverBindingHandle
,
234 if (PciVgaMiniPortPrivate
) {
235 gBS
->FreePool (PciVgaMiniPortPrivate
);
246 (Standard DriverBinding Protocol Stop() function)
253 PciVgaMiniPortDriverBindingStop (
254 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
255 IN EFI_HANDLE Controller
,
256 IN UINTN NumberOfChildren
,
257 IN EFI_HANDLE
*ChildHandleBuffer
261 EFI_VGA_MINI_PORT_PROTOCOL
*VgaMiniPort
;
262 PCI_VGA_MINI_PORT_DEV
*PciVgaMiniPortPrivate
;
264 Status
= gBS
->OpenProtocol (
266 &gEfiVgaMiniPortProtocolGuid
,
267 (VOID
**) &VgaMiniPort
,
268 This
->DriverBindingHandle
,
270 EFI_OPEN_PROTOCOL_GET_PROTOCOL
272 if (EFI_ERROR (Status
)) {
276 PciVgaMiniPortPrivate
= PCI_VGA_MINI_PORT_DEV_FROM_THIS (VgaMiniPort
);
278 Status
= gBS
->UninstallProtocolInterface (
280 &gEfiVgaMiniPortProtocolGuid
,
281 &PciVgaMiniPortPrivate
->VgaMiniPort
283 if (EFI_ERROR (Status
)) {
289 &gEfiPciIoProtocolGuid
,
290 This
->DriverBindingHandle
,
294 gBS
->FreePool (PciVgaMiniPortPrivate
);
299 // VGA Mini Port Protocol Functions
303 GC_TODO: Add function description
305 @param This GC_TODO: add argument description
306 @param ModeNumber GC_TODO: add argument description
308 @retval EFI_UNSUPPORTED GC_TODO: Add description for return value
309 @retval EFI_SUCCESS GC_TODO: Add description for return value
314 PciVgaMiniPortSetMode (
315 IN EFI_VGA_MINI_PORT_PROTOCOL
*This
,
319 if (ModeNumber
> This
->MaxMode
) {
320 return EFI_UNSUPPORTED
;