]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkModulePkg/Universal/PcatSingleSegmentPciCfgPei/PciCfg2.c
1) Add PcatSingleSegmentPciCfg2Pei in MdeModulePkg.
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / PcatSingleSegmentPciCfgPei / PciCfg2.c
CommitLineData
12232778 1/**\r
2\r
3 Copyright (c) 2006 - 2007, Intel Corporation\r
4 All rights reserved. This program and the accompanying materials\r
5 are licensed and made available under the terms and conditions of the BSD License\r
6 which accompanies this distribution. The full text of the license may be found at\r
7 http://opensource.org/licenses/bsd-license.php\r
8\r
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11\r
12**/\r
13\r
14#include "PciCfgInternal.h"\r
15\r
16/**\r
17 @par Ppi Description:\r
18 The EFI_PEI_PCI_CFG2_PPI interfaces are used to abstract\r
19 accesses to PCI controllers behind a PCI root bridge\r
20 controller.\r
21\r
22 @param Read PCI read services. See the Read() function description.\r
23\r
24 @param Write PCI write services. See the Write() function description.\r
25\r
26 @param Modify PCI read-modify-write services. See the Modify() function description.\r
27\r
28 @param Segment The PCI bus segment which the specified functions will access.\r
29\r
30**/\r
31GLOBAL_REMOVE_IF_UNREFERENCED\r
32EFI_PEI_PCI_CFG2_PPI gPciCfg2Ppi = {\r
33 PciCfg2Read,\r
34 PciCfg2Write,\r
35 PciCfg2Modify\r
36};\r
37\r
38GLOBAL_REMOVE_IF_UNREFERENCED\r
39EFI_PEI_PPI_DESCRIPTOR gPciCfg2PpiList = {\r
40 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
41 &gEfiPciCfg2PpiGuid,\r
42 &gPciCfg2Ppi\r
43};\r
44\r
45\r
46/**\r
47 @par Ppi Description:\r
48 The EFI_PEI_PCI_CFG_PPI interfaces are used to abstract accesses to PCI\r
49 controllers behind a PCI root bridge controller.\r
50\r
51 @param Read PCI read services. See the Read() function description.\r
52\r
53 @param Write PCI write services. See the Write() function description.\r
54\r
55 @param Modify PCI read-modify-write services. See the Modify() function description.\r
56\r
57 @param Segment The PCI bus segment which the specified functions will access.\r
58\r
59**/\r
60GLOBAL_REMOVE_IF_UNREFERENCED\r
61EFI_PEI_PCI_CFG_PPI gPciCfgPpi = {\r
62 PciCfgRead,\r
63 PciCfgWrite,\r
64 PciCfgModify\r
65};\r
66\r
67GLOBAL_REMOVE_IF_UNREFERENCED\r
68EFI_PEI_PPI_DESCRIPTOR gPciCfgPpiList = {\r
69 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
70 &gEfiPciCfgPpiInServiceTableGuid,\r
71 &gPciCfgPpi\r
72};\r
73\r
74/**\r
75 Reads from a given location in the PCI configuration space.\r
76\r
77 @param PeiServices An indirect pointer to the PEI Services Table published by the PEI Foundation.\r
78\r
79 @param This Pointer to local data for the interface.\r
80\r
81 @param Width The width of the access. Enumerated in bytes.\r
82 See EFI_PEI_PCI_CFG_PPI_WIDTH above.\r
83\r
84 @param Address The physical address of the access. The format of\r
85 the address is described by EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS.\r
86\r
87 @param Buffer A pointer to the buffer of data..\r
88\r
89\r
90 @retval EFI_SUCCESS The function completed successfully.\r
91\r
92 @retval EFI_DEVICE_ERROR There was a problem with the transaction.\r
93\r
94 @retval EFI_DEVICE_NOT_READY The device is not capable of supporting the operation at this\r
95 time.\r
96\r
97**/\r
98EFI_STATUS\r
99EFIAPI \r
100PciCfg2Read (\r
101 IN CONST EFI_PEI_SERVICES **PeiServices,\r
102 IN CONST EFI_PEI_PCI_CFG2_PPI *This,\r
103 IN EFI_PEI_PCI_CFG_PPI_WIDTH Width,\r
104 IN UINT64 Address,\r
105 IN OUT VOID *Buffer\r
106)\r
107{\r
108 UINTN PciLibAddress;\r
109\r
110 PciLibAddress = COMMON_TO_PCILIB_ADDRESS (Address);\r
111\r
112 if (Width == EfiPeiPciCfgWidthUint8) {\r
113 *((UINT8 *) Buffer) = PciRead8 (PciLibAddress);\r
114 } else if (Width == EfiPeiPciCfgWidthUint16) {\r
115 *((UINT16 *) Buffer) = PciRead16 (PciLibAddress);\r
116 } else if (Width == EfiPeiPciCfgWidthUint32) {\r
117 *((UINT32 *) Buffer) = PciRead32 (PciLibAddress);\r
118 } else {\r
119 return EFI_INVALID_PARAMETER;\r
120 }\r
121\r
122 return EFI_SUCCESS;\r
123}\r
124\r
125/**\r
126 Write to a given location in the PCI configuration space.\r
127\r
128 @param PeiServices An indirect pointer to the PEI Services Table published by the PEI Foundation.\r
129\r
130 @param This Pointer to local data for the interface.\r
131\r
132 @param Width The width of the access. Enumerated in bytes.\r
133 See EFI_PEI_PCI_CFG_PPI_WIDTH above.\r
134\r
135 @param Address The physical address of the access. The format of\r
136 the address is described by EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS.\r
137\r
138 @param Buffer A pointer to the buffer of data..\r
139\r
140\r
141 @retval EFI_SUCCESS The function completed successfully.\r
142\r
143 @retval EFI_DEVICE_ERROR There was a problem with the transaction.\r
144\r
145 @retval EFI_DEVICE_NOT_READY The device is not capable of supporting the operation at this\r
146 time.\r
147\r
148**/\r
149EFI_STATUS\r
150EFIAPI \r
151PciCfg2Write (\r
152 IN CONST EFI_PEI_SERVICES **PeiServices,\r
153 IN CONST EFI_PEI_PCI_CFG2_PPI *This,\r
154 IN EFI_PEI_PCI_CFG_PPI_WIDTH Width,\r
155 IN UINT64 Address,\r
156 IN OUT VOID *Buffer\r
157)\r
158{\r
159 UINTN PciLibAddress;\r
160\r
161 PciLibAddress = COMMON_TO_PCILIB_ADDRESS (Address);\r
162\r
163 if (Width == EfiPeiPciCfgWidthUint8) {\r
164 PciWrite8 (PciLibAddress, *((UINT8 *) Buffer));\r
165 } else if (Width == EfiPeiPciCfgWidthUint16) {\r
166 PciWrite16 (PciLibAddress, *((UINT16 *) Buffer));\r
167 } else if (Width == EfiPeiPciCfgWidthUint32) {\r
168 PciWrite32 (PciLibAddress, *((UINT32 *) Buffer));\r
169 } else {\r
170 return EFI_INVALID_PARAMETER;\r
171 }\r
172\r
173 return EFI_SUCCESS;\r
174}\r
175\r
176\r
177/**\r
178 PCI read-modify-write operation.\r
179\r
180 @param PeiServices An indirect pointer to the PEI Services Table\r
181 published by the PEI Foundation.\r
182\r
183 @param This Pointer to local data for the interface.\r
184\r
185 @param Width The width of the access. Enumerated in bytes. Type\r
186 EFI_PEI_PCI_CFG_PPI_WIDTH is defined in Read().\r
187\r
188 @param Address The physical address of the access.\r
189\r
190 @param SetBits Points to value to bitwise-OR with the read configuration value.\r
191\r
192 The size of the value is determined by Width.\r
193\r
194 @param ClearBits Points to the value to negate and bitwise-AND with the read configuration value.\r
195 The size of the value is determined by Width.\r
196\r
197\r
198 @retval EFI_SUCCESS The function completed successfully.\r
199\r
200 @retval EFI_DEVICE_ERROR There was a problem with the transaction.\r
201\r
202 @retval EFI_DEVICE_NOT_READY The device is not capable of supporting\r
203 the operation at this time.\r
204\r
205**/\r
206EFI_STATUS\r
207EFIAPI \r
208PciCfg2Modify (\r
209 IN CONST EFI_PEI_SERVICES **PeiServices,\r
210 IN CONST EFI_PEI_PCI_CFG2_PPI *This,\r
211 IN EFI_PEI_PCI_CFG_PPI_WIDTH Width,\r
212 IN UINT64 Address,\r
213 IN CONST VOID *SetBits,\r
214 IN CONST VOID *ClearBits\r
215)\r
216{\r
217 UINTN PciLibAddress;\r
218\r
219 PciLibAddress = COMMON_TO_PCILIB_ADDRESS (Address);\r
220\r
221 if (Width == EfiPeiPciCfgWidthUint8) {\r
222 PciAndThenOr8 (PciLibAddress, ~(*(UINT8 *)ClearBits), *((UINT8 *) SetBits));\r
223 } else if (Width == EfiPeiPciCfgWidthUint16) {\r
224 PciAndThenOr16 (PciLibAddress, ~ReadUnaligned16 ((UINT16 *) ClearBits), ReadUnaligned16 ((UINT16 *) SetBits));\r
225 } else if (Width == EfiPeiPciCfgWidthUint32) {\r
226 PciAndThenOr32 (PciLibAddress, ~ReadUnaligned32 ((UINT32 *) ClearBits), ReadUnaligned32 ((UINT32 *) SetBits));\r
227 } else {\r
228 return EFI_INVALID_PARAMETER;\r
229 }\r
230 return EFI_SUCCESS;\r
231}\r
232\r
233\r
234EFI_STATUS\r
235EFIAPI\r
236PeimInitializePciCfg (\r
237 IN EFI_FFS_FILE_HEADER *FfsHeader,\r
238 IN EFI_PEI_SERVICES **PeiServices\r
239 )\r
240{\r
241 EFI_STATUS Status;\r
242\r
243 Status = EFI_SUCCESS;\r
244\r
245 if ((**PeiServices).Hdr.Revision < PEI_SERVICES_REVISION) {\r
246 //\r
247 // BugBug: Curently, the FrameworkPkg does not define\r
248 // FRAMEWORK_PEI_SERVICES. So, In order to install \r
249 // the PeiServices.PciCfg(), we casttype \r
250 // EFI_PEI_PCI_CFG_PPI to EFI_PEI_PCI_CFG2_PPI.\r
251 // After defining the FRAMEWORK_PEI_SERVICES. this should\r
252 // be updated as:\r
253 // \r
254 // FrameworkPeiServices = (FRAMEWORK_PEI_SERVICES **) PeiServices;\r
255 // (**FrameworkPeiServices).PciCfg = &mPciCfgPpi;\r
256 // \r
257 (**PeiServices).PciCfg = (EFI_PEI_PCI_CFG2_PPI *) &gPciCfgPpi;\r
258 } else {\r
259 (**PeiServices).PciCfg = &gPciCfg2Ppi;\r
260 }\r
261 \r
262 if (!FeaturePcdGet (PcdPciCfgDisable)) {\r
263 Status = (**PeiServices).InstallPpi (PeiServices, &gPciCfgPpiList);\r
264 } \r
265 if (!FeaturePcdGet (PcdPciCfg2Disable)) {\r
266 Status = (**PeiServices).InstallPpi (PeiServices, &gPciCfg2PpiList);\r
267 }\r
268\r
269 return Status;\r
270}\r