QuarkSocPkg: Add new package for Quark SoC X1000

Changes for V4
==============
1) Remove Unicode character from C source file
2) Move delete of QuarkSocPkg\QuarkNorthCluster\Binary\QuarkMicrocode
   from QuarkPlatformPkg commit to QuarkSocPkg commit

Changes for V2
==============
1) Sync with new APIs in SmmCpuFeaturesLib class
2) Use new generic PCI serial driver PciSioSerialDxe in MdeModulePkg
3) Remove PCI serial driver from QuarkSocPkg
4) Apply optimizations to MtrrLib from MtrrLib in UefiCpuPkg
5) Convert all UNI files to utf-8
6) Replace tabs with spaces and remove trailing spaces
7) Add License.txt

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Michael Kinney <michael.d.kinney@intel.com>
Acked-by: Jordan Justen <jordan.l.justen@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@19286 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Michael Kinney
2015-12-15 19:22:23 +00:00
committed by mdkinney
parent 46ff196fde
commit 9b6bbcdbfd
176 changed files with 54761 additions and 0 deletions

View File

@@ -0,0 +1,956 @@
/** @file
PCH SPI Common Driver implements the SPI Host Controller Compatibility Interface.
Copyright (c) 2013-2015 Intel Corporation.
This program and the accompanying materials
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
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "PchSpi.h"
VOID
FillOutPublicInfoStruct (
SPI_INSTANCE *SpiInstance
)
/*++
Routine Description:
Fillout SpiInstance->InitInfo;
Arguments:
SpiInstance - Pointer to SpiInstance to initialize
Returns:
NONE
--*/
{
UINT8 Index;
SpiInstance->InitInfo.InitTable = &SpiInstance->SpiInitTable;
//
// Give invalid index in case operation not supported.
//
SpiInstance->InitInfo.JedecIdOpcodeIndex = 0xff;
SpiInstance->InitInfo.OtherOpcodeIndex = 0xff;
SpiInstance->InitInfo.WriteStatusOpcodeIndex = 0xff;
SpiInstance->InitInfo.ProgramOpcodeIndex = 0xff;
SpiInstance->InitInfo.ReadOpcodeIndex = 0xff;
SpiInstance->InitInfo.EraseOpcodeIndex = 0xff;
SpiInstance->InitInfo.ReadStatusOpcodeIndex = 0xff;
SpiInstance->InitInfo.FullChipEraseOpcodeIndex = 0xff;
for (Index = 0; Index < SPI_NUM_OPCODE; Index++) {
if (SpiInstance->SpiInitTable.OpcodeMenu[Index].Operation == EnumSpiOperationJedecId) {
SpiInstance->InitInfo.JedecIdOpcodeIndex = Index;
}
if (SpiInstance->SpiInitTable.OpcodeMenu[Index].Operation == EnumSpiOperationOther) {
SpiInstance->InitInfo.OtherOpcodeIndex = Index;
}
if (SpiInstance->SpiInitTable.OpcodeMenu[Index].Operation == EnumSpiOperationWriteStatus) {
SpiInstance->InitInfo.WriteStatusOpcodeIndex = Index;
}
if (SpiInstance->SpiInitTable.OpcodeMenu[Index].Operation == EnumSpiOperationProgramData_1_Byte ||
SpiInstance->SpiInitTable.OpcodeMenu[Index].Operation == EnumSpiOperationProgramData_64_Byte) {
SpiInstance->InitInfo.ProgramOpcodeIndex = Index;
}
if (SpiInstance->SpiInitTable.OpcodeMenu[Index].Operation == EnumSpiOperationReadData ||
SpiInstance->SpiInitTable.OpcodeMenu[Index].Operation == EnumSpiOperationFastRead ||
SpiInstance->SpiInitTable.OpcodeMenu[Index].Operation == EnumSpiOperationDualOutputFastRead) {
SpiInstance->InitInfo.ReadOpcodeIndex = Index;
}
if (SpiInstance->SpiInitTable.OpcodeMenu[Index].Operation == EnumSpiOperationErase_256_Byte ||
SpiInstance->SpiInitTable.OpcodeMenu[Index].Operation == EnumSpiOperationErase_4K_Byte ||
SpiInstance->SpiInitTable.OpcodeMenu[Index].Operation == EnumSpiOperationErase_8K_Byte ||
SpiInstance->SpiInitTable.OpcodeMenu[Index].Operation == EnumSpiOperationErase_64K_Byte) {
SpiInstance->InitInfo.EraseOpcodeIndex = Index;
}
if (SpiInstance->SpiInitTable.OpcodeMenu[Index].Operation == EnumSpiOperationReadStatus) {
SpiInstance->InitInfo.ReadStatusOpcodeIndex = Index;
}
if (SpiInstance->SpiInitTable.OpcodeMenu[Index].Operation == EnumSpiOperationFullChipErase) {
SpiInstance->InitInfo.FullChipEraseOpcodeIndex = Index;
}
}
}
EFI_STATUS
SpiProtocolConstructor (
SPI_INSTANCE *SpiInstance
)
/*++
Routine Description:
Initialize an SPI protocol instance.
The function will assert in debug if PCH RCBA has not been initialized
Arguments:
SpiInstance - Pointer to SpiInstance to initialize
Returns:
EFI_SUCCESS The protocol instance was properly initialized
EFI_UNSUPPORTED The PCH is not supported by this module
--*/
{
SpiInstance->InitDone = FALSE; // Indicate NOT READY.
//
// Check if the current PCH is known and supported by this code
//
if (!IsQncSupported ()) {
DEBUG ((DEBUG_ERROR, "PCH SPI Protocol not supported due to no proper QNC LPC found!\n"));
return EFI_UNSUPPORTED;
}
//
// Initialize the SPI protocol instance
//
SpiInstance->Signature = PCH_SPI_PRIVATE_DATA_SIGNATURE;
SpiInstance->Handle = NULL;
SpiInstance->SpiProtocol.Init = SpiProtocolInit;
SpiInstance->SpiProtocol.Lock = SpiProtocolLock;
SpiInstance->SpiProtocol.Execute = SpiProtocolExecute;
SpiInstance->SpiProtocol.Info = SpiProtocolInfo;
//
// Sanity check to ensure PCH RCBA initialization has occurred previously.
//
SpiInstance->PchRootComplexBar = MmioRead32 (
PciDeviceMmBase (PCI_BUS_NUMBER_QNC,
PCI_DEVICE_NUMBER_QNC_LPC,
PCI_FUNCTION_NUMBER_QNC_LPC) + R_QNC_LPC_RCBA
) & B_QNC_LPC_RCBA_MASK;
ASSERT (SpiInstance->PchRootComplexBar != 0);
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
UnlockFlashComponents (
IN EFI_SPI_PROTOCOL *This,
IN UINT8 UnlockCmdOpcodeIndex
)
/*++
Routine Description:
Issue unlock command to disable block protection, this only needs to be done once per SPI power on
Arguments:
This A pointer to "EFI_SPI_PROTOCOL" for issuing commands
UnlockCmdOpcodeIndex The index of the Unlock command
Returns:
EFI_SUCCESS UnLock operation succeed.
EFI_DEVICE_ERROR Device error, operation failed.
--*/
{
EFI_STATUS Status;
SPI_INSTANCE *SpiInstance;
UINT8 SpiStatus;
UINTN PchRootComplexBar;
if (UnlockCmdOpcodeIndex >= SPI_NUM_OPCODE) {
return EFI_UNSUPPORTED;
}
SpiInstance = SPI_INSTANCE_FROM_SPIPROTOCOL (This);
PchRootComplexBar = SpiInstance->PchRootComplexBar;
//
// Issue unlock command to disable block protection, this only needs to be done once per SPI power on
//
SpiStatus = 0;
//
// Issue unlock command to the flash component 1 at first
//
Status = SpiProtocolExecute (
This,
UnlockCmdOpcodeIndex,
SpiInstance->SpiInitTable.PrefixOpcode[0] == PCH_SPI_COMMAND_WRITE_ENABLE ? 0 : 1,
TRUE,
TRUE,
TRUE,
(UINTN) 0,
sizeof (SpiStatus),
&SpiStatus,
EnumSpiRegionAll
);
if (EFI_ERROR (Status)) {
DEBUG ((EFI_D_ERROR, "Unlock flash component 1 fail!\n"));
return Status;
}
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
SpiProtocolInit (
IN EFI_SPI_PROTOCOL *This,
IN SPI_INIT_TABLE *InitTable
)
/*++
Routine Description:
Initialize the host controller to execute SPI command.
Arguments:
This Pointer to the EFI_SPI_PROTOCOL instance.
InitTable Initialization data to be programmed into the SPI host controller.
Returns:
EFI_SUCCESS Initialization completed.
EFI_ACCESS_DENIED The SPI static configuration interface has been locked-down.
EFI_INVALID_PARAMETER Bad input parameters.
EFI_UNSUPPORTED Can't get Descriptor mode VSCC values
--*/
{
EFI_STATUS Status;
UINT8 Index;
UINT16 OpcodeType;
SPI_INSTANCE *SpiInstance;
BOOLEAN MultiPartitionIsSupported;
UINTN PchRootComplexBar;
UINT8 SFDPCmdOpcodeIndex;
UINT8 UnlockCmdOpcodeIndex;
UINT8 ReadDataCmdOpcodeIndex;
UINT8 FlashPartId[3];
SpiInstance = SPI_INSTANCE_FROM_SPIPROTOCOL (This);
PchRootComplexBar = SpiInstance->PchRootComplexBar;
if (InitTable != NULL) {
//
// Copy table into SPI driver Private data structure
//
CopyMem (
&SpiInstance->SpiInitTable,
InitTable,
sizeof (SPI_INIT_TABLE)
);
} else {
return EFI_INVALID_PARAMETER;
}
//
// Check if the SPI interface has been locked-down.
//
if ((MmioRead16 (PchRootComplexBar + R_QNC_RCRB_SPIS) & B_QNC_RCRB_SPIS_SCL) != 0) {
ASSERT_EFI_ERROR (EFI_ACCESS_DENIED);
return EFI_ACCESS_DENIED;
}
//
// Clear all the status bits for status regs.
//
MmioOr16 (
(UINTN) (PchRootComplexBar + R_QNC_RCRB_SPIS),
(UINT16) ((B_QNC_RCRB_SPIS_CDS | B_QNC_RCRB_SPIS_BAS))
);
MmioRead16 (PchRootComplexBar + R_QNC_RCRB_SPIS);
//
// Set the Prefix Opcode registers.
//
MmioWrite16 (
PchRootComplexBar + R_QNC_RCRB_SPIPREOP,
(SpiInstance->SpiInitTable.PrefixOpcode[1] << 8) | InitTable->PrefixOpcode[0]
);
MmioRead16 (PchRootComplexBar + R_QNC_RCRB_SPIPREOP);
//
// Set Opcode Type Configuration registers.
//
for (Index = 0, OpcodeType = 0; Index < SPI_NUM_OPCODE; Index++) {
switch (SpiInstance->SpiInitTable.OpcodeMenu[Index].Type) {
case EnumSpiOpcodeRead:
OpcodeType |= (UINT16) (B_QNC_RCRB_SPIOPTYPE_ADD_READ << (Index * 2));
break;
case EnumSpiOpcodeWrite:
OpcodeType |= (UINT16) (B_QNC_RCRB_SPIOPTYPE_ADD_WRITE << (Index * 2));
break;
case EnumSpiOpcodeWriteNoAddr:
OpcodeType |= (UINT16) (B_QNC_RCRB_SPIOPTYPE_NOADD_WRITE << (Index * 2));
break;
default:
OpcodeType |= (UINT16) (B_QNC_RCRB_SPIOPTYPE_NOADD_READ << (Index * 2));
break;
}
}
MmioWrite16 (PchRootComplexBar + R_QNC_RCRB_SPIOPTYPE, OpcodeType);
MmioRead16 (PchRootComplexBar + R_QNC_RCRB_SPIOPTYPE);
//
// Setup the Opcode Menu registers.
//
ReadDataCmdOpcodeIndex = SPI_NUM_OPCODE;
SFDPCmdOpcodeIndex = SPI_NUM_OPCODE;
UnlockCmdOpcodeIndex = SPI_NUM_OPCODE;
for (Index = 0; Index < SPI_NUM_OPCODE; Index++) {
MmioWrite8 (
PchRootComplexBar + R_QNC_RCRB_SPIOPMENU + Index,
SpiInstance->SpiInitTable.OpcodeMenu[Index].Code
);
MmioRead8 (PchRootComplexBar + R_QNC_RCRB_SPIOPMENU + Index);
if (SpiInstance->SpiInitTable.OpcodeMenu[Index].Operation == EnumSpiOperationJedecId) {
Status = SpiProtocolExecute (
This,
Index,
0,
TRUE,
TRUE,
FALSE,
(UINTN) 0,
3,
FlashPartId,
EnumSpiRegionDescriptor
);
if (EFI_ERROR (Status)) {
return Status;
}
if (FlashPartId[0] != SpiInstance->SpiInitTable.VendorId ||
FlashPartId[1] != SpiInstance->SpiInitTable.DeviceId0 ||
FlashPartId[2] != SpiInstance->SpiInitTable.DeviceId1) {
return EFI_INVALID_PARAMETER;
}
}
if (SpiInstance->SpiInitTable.OpcodeMenu[Index].Operation == EnumSpiOperationReadData ||
SpiInstance->SpiInitTable.OpcodeMenu[Index].Operation == EnumSpiOperationFastRead ||
SpiInstance->SpiInitTable.OpcodeMenu[Index].Operation == EnumSpiOperationDualOutputFastRead) {
ReadDataCmdOpcodeIndex = Index;
}
if (SpiInstance->SpiInitTable.OpcodeMenu[Index].Operation == EnumSpiOperationDiscoveryParameters) {
SFDPCmdOpcodeIndex = Index;
}
if (SpiInstance->SpiInitTable.OpcodeMenu[Index].Operation == EnumSpiOperationWriteStatus) {
UnlockCmdOpcodeIndex = Index;
}
}
MultiPartitionIsSupported = FALSE;
Status = UnlockFlashComponents (
This,
UnlockCmdOpcodeIndex
);
if (EFI_ERROR (Status)) {
DEBUG ((EFI_D_ERROR, "Unlock flash components fail!\n"));
}
SpiPhaseInit ();
FillOutPublicInfoStruct (SpiInstance);
SpiInstance->InitDone = TRUE;
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
SpiProtocolLock (
IN EFI_SPI_PROTOCOL *This
)
/*++
Routine Description:
Lock the SPI Static Configuration Interface.
Once locked, the interface can not be changed and can only be clear by system reset.
Arguments:
This Pointer to the EFI_SPI_PROTOCOL instance.
Returns:
EFI_SUCCESS Lock operation succeed.
EFI_DEVICE_ERROR Device error, operation failed.
EFI_ACCESS_DENIED The interface has already been locked.
--*/
{
SPI_INSTANCE *SpiInstance;
UINTN PchRootComplexBar;
SpiInstance = SPI_INSTANCE_FROM_SPIPROTOCOL (This);
PchRootComplexBar = SpiInstance->PchRootComplexBar;
//
// Check if the SPI interface has been locked-down.
//
if ((MmioRead16 (PchRootComplexBar + R_QNC_RCRB_SPIS) & B_QNC_RCRB_SPIS_SCL) != 0) {
return EFI_ACCESS_DENIED;
}
//
// Lock-down the configuration interface.
//
MmioOr16 ((UINTN) (PchRootComplexBar + R_QNC_RCRB_SPIS), (UINT16) (B_QNC_RCRB_SPIS_SCL));
//
// Verify if it's really locked.
//
if ((MmioRead16 (PchRootComplexBar + R_QNC_RCRB_SPIS) & B_QNC_RCRB_SPIS_SCL) == 0) {
return EFI_DEVICE_ERROR;
} else {
//
// Save updated register in S3 Boot script.
//
S3BootScriptSaveMemWrite (
S3BootScriptWidthUint16,
(UINTN) (PchRootComplexBar + R_QNC_RCRB_SPIS),
1,
(VOID *) (UINTN) (PchRootComplexBar + R_QNC_RCRB_SPIS)
);
}
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
SpiProtocolExecute (
IN EFI_SPI_PROTOCOL *This,
IN UINT8 OpcodeIndex,
IN UINT8 PrefixOpcodeIndex,
IN BOOLEAN DataCycle,
IN BOOLEAN Atomic,
IN BOOLEAN ShiftOut,
IN UINTN Address,
IN UINT32 DataByteCount,
IN OUT UINT8 *Buffer,
IN SPI_REGION_TYPE SpiRegionType
)
/*++
Routine Description:
Execute SPI commands from the host controller.
This function would be called by runtime driver, please do not use any MMIO marco here
Arguments:
This Pointer to the EFI_SPI_PROTOCOL instance.
OpcodeIndex Index of the command in the OpCode Menu.
PrefixOpcodeIndex Index of the first command to run when in an atomic cycle sequence.
DataCycle TRUE if the SPI cycle contains data
Atomic TRUE if the SPI cycle is atomic and interleave cycles are not allowed.
ShiftOut If DataByteCount is not zero, TRUE to shift data out and FALSE to shift data in.
Address In Descriptor Mode, for Descriptor Region, GbE Region, ME Region and Platform
Region, this value specifies the offset from the Region Base; for BIOS Region,
this value specifies the offset from the start of the BIOS Image. In Non
Descriptor Mode, this value specifies the offset from the start of the BIOS Image.
Please note BIOS Image size may be smaller than BIOS Region size (in Descriptor
Mode) or the flash size (in Non Descriptor Mode), and in this case, BIOS Image is
supposed to be placed at the top end of the BIOS Region (in Descriptor Mode) or
the flash (in Non Descriptor Mode)
DataByteCount Number of bytes in the data portion of the SPI cycle. This function may break the
data transfer into multiple operations. This function ensures each operation does
not cross 256 byte flash address boundary.
*NOTE: if there is some SPI chip that has a stricter address boundary requirement
(e.g., its write page size is < 256 byte), then the caller cannot rely on this
function to cut the data transfer at proper address boundaries, and it's the
caller's reponsibility to pass in a properly cut DataByteCount parameter.
Buffer Pointer to caller-allocated buffer containing the dada received or sent during the
SPI cycle.
SpiRegionType SPI Region type. Values EnumSpiRegionBios, EnumSpiRegionGbE, EnumSpiRegionMe,
EnumSpiRegionDescriptor, and EnumSpiRegionPlatformData are only applicable in
Descriptor mode. Value EnumSpiRegionAll is applicable to both Descriptor Mode
and Non Descriptor Mode, which indicates "SpiRegionOffset" is actually relative
to base of the 1st flash device (i.e., it is a Flash Linear Address).
Returns:
EFI_SUCCESS Command succeed.
EFI_INVALID_PARAMETER The parameters specified are not valid.
EFI_UNSUPPORTED Command not supported.
EFI_DEVICE_ERROR Device error, command aborts abnormally.
--*/
{
EFI_STATUS Status;
UINT16 BiosCtlSave;
UINT32 SmiEnSave;
BiosCtlSave = 0;
SmiEnSave = 0;
//
// Check if the parameters are valid.
//
if ((OpcodeIndex >= SPI_NUM_OPCODE) || (PrefixOpcodeIndex >= SPI_NUM_PREFIX_OPCODE)) {
return EFI_INVALID_PARAMETER;
}
//
// Make sure it's safe to program the command.
//
if (!WaitForSpiCycleComplete (This, FALSE)) {
return EFI_DEVICE_ERROR;
}
//
// Acquire access to the SPI interface is not required any more.
//
//
// Disable SMIs to make sure normal mode flash access is not interrupted by an SMI
// whose SMI handler accesses flash (e.g. for error logging)
//
SmiEnSave = QNCPortRead (QUARK_NC_HOST_BRIDGE_SB_PORT_ID, QNC_MSG_FSBIC_REG_HMISC);
QNCPortWrite (QUARK_NC_HOST_BRIDGE_SB_PORT_ID, QNC_MSG_FSBIC_REG_HMISC, (SmiEnSave & ~SMI_EN));
//
// Save BIOS Ctrl register
//
BiosCtlSave = PciRead16 (
PCI_LIB_ADDRESS (PCI_BUS_NUMBER_QNC,
PCI_DEVICE_NUMBER_QNC_LPC,
PCI_FUNCTION_NUMBER_QNC_LPC,
R_QNC_LPC_BIOS_CNTL)
) & (B_QNC_LPC_BIOS_CNTL_BCD | B_QNC_LPC_BIOS_CNTL_PFE | B_QNC_LPC_BIOS_CNTL_BIOSWE | B_QNC_LPC_BIOS_CNTL_SMM_BWP);
//
// Enable flash writing
//
PciOr16 (
PCI_LIB_ADDRESS (PCI_BUS_NUMBER_QNC,
PCI_DEVICE_NUMBER_QNC_LPC,
PCI_FUNCTION_NUMBER_QNC_LPC,
R_QNC_LPC_BIOS_CNTL),
(UINT16) (B_QNC_LPC_BIOS_CNTL_BIOSWE | B_QNC_LPC_BIOS_CNTL_SMM_BWP)
);
//
// If shifts the data out, disable Prefetching and Caching.
//
if (ShiftOut) {
PciAndThenOr16 (
PCI_LIB_ADDRESS (PCI_BUS_NUMBER_QNC,
PCI_DEVICE_NUMBER_QNC_LPC,
PCI_FUNCTION_NUMBER_QNC_LPC,
R_QNC_LPC_BIOS_CNTL),
(UINT16) (~(B_QNC_LPC_BIOS_CNTL_BCD | B_QNC_LPC_BIOS_CNTL_PFE)),
(UINT16) ((B_QNC_LPC_BIOS_CNTL_BCD))
);
}
//
// Sends the command to the SPI interface to execute.
//
Status = SendSpiCmd (
This,
OpcodeIndex,
PrefixOpcodeIndex,
DataCycle,
Atomic,
ShiftOut,
Address,
DataByteCount,
Buffer,
SpiRegionType
);
//
// Restore BIOS Ctrl register
//
PciAndThenOr16 (
PCI_LIB_ADDRESS (PCI_BUS_NUMBER_QNC,
PCI_DEVICE_NUMBER_QNC_LPC,
PCI_FUNCTION_NUMBER_QNC_LPC,
R_QNC_LPC_BIOS_CNTL),
(UINT16) (~(B_QNC_LPC_BIOS_CNTL_BCD | B_QNC_LPC_BIOS_CNTL_PFE | B_QNC_LPC_BIOS_CNTL_BIOSWE | B_QNC_LPC_BIOS_CNTL_SMM_BWP)),
(UINT16) (BiosCtlSave)
);
//
// Restore SMIs.
//
QNCPortWrite (QUARK_NC_HOST_BRIDGE_SB_PORT_ID, QNC_MSG_FSBIC_REG_HMISC, SmiEnSave);
return Status;
}
VOID
SpiOffset2Physical (
IN EFI_SPI_PROTOCOL *This,
IN UINTN SpiRegionOffset,
IN SPI_REGION_TYPE SpiRegionType,
OUT UINTN *HardwareSpiAddress,
OUT UINTN *BaseAddress,
OUT UINTN *LimitAddress
)
/*++
Routine Description:
Convert SPI offset to Physical address of SPI hardware
Arguments:
This Pointer to the EFI_SPI_PROTOCOL instance.
SpiRegionOffset In Descriptor Mode, for Descriptor Region, GbE Region, ME Region and Platform
Region, this value specifies the offset from the Region Base; for BIOS Region,
this value specifies the offset from the start of the BIOS Image. In Non
Descriptor Mode, this value specifies the offset from the start of the BIOS Image.
Please note BIOS Image size may be smaller than BIOS Region size (in Descriptor
Mode) or the flash size (in Non Descriptor Mode), and in this case, BIOS Image is
supposed to be placed at the top end of the BIOS Region (in Descriptor Mode) or
the flash (in Non Descriptor Mode)
BaseAddress Base Address of the region.
SpiRegionType SPI Region type. Values EnumSpiRegionBios, EnumSpiRegionGbE, EnumSpiRegionMe,
EnumSpiRegionDescriptor, and EnumSpiRegionPlatformData are only applicable in
Descriptor mode. Value EnumSpiRegionAll is applicable to both Descriptor Mode
and Non Descriptor Mode, which indicates "SpiRegionOffset" is actually relative
to base of the 1st flash device (i.e., it is a Flash Linear Address).
HardwareSpiAddress Return absolution SPI address (i.e., Flash Linear Address)
BaseAddress Return base address of the region type
LimitAddress Return limit address of the region type
Returns:
EFI_SUCCESS Command succeed.
--*/
{
SPI_INSTANCE *SpiInstance;
UINTN PchRootComplexBar;
SpiInstance = SPI_INSTANCE_FROM_SPIPROTOCOL (This);
PchRootComplexBar = SpiInstance->PchRootComplexBar;
if (SpiRegionType == EnumSpiRegionAll) {
//
// EnumSpiRegionAll indicates address is relative to flash device (i.e., address is Flash
// Linear Address)
//
*HardwareSpiAddress = SpiRegionOffset;
} else {
//
// Otherwise address is relative to BIOS image
//
*HardwareSpiAddress = SpiRegionOffset + SpiInstance->SpiInitTable.BiosStartOffset;
}
}
EFI_STATUS
SendSpiCmd (
IN EFI_SPI_PROTOCOL *This,
IN UINT8 OpcodeIndex,
IN UINT8 PrefixOpcodeIndex,
IN BOOLEAN DataCycle,
IN BOOLEAN Atomic,
IN BOOLEAN ShiftOut,
IN UINTN Address,
IN UINT32 DataByteCount,
IN OUT UINT8 *Buffer,
IN SPI_REGION_TYPE SpiRegionType
)
/*++
Routine Description:
This function sends the programmed SPI command to the slave device.
Arguments:
OpcodeIndex Index of the command in the OpCode Menu.
PrefixOpcodeIndex Index of the first command to run when in an atomic cycle sequence.
DataCycle TRUE if the SPI cycle contains data
Atomic TRUE if the SPI cycle is atomic and interleave cycles are not allowed.
ShiftOut If DataByteCount is not zero, TRUE to shift data out and FALSE to shift data in.
Address In Descriptor Mode, for Descriptor Region, GbE Region, ME Region and Platform
Region, this value specifies the offset from the Region Base; for BIOS Region,
this value specifies the offset from the start of the BIOS Image. In Non
Descriptor Mode, this value specifies the offset from the start of the BIOS Image.
Please note BIOS Image size may be smaller than BIOS Region size (in Descriptor
Mode) or the flash size (in Non Descriptor Mode), and in this case, BIOS Image is
supposed to be placed at the top end of the BIOS Region (in Descriptor Mode) or
the flash (in Non Descriptor Mode)
DataByteCount Number of bytes in the data portion of the SPI cycle. This function may break the
data transfer into multiple operations. This function ensures each operation does
not cross 256 byte flash address boundary.
*NOTE: if there is some SPI chip that has a stricter address boundary requirement
(e.g., its write page size is < 256 byte), then the caller cannot rely on this
function to cut the data transfer at proper address boundaries, and it's the
caller's reponsibility to pass in a properly cut DataByteCount parameter.
Buffer Data received or sent during the SPI cycle.
SpiRegionType SPI Region type. Values EnumSpiRegionBios, EnumSpiRegionGbE, EnumSpiRegionMe,
EnumSpiRegionDescriptor, and EnumSpiRegionPlatformData are only applicable in
Descriptor mode. Value EnumSpiRegionAll is applicable to both Descriptor Mode
and Non Descriptor Mode, which indicates "SpiRegionOffset" is actually relative
to base of the 1st flash device (i.e., it is a Flash Linear Address).
Returns:
EFI_SUCCESS SPI command completes successfully.
EFI_DEVICE_ERROR Device error, the command aborts abnormally.
EFI_ACCESS_DENIED Some unrecognized command encountered in hardware sequencing mode
EFI_INVALID_PARAMETER The parameters specified are not valid.
--*/
{
UINT32 Index;
SPI_INSTANCE *SpiInstance;
UINTN HardwareSpiAddr;
UINTN SpiBiosSize;
UINTN BaseAddress;
UINTN LimitAddress;
UINT32 SpiDataCount;
UINT8 OpCode;
SPI_OPERATION Operation;
UINTN PchRootComplexBar;
SpiInstance = SPI_INSTANCE_FROM_SPIPROTOCOL (This);
PchRootComplexBar = SpiInstance->PchRootComplexBar;
SpiBiosSize = SpiInstance->SpiInitTable.BiosSize;
Operation = SpiInstance->SpiInitTable.OpcodeMenu[OpcodeIndex].Operation;
OpCode = MmioRead8 (PchRootComplexBar + R_QNC_RCRB_SPIOPMENU + OpcodeIndex);
//
// Check if the value of opcode register is 0 or the BIOS Size of SpiInitTable is 0
//
if (OpCode == 0 || SpiBiosSize == 0) {
ASSERT (FALSE);
return EFI_INVALID_PARAMETER;
}
SpiOffset2Physical (This, Address, SpiRegionType, &HardwareSpiAddr, &BaseAddress, &LimitAddress);
//
// Have direct access to BIOS region in Descriptor mode,
//
if (SpiInstance->SpiInitTable.OpcodeMenu[OpcodeIndex].Type == EnumSpiOpcodeRead &&
SpiRegionType == EnumSpiRegionBios) {
CopyMem (
Buffer,
(UINT8 *) ((HardwareSpiAddr - BaseAddress) + (UINT32) (~(SpiBiosSize - 1))),
DataByteCount
);
return EFI_SUCCESS;
}
//
// DEBUG((EFI_D_ERROR, "SPIADDR %x, %x, %x, %x\n", Address, HardwareSpiAddr, BaseAddress,
// LimitAddress));
//
if ((DataCycle == FALSE) && (DataByteCount > 0)) {
DataByteCount = 0;
}
do {
//
// Trim at 256 byte boundary per operation,
// - PCH SPI controller requires trimming at 4KB boundary
// - Some SPI chips require trimming at 256 byte boundary for write operation
// - Trimming has limited performance impact as we can read / write atmost 64 byte
// per operation
//
if (HardwareSpiAddr + DataByteCount > ((HardwareSpiAddr + BIT8) &~(BIT8 - 1))) {
SpiDataCount = (((UINT32) (HardwareSpiAddr) + BIT8) &~(BIT8 - 1)) - (UINT32) (HardwareSpiAddr);
} else {
SpiDataCount = DataByteCount;
}
//
// Calculate the number of bytes to shift in/out during the SPI data cycle.
// Valid settings for the number of bytes duing each data portion of the
// PCH SPI cycles are: 0, 1, 2, 3, 4, 5, 6, 7, 8, 16, 24, 32, 40, 48, 56, 64
//
if (SpiDataCount >= 64) {
SpiDataCount = 64;
} else if ((SpiDataCount &~0x07) != 0) {
SpiDataCount = SpiDataCount &~0x07;
}
//
// If shifts data out, load data into the SPI data buffer.
//
if (ShiftOut) {
for (Index = 0; Index < SpiDataCount; Index++) {
MmioWrite8 (PchRootComplexBar + R_QNC_RCRB_SPID0 + Index, Buffer[Index]);
MmioRead8 (PchRootComplexBar + R_QNC_RCRB_SPID0 + Index);
}
}
MmioWrite32 (
(PchRootComplexBar + R_QNC_RCRB_SPIA),
(UINT32) (HardwareSpiAddr & B_QNC_RCRB_SPIA_MASK)
);
MmioRead32 (PchRootComplexBar + R_QNC_RCRB_SPIA);
//
// Execute the command on the SPI compatible mode
//
//
// Clear error flags
//
MmioOr16 ((PchRootComplexBar + R_QNC_RCRB_SPIS), B_QNC_RCRB_SPIS_BAS);
//
// Initialte the SPI cycle
//
if (DataCycle) {
MmioWrite16 (
(PchRootComplexBar + R_QNC_RCRB_SPIC),
( (UINT16) (B_QNC_RCRB_SPIC_DC) | (UINT16) (((SpiDataCount - 1) << 8) & B_QNC_RCRB_SPIC_DBC) |
(UINT16) ((OpcodeIndex << 4) & B_QNC_RCRB_SPIC_COP) |
(UINT16) ((PrefixOpcodeIndex << 3) & B_QNC_RCRB_SPIC_SPOP) |
(UINT16) (Atomic ? B_QNC_RCRB_SPIC_ACS : 0) |
(UINT16) (B_QNC_RCRB_SPIC_SCGO)));
} else {
MmioWrite16 (
(PchRootComplexBar + R_QNC_RCRB_SPIC),
( (UINT16) ((OpcodeIndex << 4) & B_QNC_RCRB_SPIC_COP) |
(UINT16) ((PrefixOpcodeIndex << 3) & B_QNC_RCRB_SPIC_SPOP) |
(UINT16) (Atomic ? B_QNC_RCRB_SPIC_ACS : 0) |
(UINT16) (B_QNC_RCRB_SPIC_SCGO)));
}
MmioRead16 (PchRootComplexBar + R_QNC_RCRB_SPIC);
//
// end of command execution
//
// Wait the SPI cycle to complete.
//
if (!WaitForSpiCycleComplete (This, TRUE)) {
return EFI_DEVICE_ERROR;
}
//
// If shifts data in, get data from the SPI data buffer.
//
if (!ShiftOut) {
for (Index = 0; Index < SpiDataCount; Index++) {
Buffer[Index] = MmioRead8 (PchRootComplexBar + R_QNC_RCRB_SPID0 + Index);
}
}
HardwareSpiAddr += SpiDataCount;
Buffer += SpiDataCount;
DataByteCount -= SpiDataCount;
} while (DataByteCount > 0);
return EFI_SUCCESS;
}
BOOLEAN
WaitForSpiCycleComplete (
IN EFI_SPI_PROTOCOL *This,
IN BOOLEAN ErrorCheck
)
/*++
Routine Description:
Wait execution cycle to complete on the SPI interface. Check both Hardware
and Software Sequencing status registers
Arguments:
This - The SPI protocol instance
UseSoftwareSequence - TRUE if this is a Hardware Sequencing operation
ErrorCheck - TRUE if the SpiCycle needs to do the error check
Returns:
TRUE SPI cycle completed on the interface.
FALSE Time out while waiting the SPI cycle to complete.
It's not safe to program the next command on the SPI interface.
--*/
{
UINT64 WaitTicks;
UINT64 WaitCount;
UINT16 Data16;
SPI_INSTANCE *SpiInstance;
UINTN PchRootComplexBar;
SpiInstance = SPI_INSTANCE_FROM_SPIPROTOCOL (This);
PchRootComplexBar = SpiInstance->PchRootComplexBar;
//
// Convert the wait period allowed into to tick count
//
WaitCount = WAIT_TIME / WAIT_PERIOD;
//
// Wait for the SPI cycle to complete.
//
for (WaitTicks = 0; WaitTicks < WaitCount; WaitTicks++) {
Data16 = MmioRead16 (PchRootComplexBar + R_QNC_RCRB_SPIS);
if ((Data16 & B_QNC_RCRB_SPIS_SCIP) == 0) {
MmioWrite16 (PchRootComplexBar + R_QNC_RCRB_SPIS, (B_QNC_RCRB_SPIS_BAS | B_QNC_RCRB_SPIS_CDS));
if ((Data16 & B_QNC_RCRB_SPIS_BAS) && (ErrorCheck == TRUE)) {
return FALSE;
} else {
return TRUE;
}
}
MicroSecondDelay (WAIT_PERIOD);
}
return FALSE;
}
EFI_STATUS
EFIAPI
SpiProtocolInfo (
IN EFI_SPI_PROTOCOL *This,
OUT SPI_INIT_INFO **InitInfoPtr
)
/*++
Routine Description:
Return info about SPI host controller, to help callers usage of Execute
service.
If 0xff is returned as an opcode index in init info struct
then device does not support the operation.
Arguments:
This Pointer to the EFI_SPI_PROTOCOL instance.
InitInfoPtr Pointer to init info written to this memory location.
Returns:
EFI_SUCCESS Information returned.
EFI_INVALID_PARAMETER Invalid parameter.
EFI_NOT_READY Required resources not setup.
Others Unexpected error happened.
--*/
{
SPI_INSTANCE *SpiInstance;
if (This == NULL || InitInfoPtr == NULL) {
return EFI_INVALID_PARAMETER;
}
SpiInstance = SPI_INSTANCE_FROM_SPIPROTOCOL (This);
if (SpiInstance->Signature != PCH_SPI_PRIVATE_DATA_SIGNATURE) {
return EFI_INVALID_PARAMETER;
}
if (!SpiInstance->InitDone) {
*InitInfoPtr = NULL;
return EFI_NOT_READY;
}
*InitInfoPtr = &SpiInstance->InitInfo;
return EFI_SUCCESS;
}

View File

@@ -0,0 +1,323 @@
/** @file
Header file for the PCH SPI Common Driver.
Copyright (c) 2013-2015 Intel Corporation.
This program and the accompanying materials
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
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef _SPI_COMMON_H_
#define _SPI_COMMON_H_
#include "Protocol/Spi.h"
#include <Library/PciLib.h>
#include <Library/IoLib.h>
#include <Library/DebugLib.h>
#include <Library/PcdLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/IntelQNCLib.h>
#include <Library/QNCAccessLib.h>
#include <Uefi/UefiBaseType.h>
//
// Maximum time allowed while waiting the SPI cycle to complete
// Wait Time = 6 seconds = 6000000 microseconds
// Wait Period = 10 microseconds
//
#define WAIT_TIME 6000000
#define WAIT_PERIOD 10
//
// PCH Required SPI Commands -------- COMMAND SET I ------------
// SPI flash device must support in order to be compatible with PCH
//
#define PCH_SPI_COMMAND_PROGRAM_BYTE 0x02
#define PCH_SPI_COMMAND_READ_DATA 0x03
#define PCH_SPI_COMMAND_WRITE_DISABLE 0x04
#define PCH_SPI_COMMAND_READ_STATUS 0x05
#define PCH_SPI_COMMAND_WRITE_ENABLE 0x06
#define PCH_SPI_COMMAND_FAST_READ 0x0B
#define PCH_SPI_COMMAND_READ_ID 0x9F
#define PCH_SPI_COMMAND_DUAL_FAST_READ 0x3B // Dual Output Fast Read
//
// Need to support at least one of the following two kinds of size of sector for erasing
//
#define PCH_SPI_COMMAND_4KB_ERASE 0x20
#define PCH_SPI_COMMAND_64KB_ERASE 0xD8
//
// Recommended SPI Commands -------- COMMAND SET II ------------
// SPI flash device best to support
//
#define PCH_SPI_COMMAND_WRITE_STATUS 0x01
#define PCH_SPI_COMMAND_FULL_CHIP_ERASE 0xC7
//
// Private data structure definitions for the driver
//
#define PCH_SPI_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('P', 'S', 'P', 'I')
typedef struct {
UINTN Signature;
EFI_HANDLE Handle;
EFI_SPI_PROTOCOL SpiProtocol;
SPI_INIT_TABLE SpiInitTable;
UINTN PchRootComplexBar;
BOOLEAN InitDone; // Set to TRUE on SpiProtocolInit SUCCESS.
SPI_INIT_INFO InitInfo;
} SPI_INSTANCE;
#define SPI_INSTANCE_FROM_SPIPROTOCOL(a) CR (a, SPI_INSTANCE, SpiProtocol, PCH_SPI_PRIVATE_DATA_SIGNATURE)
//
// Function prototypes used by the SPI protocol.
//
EFI_STATUS
SpiProtocolConstructor (
SPI_INSTANCE *SpiInstance
)
/*++
Routine Description:
Initialize an SPI protocol instance.
The function will assert in debug if PCH RCBA has not been initialized
Arguments:
SpiInstance - Pointer to SpiInstance to initialize
Returns:
EFI_SUCCESS The protocol instance was properly initialized
EFI_UNSUPPORTED The PCH is not supported by this module
--*/
;
EFI_STATUS
EFIAPI
SpiProtocolInit (
IN EFI_SPI_PROTOCOL *This,
IN SPI_INIT_TABLE *InitTable
)
/*++
Routine Description:
Initialize the host controller to execute SPI command.
Arguments:
This Pointer to the EFI_SPI_PROTOCOL instance.
InitTable Initialization data to be programmed into the SPI host controller.
Returns:
EFI_SUCCESS Initialization completed.
EFI_ACCESS_DENIED The SPI static configuration interface has been locked-down.
EFI_INVALID_PARAMETER Bad input parameters.
--*/
;
EFI_STATUS
EFIAPI
SpiProtocolLock (
IN EFI_SPI_PROTOCOL *This
)
/*++
Routine Description:
Lock the SPI Static Configuration Interface.
Once locked, the interface can not be changed and can only be clear by system reset.
Arguments:
This Pointer to the EFI_SPI_PROTOCOL instance.
Returns:
EFI_SUCCESS Lock operation succeed.
EFI_DEVICE_ERROR Device error, operation failed.
EFI_ACCESS_DENIED The interface has already been locked.
--*/
;
EFI_STATUS
EFIAPI
SpiProtocolExecute (
IN EFI_SPI_PROTOCOL *This,
IN UINT8 OpcodeIndex,
IN UINT8 PrefixOpcodeIndex,
IN BOOLEAN DataCycle,
IN BOOLEAN Atomic,
IN BOOLEAN ShiftOut,
IN UINTN Address,
IN UINT32 DataByteCount,
IN OUT UINT8 *Buffer,
IN SPI_REGION_TYPE SpiRegionType
)
/*++
Routine Description:
Execute SPI commands from the host controller.
Arguments:
This Pointer to the EFI_SPI_PROTOCOL instance.
OpcodeIndex Index of the command in the OpCode Menu.
PrefixOpcodeIndex Index of the first command to run when in an atomic cycle sequence.
DataCycle TRUE if the SPI cycle contains data
Atomic TRUE if the SPI cycle is atomic and interleave cycles are not allowed.
ShiftOut If DataByteCount is not zero, TRUE to shift data out and FALSE to shift data in.
Address In Descriptor Mode, for Descriptor Region, GbE Region, ME Region and Platform
Region, this value specifies the offset from the Region Base; for BIOS Region,
this value specifies the offset from the start of the BIOS Image. In Non
Descriptor Mode, this value specifies the offset from the start of the BIOS Image.
Please note BIOS Image size may be smaller than BIOS Region size (in Descriptor
Mode) or the flash size (in Non Descriptor Mode), and in this case, BIOS Image is
supposed to be placed at the top end of the BIOS Region (in Descriptor Mode) or
the flash (in Non Descriptor Mode)
DataByteCount Number of bytes in the data portion of the SPI cycle.
Buffer Pointer to caller-allocated buffer containing the dada received or sent during the SPI cycle.
SpiRegionType SPI Region type. Values EnumSpiRegionBios, EnumSpiRegionGbE, EnumSpiRegionMe,
EnumSpiRegionDescriptor, and EnumSpiRegionPlatformData are only applicable in
Descriptor mode. Value EnumSpiRegionAll is applicable to both Descriptor Mode
and Non Descriptor Mode, which indicates "SpiRegionOffset" is actually relative
to base of the 1st flash device (i.e., it is a Flash Linear Address).
Returns:
EFI_SUCCESS Command succeed.
EFI_INVALID_PARAMETER The parameters specified are not valid.
EFI_UNSUPPORTED Command not supported.
EFI_DEVICE_ERROR Device error, command aborts abnormally.
--*/
;
EFI_STATUS
SendSpiCmd (
IN EFI_SPI_PROTOCOL *This,
IN UINT8 OpcodeIndex,
IN UINT8 PrefixOpcodeIndex,
IN BOOLEAN DataCycle,
IN BOOLEAN Atomic,
IN BOOLEAN ShiftOut,
IN UINTN Address,
IN UINT32 DataByteCount,
IN OUT UINT8 *Buffer,
IN SPI_REGION_TYPE SpiRegionType
)
/*++
Routine Description:
This function sends the programmed SPI command to the slave device.
Arguments:
OpcodeIndex Index of the command in the OpCode Menu.
PrefixOpcodeIndex Index of the first command to run when in an atomic cycle sequence.
DataCycle TRUE if the SPI cycle contains data
Atomic TRUE if the SPI cycle is atomic and interleave cycles are not allowed.
ShiftOut If DataByteCount is not zero, TRUE to shift data out and FALSE to shift data in.
Address In Descriptor Mode, for Descriptor Region, GbE Region, ME Region and Platform
Region, this value specifies the offset from the Region Base; for BIOS Region,
this value specifies the offset from the start of the BIOS Image. In Non
Descriptor Mode, this value specifies the offset from the start of the BIOS Image.
Please note BIOS Image size may be smaller than BIOS Region size (in Descriptor
Mode) or the flash size (in Non Descriptor Mode), and in this case, BIOS Image is
supposed to be placed at the top end of the BIOS Region (in Descriptor Mode) or
the flash (in Non Descriptor Mode)
DataByteCount Number of bytes in the data portion of the SPI cycle. This function may break the
data transfer into multiple operations. This function ensures each operation does
not cross 256 byte flash address boundary.
*NOTE: if there is some SPI chip that has a stricter address boundary requirement
(e.g., its write page size is < 256 byte), then the caller cannot rely on this
function to cut the data transfer at proper address boundaries, and it's the
caller's reponsibility to pass in a properly cut DataByteCount parameter.
Buffer Data received or sent during the SPI cycle.
SpiRegionType SPI Region type. Values EnumSpiRegionBios, EnumSpiRegionGbE, EnumSpiRegionMe,
EnumSpiRegionDescriptor, and EnumSpiRegionPlatformData are only applicable in
Descriptor mode. Value EnumSpiRegionAll is applicable to both Descriptor Mode
and Non Descriptor Mode, which indicates "SpiRegionOffset" is actually relative
to base of the 1st flash device (i.e., it is a Flash Linear Address).
Returns:
EFI_SUCCESS SPI command completes successfully.
EFI_DEVICE_ERROR Device error, the command aborts abnormally.
EFI_ACCESS_DENIED Some unrecognized command encountered in hardware sequencing mode
EFI_INVALID_PARAMETER The parameters specified are not valid.
--*/
;
BOOLEAN
WaitForSpiCycleComplete (
IN EFI_SPI_PROTOCOL *This,
IN BOOLEAN ErrorCheck
)
/*++
Routine Description:
Wait execution cycle to complete on the SPI interface. Check both Hardware
and Software Sequencing status registers
Arguments:
This - The SPI protocol instance
UseSoftwareSequence - TRUE if this is a Hardware Sequencing operation
ErrorCheck - TRUE if the SpiCycle needs to do the error check
Returns:
TRUE SPI cycle completed on the interface.
FALSE Time out while waiting the SPI cycle to complete.
It's not safe to program the next command on the SPI interface.
--*/
;
EFI_STATUS
EFIAPI
SpiProtocolInfo (
IN EFI_SPI_PROTOCOL *This,
OUT SPI_INIT_INFO **InitInfoPtr
)
/*++
Routine Description:
Return info about SPI host controller, to help callers usage of Execute
service.
If 0xff is returned as an opcode index in init info struct
then device does not support the operation.
Arguments:
This Pointer to the EFI_SPI_PROTOCOL instance.
InitInfoPtr Pointer to init info written to this memory location.
Returns:
EFI_SUCCESS Information returned.
EFI_INVALID_PARAMETER Invalid parameter.
EFI_NOT_READY Required resources not setup.
Others Unexpected error happened.
--*/
;
#endif

View File

@@ -0,0 +1,90 @@
## @file
# Component description file for the SPI Runtime driver.
#
# Copyright (c) 2013-2015 Intel Corporation.
#
# This program and the accompanying materials
# 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
# http://opensource.org/licenses/bsd-license.php
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
##
################################################################################
#
# Defines Section - statements that will be processed to create a Makefile.
#
################################################################################
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = PchSpiRuntime
FILE_GUID = C194C6EA-B68C-4981-B64B-9BD271474B20
MODULE_TYPE = DXE_RUNTIME_DRIVER
VERSION_STRING = 1.0
ENTRY_POINT = InstallPchSpi
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64 EBC
################################################################################
#
# Sources Section - list of files that are required for the build to succeed.
#
################################################################################
[Sources]
RuntimeDxe/PchSpi.h
RuntimeDxe/PchSpi.c
Common/SpiCommon.c
Common/SpiCommon.h
################################################################################
#
# Package Dependency Section - list of Package files that are required for
# this module.
#
################################################################################
[Packages]
MdePkg/MdePkg.dec
QuarkSocPkg/QuarkSocPkg.dec
################################################################################
#
# Library Class Section - list of Library Classes that are required for
# this module.
#
################################################################################
[LibraryClasses]
UefiRuntimeServicesTableLib
UefiRuntimeLib
UefiBootServicesTableLib
UefiDriverEntryPoint
IntelQNCLib
QNCAccessLib
TimerLib
DxeServicesTableLib
UefiLib
DebugLib
MemoryAllocationLib
S3BootScriptLib
PciExpressLib
################################################################################
#
# Protocol C Name Section - list of Protocol and Protocol Notify C Names
# that this module uses or produces.
#
################################################################################
[Protocols]
gEfiSpiProtocolGuid
[Pcd]
gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress
gEfiQuarkNcSocIdTokenSpaceGuid.PcdRcbaMmioSize
[Depex]
TRUE

View File

@@ -0,0 +1,56 @@
## @file
# Spi smm driver
#
# Component description file for the SPI SMM driver.
#
# Copyright (c) 2013-2015 Intel Corporation.
#
# This program and the accompanying materials
# 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
# http://opensource.org/licenses/bsd-license.php
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
##
[defines]
INF_VERSION = 0x00010005
BASE_NAME = PchSpiSmm
FILE_GUID = 27F4917B-A707-4aad-9676-26DF168CBF0D
MODULE_TYPE = DXE_SMM_DRIVER
VERSION_STRING = 1.0
PI_SPECIFICATION_VERSION = 0x0001000A
ENTRY_POINT = InstallPchSpi
[Sources]
Smm/PchSpi.h
Smm/PchSpi.c
Common/SpiCommon.c
Common/SpiCommon.h
[Packages]
MdePkg/MdePkg.dec
QuarkSocPkg/QuarkSocPkg.dec
[LibraryClasses]
DebugLib
IoLib
IntelQNCLib
QNCAccessLib
TimerLib
S3BootScriptLib
UefiDriverEntryPoint
UefiBootServicesTableLib
BaseLib
SmmServicesTableLib
[Protocols]
gEfiSmmSpiProtocolGuid # PRODUCES
[Pcd]
gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress
[Depex]
gEfiSmmBase2ProtocolGuid

View File

@@ -0,0 +1,211 @@
/** @file
PCH SPI Runtime Driver implements the SPI Host Controller Compatibility Interface.
Copyright (c) 2013-2015 Intel Corporation.
This program and the accompanying materials
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
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "PchSpi.h"
extern EFI_GUID gEfiEventVirtualAddressChangeGuid;
//
// Global variables
//
SPI_INSTANCE *mSpiInstance;
CONST UINT32 mSpiRegister[] = {
R_QNC_RCRB_SPIS,
R_QNC_RCRB_SPIPREOP,
R_QNC_RCRB_SPIOPMENU,
R_QNC_RCRB_SPIOPMENU + 4
};
//
// Function implementations
//
VOID
PchSpiVirtualddressChangeEvent (
IN EFI_EVENT Event,
IN VOID *Context
)
/*++
Routine Description:
Fixup internal data pointers so that the services can be called in virtual mode.
Arguments:
Event The event registered.
Context Event context. Not used in this event handler.
Returns:
None.
--*/
{
gRT->ConvertPointer (EFI_INTERNAL_POINTER, (VOID *) &(mSpiInstance->PchRootComplexBar));
gRT->ConvertPointer (EFI_INTERNAL_POINTER, (VOID *) &(mSpiInstance->SpiProtocol.Init));
gRT->ConvertPointer (EFI_INTERNAL_POINTER, (VOID *) &(mSpiInstance->SpiProtocol.Lock));
gRT->ConvertPointer (EFI_INTERNAL_POINTER, (VOID *) &(mSpiInstance->SpiProtocol.Execute));
gRT->ConvertPointer (EFI_INTERNAL_POINTER, (VOID *) &(mSpiInstance));
}
EFI_STATUS
EFIAPI
InstallPchSpi (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
/*++
Routine Description:
Entry point for the SPI host controller driver.
Arguments:
ImageHandle Image handle of this driver.
SystemTable Global system service table.
Returns:
EFI_SUCCESS Initialization complete.
EFI_UNSUPPORTED The chipset is unsupported by this driver.
EFI_OUT_OF_RESOURCES Do not have enough resources to initialize the driver.
EFI_DEVICE_ERROR Device error, driver exits abnormally.
--*/
{
EFI_STATUS Status;
UINT64 BaseAddress;
UINT64 Length;
EFI_GCD_MEMORY_SPACE_DESCRIPTOR GcdMemorySpaceDescriptor;
UINT64 Attributes;
EFI_EVENT Event;
DEBUG ((DEBUG_INFO, "InstallPchSpi() Start\n"));
//
// Allocate Runtime memory for the SPI protocol instance.
//
mSpiInstance = AllocateRuntimeZeroPool (sizeof (SPI_INSTANCE));
if (mSpiInstance == NULL) {
return EFI_OUT_OF_RESOURCES;
}
//
// Initialize the SPI protocol instance
//
Status = SpiProtocolConstructor (mSpiInstance);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Install the EFI_SPI_PROTOCOL interface
//
Status = gBS->InstallMultipleProtocolInterfaces (
&(mSpiInstance->Handle),
&gEfiSpiProtocolGuid,
&(mSpiInstance->SpiProtocol),
NULL
);
if (EFI_ERROR (Status)) {
FreePool (mSpiInstance);
return EFI_DEVICE_ERROR;
}
//
// Set RCBA space in GCD to be RUNTIME so that the range will be supported in
// virtual address mode in EFI aware OS runtime.
// It will assert if RCBA Memory Space is not allocated
// The caller is responsible for the existence and allocation of the RCBA Memory Spaces
//
BaseAddress = (EFI_PHYSICAL_ADDRESS) (mSpiInstance->PchRootComplexBar);
Length = PcdGet64 (PcdRcbaMmioSize);
Status = gDS->GetMemorySpaceDescriptor (BaseAddress, &GcdMemorySpaceDescriptor);
ASSERT_EFI_ERROR (Status);
Attributes = GcdMemorySpaceDescriptor.Attributes | EFI_MEMORY_RUNTIME;
Status = gDS->AddMemorySpace (
EfiGcdMemoryTypeMemoryMappedIo,
BaseAddress,
Length,
EFI_MEMORY_RUNTIME | EFI_MEMORY_UC
);
ASSERT_EFI_ERROR(Status);
Status = gDS->SetMemorySpaceAttributes (
BaseAddress,
Length,
Attributes
);
ASSERT_EFI_ERROR (Status);
Status = gBS->CreateEventEx (
EVT_NOTIFY_SIGNAL,
TPL_NOTIFY,
PchSpiVirtualddressChangeEvent,
NULL,
&gEfiEventVirtualAddressChangeGuid,
&Event
);
ASSERT_EFI_ERROR (Status);
DEBUG ((DEBUG_INFO, "InstallPchSpi() End\n"));
return EFI_SUCCESS;
}
VOID
EFIAPI
SpiPhaseInit (
VOID
)
/*++
Routine Description:
This function is a a hook for Spi Dxe phase specific initialization
Arguments:
None
Returns:
None
--*/
{
UINTN Index;
//
// Disable SMM BIOS write protect if it's not a SMM protocol
//
MmioAnd8 (
PciDeviceMmBase (PCI_BUS_NUMBER_QNC,
PCI_DEVICE_NUMBER_QNC_LPC,
PCI_FUNCTION_NUMBER_QNC_LPC) + R_QNC_LPC_BIOS_CNTL,
(UINT8) (~B_QNC_LPC_BIOS_CNTL_SMM_BWP)
);
//
// Save SPI Registers for S3 resume usage
//
for (Index = 0; Index < sizeof (mSpiRegister) / sizeof (UINT32); Index++) {
S3BootScriptSaveMemWrite (
S3BootScriptWidthUint32,
(UINTN) (mSpiInstance->PchRootComplexBar + mSpiRegister[Index]),
1,
(VOID *) (UINTN) (mSpiInstance->PchRootComplexBar + mSpiRegister[Index])
);
}
}

View File

@@ -0,0 +1,85 @@
/** @file
Header file for the PCH SPI Runtime Driver.
Copyright (c) 2013-2015 Intel Corporation.
This program and the accompanying materials
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
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef _PCH_SPI_H_
#define _PCH_SPI_H_
#include <Library/PcdLib.h>
#include <Library/UefiLib.h>
#include <Library/DebugLib.h>
#include <Library/UefiRuntimeLib.h>
#include <Library/S3BootScriptLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/DxeServicesTableLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Protocol/Spi.h>
#include "SpiCommon.h"
#include <Library/PciExpressLib.h>
#include <IntelQNCRegs.h>
#include <Library/IntelQNCLib.h>
#include <Library/QNCAccessLib.h>
#include <Library/TimerLib.h>
#define EFI_INTERNAL_POINTER 0x00000004
//
// Function prototypes used by the SPI protocol.
//
VOID
PchSpiVirtualddressChangeEvent (
IN EFI_EVENT Event,
IN VOID *Context
)
/*++
Routine Description:
Fixup internal data pointers so that the services can be called in virtual mode.
Arguments:
Event The event registered.
Context Event context. Not used in this event handler.
Returns:
None.
--*/
;
VOID
EFIAPI
SpiPhaseInit (
VOID
)
/*++
Routine Description:
This function is a hook for Spi Dxe phase specific initialization
Arguments:
None
Returns:
None
--*/
;
#endif

View File

@@ -0,0 +1,129 @@
/** @file
PCH SPI SMM Driver implements the SPI Host Controller Compatibility Interface.
Copyright (c) 2013-2015 Intel Corporation.
This program and the accompanying materials
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
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "PchSpi.h"
SPI_INSTANCE *mSpiInstance;
CONST UINT32 mSpiRegister[] = {
R_QNC_RCRB_SPIS,
R_QNC_RCRB_SPIPREOP,
R_QNC_RCRB_SPIOPMENU,
R_QNC_RCRB_SPIOPMENU + 4
};
EFI_STATUS
EFIAPI
InstallPchSpi (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
/*++
Routine Description:
Entry point for the SPI host controller driver.
Arguments:
ImageHandle Image handle of this driver.
SystemTable Global system service table.
Returns:
EFI_SUCCESS Initialization complete.
EFI_UNSUPPORTED The chipset is unsupported by this driver.
EFI_OUT_OF_RESOURCES Do not have enough resources to initialize the driver.
EFI_DEVICE_ERROR Device error, driver exits abnormally.
--*/
{
EFI_STATUS Status;
//
// Allocate pool for SPI protocol instance
//
Status = gSmst->SmmAllocatePool (
EfiRuntimeServicesData, // MemoryType don't care
sizeof (SPI_INSTANCE),
(VOID **) &mSpiInstance
);
if (EFI_ERROR (Status)) {
return Status;
}
if (mSpiInstance == NULL) {
return EFI_OUT_OF_RESOURCES;
}
ZeroMem ((VOID *) mSpiInstance, sizeof (SPI_INSTANCE));
//
// Initialize the SPI protocol instance
//
Status = SpiProtocolConstructor (mSpiInstance);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Install the SMM EFI_SPI_PROTOCOL interface
//
Status = gSmst->SmmInstallProtocolInterface (
&(mSpiInstance->Handle),
&gEfiSmmSpiProtocolGuid,
EFI_NATIVE_INTERFACE,
&(mSpiInstance->SpiProtocol)
);
if (EFI_ERROR (Status)) {
gSmst->SmmFreePool (mSpiInstance);
return EFI_DEVICE_ERROR;
}
return EFI_SUCCESS;
}
VOID
EFIAPI
SpiPhaseInit (
VOID
)
/*++
Routine Description:
This function is a a hook for Spi Smm phase specific initialization
Arguments:
None
Returns:
None
--*/
{
UINTN Index;
//
// Save SPI Registers for S3 resume usage
//
for (Index = 0; Index < sizeof (mSpiRegister) / sizeof (UINT32); Index++) {
S3BootScriptSaveMemWrite (
S3BootScriptWidthUint32,
(UINTN) (mSpiInstance->PchRootComplexBar + mSpiRegister[Index]),
1,
(VOID *) (UINTN) (mSpiInstance->PchRootComplexBar + mSpiRegister[Index])
);
}
}

View File

@@ -0,0 +1,53 @@
/** @file
Header file for the PCH SPI SMM Driver.
Copyright (c) 2013-2015 Intel Corporation.
This program and the accompanying materials
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
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef _PCH_SPI_H_
#define _PCH_SPI_H_
#include <Library/IoLib.h>
#include <Library/DebugLib.h>
#include <Library/S3BootScriptLib.h>
#include <Library/UefiDriverEntryPoint.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/BaseLib.h>
#include <Protocol/Spi.h>
#include "SpiCommon.h"
#include <Library/SmmServicesTableLib.h>
#include <IntelQNCRegs.h>
#include <Library/IntelQNCLib.h>
#include <Library/QNCAccessLib.h>
#include <Library/TimerLib.h>
VOID
EFIAPI
SpiPhaseInit (
VOID
)
/*++
Routine Description:
This function is a hook for Spi Smm phase specific initialization
Arguments:
None
Returns:
None
--*/
;
#endif