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
,
39 //@MT: EFI_DRIVER_ENTRY_POINT (PciVgaMiniPortDriverEntryPoint)
43 PciVgaMiniPortDriverEntryPoint (
44 IN EFI_HANDLE ImageHandle
,
45 IN EFI_SYSTEM_TABLE
*SystemTable
53 (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)
59 return EfiLibInstallAllDriverProtocols (
62 &gPciVgaMiniPortDriverBinding
,
64 &gPciVgaMiniPortComponentName
,
74 (Standard DriverBinding Protocol Supported() function)
81 PciVgaMiniPortDriverBindingSupported (
82 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
83 IN EFI_HANDLE Controller
,
84 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
88 EFI_PCI_IO_PROTOCOL
*PciIo
;
92 // Open the IO Abstraction(s) needed to perform the supported test
94 Status
= gBS
->OpenProtocol (
96 &gEfiPciIoProtocolGuid
,
98 This
->DriverBindingHandle
,
100 EFI_OPEN_PROTOCOL_BY_DRIVER
102 if (EFI_ERROR (Status
)) {
106 // See if this is a PCI VGA Controller by looking at the Command register and
107 // Class Code Register
109 Status
= PciIo
->Pci
.Read (
113 sizeof (Pci
) / sizeof (UINT32
),
116 if (EFI_ERROR (Status
)) {
120 Status
= EFI_UNSUPPORTED
;
122 // See if the device is an enabled VGA device.
123 // Most systems can only have on VGA device on at a time.
125 if (((Pci
.Hdr
.Command
& 0x03) == 0x03) && IS_PCI_VGA (&Pci
)) {
126 Status
= EFI_SUCCESS
;
132 &gEfiPciIoProtocolGuid
,
133 This
->DriverBindingHandle
,
142 Install VGA Mini Port Protocol onto VGA device handles
144 (Standard DriverBinding Protocol Start() function)
151 PciVgaMiniPortDriverBindingStart (
152 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
153 IN EFI_HANDLE Controller
,
154 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
158 EFI_PCI_IO_PROTOCOL
*PciIo
;
159 PCI_VGA_MINI_PORT_DEV
*PciVgaMiniPortPrivate
;
161 PciVgaMiniPortPrivate
= NULL
;
164 // Open the IO Abstraction(s) needed
166 Status
= gBS
->OpenProtocol (
168 &gEfiPciIoProtocolGuid
,
170 This
->DriverBindingHandle
,
172 EFI_OPEN_PROTOCOL_BY_DRIVER
174 if (EFI_ERROR (Status
)) {
178 // Allocate the private device structure
180 Status
= gBS
->AllocatePool (
182 sizeof (PCI_VGA_MINI_PORT_DEV
),
183 (VOID
**) &PciVgaMiniPortPrivate
185 if (EFI_ERROR (Status
)) {
189 ZeroMem (PciVgaMiniPortPrivate
, sizeof (PCI_VGA_MINI_PORT_DEV
));
192 // Initialize the private device structure
194 PciVgaMiniPortPrivate
->Signature
= PCI_VGA_MINI_PORT_DEV_SIGNATURE
;
195 PciVgaMiniPortPrivate
->Handle
= Controller
;
196 PciVgaMiniPortPrivate
->PciIo
= PciIo
;
198 PciVgaMiniPortPrivate
->VgaMiniPort
.SetMode
= PciVgaMiniPortSetMode
;
199 PciVgaMiniPortPrivate
->VgaMiniPort
.VgaMemoryOffset
= 0xb8000;
200 PciVgaMiniPortPrivate
->VgaMiniPort
.CrtcAddressRegisterOffset
= 0x3d4;
201 PciVgaMiniPortPrivate
->VgaMiniPort
.CrtcDataRegisterOffset
= 0x3d5;
202 PciVgaMiniPortPrivate
->VgaMiniPort
.VgaMemoryBar
= EFI_PCI_IO_PASS_THROUGH_BAR
;
203 PciVgaMiniPortPrivate
->VgaMiniPort
.CrtcAddressRegisterBar
= EFI_PCI_IO_PASS_THROUGH_BAR
;
204 PciVgaMiniPortPrivate
->VgaMiniPort
.CrtcDataRegisterBar
= EFI_PCI_IO_PASS_THROUGH_BAR
;
205 PciVgaMiniPortPrivate
->VgaMiniPort
.MaxMode
= 1;
208 // Install Vga Mini Port Protocol
210 Status
= gBS
->InstallMultipleProtocolInterfaces (
212 &gEfiVgaMiniPortProtocolGuid
,
213 &PciVgaMiniPortPrivate
->VgaMiniPort
,
217 if (EFI_ERROR (Status
)) {
220 &gEfiPciIoProtocolGuid
,
221 This
->DriverBindingHandle
,
224 if (PciVgaMiniPortPrivate
) {
225 gBS
->FreePool (PciVgaMiniPortPrivate
);
236 (Standard DriverBinding Protocol Stop() function)
243 PciVgaMiniPortDriverBindingStop (
244 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
245 IN EFI_HANDLE Controller
,
246 IN UINTN NumberOfChildren
,
247 IN EFI_HANDLE
*ChildHandleBuffer
251 EFI_VGA_MINI_PORT_PROTOCOL
*VgaMiniPort
;
252 PCI_VGA_MINI_PORT_DEV
*PciVgaMiniPortPrivate
;
254 Status
= gBS
->OpenProtocol (
256 &gEfiVgaMiniPortProtocolGuid
,
257 (VOID
**) &VgaMiniPort
,
258 This
->DriverBindingHandle
,
260 EFI_OPEN_PROTOCOL_GET_PROTOCOL
262 if (EFI_ERROR (Status
)) {
266 PciVgaMiniPortPrivate
= PCI_VGA_MINI_PORT_DEV_FROM_THIS (VgaMiniPort
);
268 Status
= gBS
->UninstallProtocolInterface (
270 &gEfiVgaMiniPortProtocolGuid
,
271 &PciVgaMiniPortPrivate
->VgaMiniPort
273 if (EFI_ERROR (Status
)) {
279 &gEfiPciIoProtocolGuid
,
280 This
->DriverBindingHandle
,
284 gBS
->FreePool (PciVgaMiniPortPrivate
);
289 // VGA Mini Port Protocol Functions
293 GC_TODO: Add function description
295 @param This GC_TODO: add argument description
296 @param ModeNumber GC_TODO: add argument description
298 @retval EFI_UNSUPPORTED GC_TODO: Add description for return value
299 @retval EFI_SUCCESS GC_TODO: Add description for return value
304 PciVgaMiniPortSetMode (
305 IN EFI_VGA_MINI_PORT_PROTOCOL
*This
,
309 if (ModeNumber
> This
->MaxMode
) {
310 return EFI_UNSUPPORTED
;