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