VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Firmware/OvmfPkg/Library/DxePciLibI440FxQ35/PciLib.c@ 107675

最後變更 在這個檔案從107675是 99404,由 vboxsync 提交於 2 年 前

Devices/EFI/FirmwareNew: Update to edk2-stable202302 and make it build, bugref:4643

  • 屬性 svn:eol-style 設為 native
檔案大小: 41.2 KB
 
1/** @file
2 PCI Library functions that use
3 (a) I/O ports 0xCF8 and 0xCFC to perform PCI Configuration cycles, layering
4 on top of one PCI CF8 Library instance; or
5 (b) PCI Library functions that use the 256 MB PCI Express MMIO window to
6 perform PCI Configuration cycles, layering on PCI Express Library.
7
8 The decision is made in the entry point function, based on the OVMF platform
9 type, and then adhered to during the lifetime of the client module.
10
11 Copyright (C) 2016, Red Hat, Inc.
12
13 Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
14 SPDX-License-Identifier: BSD-2-Clause-Patent
15
16**/
17
18#include <Base.h>
19
20#include <IndustryStandard/Q35MchIch9.h>
21
22#include <Library/PciLib.h>
23#include <Library/PciCf8Lib.h>
24#include <Library/PciExpressLib.h>
25#include <Library/PcdLib.h>
26
27STATIC BOOLEAN mRunningOnQ35;
28
29RETURN_STATUS
30EFIAPI
31InitializeConfigAccessMethod (
32 VOID
33 )
34{
35 mRunningOnQ35 = (PcdGet16 (PcdOvmfHostBridgePciDevId) ==
36 INTEL_Q35_MCH_DEVICE_ID);
37 return RETURN_SUCCESS;
38}
39
40/**
41 Registers a PCI device so PCI configuration registers may be accessed after
42 SetVirtualAddressMap().
43
44 Registers the PCI device specified by Address so all the PCI configuration registers
45 associated with that PCI device may be accessed after SetVirtualAddressMap() is called.
46
47 If Address > 0x0FFFFFFF, then ASSERT().
48
49 @param Address The address that encodes the PCI Bus, Device, Function and
50 Register.
51
52 @retval RETURN_SUCCESS The PCI device was registered for runtime access.
53 @retval RETURN_UNSUPPORTED An attempt was made to call this function
54 after ExitBootServices().
55 @retval RETURN_UNSUPPORTED The resources required to access the PCI device
56 at runtime could not be mapped.
57 @retval RETURN_OUT_OF_RESOURCES There are not enough resources available to
58 complete the registration.
59
60**/
61RETURN_STATUS
62EFIAPI
63PciRegisterForRuntimeAccess (
64 IN UINTN Address
65 )
66{
67 return mRunningOnQ35 ?
68 PciExpressRegisterForRuntimeAccess (Address) :
69 PciCf8RegisterForRuntimeAccess (Address);
70}
71
72/**
73 Reads an 8-bit PCI configuration register.
74
75 Reads and returns the 8-bit PCI configuration register specified by Address.
76 This function must guarantee that all PCI read and write operations are
77 serialized.
78
79 If Address > 0x0FFFFFFF, then ASSERT().
80
81 @param Address The address that encodes the PCI Bus, Device, Function and
82 Register.
83
84 @return The read value from the PCI configuration register.
85
86**/
87UINT8
88EFIAPI
89PciRead8 (
90 IN UINTN Address
91 )
92{
93 return mRunningOnQ35 ?
94 PciExpressRead8 (Address) :
95 PciCf8Read8 (Address);
96}
97
98/**
99 Writes an 8-bit PCI configuration register.
100
101 Writes the 8-bit PCI configuration register specified by Address with the
102 value specified by Value. Value is returned. This function must guarantee
103 that all PCI read and write operations are serialized.
104
105 If Address > 0x0FFFFFFF, then ASSERT().
106
107 @param Address The address that encodes the PCI Bus, Device, Function and
108 Register.
109 @param Value The value to write.
110
111 @return The value written to the PCI configuration register.
112
113**/
114UINT8
115EFIAPI
116PciWrite8 (
117 IN UINTN Address,
118 IN UINT8 Value
119 )
120{
121 return mRunningOnQ35 ?
122 PciExpressWrite8 (Address, Value) :
123 PciCf8Write8 (Address, Value);
124}
125
126/**
127 Performs a bitwise OR of an 8-bit PCI configuration register with
128 an 8-bit value.
129
130 Reads the 8-bit PCI configuration register specified by Address, performs a
131 bitwise OR between the read result and the value specified by
132 OrData, and writes the result to the 8-bit PCI configuration register
133 specified by Address. The value written to the PCI configuration register is
134 returned. This function must guarantee that all PCI read and write operations
135 are serialized.
136
137 If Address > 0x0FFFFFFF, then ASSERT().
138
139 @param Address The address that encodes the PCI Bus, Device, Function and
140 Register.
141 @param OrData The value to OR with the PCI configuration register.
142
143 @return The value written back to the PCI configuration register.
144
145**/
146UINT8
147EFIAPI
148PciOr8 (
149 IN UINTN Address,
150 IN UINT8 OrData
151 )
152{
153 return mRunningOnQ35 ?
154 PciExpressOr8 (Address, OrData) :
155 PciCf8Or8 (Address, OrData);
156}
157
158/**
159 Performs a bitwise AND of an 8-bit PCI configuration register with an 8-bit
160 value.
161
162 Reads the 8-bit PCI configuration register specified by Address, performs a
163 bitwise AND between the read result and the value specified by AndData, and
164 writes the result to the 8-bit PCI configuration register specified by
165 Address. The value written to the PCI configuration register is returned.
166 This function must guarantee that all PCI read and write operations are
167 serialized.
168
169 If Address > 0x0FFFFFFF, then ASSERT().
170
171 @param Address The address that encodes the PCI Bus, Device, Function and
172 Register.
173 @param AndData The value to AND with the PCI configuration register.
174
175 @return The value written back to the PCI configuration register.
176
177**/
178UINT8
179EFIAPI
180PciAnd8 (
181 IN UINTN Address,
182 IN UINT8 AndData
183 )
184{
185 return mRunningOnQ35 ?
186 PciExpressAnd8 (Address, AndData) :
187 PciCf8And8 (Address, AndData);
188}
189
190/**
191 Performs a bitwise AND of an 8-bit PCI configuration register with an 8-bit
192 value, followed a bitwise OR with another 8-bit value.
193
194 Reads the 8-bit PCI configuration register specified by Address, performs a
195 bitwise AND between the read result and the value specified by AndData,
196 performs a bitwise OR between the result of the AND operation and
197 the value specified by OrData, and writes the result to the 8-bit PCI
198 configuration register specified by Address. The value written to the PCI
199 configuration register is returned. This function must guarantee that all PCI
200 read and write operations are serialized.
201
202 If Address > 0x0FFFFFFF, then ASSERT().
203
204 @param Address The address that encodes the PCI Bus, Device, Function and
205 Register.
206 @param AndData The value to AND with the PCI configuration register.
207 @param OrData The value to OR with the result of the AND operation.
208
209 @return The value written back to the PCI configuration register.
210
211**/
212UINT8
213EFIAPI
214PciAndThenOr8 (
215 IN UINTN Address,
216 IN UINT8 AndData,
217 IN UINT8 OrData
218 )
219{
220 return mRunningOnQ35 ?
221 PciExpressAndThenOr8 (Address, AndData, OrData) :
222 PciCf8AndThenOr8 (Address, AndData, OrData);
223}
224
225/**
226 Reads a bit field of a PCI configuration register.
227
228 Reads the bit field in an 8-bit PCI configuration register. The bit field is
229 specified by the StartBit and the EndBit. The value of the bit field is
230 returned.
231
232 If Address > 0x0FFFFFFF, then ASSERT().
233 If StartBit is greater than 7, then ASSERT().
234 If EndBit is greater than 7, then ASSERT().
235 If EndBit is less than StartBit, then ASSERT().
236
237 @param Address The PCI configuration register to read.
238 @param StartBit The ordinal of the least significant bit in the bit field.
239 Range 0..7.
240 @param EndBit The ordinal of the most significant bit in the bit field.
241 Range 0..7.
242
243 @return The value of the bit field read from the PCI configuration register.
244
245**/
246UINT8
247EFIAPI
248PciBitFieldRead8 (
249 IN UINTN Address,
250 IN UINTN StartBit,
251 IN UINTN EndBit
252 )
253{
254 return mRunningOnQ35 ?
255 PciExpressBitFieldRead8 (Address, StartBit, EndBit) :
256 PciCf8BitFieldRead8 (Address, StartBit, EndBit);
257}
258
259/**
260 Writes a bit field to a PCI configuration register.
261
262 Writes Value to the bit field of the PCI configuration register. The bit
263 field is specified by the StartBit and the EndBit. All other bits in the
264 destination PCI configuration register are preserved. The new value of the
265 8-bit register is returned.
266
267 If Address > 0x0FFFFFFF, then ASSERT().
268 If StartBit is greater than 7, then ASSERT().
269 If EndBit is greater than 7, then ASSERT().
270 If EndBit is less than StartBit, then ASSERT().
271 If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
272
273 @param Address The PCI configuration register to write.
274 @param StartBit The ordinal of the least significant bit in the bit field.
275 Range 0..7.
276 @param EndBit The ordinal of the most significant bit in the bit field.
277 Range 0..7.
278 @param Value The new value of the bit field.
279
280 @return The value written back to the PCI configuration register.
281
282**/
283UINT8
284EFIAPI
285PciBitFieldWrite8 (
286 IN UINTN Address,
287 IN UINTN StartBit,
288 IN UINTN EndBit,
289 IN UINT8 Value
290 )
291{
292 return mRunningOnQ35 ?
293 PciExpressBitFieldWrite8 (Address, StartBit, EndBit, Value) :
294 PciCf8BitFieldWrite8 (Address, StartBit, EndBit, Value);
295}
296
297/**
298 Reads a bit field in an 8-bit PCI configuration, performs a bitwise OR, and
299 writes the result back to the bit field in the 8-bit port.
300
301 Reads the 8-bit PCI configuration register specified by Address, performs a
302 bitwise OR between the read result and the value specified by
303 OrData, and writes the result to the 8-bit PCI configuration register
304 specified by Address. The value written to the PCI configuration register is
305 returned. This function must guarantee that all PCI read and write operations
306 are serialized. Extra left bits in OrData are stripped.
307
308 If Address > 0x0FFFFFFF, then ASSERT().
309 If StartBit is greater than 7, then ASSERT().
310 If EndBit is greater than 7, then ASSERT().
311 If EndBit is less than StartBit, then ASSERT().
312 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
313
314 @param Address The PCI configuration register to write.
315 @param StartBit The ordinal of the least significant bit in the bit field.
316 Range 0..7.
317 @param EndBit The ordinal of the most significant bit in the bit field.
318 Range 0..7.
319 @param OrData The value to OR with the PCI configuration register.
320
321 @return The value written back to the PCI configuration register.
322
323**/
324UINT8
325EFIAPI
326PciBitFieldOr8 (
327 IN UINTN Address,
328 IN UINTN StartBit,
329 IN UINTN EndBit,
330 IN UINT8 OrData
331 )
332{
333 return mRunningOnQ35 ?
334 PciExpressBitFieldOr8 (Address, StartBit, EndBit, OrData) :
335 PciCf8BitFieldOr8 (Address, StartBit, EndBit, OrData);
336}
337
338/**
339 Reads a bit field in an 8-bit PCI configuration register, performs a bitwise
340 AND, and writes the result back to the bit field in the 8-bit register.
341
342 Reads the 8-bit PCI configuration register specified by Address, performs a
343 bitwise AND between the read result and the value specified by AndData, and
344 writes the result to the 8-bit PCI configuration register specified by
345 Address. The value written to the PCI configuration register is returned.
346 This function must guarantee that all PCI read and write operations are
347 serialized. Extra left bits in AndData are stripped.
348
349 If Address > 0x0FFFFFFF, then ASSERT().
350 If StartBit is greater than 7, then ASSERT().
351 If EndBit is greater than 7, then ASSERT().
352 If EndBit is less than StartBit, then ASSERT().
353 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
354
355 @param Address The PCI configuration register to write.
356 @param StartBit The ordinal of the least significant bit in the bit field.
357 Range 0..7.
358 @param EndBit The ordinal of the most significant bit in the bit field.
359 Range 0..7.
360 @param AndData The value to AND with the PCI configuration register.
361
362 @return The value written back to the PCI configuration register.
363
364**/
365UINT8
366EFIAPI
367PciBitFieldAnd8 (
368 IN UINTN Address,
369 IN UINTN StartBit,
370 IN UINTN EndBit,
371 IN UINT8 AndData
372 )
373{
374 return mRunningOnQ35 ?
375 PciExpressBitFieldAnd8 (Address, StartBit, EndBit, AndData) :
376 PciCf8BitFieldAnd8 (Address, StartBit, EndBit, AndData);
377}
378
379/**
380 Reads a bit field in an 8-bit port, performs a bitwise AND followed by a
381 bitwise OR, and writes the result back to the bit field in the
382 8-bit port.
383
384 Reads the 8-bit PCI configuration register specified by Address, performs a
385 bitwise AND followed by a bitwise OR between the read result and
386 the value specified by AndData, and writes the result to the 8-bit PCI
387 configuration register specified by Address. The value written to the PCI
388 configuration register is returned. This function must guarantee that all PCI
389 read and write operations are serialized. Extra left bits in both AndData and
390 OrData are stripped.
391
392 If Address > 0x0FFFFFFF, then ASSERT().
393 If StartBit is greater than 7, then ASSERT().
394 If EndBit is greater than 7, then ASSERT().
395 If EndBit is less than StartBit, then ASSERT().
396 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
397 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
398
399 @param Address The PCI configuration register to write.
400 @param StartBit The ordinal of the least significant bit in the bit field.
401 Range 0..7.
402 @param EndBit The ordinal of the most significant bit in the bit field.
403 Range 0..7.
404 @param AndData The value to AND with the PCI configuration register.
405 @param OrData The value to OR with the result of the AND operation.
406
407 @return The value written back to the PCI configuration register.
408
409**/
410UINT8
411EFIAPI
412PciBitFieldAndThenOr8 (
413 IN UINTN Address,
414 IN UINTN StartBit,
415 IN UINTN EndBit,
416 IN UINT8 AndData,
417 IN UINT8 OrData
418 )
419{
420 return mRunningOnQ35 ?
421 PciExpressBitFieldAndThenOr8 (Address, StartBit, EndBit, AndData, OrData) :
422 PciCf8BitFieldAndThenOr8 (Address, StartBit, EndBit, AndData, OrData);
423}
424
425/**
426 Reads a 16-bit PCI configuration register.
427
428 Reads and returns the 16-bit PCI configuration register specified by Address.
429 This function must guarantee that all PCI read and write operations are
430 serialized.
431
432 If Address > 0x0FFFFFFF, then ASSERT().
433 If Address is not aligned on a 16-bit boundary, then ASSERT().
434
435 @param Address The address that encodes the PCI Bus, Device, Function and
436 Register.
437
438 @return The read value from the PCI configuration register.
439
440**/
441UINT16
442EFIAPI
443PciRead16 (
444 IN UINTN Address
445 )
446{
447 return mRunningOnQ35 ?
448 PciExpressRead16 (Address) :
449 PciCf8Read16 (Address);
450}
451
452/**
453 Writes a 16-bit PCI configuration register.
454
455 Writes the 16-bit PCI configuration register specified by Address with the
456 value specified by Value. Value is returned. This function must guarantee
457 that all PCI read and write operations are serialized.
458
459 If Address > 0x0FFFFFFF, then ASSERT().
460 If Address is not aligned on a 16-bit boundary, then ASSERT().
461
462 @param Address The address that encodes the PCI Bus, Device, Function and
463 Register.
464 @param Value The value to write.
465
466 @return The value written to the PCI configuration register.
467
468**/
469UINT16
470EFIAPI
471PciWrite16 (
472 IN UINTN Address,
473 IN UINT16 Value
474 )
475{
476 return mRunningOnQ35 ?
477 PciExpressWrite16 (Address, Value) :
478 PciCf8Write16 (Address, Value);
479}
480
481/**
482 Performs a bitwise OR of a 16-bit PCI configuration register with
483 a 16-bit value.
484
485 Reads the 16-bit PCI configuration register specified by Address, performs a
486 bitwise OR between the read result and the value specified by
487 OrData, and writes the result to the 16-bit PCI configuration register
488 specified by Address. The value written to the PCI configuration register is
489 returned. This function must guarantee that all PCI read and write operations
490 are serialized.
491
492 If Address > 0x0FFFFFFF, then ASSERT().
493 If Address is not aligned on a 16-bit boundary, then ASSERT().
494
495 @param Address The address that encodes the PCI Bus, Device, Function and
496 Register.
497 @param OrData The value to OR with the PCI configuration register.
498
499 @return The value written back to the PCI configuration register.
500
501**/
502UINT16
503EFIAPI
504PciOr16 (
505 IN UINTN Address,
506 IN UINT16 OrData
507 )
508{
509 return mRunningOnQ35 ?
510 PciExpressOr16 (Address, OrData) :
511 PciCf8Or16 (Address, OrData);
512}
513
514/**
515 Performs a bitwise AND of a 16-bit PCI configuration register with a 16-bit
516 value.
517
518 Reads the 16-bit PCI configuration register specified by Address, performs a
519 bitwise AND between the read result and the value specified by AndData, and
520 writes the result to the 16-bit PCI configuration register specified by
521 Address. The value written to the PCI configuration register is returned.
522 This function must guarantee that all PCI read and write operations are
523 serialized.
524
525 If Address > 0x0FFFFFFF, then ASSERT().
526 If Address is not aligned on a 16-bit boundary, then ASSERT().
527
528 @param Address The address that encodes the PCI Bus, Device, Function and
529 Register.
530 @param AndData The value to AND with the PCI configuration register.
531
532 @return The value written back to the PCI configuration register.
533
534**/
535UINT16
536EFIAPI
537PciAnd16 (
538 IN UINTN Address,
539 IN UINT16 AndData
540 )
541{
542 return mRunningOnQ35 ?
543 PciExpressAnd16 (Address, AndData) :
544 PciCf8And16 (Address, AndData);
545}
546
547/**
548 Performs a bitwise AND of a 16-bit PCI configuration register with a 16-bit
549 value, followed a bitwise OR with another 16-bit value.
550
551 Reads the 16-bit PCI configuration register specified by Address, performs a
552 bitwise AND between the read result and the value specified by AndData,
553 performs a bitwise OR between the result of the AND operation and
554 the value specified by OrData, and writes the result to the 16-bit PCI
555 configuration register specified by Address. The value written to the PCI
556 configuration register is returned. This function must guarantee that all PCI
557 read and write operations are serialized.
558
559 If Address > 0x0FFFFFFF, then ASSERT().
560 If Address is not aligned on a 16-bit boundary, then ASSERT().
561
562 @param Address The address that encodes the PCI Bus, Device, Function and
563 Register.
564 @param AndData The value to AND with the PCI configuration register.
565 @param OrData The value to OR with the result of the AND operation.
566
567 @return The value written back to the PCI configuration register.
568
569**/
570UINT16
571EFIAPI
572PciAndThenOr16 (
573 IN UINTN Address,
574 IN UINT16 AndData,
575 IN UINT16 OrData
576 )
577{
578 return mRunningOnQ35 ?
579 PciExpressAndThenOr16 (Address, AndData, OrData) :
580 PciCf8AndThenOr16 (Address, AndData, OrData);
581}
582
583/**
584 Reads a bit field of a PCI configuration register.
585
586 Reads the bit field in a 16-bit PCI configuration register. The bit field is
587 specified by the StartBit and the EndBit. The value of the bit field is
588 returned.
589
590 If Address > 0x0FFFFFFF, then ASSERT().
591 If Address is not aligned on a 16-bit boundary, then ASSERT().
592 If StartBit is greater than 15, then ASSERT().
593 If EndBit is greater than 15, then ASSERT().
594 If EndBit is less than StartBit, then ASSERT().
595
596 @param Address The PCI configuration register to read.
597 @param StartBit The ordinal of the least significant bit in the bit field.
598 Range 0..15.
599 @param EndBit The ordinal of the most significant bit in the bit field.
600 Range 0..15.
601
602 @return The value of the bit field read from the PCI configuration register.
603
604**/
605UINT16
606EFIAPI
607PciBitFieldRead16 (
608 IN UINTN Address,
609 IN UINTN StartBit,
610 IN UINTN EndBit
611 )
612{
613 return mRunningOnQ35 ?
614 PciExpressBitFieldRead16 (Address, StartBit, EndBit) :
615 PciCf8BitFieldRead16 (Address, StartBit, EndBit);
616}
617
618/**
619 Writes a bit field to a PCI configuration register.
620
621 Writes Value to the bit field of the PCI configuration register. The bit
622 field is specified by the StartBit and the EndBit. All other bits in the
623 destination PCI configuration register are preserved. The new value of the
624 16-bit register is returned.
625
626 If Address > 0x0FFFFFFF, then ASSERT().
627 If Address is not aligned on a 16-bit boundary, then ASSERT().
628 If StartBit is greater than 15, then ASSERT().
629 If EndBit is greater than 15, then ASSERT().
630 If EndBit is less than StartBit, then ASSERT().
631 If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
632
633 @param Address The PCI configuration register to write.
634 @param StartBit The ordinal of the least significant bit in the bit field.
635 Range 0..15.
636 @param EndBit The ordinal of the most significant bit in the bit field.
637 Range 0..15.
638 @param Value The new value of the bit field.
639
640 @return The value written back to the PCI configuration register.
641
642**/
643UINT16
644EFIAPI
645PciBitFieldWrite16 (
646 IN UINTN Address,
647 IN UINTN StartBit,
648 IN UINTN EndBit,
649 IN UINT16 Value
650 )
651{
652 return mRunningOnQ35 ?
653 PciExpressBitFieldWrite16 (Address, StartBit, EndBit, Value) :
654 PciCf8BitFieldWrite16 (Address, StartBit, EndBit, Value);
655}
656
657/**
658 Reads a bit field in a 16-bit PCI configuration, performs a bitwise OR, and
659 writes the result back to the bit field in the 16-bit port.
660
661 Reads the 16-bit PCI configuration register specified by Address, performs a
662 bitwise OR between the read result and the value specified by
663 OrData, and writes the result to the 16-bit PCI configuration register
664 specified by Address. The value written to the PCI configuration register is
665 returned. This function must guarantee that all PCI read and write operations
666 are serialized. Extra left bits in OrData are stripped.
667
668 If Address > 0x0FFFFFFF, then ASSERT().
669 If Address is not aligned on a 16-bit boundary, then ASSERT().
670 If StartBit is greater than 15, then ASSERT().
671 If EndBit is greater than 15, then ASSERT().
672 If EndBit is less than StartBit, then ASSERT().
673 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
674
675 @param Address The PCI configuration register to write.
676 @param StartBit The ordinal of the least significant bit in the bit field.
677 Range 0..15.
678 @param EndBit The ordinal of the most significant bit in the bit field.
679 Range 0..15.
680 @param OrData The value to OR with the PCI configuration register.
681
682 @return The value written back to the PCI configuration register.
683
684**/
685UINT16
686EFIAPI
687PciBitFieldOr16 (
688 IN UINTN Address,
689 IN UINTN StartBit,
690 IN UINTN EndBit,
691 IN UINT16 OrData
692 )
693{
694 return mRunningOnQ35 ?
695 PciExpressBitFieldOr16 (Address, StartBit, EndBit, OrData) :
696 PciCf8BitFieldOr16 (Address, StartBit, EndBit, OrData);
697}
698
699/**
700 Reads a bit field in a 16-bit PCI configuration register, performs a bitwise
701 AND, and writes the result back to the bit field in the 16-bit register.
702
703 Reads the 16-bit PCI configuration register specified by Address, performs a
704 bitwise AND between the read result and the value specified by AndData, and
705 writes the result to the 16-bit PCI configuration register specified by
706 Address. The value written to the PCI configuration register is returned.
707 This function must guarantee that all PCI read and write operations are
708 serialized. Extra left bits in AndData are stripped.
709
710 If Address > 0x0FFFFFFF, then ASSERT().
711 If Address is not aligned on a 16-bit boundary, then ASSERT().
712 If StartBit is greater than 15, then ASSERT().
713 If EndBit is greater than 15, then ASSERT().
714 If EndBit is less than StartBit, then ASSERT().
715 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
716
717 @param Address The PCI configuration register to write.
718 @param StartBit The ordinal of the least significant bit in the bit field.
719 Range 0..15.
720 @param EndBit The ordinal of the most significant bit in the bit field.
721 Range 0..15.
722 @param AndData The value to AND with the PCI configuration register.
723
724 @return The value written back to the PCI configuration register.
725
726**/
727UINT16
728EFIAPI
729PciBitFieldAnd16 (
730 IN UINTN Address,
731 IN UINTN StartBit,
732 IN UINTN EndBit,
733 IN UINT16 AndData
734 )
735{
736 return mRunningOnQ35 ?
737 PciExpressBitFieldAnd16 (Address, StartBit, EndBit, AndData) :
738 PciCf8BitFieldAnd16 (Address, StartBit, EndBit, AndData);
739}
740
741/**
742 Reads a bit field in a 16-bit port, performs a bitwise AND followed by a
743 bitwise OR, and writes the result back to the bit field in the
744 16-bit port.
745
746 Reads the 16-bit PCI configuration register specified by Address, performs a
747 bitwise AND followed by a bitwise OR between the read result and
748 the value specified by AndData, and writes the result to the 16-bit PCI
749 configuration register specified by Address. The value written to the PCI
750 configuration register is returned. This function must guarantee that all PCI
751 read and write operations are serialized. Extra left bits in both AndData and
752 OrData are stripped.
753
754 If Address > 0x0FFFFFFF, then ASSERT().
755 If Address is not aligned on a 16-bit boundary, then ASSERT().
756 If StartBit is greater than 15, then ASSERT().
757 If EndBit is greater than 15, then ASSERT().
758 If EndBit is less than StartBit, then ASSERT().
759 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
760 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
761
762 @param Address The PCI configuration register to write.
763 @param StartBit The ordinal of the least significant bit in the bit field.
764 Range 0..15.
765 @param EndBit The ordinal of the most significant bit in the bit field.
766 Range 0..15.
767 @param AndData The value to AND with the PCI configuration register.
768 @param OrData The value to OR with the result of the AND operation.
769
770 @return The value written back to the PCI configuration register.
771
772**/
773UINT16
774EFIAPI
775PciBitFieldAndThenOr16 (
776 IN UINTN Address,
777 IN UINTN StartBit,
778 IN UINTN EndBit,
779 IN UINT16 AndData,
780 IN UINT16 OrData
781 )
782{
783 return mRunningOnQ35 ?
784 PciExpressBitFieldAndThenOr16 (Address, StartBit, EndBit, AndData, OrData) :
785 PciCf8BitFieldAndThenOr16 (Address, StartBit, EndBit, AndData, OrData);
786}
787
788/**
789 Reads a 32-bit PCI configuration register.
790
791 Reads and returns the 32-bit PCI configuration register specified by Address.
792 This function must guarantee that all PCI read and write operations are
793 serialized.
794
795 If Address > 0x0FFFFFFF, then ASSERT().
796 If Address is not aligned on a 32-bit boundary, then ASSERT().
797
798 @param Address The address that encodes the PCI Bus, Device, Function and
799 Register.
800
801 @return The read value from the PCI configuration register.
802
803**/
804UINT32
805EFIAPI
806PciRead32 (
807 IN UINTN Address
808 )
809{
810 return mRunningOnQ35 ?
811 PciExpressRead32 (Address) :
812 PciCf8Read32 (Address);
813}
814
815/**
816 Writes a 32-bit PCI configuration register.
817
818 Writes the 32-bit PCI configuration register specified by Address with the
819 value specified by Value. Value is returned. This function must guarantee
820 that all PCI read and write operations are serialized.
821
822 If Address > 0x0FFFFFFF, then ASSERT().
823 If Address is not aligned on a 32-bit boundary, then ASSERT().
824
825 @param Address The address that encodes the PCI Bus, Device, Function and
826 Register.
827 @param Value The value to write.
828
829 @return The value written to the PCI configuration register.
830
831**/
832UINT32
833EFIAPI
834PciWrite32 (
835 IN UINTN Address,
836 IN UINT32 Value
837 )
838{
839 return mRunningOnQ35 ?
840 PciExpressWrite32 (Address, Value) :
841 PciCf8Write32 (Address, Value);
842}
843
844/**
845 Performs a bitwise OR of a 32-bit PCI configuration register with
846 a 32-bit value.
847
848 Reads the 32-bit PCI configuration register specified by Address, performs a
849 bitwise OR between the read result and the value specified by
850 OrData, and writes the result to the 32-bit PCI configuration register
851 specified by Address. The value written to the PCI configuration register is
852 returned. This function must guarantee that all PCI read and write operations
853 are serialized.
854
855 If Address > 0x0FFFFFFF, then ASSERT().
856 If Address is not aligned on a 32-bit boundary, then ASSERT().
857
858 @param Address The address that encodes the PCI Bus, Device, Function and
859 Register.
860 @param OrData The value to OR with the PCI configuration register.
861
862 @return The value written back to the PCI configuration register.
863
864**/
865UINT32
866EFIAPI
867PciOr32 (
868 IN UINTN Address,
869 IN UINT32 OrData
870 )
871{
872 return mRunningOnQ35 ?
873 PciExpressOr32 (Address, OrData) :
874 PciCf8Or32 (Address, OrData);
875}
876
877/**
878 Performs a bitwise AND of a 32-bit PCI configuration register with a 32-bit
879 value.
880
881 Reads the 32-bit PCI configuration register specified by Address, performs a
882 bitwise AND between the read result and the value specified by AndData, and
883 writes the result to the 32-bit PCI configuration register specified by
884 Address. The value written to the PCI configuration register is returned.
885 This function must guarantee that all PCI read and write operations are
886 serialized.
887
888 If Address > 0x0FFFFFFF, then ASSERT().
889 If Address is not aligned on a 32-bit boundary, then ASSERT().
890
891 @param Address The address that encodes the PCI Bus, Device, Function and
892 Register.
893 @param AndData The value to AND with the PCI configuration register.
894
895 @return The value written back to the PCI configuration register.
896
897**/
898UINT32
899EFIAPI
900PciAnd32 (
901 IN UINTN Address,
902 IN UINT32 AndData
903 )
904{
905 return mRunningOnQ35 ?
906 PciExpressAnd32 (Address, AndData) :
907 PciCf8And32 (Address, AndData);
908}
909
910/**
911 Performs a bitwise AND of a 32-bit PCI configuration register with a 32-bit
912 value, followed a bitwise OR with another 32-bit value.
913
914 Reads the 32-bit PCI configuration register specified by Address, performs a
915 bitwise AND between the read result and the value specified by AndData,
916 performs a bitwise OR between the result of the AND operation and
917 the value specified by OrData, and writes the result to the 32-bit PCI
918 configuration register specified by Address. The value written to the PCI
919 configuration register is returned. This function must guarantee that all PCI
920 read and write operations are serialized.
921
922 If Address > 0x0FFFFFFF, then ASSERT().
923 If Address is not aligned on a 32-bit boundary, then ASSERT().
924
925 @param Address The address that encodes the PCI Bus, Device, Function and
926 Register.
927 @param AndData The value to AND with the PCI configuration register.
928 @param OrData The value to OR with the result of the AND operation.
929
930 @return The value written back to the PCI configuration register.
931
932**/
933UINT32
934EFIAPI
935PciAndThenOr32 (
936 IN UINTN Address,
937 IN UINT32 AndData,
938 IN UINT32 OrData
939 )
940{
941 return mRunningOnQ35 ?
942 PciExpressAndThenOr32 (Address, AndData, OrData) :
943 PciCf8AndThenOr32 (Address, AndData, OrData);
944}
945
946/**
947 Reads a bit field of a PCI configuration register.
948
949 Reads the bit field in a 32-bit PCI configuration register. The bit field is
950 specified by the StartBit and the EndBit. The value of the bit field is
951 returned.
952
953 If Address > 0x0FFFFFFF, then ASSERT().
954 If Address is not aligned on a 32-bit boundary, then ASSERT().
955 If StartBit is greater than 31, then ASSERT().
956 If EndBit is greater than 31, then ASSERT().
957 If EndBit is less than StartBit, then ASSERT().
958
959 @param Address The PCI configuration register to read.
960 @param StartBit The ordinal of the least significant bit in the bit field.
961 Range 0..31.
962 @param EndBit The ordinal of the most significant bit in the bit field.
963 Range 0..31.
964
965 @return The value of the bit field read from the PCI configuration register.
966
967**/
968UINT32
969EFIAPI
970PciBitFieldRead32 (
971 IN UINTN Address,
972 IN UINTN StartBit,
973 IN UINTN EndBit
974 )
975{
976 return mRunningOnQ35 ?
977 PciExpressBitFieldRead32 (Address, StartBit, EndBit) :
978 PciCf8BitFieldRead32 (Address, StartBit, EndBit);
979}
980
981/**
982 Writes a bit field to a PCI configuration register.
983
984 Writes Value to the bit field of the PCI configuration register. The bit
985 field is specified by the StartBit and the EndBit. All other bits in the
986 destination PCI configuration register are preserved. The new value of the
987 32-bit register is returned.
988
989 If Address > 0x0FFFFFFF, then ASSERT().
990 If Address is not aligned on a 32-bit boundary, then ASSERT().
991 If StartBit is greater than 31, then ASSERT().
992 If EndBit is greater than 31, then ASSERT().
993 If EndBit is less than StartBit, then ASSERT().
994 If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
995
996 @param Address The PCI configuration register to write.
997 @param StartBit The ordinal of the least significant bit in the bit field.
998 Range 0..31.
999 @param EndBit The ordinal of the most significant bit in the bit field.
1000 Range 0..31.
1001 @param Value The new value of the bit field.
1002
1003 @return The value written back to the PCI configuration register.
1004
1005**/
1006UINT32
1007EFIAPI
1008PciBitFieldWrite32 (
1009 IN UINTN Address,
1010 IN UINTN StartBit,
1011 IN UINTN EndBit,
1012 IN UINT32 Value
1013 )
1014{
1015 return mRunningOnQ35 ?
1016 PciExpressBitFieldWrite32 (Address, StartBit, EndBit, Value) :
1017 PciCf8BitFieldWrite32 (Address, StartBit, EndBit, Value);
1018}
1019
1020/**
1021 Reads a bit field in a 32-bit PCI configuration, performs a bitwise OR, and
1022 writes the result back to the bit field in the 32-bit port.
1023
1024 Reads the 32-bit PCI configuration register specified by Address, performs a
1025 bitwise OR between the read result and the value specified by
1026 OrData, and writes the result to the 32-bit PCI configuration register
1027 specified by Address. The value written to the PCI configuration register is
1028 returned. This function must guarantee that all PCI read and write operations
1029 are serialized. Extra left bits in OrData are stripped.
1030
1031 If Address > 0x0FFFFFFF, then ASSERT().
1032 If Address is not aligned on a 32-bit boundary, then ASSERT().
1033 If StartBit is greater than 31, then ASSERT().
1034 If EndBit is greater than 31, then ASSERT().
1035 If EndBit is less than StartBit, then ASSERT().
1036 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
1037
1038 @param Address The PCI configuration register to write.
1039 @param StartBit The ordinal of the least significant bit in the bit field.
1040 Range 0..31.
1041 @param EndBit The ordinal of the most significant bit in the bit field.
1042 Range 0..31.
1043 @param OrData The value to OR with the PCI configuration register.
1044
1045 @return The value written back to the PCI configuration register.
1046
1047**/
1048UINT32
1049EFIAPI
1050PciBitFieldOr32 (
1051 IN UINTN Address,
1052 IN UINTN StartBit,
1053 IN UINTN EndBit,
1054 IN UINT32 OrData
1055 )
1056{
1057 return mRunningOnQ35 ?
1058 PciExpressBitFieldOr32 (Address, StartBit, EndBit, OrData) :
1059 PciCf8BitFieldOr32 (Address, StartBit, EndBit, OrData);
1060}
1061
1062/**
1063 Reads a bit field in a 32-bit PCI configuration register, performs a bitwise
1064 AND, and writes the result back to the bit field in the 32-bit register.
1065
1066 Reads the 32-bit PCI configuration register specified by Address, performs a
1067 bitwise AND between the read result and the value specified by AndData, and
1068 writes the result to the 32-bit PCI configuration register specified by
1069 Address. The value written to the PCI configuration register is returned.
1070 This function must guarantee that all PCI read and write operations are
1071 serialized. Extra left bits in AndData are stripped.
1072
1073 If Address > 0x0FFFFFFF, then ASSERT().
1074 If Address is not aligned on a 32-bit boundary, then ASSERT().
1075 If StartBit is greater than 31, then ASSERT().
1076 If EndBit is greater than 31, then ASSERT().
1077 If EndBit is less than StartBit, then ASSERT().
1078 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
1079
1080 @param Address The PCI configuration register to write.
1081 @param StartBit The ordinal of the least significant bit in the bit field.
1082 Range 0..31.
1083 @param EndBit The ordinal of the most significant bit in the bit field.
1084 Range 0..31.
1085 @param AndData The value to AND with the PCI configuration register.
1086
1087 @return The value written back to the PCI configuration register.
1088
1089**/
1090UINT32
1091EFIAPI
1092PciBitFieldAnd32 (
1093 IN UINTN Address,
1094 IN UINTN StartBit,
1095 IN UINTN EndBit,
1096 IN UINT32 AndData
1097 )
1098{
1099 return mRunningOnQ35 ?
1100 PciExpressBitFieldAnd32 (Address, StartBit, EndBit, AndData) :
1101 PciCf8BitFieldAnd32 (Address, StartBit, EndBit, AndData);
1102}
1103
1104/**
1105 Reads a bit field in a 32-bit port, performs a bitwise AND followed by a
1106 bitwise OR, and writes the result back to the bit field in the
1107 32-bit port.
1108
1109 Reads the 32-bit PCI configuration register specified by Address, performs a
1110 bitwise AND followed by a bitwise OR between the read result and
1111 the value specified by AndData, and writes the result to the 32-bit PCI
1112 configuration register specified by Address. The value written to the PCI
1113 configuration register is returned. This function must guarantee that all PCI
1114 read and write operations are serialized. Extra left bits in both AndData and
1115 OrData are stripped.
1116
1117 If Address > 0x0FFFFFFF, then ASSERT().
1118 If Address is not aligned on a 32-bit boundary, then ASSERT().
1119 If StartBit is greater than 31, then ASSERT().
1120 If EndBit is greater than 31, then ASSERT().
1121 If EndBit is less than StartBit, then ASSERT().
1122 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
1123 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
1124
1125 @param Address The PCI configuration register to write.
1126 @param StartBit The ordinal of the least significant bit in the bit field.
1127 Range 0..31.
1128 @param EndBit The ordinal of the most significant bit in the bit field.
1129 Range 0..31.
1130 @param AndData The value to AND with the PCI configuration register.
1131 @param OrData The value to OR with the result of the AND operation.
1132
1133 @return The value written back to the PCI configuration register.
1134
1135**/
1136UINT32
1137EFIAPI
1138PciBitFieldAndThenOr32 (
1139 IN UINTN Address,
1140 IN UINTN StartBit,
1141 IN UINTN EndBit,
1142 IN UINT32 AndData,
1143 IN UINT32 OrData
1144 )
1145{
1146 return mRunningOnQ35 ?
1147 PciExpressBitFieldAndThenOr32 (Address, StartBit, EndBit, AndData, OrData) :
1148 PciCf8BitFieldAndThenOr32 (Address, StartBit, EndBit, AndData, OrData);
1149}
1150
1151/**
1152 Reads a range of PCI configuration registers into a caller supplied buffer.
1153
1154 Reads the range of PCI configuration registers specified by StartAddress and
1155 Size into the buffer specified by Buffer. This function only allows the PCI
1156 configuration registers from a single PCI function to be read. Size is
1157 returned. When possible 32-bit PCI configuration read cycles are used to read
1158 from StartAddress to StartAddress + Size. Due to alignment restrictions, 8-bit
1159 and 16-bit PCI configuration read cycles may be used at the beginning and the
1160 end of the range.
1161
1162 If StartAddress > 0x0FFFFFFF, then ASSERT().
1163 If ((StartAddress & 0xFFF) + Size) > 0x1000, then ASSERT().
1164 If Size > 0 and Buffer is NULL, then ASSERT().
1165
1166 @param StartAddress The starting address that encodes the PCI Bus, Device,
1167 Function and Register.
1168 @param Size The size in bytes of the transfer.
1169 @param Buffer The pointer to a buffer receiving the data read.
1170
1171 @return Size
1172
1173**/
1174UINTN
1175EFIAPI
1176PciReadBuffer (
1177 IN UINTN StartAddress,
1178 IN UINTN Size,
1179 OUT VOID *Buffer
1180 )
1181{
1182 return mRunningOnQ35 ?
1183 PciExpressReadBuffer (StartAddress, Size, Buffer) :
1184 PciCf8ReadBuffer (StartAddress, Size, Buffer);
1185}
1186
1187/**
1188 Copies the data in a caller supplied buffer to a specified range of PCI
1189 configuration space.
1190
1191 Writes the range of PCI configuration registers specified by StartAddress and
1192 Size from the buffer specified by Buffer. This function only allows the PCI
1193 configuration registers from a single PCI function to be written. Size is
1194 returned. When possible 32-bit PCI configuration write cycles are used to
1195 write from StartAddress to StartAddress + Size. Due to alignment restrictions,
1196 8-bit and 16-bit PCI configuration write cycles may be used at the beginning
1197 and the end of the range.
1198
1199 If StartAddress > 0x0FFFFFFF, then ASSERT().
1200 If ((StartAddress & 0xFFF) + Size) > 0x1000, then ASSERT().
1201 If Size > 0 and Buffer is NULL, then ASSERT().
1202
1203 @param StartAddress The starting address that encodes the PCI Bus, Device,
1204 Function and Register.
1205 @param Size The size in bytes of the transfer.
1206 @param Buffer The pointer to a buffer containing the data to write.
1207
1208 @return Size written to StartAddress.
1209
1210**/
1211UINTN
1212EFIAPI
1213PciWriteBuffer (
1214 IN UINTN StartAddress,
1215 IN UINTN Size,
1216 IN VOID *Buffer
1217 )
1218{
1219 return mRunningOnQ35 ?
1220 PciExpressWriteBuffer (StartAddress, Size, Buffer) :
1221 PciCf8WriteBuffer (StartAddress, Size, Buffer);
1222}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette