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
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.
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.
33 // Cirrus Logic 5430 Controller Driver
36 #include "CirrusLogic5430.h"
38 EFI_DRIVER_BINDING_PROTOCOL gCirrusLogic5430DriverBinding
= {
39 CirrusLogic5430ControllerDriverSupported
,
40 CirrusLogic5430ControllerDriverStart
,
41 CirrusLogic5430ControllerDriverStop
,
49 CirrusLogic5430ControllerDriverSupported (
50 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
51 IN EFI_HANDLE Controller
,
52 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
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
70 EFI_PCI_IO_PROTOCOL
*PciIo
;
74 // Open the PCI I/O Protocol
76 Status
= gBS
->OpenProtocol (
78 &gEfiPciIoProtocolGuid
,
80 This
->DriverBindingHandle
,
82 EFI_OPEN_PROTOCOL_BY_DRIVER
84 if (EFI_ERROR (Status
)) {
89 // Read the PCI Configuration Header from the PCI Device
91 Status
= PciIo
->Pci
.Read (
95 sizeof (Pci
) / sizeof (UINT32
),
98 if (EFI_ERROR (Status
)) {
102 Status
= EFI_UNSUPPORTED
;
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.
107 // if (((Pci.Hdr.Command & 0x01) == 0x01)) {
109 // See if this is a Cirrus Logic PCI controller
111 if (Pci
.Hdr
.VendorId
== CIRRUS_LOGIC_VENDOR_ID
) {
113 // See if this is a 5430 or a 5446 PCI controller
115 if (Pci
.Hdr
.DeviceId
== CIRRUS_LOGIC_5430_DEVICE_ID
) {
116 Status
= EFI_SUCCESS
;
119 if (Pci
.Hdr
.DeviceId
== CIRRUS_LOGIC_5430_ALTERNATE_DEVICE_ID
) {
120 Status
= EFI_SUCCESS
;
123 if (Pci
.Hdr
.DeviceId
== CIRRUS_LOGIC_5446_DEVICE_ID
) {
124 Status
= EFI_SUCCESS
;
130 // Close the PCI I/O Protocol
134 &gEfiPciIoProtocolGuid
,
135 This
->DriverBindingHandle
,
144 CirrusLogic5430ControllerDriverStart (
145 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
146 IN EFI_HANDLE Controller
,
147 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
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
165 CIRRUS_LOGIC_5430_PRIVATE_DATA
*Private
;
168 // Allocate Private context data for UGA Draw inteface.
171 Private
= AllocateZeroPool (sizeof (CIRRUS_LOGIC_5430_PRIVATE_DATA
));
172 if (Private
== NULL
) {
173 Status
= EFI_OUT_OF_RESOURCES
;
178 // Set up context record
180 Private
->Signature
= CIRRUS_LOGIC_5430_PRIVATE_DATA_SIGNATURE
;
181 Private
->Handle
= Controller
;
184 // Open PCI I/O Protocol
186 Status
= gBS
->OpenProtocol (
188 &gEfiPciIoProtocolGuid
,
189 (VOID
**) &Private
->PciIo
,
190 This
->DriverBindingHandle
,
192 EFI_OPEN_PROTOCOL_BY_DRIVER
194 if (EFI_ERROR (Status
)) {
198 Status
= Private
->PciIo
->Attributes (
200 EfiPciIoAttributeOperationEnable
,
201 EFI_PCI_DEVICE_ENABLE
| EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY
| EFI_PCI_IO_ATTRIBUTE_VGA_IO
,
204 if (EFI_ERROR (Status
)) {
209 // Start the UGA Draw software stack.
211 Status
= CirrusLogic5430UgaDrawConstructor (Private
);
212 if (EFI_ERROR (Status
)) {
217 // Publish the UGA Draw interface to the world
219 Status
= gBS
->InstallMultipleProtocolInterfaces (
221 &gEfiUgaDrawProtocolGuid
,
227 if (EFI_ERROR (Status
)) {
229 if (Private
->PciIo
) {
230 Private
->PciIo
->Attributes (
232 EfiPciIoAttributeOperationDisable
,
233 EFI_PCI_DEVICE_ENABLE
| EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY
| EFI_PCI_IO_ATTRIBUTE_VGA_IO
,
240 // Close the PCI I/O Protocol
244 &gEfiPciIoProtocolGuid
,
245 This
->DriverBindingHandle
,
249 gBS
->FreePool (Private
);
258 CirrusLogic5430ControllerDriverStop (
259 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
260 IN EFI_HANDLE Controller
,
261 IN UINTN NumberOfChildren
,
262 IN EFI_HANDLE
*ChildHandleBuffer
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
281 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
283 CIRRUS_LOGIC_5430_PRIVATE_DATA
*Private
;
285 Status
= gBS
->OpenProtocol (
287 &gEfiUgaDrawProtocolGuid
,
289 This
->DriverBindingHandle
,
291 EFI_OPEN_PROTOCOL_GET_PROTOCOL
293 if (EFI_ERROR (Status
)) {
295 // If the UGA Draw interface does not exist the driver is not started
301 // Get our private context information
303 Private
= CIRRUS_LOGIC_5430_PRIVATE_DATA_FROM_UGA_DRAW_THIS (UgaDraw
);
306 // Remove the UGA Draw interface from the system
308 Status
= gBS
->UninstallMultipleProtocolInterfaces (
310 &gEfiUgaDrawProtocolGuid
,
314 if (EFI_ERROR (Status
)) {
319 // Shutdown the hardware
321 CirrusLogic5430UgaDrawDestructor (Private
);
323 Private
->PciIo
->Attributes (
325 EfiPciIoAttributeOperationDisable
,
326 EFI_PCI_DEVICE_ENABLE
| EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY
| EFI_PCI_IO_ATTRIBUTE_VGA_IO
,
331 // Close the PCI I/O Protocol
335 &gEfiPciIoProtocolGuid
,
336 This
->DriverBindingHandle
,
341 // Free our instance data
343 gBS
->FreePool (Private
);