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