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