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