Complete the library instances in IntelFrameworkModulePkg
[mirror_edk2.git] / IntelFrameworkModulePkg / Library / PciIncompatibleDeviceSupportLib / PciIncompatibleDeviceSupportLib.c
CommitLineData
54bd896e 1/** @file\r
2 The implementation of PCI incompatible device support libary.\r
3\r
4Copyright (c) 2007 Intel Corporation. All rights reserved. <BR>\r
5This software and associated documentation (if any) is furnished\r
6under a license and may only be used or copied in accordance\r
7with the terms of the license. Except as permitted by such\r
8license, no part of this software or documentation may be\r
9reproduced, stored in a retrieval system, or transmitted in any\r
10form or by any means without the express written consent of\r
11Intel Corporation.\r
12\r
13**/\r
14\r
15//\r
16// Include common header file for this module.\r
17//\r
18#include "CommonHeader.h"\r
19\r
20#include "IncompatiblePciDeviceList.h"\r
21\r
22/**\r
23 Check whether two PCI devices matched\r
24\r
25 @param PciDeviceInfo A pointer to EFI_PCI_DEVICE_INFO.\r
26 @param Header A pointer to EFI_PCI_DEVICE_INFO.\r
27\r
28 @retval returns EFI_SUCCESS if two PCI device matched.\r
29**/\r
30STATIC\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 returns EFI_SUCCESS if check incompatible device ok.\r
86 Otherwise return EFI_UNSUPPORTED.\r
87**/\r
88RETURN_STATUS\r
89EFIAPI\r
90PciResourceUpdateCheck (\r
91 IN EFI_PCI_DEVICE_INFO *PciDeviceInfo,\r
92 OUT VOID *Configuration\r
93 )\r
94{\r
95 UINT64 Tag;\r
96 UINT64 *ListPtr;\r
97 UINT64 *TempListPtr;\r
98 EFI_PCI_DEVICE_INFO *Header;\r
99 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *AcpiPtr;\r
100 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *OldAcpiPtr;\r
101 EFI_PCI_RESOUCE_DESCRIPTOR *Dsc;\r
102 EFI_ACPI_END_TAG_DESCRIPTOR *PtrEnd;\r
103 UINTN Index;\r
104\r
105 ASSERT (PciDeviceInfo != NULL);\r
106\r
107 //\r
108 // Initialize the return value to NULL\r
109 //\r
110 * (VOID **) Configuration = NULL;\r
111\r
112 ListPtr = IncompatiblePciDeviceListForResource;\r
113 while (*ListPtr != LIST_END_TAG) {\r
114\r
115 Tag = *ListPtr;\r
116\r
117 switch (Tag) {\r
118 case DEVICE_INF_TAG:\r
119 Header = (EFI_PCI_DEVICE_INFO *) (ListPtr + 1);\r
120 ListPtr = ListPtr + 1 + sizeof (EFI_PCI_DEVICE_INFO) / sizeof (UINT64);\r
121\r
122 if (DeviceCheck (PciDeviceInfo, Header) != EFI_SUCCESS) {\r
123 continue;\r
124 }\r
125\r
126 //\r
127 // Matched an item, so construct the ACPI descriptor for the resource.\r
128 //\r
129 //\r
130 // Count the resource items so that to allocate space\r
131 //\r
132 for (Index = 0, TempListPtr = ListPtr; *TempListPtr == DEVICE_RES_TAG; Index++) {\r
133 TempListPtr = TempListPtr + 1 + ((sizeof (EFI_PCI_RESOUCE_DESCRIPTOR)) / sizeof (UINT64));\r
134 }\r
135 //\r
136 // If there is at least one type of resource request,\r
137 // allocate a acpi resource node\r
138 //\r
139 if (Index == 0) {\r
140 return EFI_ABORTED;\r
141 }\r
142\r
143 AcpiPtr = AllocateZeroPool (\r
144 sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR) * Index + sizeof (EFI_ACPI_END_TAG_DESCRIPTOR)\r
145 );\r
146\r
147 OldAcpiPtr = AcpiPtr;\r
148\r
149 //\r
150 // Fill the EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR structure\r
151 // according to the EFI_PCI_RESOUCE_DESCRIPTOR structure\r
152 //\r
153 for (; *ListPtr == DEVICE_RES_TAG;) {\r
154\r
155 Dsc = (EFI_PCI_RESOUCE_DESCRIPTOR *) (ListPtr + 1);\r
156\r
157 AcpiPtr->Desc = ACPI_ADDRESS_SPACE_DESCRIPTOR;\r
158 AcpiPtr->Len = sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR);\r
159 AcpiPtr->ResType = (UINT8) Dsc->ResType;\r
160 AcpiPtr->GenFlag = (UINT8) Dsc->GenFlag;\r
161 AcpiPtr->SpecificFlag = (UINT8) Dsc->SpecificFlag;\r
162 AcpiPtr->AddrSpaceGranularity = Dsc->AddrSpaceGranularity;;\r
163 AcpiPtr->AddrRangeMin = Dsc->AddrRangeMin;\r
164 AcpiPtr->AddrRangeMax = Dsc->AddrRangeMax;\r
165 AcpiPtr->AddrTranslationOffset = Dsc->AddrTranslationOffset;\r
166 AcpiPtr->AddrLen = Dsc->AddrLen;\r
167\r
168 ListPtr = ListPtr + 1 + ((sizeof (EFI_PCI_RESOUCE_DESCRIPTOR)) / sizeof (UINT64));\r
169 AcpiPtr++;\r
170 }\r
171 //\r
172 // put the checksum\r
173 //\r
174 PtrEnd = (EFI_ACPI_END_TAG_DESCRIPTOR *) (AcpiPtr);\r
175 PtrEnd->Desc = ACPI_END_TAG_DESCRIPTOR;\r
176 PtrEnd->Checksum = 0;\r
177\r
178 *(VOID **) Configuration = OldAcpiPtr;\r
179\r
180 return EFI_SUCCESS;\r
181\r
182 case DEVICE_RES_TAG:\r
183 //\r
184 // Adjust the pointer to the next PCI resource descriptor item\r
185 //\r
186 ListPtr = ListPtr + 1 + ((sizeof (EFI_PCI_RESOUCE_DESCRIPTOR)) / sizeof (UINT64));\r
187 break;\r
188\r
189 default:\r
190 return EFI_UNSUPPORTED;\r
191 }\r
192 }\r
193\r
194 return EFI_UNSUPPORTED;\r
195\r
196}\r
197\r
198/**\r
199 Check the incompatible device list and return configuraton register mask values.\r
200\r
201 This function searches the incompatible device list according to request\r
202 information. If the PCI device belongs to the devices list, corresponding\r
203 configuration informtion will be returned, in the meantime return EFI_SUCCESS.\r
204\r
205 @param PciDeviceInfo A pointer to EFI_PCI_DEVICE_INFO.\r
206 @param AccessType Access Type, READ or WRITE.\r
207 @param Offset The address within the PCI configuration space.\r
208 @param Configuration Returned information.\r
209\r
210 @retval returns EFI_SUCCESS if check incompatible device ok.\r
211 Otherwise return EFI_UNSUPPORTED.\r
212**/\r
213RETURN_STATUS\r
214EFIAPI\r
215PciRegisterUpdateCheck (\r
216 IN EFI_PCI_DEVICE_INFO *PciDeviceInfo,\r
217 IN UINT64 AccessType,\r
218 IN UINT64 Offset,\r
219 OUT VOID *Configuration\r
220 )\r
221{\r
222 EFI_PCI_DEVICE_INFO *Header;\r
223 UINT64 Tag;\r
224 UINT64 *ListPtr;\r
225 EFI_PCI_REGISTER_VALUE_DATA *RegisterPtr;\r
226 EFI_PCI_REGISTER_VALUE_DATA *Dsc;\r
227\r
228 ASSERT (PciDeviceInfo != NULL);\r
229\r
230 ListPtr = IncompatiblePciDeviceListForRegister;\r
231\r
232 //\r
233 // Initialize the return value to NULL\r
234 //\r
235 * (VOID **) Configuration = NULL;\r
236\r
237 while (*ListPtr != LIST_END_TAG) {\r
238\r
239 Tag = *ListPtr;\r
240\r
241 switch (Tag) {\r
242 case DEVICE_INF_TAG:\r
243 Header = (EFI_PCI_DEVICE_INFO *) (ListPtr + 1);\r
244 ListPtr = ListPtr + 1 + sizeof (EFI_PCI_DEVICE_INFO) / sizeof (UINT64);\r
245\r
246 //\r
247 // Check whether the PCI device matches the device in the incompatible devices list?\r
248 // If not, ship next\r
249 //\r
250 if (DeviceCheck (PciDeviceInfo, Header) != EFI_SUCCESS) {\r
251 continue;\r
252 }\r
253\r
254 //\r
255 // Matched an item, check whether access matches?\r
256 //\r
257 for (; *ListPtr == DEVICE_RES_TAG;) {\r
258 ListPtr ++;\r
259 if (((EFI_PCI_REGISTER_VALUE_DESCRIPTOR *)ListPtr)->Offset == (Offset & 0xfc)) {\r
260 if (((EFI_PCI_REGISTER_VALUE_DESCRIPTOR *)ListPtr)->AccessType == AccessType) {\r
261\r
262 Dsc = (EFI_PCI_REGISTER_VALUE_DATA *) (ListPtr + 2);\r
263 RegisterPtr = AllocateZeroPool (sizeof (EFI_PCI_REGISTER_VALUE_DATA));\r
264\r
265 RegisterPtr->AndValue = Dsc->AndValue;\r
266 RegisterPtr->OrValue = Dsc->OrValue;\r
267\r
268 *(VOID **) Configuration = RegisterPtr;\r
269\r
270 return EFI_SUCCESS;\r
271 }\r
272 }\r
273 ListPtr += sizeof (EFI_PCI_REGISTER_VALUE_DESCRIPTOR) / (sizeof (UINT64));\r
274 }\r
275 return EFI_UNSUPPORTED;\r
276\r
277 case DEVICE_RES_TAG:\r
278 //\r
279 // Adjust the pointer to the next item\r
280 //\r
281 ListPtr = ListPtr + 1 + ((sizeof (EFI_PCI_REGISTER_VALUE_DESCRIPTOR)) / sizeof (UINT64));\r
282 break;\r
283\r
284 default:\r
285 return EFI_UNSUPPORTED;\r
286 }\r
287 }\r
288\r
289 return EFI_UNSUPPORTED;\r
290}\r
291\r
292/**\r
293 Check the incompatible device list for access width incompatibility and\r
294 return the configuration\r
295\r
296 This function searches the incompatible device list for access width\r
297 incompatibility according to request information. If the PCI device\r
298 belongs to the devices list, corresponding configuration informtion\r
299 will be returned, in the meantime return EFI_SUCCESS.\r
300\r
301 @param PciDeviceInfo A pointer to PCI device information.\r
302 @param AccessType Access type, READ or WRITE.\r
303 @param Offset The address within the PCI configuration space.\r
304 @param AccessWidth Access width needs to check incompatibility.\r
305 @param Configuration Returned information.\r
306\r
307 @retval returns EFI_SUCCESS if check incompatible device ok.\r
308 Otherwise return EFI_UNSUPPORTED.\r
309**/\r
310RETURN_STATUS\r
311EFIAPI\r
312PciRegisterAccessCheck (\r
313 IN EFI_PCI_DEVICE_INFO *PciDeviceInfo,\r
314 IN UINT64 AccessType,\r
315 IN UINT64 Offset,\r
316 IN UINT64 AccessWidth,\r
317 OUT VOID *Configuration\r
318 )\r
319{\r
320 EFI_PCI_DEVICE_INFO *Header;\r
321 UINT64 Tag;\r
322 UINT64 *ListPtr;\r
323 EFI_PCI_REGISTER_ACCESS_DATA *RegisterPtr;\r
324 EFI_PCI_REGISTER_ACCESS_DATA *Dsc;\r
325\r
326 ASSERT (PciDeviceInfo != NULL);\r
327\r
328 ListPtr = DeviceListForAccessWidth;\r
329\r
330 //\r
331 // Initialize the return value to NULL\r
332 //\r
333 * (VOID **) Configuration = NULL;\r
334\r
335 while (*ListPtr != LIST_END_TAG) {\r
336\r
337 Tag = *ListPtr;\r
338\r
339 switch (Tag) {\r
340 case DEVICE_INF_TAG:\r
341 Header = (EFI_PCI_DEVICE_INFO *) (ListPtr + 1);\r
342 ListPtr = ListPtr + 1 + sizeof (EFI_PCI_DEVICE_INFO) / sizeof (UINT64);\r
343\r
344 //\r
345 // Check whether the PCI device matches the device in the incompatible devices list?\r
346 // If not, ship next\r
347 //\r
348 if (DeviceCheck (PciDeviceInfo, Header) != EFI_SUCCESS) {\r
349 continue;\r
350 }\r
351\r
352 //\r
353 // Matched an item, check whether access matches?\r
354 //\r
355 for (; *ListPtr == DEVICE_RES_TAG;) {\r
356 ListPtr ++;\r
357 if (((EFI_PCI_REGISTER_ACCESS_DESCRIPTOR *) ListPtr)->AccessType == AccessType &&\r
358 ((EFI_PCI_REGISTER_ACCESS_DESCRIPTOR *) ListPtr)->AccessWidth == AccessWidth ) {\r
359\r
360 Dsc = (EFI_PCI_REGISTER_ACCESS_DATA *) (ListPtr + 2);\r
361\r
362 if((Dsc->StartOffset <= Offset) && (Dsc->EndOffset > Offset)) {\r
363\r
364 RegisterPtr = AllocateZeroPool (sizeof (EFI_PCI_REGISTER_ACCESS_DATA));\r
365\r
366 RegisterPtr->StartOffset = Dsc->StartOffset;\r
367 RegisterPtr->EndOffset = Dsc->EndOffset;\r
368 RegisterPtr->Width = Dsc->Width;\r
369\r
370 *(VOID **) Configuration = RegisterPtr;\r
371\r
372 return EFI_SUCCESS;\r
373 }\r
374 }\r
375 ListPtr += sizeof (EFI_PCI_REGISTER_ACCESS_DESCRIPTOR) / (sizeof (UINT64));\r
376 }\r
377 return EFI_UNSUPPORTED;\r
378\r
379 case DEVICE_RES_TAG:\r
380 //\r
381 // Adjust the pointer to the next item\r
382 //\r
383 ListPtr = ListPtr + 1 + ((sizeof (EFI_PCI_REGISTER_ACCESS_DESCRIPTOR)) / sizeof (UINT64));\r
384 break;\r
385\r
386 default:\r
387 return EFI_UNSUPPORTED;\r
388 }\r
389 }\r
390\r
391 return EFI_UNSUPPORTED;\r
392}\r
393\r