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