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