Save original PCI attributes in start() function and restore it in Stop().

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@4324 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
vanjeff 2007-11-23 06:19:16 +00:00
parent 54857d5a7c
commit 94b73c2482
2 changed files with 71 additions and 55 deletions

View File

@ -4,21 +4,21 @@
Protocols for the Cirrus Logic 5430 family of PCI video controllers. Protocols for the Cirrus Logic 5430 family of PCI video controllers.
This driver is only usable in the EFI pre-boot environment. This driver is only usable in the EFI pre-boot environment.
This sample is intended to show how the UGA Draw and Graphics output Protocol This sample is intended to show how the UGA Draw and Graphics output Protocol
is able to function. is able to function.
The UGA I/O Protocol is not implemented in this sample. The UGA I/O Protocol is not implemented in this sample.
A fully compliant EFI UGA driver requires both A fully compliant EFI UGA driver requires both
the UGA Draw and the UGA I/O Protocol. Please refer to Microsoft's the UGA Draw and the UGA I/O Protocol. Please refer to Microsoft's
documentation on UGA for details on how to write a UGA driver that is able documentation on UGA for details on how to write a UGA driver that is able
to function both in the EFI pre-boot environment and from the OS runtime. to function both in the EFI pre-boot environment and from the OS runtime.
Copyright (c) 2006, Intel Corporation Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/ **/
@ -40,8 +40,8 @@ EFI_DRIVER_BINDING_PROTOCOL gCirrusLogic5430DriverBinding = {
/// Generic Attribute Controller Register Settings /// Generic Attribute Controller Register Settings
/// ///
UINT8 AttributeController[21] = { UINT8 AttributeController[21] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x41, 0x00, 0x0F, 0x00, 0x00 0x41, 0x00, 0x0F, 0x00, 0x00
}; };
@ -57,13 +57,13 @@ UINT8 GraphicsController[9] = {
// //
UINT8 Crtc_640_480_256_60[28] = { UINT8 Crtc_640_480_256_60[28] = {
0x5d, 0x4f, 0x50, 0x82, 0x53, 0x9f, 0x00, 0x3e, 0x5d, 0x4f, 0x50, 0x82, 0x53, 0x9f, 0x00, 0x3e,
0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xe1, 0x83, 0xdf, 0x50, 0x00, 0xe7, 0x04, 0xe3, 0xe1, 0x83, 0xdf, 0x50, 0x00, 0xe7, 0x04, 0xe3,
0xff, 0x00, 0x00, 0x22 0xff, 0x00, 0x00, 0x22
}; };
UINT16 Seq_640_480_256_60[15] = { UINT16 Seq_640_480_256_60[15] = {
0x0100, 0x0101, 0x0f02, 0x0003, 0x0e04, 0x1107, 0x0008, 0x4a0b, 0x0100, 0x0101, 0x0f02, 0x0003, 0x0e04, 0x1107, 0x0008, 0x4a0b,
0x5b0c, 0x450d, 0x7e0e, 0x2b1b, 0x2f1c, 0x301d, 0x331e 0x5b0c, 0x450d, 0x7e0e, 0x2b1b, 0x2f1c, 0x301d, 0x331e
}; };
@ -71,14 +71,14 @@ UINT16 Seq_640_480_256_60[15] = {
// 800 x 600 x 256 color @ 60 Hertz // 800 x 600 x 256 color @ 60 Hertz
// //
UINT8 Crtc_800_600_256_60[28] = { UINT8 Crtc_800_600_256_60[28] = {
0x7F, 0x63, 0x64, 0x80, 0x6B, 0x1B, 0x72, 0xF0, 0x7F, 0x63, 0x64, 0x80, 0x6B, 0x1B, 0x72, 0xF0,
0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x58, 0x8C, 0x57, 0x64, 0x00, 0x5F, 0x91, 0xE3, 0x58, 0x8C, 0x57, 0x64, 0x00, 0x5F, 0x91, 0xE3,
0xFF, 0x00, 0x00, 0x22 0xFF, 0x00, 0x00, 0x22
}; };
UINT16 Seq_800_600_256_60[15] = { UINT16 Seq_800_600_256_60[15] = {
0x0100, 0x0101, 0x0f02, 0x0003, 0x0e04, 0x1107, 0x0008, 0x4a0b, 0x0100, 0x0101, 0x0f02, 0x0003, 0x0e04, 0x1107, 0x0008, 0x4a0b,
0x5b0c, 0x450d, 0x510e, 0x2b1b, 0x2f1c, 0x301d, 0x3a1e 0x5b0c, 0x450d, 0x510e, 0x2b1b, 0x2f1c, 0x301d, 0x3a1e
}; };
@ -86,14 +86,14 @@ UINT16 Seq_800_600_256_60[15] = {
// 1024 x 768 x 256 color @ 60 Hertz // 1024 x 768 x 256 color @ 60 Hertz
// //
UINT8 Crtc_1024_768_256_60[28] = { UINT8 Crtc_1024_768_256_60[28] = {
0xA3, 0x7F, 0x80, 0x86, 0x85, 0x96, 0x24, 0xFD, 0xA3, 0x7F, 0x80, 0x86, 0x85, 0x96, 0x24, 0xFD,
0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x02, 0x88, 0xFF, 0x80, 0x00, 0x00, 0x24, 0xE3, 0x02, 0x88, 0xFF, 0x80, 0x00, 0x00, 0x24, 0xE3,
0xFF, 0x4A, 0x00, 0x22 0xFF, 0x4A, 0x00, 0x22
}; };
UINT16 Seq_1024_768_256_60[15] = { UINT16 Seq_1024_768_256_60[15] = {
0x0100, 0x0101, 0x0f02, 0x0003, 0x0e04, 0x1107, 0x0008, 0x4a0b, 0x0100, 0x0101, 0x0f02, 0x0003, 0x0e04, 0x1107, 0x0008, 0x4a0b,
0x5b0c, 0x450d, 0x760e, 0x2b1b, 0x2f1c, 0x301d, 0x341e 0x5b0c, 0x450d, 0x760e, 0x2b1b, 0x2f1c, 0x301d, 0x341e
}; };
@ -102,8 +102,8 @@ UINT16 Seq_1024_768_256_60[15] = {
/// ///
CIRRUS_LOGIC_5430_VIDEO_MODES CirrusLogic5430VideoModes[] = { CIRRUS_LOGIC_5430_VIDEO_MODES CirrusLogic5430VideoModes[] = {
{ 640, 480, 8, 60, Crtc_640_480_256_60, Seq_640_480_256_60, 0xe3 }, { 640, 480, 8, 60, Crtc_640_480_256_60, Seq_640_480_256_60, 0xe3 },
{ 800, 600, 8, 60, Crtc_800_600_256_60, Seq_800_600_256_60, 0xef }, { 800, 600, 8, 60, Crtc_800_600_256_60, Seq_800_600_256_60, 0xef },
{ 1024, 768, 8, 60, Crtc_1024_768_256_60, Seq_1024_768_256_60, 0xef } { 1024, 768, 8, 60, Crtc_1024_768_256_60, Seq_1024_768_256_60, 0xef }
}; };
/** /**
@ -242,6 +242,20 @@ CirrusLogic5430ControllerDriverStart (
goto Error; goto Error;
} }
//
// Save original PCI attributes
//
Status = Private->PciIo->Attributes (
Private->PciIo,
EfiPciIoAttributeOperationGet,
0,
&Private->OriginalPciAttributes
);
if (EFI_ERROR (Status)) {
goto Error;
}
Status = Private->PciIo->Attributes ( Status = Private->PciIo->Attributes (
Private->PciIo, Private->PciIo,
EfiPciIoAttributeOperationEnable, EfiPciIoAttributeOperationEnable,
@ -290,40 +304,42 @@ CirrusLogic5430ControllerDriverStart (
&Private->GraphicsOutput, &Private->GraphicsOutput,
NULL NULL
); );
} else { } else {
// //
// This driver must support eithor GOP or UGA or both. // This driver must support eithor GOP or UGA or both.
// //
ASSERT (FALSE); ASSERT (FALSE);
Status = EFI_UNSUPPORTED; Status = EFI_UNSUPPORTED;
} }
} }
Error: Error:
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
if (Private) { if (Private) {
if (Private->PciIo) { if (Private->PciIo) {
//
// Restore original PCI attributes
//
Private->PciIo->Attributes ( Private->PciIo->Attributes (
Private->PciIo, Private->PciIo,
EfiPciIoAttributeOperationDisable, EfiPciIoAttributeOperationSet,
EFI_PCI_DEVICE_ENABLE | EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY | EFI_PCI_IO_ATTRIBUTE_VGA_IO, Private->OriginalPciAttributes,
NULL NULL
); );
}
} //
// Close the PCI I/O Protocol
//
gBS->CloseProtocol (
Private->Handle,
&gEfiPciIoProtocolGuid,
This->DriverBindingHandle,
Private->Handle
);
}
//
// Close the PCI I/O Protocol
//
gBS->CloseProtocol (
Private->Handle,
&gEfiPciIoProtocolGuid,
This->DriverBindingHandle,
Private->Handle
);
if (Private) {
gBS->FreePool (Private); gBS->FreePool (Private);
} }
} }
@ -433,16 +449,15 @@ CirrusLogic5430ControllerDriverStop (
return Status; return Status;
} }
// //
// Shutdown the hardware // Restore original PCI attributes
// //
Private->PciIo->Attributes ( Private->PciIo->Attributes (
Private->PciIo, Private->PciIo,
EfiPciIoAttributeOperationDisable, EfiPciIoAttributeOperationSet,
EFI_PCI_DEVICE_ENABLE | EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY | EFI_PCI_IO_ATTRIBUTE_VGA_IO, Private->OriginalPciAttributes,
NULL NULL
); );
// //
// Close the PCI I/O Protocol // Close the PCI I/O Protocol
@ -787,7 +802,7 @@ InitializeCirrusLogic5430 (
ASSERT_EFI_ERROR (Status); ASSERT_EFI_ERROR (Status);
// //
// Install EFI Driver Supported EFI Version Protocol required for // Install EFI Driver Supported EFI Version Protocol required for
// EFI drivers that are on PCI and other plug in cards. // EFI drivers that are on PCI and other plug in cards.
// //
gCirrusLogic5430DriverSupportedEfiVersion.FirmwareVersion = PcdGet32 (PcdDriverSupportedEfiVersion); gCirrusLogic5430DriverSupportedEfiVersion.FirmwareVersion = PcdGet32 (PcdDriverSupportedEfiVersion);

View File

@ -1,14 +1,14 @@
/** @file /** @file
Cirrus Logic 5430 Controller Driver Cirrus Logic 5430 Controller Driver
Copyright (c) 2006, Intel Corporation Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/ **/
@ -65,6 +65,7 @@ typedef struct {
UINT64 Signature; UINT64 Signature;
EFI_HANDLE Handle; EFI_HANDLE Handle;
EFI_PCI_IO_PROTOCOL *PciIo; EFI_PCI_IO_PROTOCOL *PciIo;
UINT64 OriginalPciAttributes;
EFI_UGA_DRAW_PROTOCOL UgaDraw; EFI_UGA_DRAW_PROTOCOL UgaDraw;
EFI_GRAPHICS_OUTPUT_PROTOCOL GraphicsOutput; EFI_GRAPHICS_OUTPUT_PROTOCOL GraphicsOutput;
UINTN CurrentMode; UINTN CurrentMode;