2 PCH SPI Runtime Driver implements the SPI Host Controller Compatibility Interface.
4 Copyright (c) 2013-2015 Intel Corporation.
6 SPDX-License-Identifier: BSD-2-Clause-Patent
11 extern EFI_GUID gEfiEventVirtualAddressChangeGuid
;
16 SPI_INSTANCE
*mSpiInstance
;
17 CONST UINT32 mSpiRegister
[] = {
21 R_QNC_RCRB_SPIOPMENU
+ 4
25 // Function implementations
28 PchSpiVirtualddressChangeEvent (
36 Fixup internal data pointers so that the services can be called in virtual mode.
40 Event The event registered.
41 Context Event context. Not used in this event handler.
49 gRT
->ConvertPointer (EFI_INTERNAL_POINTER
, (VOID
*) &(mSpiInstance
->PchRootComplexBar
));
50 gRT
->ConvertPointer (EFI_INTERNAL_POINTER
, (VOID
*) &(mSpiInstance
->SpiProtocol
.Init
));
51 gRT
->ConvertPointer (EFI_INTERNAL_POINTER
, (VOID
*) &(mSpiInstance
->SpiProtocol
.Lock
));
52 gRT
->ConvertPointer (EFI_INTERNAL_POINTER
, (VOID
*) &(mSpiInstance
->SpiProtocol
.Execute
));
53 gRT
->ConvertPointer (EFI_INTERNAL_POINTER
, (VOID
*) &(mSpiInstance
));
59 IN EFI_HANDLE ImageHandle
,
60 IN EFI_SYSTEM_TABLE
*SystemTable
66 Entry point for the SPI host controller driver.
70 ImageHandle Image handle of this driver.
71 SystemTable Global system service table.
75 EFI_SUCCESS Initialization complete.
76 EFI_UNSUPPORTED The chipset is unsupported by this driver.
77 EFI_OUT_OF_RESOURCES Do not have enough resources to initialize the driver.
78 EFI_DEVICE_ERROR Device error, driver exits abnormally.
85 EFI_GCD_MEMORY_SPACE_DESCRIPTOR GcdMemorySpaceDescriptor
;
89 DEBUG ((DEBUG_INFO
, "InstallPchSpi() Start\n"));
92 // Allocate Runtime memory for the SPI protocol instance.
94 mSpiInstance
= AllocateRuntimeZeroPool (sizeof (SPI_INSTANCE
));
95 if (mSpiInstance
== NULL
) {
96 return EFI_OUT_OF_RESOURCES
;
99 // Initialize the SPI protocol instance
101 Status
= SpiProtocolConstructor (mSpiInstance
);
102 if (EFI_ERROR (Status
)) {
106 // Install the EFI_SPI_PROTOCOL interface
108 Status
= gBS
->InstallMultipleProtocolInterfaces (
109 &(mSpiInstance
->Handle
),
110 &gEfiSpiProtocolGuid
,
111 &(mSpiInstance
->SpiProtocol
),
114 if (EFI_ERROR (Status
)) {
115 FreePool (mSpiInstance
);
116 return EFI_DEVICE_ERROR
;
119 // Set RCBA space in GCD to be RUNTIME so that the range will be supported in
120 // virtual address mode in EFI aware OS runtime.
121 // It will assert if RCBA Memory Space is not allocated
122 // The caller is responsible for the existence and allocation of the RCBA Memory Spaces
124 BaseAddress
= (EFI_PHYSICAL_ADDRESS
) (mSpiInstance
->PchRootComplexBar
);
125 Length
= PcdGet64 (PcdRcbaMmioSize
);
127 Status
= gDS
->GetMemorySpaceDescriptor (BaseAddress
, &GcdMemorySpaceDescriptor
);
128 ASSERT_EFI_ERROR (Status
);
130 Attributes
= GcdMemorySpaceDescriptor
.Attributes
| EFI_MEMORY_RUNTIME
;
132 Status
= gDS
->AddMemorySpace (
133 EfiGcdMemoryTypeMemoryMappedIo
,
136 EFI_MEMORY_RUNTIME
| EFI_MEMORY_UC
138 ASSERT_EFI_ERROR(Status
);
140 Status
= gDS
->SetMemorySpaceAttributes (
145 ASSERT_EFI_ERROR (Status
);
147 Status
= gBS
->CreateEventEx (
150 PchSpiVirtualddressChangeEvent
,
152 &gEfiEventVirtualAddressChangeGuid
,
155 ASSERT_EFI_ERROR (Status
);
157 DEBUG ((DEBUG_INFO
, "InstallPchSpi() End\n"));
170 This function is a a hook for Spi Dxe phase specific initialization
185 // Disable SMM BIOS write protect if it's not a SMM protocol
188 PciDeviceMmBase (PCI_BUS_NUMBER_QNC
,
189 PCI_DEVICE_NUMBER_QNC_LPC
,
190 PCI_FUNCTION_NUMBER_QNC_LPC
) + R_QNC_LPC_BIOS_CNTL
,
191 (UINT8
) (~B_QNC_LPC_BIOS_CNTL_SMM_BWP
)
195 // Save SPI Registers for S3 resume usage
197 for (Index
= 0; Index
< sizeof (mSpiRegister
) / sizeof (UINT32
); Index
++) {
198 S3BootScriptSaveMemWrite (
199 S3BootScriptWidthUint32
,
200 (UINTN
) (mSpiInstance
->PchRootComplexBar
+ mSpiRegister
[Index
]),
202 (VOID
*) (UINTN
) (mSpiInstance
->PchRootComplexBar
+ mSpiRegister
[Index
])