]>
Commit | Line | Data |
---|---|---|
ed72955c | 1 | /** @file\r |
878ddf1f | 2 | Cirrus Logic 5430 Controller Driver.\r |
3 | This driver is a sample implementation of the UGA Draw Protocol for the\r | |
4 | Cirrus Logic 5430 family of PCI video controllers. This driver is only\r | |
5 | usable in the EFI pre-boot environment. This sample is intended to show\r | |
6 | how the UGA Draw Protocol is able to function. The UGA I/O Protocol is not\r | |
7 | implemented in this sample. A fully compliant EFI UGA driver requires both\r | |
8 | the UGA Draw and the UGA I/O Protocol. Please refer to Microsoft's\r | |
9 | documentation on UGA for details on how to write a UGA driver that is able\r | |
10 | to function both in the EFI pre-boot environment and from the OS runtime.\r | |
11 | \r | |
ed72955c | 12 | Copyright (c) 2006, Intel Corporation \r |
13 | All rights reserved. This program and the accompanying materials \r | |
14 | are licensed and made available under the terms and conditions of the BSD License \r | |
15 | which accompanies this distribution. The full text of the license may be found at \r | |
16 | http://opensource.org/licenses/bsd-license.php \r | |
17 | \r | |
18 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r | |
19 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r | |
878ddf1f | 20 | \r |
ed72955c | 21 | **/\r |
878ddf1f | 22 | \r |
23 | //\r | |
24 | // Cirrus Logic 5430 Controller Driver\r | |
25 | //\r | |
26 | \r | |
27 | #include "CirrusLogic5430.h"\r | |
28 | \r | |
29 | EFI_DRIVER_BINDING_PROTOCOL gCirrusLogic5430DriverBinding = {\r | |
30 | CirrusLogic5430ControllerDriverSupported,\r | |
31 | CirrusLogic5430ControllerDriverStart,\r | |
32 | CirrusLogic5430ControllerDriverStop,\r | |
33 | 0x10,\r | |
34 | NULL,\r | |
35 | NULL\r | |
36 | };\r | |
37 | \r | |
ed72955c | 38 | /**\r |
39 | CirrusLogic5430ControllerDriverSupported\r | |
40 | \r | |
41 | TODO: This - add argument and description to function comment\r | |
42 | TODO: Controller - add argument and description to function comment\r | |
43 | TODO: RemainingDevicePath - add argument and description to function comment\r | |
44 | **/\r | |
878ddf1f | 45 | EFI_STATUS\r |
46 | EFIAPI\r | |
47 | CirrusLogic5430ControllerDriverSupported (\r | |
48 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
49 | IN EFI_HANDLE Controller,\r | |
50 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
51 | )\r | |
878ddf1f | 52 | {\r |
53 | EFI_STATUS Status;\r | |
54 | EFI_PCI_IO_PROTOCOL *PciIo;\r | |
55 | PCI_TYPE00 Pci;\r | |
56 | \r | |
57 | //\r | |
58 | // Open the PCI I/O Protocol\r | |
59 | //\r | |
60 | Status = gBS->OpenProtocol (\r | |
61 | Controller,\r | |
62 | &gEfiPciIoProtocolGuid,\r | |
63 | (VOID **) &PciIo,\r | |
64 | This->DriverBindingHandle,\r | |
65 | Controller,\r | |
66 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
67 | );\r | |
68 | if (EFI_ERROR (Status)) {\r | |
69 | return Status;\r | |
70 | }\r | |
71 | \r | |
72 | //\r | |
73 | // Read the PCI Configuration Header from the PCI Device\r | |
74 | //\r | |
75 | Status = PciIo->Pci.Read (\r | |
76 | PciIo,\r | |
77 | EfiPciIoWidthUint32,\r | |
78 | 0,\r | |
79 | sizeof (Pci) / sizeof (UINT32),\r | |
80 | &Pci\r | |
81 | );\r | |
82 | if (EFI_ERROR (Status)) {\r | |
83 | goto Done;\r | |
84 | }\r | |
85 | \r | |
86 | Status = EFI_UNSUPPORTED;\r | |
87 | //\r | |
88 | // See if the I/O enable is on. Most systems only allow one VGA device to be turned on\r | |
89 | // at a time, so see if this is one that is turned on.\r | |
90 | //\r | |
91 | // if (((Pci.Hdr.Command & 0x01) == 0x01)) {\r | |
92 | //\r | |
93 | // See if this is a Cirrus Logic PCI controller\r | |
94 | //\r | |
95 | if (Pci.Hdr.VendorId == CIRRUS_LOGIC_VENDOR_ID) {\r | |
96 | //\r | |
97 | // See if this is a 5430 or a 5446 PCI controller\r | |
98 | //\r | |
99 | if (Pci.Hdr.DeviceId == CIRRUS_LOGIC_5430_DEVICE_ID) {\r | |
100 | Status = EFI_SUCCESS;\r | |
101 | }\r | |
102 | \r | |
103 | if (Pci.Hdr.DeviceId == CIRRUS_LOGIC_5430_ALTERNATE_DEVICE_ID) {\r | |
104 | Status = EFI_SUCCESS;\r | |
105 | }\r | |
106 | \r | |
107 | if (Pci.Hdr.DeviceId == CIRRUS_LOGIC_5446_DEVICE_ID) {\r | |
108 | Status = EFI_SUCCESS;\r | |
109 | }\r | |
110 | }\r | |
111 | \r | |
112 | Done:\r | |
113 | //\r | |
114 | // Close the PCI I/O Protocol\r | |
115 | //\r | |
116 | gBS->CloseProtocol (\r | |
117 | Controller,\r | |
118 | &gEfiPciIoProtocolGuid,\r | |
119 | This->DriverBindingHandle,\r | |
120 | Controller\r | |
121 | );\r | |
122 | \r | |
123 | return Status;\r | |
124 | }\r | |
125 | \r | |
ed72955c | 126 | /**\r |
127 | CirrusLogic5430ControllerDriverStart\r | |
128 | \r | |
129 | TODO: This - add argument and description to function comment\r | |
130 | TODO: Controller - add argument and description to function comment\r | |
131 | TODO: RemainingDevicePath - add argument and description to function comment\r | |
132 | **/\r | |
878ddf1f | 133 | EFI_STATUS\r |
134 | EFIAPI\r | |
135 | CirrusLogic5430ControllerDriverStart (\r | |
136 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
137 | IN EFI_HANDLE Controller,\r | |
138 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
139 | )\r | |
878ddf1f | 140 | {\r |
141 | EFI_STATUS Status;\r | |
142 | CIRRUS_LOGIC_5430_PRIVATE_DATA *Private;\r | |
143 | \r | |
144 | //\r | |
145 | // Allocate Private context data for UGA Draw inteface.\r | |
146 | //\r | |
147 | Private = NULL;\r | |
148 | Private = AllocateZeroPool (sizeof (CIRRUS_LOGIC_5430_PRIVATE_DATA));\r | |
149 | if (Private == NULL) {\r | |
150 | Status = EFI_OUT_OF_RESOURCES;\r | |
151 | goto Error;\r | |
152 | }\r | |
153 | \r | |
154 | //\r | |
155 | // Set up context record\r | |
156 | //\r | |
157 | Private->Signature = CIRRUS_LOGIC_5430_PRIVATE_DATA_SIGNATURE;\r | |
158 | Private->Handle = Controller;\r | |
159 | \r | |
160 | //\r | |
161 | // Open PCI I/O Protocol\r | |
162 | //\r | |
163 | Status = gBS->OpenProtocol (\r | |
164 | Private->Handle,\r | |
165 | &gEfiPciIoProtocolGuid,\r | |
166 | (VOID **) &Private->PciIo,\r | |
167 | This->DriverBindingHandle,\r | |
168 | Private->Handle,\r | |
169 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
170 | );\r | |
171 | if (EFI_ERROR (Status)) {\r | |
172 | goto Error;\r | |
173 | }\r | |
174 | \r | |
175 | Status = Private->PciIo->Attributes (\r | |
176 | Private->PciIo,\r | |
177 | EfiPciIoAttributeOperationEnable,\r | |
178 | EFI_PCI_DEVICE_ENABLE | EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY | EFI_PCI_IO_ATTRIBUTE_VGA_IO,\r | |
179 | NULL\r | |
180 | );\r | |
181 | if (EFI_ERROR (Status)) {\r | |
182 | goto Error;\r | |
183 | }\r | |
184 | \r | |
185 | //\r | |
186 | // Start the UGA Draw software stack.\r | |
187 | //\r | |
188 | Status = CirrusLogic5430UgaDrawConstructor (Private);\r | |
189 | if (EFI_ERROR (Status)) {\r | |
190 | goto Error;\r | |
191 | }\r | |
192 | \r | |
193 | //\r | |
194 | // Publish the UGA Draw interface to the world\r | |
195 | //\r | |
196 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
197 | &Private->Handle,\r | |
198 | &gEfiUgaDrawProtocolGuid,\r | |
199 | &Private->UgaDraw,\r | |
200 | NULL\r | |
201 | );\r | |
202 | \r | |
203 | Error:\r | |
204 | if (EFI_ERROR (Status)) {\r | |
205 | if (Private) {\r | |
206 | if (Private->PciIo) {\r | |
207 | Private->PciIo->Attributes (\r | |
208 | Private->PciIo,\r | |
209 | EfiPciIoAttributeOperationDisable,\r | |
210 | EFI_PCI_DEVICE_ENABLE | EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY | EFI_PCI_IO_ATTRIBUTE_VGA_IO,\r | |
211 | NULL\r | |
212 | );\r | |
213 | }\r | |
214 | }\r | |
215 | \r | |
216 | //\r | |
217 | // Close the PCI I/O Protocol\r | |
218 | //\r | |
219 | gBS->CloseProtocol (\r | |
220 | Private->Handle,\r | |
221 | &gEfiPciIoProtocolGuid,\r | |
222 | This->DriverBindingHandle,\r | |
223 | Private->Handle\r | |
224 | );\r | |
225 | if (Private) {\r | |
226 | gBS->FreePool (Private);\r | |
227 | }\r | |
228 | }\r | |
229 | \r | |
230 | return Status;\r | |
231 | }\r | |
232 | \r | |
ed72955c | 233 | /**\r |
234 | CirrusLogic5430ControllerDriverStop\r | |
235 | \r | |
236 | TODO: This - add argument and description to function comment\r | |
237 | TODO: Controller - add argument and description to function comment\r | |
238 | TODO: NumberOfChildren - add argument and description to function comment\r | |
239 | TODO: ChildHandleBuffer - add argument and description to function comment\r | |
240 | TODO: EFI_SUCCESS - add return value to function comment\r | |
241 | **/\r | |
878ddf1f | 242 | EFI_STATUS\r |
243 | EFIAPI\r | |
244 | CirrusLogic5430ControllerDriverStop (\r | |
245 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
246 | IN EFI_HANDLE Controller,\r | |
247 | IN UINTN NumberOfChildren,\r | |
248 | IN EFI_HANDLE *ChildHandleBuffer\r | |
249 | )\r | |
878ddf1f | 250 | {\r |
251 | EFI_UGA_DRAW_PROTOCOL *UgaDraw;\r | |
252 | EFI_STATUS Status;\r | |
253 | CIRRUS_LOGIC_5430_PRIVATE_DATA *Private;\r | |
254 | \r | |
255 | Status = gBS->OpenProtocol (\r | |
256 | Controller,\r | |
257 | &gEfiUgaDrawProtocolGuid,\r | |
258 | (VOID **) &UgaDraw,\r | |
259 | This->DriverBindingHandle,\r | |
260 | Controller,\r | |
261 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
262 | );\r | |
263 | if (EFI_ERROR (Status)) {\r | |
264 | //\r | |
265 | // If the UGA Draw interface does not exist the driver is not started\r | |
266 | //\r | |
267 | return Status;\r | |
268 | }\r | |
269 | \r | |
270 | //\r | |
271 | // Get our private context information\r | |
272 | //\r | |
273 | Private = CIRRUS_LOGIC_5430_PRIVATE_DATA_FROM_UGA_DRAW_THIS (UgaDraw);\r | |
274 | \r | |
275 | //\r | |
276 | // Remove the UGA Draw interface from the system\r | |
277 | //\r | |
278 | Status = gBS->UninstallMultipleProtocolInterfaces (\r | |
279 | Private->Handle,\r | |
280 | &gEfiUgaDrawProtocolGuid,\r | |
281 | &Private->UgaDraw,\r | |
282 | NULL\r | |
283 | );\r | |
284 | if (EFI_ERROR (Status)) {\r | |
285 | return Status;\r | |
286 | }\r | |
287 | \r | |
288 | //\r | |
289 | // Shutdown the hardware\r | |
290 | //\r | |
291 | CirrusLogic5430UgaDrawDestructor (Private);\r | |
292 | \r | |
293 | Private->PciIo->Attributes (\r | |
294 | Private->PciIo,\r | |
295 | EfiPciIoAttributeOperationDisable,\r | |
296 | EFI_PCI_DEVICE_ENABLE | EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY | EFI_PCI_IO_ATTRIBUTE_VGA_IO,\r | |
297 | NULL\r | |
298 | );\r | |
299 | \r | |
300 | //\r | |
301 | // Close the PCI I/O Protocol\r | |
302 | //\r | |
303 | gBS->CloseProtocol (\r | |
304 | Controller,\r | |
305 | &gEfiPciIoProtocolGuid,\r | |
306 | This->DriverBindingHandle,\r | |
307 | Controller\r | |
308 | );\r | |
309 | \r | |
310 | //\r | |
311 | // Free our instance data\r | |
312 | //\r | |
313 | gBS->FreePool (Private);\r | |
314 | \r | |
315 | return EFI_SUCCESS;\r | |
316 | }\r |