2 Cirrus Logic 5430 Controller Driver.
3 This driver is a sample implementation of the UGA Draw Protocol for the
4 Cirrus Logic 5430 family of PCI video controllers. This driver is only
5 usable in the EFI pre-boot environment. This sample is intended to show
6 how the UGA Draw Protocol is able to function. The UGA I/O Protocol is not
7 implemented in this sample. A fully compliant EFI UGA driver requires both
8 the UGA Draw and the UGA I/O Protocol. Please refer to Microsoft's
9 documentation on UGA for details on how to write a UGA driver that is able
10 to function both in the EFI pre-boot environment and from the OS runtime.
12 Copyright (c) 2006, Intel Corporation
13 All rights reserved. This program and the accompanying materials
14 are licensed and made available under the terms and conditions of the BSD License
15 which accompanies this distribution. The full text of the license may be found at
16 http://opensource.org/licenses/bsd-license.php
18 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
19 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
24 // Cirrus Logic 5430 Controller Driver
27 #include "CirrusLogic5430.h"
29 EFI_DRIVER_BINDING_PROTOCOL gCirrusLogic5430DriverBinding
= {
30 CirrusLogic5430ControllerDriverSupported
,
31 CirrusLogic5430ControllerDriverStart
,
32 CirrusLogic5430ControllerDriverStop
,
39 CirrusLogic5430ControllerDriverSupported
41 TODO: This - add argument and description to function comment
42 TODO: Controller - add argument and description to function comment
43 TODO: RemainingDevicePath - add argument and description to function comment
47 CirrusLogic5430ControllerDriverSupported (
48 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
49 IN EFI_HANDLE Controller
,
50 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
54 EFI_PCI_IO_PROTOCOL
*PciIo
;
58 // Open the PCI I/O Protocol
60 Status
= gBS
->OpenProtocol (
62 &gEfiPciIoProtocolGuid
,
64 This
->DriverBindingHandle
,
66 EFI_OPEN_PROTOCOL_BY_DRIVER
68 if (EFI_ERROR (Status
)) {
73 // Read the PCI Configuration Header from the PCI Device
75 Status
= PciIo
->Pci
.Read (
79 sizeof (Pci
) / sizeof (UINT32
),
82 if (EFI_ERROR (Status
)) {
86 Status
= EFI_UNSUPPORTED
;
88 // See if the I/O enable is on. Most systems only allow one VGA device to be turned on
89 // at a time, so see if this is one that is turned on.
91 // if (((Pci.Hdr.Command & 0x01) == 0x01)) {
93 // See if this is a Cirrus Logic PCI controller
95 if (Pci
.Hdr
.VendorId
== CIRRUS_LOGIC_VENDOR_ID
) {
97 // See if this is a 5430 or a 5446 PCI controller
99 if (Pci
.Hdr
.DeviceId
== CIRRUS_LOGIC_5430_DEVICE_ID
) {
100 Status
= EFI_SUCCESS
;
103 if (Pci
.Hdr
.DeviceId
== CIRRUS_LOGIC_5430_ALTERNATE_DEVICE_ID
) {
104 Status
= EFI_SUCCESS
;
107 if (Pci
.Hdr
.DeviceId
== CIRRUS_LOGIC_5446_DEVICE_ID
) {
108 Status
= EFI_SUCCESS
;
114 // Close the PCI I/O Protocol
118 &gEfiPciIoProtocolGuid
,
119 This
->DriverBindingHandle
,
127 CirrusLogic5430ControllerDriverStart
129 TODO: This - add argument and description to function comment
130 TODO: Controller - add argument and description to function comment
131 TODO: RemainingDevicePath - add argument and description to function comment
135 CirrusLogic5430ControllerDriverStart (
136 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
137 IN EFI_HANDLE Controller
,
138 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
142 CIRRUS_LOGIC_5430_PRIVATE_DATA
*Private
;
145 // Allocate Private context data for UGA Draw inteface.
148 Private
= AllocateZeroPool (sizeof (CIRRUS_LOGIC_5430_PRIVATE_DATA
));
149 if (Private
== NULL
) {
150 Status
= EFI_OUT_OF_RESOURCES
;
155 // Set up context record
157 Private
->Signature
= CIRRUS_LOGIC_5430_PRIVATE_DATA_SIGNATURE
;
158 Private
->Handle
= Controller
;
161 // Open PCI I/O Protocol
163 Status
= gBS
->OpenProtocol (
165 &gEfiPciIoProtocolGuid
,
166 (VOID
**) &Private
->PciIo
,
167 This
->DriverBindingHandle
,
169 EFI_OPEN_PROTOCOL_BY_DRIVER
171 if (EFI_ERROR (Status
)) {
175 Status
= Private
->PciIo
->Attributes (
177 EfiPciIoAttributeOperationEnable
,
178 EFI_PCI_DEVICE_ENABLE
| EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY
| EFI_PCI_IO_ATTRIBUTE_VGA_IO
,
181 if (EFI_ERROR (Status
)) {
186 // Start the UGA Draw software stack.
188 Status
= CirrusLogic5430UgaDrawConstructor (Private
);
189 if (EFI_ERROR (Status
)) {
194 // Publish the UGA Draw interface to the world
196 Status
= gBS
->InstallMultipleProtocolInterfaces (
198 &gEfiUgaDrawProtocolGuid
,
204 if (EFI_ERROR (Status
)) {
206 if (Private
->PciIo
) {
207 Private
->PciIo
->Attributes (
209 EfiPciIoAttributeOperationDisable
,
210 EFI_PCI_DEVICE_ENABLE
| EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY
| EFI_PCI_IO_ATTRIBUTE_VGA_IO
,
217 // Close the PCI I/O Protocol
221 &gEfiPciIoProtocolGuid
,
222 This
->DriverBindingHandle
,
226 gBS
->FreePool (Private
);
234 CirrusLogic5430ControllerDriverStop
236 TODO: This - add argument and description to function comment
237 TODO: Controller - add argument and description to function comment
238 TODO: NumberOfChildren - add argument and description to function comment
239 TODO: ChildHandleBuffer - add argument and description to function comment
240 TODO: EFI_SUCCESS - add return value to function comment
244 CirrusLogic5430ControllerDriverStop (
245 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
246 IN EFI_HANDLE Controller
,
247 IN UINTN NumberOfChildren
,
248 IN EFI_HANDLE
*ChildHandleBuffer
251 EFI_UGA_DRAW_PROTOCOL
*UgaDraw
;
253 CIRRUS_LOGIC_5430_PRIVATE_DATA
*Private
;
255 Status
= gBS
->OpenProtocol (
257 &gEfiUgaDrawProtocolGuid
,
259 This
->DriverBindingHandle
,
261 EFI_OPEN_PROTOCOL_GET_PROTOCOL
263 if (EFI_ERROR (Status
)) {
265 // If the UGA Draw interface does not exist the driver is not started
271 // Get our private context information
273 Private
= CIRRUS_LOGIC_5430_PRIVATE_DATA_FROM_UGA_DRAW_THIS (UgaDraw
);
276 // Remove the UGA Draw interface from the system
278 Status
= gBS
->UninstallMultipleProtocolInterfaces (
280 &gEfiUgaDrawProtocolGuid
,
284 if (EFI_ERROR (Status
)) {
289 // Shutdown the hardware
291 CirrusLogic5430UgaDrawDestructor (Private
);
293 Private
->PciIo
->Attributes (
295 EfiPciIoAttributeOperationDisable
,
296 EFI_PCI_DEVICE_ENABLE
| EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY
| EFI_PCI_IO_ATTRIBUTE_VGA_IO
,
301 // Close the PCI I/O Protocol
305 &gEfiPciIoProtocolGuid
,
306 This
->DriverBindingHandle
,
311 // Free our instance data
313 gBS
->FreePool (Private
);