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
,
41 PciVgaMiniPortDriverEntryPoint (
42 IN EFI_HANDLE ImageHandle
,
43 IN EFI_SYSTEM_TABLE
*SystemTable
51 (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)
57 return EfiLibInstallDriverBindingComponentName2 (
60 &gPciVgaMiniPortDriverBinding
,
62 &gPciVgaMiniPortComponentName
,
63 &gPciVgaMiniPortComponentName2
71 (Standard DriverBinding Protocol Supported() function)
78 PciVgaMiniPortDriverBindingSupported (
79 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
80 IN EFI_HANDLE Controller
,
81 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
85 EFI_PCI_IO_PROTOCOL
*PciIo
;
89 // Open the IO Abstraction(s) needed to perform the supported test
91 Status
= gBS
->OpenProtocol (
93 &gEfiPciIoProtocolGuid
,
95 This
->DriverBindingHandle
,
97 EFI_OPEN_PROTOCOL_BY_DRIVER
99 if (EFI_ERROR (Status
)) {
103 // See if this is a PCI VGA Controller by looking at the Command register and
104 // Class Code Register
106 Status
= PciIo
->Pci
.Read (
110 sizeof (Pci
) / sizeof (UINT32
),
113 if (EFI_ERROR (Status
)) {
117 Status
= EFI_UNSUPPORTED
;
119 // See if the device is an enabled VGA device.
120 // Most systems can only have on VGA device on at a time.
122 if (((Pci
.Hdr
.Command
& 0x03) == 0x03) && IS_PCI_VGA (&Pci
)) {
123 Status
= EFI_SUCCESS
;
129 &gEfiPciIoProtocolGuid
,
130 This
->DriverBindingHandle
,
139 Install VGA Mini Port Protocol onto VGA device handles
141 (Standard DriverBinding Protocol Start() function)
148 PciVgaMiniPortDriverBindingStart (
149 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
150 IN EFI_HANDLE Controller
,
151 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
155 EFI_PCI_IO_PROTOCOL
*PciIo
;
156 PCI_VGA_MINI_PORT_DEV
*PciVgaMiniPortPrivate
;
158 PciVgaMiniPortPrivate
= NULL
;
161 // Open the IO Abstraction(s) needed
163 Status
= gBS
->OpenProtocol (
165 &gEfiPciIoProtocolGuid
,
167 This
->DriverBindingHandle
,
169 EFI_OPEN_PROTOCOL_BY_DRIVER
171 if (EFI_ERROR (Status
)) {
175 // Allocate the private device structure
177 Status
= gBS
->AllocatePool (
179 sizeof (PCI_VGA_MINI_PORT_DEV
),
180 (VOID
**) &PciVgaMiniPortPrivate
182 if (EFI_ERROR (Status
)) {
186 ZeroMem (PciVgaMiniPortPrivate
, sizeof (PCI_VGA_MINI_PORT_DEV
));
189 // Initialize the private device structure
191 PciVgaMiniPortPrivate
->Signature
= PCI_VGA_MINI_PORT_DEV_SIGNATURE
;
192 PciVgaMiniPortPrivate
->Handle
= Controller
;
193 PciVgaMiniPortPrivate
->PciIo
= PciIo
;
195 PciVgaMiniPortPrivate
->VgaMiniPort
.SetMode
= PciVgaMiniPortSetMode
;
196 PciVgaMiniPortPrivate
->VgaMiniPort
.VgaMemoryOffset
= 0xb8000;
197 PciVgaMiniPortPrivate
->VgaMiniPort
.CrtcAddressRegisterOffset
= 0x3d4;
198 PciVgaMiniPortPrivate
->VgaMiniPort
.CrtcDataRegisterOffset
= 0x3d5;
199 PciVgaMiniPortPrivate
->VgaMiniPort
.VgaMemoryBar
= EFI_PCI_IO_PASS_THROUGH_BAR
;
200 PciVgaMiniPortPrivate
->VgaMiniPort
.CrtcAddressRegisterBar
= EFI_PCI_IO_PASS_THROUGH_BAR
;
201 PciVgaMiniPortPrivate
->VgaMiniPort
.CrtcDataRegisterBar
= EFI_PCI_IO_PASS_THROUGH_BAR
;
202 PciVgaMiniPortPrivate
->VgaMiniPort
.MaxMode
= 1;
205 // Install Vga Mini Port Protocol
207 Status
= gBS
->InstallMultipleProtocolInterfaces (
209 &gEfiVgaMiniPortProtocolGuid
,
210 &PciVgaMiniPortPrivate
->VgaMiniPort
,
214 if (EFI_ERROR (Status
)) {
217 &gEfiPciIoProtocolGuid
,
218 This
->DriverBindingHandle
,
221 if (PciVgaMiniPortPrivate
) {
222 gBS
->FreePool (PciVgaMiniPortPrivate
);
233 (Standard DriverBinding Protocol Stop() function)
240 PciVgaMiniPortDriverBindingStop (
241 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
242 IN EFI_HANDLE Controller
,
243 IN UINTN NumberOfChildren
,
244 IN EFI_HANDLE
*ChildHandleBuffer
248 EFI_VGA_MINI_PORT_PROTOCOL
*VgaMiniPort
;
249 PCI_VGA_MINI_PORT_DEV
*PciVgaMiniPortPrivate
;
251 Status
= gBS
->OpenProtocol (
253 &gEfiVgaMiniPortProtocolGuid
,
254 (VOID
**) &VgaMiniPort
,
255 This
->DriverBindingHandle
,
257 EFI_OPEN_PROTOCOL_GET_PROTOCOL
259 if (EFI_ERROR (Status
)) {
263 PciVgaMiniPortPrivate
= PCI_VGA_MINI_PORT_DEV_FROM_THIS (VgaMiniPort
);
265 Status
= gBS
->UninstallProtocolInterface (
267 &gEfiVgaMiniPortProtocolGuid
,
268 &PciVgaMiniPortPrivate
->VgaMiniPort
270 if (EFI_ERROR (Status
)) {
276 &gEfiPciIoProtocolGuid
,
277 This
->DriverBindingHandle
,
281 gBS
->FreePool (PciVgaMiniPortPrivate
);
286 // VGA Mini Port Protocol Functions
290 GC_TODO: Add function description
292 @param This GC_TODO: add argument description
293 @param ModeNumber GC_TODO: add argument description
295 @retval EFI_UNSUPPORTED GC_TODO: Add description for return value
296 @retval EFI_SUCCESS GC_TODO: Add description for return value
301 PciVgaMiniPortSetMode (
302 IN EFI_VGA_MINI_PORT_PROTOCOL
*This
,
306 if (ModeNumber
> This
->MaxMode
) {
307 return EFI_UNSUPPORTED
;