]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Bus/Pci/VgaMiniPortDxe/VgaMiniPort.c
Add function doxygen header for VgaMiniPort module.
[mirror_edk2.git] / IntelFrameworkModulePkg / Bus / Pci / VgaMiniPortDxe / VgaMiniPort.c
1 /** @file
2
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
8
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.
11
12 **/
13
14 #include "VgaMiniPort.h"
15
16 //
17 // EFI Driver Binding Protocol Instance
18 //
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.
26 //
27 EFI_DRIVER_BINDING_PROTOCOL gPciVgaMiniPortDriverBinding = {
28 PciVgaMiniPortDriverBindingSupported,
29 PciVgaMiniPortDriverBindingStart,
30 PciVgaMiniPortDriverBindingStop,
31 0x00000000,
32 NULL,
33 NULL
34 };
35
36 /**
37 Driver entry point for VgaMiniPort driver.
38
39 @param ImageHandle Driver image handle
40 @param SystemTable Point to EFI_SYSTEM_TABLE
41
42 @retval Status of install driver binding protocol.
43 **/
44 EFI_STATUS
45 EFIAPI
46 PciVgaMiniPortDriverEntryPoint (
47 IN EFI_HANDLE ImageHandle,
48 IN EFI_SYSTEM_TABLE *SystemTable
49 )
50 {
51 return EfiLibInstallDriverBindingComponentName2 (
52 ImageHandle,
53 SystemTable,
54 &gPciVgaMiniPortDriverBinding,
55 ImageHandle,
56 &gPciVgaMiniPortComponentName,
57 &gPciVgaMiniPortComponentName2
58 );
59 }
60
61
62 /**
63 Supported.
64
65 (Standard DriverBinding Protocol Supported() function)
66
67 @return EFI_STATUS
68
69 **/
70 EFI_STATUS
71 EFIAPI
72 PciVgaMiniPortDriverBindingSupported (
73 IN EFI_DRIVER_BINDING_PROTOCOL *This,
74 IN EFI_HANDLE Controller,
75 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
76 )
77 {
78 EFI_STATUS Status;
79 EFI_PCI_IO_PROTOCOL *PciIo;
80 PCI_TYPE00 Pci;
81
82 //
83 // Open the IO Abstraction(s) needed to perform the supported test
84 //
85 Status = gBS->OpenProtocol (
86 Controller,
87 &gEfiPciIoProtocolGuid,
88 (VOID **) &PciIo,
89 This->DriverBindingHandle,
90 Controller,
91 EFI_OPEN_PROTOCOL_BY_DRIVER
92 );
93 if (EFI_ERROR (Status)) {
94 return Status;
95 }
96 //
97 // See if this is a PCI VGA Controller by looking at the Command register and
98 // Class Code Register
99 //
100 Status = PciIo->Pci.Read (
101 PciIo,
102 EfiPciIoWidthUint32,
103 0,
104 sizeof (Pci) / sizeof (UINT32),
105 &Pci
106 );
107 if (EFI_ERROR (Status)) {
108 goto Done;
109 }
110
111 Status = EFI_UNSUPPORTED;
112 //
113 // See if the device is an enabled VGA device.
114 // Most systems can only have on VGA device on at a time.
115 //
116 if (((Pci.Hdr.Command & 0x03) == 0x03) && IS_PCI_VGA (&Pci)) {
117 Status = EFI_SUCCESS;
118 }
119
120 Done:
121 gBS->CloseProtocol (
122 Controller,
123 &gEfiPciIoProtocolGuid,
124 This->DriverBindingHandle,
125 Controller
126 );
127
128 return Status;
129 }
130
131
132 /**
133 Install VGA Mini Port Protocol onto VGA device handles
134
135 (Standard DriverBinding Protocol Start() function)
136
137 @return EFI_STATUS
138
139 **/
140 EFI_STATUS
141 EFIAPI
142 PciVgaMiniPortDriverBindingStart (
143 IN EFI_DRIVER_BINDING_PROTOCOL *This,
144 IN EFI_HANDLE Controller,
145 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
146 )
147 {
148 EFI_STATUS Status;
149 EFI_PCI_IO_PROTOCOL *PciIo;
150 PCI_VGA_MINI_PORT_DEV *PciVgaMiniPortPrivate;
151
152 PciVgaMiniPortPrivate = NULL;
153 PciIo = NULL;
154 //
155 // Open the IO Abstraction(s) needed
156 //
157 Status = gBS->OpenProtocol (
158 Controller,
159 &gEfiPciIoProtocolGuid,
160 (VOID **) &PciIo,
161 This->DriverBindingHandle,
162 Controller,
163 EFI_OPEN_PROTOCOL_BY_DRIVER
164 );
165 if (EFI_ERROR (Status)) {
166 goto Done;
167 }
168 //
169 // Allocate the private device structure
170 //
171 Status = gBS->AllocatePool (
172 EfiBootServicesData,
173 sizeof (PCI_VGA_MINI_PORT_DEV),
174 (VOID **) &PciVgaMiniPortPrivate
175 );
176 if (EFI_ERROR (Status)) {
177 goto Done;
178 }
179
180 ZeroMem (PciVgaMiniPortPrivate, sizeof (PCI_VGA_MINI_PORT_DEV));
181
182 //
183 // Initialize the private device structure
184 //
185 PciVgaMiniPortPrivate->Signature = PCI_VGA_MINI_PORT_DEV_SIGNATURE;
186 PciVgaMiniPortPrivate->Handle = Controller;
187 PciVgaMiniPortPrivate->PciIo = PciIo;
188
189 PciVgaMiniPortPrivate->VgaMiniPort.SetMode = PciVgaMiniPortSetMode;
190 PciVgaMiniPortPrivate->VgaMiniPort.VgaMemoryOffset = 0xb8000;
191 PciVgaMiniPortPrivate->VgaMiniPort.CrtcAddressRegisterOffset = 0x3d4;
192 PciVgaMiniPortPrivate->VgaMiniPort.CrtcDataRegisterOffset = 0x3d5;
193 PciVgaMiniPortPrivate->VgaMiniPort.VgaMemoryBar = EFI_PCI_IO_PASS_THROUGH_BAR;
194 PciVgaMiniPortPrivate->VgaMiniPort.CrtcAddressRegisterBar = EFI_PCI_IO_PASS_THROUGH_BAR;
195 PciVgaMiniPortPrivate->VgaMiniPort.CrtcDataRegisterBar = EFI_PCI_IO_PASS_THROUGH_BAR;
196 PciVgaMiniPortPrivate->VgaMiniPort.MaxMode = 1;
197
198 //
199 // Install Vga Mini Port Protocol
200 //
201 Status = gBS->InstallMultipleProtocolInterfaces (
202 &Controller,
203 &gEfiVgaMiniPortProtocolGuid,
204 &PciVgaMiniPortPrivate->VgaMiniPort,
205 NULL
206 );
207 Done:
208 if (EFI_ERROR (Status)) {
209 gBS->CloseProtocol (
210 Controller,
211 &gEfiPciIoProtocolGuid,
212 This->DriverBindingHandle,
213 Controller
214 );
215 if (PciVgaMiniPortPrivate) {
216 gBS->FreePool (PciVgaMiniPortPrivate);
217 }
218 }
219
220 return Status;
221 }
222
223
224 /**
225 Stop.
226
227 (Standard DriverBinding Protocol Stop() function)
228
229 @return EFI_STATUS
230
231 **/
232 EFI_STATUS
233 EFIAPI
234 PciVgaMiniPortDriverBindingStop (
235 IN EFI_DRIVER_BINDING_PROTOCOL *This,
236 IN EFI_HANDLE Controller,
237 IN UINTN NumberOfChildren,
238 IN EFI_HANDLE *ChildHandleBuffer
239 )
240 {
241 EFI_STATUS Status;
242 EFI_VGA_MINI_PORT_PROTOCOL *VgaMiniPort;
243 PCI_VGA_MINI_PORT_DEV *PciVgaMiniPortPrivate;
244
245 Status = gBS->OpenProtocol (
246 Controller,
247 &gEfiVgaMiniPortProtocolGuid,
248 (VOID **) &VgaMiniPort,
249 This->DriverBindingHandle,
250 Controller,
251 EFI_OPEN_PROTOCOL_GET_PROTOCOL
252 );
253 if (EFI_ERROR (Status)) {
254 return Status;
255 }
256
257 PciVgaMiniPortPrivate = PCI_VGA_MINI_PORT_DEV_FROM_THIS (VgaMiniPort);
258
259 Status = gBS->UninstallProtocolInterface (
260 Controller,
261 &gEfiVgaMiniPortProtocolGuid,
262 &PciVgaMiniPortPrivate->VgaMiniPort
263 );
264 if (EFI_ERROR (Status)) {
265 return Status;
266 }
267
268 gBS->CloseProtocol (
269 Controller,
270 &gEfiPciIoProtocolGuid,
271 This->DriverBindingHandle,
272 Controller
273 );
274
275 gBS->FreePool (PciVgaMiniPortPrivate);
276
277 return EFI_SUCCESS;
278 }
279 //
280 // VGA Mini Port Protocol Functions
281 //
282
283 /**
284 Thunk function of EFI_VGA_MINI_PORT_SET_MODE
285
286 @param This Point to instance of EFI_VGA_MINI_PORT_PROTOCOL
287 @param ModeNumber Mode number
288
289 @retval EFI_UNSUPPORTED Invalid mode number
290 @retval EFI_SUCCESS Success
291
292 **/
293 EFI_STATUS
294 EFIAPI
295 PciVgaMiniPortSetMode (
296 IN EFI_VGA_MINI_PORT_PROTOCOL *This,
297 IN UINTN ModeNumber
298 )
299 {
300 if (ModeNumber > This->MaxMode) {
301 return EFI_UNSUPPORTED;
302 }
303
304 return EFI_SUCCESS;
305 }
306