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