2 The template of PCI incompatible device support libary.
4 Copyright (c) 2006 - 2009, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "IncompatiblePciDeviceList.h"
17 EFI_PCI_REGISTER_ACCESS_DATA mPciRegisterAccessData
= {0, 0, 0};
18 EFI_PCI_REGISTER_VALUE_DATA mPciRegisterValueData
= {0, 0};
22 Check whether two PCI devices matched.
24 @param PciDeviceInfo A pointer to EFI_PCI_DEVICE_INFO.
25 @param Header A pointer to EFI_PCI_DEVICE_INFO.
27 @retval EFI_SUCCESS Two PCI devices matched.
28 @retval EFI_UNSUPPORTED Two PCI devices don't match.
33 IN EFI_PCI_DEVICE_INFO
*PciDeviceInfo
,
34 IN EFI_PCI_DEVICE_INFO
*Header
38 // See if the Header matches the parameters passed in
40 if (Header
->VendorID
!= DEVICE_ID_NOCARE
) {
41 if (PciDeviceInfo
->VendorID
!= Header
->VendorID
) {
42 return EFI_UNSUPPORTED
;
46 if (Header
->DeviceID
!= DEVICE_ID_NOCARE
) {
47 if (PciDeviceInfo
->DeviceID
!= Header
->DeviceID
) {
48 return EFI_UNSUPPORTED
;
52 if (Header
->RevisionID
!= DEVICE_ID_NOCARE
) {
53 if (PciDeviceInfo
->RevisionID
!= Header
->RevisionID
) {
54 return EFI_UNSUPPORTED
;
58 if (Header
->SubsystemVendorID
!= DEVICE_ID_NOCARE
) {
59 if (PciDeviceInfo
->SubsystemVendorID
!= Header
->SubsystemVendorID
) {
60 return EFI_UNSUPPORTED
;
64 if (Header
->SubsystemID
!= DEVICE_ID_NOCARE
) {
65 if (PciDeviceInfo
->SubsystemID
!= Header
->SubsystemID
) {
66 return EFI_UNSUPPORTED
;
75 Check the incompatible device list for ACPI resource update and return
78 This function searches the incompatible device list according to request
79 information. If the PCI device belongs to the devices list, corresponding
80 configuration informtion will be returned, in the meantime return EFI_SUCCESS.
82 @param PciDeviceInfo A pointer to PCI device information.
83 @param Configuration Returned information.
85 @retval EFI_SUCCESS If check incompatible device successfully.
86 @retval EFI_ABORTED No any resource type.
87 @retval EFI_OUT_OF_RESOURCES No memory available.
88 @retval EFI_UNSUPPORTED Invalid Tag encounted.
93 PciResourceUpdateCheck (
94 IN EFI_PCI_DEVICE_INFO
*PciDeviceInfo
,
95 OUT VOID
*Configuration
101 EFI_PCI_DEVICE_INFO
*Header
;
102 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*AcpiPtr
;
103 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*OldAcpiPtr
;
104 EFI_PCI_RESOUCE_DESCRIPTOR
*Dsc
;
105 EFI_ACPI_END_TAG_DESCRIPTOR
*PtrEnd
;
108 ASSERT (PciDeviceInfo
!= NULL
);
111 // Initialize the return value to NULL
113 * (VOID
**) Configuration
= NULL
;
115 ListPtr
= gIncompatiblePciDeviceListForResource
;
116 while (*ListPtr
!= LIST_END_TAG
) {
122 Header
= (EFI_PCI_DEVICE_INFO
*) (ListPtr
+ 1);
123 ListPtr
= ListPtr
+ 1 + sizeof (EFI_PCI_DEVICE_INFO
) / sizeof (UINT64
);
125 if (DeviceCheck (PciDeviceInfo
, Header
) != EFI_SUCCESS
) {
130 // Matched an item, so construct the ACPI descriptor for the resource.
133 // Count the resource items so that to allocate space
135 for (Index
= 0, TempListPtr
= ListPtr
; *TempListPtr
== DEVICE_RES_TAG
; Index
++) {
136 TempListPtr
= TempListPtr
+ 1 + ((sizeof (EFI_PCI_RESOUCE_DESCRIPTOR
)) / sizeof (UINT64
));
139 // If there is at least one type of resource request,
140 // allocate a acpi resource node
146 AcpiPtr
= AllocateZeroPool (
147 sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
) * Index
+ sizeof (EFI_ACPI_END_TAG_DESCRIPTOR
)
149 if (AcpiPtr
== NULL
) {
150 return EFI_OUT_OF_RESOURCES
;
153 OldAcpiPtr
= AcpiPtr
;
156 // Fill the EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR structure
157 // according to the EFI_PCI_RESOUCE_DESCRIPTOR structure
159 for (; *ListPtr
== DEVICE_RES_TAG
;) {
161 Dsc
= (EFI_PCI_RESOUCE_DESCRIPTOR
*) (ListPtr
+ 1);
163 AcpiPtr
->Desc
= ACPI_ADDRESS_SPACE_DESCRIPTOR
;
164 AcpiPtr
->Len
= sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
);
165 AcpiPtr
->ResType
= (UINT8
) Dsc
->ResType
;
166 AcpiPtr
->GenFlag
= (UINT8
) Dsc
->GenFlag
;
167 AcpiPtr
->SpecificFlag
= (UINT8
) Dsc
->SpecificFlag
;
168 AcpiPtr
->AddrSpaceGranularity
= Dsc
->AddrSpaceGranularity
;;
169 AcpiPtr
->AddrRangeMin
= Dsc
->AddrRangeMin
;
170 AcpiPtr
->AddrRangeMax
= Dsc
->AddrRangeMax
;
171 AcpiPtr
->AddrTranslationOffset
= Dsc
->AddrTranslationOffset
;
172 AcpiPtr
->AddrLen
= Dsc
->AddrLen
;
174 ListPtr
= ListPtr
+ 1 + ((sizeof (EFI_PCI_RESOUCE_DESCRIPTOR
)) / sizeof (UINT64
));
180 PtrEnd
= (EFI_ACPI_END_TAG_DESCRIPTOR
*) (AcpiPtr
);
181 PtrEnd
->Desc
= ACPI_END_TAG_DESCRIPTOR
;
182 PtrEnd
->Checksum
= 0;
184 *(VOID
**) Configuration
= OldAcpiPtr
;
190 // Adjust the pointer to the next PCI resource descriptor item
192 ListPtr
= ListPtr
+ 1 + ((sizeof (EFI_PCI_RESOUCE_DESCRIPTOR
)) / sizeof (UINT64
));
196 return EFI_UNSUPPORTED
;
200 return EFI_UNSUPPORTED
;
205 Check the incompatible device list and return configuraton register mask values.
207 This function searches the incompatible device list according to request
208 information. If the PCI device belongs to the devices list, corresponding
209 configuration informtion will be returned, in the meantime return EFI_SUCCESS.
211 @param PciDeviceInfo A pointer to EFI_PCI_DEVICE_INFO.
212 @param AccessType Access Type, READ or WRITE.
213 @param Offset The address within the PCI configuration space.
214 @param Configuration Returned information.
216 @retval EFI_SUCCESS If check incompatible device successfully.
217 @retval EFI_UNSUPPORTED Failed to check incompatibility device.
222 PciRegisterUpdateCheck (
223 IN EFI_PCI_DEVICE_INFO
*PciDeviceInfo
,
224 IN UINT64 AccessType
,
226 OUT VOID
*Configuration
229 EFI_PCI_DEVICE_INFO
*Header
;
232 EFI_PCI_REGISTER_VALUE_DATA
*RegisterPtr
;
233 EFI_PCI_REGISTER_VALUE_DATA
*Dsc
;
235 ASSERT (PciDeviceInfo
!= NULL
);
237 ListPtr
= gIncompatiblePciDeviceListForRegister
;
240 // Initialize the return value to NULL
242 * (VOID
**) Configuration
= NULL
;
244 while (*ListPtr
!= LIST_END_TAG
) {
250 Header
= (EFI_PCI_DEVICE_INFO
*) (ListPtr
+ 1);
251 ListPtr
= ListPtr
+ 1 + sizeof (EFI_PCI_DEVICE_INFO
) / sizeof (UINT64
);
254 // Check whether the PCI device matches the device in the incompatible devices list?
257 if (DeviceCheck (PciDeviceInfo
, Header
) != EFI_SUCCESS
) {
262 // Matched an item, check whether access matches?
264 for (; *ListPtr
== DEVICE_RES_TAG
;) {
266 if (((EFI_PCI_REGISTER_VALUE_DESCRIPTOR
*)ListPtr
)->Offset
== (Offset
& 0xfc)) {
267 if (((EFI_PCI_REGISTER_VALUE_DESCRIPTOR
*)ListPtr
)->AccessType
== AccessType
) {
269 Dsc
= (EFI_PCI_REGISTER_VALUE_DATA
*) (ListPtr
+ 2);
271 RegisterPtr
= &mPciRegisterValueData
;
273 RegisterPtr
->AndValue
= Dsc
->AndValue
;
274 RegisterPtr
->OrValue
= Dsc
->OrValue
;
276 *(VOID
**) Configuration
= RegisterPtr
;
281 ListPtr
+= sizeof (EFI_PCI_REGISTER_VALUE_DESCRIPTOR
) / (sizeof (UINT64
));
283 return EFI_UNSUPPORTED
;
287 // Adjust the pointer to the next item
289 ListPtr
= ListPtr
+ 1 + ((sizeof (EFI_PCI_REGISTER_VALUE_DESCRIPTOR
)) / sizeof (UINT64
));
293 return EFI_UNSUPPORTED
;
297 return EFI_UNSUPPORTED
;
301 Check the incompatible device list for access width incompatibility and
302 return the configuration
304 This function searches the incompatible device list for access width
305 incompatibility according to request information. If the PCI device
306 belongs to the devices list, corresponding configuration informtion
307 will be returned, in the meantime return EFI_SUCCESS.
309 @param PciDeviceInfo A pointer to PCI device information.
310 @param AccessType Access type, READ or WRITE.
311 @param Offset The address within the PCI configuration space.
312 @param AccessWidth Access width needs to check incompatibility.
313 @param Configuration Returned information.
315 @retval EFI_SUCCESS If check incompatible device successfully.
316 @retval EFI_UNSUPPORTED Failed to check incompatibility device.
321 PciRegisterAccessCheck (
322 IN EFI_PCI_DEVICE_INFO
*PciDeviceInfo
,
323 IN UINT64 AccessType
,
325 IN UINT64 AccessWidth
,
326 OUT VOID
*Configuration
329 EFI_PCI_DEVICE_INFO
*Header
;
332 EFI_PCI_REGISTER_ACCESS_DATA
*RegisterPtr
;
333 EFI_PCI_REGISTER_ACCESS_DATA
*Dsc
;
335 ASSERT (PciDeviceInfo
!= NULL
);
337 ListPtr
= gDeviceListForAccessWidth
;
340 // Initialize the return value to NULL
342 * (VOID
**) Configuration
= NULL
;
344 while (*ListPtr
!= LIST_END_TAG
) {
350 Header
= (EFI_PCI_DEVICE_INFO
*) (ListPtr
+ 1);
351 ListPtr
= ListPtr
+ 1 + sizeof (EFI_PCI_DEVICE_INFO
) / sizeof (UINT64
);
354 // Check whether the PCI device matches the device in the incompatible devices list?
357 if (DeviceCheck (PciDeviceInfo
, Header
) != EFI_SUCCESS
) {
362 // Matched an item, check whether access matches?
364 for (; *ListPtr
== DEVICE_RES_TAG
;) {
366 if (((EFI_PCI_REGISTER_ACCESS_DESCRIPTOR
*) ListPtr
)->AccessType
== AccessType
&&
367 ((EFI_PCI_REGISTER_ACCESS_DESCRIPTOR
*) ListPtr
)->AccessWidth
== AccessWidth
) {
369 Dsc
= (EFI_PCI_REGISTER_ACCESS_DATA
*) (ListPtr
+ 2);
371 if((Dsc
->StartOffset
<= Offset
) && (Dsc
->EndOffset
> Offset
)) {
373 RegisterPtr
= &mPciRegisterAccessData
;
375 RegisterPtr
->StartOffset
= Dsc
->StartOffset
;
376 RegisterPtr
->EndOffset
= Dsc
->EndOffset
;
377 RegisterPtr
->Width
= Dsc
->Width
;
379 *(VOID
**) Configuration
= RegisterPtr
;
384 ListPtr
+= sizeof (EFI_PCI_REGISTER_ACCESS_DESCRIPTOR
) / (sizeof (UINT64
));
386 return EFI_UNSUPPORTED
;
390 // Adjust the pointer to the next item
392 ListPtr
= ListPtr
+ 1 + ((sizeof (EFI_PCI_REGISTER_ACCESS_DESCRIPTOR
)) / sizeof (UINT64
));
396 return EFI_UNSUPPORTED
;
400 return EFI_UNSUPPORTED
;