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)
67 @param This The driver binding protocol.
68 @param Controller The controller handle to check.
69 @param RemainingDevicePath The remaining device path.
71 @retval EFI_SUCCESS The driver supports this controller.
72 @retval EFI_UNSUPPORTED This device isn't supported.
77 PciVgaMiniPortDriverBindingSupported (
78 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
79 IN EFI_HANDLE Controller
,
80 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
84 EFI_PCI_IO_PROTOCOL
*PciIo
;
88 // Open the IO Abstraction(s) needed to perform the supported test
90 Status
= gBS
->OpenProtocol (
92 &gEfiPciIoProtocolGuid
,
94 This
->DriverBindingHandle
,
96 EFI_OPEN_PROTOCOL_BY_DRIVER
98 if (EFI_ERROR (Status
)) {
102 // See if this is a PCI VGA Controller by looking at the Command register and
103 // Class Code Register
105 Status
= PciIo
->Pci
.Read (
109 sizeof (Pci
) / sizeof (UINT32
),
112 if (EFI_ERROR (Status
)) {
116 Status
= EFI_UNSUPPORTED
;
118 // See if the device is an enabled VGA device.
119 // Most systems can only have on VGA device on at a time.
121 if (((Pci
.Hdr
.Command
& 0x03) == 0x03) && IS_PCI_VGA (&Pci
)) {
122 Status
= EFI_SUCCESS
;
128 &gEfiPciIoProtocolGuid
,
129 This
->DriverBindingHandle
,
138 Install VGA Mini Port Protocol onto VGA device handles
140 (Standard DriverBinding Protocol Start() function)
142 @param This The driver binding instance.
143 @param Controller The controller to check.
144 @param RemainingDevicePath The remaining device patch.
146 @retval EFI_SUCCESS The controller is controlled by the driver.
147 @retval EFI_ALREADY_STARTED The controller is already controlled by the driver.
148 @retval EFI_OUT_OF_RESOURCES Failed to allocate resources.
153 PciVgaMiniPortDriverBindingStart (
154 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
155 IN EFI_HANDLE Controller
,
156 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
160 EFI_PCI_IO_PROTOCOL
*PciIo
;
161 PCI_VGA_MINI_PORT_DEV
*PciVgaMiniPortPrivate
;
163 PciVgaMiniPortPrivate
= NULL
;
166 // Open the IO Abstraction(s) needed
168 Status
= gBS
->OpenProtocol (
170 &gEfiPciIoProtocolGuid
,
172 This
->DriverBindingHandle
,
174 EFI_OPEN_PROTOCOL_BY_DRIVER
176 if (EFI_ERROR (Status
)) {
180 // Allocate the private device structure
182 Status
= gBS
->AllocatePool (
184 sizeof (PCI_VGA_MINI_PORT_DEV
),
185 (VOID
**) &PciVgaMiniPortPrivate
187 if (EFI_ERROR (Status
)) {
191 ZeroMem (PciVgaMiniPortPrivate
, sizeof (PCI_VGA_MINI_PORT_DEV
));
194 // Initialize the private device structure
196 PciVgaMiniPortPrivate
->Signature
= PCI_VGA_MINI_PORT_DEV_SIGNATURE
;
197 PciVgaMiniPortPrivate
->Handle
= Controller
;
198 PciVgaMiniPortPrivate
->PciIo
= PciIo
;
200 PciVgaMiniPortPrivate
->VgaMiniPort
.SetMode
= PciVgaMiniPortSetMode
;
201 PciVgaMiniPortPrivate
->VgaMiniPort
.VgaMemoryOffset
= 0xb8000;
202 PciVgaMiniPortPrivate
->VgaMiniPort
.CrtcAddressRegisterOffset
= 0x3d4;
203 PciVgaMiniPortPrivate
->VgaMiniPort
.CrtcDataRegisterOffset
= 0x3d5;
204 PciVgaMiniPortPrivate
->VgaMiniPort
.VgaMemoryBar
= EFI_PCI_IO_PASS_THROUGH_BAR
;
205 PciVgaMiniPortPrivate
->VgaMiniPort
.CrtcAddressRegisterBar
= EFI_PCI_IO_PASS_THROUGH_BAR
;
206 PciVgaMiniPortPrivate
->VgaMiniPort
.CrtcDataRegisterBar
= EFI_PCI_IO_PASS_THROUGH_BAR
;
207 PciVgaMiniPortPrivate
->VgaMiniPort
.MaxMode
= 1;
210 // Install Vga Mini Port Protocol
212 Status
= gBS
->InstallMultipleProtocolInterfaces (
214 &gEfiVgaMiniPortProtocolGuid
,
215 &PciVgaMiniPortPrivate
->VgaMiniPort
,
219 if (EFI_ERROR (Status
)) {
222 &gEfiPciIoProtocolGuid
,
223 This
->DriverBindingHandle
,
226 if (PciVgaMiniPortPrivate
!= NULL
) {
227 gBS
->FreePool (PciVgaMiniPortPrivate
);
238 (Standard DriverBinding Protocol Stop() function)
240 @param This The driver binding protocol.
241 @param Controller The controller to release.
242 @param NumberOfChildren The child number that opened controller
244 @param ChildHandleBuffer The array of child handle.
246 @retval EFI_SUCCESS The controller or children are stopped.
247 @retval EFI_DEVICE_ERROR Failed to stop the driver.
252 PciVgaMiniPortDriverBindingStop (
253 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
254 IN EFI_HANDLE Controller
,
255 IN UINTN NumberOfChildren
,
256 IN EFI_HANDLE
*ChildHandleBuffer
260 EFI_VGA_MINI_PORT_PROTOCOL
*VgaMiniPort
;
261 PCI_VGA_MINI_PORT_DEV
*PciVgaMiniPortPrivate
;
263 Status
= gBS
->OpenProtocol (
265 &gEfiVgaMiniPortProtocolGuid
,
266 (VOID
**) &VgaMiniPort
,
267 This
->DriverBindingHandle
,
269 EFI_OPEN_PROTOCOL_GET_PROTOCOL
271 if (EFI_ERROR (Status
)) {
275 PciVgaMiniPortPrivate
= PCI_VGA_MINI_PORT_DEV_FROM_THIS (VgaMiniPort
);
277 Status
= gBS
->UninstallProtocolInterface (
279 &gEfiVgaMiniPortProtocolGuid
,
280 &PciVgaMiniPortPrivate
->VgaMiniPort
282 if (EFI_ERROR (Status
)) {
288 &gEfiPciIoProtocolGuid
,
289 This
->DriverBindingHandle
,
293 gBS
->FreePool (PciVgaMiniPortPrivate
);
298 // VGA Mini Port Protocol Functions
302 Thunk function of EFI_VGA_MINI_PORT_SET_MODE.
304 @param This Point to instance of EFI_VGA_MINI_PORT_PROTOCOL.
305 @param ModeNumber Mode number.
307 @retval EFI_UNSUPPORTED Invalid mode number.
308 @retval EFI_SUCCESS Success.
313 PciVgaMiniPortSetMode (
314 IN EFI_VGA_MINI_PORT_PROTOCOL
*This
,
318 if (ModeNumber
> This
->MaxMode
) {
319 return EFI_UNSUPPORTED
;