@@ -2420,6 +2420,36 @@ CHAR16 *IndicatorTable[] = {
24202420 L"Off"
24212421};
24222422
2423+ /**
2424+ Safe wrapper function for DumpHex that validates PCI configuration space boundaries.
2425+
2426+ This function ensures that hex dumps do not exceed the standard 4KB PCIe configuration
2427+ space boundary (0x1000). If the requested dump would exceed this boundary, it prints
2428+ an error message and truncates the dump size to remain within valid bounds.
2429+
2430+ @param[in] Indent Number of spaces to indent the hex dump output for formatting.
2431+ @param[in] Offset Starting offset within the PCI configuration space to begin dumping.
2432+ @param[in] DataSize Number of bytes to dump. Will be truncated if it exceeds the 4KB boundary.
2433+ @param[in] UserData Pointer to the data buffer containing the PCI configuration space data.
2434+
2435+ **/
2436+ VOID
2437+ PciConfigSpaceDumpHex (
2438+ IN UINTN Indent ,
2439+ IN UINTN Offset ,
2440+ IN UINTN DataSize ,
2441+ IN VOID * UserData
2442+ )
2443+ {
2444+ // Ensure we don't exceed the 4KB config space boundary
2445+ if (Offset + DataSize > 0x1000 ) {
2446+ ShellPrintDefaultEx (L"\nError: Requested dump size exceeds PCIe 4KB configuration space boundary (CurrentOffset: 0x%03X, Size: 0x%03X). Truncating to valid range.\n\n" , Offset , DataSize );
2447+ DataSize = 0x1000 - Offset ;
2448+ }
2449+
2450+ DumpHex (Indent , Offset , DataSize , UserData );
2451+ }
2452+
24232453/**
24242454 Function for 'pci' command.
24252455
@@ -5051,7 +5081,7 @@ PrintInterpretedExtendedCompatibilityLinkControl (
50515081 Header -> RootComplexLinkControl ,
50525082 Header -> RootComplexLinkStatus
50535083 );
5054- DumpHex (
5084+ PciConfigSpaceDumpHex (
50555085 4 ,
50565086 EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8 * )HeaderAddress - (UINT8 * )HeadersBaseAddress ),
50575087 sizeof (PCI_EXPRESS_EXTENDED_CAPABILITIES_INTERNAL_LINK_CONTROL ),
@@ -5083,7 +5113,7 @@ PrintInterpretedExtendedCompatibilityPowerBudgeting (
50835113 Header -> Data ,
50845114 Header -> PowerBudgetCapability
50855115 );
5086- DumpHex (
5116+ PciConfigSpaceDumpHex (
50875117 4 ,
50885118 EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8 * )HeaderAddress - (UINT8 * )HeadersBaseAddress ),
50895119 sizeof (PCI_EXPRESS_EXTENDED_CAPABILITIES_POWER_BUDGETING ),
@@ -5133,7 +5163,7 @@ PrintInterpretedExtendedCompatibilityAcs (
51335163 }
51345164 }
51355165
5136- DumpHex (
5166+ PciConfigSpaceDumpHex (
51375167 4 ,
51385168 EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8 * )HeaderAddress - (UINT8 * )HeadersBaseAddress ),
51395169 sizeof (PCI_EXPRESS_EXTENDED_CAPABILITIES_ACS_EXTENDED ) + (VectorSize / 8 ) - 1 ,
@@ -5164,7 +5194,7 @@ PrintInterpretedExtendedCompatibilityLatencyToleranceReporting (
51645194 Header -> MaxSnoopLatency ,
51655195 Header -> MaxNoSnoopLatency
51665196 );
5167- DumpHex (
5197+ PciConfigSpaceDumpHex (
51685198 4 ,
51695199 EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8 * )HeaderAddress - (UINT8 * )HeadersBaseAddress ),
51705200 sizeof (PCI_EXPRESS_EXTENDED_CAPABILITIES_LATENCE_TOLERANCE_REPORTING ),
@@ -5194,7 +5224,7 @@ PrintInterpretedExtendedCompatibilitySerialNumber (
51945224 gShellDebug1HiiHandle ,
51955225 Header -> SerialNumber
51965226 );
5197- DumpHex (
5227+ PciConfigSpaceDumpHex (
51985228 4 ,
51995229 EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8 * )HeaderAddress - (UINT8 * )HeadersBaseAddress ),
52005230 sizeof (PCI_EXPRESS_EXTENDED_CAPABILITIES_SERIAL_NUMBER ),
@@ -5227,7 +5257,7 @@ PrintInterpretedExtendedCompatibilityRcrb (
52275257 Header -> RcrbCapabilities ,
52285258 Header -> RcrbControl
52295259 );
5230- DumpHex (
5260+ PciConfigSpaceDumpHex (
52315261 4 ,
52325262 EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8 * )HeaderAddress - (UINT8 * )HeadersBaseAddress ),
52335263 sizeof (PCI_EXPRESS_EXTENDED_CAPABILITIES_RCRB_HEADER ),
@@ -5257,7 +5287,7 @@ PrintInterpretedExtendedCompatibilityVendorSpecific (
52575287 gShellDebug1HiiHandle ,
52585288 Header -> VendorSpecificHeader
52595289 );
5260- DumpHex (
5290+ PciConfigSpaceDumpHex (
52615291 4 ,
52625292 EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8 * )HeaderAddress - (UINT8 * )HeadersBaseAddress ),
52635293 PCI_EXPRESS_EXTENDED_CAPABILITY_VENDOR_SPECIFIC_GET_SIZE (Header ),
@@ -5287,7 +5317,7 @@ PrintInterpretedExtendedCompatibilityECEA (
52875317 gShellDebug1HiiHandle ,
52885318 Header -> AssociationBitmap
52895319 );
5290- DumpHex (
5320+ PciConfigSpaceDumpHex (
52915321 4 ,
52925322 EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8 * )HeaderAddress - (UINT8 * )HeadersBaseAddress ),
52935323 sizeof (PCI_EXPRESS_EXTENDED_CAPABILITIES_EVENT_COLLECTOR_ENDPOINT_ASSOCIATION ),
@@ -5318,7 +5348,7 @@ PrintInterpretedExtendedCompatibilityAri (
53185348 Header -> AriCapability ,
53195349 Header -> AriControl
53205350 );
5321- DumpHex (
5351+ PciConfigSpaceDumpHex (
53225352 4 ,
53235353 EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8 * )HeaderAddress - (UINT8 * )HeadersBaseAddress ),
53245354 sizeof (PCI_EXPRESS_EXTENDED_CAPABILITIES_ARI_CAPABILITY ),
@@ -5361,7 +5391,7 @@ PrintInterpretedExtendedCompatibilityDynamicPowerAllocation (
53615391 );
53625392 }
53635393
5364- DumpHex (
5394+ PciConfigSpaceDumpHex (
53655395 4 ,
53665396 EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8 * )HeaderAddress - (UINT8 * )HeadersBaseAddress ),
53675397 sizeof (PCI_EXPRESS_EXTENDED_CAPABILITIES_DYNAMIC_POWER_ALLOCATION ) - 1 + PCI_EXPRESS_EXTENDED_CAPABILITY_DYNAMIC_POWER_ALLOCATION_GET_SUBSTATE_MAX (Header ),
@@ -5402,7 +5432,7 @@ PrintInterpretedExtendedCompatibilityLinkDeclaration (
54025432 );
54035433 }
54045434
5405- DumpHex (
5435+ PciConfigSpaceDumpHex (
54065436 4 ,
54075437 EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8 * )HeaderAddress - (UINT8 * )HeadersBaseAddress ),
54085438 sizeof (PCI_EXPRESS_EXTENDED_CAPABILITIES_LINK_DECLARATION ) + (PCI_EXPRESS_EXTENDED_CAPABILITY_LINK_DECLARATION_GET_LINK_COUNT (Header )- 1 )* sizeof (UINT32 ),
@@ -5449,7 +5479,7 @@ PrintInterpretedExtendedCompatibilityAer (
54495479 Header -> TlpPrefixLog [2 ],
54505480 Header -> TlpPrefixLog [3 ]
54515481 );
5452- DumpHex (
5482+ PciConfigSpaceDumpHex (
54535483 4 ,
54545484 EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8 * )HeaderAddress - (UINT8 * )HeadersBaseAddress ),
54555485 sizeof (PCI_EXPRESS_EXTENDED_CAPABILITIES_ADVANCED_ERROR_REPORTING ),
@@ -5488,7 +5518,7 @@ PrintInterpretedExtendedCompatibilityMulticast (
54885518 Header -> McOverlayBar
54895519 );
54905520
5491- DumpHex (
5521+ PciConfigSpaceDumpHex (
54925522 4 ,
54935523 EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8 * )HeaderAddress - (UINT8 * )HeadersBaseAddress ),
54945524 sizeof (PCI_EXPRESS_EXTENDED_CAPABILITIES_MULTICAST ),
@@ -5539,7 +5569,7 @@ PrintInterpretedExtendedCompatibilityVirtualChannel (
55395569 );
55405570 }
55415571
5542- DumpHex (
5572+ PciConfigSpaceDumpHex (
55435573 4 ,
55445574 EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8 * )HeaderAddress - (UINT8 * )HeadersBaseAddress ),
55455575 sizeof (PCI_EXPRESS_EXTENDED_CAPABILITIES_VIRTUAL_CHANNEL_CAPABILITY )
@@ -5577,7 +5607,7 @@ PrintInterpretedExtendedCompatibilityResizeableBar (
55775607 );
55785608 }
55795609
5580- DumpHex (
5610+ PciConfigSpaceDumpHex (
55815611 4 ,
55825612 EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8 * )HeaderAddress - (UINT8 * )HeadersBaseAddress ),
55835613 (UINT32 )GET_NUMBER_RESIZABLE_BARS (Header ) * sizeof (PCI_EXPRESS_EXTENDED_CAPABILITIES_RESIZABLE_BAR_ENTRY ),
@@ -5609,14 +5639,14 @@ PrintInterpretedExtendedCompatibilityTph (
56095639 Header -> TphRequesterCapability ,
56105640 Header -> TphRequesterControl
56115641 );
5612- DumpHex (
5642+ PciConfigSpaceDumpHex (
56135643 8 ,
56145644 EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8 * )Header -> TphStTable - (UINT8 * )HeadersBaseAddress ),
56155645 GET_TPH_TABLE_SIZE (Header ),
56165646 (VOID * )Header -> TphStTable
56175647 );
56185648
5619- DumpHex (
5649+ PciConfigSpaceDumpHex (
56205650 4 ,
56215651 EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8 * )HeaderAddress - (UINT8 * )HeadersBaseAddress ),
56225652 sizeof (PCI_EXPRESS_EXTENDED_CAPABILITIES_TPH ) + GET_TPH_TABLE_SIZE (Header ) - sizeof (UINT16 ),
@@ -5650,14 +5680,14 @@ PrintInterpretedExtendedCompatibilitySecondary (
56505680 Header -> LinkControl3 .Uint32 ,
56515681 Header -> LaneErrorStatus
56525682 );
5653- DumpHex (
5683+ PciConfigSpaceDumpHex (
56545684 8 ,
56555685 EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8 * )Header -> EqualizationControl - (UINT8 * )HeadersBaseAddress ),
56565686 PciExpressCap -> LinkCapability .Bits .MaxLinkWidth * sizeof (PCI_EXPRESS_REG_LANE_EQUALIZATION_CONTROL ),
56575687 (VOID * )Header -> EqualizationControl
56585688 );
56595689
5660- DumpHex (
5690+ PciConfigSpaceDumpHex (
56615691 4 ,
56625692 EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8 * )HeaderAddress - (UINT8 * )HeadersBaseAddress ),
56635693 sizeof (PCI_EXPRESS_EXTENDED_CAPABILITIES_SECONDARY_PCIE ) - sizeof (Header -> EqualizationControl )
@@ -5691,7 +5721,7 @@ PrintInterpretedExtendedCompatibilityAts (
56915721 Header -> Control .Uint16
56925722 );
56935723
5694- DumpHex (
5724+ PciConfigSpaceDumpHex (
56955725 4 ,
56965726 EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8 * )HeaderAddress - (UINT8 * )HeadersBaseAddress ),
56975727 sizeof (PCI_EXPRESS_EXTENDED_CAPABILITIES_ATS ),
@@ -5746,7 +5776,7 @@ PrintInterpretedExtendedCompatibilitySriov (
57465776 Header -> VFMigrationStateArrayOffset
57475777 );
57485778
5749- DumpHex (
5779+ PciConfigSpaceDumpHex (
57505780 4 ,
57515781 EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8 * )HeaderAddress - (UINT8 * )HeadersBaseAddress ),
57525782 sizeof (SR_IOV_CAPABILITY_REGISTER ),
@@ -5780,7 +5810,7 @@ PrintInterpretedExtendedCompatibilityPri (
57805810 Header -> Status .Uint32
57815811 );
57825812
5783- DumpHex (
5813+ PciConfigSpaceDumpHex (
57845814 4 ,
57855815 EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8 * )HeaderAddress - (UINT8 * )HeadersBaseAddress ),
57865816 sizeof (PCI_EXPRESS_EXTENDED_CAPABILITIES_PRI ),
@@ -5813,7 +5843,7 @@ PrintInterpretedExtendedCompatibilityPasid (
58135843 Header -> Control .Uint16
58145844 );
58155845
5816- DumpHex (
5846+ PciConfigSpaceDumpHex (
58175847 4 ,
58185848 EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8 * )HeaderAddress - (UINT8 * )HeadersBaseAddress ),
58195849 sizeof (PCI_EXPRESS_EXTENDED_CAPABILITIES_PASID ),
@@ -5847,7 +5877,7 @@ PrintInterpretedExtendedCompatibilityL1PmSubstates (
58475877 Header -> Control2 .Uint32
58485878 );
58495879
5850- DumpHex (
5880+ PciConfigSpaceDumpHex (
58515881 4 ,
58525882 EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8 * )HeaderAddress - (UINT8 * )HeadersBaseAddress ),
58535883 sizeof (PCI_EXPRESS_EXTENDED_CAPABILITIES_L1_PM_SUBSTATES ),
@@ -5882,19 +5912,12 @@ PrintInterpretedExtendedCompatibilityDesignatedVendorSpecific (
58825912 Header -> DesignatedVendorSpecificHeader1 .Bits .DvsecLength
58835913 );
58845914
5885- UINT32 NextCapOffset = HeaderAddress -> NextCapabilityOffset ;
5886- UINTN Size ;
5915+ UINTN Size ;
58875916
5888- if (NextCapOffset == 0 ) {
5889- // The DVSEC length field plus the PCI Express header
5890- Size = sizeof (PCI_EXPRESS_EXTENDED_CAPABILITIES_HEADER ) +
5891- Header -> DesignatedVendorSpecificHeader1 .Bits .DvsecLength ;
5892- } else {
5893- Size = NextCapOffset - (((UINT8 * )HeaderAddress - (UINT8 * )HeadersBaseAddress ) & 0xFFF );
5894- }
5917+ Size = Header -> DesignatedVendorSpecificHeader1 .Bits .DvsecLength ;
58955918
58965919 // Dump the entire structure including the variable-length vendor specific data
5897- DumpHex (
5920+ PciConfigSpaceDumpHex (
58985921 4 ,
58995922 EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8 * )HeaderAddress - (UINT8 * )HeadersBaseAddress ),
59005923 Size ,
@@ -5969,7 +5992,7 @@ PrintInterpretedExtendedCompatibilityVfResizableBar (
59695992 );
59705993 }
59715994
5972- DumpHex (
5995+ PciConfigSpaceDumpHex (
59735996 4 ,
59745997 EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8 * )HeaderAddress - (UINT8 * )HeadersBaseAddress ),
59755998 HeaderSize + EntryCount * EntrySize ,
@@ -6002,7 +6025,7 @@ PrintInterpretedExtendedCompatibilityDataLinkFeature (
60026025 Header -> Control .Uint32
60036026 );
60046027
6005- DumpHex (
6028+ PciConfigSpaceDumpHex (
60066029 4 ,
60076030 EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8 * )HeaderAddress - (UINT8 * )HeadersBaseAddress ),
60086031 sizeof (PCI_EXPRESS_EXTENDED_CAPABILITIES_DATA_LINK_FEATURE ),
@@ -6058,7 +6081,7 @@ PrintInterpretedExtendedCompatibilityPhysicalLayer16 (
60586081 Header -> SecondRetimerDataParityMismatchStatus
60596082 );
60606083
6061- // Calculate the size for DumpHex
6084+ // Calculate the size for PciConfigSpaceDumpHex
60626085 UINT32 NextCapOffset = HeaderAddress -> NextCapabilityOffset ;
60636086 UINTN Size ;
60646087
@@ -6072,7 +6095,7 @@ PrintInterpretedExtendedCompatibilityPhysicalLayer16 (
60726095 Size = NextCapOffset - (((UINT8 * )HeaderAddress - (UINT8 * )HeadersBaseAddress ) & 0xFFF );
60736096 }
60746097
6075- DumpHex (
6098+ PciConfigSpaceDumpHex (
60766099 4 ,
60776100 EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8 * )HeaderAddress - (UINT8 * )HeadersBaseAddress ),
60786101 Size ,
@@ -6131,7 +6154,7 @@ PrintInterpretedExtendedCompatibilityLaneMargining (
61316154 Header -> Status .Bits .MaxLanesReceivingTestPattern
61326155 );
61336156
6134- DumpHex (
6157+ PciConfigSpaceDumpHex (
61356158 4 ,
61366159 EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8 * )HeaderAddress - (UINT8 * )HeadersBaseAddress ),
61376160 sizeof (PCI_EXPRESS_EXTENDED_CAPABILITIES_LANE_MARGINING_AT_RECEIVER ),
@@ -6227,7 +6250,7 @@ PrintInterpretedExtendedCompatibilityPhysicalLayer32 (
62276250 Size = NextCapOffset - (((UINT8 * )HeaderAddress - (UINT8 * )HeadersBaseAddress ) & 0xFFF );
62286251 }
62296252
6230- DumpHex (
6253+ PciConfigSpaceDumpHex (
62316254 4 ,
62326255 EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8 * )HeaderAddress - (UINT8 * )HeadersBaseAddress ),
62336256 Size ,
@@ -6261,7 +6284,7 @@ PrintInterpretedExtendedCompatibilityAlternateProtocol (
62616284 Header -> AltProtocolControl
62626285 );
62636286
6264- DumpHex (
6287+ PciConfigSpaceDumpHex (
62656288 4 ,
62666289 EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8 * )HeaderAddress - (UINT8 * )HeadersBaseAddress ),
62676290 sizeof (PCI_EXPRESS_EXTENDED_CAPABILITIES_ALTERNATE_PROTOCOL ),
@@ -6295,7 +6318,7 @@ PrintInterpretedExtendedCompatibilityDataObjectExchange (
62956318 Header -> DoeStatus
62966319 );
62976320
6298- DumpHex (
6321+ PciConfigSpaceDumpHex (
62996322 4 ,
63006323 EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8 * )HeaderAddress - (UINT8 * )HeadersBaseAddress ),
63016324 sizeof (PCI_EXPRESS_EXTENDED_CAPABILITIES_DATA_OBJECT_EXCHANGE ),
@@ -6362,7 +6385,7 @@ PrintInterpretedExtendedCompatibilityDevice3 (
63626385 Header -> Status .Bits .RemoteL0pSupported
63636386 );
63646387
6365- // Calculate the size for DumpHex
6388+ // Calculate the size for PciConfigSpaceDumpHex
63666389 UINT32 NextCapOffset = HeaderAddress -> NextCapabilityOffset ;
63676390 UINTN Size ;
63686391
@@ -6374,7 +6397,7 @@ PrintInterpretedExtendedCompatibilityDevice3 (
63746397 Size = NextCapOffset - (((UINT8 * )HeaderAddress - (UINT8 * )HeadersBaseAddress ) & 0xFFF );
63756398 }
63766399
6377- DumpHex (
6400+ PciConfigSpaceDumpHex (
63786401 4 ,
63796402 EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8 * )HeaderAddress - (UINT8 * )HeadersBaseAddress ),
63806403 Size ,
@@ -6408,7 +6431,7 @@ PrintInterpretedExtendedCompatibilityIntegrityEncryption (
64086431 Header -> IdeStatus
64096432 );
64106433
6411- DumpHex (
6434+ PciConfigSpaceDumpHex (
64126435 4 ,
64136436 EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8 * )HeaderAddress - (UINT8 * )HeadersBaseAddress ),
64146437 sizeof (PCI_EXPRESS_EXTENDED_CAPABILITIES_INTEGRITY_DATA_ENCRYPTION ),
@@ -6457,7 +6480,7 @@ PrintInterpretedExtendedCompatibilityPhysicalLayer64 (
64576480 Header -> Status .Bits .NoEqualizationNeededRcvd
64586481 );
64596482
6460- // Calculate the size for DumpHex
6483+ // Calculate the size for PciConfigSpaceDumpHex
64616484 UINT32 NextCapOffset = HeaderAddress -> NextCapabilityOffset ;
64626485 UINTN Size ;
64636486
@@ -6471,7 +6494,7 @@ PrintInterpretedExtendedCompatibilityPhysicalLayer64 (
64716494 Size = NextCapOffset - (((UINT8 * )HeaderAddress - (UINT8 * )HeadersBaseAddress ) & 0xFFF );
64726495 }
64736496
6474- DumpHex (
6497+ PciConfigSpaceDumpHex (
64756498 4 ,
64766499 EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8 * )HeaderAddress - (UINT8 * )HeadersBaseAddress ),
64776500 Size ,
@@ -6512,7 +6535,7 @@ PrintInterpretedExtendedCompatibilityFlitLogging (
65126535 Header -> FlitErrorData3
65136536 );
65146537
6515- DumpHex (
6538+ PciConfigSpaceDumpHex (
65166539 4 ,
65176540 EFI_PCIE_CAPABILITY_BASE_OFFSET + ((UINT8 * )HeaderAddress - (UINT8 * )HeadersBaseAddress ),
65186541 sizeof (PCI_EXPRESS_EXTENDED_CAPABILITIES_FLIT_LOGGING ),
0 commit comments