]> git.proxmox.com Git - mirror_edk2.git/blame - QuarkSocPkg/QuarkNorthCluster/Spi/RuntimeDxe/PchSpi.c
QuarkSocPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / QuarkSocPkg / QuarkNorthCluster / Spi / RuntimeDxe / PchSpi.c
CommitLineData
9b6bbcdb
MK
1/** @file\r
2PCH SPI Runtime Driver implements the SPI Host Controller Compatibility Interface.\r
3\r
4Copyright (c) 2013-2015 Intel Corporation.\r
5\r
c9f231d0 6SPDX-License-Identifier: BSD-2-Clause-Patent\r
9b6bbcdb
MK
7\r
8**/\r
9#include "PchSpi.h"\r
10\r
11extern EFI_GUID gEfiEventVirtualAddressChangeGuid;\r
12\r
13//\r
14// Global variables\r
15//\r
16SPI_INSTANCE *mSpiInstance;\r
17CONST UINT32 mSpiRegister[] = {\r
18 R_QNC_RCRB_SPIS,\r
19 R_QNC_RCRB_SPIPREOP,\r
20 R_QNC_RCRB_SPIOPMENU,\r
21 R_QNC_RCRB_SPIOPMENU + 4\r
22 };\r
23\r
24//\r
25// Function implementations\r
26//\r
27VOID\r
28PchSpiVirtualddressChangeEvent (\r
29 IN EFI_EVENT Event,\r
30 IN VOID *Context\r
31 )\r
32/*++\r
33\r
34Routine Description:\r
35\r
36 Fixup internal data pointers so that the services can be called in virtual mode.\r
37\r
38Arguments:\r
39\r
40 Event The event registered.\r
41 Context Event context. Not used in this event handler.\r
42\r
43Returns:\r
44\r
45 None.\r
46\r
47--*/\r
48{\r
49 gRT->ConvertPointer (EFI_INTERNAL_POINTER, (VOID *) &(mSpiInstance->PchRootComplexBar));\r
50 gRT->ConvertPointer (EFI_INTERNAL_POINTER, (VOID *) &(mSpiInstance->SpiProtocol.Init));\r
51 gRT->ConvertPointer (EFI_INTERNAL_POINTER, (VOID *) &(mSpiInstance->SpiProtocol.Lock));\r
52 gRT->ConvertPointer (EFI_INTERNAL_POINTER, (VOID *) &(mSpiInstance->SpiProtocol.Execute));\r
53 gRT->ConvertPointer (EFI_INTERNAL_POINTER, (VOID *) &(mSpiInstance));\r
54}\r
55\r
56EFI_STATUS\r
57EFIAPI\r
58InstallPchSpi (\r
59 IN EFI_HANDLE ImageHandle,\r
60 IN EFI_SYSTEM_TABLE *SystemTable\r
61 )\r
62/*++\r
63\r
64Routine Description:\r
65\r
66 Entry point for the SPI host controller driver.\r
67\r
68Arguments:\r
69\r
70 ImageHandle Image handle of this driver.\r
71 SystemTable Global system service table.\r
72\r
73Returns:\r
74\r
75 EFI_SUCCESS Initialization complete.\r
76 EFI_UNSUPPORTED The chipset is unsupported by this driver.\r
77 EFI_OUT_OF_RESOURCES Do not have enough resources to initialize the driver.\r
78 EFI_DEVICE_ERROR Device error, driver exits abnormally.\r
79\r
80--*/\r
81{\r
82 EFI_STATUS Status;\r
83 UINT64 BaseAddress;\r
84 UINT64 Length;\r
85 EFI_GCD_MEMORY_SPACE_DESCRIPTOR GcdMemorySpaceDescriptor;\r
86 UINT64 Attributes;\r
87 EFI_EVENT Event;\r
88\r
89 DEBUG ((DEBUG_INFO, "InstallPchSpi() Start\n"));\r
90\r
91 //\r
92 // Allocate Runtime memory for the SPI protocol instance.\r
93 //\r
94 mSpiInstance = AllocateRuntimeZeroPool (sizeof (SPI_INSTANCE));\r
95 if (mSpiInstance == NULL) {\r
96 return EFI_OUT_OF_RESOURCES;\r
97 }\r
98 //\r
99 // Initialize the SPI protocol instance\r
100 //\r
101 Status = SpiProtocolConstructor (mSpiInstance);\r
102 if (EFI_ERROR (Status)) {\r
103 return Status;\r
104 }\r
105 //\r
106 // Install the EFI_SPI_PROTOCOL interface\r
107 //\r
108 Status = gBS->InstallMultipleProtocolInterfaces (\r
109 &(mSpiInstance->Handle),\r
110 &gEfiSpiProtocolGuid,\r
111 &(mSpiInstance->SpiProtocol),\r
112 NULL\r
113 );\r
114 if (EFI_ERROR (Status)) {\r
115 FreePool (mSpiInstance);\r
116 return EFI_DEVICE_ERROR;\r
117 }\r
118 //\r
119 // Set RCBA space in GCD to be RUNTIME so that the range will be supported in\r
120 // virtual address mode in EFI aware OS runtime.\r
121 // It will assert if RCBA Memory Space is not allocated\r
122 // The caller is responsible for the existence and allocation of the RCBA Memory Spaces\r
123 //\r
124 BaseAddress = (EFI_PHYSICAL_ADDRESS) (mSpiInstance->PchRootComplexBar);\r
125 Length = PcdGet64 (PcdRcbaMmioSize);\r
126\r
127 Status = gDS->GetMemorySpaceDescriptor (BaseAddress, &GcdMemorySpaceDescriptor);\r
128 ASSERT_EFI_ERROR (Status);\r
129\r
130 Attributes = GcdMemorySpaceDescriptor.Attributes | EFI_MEMORY_RUNTIME;\r
131\r
132 Status = gDS->AddMemorySpace (\r
133 EfiGcdMemoryTypeMemoryMappedIo,\r
134 BaseAddress,\r
135 Length,\r
136 EFI_MEMORY_RUNTIME | EFI_MEMORY_UC\r
137 );\r
138 ASSERT_EFI_ERROR(Status);\r
139\r
140 Status = gDS->SetMemorySpaceAttributes (\r
141 BaseAddress,\r
142 Length,\r
143 Attributes\r
144 );\r
145 ASSERT_EFI_ERROR (Status);\r
146\r
147 Status = gBS->CreateEventEx (\r
148 EVT_NOTIFY_SIGNAL,\r
149 TPL_NOTIFY,\r
150 PchSpiVirtualddressChangeEvent,\r
151 NULL,\r
152 &gEfiEventVirtualAddressChangeGuid,\r
153 &Event\r
154 );\r
155 ASSERT_EFI_ERROR (Status);\r
156\r
157 DEBUG ((DEBUG_INFO, "InstallPchSpi() End\n"));\r
158\r
159 return EFI_SUCCESS;\r
160}\r
161\r
162VOID\r
163EFIAPI\r
164SpiPhaseInit (\r
165 VOID\r
166 )\r
167/*++\r
168Routine Description:\r
169\r
170 This function is a a hook for Spi Dxe phase specific initialization\r
171\r
172Arguments:\r
173\r
174 None\r
175\r
176Returns:\r
177\r
178 None\r
179\r
180--*/\r
181{\r
182 UINTN Index;\r
183\r
184 //\r
185 // Disable SMM BIOS write protect if it's not a SMM protocol\r
186 //\r
187 MmioAnd8 (\r
188 PciDeviceMmBase (PCI_BUS_NUMBER_QNC,\r
189 PCI_DEVICE_NUMBER_QNC_LPC,\r
190 PCI_FUNCTION_NUMBER_QNC_LPC) + R_QNC_LPC_BIOS_CNTL,\r
191 (UINT8) (~B_QNC_LPC_BIOS_CNTL_SMM_BWP)\r
192 );\r
193\r
194 //\r
195 // Save SPI Registers for S3 resume usage\r
196 //\r
197 for (Index = 0; Index < sizeof (mSpiRegister) / sizeof (UINT32); Index++) {\r
198 S3BootScriptSaveMemWrite (\r
199 S3BootScriptWidthUint32,\r
200 (UINTN) (mSpiInstance->PchRootComplexBar + mSpiRegister[Index]),\r
201 1,\r
202 (VOID *) (UINTN) (mSpiInstance->PchRootComplexBar + mSpiRegister[Index])\r
203 );\r
204 }\r
205}\r