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