]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/DxeRuntimePciExpressLib/PciExpressLib.c
MdePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdePkg / Library / DxeRuntimePciExpressLib / PciExpressLib.c
1 /** @file
2 Functions in this library instance make use of MMIO functions in IoLib to
3 access memory mapped PCI configuration space.
4
5 All assertions for I/O operations are handled in MMIO functions in the IoLib
6 Library.
7
8 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
9 SPDX-License-Identifier: BSD-2-Clause-Patent
10
11 **/
12
13
14 #include <PiDxe.h>
15
16 #include <Guid/EventGroup.h>
17
18 #include <Library/BaseLib.h>
19 #include <Library/PciExpressLib.h>
20 #include <Library/IoLib.h>
21 #include <Library/DebugLib.h>
22 #include <Library/PcdLib.h>
23 #include <Library/MemoryAllocationLib.h>
24 #include <Library/UefiBootServicesTableLib.h>
25 #include <Library/DxeServicesTableLib.h>
26 #include <Library/UefiRuntimeLib.h>
27
28 ///
29 /// Define table for mapping PCI Express MMIO physical addresses to virtual addresses at OS runtime
30 ///
31 typedef struct {
32 UINTN PhysicalAddress;
33 UINTN VirtualAddress;
34 } PCI_EXPRESS_RUNTIME_REGISTRATION_TABLE;
35
36 ///
37 /// Set Virtual Address Map Event
38 ///
39 EFI_EVENT mDxeRuntimePciExpressLibVirtualNotifyEvent = NULL;
40
41 ///
42 /// Module global that contains the base physical address of the PCI Express MMIO range.
43 ///
44 UINTN mDxeRuntimePciExpressLibPciExpressBaseAddress = 0;
45
46 ///
47 /// The number of PCI devices that have been registered for runtime access.
48 ///
49 UINTN mDxeRuntimePciExpressLibNumberOfRuntimeRanges = 0;
50
51 ///
52 /// The table of PCI devices that have been registered for runtime access.
53 ///
54 PCI_EXPRESS_RUNTIME_REGISTRATION_TABLE *mDxeRuntimePciExpressLibRegistrationTable = NULL;
55
56 ///
57 /// The table index of the most recent virtual address lookup.
58 ///
59 UINTN mDxeRuntimePciExpressLibLastRuntimeRange = 0;
60
61
62 /**
63 Convert the physical PCI Express MMIO addresses for all registered PCI devices
64 to virtual addresses.
65
66 @param[in] Event The event that is being processed.
67 @param[in] Context The Event Context.
68 **/
69 VOID
70 EFIAPI
71 DxeRuntimePciExpressLibVirtualNotify (
72 IN EFI_EVENT Event,
73 IN VOID *Context
74 )
75 {
76 UINTN Index;
77
78 //
79 // If there have been no runtime registrations, then just return
80 //
81 if (mDxeRuntimePciExpressLibRegistrationTable == NULL) {
82 return;
83 }
84
85 //
86 // Convert physical addresses associated with the set of registered PCI devices to
87 // virtual addresses.
88 //
89 for (Index = 0; Index < mDxeRuntimePciExpressLibNumberOfRuntimeRanges; Index++) {
90 EfiConvertPointer (0, (VOID **) &(mDxeRuntimePciExpressLibRegistrationTable[Index].VirtualAddress));
91 }
92
93 //
94 // Convert table pointer that is allocated from EfiRuntimeServicesData to a virtual address.
95 //
96 EfiConvertPointer (0, (VOID **) &mDxeRuntimePciExpressLibRegistrationTable);
97 }
98
99 /**
100 The constructor function caches the PCI Express Base Address and creates a
101 Set Virtual Address Map event to convert physical address to virtual addresses.
102
103 @param ImageHandle The firmware allocated handle for the EFI image.
104 @param SystemTable A pointer to the EFI System Table.
105
106 @retval EFI_SUCCESS The constructor completed successfully.
107 @retval Other value The constructor did not complete successfully.
108
109 **/
110 EFI_STATUS
111 EFIAPI
112 DxeRuntimePciExpressLibConstructor (
113 IN EFI_HANDLE ImageHandle,
114 IN EFI_SYSTEM_TABLE *SystemTable
115 )
116 {
117 EFI_STATUS Status;
118
119 //
120 // Cache the physical address of the PCI Express MMIO range into a module global variable
121 //
122 mDxeRuntimePciExpressLibPciExpressBaseAddress = (UINTN) PcdGet64 (PcdPciExpressBaseAddress);
123
124 //
125 // Register SetVirtualAddressMap () notify function
126 //
127 Status = gBS->CreateEventEx (
128 EVT_NOTIFY_SIGNAL,
129 TPL_NOTIFY,
130 DxeRuntimePciExpressLibVirtualNotify,
131 NULL,
132 &gEfiEventVirtualAddressChangeGuid,
133 &mDxeRuntimePciExpressLibVirtualNotifyEvent
134 );
135 ASSERT_EFI_ERROR (Status);
136
137 return Status;
138 }
139
140 /**
141 The destructor function frees any allocated buffers and closes the Set Virtual
142 Address Map event.
143
144 @param ImageHandle The firmware allocated handle for the EFI image.
145 @param SystemTable A pointer to the EFI System Table.
146
147 @retval EFI_SUCCESS The destructor completed successfully.
148 @retval Other value The destructor did not complete successfully.
149
150 **/
151 EFI_STATUS
152 EFIAPI
153 DxeRuntimePciExpressLibDestructor (
154 IN EFI_HANDLE ImageHandle,
155 IN EFI_SYSTEM_TABLE *SystemTable
156 )
157 {
158 EFI_STATUS Status;
159
160 //
161 // If one or more PCI devices have been registered for runtime access, then
162 // free the registration table.
163 //
164 if (mDxeRuntimePciExpressLibRegistrationTable != NULL) {
165 FreePool (mDxeRuntimePciExpressLibRegistrationTable);
166 }
167
168 //
169 // Close the Set Virtual Address Map event
170 //
171 Status = gBS->CloseEvent (mDxeRuntimePciExpressLibVirtualNotifyEvent);
172 ASSERT_EFI_ERROR (Status);
173
174 return Status;
175 }
176
177 /**
178 Gets the base address of PCI Express.
179
180 This internal functions retrieves PCI Express Base Address via a PCD entry
181 PcdPciExpressBaseAddress.
182
183 @param Address The address that encodes the PCI Bus, Device, Function and Register.
184 @return The base address of PCI Express.
185
186 **/
187 UINTN
188 GetPciExpressAddress (
189 IN UINTN Address
190 )
191 {
192 UINTN Index;
193
194 //
195 // Make sure Address is valid
196 //
197 ASSERT (((Address) & ~0xfffffff) == 0);
198
199 //
200 // Convert Address to a physical address in the MMIO PCI Express range
201 //
202 Address += mDxeRuntimePciExpressLibPciExpressBaseAddress;
203
204 //
205 // If SetVirtualAddressMap() has not been called, then just return the physical address
206 //
207 if (!EfiGoneVirtual ()) {
208 return Address;
209 }
210
211 //
212 // See if there is a physical address match at the exact same index as the last address match
213 //
214 if (mDxeRuntimePciExpressLibRegistrationTable[mDxeRuntimePciExpressLibLastRuntimeRange].PhysicalAddress == (Address & (~0x00000fff))) {
215 //
216 // Convert the physical address to a virtual address and return the virtual address
217 //
218 return (Address & 0x00000fff) + mDxeRuntimePciExpressLibRegistrationTable[mDxeRuntimePciExpressLibLastRuntimeRange].VirtualAddress;
219 }
220
221 //
222 // Search the entire table for a physical address match
223 //
224 for (Index = 0; Index < mDxeRuntimePciExpressLibNumberOfRuntimeRanges; Index++) {
225 if (mDxeRuntimePciExpressLibRegistrationTable[Index].PhysicalAddress == (Address & (~0x00000fff))) {
226 //
227 // Cache the matching index value
228 //
229 mDxeRuntimePciExpressLibLastRuntimeRange = Index;
230 //
231 // Convert the physical address to a virtual address and return the virtual address
232 //
233 return (Address & 0x00000fff) + mDxeRuntimePciExpressLibRegistrationTable[Index].VirtualAddress;
234 }
235 }
236
237 //
238 // No match was found. This is a critical error at OS runtime, so ASSERT() and force a breakpoint.
239 //
240 ASSERT (FALSE);
241 CpuBreakpoint();
242
243 //
244 // Return the physical address
245 //
246 return Address;
247 }
248
249 /**
250 Registers a PCI device so PCI configuration registers may be accessed after
251 SetVirtualAddressMap().
252
253 Registers the PCI device specified by Address so all the PCI configuration
254 registers associated with that PCI device may be accessed after SetVirtualAddressMap()
255 is called.
256
257 If Address > 0x0FFFFFFF, then ASSERT().
258
259 @param Address The address that encodes the PCI Bus, Device, Function and
260 Register.
261
262 @retval RETURN_SUCCESS The PCI device was registered for runtime access.
263 @retval RETURN_UNSUPPORTED An attempt was made to call this function
264 after ExitBootServices().
265 @retval RETURN_UNSUPPORTED The resources required to access the PCI device
266 at runtime could not be mapped.
267 @retval RETURN_OUT_OF_RESOURCES There are not enough resources available to
268 complete the registration.
269
270 **/
271 RETURN_STATUS
272 EFIAPI
273 PciExpressRegisterForRuntimeAccess (
274 IN UINTN Address
275 )
276 {
277 EFI_STATUS Status;
278 EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor;
279 UINTN Index;
280 VOID *NewTable;
281
282 //
283 // Return an error if this function is called after ExitBootServices().
284 //
285 if (EfiAtRuntime ()) {
286 return RETURN_UNSUPPORTED;
287 }
288
289 //
290 // Make sure Address is valid
291 //
292 ASSERT (((Address) & ~0xfffffff) == 0);
293
294 //
295 // Convert Address to a physical address in the MMIO PCI Express range
296 // at the beginning of the PCI Configuration header for the specified
297 // PCI Bus/Dev/Func
298 //
299 Address = GetPciExpressAddress (Address & 0x0ffff000);
300
301 //
302 // See if Address has already been registerd for runtime access
303 //
304 for (Index = 0; Index < mDxeRuntimePciExpressLibNumberOfRuntimeRanges; Index++) {
305 if (mDxeRuntimePciExpressLibRegistrationTable[Index].PhysicalAddress == Address) {
306 return RETURN_SUCCESS;
307 }
308 }
309
310 //
311 // Get the GCD Memory Descriptor for the PCI Express Bus/Dev/Func specified by Address
312 //
313 Status = gDS->GetMemorySpaceDescriptor (Address, &Descriptor);
314 if (EFI_ERROR (Status)) {
315 return RETURN_UNSUPPORTED;
316 }
317
318 //
319 // Mark the 4KB region for the PCI Express Bus/Dev/Func as EFI_RUNTIME_MEMORY so the OS
320 // will allocate a virtual address range for the 4KB PCI Configuration Header.
321 //
322 Status = gDS->SetMemorySpaceAttributes (Address, 0x1000, Descriptor.Attributes | EFI_MEMORY_RUNTIME);
323 if (EFI_ERROR (Status)) {
324 return RETURN_UNSUPPORTED;
325 }
326
327 //
328 // Grow the size of the registration table
329 //
330 NewTable = ReallocateRuntimePool (
331 (mDxeRuntimePciExpressLibNumberOfRuntimeRanges + 0) * sizeof (PCI_EXPRESS_RUNTIME_REGISTRATION_TABLE),
332 (mDxeRuntimePciExpressLibNumberOfRuntimeRanges + 1) * sizeof (PCI_EXPRESS_RUNTIME_REGISTRATION_TABLE),
333 mDxeRuntimePciExpressLibRegistrationTable
334 );
335 if (NewTable == NULL) {
336 return RETURN_OUT_OF_RESOURCES;
337 }
338 mDxeRuntimePciExpressLibRegistrationTable = NewTable;
339 mDxeRuntimePciExpressLibRegistrationTable[mDxeRuntimePciExpressLibNumberOfRuntimeRanges].PhysicalAddress = Address;
340 mDxeRuntimePciExpressLibRegistrationTable[mDxeRuntimePciExpressLibNumberOfRuntimeRanges].VirtualAddress = Address;
341 mDxeRuntimePciExpressLibNumberOfRuntimeRanges++;
342
343 return RETURN_SUCCESS;
344 }
345
346
347 /**
348 Reads an 8-bit PCI configuration register.
349
350 Reads and returns the 8-bit PCI configuration register specified by Address.
351 This function must guarantee that all PCI read and write operations are
352 serialized.
353
354 If Address > 0x0FFFFFFF, then ASSERT().
355
356 @param Address The address that encodes the PCI Bus, Device, Function and
357 Register.
358
359 @return The read value from the PCI configuration register.
360
361 **/
362 UINT8
363 EFIAPI
364 PciExpressRead8 (
365 IN UINTN Address
366 )
367 {
368 return MmioRead8 (GetPciExpressAddress (Address));
369 }
370
371 /**
372 Writes an 8-bit PCI configuration register.
373
374 Writes the 8-bit PCI configuration register specified by Address with the
375 value specified by Value. Value is returned. This function must guarantee
376 that all PCI read and write operations are serialized.
377
378 If Address > 0x0FFFFFFF, then ASSERT().
379
380 @param Address The address that encodes the PCI Bus, Device, Function and
381 Register.
382 @param Value The value to write.
383
384 @return The value written to the PCI configuration register.
385
386 **/
387 UINT8
388 EFIAPI
389 PciExpressWrite8 (
390 IN UINTN Address,
391 IN UINT8 Value
392 )
393 {
394 return MmioWrite8 (GetPciExpressAddress (Address), Value);
395 }
396
397 /**
398 Performs a bitwise OR of an 8-bit PCI configuration register with
399 an 8-bit value.
400
401 Reads the 8-bit PCI configuration register specified by Address, performs a
402 bitwise OR between the read result and the value specified by
403 OrData, and writes the result to the 8-bit PCI configuration register
404 specified by Address. The value written to the PCI configuration register is
405 returned. This function must guarantee that all PCI read and write operations
406 are serialized.
407
408 If Address > 0x0FFFFFFF, then ASSERT().
409
410 @param Address The address that encodes the PCI Bus, Device, Function and
411 Register.
412 @param OrData The value to OR with the PCI configuration register.
413
414 @return The value written back to the PCI configuration register.
415
416 **/
417 UINT8
418 EFIAPI
419 PciExpressOr8 (
420 IN UINTN Address,
421 IN UINT8 OrData
422 )
423 {
424 return MmioOr8 (GetPciExpressAddress (Address), OrData);
425 }
426
427 /**
428 Performs a bitwise AND of an 8-bit PCI configuration register with an 8-bit
429 value.
430
431 Reads the 8-bit PCI configuration register specified by Address, performs a
432 bitwise AND between the read result and the value specified by AndData, and
433 writes the result to the 8-bit PCI configuration register specified by
434 Address. The value written to the PCI configuration register is returned.
435 This function must guarantee that all PCI read and write operations are
436 serialized.
437
438 If Address > 0x0FFFFFFF, then ASSERT().
439
440 @param Address The address that encodes the PCI Bus, Device, Function and
441 Register.
442 @param AndData The value to AND with the PCI configuration register.
443
444 @return The value written back to the PCI configuration register.
445
446 **/
447 UINT8
448 EFIAPI
449 PciExpressAnd8 (
450 IN UINTN Address,
451 IN UINT8 AndData
452 )
453 {
454 return MmioAnd8 (GetPciExpressAddress (Address), AndData);
455 }
456
457 /**
458 Performs a bitwise AND of an 8-bit PCI configuration register with an 8-bit
459 value, followed a bitwise OR with another 8-bit value.
460
461 Reads the 8-bit PCI configuration register specified by Address, performs a
462 bitwise AND between the read result and the value specified by AndData,
463 performs a bitwise OR between the result of the AND operation and
464 the value specified by OrData, and writes the result to the 8-bit PCI
465 configuration register specified by Address. The value written to the PCI
466 configuration register is returned. This function must guarantee that all PCI
467 read and write operations are serialized.
468
469 If Address > 0x0FFFFFFF, then ASSERT().
470
471 @param Address The address that encodes the PCI Bus, Device, Function and
472 Register.
473 @param AndData The value to AND with the PCI configuration register.
474 @param OrData The value to OR with the result of the AND operation.
475
476 @return The value written back to the PCI configuration register.
477
478 **/
479 UINT8
480 EFIAPI
481 PciExpressAndThenOr8 (
482 IN UINTN Address,
483 IN UINT8 AndData,
484 IN UINT8 OrData
485 )
486 {
487 return MmioAndThenOr8 (
488 GetPciExpressAddress (Address),
489 AndData,
490 OrData
491 );
492 }
493
494 /**
495 Reads a bit field of a PCI configuration register.
496
497 Reads the bit field in an 8-bit PCI configuration register. The bit field is
498 specified by the StartBit and the EndBit. The value of the bit field is
499 returned.
500
501 If Address > 0x0FFFFFFF, then ASSERT().
502 If StartBit is greater than 7, then ASSERT().
503 If EndBit is greater than 7, then ASSERT().
504 If EndBit is less than StartBit, then ASSERT().
505
506 @param Address The PCI configuration register to read.
507 @param StartBit The ordinal of the least significant bit in the bit field.
508 Range 0..7.
509 @param EndBit The ordinal of the most significant bit in the bit field.
510 Range 0..7.
511
512 @return The value of the bit field read from the PCI configuration register.
513
514 **/
515 UINT8
516 EFIAPI
517 PciExpressBitFieldRead8 (
518 IN UINTN Address,
519 IN UINTN StartBit,
520 IN UINTN EndBit
521 )
522 {
523 return MmioBitFieldRead8 (
524 GetPciExpressAddress (Address),
525 StartBit,
526 EndBit
527 );
528 }
529
530 /**
531 Writes a bit field to a PCI configuration register.
532
533 Writes Value to the bit field of the PCI configuration register. The bit
534 field is specified by the StartBit and the EndBit. All other bits in the
535 destination PCI configuration register are preserved. The new value of the
536 8-bit register is returned.
537
538 If Address > 0x0FFFFFFF, then ASSERT().
539 If StartBit is greater than 7, then ASSERT().
540 If EndBit is greater than 7, then ASSERT().
541 If EndBit is less than StartBit, then ASSERT().
542 If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
543
544 @param Address The PCI configuration register to write.
545 @param StartBit The ordinal of the least significant bit in the bit field.
546 Range 0..7.
547 @param EndBit The ordinal of the most significant bit in the bit field.
548 Range 0..7.
549 @param Value The new value of the bit field.
550
551 @return The value written back to the PCI configuration register.
552
553 **/
554 UINT8
555 EFIAPI
556 PciExpressBitFieldWrite8 (
557 IN UINTN Address,
558 IN UINTN StartBit,
559 IN UINTN EndBit,
560 IN UINT8 Value
561 )
562 {
563 return MmioBitFieldWrite8 (
564 GetPciExpressAddress (Address),
565 StartBit,
566 EndBit,
567 Value
568 );
569 }
570
571 /**
572 Reads a bit field in an 8-bit PCI configuration, performs a bitwise OR, and
573 writes the result back to the bit field in the 8-bit port.
574
575 Reads the 8-bit PCI configuration register specified by Address, performs a
576 bitwise OR between the read result and the value specified by
577 OrData, and writes the result to the 8-bit PCI configuration register
578 specified by Address. The value written to the PCI configuration register is
579 returned. This function must guarantee that all PCI read and write operations
580 are serialized. Extra left bits in OrData are stripped.
581
582 If Address > 0x0FFFFFFF, then ASSERT().
583 If StartBit is greater than 7, then ASSERT().
584 If EndBit is greater than 7, then ASSERT().
585 If EndBit is less than StartBit, then ASSERT().
586 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
587
588 @param Address The PCI configuration register to write.
589 @param StartBit The ordinal of the least significant bit in the bit field.
590 Range 0..7.
591 @param EndBit The ordinal of the most significant bit in the bit field.
592 Range 0..7.
593 @param OrData The value to OR with the PCI configuration register.
594
595 @return The value written back to the PCI configuration register.
596
597 **/
598 UINT8
599 EFIAPI
600 PciExpressBitFieldOr8 (
601 IN UINTN Address,
602 IN UINTN StartBit,
603 IN UINTN EndBit,
604 IN UINT8 OrData
605 )
606 {
607 return MmioBitFieldOr8 (
608 GetPciExpressAddress (Address),
609 StartBit,
610 EndBit,
611 OrData
612 );
613 }
614
615 /**
616 Reads a bit field in an 8-bit PCI configuration register, performs a bitwise
617 AND, and writes the result back to the bit field in the 8-bit register.
618
619 Reads the 8-bit PCI configuration register specified by Address, performs a
620 bitwise AND between the read result and the value specified by AndData, and
621 writes the result to the 8-bit PCI configuration register specified by
622 Address. The value written to the PCI configuration register is returned.
623 This function must guarantee that all PCI read and write operations are
624 serialized. Extra left bits in AndData are stripped.
625
626 If Address > 0x0FFFFFFF, then ASSERT().
627 If StartBit is greater than 7, then ASSERT().
628 If EndBit is greater than 7, then ASSERT().
629 If EndBit is less than StartBit, then ASSERT().
630 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
631
632 @param Address The PCI configuration register to write.
633 @param StartBit The ordinal of the least significant bit in the bit field.
634 Range 0..7.
635 @param EndBit The ordinal of the most significant bit in the bit field.
636 Range 0..7.
637 @param AndData The value to AND with the PCI configuration register.
638
639 @return The value written back to the PCI configuration register.
640
641 **/
642 UINT8
643 EFIAPI
644 PciExpressBitFieldAnd8 (
645 IN UINTN Address,
646 IN UINTN StartBit,
647 IN UINTN EndBit,
648 IN UINT8 AndData
649 )
650 {
651 return MmioBitFieldAnd8 (
652 GetPciExpressAddress (Address),
653 StartBit,
654 EndBit,
655 AndData
656 );
657 }
658
659 /**
660 Reads a bit field in an 8-bit port, performs a bitwise AND followed by a
661 bitwise OR, and writes the result back to the bit field in the
662 8-bit port.
663
664 Reads the 8-bit PCI configuration register specified by Address, performs a
665 bitwise AND followed by a bitwise OR between the read result and
666 the value specified by AndData, and writes the result to the 8-bit PCI
667 configuration register specified by Address. The value written to the PCI
668 configuration register is returned. This function must guarantee that all PCI
669 read and write operations are serialized. Extra left bits in both AndData and
670 OrData are stripped.
671
672 If Address > 0x0FFFFFFF, then ASSERT().
673 If StartBit is greater than 7, then ASSERT().
674 If EndBit is greater than 7, then ASSERT().
675 If EndBit is less than StartBit, then ASSERT().
676 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
677 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
678
679 @param Address The PCI configuration register to write.
680 @param StartBit The ordinal of the least significant bit in the bit field.
681 Range 0..7.
682 @param EndBit The ordinal of the most significant bit in the bit field.
683 Range 0..7.
684 @param AndData The value to AND with the PCI configuration register.
685 @param OrData The value to OR with the result of the AND operation.
686
687 @return The value written back to the PCI configuration register.
688
689 **/
690 UINT8
691 EFIAPI
692 PciExpressBitFieldAndThenOr8 (
693 IN UINTN Address,
694 IN UINTN StartBit,
695 IN UINTN EndBit,
696 IN UINT8 AndData,
697 IN UINT8 OrData
698 )
699 {
700 return MmioBitFieldAndThenOr8 (
701 GetPciExpressAddress (Address),
702 StartBit,
703 EndBit,
704 AndData,
705 OrData
706 );
707 }
708
709 /**
710 Reads a 16-bit PCI configuration register.
711
712 Reads and returns the 16-bit PCI configuration register specified by Address.
713 This function must guarantee that all PCI read and write operations are
714 serialized.
715
716 If Address > 0x0FFFFFFF, then ASSERT().
717 If Address is not aligned on a 16-bit boundary, then ASSERT().
718
719 @param Address The address that encodes the PCI Bus, Device, Function and
720 Register.
721
722 @return The read value from the PCI configuration register.
723
724 **/
725 UINT16
726 EFIAPI
727 PciExpressRead16 (
728 IN UINTN Address
729 )
730 {
731 return MmioRead16 (GetPciExpressAddress (Address));
732 }
733
734 /**
735 Writes a 16-bit PCI configuration register.
736
737 Writes the 16-bit PCI configuration register specified by Address with the
738 value specified by Value. Value is returned. This function must guarantee
739 that all PCI read and write operations are serialized.
740
741 If Address > 0x0FFFFFFF, then ASSERT().
742 If Address is not aligned on a 16-bit boundary, then ASSERT().
743
744 @param Address The address that encodes the PCI Bus, Device, Function and
745 Register.
746 @param Value The value to write.
747
748 @return The value written to the PCI configuration register.
749
750 **/
751 UINT16
752 EFIAPI
753 PciExpressWrite16 (
754 IN UINTN Address,
755 IN UINT16 Value
756 )
757 {
758 return MmioWrite16 (GetPciExpressAddress (Address), Value);
759 }
760
761 /**
762 Performs a bitwise OR of a 16-bit PCI configuration register with
763 a 16-bit value.
764
765 Reads the 16-bit PCI configuration register specified by Address, performs a
766 bitwise OR between the read result and the value specified by
767 OrData, and writes the result to the 16-bit PCI configuration register
768 specified by Address. The value written to the PCI configuration register is
769 returned. This function must guarantee that all PCI read and write operations
770 are serialized.
771
772 If Address > 0x0FFFFFFF, then ASSERT().
773 If Address is not aligned on a 16-bit boundary, then ASSERT().
774
775 @param Address The address that encodes the PCI Bus, Device, Function and
776 Register.
777 @param OrData The value to OR with the PCI configuration register.
778
779 @return The value written back to the PCI configuration register.
780
781 **/
782 UINT16
783 EFIAPI
784 PciExpressOr16 (
785 IN UINTN Address,
786 IN UINT16 OrData
787 )
788 {
789 return MmioOr16 (GetPciExpressAddress (Address), OrData);
790 }
791
792 /**
793 Performs a bitwise AND of a 16-bit PCI configuration register with a 16-bit
794 value.
795
796 Reads the 16-bit PCI configuration register specified by Address, performs a
797 bitwise AND between the read result and the value specified by AndData, and
798 writes the result to the 16-bit PCI configuration register specified by
799 Address. The value written to the PCI configuration register is returned.
800 This function must guarantee that all PCI read and write operations are
801 serialized.
802
803 If Address > 0x0FFFFFFF, then ASSERT().
804 If Address is not aligned on a 16-bit boundary, then ASSERT().
805
806 @param Address The address that encodes the PCI Bus, Device, Function and
807 Register.
808 @param AndData The value to AND with the PCI configuration register.
809
810 @return The value written back to the PCI configuration register.
811
812 **/
813 UINT16
814 EFIAPI
815 PciExpressAnd16 (
816 IN UINTN Address,
817 IN UINT16 AndData
818 )
819 {
820 return MmioAnd16 (GetPciExpressAddress (Address), AndData);
821 }
822
823 /**
824 Performs a bitwise AND of a 16-bit PCI configuration register with a 16-bit
825 value, followed a bitwise OR with another 16-bit value.
826
827 Reads the 16-bit PCI configuration register specified by Address, performs a
828 bitwise AND between the read result and the value specified by AndData,
829 performs a bitwise OR between the result of the AND operation and
830 the value specified by OrData, and writes the result to the 16-bit PCI
831 configuration register specified by Address. The value written to the PCI
832 configuration register is returned. This function must guarantee that all PCI
833 read and write operations are serialized.
834
835 If Address > 0x0FFFFFFF, then ASSERT().
836 If Address is not aligned on a 16-bit boundary, then ASSERT().
837
838 @param Address The address that encodes the PCI Bus, Device, Function and
839 Register.
840 @param AndData The value to AND with the PCI configuration register.
841 @param OrData The value to OR with the result of the AND operation.
842
843 @return The value written back to the PCI configuration register.
844
845 **/
846 UINT16
847 EFIAPI
848 PciExpressAndThenOr16 (
849 IN UINTN Address,
850 IN UINT16 AndData,
851 IN UINT16 OrData
852 )
853 {
854 return MmioAndThenOr16 (
855 GetPciExpressAddress (Address),
856 AndData,
857 OrData
858 );
859 }
860
861 /**
862 Reads a bit field of a PCI configuration register.
863
864 Reads the bit field in a 16-bit PCI configuration register. The bit field is
865 specified by the StartBit and the EndBit. The value of the bit field is
866 returned.
867
868 If Address > 0x0FFFFFFF, then ASSERT().
869 If Address is not aligned on a 16-bit boundary, then ASSERT().
870 If StartBit is greater than 15, then ASSERT().
871 If EndBit is greater than 15, then ASSERT().
872 If EndBit is less than StartBit, then ASSERT().
873
874 @param Address The PCI configuration register to read.
875 @param StartBit The ordinal of the least significant bit in the bit field.
876 Range 0..15.
877 @param EndBit The ordinal of the most significant bit in the bit field.
878 Range 0..15.
879
880 @return The value of the bit field read from the PCI configuration register.
881
882 **/
883 UINT16
884 EFIAPI
885 PciExpressBitFieldRead16 (
886 IN UINTN Address,
887 IN UINTN StartBit,
888 IN UINTN EndBit
889 )
890 {
891 return MmioBitFieldRead16 (
892 GetPciExpressAddress (Address),
893 StartBit,
894 EndBit
895 );
896 }
897
898 /**
899 Writes a bit field to a PCI configuration register.
900
901 Writes Value to the bit field of the PCI configuration register. The bit
902 field is specified by the StartBit and the EndBit. All other bits in the
903 destination PCI configuration register are preserved. The new value of the
904 16-bit register is returned.
905
906 If Address > 0x0FFFFFFF, then ASSERT().
907 If Address is not aligned on a 16-bit boundary, then ASSERT().
908 If StartBit is greater than 15, then ASSERT().
909 If EndBit is greater than 15, then ASSERT().
910 If EndBit is less than StartBit, then ASSERT().
911 If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
912
913 @param Address The PCI configuration register to write.
914 @param StartBit The ordinal of the least significant bit in the bit field.
915 Range 0..15.
916 @param EndBit The ordinal of the most significant bit in the bit field.
917 Range 0..15.
918 @param Value The new value of the bit field.
919
920 @return The value written back to the PCI configuration register.
921
922 **/
923 UINT16
924 EFIAPI
925 PciExpressBitFieldWrite16 (
926 IN UINTN Address,
927 IN UINTN StartBit,
928 IN UINTN EndBit,
929 IN UINT16 Value
930 )
931 {
932 return MmioBitFieldWrite16 (
933 GetPciExpressAddress (Address),
934 StartBit,
935 EndBit,
936 Value
937 );
938 }
939
940 /**
941 Reads a bit field in a 16-bit PCI configuration, performs a bitwise OR, and
942 writes the result back to the bit field in the 16-bit port.
943
944 Reads the 16-bit PCI configuration register specified by Address, performs a
945 bitwise OR between the read result and the value specified by
946 OrData, and writes the result to the 16-bit PCI configuration register
947 specified by Address. The value written to the PCI configuration register is
948 returned. This function must guarantee that all PCI read and write operations
949 are serialized. Extra left bits in OrData are stripped.
950
951 If Address > 0x0FFFFFFF, then ASSERT().
952 If Address is not aligned on a 16-bit boundary, then ASSERT().
953 If StartBit is greater than 15, then ASSERT().
954 If EndBit is greater than 15, then ASSERT().
955 If EndBit is less than StartBit, then ASSERT().
956 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
957
958 @param Address The PCI configuration register to write.
959 @param StartBit The ordinal of the least significant bit in the bit field.
960 Range 0..15.
961 @param EndBit The ordinal of the most significant bit in the bit field.
962 Range 0..15.
963 @param OrData The value to OR with the PCI configuration register.
964
965 @return The value written back to the PCI configuration register.
966
967 **/
968 UINT16
969 EFIAPI
970 PciExpressBitFieldOr16 (
971 IN UINTN Address,
972 IN UINTN StartBit,
973 IN UINTN EndBit,
974 IN UINT16 OrData
975 )
976 {
977 return MmioBitFieldOr16 (
978 GetPciExpressAddress (Address),
979 StartBit,
980 EndBit,
981 OrData
982 );
983 }
984
985 /**
986 Reads a bit field in a 16-bit PCI configuration register, performs a bitwise
987 AND, and writes the result back to the bit field in the 16-bit register.
988
989 Reads the 16-bit PCI configuration register specified by Address, performs a
990 bitwise AND between the read result and the value specified by AndData, and
991 writes the result to the 16-bit PCI configuration register specified by
992 Address. The value written to the PCI configuration register is returned.
993 This function must guarantee that all PCI read and write operations are
994 serialized. Extra left bits in AndData are stripped.
995
996 If Address > 0x0FFFFFFF, then ASSERT().
997 If Address is not aligned on a 16-bit boundary, then ASSERT().
998 If StartBit is greater than 15, then ASSERT().
999 If EndBit is greater than 15, then ASSERT().
1000 If EndBit is less than StartBit, then ASSERT().
1001 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
1002
1003 @param Address The PCI configuration register to write.
1004 @param StartBit The ordinal of the least significant bit in the bit field.
1005 Range 0..15.
1006 @param EndBit The ordinal of the most significant bit in the bit field.
1007 Range 0..15.
1008 @param AndData The value to AND with the PCI configuration register.
1009
1010 @return The value written back to the PCI configuration register.
1011
1012 **/
1013 UINT16
1014 EFIAPI
1015 PciExpressBitFieldAnd16 (
1016 IN UINTN Address,
1017 IN UINTN StartBit,
1018 IN UINTN EndBit,
1019 IN UINT16 AndData
1020 )
1021 {
1022 return MmioBitFieldAnd16 (
1023 GetPciExpressAddress (Address),
1024 StartBit,
1025 EndBit,
1026 AndData
1027 );
1028 }
1029
1030 /**
1031 Reads a bit field in a 16-bit port, performs a bitwise AND followed by a
1032 bitwise OR, and writes the result back to the bit field in the
1033 16-bit port.
1034
1035 Reads the 16-bit PCI configuration register specified by Address, performs a
1036 bitwise AND followed by a bitwise OR between the read result and
1037 the value specified by AndData, and writes the result to the 16-bit PCI
1038 configuration register specified by Address. The value written to the PCI
1039 configuration register is returned. This function must guarantee that all PCI
1040 read and write operations are serialized. Extra left bits in both AndData and
1041 OrData are stripped.
1042
1043 If Address > 0x0FFFFFFF, then ASSERT().
1044 If Address is not aligned on a 16-bit boundary, then ASSERT().
1045 If StartBit is greater than 15, then ASSERT().
1046 If EndBit is greater than 15, then ASSERT().
1047 If EndBit is less than StartBit, then ASSERT().
1048 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
1049 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
1050
1051 @param Address The PCI configuration register to write.
1052 @param StartBit The ordinal of the least significant bit in the bit field.
1053 Range 0..15.
1054 @param EndBit The ordinal of the most significant bit in the bit field.
1055 Range 0..15.
1056 @param AndData The value to AND with the PCI configuration register.
1057 @param OrData The value to OR with the result of the AND operation.
1058
1059 @return The value written back to the PCI configuration register.
1060
1061 **/
1062 UINT16
1063 EFIAPI
1064 PciExpressBitFieldAndThenOr16 (
1065 IN UINTN Address,
1066 IN UINTN StartBit,
1067 IN UINTN EndBit,
1068 IN UINT16 AndData,
1069 IN UINT16 OrData
1070 )
1071 {
1072 return MmioBitFieldAndThenOr16 (
1073 GetPciExpressAddress (Address),
1074 StartBit,
1075 EndBit,
1076 AndData,
1077 OrData
1078 );
1079 }
1080
1081 /**
1082 Reads a 32-bit PCI configuration register.
1083
1084 Reads and returns the 32-bit PCI configuration register specified by Address.
1085 This function must guarantee that all PCI read and write operations are
1086 serialized.
1087
1088 If Address > 0x0FFFFFFF, then ASSERT().
1089 If Address is not aligned on a 32-bit boundary, then ASSERT().
1090
1091 @param Address The address that encodes the PCI Bus, Device, Function and
1092 Register.
1093
1094 @return The read value from the PCI configuration register.
1095
1096 **/
1097 UINT32
1098 EFIAPI
1099 PciExpressRead32 (
1100 IN UINTN Address
1101 )
1102 {
1103 return MmioRead32 (GetPciExpressAddress (Address));
1104 }
1105
1106 /**
1107 Writes a 32-bit PCI configuration register.
1108
1109 Writes the 32-bit PCI configuration register specified by Address with the
1110 value specified by Value. Value is returned. This function must guarantee
1111 that all PCI read and write operations are serialized.
1112
1113 If Address > 0x0FFFFFFF, then ASSERT().
1114 If Address is not aligned on a 32-bit boundary, then ASSERT().
1115
1116 @param Address The address that encodes the PCI Bus, Device, Function and
1117 Register.
1118 @param Value The value to write.
1119
1120 @return The value written to the PCI configuration register.
1121
1122 **/
1123 UINT32
1124 EFIAPI
1125 PciExpressWrite32 (
1126 IN UINTN Address,
1127 IN UINT32 Value
1128 )
1129 {
1130 return MmioWrite32 (GetPciExpressAddress (Address), Value);
1131 }
1132
1133 /**
1134 Performs a bitwise OR of a 32-bit PCI configuration register with
1135 a 32-bit value.
1136
1137 Reads the 32-bit PCI configuration register specified by Address, performs a
1138 bitwise OR between the read result and the value specified by
1139 OrData, and writes the result to the 32-bit PCI configuration register
1140 specified by Address. The value written to the PCI configuration register is
1141 returned. This function must guarantee that all PCI read and write operations
1142 are serialized.
1143
1144 If Address > 0x0FFFFFFF, then ASSERT().
1145 If Address is not aligned on a 32-bit boundary, then ASSERT().
1146
1147 @param Address The address that encodes the PCI Bus, Device, Function and
1148 Register.
1149 @param OrData The value to OR with the PCI configuration register.
1150
1151 @return The value written back to the PCI configuration register.
1152
1153 **/
1154 UINT32
1155 EFIAPI
1156 PciExpressOr32 (
1157 IN UINTN Address,
1158 IN UINT32 OrData
1159 )
1160 {
1161 return MmioOr32 (GetPciExpressAddress (Address), OrData);
1162 }
1163
1164 /**
1165 Performs a bitwise AND of a 32-bit PCI configuration register with a 32-bit
1166 value.
1167
1168 Reads the 32-bit PCI configuration register specified by Address, performs a
1169 bitwise AND between the read result and the value specified by AndData, and
1170 writes the result to the 32-bit PCI configuration register specified by
1171 Address. The value written to the PCI configuration register is returned.
1172 This function must guarantee that all PCI read and write operations are
1173 serialized.
1174
1175 If Address > 0x0FFFFFFF, then ASSERT().
1176 If Address is not aligned on a 32-bit boundary, then ASSERT().
1177
1178 @param Address The address that encodes the PCI Bus, Device, Function and
1179 Register.
1180 @param AndData The value to AND with the PCI configuration register.
1181
1182 @return The value written back to the PCI configuration register.
1183
1184 **/
1185 UINT32
1186 EFIAPI
1187 PciExpressAnd32 (
1188 IN UINTN Address,
1189 IN UINT32 AndData
1190 )
1191 {
1192 return MmioAnd32 (GetPciExpressAddress (Address), AndData);
1193 }
1194
1195 /**
1196 Performs a bitwise AND of a 32-bit PCI configuration register with a 32-bit
1197 value, followed a bitwise OR with another 32-bit value.
1198
1199 Reads the 32-bit PCI configuration register specified by Address, performs a
1200 bitwise AND between the read result and the value specified by AndData,
1201 performs a bitwise OR between the result of the AND operation and
1202 the value specified by OrData, and writes the result to the 32-bit PCI
1203 configuration register specified by Address. The value written to the PCI
1204 configuration register is returned. This function must guarantee that all PCI
1205 read and write operations are serialized.
1206
1207 If Address > 0x0FFFFFFF, then ASSERT().
1208 If Address is not aligned on a 32-bit boundary, then ASSERT().
1209
1210 @param Address The address that encodes the PCI Bus, Device, Function and
1211 Register.
1212 @param AndData The value to AND with the PCI configuration register.
1213 @param OrData The value to OR with the result of the AND operation.
1214
1215 @return The value written back to the PCI configuration register.
1216
1217 **/
1218 UINT32
1219 EFIAPI
1220 PciExpressAndThenOr32 (
1221 IN UINTN Address,
1222 IN UINT32 AndData,
1223 IN UINT32 OrData
1224 )
1225 {
1226 return MmioAndThenOr32 (
1227 GetPciExpressAddress (Address),
1228 AndData,
1229 OrData
1230 );
1231 }
1232
1233 /**
1234 Reads a bit field of a PCI configuration register.
1235
1236 Reads the bit field in a 32-bit PCI configuration register. The bit field is
1237 specified by the StartBit and the EndBit. The value of the bit field is
1238 returned.
1239
1240 If Address > 0x0FFFFFFF, then ASSERT().
1241 If Address is not aligned on a 32-bit boundary, then ASSERT().
1242 If StartBit is greater than 31, then ASSERT().
1243 If EndBit is greater than 31, then ASSERT().
1244 If EndBit is less than StartBit, then ASSERT().
1245
1246 @param Address The PCI configuration register to read.
1247 @param StartBit The ordinal of the least significant bit in the bit field.
1248 Range 0..31.
1249 @param EndBit The ordinal of the most significant bit in the bit field.
1250 Range 0..31.
1251
1252 @return The value of the bit field read from the PCI configuration register.
1253
1254 **/
1255 UINT32
1256 EFIAPI
1257 PciExpressBitFieldRead32 (
1258 IN UINTN Address,
1259 IN UINTN StartBit,
1260 IN UINTN EndBit
1261 )
1262 {
1263 return MmioBitFieldRead32 (
1264 GetPciExpressAddress (Address),
1265 StartBit,
1266 EndBit
1267 );
1268 }
1269
1270 /**
1271 Writes a bit field to a PCI configuration register.
1272
1273 Writes Value to the bit field of the PCI configuration register. The bit
1274 field is specified by the StartBit and the EndBit. All other bits in the
1275 destination PCI configuration register are preserved. The new value of the
1276 32-bit register is returned.
1277
1278 If Address > 0x0FFFFFFF, then ASSERT().
1279 If Address is not aligned on a 32-bit boundary, then ASSERT().
1280 If StartBit is greater than 31, then ASSERT().
1281 If EndBit is greater than 31, then ASSERT().
1282 If EndBit is less than StartBit, then ASSERT().
1283 If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
1284
1285 @param Address The PCI configuration register to write.
1286 @param StartBit The ordinal of the least significant bit in the bit field.
1287 Range 0..31.
1288 @param EndBit The ordinal of the most significant bit in the bit field.
1289 Range 0..31.
1290 @param Value The new value of the bit field.
1291
1292 @return The value written back to the PCI configuration register.
1293
1294 **/
1295 UINT32
1296 EFIAPI
1297 PciExpressBitFieldWrite32 (
1298 IN UINTN Address,
1299 IN UINTN StartBit,
1300 IN UINTN EndBit,
1301 IN UINT32 Value
1302 )
1303 {
1304 return MmioBitFieldWrite32 (
1305 GetPciExpressAddress (Address),
1306 StartBit,
1307 EndBit,
1308 Value
1309 );
1310 }
1311
1312 /**
1313 Reads a bit field in a 32-bit PCI configuration, performs a bitwise OR, and
1314 writes the result back to the bit field in the 32-bit port.
1315
1316 Reads the 32-bit PCI configuration register specified by Address, performs a
1317 bitwise OR between the read result and the value specified by
1318 OrData, and writes the result to the 32-bit PCI configuration register
1319 specified by Address. The value written to the PCI configuration register is
1320 returned. This function must guarantee that all PCI read and write operations
1321 are serialized. Extra left bits in OrData are stripped.
1322
1323 If Address > 0x0FFFFFFF, then ASSERT().
1324 If Address is not aligned on a 32-bit boundary, then ASSERT().
1325 If StartBit is greater than 31, then ASSERT().
1326 If EndBit is greater than 31, then ASSERT().
1327 If EndBit is less than StartBit, then ASSERT().
1328 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
1329
1330 @param Address The PCI configuration register to write.
1331 @param StartBit The ordinal of the least significant bit in the bit field.
1332 Range 0..31.
1333 @param EndBit The ordinal of the most significant bit in the bit field.
1334 Range 0..31.
1335 @param OrData The value to OR with the PCI configuration register.
1336
1337 @return The value written back to the PCI configuration register.
1338
1339 **/
1340 UINT32
1341 EFIAPI
1342 PciExpressBitFieldOr32 (
1343 IN UINTN Address,
1344 IN UINTN StartBit,
1345 IN UINTN EndBit,
1346 IN UINT32 OrData
1347 )
1348 {
1349 return MmioBitFieldOr32 (
1350 GetPciExpressAddress (Address),
1351 StartBit,
1352 EndBit,
1353 OrData
1354 );
1355 }
1356
1357 /**
1358 Reads a bit field in a 32-bit PCI configuration register, performs a bitwise
1359 AND, and writes the result back to the bit field in the 32-bit register.
1360
1361 Reads the 32-bit PCI configuration register specified by Address, performs a
1362 bitwise AND between the read result and the value specified by AndData, and
1363 writes the result to the 32-bit PCI configuration register specified by
1364 Address. The value written to the PCI configuration register is returned.
1365 This function must guarantee that all PCI read and write operations are
1366 serialized. Extra left bits in AndData are stripped.
1367
1368 If Address > 0x0FFFFFFF, then ASSERT().
1369 If Address is not aligned on a 32-bit boundary, then ASSERT().
1370 If StartBit is greater than 31, then ASSERT().
1371 If EndBit is greater than 31, then ASSERT().
1372 If EndBit is less than StartBit, then ASSERT().
1373 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
1374
1375 @param Address The PCI configuration register to write.
1376 @param StartBit The ordinal of the least significant bit in the bit field.
1377 Range 0..31.
1378 @param EndBit The ordinal of the most significant bit in the bit field.
1379 Range 0..31.
1380 @param AndData The value to AND with the PCI configuration register.
1381
1382 @return The value written back to the PCI configuration register.
1383
1384 **/
1385 UINT32
1386 EFIAPI
1387 PciExpressBitFieldAnd32 (
1388 IN UINTN Address,
1389 IN UINTN StartBit,
1390 IN UINTN EndBit,
1391 IN UINT32 AndData
1392 )
1393 {
1394 return MmioBitFieldAnd32 (
1395 GetPciExpressAddress (Address),
1396 StartBit,
1397 EndBit,
1398 AndData
1399 );
1400 }
1401
1402 /**
1403 Reads a bit field in a 32-bit port, performs a bitwise AND followed by a
1404 bitwise OR, and writes the result back to the bit field in the
1405 32-bit port.
1406
1407 Reads the 32-bit PCI configuration register specified by Address, performs a
1408 bitwise AND followed by a bitwise OR between the read result and
1409 the value specified by AndData, and writes the result to the 32-bit PCI
1410 configuration register specified by Address. The value written to the PCI
1411 configuration register is returned. This function must guarantee that all PCI
1412 read and write operations are serialized. Extra left bits in both AndData and
1413 OrData are stripped.
1414
1415 If Address > 0x0FFFFFFF, then ASSERT().
1416 If Address is not aligned on a 32-bit boundary, then ASSERT().
1417 If StartBit is greater than 31, then ASSERT().
1418 If EndBit is greater than 31, then ASSERT().
1419 If EndBit is less than StartBit, then ASSERT().
1420 If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
1421 If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().
1422
1423 @param Address The PCI configuration register to write.
1424 @param StartBit The ordinal of the least significant bit in the bit field.
1425 Range 0..31.
1426 @param EndBit The ordinal of the most significant bit in the bit field.
1427 Range 0..31.
1428 @param AndData The value to AND with the PCI configuration register.
1429 @param OrData The value to OR with the result of the AND operation.
1430
1431 @return The value written back to the PCI configuration register.
1432
1433 **/
1434 UINT32
1435 EFIAPI
1436 PciExpressBitFieldAndThenOr32 (
1437 IN UINTN Address,
1438 IN UINTN StartBit,
1439 IN UINTN EndBit,
1440 IN UINT32 AndData,
1441 IN UINT32 OrData
1442 )
1443 {
1444 return MmioBitFieldAndThenOr32 (
1445 GetPciExpressAddress (Address),
1446 StartBit,
1447 EndBit,
1448 AndData,
1449 OrData
1450 );
1451 }
1452
1453 /**
1454 Reads a range of PCI configuration registers into a caller supplied buffer.
1455
1456 Reads the range of PCI configuration registers specified by StartAddress and
1457 Size into the buffer specified by Buffer. This function only allows the PCI
1458 configuration registers from a single PCI function to be read. Size is
1459 returned. When possible 32-bit PCI configuration read cycles are used to read
1460 from StartAdress to StartAddress + Size. Due to alignment restrictions, 8-bit
1461 and 16-bit PCI configuration read cycles may be used at the beginning and the
1462 end of the range.
1463
1464 If StartAddress > 0x0FFFFFFF, then ASSERT().
1465 If ((StartAddress & 0xFFF) + Size) > 0x1000, then ASSERT().
1466 If Size > 0 and Buffer is NULL, then ASSERT().
1467
1468 @param StartAddress The starting address that encodes the PCI Bus, Device,
1469 Function and Register.
1470 @param Size The size in bytes of the transfer.
1471 @param Buffer The pointer to a buffer receiving the data read.
1472
1473 @return Size read data from StartAddress.
1474
1475 **/
1476 UINTN
1477 EFIAPI
1478 PciExpressReadBuffer (
1479 IN UINTN StartAddress,
1480 IN UINTN Size,
1481 OUT VOID *Buffer
1482 )
1483 {
1484 UINTN ReturnValue;
1485
1486 //
1487 // Make sure Address is valid
1488 //
1489 ASSERT (((StartAddress) & ~0xfffffff) == 0);
1490 ASSERT (((StartAddress & 0xFFF) + Size) <= 0x1000);
1491
1492 if (Size == 0) {
1493 return Size;
1494 }
1495
1496 ASSERT (Buffer != NULL);
1497
1498 //
1499 // Save Size for return
1500 //
1501 ReturnValue = Size;
1502
1503 if ((StartAddress & 1) != 0) {
1504 //
1505 // Read a byte if StartAddress is byte aligned
1506 //
1507 *(volatile UINT8 *)Buffer = PciExpressRead8 (StartAddress);
1508 StartAddress += sizeof (UINT8);
1509 Size -= sizeof (UINT8);
1510 Buffer = (UINT8*)Buffer + 1;
1511 }
1512
1513 if (Size >= sizeof (UINT16) && (StartAddress & 2) != 0) {
1514 //
1515 // Read a word if StartAddress is word aligned
1516 //
1517 WriteUnaligned16 ((UINT16 *) Buffer, (UINT16) PciExpressRead16 (StartAddress));
1518
1519 StartAddress += sizeof (UINT16);
1520 Size -= sizeof (UINT16);
1521 Buffer = (UINT16*)Buffer + 1;
1522 }
1523
1524 while (Size >= sizeof (UINT32)) {
1525 //
1526 // Read as many double words as possible
1527 //
1528 WriteUnaligned32 ((UINT32 *) Buffer, (UINT32) PciExpressRead32 (StartAddress));
1529
1530 StartAddress += sizeof (UINT32);
1531 Size -= sizeof (UINT32);
1532 Buffer = (UINT32*)Buffer + 1;
1533 }
1534
1535 if (Size >= sizeof (UINT16)) {
1536 //
1537 // Read the last remaining word if exist
1538 //
1539 WriteUnaligned16 ((UINT16 *) Buffer, (UINT16) PciExpressRead16 (StartAddress));
1540 StartAddress += sizeof (UINT16);
1541 Size -= sizeof (UINT16);
1542 Buffer = (UINT16*)Buffer + 1;
1543 }
1544
1545 if (Size >= sizeof (UINT8)) {
1546 //
1547 // Read the last remaining byte if exist
1548 //
1549 *(volatile UINT8 *)Buffer = PciExpressRead8 (StartAddress);
1550 }
1551
1552 return ReturnValue;
1553 }
1554
1555 /**
1556 Copies the data in a caller supplied buffer to a specified range of PCI
1557 configuration space.
1558
1559 Writes the range of PCI configuration registers specified by StartAddress and
1560 Size from the buffer specified by Buffer. This function only allows the PCI
1561 configuration registers from a single PCI function to be written. Size is
1562 returned. When possible 32-bit PCI configuration write cycles are used to
1563 write from StartAdress to StartAddress + Size. Due to alignment restrictions,
1564 8-bit and 16-bit PCI configuration write cycles may be used at the beginning
1565 and the end of the range.
1566
1567 If StartAddress > 0x0FFFFFFF, then ASSERT().
1568 If ((StartAddress & 0xFFF) + Size) > 0x1000, then ASSERT().
1569 If Size > 0 and Buffer is NULL, then ASSERT().
1570
1571 @param StartAddress The starting address that encodes the PCI Bus, Device,
1572 Function and Register.
1573 @param Size The size in bytes of the transfer.
1574 @param Buffer The pointer to a buffer containing the data to write.
1575
1576 @return Size written to StartAddress.
1577
1578 **/
1579 UINTN
1580 EFIAPI
1581 PciExpressWriteBuffer (
1582 IN UINTN StartAddress,
1583 IN UINTN Size,
1584 IN VOID *Buffer
1585 )
1586 {
1587 UINTN ReturnValue;
1588
1589 //
1590 // Make sure Address is valid
1591 //
1592 ASSERT (((StartAddress) & ~0xfffffff) == 0);
1593 ASSERT (((StartAddress & 0xFFF) + Size) <= 0x1000);
1594
1595 if (Size == 0) {
1596 return 0;
1597 }
1598
1599 ASSERT (Buffer != NULL);
1600
1601 //
1602 // Save Size for return
1603 //
1604 ReturnValue = Size;
1605
1606 if ((StartAddress & 1) != 0) {
1607 //
1608 // Write a byte if StartAddress is byte aligned
1609 //
1610 PciExpressWrite8 (StartAddress, *(UINT8*)Buffer);
1611 StartAddress += sizeof (UINT8);
1612 Size -= sizeof (UINT8);
1613 Buffer = (UINT8*)Buffer + 1;
1614 }
1615
1616 if (Size >= sizeof (UINT16) && (StartAddress & 2) != 0) {
1617 //
1618 // Write a word if StartAddress is word aligned
1619 //
1620 PciExpressWrite16 (StartAddress, ReadUnaligned16 ((UINT16*)Buffer));
1621 StartAddress += sizeof (UINT16);
1622 Size -= sizeof (UINT16);
1623 Buffer = (UINT16*)Buffer + 1;
1624 }
1625
1626 while (Size >= sizeof (UINT32)) {
1627 //
1628 // Write as many double words as possible
1629 //
1630 PciExpressWrite32 (StartAddress, ReadUnaligned32 ((UINT32*)Buffer));
1631 StartAddress += sizeof (UINT32);
1632 Size -= sizeof (UINT32);
1633 Buffer = (UINT32*)Buffer + 1;
1634 }
1635
1636 if (Size >= sizeof (UINT16)) {
1637 //
1638 // Write the last remaining word if exist
1639 //
1640 PciExpressWrite16 (StartAddress, ReadUnaligned16 ((UINT16*)Buffer));
1641 StartAddress += sizeof (UINT16);
1642 Size -= sizeof (UINT16);
1643 Buffer = (UINT16*)Buffer + 1;
1644 }
1645
1646 if (Size >= sizeof (UINT8)) {
1647 //
1648 // Write the last remaining byte if exist
1649 //
1650 PciExpressWrite8 (StartAddress, *(UINT8*)Buffer);
1651 }
1652
1653 return ReturnValue;
1654 }