2 Implements EFI Driver Binding Protocol and VGA Mini Port Protocol for VGA Mini Port Driver.
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #include "VgaMiniPort.h"
12 // EFI Driver Binding Protocol Instance
14 // This driver has a version value of 0x00000000. This is the
15 // lowest possible priority for a driver. This is done on purpose to help
16 // the developers of UGA drivers. This driver can bind if no UGA driver
17 // is present, so a console is available. Then, when a UGA driver is loaded
18 // this driver can be disconnected, and the UGA driver can be connected.
19 // As long as the UGA driver has a version value greater than 0x00000000, it
20 // will be connected first and will block this driver from connecting.
22 EFI_DRIVER_BINDING_PROTOCOL gPciVgaMiniPortDriverBinding
= {
23 PciVgaMiniPortDriverBindingSupported
,
24 PciVgaMiniPortDriverBindingStart
,
25 PciVgaMiniPortDriverBindingStop
,
32 Entrypoint of VGA Mini Port Driver.
34 This function is the entrypoint of UVGA Mini Port Driver. It installs Driver Binding
35 Protocols together with Component Name Protocols.
37 @param ImageHandle The firmware allocated handle for the EFI image.
38 @param SystemTable A pointer to the EFI System Table.
40 @retval EFI_SUCCESS The entry point is executed successfully.
45 PciVgaMiniPortDriverEntryPoint (
46 IN EFI_HANDLE ImageHandle
,
47 IN EFI_SYSTEM_TABLE
*SystemTable
52 Status
= EfiLibInstallDriverBindingComponentName2 (
55 &gPciVgaMiniPortDriverBinding
,
57 &gPciVgaMiniPortComponentName
,
58 &gPciVgaMiniPortComponentName2
60 ASSERT_EFI_ERROR (Status
);
67 Check whether VGA Mini Port driver supports this device.
69 @param This The driver binding protocol.
70 @param Controller The controller handle to check.
71 @param RemainingDevicePath The remaining device path.
73 @retval EFI_SUCCESS The driver supports this controller.
74 @retval EFI_UNSUPPORTED This device isn't supported.
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 Starts the VGA device with this driver.
142 This function consumes PCI I/O Protocol, and installs VGA Mini Port Protocol
143 onto the VGA device handle.
145 @param This The driver binding instance.
146 @param Controller The controller to check.
147 @param RemainingDevicePath The remaining device patch.
149 @retval EFI_SUCCESS The controller is controlled by the driver.
150 @retval EFI_ALREADY_STARTED The controller is already controlled by the driver.
151 @retval EFI_OUT_OF_RESOURCES Failed to allocate resources.
156 PciVgaMiniPortDriverBindingStart (
157 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
158 IN EFI_HANDLE Controller
,
159 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
163 EFI_PCI_IO_PROTOCOL
*PciIo
;
164 PCI_VGA_MINI_PORT_DEV
*PciVgaMiniPortPrivate
;
166 PciVgaMiniPortPrivate
= NULL
;
169 // Open the IO Abstraction(s) needed
171 Status
= gBS
->OpenProtocol (
173 &gEfiPciIoProtocolGuid
,
175 This
->DriverBindingHandle
,
177 EFI_OPEN_PROTOCOL_BY_DRIVER
179 if (EFI_ERROR (Status
)) {
183 // Allocate the private device structure
185 PciVgaMiniPortPrivate
= AllocateZeroPool (sizeof (PCI_VGA_MINI_PORT_DEV
));
186 ASSERT (PciVgaMiniPortPrivate
!= NULL
);
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
!= NULL
) {
222 FreePool (PciVgaMiniPortPrivate
);
231 Stop the VGA device with this driver.
233 This function uninstalls VGA Mini Port Protocol from the VGA device handle,
234 and closes PCI I/O Protocol.
236 @param This The driver binding protocol.
237 @param Controller The controller to release.
238 @param NumberOfChildren The child number that opened controller
240 @param ChildHandleBuffer The array of child handle.
242 @retval EFI_SUCCESS The controller or children are stopped.
243 @retval EFI_DEVICE_ERROR Failed to stop the driver.
248 PciVgaMiniPortDriverBindingStop (
249 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
250 IN EFI_HANDLE Controller
,
251 IN UINTN NumberOfChildren
,
252 IN EFI_HANDLE
*ChildHandleBuffer
256 EFI_VGA_MINI_PORT_PROTOCOL
*VgaMiniPort
;
257 PCI_VGA_MINI_PORT_DEV
*PciVgaMiniPortPrivate
;
259 Status
= gBS
->OpenProtocol (
261 &gEfiVgaMiniPortProtocolGuid
,
262 (VOID
**) &VgaMiniPort
,
263 This
->DriverBindingHandle
,
265 EFI_OPEN_PROTOCOL_GET_PROTOCOL
267 if (EFI_ERROR (Status
)) {
271 PciVgaMiniPortPrivate
= PCI_VGA_MINI_PORT_DEV_FROM_THIS (VgaMiniPort
);
273 Status
= gBS
->UninstallProtocolInterface (
275 &gEfiVgaMiniPortProtocolGuid
,
276 &PciVgaMiniPortPrivate
->VgaMiniPort
278 if (EFI_ERROR (Status
)) {
284 &gEfiPciIoProtocolGuid
,
285 This
->DriverBindingHandle
,
289 FreePool (PciVgaMiniPortPrivate
);
294 // VGA Mini Port Protocol Functions
298 Sets the text display mode of a VGA controller.
300 This function implements EFI_VGA_MINI_PORT_PROTOCOL.SetMode().
301 If ModeNumber exceeds the valid range, then EFI_UNSUPPORTED is returned.
302 Otherwise, EFI_SUCCESS is directly returned without real operation.
304 @param This Protocol instance pointer.
305 @param ModeNumber Mode number. 0 - 80x25 1-80x50
307 @retval EFI_SUCCESS The mode was set
308 @retval EFI_UNSUPPORTED ModeNumber is not supported.
309 @retval EFI_DEVICE_ERROR The device is not functioning properly.
314 PciVgaMiniPortSetMode (
315 IN EFI_VGA_MINI_PORT_PROTOCOL
*This
,
319 if (ModeNumber
> This
->MaxMode
) {
320 return EFI_UNSUPPORTED
;