2 Implements EFI Driver Binding Protocol and VGA Mini Port Protocol for VGA Mini Port Driver.
4 Copyright (c) 2006 - 2009 Intel Corporation. All rights reserved
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "VgaMiniPort.h"
18 // EFI Driver Binding Protocol Instance
20 // This driver has a version value of 0x00000000. This is the
21 // lowest possible priority for a driver. This is done on purpose to help
22 // the developers of UGA drivers. This driver can bind if no UGA driver
23 // is present, so a console is available. Then, when a UGA driver is loaded
24 // this driver can be disconnected, and the UGA driver can be connected.
25 // As long as the UGA driver has a version value greater than 0x00000000, it
26 // will be connected first and will block this driver from connecting.
28 EFI_DRIVER_BINDING_PROTOCOL gPciVgaMiniPortDriverBinding
= {
29 PciVgaMiniPortDriverBindingSupported
,
30 PciVgaMiniPortDriverBindingStart
,
31 PciVgaMiniPortDriverBindingStop
,
38 Entrypoint of VGA Mini Port Driver.
40 This function is the entrypoint of UVGA Mini Port Driver. It installs Driver Binding
41 Protocols together with Component Name Protocols.
43 @param ImageHandle The firmware allocated handle for the EFI image.
44 @param SystemTable A pointer to the EFI System Table.
46 @retval EFI_SUCCESS The entry point is executed successfully.
51 PciVgaMiniPortDriverEntryPoint (
52 IN EFI_HANDLE ImageHandle
,
53 IN EFI_SYSTEM_TABLE
*SystemTable
58 Status
= EfiLibInstallDriverBindingComponentName2 (
61 &gPciVgaMiniPortDriverBinding
,
63 &gPciVgaMiniPortComponentName
,
64 &gPciVgaMiniPortComponentName2
66 ASSERT_EFI_ERROR (Status
);
73 Check whether VGA Mini Port driver supports this device.
75 @param This The driver binding protocol.
76 @param Controller The controller handle to check.
77 @param RemainingDevicePath The remaining device path.
79 @retval EFI_SUCCESS The driver supports this controller.
80 @retval EFI_UNSUPPORTED This device isn't supported.
85 PciVgaMiniPortDriverBindingSupported (
86 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
87 IN EFI_HANDLE Controller
,
88 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
92 EFI_PCI_IO_PROTOCOL
*PciIo
;
96 // Open the IO Abstraction(s) needed to perform the supported test
98 Status
= gBS
->OpenProtocol (
100 &gEfiPciIoProtocolGuid
,
102 This
->DriverBindingHandle
,
104 EFI_OPEN_PROTOCOL_BY_DRIVER
106 if (EFI_ERROR (Status
)) {
110 // See if this is a PCI VGA Controller by looking at the Command register and
111 // Class Code Register
113 Status
= PciIo
->Pci
.Read (
117 sizeof (Pci
) / sizeof (UINT32
),
120 if (EFI_ERROR (Status
)) {
124 Status
= EFI_UNSUPPORTED
;
126 // See if the device is an enabled VGA device.
127 // Most systems can only have on VGA device on at a time.
129 if (((Pci
.Hdr
.Command
& 0x03) == 0x03) && IS_PCI_VGA (&Pci
)) {
130 Status
= EFI_SUCCESS
;
136 &gEfiPciIoProtocolGuid
,
137 This
->DriverBindingHandle
,
146 Starts the VGA device with this driver.
148 This function consumes PCI I/O Protocol, and installs VGA Mini Port Protocol
149 onto the VGA device handle.
151 @param This The driver binding instance.
152 @param Controller The controller to check.
153 @param RemainingDevicePath The remaining device patch.
155 @retval EFI_SUCCESS The controller is controlled by the driver.
156 @retval EFI_ALREADY_STARTED The controller is already controlled by the driver.
157 @retval EFI_OUT_OF_RESOURCES Failed to allocate resources.
162 PciVgaMiniPortDriverBindingStart (
163 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
164 IN EFI_HANDLE Controller
,
165 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
169 EFI_PCI_IO_PROTOCOL
*PciIo
;
170 PCI_VGA_MINI_PORT_DEV
*PciVgaMiniPortPrivate
;
172 PciVgaMiniPortPrivate
= NULL
;
175 // Open the IO Abstraction(s) needed
177 Status
= gBS
->OpenProtocol (
179 &gEfiPciIoProtocolGuid
,
181 This
->DriverBindingHandle
,
183 EFI_OPEN_PROTOCOL_BY_DRIVER
185 if (EFI_ERROR (Status
)) {
189 // Allocate the private device structure
191 PciVgaMiniPortPrivate
= AllocateZeroPool (sizeof (PCI_VGA_MINI_PORT_DEV
));
192 ASSERT (PciVgaMiniPortPrivate
!= NULL
);
195 // Initialize the private device structure
197 PciVgaMiniPortPrivate
->Signature
= PCI_VGA_MINI_PORT_DEV_SIGNATURE
;
198 PciVgaMiniPortPrivate
->Handle
= Controller
;
199 PciVgaMiniPortPrivate
->PciIo
= PciIo
;
201 PciVgaMiniPortPrivate
->VgaMiniPort
.SetMode
= PciVgaMiniPortSetMode
;
202 PciVgaMiniPortPrivate
->VgaMiniPort
.VgaMemoryOffset
= 0xb8000;
203 PciVgaMiniPortPrivate
->VgaMiniPort
.CrtcAddressRegisterOffset
= 0x3d4;
204 PciVgaMiniPortPrivate
->VgaMiniPort
.CrtcDataRegisterOffset
= 0x3d5;
205 PciVgaMiniPortPrivate
->VgaMiniPort
.VgaMemoryBar
= EFI_PCI_IO_PASS_THROUGH_BAR
;
206 PciVgaMiniPortPrivate
->VgaMiniPort
.CrtcAddressRegisterBar
= EFI_PCI_IO_PASS_THROUGH_BAR
;
207 PciVgaMiniPortPrivate
->VgaMiniPort
.CrtcDataRegisterBar
= EFI_PCI_IO_PASS_THROUGH_BAR
;
208 PciVgaMiniPortPrivate
->VgaMiniPort
.MaxMode
= 1;
211 // Install VGA Mini Port Protocol
213 Status
= gBS
->InstallMultipleProtocolInterfaces (
215 &gEfiVgaMiniPortProtocolGuid
,
216 &PciVgaMiniPortPrivate
->VgaMiniPort
,
220 if (EFI_ERROR (Status
)) {
223 &gEfiPciIoProtocolGuid
,
224 This
->DriverBindingHandle
,
227 if (PciVgaMiniPortPrivate
!= NULL
) {
228 FreePool (PciVgaMiniPortPrivate
);
237 Stop the VGA device with this driver.
239 This function uninstalls VGA Mini Port Protocol from the VGA device handle,
240 and closes PCI I/O Protocol.
242 @param This The driver binding protocol.
243 @param Controller The controller to release.
244 @param NumberOfChildren The child number that opened controller
246 @param ChildHandleBuffer The array of child handle.
248 @retval EFI_SUCCESS The controller or children are stopped.
249 @retval EFI_DEVICE_ERROR Failed to stop the driver.
254 PciVgaMiniPortDriverBindingStop (
255 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
256 IN EFI_HANDLE Controller
,
257 IN UINTN NumberOfChildren
,
258 IN EFI_HANDLE
*ChildHandleBuffer
262 EFI_VGA_MINI_PORT_PROTOCOL
*VgaMiniPort
;
263 PCI_VGA_MINI_PORT_DEV
*PciVgaMiniPortPrivate
;
265 Status
= gBS
->OpenProtocol (
267 &gEfiVgaMiniPortProtocolGuid
,
268 (VOID
**) &VgaMiniPort
,
269 This
->DriverBindingHandle
,
271 EFI_OPEN_PROTOCOL_GET_PROTOCOL
273 if (EFI_ERROR (Status
)) {
277 PciVgaMiniPortPrivate
= PCI_VGA_MINI_PORT_DEV_FROM_THIS (VgaMiniPort
);
279 Status
= gBS
->UninstallProtocolInterface (
281 &gEfiVgaMiniPortProtocolGuid
,
282 &PciVgaMiniPortPrivate
->VgaMiniPort
284 if (EFI_ERROR (Status
)) {
290 &gEfiPciIoProtocolGuid
,
291 This
->DriverBindingHandle
,
295 FreePool (PciVgaMiniPortPrivate
);
300 // VGA Mini Port Protocol Functions
304 Sets the text display mode of a VGA controller.
306 This function implements EFI_VGA_MINI_PORT_PROTOCOL.SetMode().
307 If ModeNumber exceeds the valid range, then EFI_UNSUPPORTED is returned.
308 Otherwise, EFI_SUCCESS is directly returned without real operation.
310 @param This Protocol instance pointer.
311 @param ModeNumber Mode number. 0 - 80x25 1-80x50
313 @retval EFI_SUCCESS The mode was set
314 @retval EFI_UNSUPPORTED ModeNumber is not supported.
315 @retval EFI_DEVICE_ERROR The device is not functioning properly.
320 PciVgaMiniPortSetMode (
321 IN EFI_VGA_MINI_PORT_PROTOCOL
*This
,
325 if (ModeNumber
> This
->MaxMode
) {
326 return EFI_UNSUPPORTED
;