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