]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - IntelFrameworkModulePkg/Library/PciIncompatibleDeviceSupportLib/PciIncompatibleDeviceSupportLib.c
Code scrub for PCI Bus module and PciIncompatibleDeviceSupportLib module.
[mirror_edk2.git] / IntelFrameworkModulePkg / Library / PciIncompatibleDeviceSupportLib / PciIncompatibleDeviceSupportLib.c
... / ...
CommitLineData
1/** @file\r
2 The template of PCI incompatible device support libary.\r
3\r
4Copyright (c) 2006 - 2009, Intel Corporation\r
5All rights reserved. This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include "IncompatiblePciDeviceList.h"\r
16\r
17EFI_PCI_REGISTER_ACCESS_DATA mPciRegisterAccessData = {0, 0, 0}; \r
18EFI_PCI_REGISTER_VALUE_DATA mPciRegisterValueData = {0, 0};\r
19 \r
20\r
21/**\r
22 Check whether two PCI devices matched.\r
23\r
24 @param PciDeviceInfo A pointer to EFI_PCI_DEVICE_INFO.\r
25 @param Header A pointer to EFI_PCI_DEVICE_INFO.\r
26\r
27 @retval EFI_SUCCESS Two PCI devices matched.\r
28 @retval EFI_UNSUPPORTED Two PCI devices don't match.\r
29\r
30**/\r
31EFI_STATUS\r
32DeviceCheck (\r
33 IN EFI_PCI_DEVICE_INFO *PciDeviceInfo,\r
34 IN EFI_PCI_DEVICE_INFO *Header\r
35 )\r
36{\r
37 //\r
38 // See if the Header matches the parameters passed in\r
39 //\r
40 if (Header->VendorID != DEVICE_ID_NOCARE) {\r
41 if (PciDeviceInfo->VendorID != Header->VendorID) {\r
42 return EFI_UNSUPPORTED;\r
43 }\r
44 }\r
45\r
46 if (Header->DeviceID != DEVICE_ID_NOCARE) {\r
47 if (PciDeviceInfo->DeviceID != Header->DeviceID) {\r
48 return EFI_UNSUPPORTED;\r
49 }\r
50 }\r
51\r
52 if (Header->RevisionID != DEVICE_ID_NOCARE) {\r
53 if (PciDeviceInfo->RevisionID != Header->RevisionID) {\r
54 return EFI_UNSUPPORTED;\r
55 }\r
56 }\r
57\r
58 if (Header->SubsystemVendorID != DEVICE_ID_NOCARE) {\r
59 if (PciDeviceInfo->SubsystemVendorID != Header->SubsystemVendorID) {\r
60 return EFI_UNSUPPORTED;\r
61 }\r
62 }\r
63\r
64 if (Header->SubsystemID != DEVICE_ID_NOCARE) {\r
65 if (PciDeviceInfo->SubsystemID != Header->SubsystemID) {\r
66 return EFI_UNSUPPORTED;\r
67 }\r
68 }\r
69\r
70 return EFI_SUCCESS;\r
71}\r
72\r
73\r
74/**\r
75 Check the incompatible device list for ACPI resource update and return\r
76 the configuration.\r
77\r
78 This function searches the incompatible device list according to request\r
79 information. If the PCI device belongs to the devices list, corresponding\r
80 configuration informtion will be returned, in the meantime return EFI_SUCCESS.\r
81\r
82 @param PciDeviceInfo A pointer to PCI device information.\r
83 @param Configuration Returned information.\r
84\r
85 @retval EFI_SUCCESS If check incompatible device successfully.\r
86 @retval EFI_ABORTED No any resource type.\r
87 @retval EFI_OUT_OF_RESOURCES No memory available.\r
88 @retval EFI_UNSUPPORTED Invalid Tag encounted.\r
89\r
90**/\r
91EFI_STATUS\r
92EFIAPI\r
93PciResourceUpdateCheck (\r
94 IN EFI_PCI_DEVICE_INFO *PciDeviceInfo,\r
95 OUT VOID *Configuration\r
96 )\r
97{\r
98 UINT64 Tag;\r
99 UINT64 *ListPtr;\r
100 UINT64 *TempListPtr;\r
101 EFI_PCI_DEVICE_INFO *Header;\r
102 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *AcpiPtr;\r
103 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *OldAcpiPtr;\r
104 EFI_PCI_RESOUCE_DESCRIPTOR *Dsc;\r
105 EFI_ACPI_END_TAG_DESCRIPTOR *PtrEnd;\r
106 UINTN Index;\r
107\r
108 ASSERT (PciDeviceInfo != NULL);\r
109\r
110 //\r
111 // Initialize the return value to NULL\r
112 //\r
113 * (VOID **) Configuration = NULL;\r
114\r
115 ListPtr = gIncompatiblePciDeviceListForResource;\r
116 while (*ListPtr != LIST_END_TAG) {\r
117\r
118 Tag = *ListPtr;\r
119\r
120 switch (Tag) {\r
121 case DEVICE_INF_TAG:\r
122 Header = (EFI_PCI_DEVICE_INFO *) (ListPtr + 1);\r
123 ListPtr = ListPtr + 1 + sizeof (EFI_PCI_DEVICE_INFO) / sizeof (UINT64);\r
124\r
125 if (DeviceCheck (PciDeviceInfo, Header) != EFI_SUCCESS) {\r
126 continue;\r
127 }\r
128\r
129 //\r
130 // Matched an item, so construct the ACPI descriptor for the resource.\r
131 //\r
132 //\r
133 // Count the resource items so that to allocate space\r
134 //\r
135 for (Index = 0, TempListPtr = ListPtr; *TempListPtr == DEVICE_RES_TAG; Index++) {\r
136 TempListPtr = TempListPtr + 1 + ((sizeof (EFI_PCI_RESOUCE_DESCRIPTOR)) / sizeof (UINT64));\r
137 }\r
138 //\r
139 // If there is at least one type of resource request,\r
140 // allocate a acpi resource node\r
141 //\r
142 if (Index == 0) {\r
143 return EFI_ABORTED;\r
144 }\r
145\r
146 AcpiPtr = AllocateZeroPool (\r
147 sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR) * Index + sizeof (EFI_ACPI_END_TAG_DESCRIPTOR)\r
148 );\r
149 if (AcpiPtr == NULL) {\r
150 return EFI_OUT_OF_RESOURCES;\r
151 }\r
152\r
153 OldAcpiPtr = AcpiPtr;\r
154\r
155 //\r
156 // Fill the EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR structure\r
157 // according to the EFI_PCI_RESOUCE_DESCRIPTOR structure\r
158 //\r
159 for (; *ListPtr == DEVICE_RES_TAG;) {\r
160\r
161 Dsc = (EFI_PCI_RESOUCE_DESCRIPTOR *) (ListPtr + 1);\r
162\r
163 AcpiPtr->Desc = ACPI_ADDRESS_SPACE_DESCRIPTOR;\r
164 AcpiPtr->Len = sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR);\r
165 AcpiPtr->ResType = (UINT8) Dsc->ResType;\r
166 AcpiPtr->GenFlag = (UINT8) Dsc->GenFlag;\r
167 AcpiPtr->SpecificFlag = (UINT8) Dsc->SpecificFlag;\r
168 AcpiPtr->AddrSpaceGranularity = Dsc->AddrSpaceGranularity;;\r
169 AcpiPtr->AddrRangeMin = Dsc->AddrRangeMin;\r
170 AcpiPtr->AddrRangeMax = Dsc->AddrRangeMax;\r
171 AcpiPtr->AddrTranslationOffset = Dsc->AddrTranslationOffset;\r
172 AcpiPtr->AddrLen = Dsc->AddrLen;\r
173\r
174 ListPtr = ListPtr + 1 + ((sizeof (EFI_PCI_RESOUCE_DESCRIPTOR)) / sizeof (UINT64));\r
175 AcpiPtr++;\r
176 }\r
177 //\r
178 // put the checksum\r
179 //\r
180 PtrEnd = (EFI_ACPI_END_TAG_DESCRIPTOR *) (AcpiPtr);\r
181 PtrEnd->Desc = ACPI_END_TAG_DESCRIPTOR;\r
182 PtrEnd->Checksum = 0;\r
183\r
184 *(VOID **) Configuration = OldAcpiPtr;\r
185\r
186 return EFI_SUCCESS;\r
187\r
188 case DEVICE_RES_TAG:\r
189 //\r
190 // Adjust the pointer to the next PCI resource descriptor item\r
191 //\r
192 ListPtr = ListPtr + 1 + ((sizeof (EFI_PCI_RESOUCE_DESCRIPTOR)) / sizeof (UINT64));\r
193 break;\r
194\r
195 default:\r
196 return EFI_UNSUPPORTED;\r
197 }\r
198 }\r
199\r
200 return EFI_UNSUPPORTED;\r
201\r
202}\r
203\r
204/**\r
205 Check the incompatible device list and return configuraton register mask values.\r
206\r
207 This function searches the incompatible device list according to request\r
208 information. If the PCI device belongs to the devices list, corresponding\r
209 configuration informtion will be returned, in the meantime return EFI_SUCCESS.\r
210\r
211 @param PciDeviceInfo A pointer to EFI_PCI_DEVICE_INFO.\r
212 @param AccessType Access Type, READ or WRITE.\r
213 @param Offset The address within the PCI configuration space.\r
214 @param Configuration Returned information.\r
215\r
216 @retval EFI_SUCCESS If check incompatible device successfully.\r
217 @retval EFI_UNSUPPORTED Failed to check incompatibility device.\r
218\r
219**/\r
220EFI_STATUS\r
221EFIAPI\r
222PciRegisterUpdateCheck (\r
223 IN EFI_PCI_DEVICE_INFO *PciDeviceInfo,\r
224 IN UINT64 AccessType,\r
225 IN UINT64 Offset,\r
226 OUT VOID *Configuration\r
227 )\r
228{\r
229 EFI_PCI_DEVICE_INFO *Header;\r
230 UINT64 Tag;\r
231 UINT64 *ListPtr;\r
232 EFI_PCI_REGISTER_VALUE_DATA *RegisterPtr;\r
233 EFI_PCI_REGISTER_VALUE_DATA *Dsc;\r
234\r
235 ASSERT (PciDeviceInfo != NULL);\r
236\r
237 ListPtr = gIncompatiblePciDeviceListForRegister;\r
238\r
239 //\r
240 // Initialize the return value to NULL\r
241 //\r
242 * (VOID **) Configuration = NULL;\r
243\r
244 while (*ListPtr != LIST_END_TAG) {\r
245\r
246 Tag = *ListPtr;\r
247\r
248 switch (Tag) {\r
249 case DEVICE_INF_TAG:\r
250 Header = (EFI_PCI_DEVICE_INFO *) (ListPtr + 1);\r
251 ListPtr = ListPtr + 1 + sizeof (EFI_PCI_DEVICE_INFO) / sizeof (UINT64);\r
252\r
253 //\r
254 // Check whether the PCI device matches the device in the incompatible devices list?\r
255 // If not, ship next\r
256 //\r
257 if (DeviceCheck (PciDeviceInfo, Header) != EFI_SUCCESS) {\r
258 continue;\r
259 }\r
260\r
261 //\r
262 // Matched an item, check whether access matches?\r
263 //\r
264 for (; *ListPtr == DEVICE_RES_TAG;) {\r
265 ListPtr ++;\r
266 if (((EFI_PCI_REGISTER_VALUE_DESCRIPTOR *)ListPtr)->Offset == (Offset & 0xfc)) {\r
267 if (((EFI_PCI_REGISTER_VALUE_DESCRIPTOR *)ListPtr)->AccessType == AccessType) {\r
268\r
269 Dsc = (EFI_PCI_REGISTER_VALUE_DATA *) (ListPtr + 2);\r
270 \r
271 RegisterPtr = &mPciRegisterValueData;\r
272\r
273 RegisterPtr->AndValue = Dsc->AndValue;\r
274 RegisterPtr->OrValue = Dsc->OrValue;\r
275\r
276 *(VOID **) Configuration = RegisterPtr;\r
277\r
278 return EFI_SUCCESS;\r
279 }\r
280 }\r
281 ListPtr += sizeof (EFI_PCI_REGISTER_VALUE_DESCRIPTOR) / (sizeof (UINT64));\r
282 }\r
283 return EFI_UNSUPPORTED;\r
284\r
285 case DEVICE_RES_TAG:\r
286 //\r
287 // Adjust the pointer to the next item\r
288 //\r
289 ListPtr = ListPtr + 1 + ((sizeof (EFI_PCI_REGISTER_VALUE_DESCRIPTOR)) / sizeof (UINT64));\r
290 break;\r
291\r
292 default:\r
293 return EFI_UNSUPPORTED;\r
294 }\r
295 }\r
296\r
297 return EFI_UNSUPPORTED;\r
298}\r
299\r
300/**\r
301 Check the incompatible device list for access width incompatibility and\r
302 return the configuration\r
303\r
304 This function searches the incompatible device list for access width\r
305 incompatibility according to request information. If the PCI device\r
306 belongs to the devices list, corresponding configuration informtion\r
307 will be returned, in the meantime return EFI_SUCCESS.\r
308\r
309 @param PciDeviceInfo A pointer to PCI device information.\r
310 @param AccessType Access type, READ or WRITE.\r
311 @param Offset The address within the PCI configuration space.\r
312 @param AccessWidth Access width needs to check incompatibility.\r
313 @param Configuration Returned information.\r
314\r
315 @retval EFI_SUCCESS If check incompatible device successfully.\r
316 @retval EFI_UNSUPPORTED Failed to check incompatibility device.\r
317\r
318**/\r
319EFI_STATUS\r
320EFIAPI\r
321PciRegisterAccessCheck (\r
322 IN EFI_PCI_DEVICE_INFO *PciDeviceInfo,\r
323 IN UINT64 AccessType,\r
324 IN UINT64 Offset,\r
325 IN UINT64 AccessWidth,\r
326 OUT VOID *Configuration\r
327 )\r
328{\r
329 EFI_PCI_DEVICE_INFO *Header;\r
330 UINT64 Tag;\r
331 UINT64 *ListPtr;\r
332 EFI_PCI_REGISTER_ACCESS_DATA *RegisterPtr;\r
333 EFI_PCI_REGISTER_ACCESS_DATA *Dsc;\r
334\r
335 ASSERT (PciDeviceInfo != NULL);\r
336\r
337 ListPtr = gDeviceListForAccessWidth;\r
338\r
339 //\r
340 // Initialize the return value to NULL\r
341 //\r
342 * (VOID **) Configuration = NULL;\r
343\r
344 while (*ListPtr != LIST_END_TAG) {\r
345\r
346 Tag = *ListPtr;\r
347\r
348 switch (Tag) {\r
349 case DEVICE_INF_TAG:\r
350 Header = (EFI_PCI_DEVICE_INFO *) (ListPtr + 1);\r
351 ListPtr = ListPtr + 1 + sizeof (EFI_PCI_DEVICE_INFO) / sizeof (UINT64);\r
352\r
353 //\r
354 // Check whether the PCI device matches the device in the incompatible devices list?\r
355 // If not, ship next\r
356 //\r
357 if (DeviceCheck (PciDeviceInfo, Header) != EFI_SUCCESS) {\r
358 continue;\r
359 }\r
360\r
361 //\r
362 // Matched an item, check whether access matches?\r
363 //\r
364 for (; *ListPtr == DEVICE_RES_TAG;) {\r
365 ListPtr ++;\r
366 if (((EFI_PCI_REGISTER_ACCESS_DESCRIPTOR *) ListPtr)->AccessType == AccessType &&\r
367 ((EFI_PCI_REGISTER_ACCESS_DESCRIPTOR *) ListPtr)->AccessWidth == AccessWidth ) {\r
368\r
369 Dsc = (EFI_PCI_REGISTER_ACCESS_DATA *) (ListPtr + 2);\r
370\r
371 if((Dsc->StartOffset <= Offset) && (Dsc->EndOffset > Offset)) {\r
372\r
373 RegisterPtr = &mPciRegisterAccessData;\r
374\r
375 RegisterPtr->StartOffset = Dsc->StartOffset;\r
376 RegisterPtr->EndOffset = Dsc->EndOffset;\r
377 RegisterPtr->Width = Dsc->Width;\r
378\r
379 *(VOID **) Configuration = RegisterPtr;\r
380\r
381 return EFI_SUCCESS;\r
382 }\r
383 }\r
384 ListPtr += sizeof (EFI_PCI_REGISTER_ACCESS_DESCRIPTOR) / (sizeof (UINT64));\r
385 }\r
386 return EFI_UNSUPPORTED;\r
387\r
388 case DEVICE_RES_TAG:\r
389 //\r
390 // Adjust the pointer to the next item\r
391 //\r
392 ListPtr = ListPtr + 1 + ((sizeof (EFI_PCI_REGISTER_ACCESS_DESCRIPTOR)) / sizeof (UINT64));\r
393 break;\r
394\r
395 default:\r
396 return EFI_UNSUPPORTED;\r
397 }\r
398 }\r
399\r
400 return EFI_UNSUPPORTED;\r
401}\r
402\r