2 PCH SPI Runtime Driver implements the SPI Host Controller Compatibility Interface.
4 Copyright (c) 2013-2015 Intel Corporation.
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 extern EFI_GUID gEfiEventVirtualAddressChangeGuid
;
22 SPI_INSTANCE
*mSpiInstance
;
23 CONST UINT32 mSpiRegister
[] = {
27 R_QNC_RCRB_SPIOPMENU
+ 4
31 // Function implementations
34 PchSpiVirtualddressChangeEvent (
42 Fixup internal data pointers so that the services can be called in virtual mode.
46 Event The event registered.
47 Context Event context. Not used in this event handler.
55 gRT
->ConvertPointer (EFI_INTERNAL_POINTER
, (VOID
*) &(mSpiInstance
->PchRootComplexBar
));
56 gRT
->ConvertPointer (EFI_INTERNAL_POINTER
, (VOID
*) &(mSpiInstance
->SpiProtocol
.Init
));
57 gRT
->ConvertPointer (EFI_INTERNAL_POINTER
, (VOID
*) &(mSpiInstance
->SpiProtocol
.Lock
));
58 gRT
->ConvertPointer (EFI_INTERNAL_POINTER
, (VOID
*) &(mSpiInstance
->SpiProtocol
.Execute
));
59 gRT
->ConvertPointer (EFI_INTERNAL_POINTER
, (VOID
*) &(mSpiInstance
));
65 IN EFI_HANDLE ImageHandle
,
66 IN EFI_SYSTEM_TABLE
*SystemTable
72 Entry point for the SPI host controller driver.
76 ImageHandle Image handle of this driver.
77 SystemTable Global system service table.
81 EFI_SUCCESS Initialization complete.
82 EFI_UNSUPPORTED The chipset is unsupported by this driver.
83 EFI_OUT_OF_RESOURCES Do not have enough resources to initialize the driver.
84 EFI_DEVICE_ERROR Device error, driver exits abnormally.
91 EFI_GCD_MEMORY_SPACE_DESCRIPTOR GcdMemorySpaceDescriptor
;
95 DEBUG ((DEBUG_INFO
, "InstallPchSpi() Start\n"));
98 // Allocate Runtime memory for the SPI protocol instance.
100 mSpiInstance
= AllocateRuntimeZeroPool (sizeof (SPI_INSTANCE
));
101 if (mSpiInstance
== NULL
) {
102 return EFI_OUT_OF_RESOURCES
;
105 // Initialize the SPI protocol instance
107 Status
= SpiProtocolConstructor (mSpiInstance
);
108 if (EFI_ERROR (Status
)) {
112 // Install the EFI_SPI_PROTOCOL interface
114 Status
= gBS
->InstallMultipleProtocolInterfaces (
115 &(mSpiInstance
->Handle
),
116 &gEfiSpiProtocolGuid
,
117 &(mSpiInstance
->SpiProtocol
),
120 if (EFI_ERROR (Status
)) {
121 FreePool (mSpiInstance
);
122 return EFI_DEVICE_ERROR
;
125 // Set RCBA space in GCD to be RUNTIME so that the range will be supported in
126 // virtual address mode in EFI aware OS runtime.
127 // It will assert if RCBA Memory Space is not allocated
128 // The caller is responsible for the existence and allocation of the RCBA Memory Spaces
130 BaseAddress
= (EFI_PHYSICAL_ADDRESS
) (mSpiInstance
->PchRootComplexBar
);
131 Length
= PcdGet64 (PcdRcbaMmioSize
);
133 Status
= gDS
->GetMemorySpaceDescriptor (BaseAddress
, &GcdMemorySpaceDescriptor
);
134 ASSERT_EFI_ERROR (Status
);
136 Attributes
= GcdMemorySpaceDescriptor
.Attributes
| EFI_MEMORY_RUNTIME
;
138 Status
= gDS
->AddMemorySpace (
139 EfiGcdMemoryTypeMemoryMappedIo
,
142 EFI_MEMORY_RUNTIME
| EFI_MEMORY_UC
144 ASSERT_EFI_ERROR(Status
);
146 Status
= gDS
->SetMemorySpaceAttributes (
151 ASSERT_EFI_ERROR (Status
);
153 Status
= gBS
->CreateEventEx (
156 PchSpiVirtualddressChangeEvent
,
158 &gEfiEventVirtualAddressChangeGuid
,
161 ASSERT_EFI_ERROR (Status
);
163 DEBUG ((DEBUG_INFO
, "InstallPchSpi() End\n"));
176 This function is a a hook for Spi Dxe phase specific initialization
191 // Disable SMM BIOS write protect if it's not a SMM protocol
194 PciDeviceMmBase (PCI_BUS_NUMBER_QNC
,
195 PCI_DEVICE_NUMBER_QNC_LPC
,
196 PCI_FUNCTION_NUMBER_QNC_LPC
) + R_QNC_LPC_BIOS_CNTL
,
197 (UINT8
) (~B_QNC_LPC_BIOS_CNTL_SMM_BWP
)
201 // Save SPI Registers for S3 resume usage
203 for (Index
= 0; Index
< sizeof (mSpiRegister
) / sizeof (UINT32
); Index
++) {
204 S3BootScriptSaveMemWrite (
205 S3BootScriptWidthUint32
,
206 (UINTN
) (mSpiInstance
->PchRootComplexBar
+ mSpiRegister
[Index
]),
208 (VOID
*) (UINTN
) (mSpiInstance
->PchRootComplexBar
+ mSpiRegister
[Index
])