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 EfiLibInstallAllDriverProtocols (
60 &gPciVgaMiniPortDriverBinding
,
62 &gPciVgaMiniPortComponentName
,
72 (Standard DriverBinding Protocol Supported() function)
79 PciVgaMiniPortDriverBindingSupported (
80 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
81 IN EFI_HANDLE Controller
,
82 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
86 EFI_PCI_IO_PROTOCOL
*PciIo
;
90 // Open the IO Abstraction(s) needed to perform the supported test
92 Status
= gBS
->OpenProtocol (
94 &gEfiPciIoProtocolGuid
,
96 This
->DriverBindingHandle
,
98 EFI_OPEN_PROTOCOL_BY_DRIVER
100 if (EFI_ERROR (Status
)) {
104 // See if this is a PCI VGA Controller by looking at the Command register and
105 // Class Code Register
107 Status
= PciIo
->Pci
.Read (
111 sizeof (Pci
) / sizeof (UINT32
),
114 if (EFI_ERROR (Status
)) {
118 Status
= EFI_UNSUPPORTED
;
120 // See if the device is an enabled VGA device.
121 // Most systems can only have on VGA device on at a time.
123 if (((Pci
.Hdr
.Command
& 0x03) == 0x03) && IS_PCI_VGA (&Pci
)) {
124 Status
= EFI_SUCCESS
;
130 &gEfiPciIoProtocolGuid
,
131 This
->DriverBindingHandle
,
140 Install VGA Mini Port Protocol onto VGA device handles
142 (Standard DriverBinding Protocol Start() function)
149 PciVgaMiniPortDriverBindingStart (
150 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
151 IN EFI_HANDLE Controller
,
152 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
156 EFI_PCI_IO_PROTOCOL
*PciIo
;
157 PCI_VGA_MINI_PORT_DEV
*PciVgaMiniPortPrivate
;
159 PciVgaMiniPortPrivate
= NULL
;
162 // Open the IO Abstraction(s) needed
164 Status
= gBS
->OpenProtocol (
166 &gEfiPciIoProtocolGuid
,
168 This
->DriverBindingHandle
,
170 EFI_OPEN_PROTOCOL_BY_DRIVER
172 if (EFI_ERROR (Status
)) {
176 // Allocate the private device structure
178 Status
= gBS
->AllocatePool (
180 sizeof (PCI_VGA_MINI_PORT_DEV
),
181 (VOID
**) &PciVgaMiniPortPrivate
183 if (EFI_ERROR (Status
)) {
187 ZeroMem (PciVgaMiniPortPrivate
, sizeof (PCI_VGA_MINI_PORT_DEV
));
190 // Initialize the private device structure
192 PciVgaMiniPortPrivate
->Signature
= PCI_VGA_MINI_PORT_DEV_SIGNATURE
;
193 PciVgaMiniPortPrivate
->Handle
= Controller
;
194 PciVgaMiniPortPrivate
->PciIo
= PciIo
;
196 PciVgaMiniPortPrivate
->VgaMiniPort
.SetMode
= PciVgaMiniPortSetMode
;
197 PciVgaMiniPortPrivate
->VgaMiniPort
.VgaMemoryOffset
= 0xb8000;
198 PciVgaMiniPortPrivate
->VgaMiniPort
.CrtcAddressRegisterOffset
= 0x3d4;
199 PciVgaMiniPortPrivate
->VgaMiniPort
.CrtcDataRegisterOffset
= 0x3d5;
200 PciVgaMiniPortPrivate
->VgaMiniPort
.VgaMemoryBar
= EFI_PCI_IO_PASS_THROUGH_BAR
;
201 PciVgaMiniPortPrivate
->VgaMiniPort
.CrtcAddressRegisterBar
= EFI_PCI_IO_PASS_THROUGH_BAR
;
202 PciVgaMiniPortPrivate
->VgaMiniPort
.CrtcDataRegisterBar
= EFI_PCI_IO_PASS_THROUGH_BAR
;
203 PciVgaMiniPortPrivate
->VgaMiniPort
.MaxMode
= 1;
206 // Install Vga Mini Port Protocol
208 Status
= gBS
->InstallMultipleProtocolInterfaces (
210 &gEfiVgaMiniPortProtocolGuid
,
211 &PciVgaMiniPortPrivate
->VgaMiniPort
,
215 if (EFI_ERROR (Status
)) {
218 &gEfiPciIoProtocolGuid
,
219 This
->DriverBindingHandle
,
222 if (PciVgaMiniPortPrivate
) {
223 gBS
->FreePool (PciVgaMiniPortPrivate
);
234 (Standard DriverBinding Protocol Stop() function)
241 PciVgaMiniPortDriverBindingStop (
242 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
243 IN EFI_HANDLE Controller
,
244 IN UINTN NumberOfChildren
,
245 IN EFI_HANDLE
*ChildHandleBuffer
249 EFI_VGA_MINI_PORT_PROTOCOL
*VgaMiniPort
;
250 PCI_VGA_MINI_PORT_DEV
*PciVgaMiniPortPrivate
;
252 Status
= gBS
->OpenProtocol (
254 &gEfiVgaMiniPortProtocolGuid
,
255 (VOID
**) &VgaMiniPort
,
256 This
->DriverBindingHandle
,
258 EFI_OPEN_PROTOCOL_GET_PROTOCOL
260 if (EFI_ERROR (Status
)) {
264 PciVgaMiniPortPrivate
= PCI_VGA_MINI_PORT_DEV_FROM_THIS (VgaMiniPort
);
266 Status
= gBS
->UninstallProtocolInterface (
268 &gEfiVgaMiniPortProtocolGuid
,
269 &PciVgaMiniPortPrivate
->VgaMiniPort
271 if (EFI_ERROR (Status
)) {
277 &gEfiPciIoProtocolGuid
,
278 This
->DriverBindingHandle
,
282 gBS
->FreePool (PciVgaMiniPortPrivate
);
287 // VGA Mini Port Protocol Functions
291 GC_TODO: Add function description
293 @param This GC_TODO: add argument description
294 @param ModeNumber GC_TODO: add argument description
296 @retval EFI_UNSUPPORTED GC_TODO: Add description for return value
297 @retval EFI_SUCCESS GC_TODO: Add description for return value
302 PciVgaMiniPortSetMode (
303 IN EFI_VGA_MINI_PORT_PROTOCOL
*This
,
307 if (ModeNumber
> This
->MaxMode
) {
308 return EFI_UNSUPPORTED
;