]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Bus/Pci/VgaMiniPortDxe/VgaMiniPort.c
Update For R9 Review.
[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 @param This The driver binding protocol.
68 @param Controller The controller handle to check.
69 @param RemainingDevicePath The remaining device path.
70
71 @retval EFI_SUCCESS The driver supports this controller.
72 @retval EFI_UNSUPPORTED This device isn't supported.
73
74 **/
75 EFI_STATUS
76 EFIAPI
77 PciVgaMiniPortDriverBindingSupported (
78 IN EFI_DRIVER_BINDING_PROTOCOL *This,
79 IN EFI_HANDLE Controller,
80 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
81 )
82 {
83 EFI_STATUS Status;
84 EFI_PCI_IO_PROTOCOL *PciIo;
85 PCI_TYPE00 Pci;
86
87 //
88 // Open the IO Abstraction(s) needed to perform the supported test
89 //
90 Status = gBS->OpenProtocol (
91 Controller,
92 &gEfiPciIoProtocolGuid,
93 (VOID **) &PciIo,
94 This->DriverBindingHandle,
95 Controller,
96 EFI_OPEN_PROTOCOL_BY_DRIVER
97 );
98 if (EFI_ERROR (Status)) {
99 return Status;
100 }
101 //
102 // See if this is a PCI VGA Controller by looking at the Command register and
103 // Class Code Register
104 //
105 Status = PciIo->Pci.Read (
106 PciIo,
107 EfiPciIoWidthUint32,
108 0,
109 sizeof (Pci) / sizeof (UINT32),
110 &Pci
111 );
112 if (EFI_ERROR (Status)) {
113 goto Done;
114 }
115
116 Status = EFI_UNSUPPORTED;
117 //
118 // See if the device is an enabled VGA device.
119 // Most systems can only have on VGA device on at a time.
120 //
121 if (((Pci.Hdr.Command & 0x03) == 0x03) && IS_PCI_VGA (&Pci)) {
122 Status = EFI_SUCCESS;
123 }
124
125 Done:
126 gBS->CloseProtocol (
127 Controller,
128 &gEfiPciIoProtocolGuid,
129 This->DriverBindingHandle,
130 Controller
131 );
132
133 return Status;
134 }
135
136
137 /**
138 Install VGA Mini Port Protocol onto VGA device handles
139
140 (Standard DriverBinding Protocol Start() function)
141
142 @param This The driver binding instance.
143 @param Controller The controller to check.
144 @param RemainingDevicePath The remaining device patch.
145
146 @retval EFI_SUCCESS The controller is controlled by the driver.
147 @retval EFI_ALREADY_STARTED The controller is already controlled by the driver.
148 @retval EFI_OUT_OF_RESOURCES Failed to allocate resources.
149
150 **/
151 EFI_STATUS
152 EFIAPI
153 PciVgaMiniPortDriverBindingStart (
154 IN EFI_DRIVER_BINDING_PROTOCOL *This,
155 IN EFI_HANDLE Controller,
156 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
157 )
158 {
159 EFI_STATUS Status;
160 EFI_PCI_IO_PROTOCOL *PciIo;
161 PCI_VGA_MINI_PORT_DEV *PciVgaMiniPortPrivate;
162
163 PciVgaMiniPortPrivate = NULL;
164 PciIo = NULL;
165 //
166 // Open the IO Abstraction(s) needed
167 //
168 Status = gBS->OpenProtocol (
169 Controller,
170 &gEfiPciIoProtocolGuid,
171 (VOID **) &PciIo,
172 This->DriverBindingHandle,
173 Controller,
174 EFI_OPEN_PROTOCOL_BY_DRIVER
175 );
176 if (EFI_ERROR (Status)) {
177 goto Done;
178 }
179 //
180 // Allocate the private device structure
181 //
182 Status = gBS->AllocatePool (
183 EfiBootServicesData,
184 sizeof (PCI_VGA_MINI_PORT_DEV),
185 (VOID **) &PciVgaMiniPortPrivate
186 );
187 if (EFI_ERROR (Status)) {
188 goto Done;
189 }
190
191 ZeroMem (PciVgaMiniPortPrivate, sizeof (PCI_VGA_MINI_PORT_DEV));
192
193 //
194 // Initialize the private device structure
195 //
196 PciVgaMiniPortPrivate->Signature = PCI_VGA_MINI_PORT_DEV_SIGNATURE;
197 PciVgaMiniPortPrivate->Handle = Controller;
198 PciVgaMiniPortPrivate->PciIo = PciIo;
199
200 PciVgaMiniPortPrivate->VgaMiniPort.SetMode = PciVgaMiniPortSetMode;
201 PciVgaMiniPortPrivate->VgaMiniPort.VgaMemoryOffset = 0xb8000;
202 PciVgaMiniPortPrivate->VgaMiniPort.CrtcAddressRegisterOffset = 0x3d4;
203 PciVgaMiniPortPrivate->VgaMiniPort.CrtcDataRegisterOffset = 0x3d5;
204 PciVgaMiniPortPrivate->VgaMiniPort.VgaMemoryBar = EFI_PCI_IO_PASS_THROUGH_BAR;
205 PciVgaMiniPortPrivate->VgaMiniPort.CrtcAddressRegisterBar = EFI_PCI_IO_PASS_THROUGH_BAR;
206 PciVgaMiniPortPrivate->VgaMiniPort.CrtcDataRegisterBar = EFI_PCI_IO_PASS_THROUGH_BAR;
207 PciVgaMiniPortPrivate->VgaMiniPort.MaxMode = 1;
208
209 //
210 // Install Vga Mini Port Protocol
211 //
212 Status = gBS->InstallMultipleProtocolInterfaces (
213 &Controller,
214 &gEfiVgaMiniPortProtocolGuid,
215 &PciVgaMiniPortPrivate->VgaMiniPort,
216 NULL
217 );
218 Done:
219 if (EFI_ERROR (Status)) {
220 gBS->CloseProtocol (
221 Controller,
222 &gEfiPciIoProtocolGuid,
223 This->DriverBindingHandle,
224 Controller
225 );
226 if (PciVgaMiniPortPrivate != NULL) {
227 gBS->FreePool (PciVgaMiniPortPrivate);
228 }
229 }
230
231 return Status;
232 }
233
234
235 /**
236 Stop.
237
238 (Standard DriverBinding Protocol Stop() function)
239
240 @param This The driver binding protocol.
241 @param Controller The controller to release.
242 @param NumberOfChildren The child number that opened controller
243 BY_CHILD.
244 @param ChildHandleBuffer The array of child handle.
245
246 @retval EFI_SUCCESS The controller or children are stopped.
247 @retval EFI_DEVICE_ERROR Failed to stop the driver.
248
249 **/
250 EFI_STATUS
251 EFIAPI
252 PciVgaMiniPortDriverBindingStop (
253 IN EFI_DRIVER_BINDING_PROTOCOL *This,
254 IN EFI_HANDLE Controller,
255 IN UINTN NumberOfChildren,
256 IN EFI_HANDLE *ChildHandleBuffer
257 )
258 {
259 EFI_STATUS Status;
260 EFI_VGA_MINI_PORT_PROTOCOL *VgaMiniPort;
261 PCI_VGA_MINI_PORT_DEV *PciVgaMiniPortPrivate;
262
263 Status = gBS->OpenProtocol (
264 Controller,
265 &gEfiVgaMiniPortProtocolGuid,
266 (VOID **) &VgaMiniPort,
267 This->DriverBindingHandle,
268 Controller,
269 EFI_OPEN_PROTOCOL_GET_PROTOCOL
270 );
271 if (EFI_ERROR (Status)) {
272 return Status;
273 }
274
275 PciVgaMiniPortPrivate = PCI_VGA_MINI_PORT_DEV_FROM_THIS (VgaMiniPort);
276
277 Status = gBS->UninstallProtocolInterface (
278 Controller,
279 &gEfiVgaMiniPortProtocolGuid,
280 &PciVgaMiniPortPrivate->VgaMiniPort
281 );
282 if (EFI_ERROR (Status)) {
283 return Status;
284 }
285
286 gBS->CloseProtocol (
287 Controller,
288 &gEfiPciIoProtocolGuid,
289 This->DriverBindingHandle,
290 Controller
291 );
292
293 gBS->FreePool (PciVgaMiniPortPrivate);
294
295 return EFI_SUCCESS;
296 }
297 //
298 // VGA Mini Port Protocol Functions
299 //
300
301 /**
302 Thunk function of EFI_VGA_MINI_PORT_SET_MODE.
303
304 @param This Point to instance of EFI_VGA_MINI_PORT_PROTOCOL.
305 @param ModeNumber Mode number.
306
307 @retval EFI_UNSUPPORTED Invalid mode number.
308 @retval EFI_SUCCESS Success.
309
310 **/
311 EFI_STATUS
312 EFIAPI
313 PciVgaMiniPortSetMode (
314 IN EFI_VGA_MINI_PORT_PROTOCOL *This,
315 IN UINTN ModeNumber
316 )
317 {
318 if (ModeNumber > This->MaxMode) {
319 return EFI_UNSUPPORTED;
320 }
321
322 return EFI_SUCCESS;
323 }
324