| Age | Commit message (Collapse) | Author | Files | Lines |
|
This reverts commit 0e7dad44bae663193b580adeb9d942c2559166f6.
Signed-off-by: Aaron Pop <aaronpop@microsoft.com>
|
|
This reverts commit 0d61209231b2ec50ca6f6b96825baaa07c280854.
Signed-off-by: Aaron Pop <aaronpop@microsoft.com>
|
|
The Enhanced Allocation capability of a PCI-PCI bridge carries an
additional DWORD describing the fixed secondary and subordinate bus
numbers used by the bridge, if it does not rely on its bus number
registers. Such a bridge only forwards configuration transactions for
its fixed bus numbers, and so they must be assigned to it during bus
enumeration.
Record the fixed bus numbers when parsing the EA capability, and assign
them in PciScanBus () instead of allocating the next available bus
number. The buses below the bridge are numbered from its fixed secondary
bus number onwards, and the entire fixed range is consumed, regardless
of how many buses are actually in use below the bridge. Hot plug bus
padding does not apply to such bridges.
As bus numbers are assigned in ascending order, the fixed bus numbers
cannot be honoured if they have already been assigned to another
bridge, if they are not covered by a single bus number range of the root
bridge, or if they are not nested inside the fixed bus numbers of an
upstream bridge. In this case, do not scan behind the bridge, and set
its primary bus number to an invalid value, so that the device info
collector pass does not scan behind it either: its bus number registers
are likely hardwired, and so the hierarchy behind it may remain visible
on buses that are assigned to other bridges.
Report an error if buses below a bridge with fixed bus numbers end up
outside of its fixed range, as those will be unreachable.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
|
|
A PCI-PCI bridge that implements the Enhanced Allocation (EA) capability
may use entries with BEI 6 to describe fixed I/O, memory and prefetchable
memory ranges that it forwards to its secondary side, regardless of the
contents of its Base/Limit registers.
So record such windows when parsing the EA capability of a bridge, and
treat the corresponding decodes as supported so that resources are not
degraded to a different type on account of the Base/Limit registers not
being implemented.
When calculating the aperture of such a bridge window, pin it to the fixed
range. Fixed resources below the bridge must reside inside that range, and
are dropped otherwise. Relocatable resources are placed inside the range at
the offsets calculated for them, provided that the window does not hold any
fixed resources, and is large enough, suitably aligned and, if it resides
above 4 GB, only covers resources that may be placed above 4 GB. Otherwise,
they are dropped.
Pinned EA windows are not programmed into the Base/Limit registers, and
propagate upwards as fixed resources, like any other pinned bridge window.
The on-chip bridges of some SoCs (e.g., Cavium/Marvell ThunderX family)
implement the EA capability only to describe their fixed bus numbers, and
carry no BEI 6 entries at all. The fixed BARs below such bridges are 64-bit
non-prefetchable ranges above 4 GB, and those below different bridges are
interleaved, as each device has BARs in multiple distinct regions. Covering
them with pinned windows does not work: the 32-bit non-prefetchable window
cannot describe them, and the pinned windows of sibling bridges overlap.
Evidently, such bridges forward the fixed ranges below them regardless of
their Base/Limit registers.
So assume that a bridge that implements the EA capability but has no BEI 6
entry for a certain type of window passes through the fixed resources of
that type below it: move them to the resource nodes of the upstream bus,
restoring the original BAR type of fixed device resources, and leave the
bridge window to the relocatable resources below it, if any. Bridges that
do not implement the EA capability are unaffected.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
|
|
After submitting the resource requirements for a root bridge, pass the
fixed ranges below it to the host bridge driver via the EDKII PCI Host
Bridge Fixed Resource protocol, if it is implemented. These are the fixed
BARs of devices on the root bus, and the pinned windows of PCI-PCI bridges
that cover fixed BARs further down the hierarchy.
If the protocol is not implemented, log the fixed ranges, as they need to
be reserved by the platform in that case.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
|
|
Implement the EDKII PCI Host Bridge Fixed Resource protocol, and install
it alongside the resource allocation protocol.
Fixed ranges submitted for a root bridge are validated against its
apertures, and claimed in GCD at their host address before any of the
root bridge windows are allocated, so that the allocator will steer clear
of them. Failure to claim a range is not treated as an error, given that
the platform may have reserved it already. The claimed ranges are released
again when the resources are freed or the enumeration is restarted.
The fixed ranges are appended to the resource descriptors returned by the
root bridge's Configuration () method, which permits the PCI bus driver to
resolve the translation offset for BARs that decode a fixed range.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
|
|
BARs described by an Enhanced Allocation capability decode a fixed address
range, and so they must be excluded from the ordinary resource allocation,
which assigns relocatable ranges by packing BARs at offsets from the base
of the enclosing window.
So represent such BARs as fixed resource nodes, which are not taken into
account when calculating the size of the enclosing window, and which are
not programmed into the BAR registers.
A PCI-PCI bridge window that covers fixed resource nodes must itself be
pinned to a range that covers all of them. Relocatable resources of the
same type below such a bridge cannot be accommodated, and are dropped with
an error. The pinned windows are programmed before the rest of the
hierarchy, and are propagated upwards as fixed nodes.
Finally, permit PciIo to fall back to a translation offset of 0 for fixed
BARs that are not covered by any of the root bridge's resource windows,
given that the platform may have reserved these ranges by other means.
Fixed resources don't occupy any of the relocatable aperture of the
enclosing window, and so a window or root bridge resource pool that only
holds fixed resources does not request any resources. So don't submit a
resource request for it, and don't treat the absence of an allocated base
as an error when programming the resources below it. This is the case,
e.g., for root bridges whose devices only have fixed BARs.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
|
|
Devices that implement the PCI Enhanced Allocation (EA) capability may
have BARs that are hardwired to a fixed address range, and that cannot be
sized or relocated via the ordinary BAR registers.
So when gathering device and PCI-PCI bridge information, parse the EA
capability if it exists, and use each enabled entry for BEI 0-5 (0-1 for
bridges) to override the information obtained from the corresponding BAR:
record the fixed base address and size, and mark the BAR as having a fixed
address, so that the resource allocator can take this into account.
Do the same after resizable BARs have been adjusted, as this re-parses the
BAR registers, and ensure that UpdatePciInfo () leaves such BARs alone.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
|
|
Currently, PciOperateRegister() unconditionally writes to the target PCI
configuration register (Command or Bridge Control) on
EFI_ENABLE_REGISTER and EFI_DISABLE_REGISTER operations even when the
requested bits are already in the target state or when Command is 0.
Similarly, PciIoAttributes() unconditionally invokes
PCI_ENABLE_COMMAND_REGISTER() and PCI_DISABLE_COMMAND_REGISTER() even
when Command is 0 (unlike BridgeControl, which is guarded by
BridgeControl != 0), and unconditionally recurses into
UpStreamBridge->PciIo.Attributes() even when UpStreamAttributes is 0
(such as when enabling IO, MEMORY, or BUS_MASTER on an endpoint).
Under virtualization (especially confidential computing environments
such as AMD SEV-SNP and Intel TDX), every PCI configuration space read
or write traps to the hypervisor. Update PciOperateRegister() to skip
no-op register reads/writes when Command is 0 or when the register value
is unchanged, and update PciIoAttributes() to guard Command register
updates and upstream bridge recursion on non-zero masks.
Suggested-by: Ard Biesheuvel <ardb+tianocore@kernel.org>
Signed-off-by: Kevin Loughlin <kevinloughlin@google.com>
|
|
Follow JESD216H 6.4.19, DWORD 16
Introduce Enter4Byte/Exit4Byte In SpiNorFlashJedecSfdp And SpiNorFlash
Fixes: #13171
Continuous-integration-options: PatchCheck.ignore-multi-package
Signed-off-by: Vincent Ke <vincentke@ami.com>
|
|
Several places in MdeModulePkg were implementing their
own versions of hex dumping logic; use the DebugLib.h
macro instead.
Prints change slightly, they are now standardized with
uppercase hex, prefixes on every row instead of in the
header only, and VarCheckHiiLib no longer indents rows
with *ASCII*.
Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
|
|
UsbGetDevBosDesc() allocates a buffer for the initial BOS descriptor
request. If that request fails, the success-only cleanup is skipped and
the function returns without freeing the buffer. Repeated enumeration
attempts can leak one allocation per failure.
Free the initial buffer before returning the transfer error.
The leaking retrieval helper was introduced by PR #12714:
https://github.com/tianocore/edk2/pull/12714
Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
|
|
UsbIsSSDevice() trusts device-reported NumDeviceCaps and capability
Length fields without bounding reads to the BOS buffer. Malformed values
can cause out-of-bounds reads and an exception during device enumeration.
Validate the BOS header and total length. Before reading each capability,
check that its header and declared length fit in the remaining bytes.
Reject malformed or truncated descriptors and recognize SuperSpeed only
after validating the complete capability list.
The unbounded parser was introduced by PR #12714:
https://github.com/tianocore/edk2/pull/12714
Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
|
|
UsbEnumerateNewDev() frees DevDesc before resetting the port for an
enumeration retry. UsbRootHubResetPort() scans that device during the
reset and previously dereferenced DevDesc without checking it.
For a SuperSpeed-capable device running below SuperSpeed, IsSSDev and
Speed still satisfy the scan's preceding conditions after DevDesc is
cleared. The DeviceClass access can therefore cause a null-pointer
exception. Add descriptor checks before those dereferences and clear
IsSSDev when freeing the descriptor.
The unsafe reset dereference was introduced by PR #12714:
https://github.com/tianocore/edk2/pull/12714
Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
|
|
Test valid SuperSpeed recognition and reject capabilities extending beyond
the BOS total length or supplied buffer. Verify failed initial BOS reads
free their buffers and root-hub reset succeeds after descriptor cleanup.
Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
|
|
A blank (unwritten) optical disc reports a zero capacity through READ
CAPACITY (LastBlock == 0). The driver currently exposes such a device
with BlockSize 2048 and LastBlock 0, so upper layers such as PartitionDxe
and the BDS removable-media boot probe keep reading LBA 0. The drive
rejects the read with "Illegal Request / LBA out of range" (sense 5/21/0)
and UsbMassReadBlocks enters its reset recovery loop. So each failed probe
can block for tens of seconds and boot appears to hang.
Treat an optical device with zero capacity as media absent so that the
media is skipped instead of being probed.
Signed-off-by: Haword <zhenghaowei@loongson.cn>
|
|
Memory leak anytime the FormatNvm function is called.
Signed-off-by: Sean Brogan <sebrogan@microsoft.com>
|
|
LastBlock field is inclusive.
To lower confusion it should be initialized to the intended
value which was to create metadata for an 8mb disk.
Signed-off-by: Sean Brogan <sebrogan@microsoft.com>
|
|
NamespaceData was allocated, zeroed, and never modifed.
Then it was copied over another buffer that was already zero.
Then it was leaked.
Remove local variable NamespaceData and the associated code.
Signed-off-by: Sean Brogan <sebrogan@microsoft.com>
|
|
Add tests for MediaClear functions in the Nvme Media Sanitize Unit tests
Signed-off-by: Sean Brogan <sebrogan@microsoft.com>
|
|
Replace hardcoded PCI configuration-space offsets with the type-safe
macros from MdePkg/Include/IndustryStandard/Pci22.h. This removes magic
numbers from the PciBus driver and makes the code easier to read and
maintain. No functional change.
1. MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c
- GatherDeviceInfo() / InitializePciDevice(): use
PCI_BASE_ADDRESSREG_OFFSET and PCI_BASE_ADDRESSREG5_OFFSET as the
BAR scan loop bounds instead of 0x10/0x24.
- GatherPpbInfo(): use PCI_BASE_ADDRESSREG_OFFSET /
PCI_BASE_ADDRESSREG1_OFFSET for the two PPB BARs, and the
PCI_BRIDGE_* offset macros instead of 0x1C/0x24/0x28.
- GatherP2CInfo(): use PCI_BASE_ADDRESSREG_OFFSET instead of 0x10
for the CardBus bridge BAR.
- InitializePpb(): use the PCI_BRIDGE_* offset macros instead of
hardcoded offsets (0x1C/0x1D/0x20/0x22/0x24/0x26/0x28/0x2C/0x30/0x32)
when initializing the I/O, 32-bit memory, and 64-bit memory windows
to their disabled state (base set to all-ones, limit to all-zeros).
- IsPciDeviceRejected(): use PCI_CARD_MEMORY_BASE_0,
PCI_CARD_IO_BASE_0_LOWER, and PCI_CARD_IO_LIMIT_1_LOWER in place of
0x1C/0x2C/0x38 for the CardBus BAR scan, and
PCI_BASE_ADDRESSREG1_OFFSET / PCI_BASE_ADDRESSREG5_OFFSET instead of
0x14/0x24 for the standard PCI BAR scan.
- ResetAllPpbBusNumber(): use PCI_BRIDGE_PRIMARY_BUS_REGISTER_OFFSET
instead of 0x18.
2. MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c
- Use PCI_BASE_ADDRESSREG_OFFSET / PCI_BASE_ADDRESSREG5_OFFSET as the
BAR scan loop bounds instead of 0x10/0x24.
3. MdeModulePkg/Bus/Pci/PciBusDxe/PciResourceSupport.c
- ProgramPpbAperture(): replace hardcoded PCI bridge aperture offsets
with the PCI_BRIDGE_* macros in the PPB_IO_RANGE, PPB_MEM32_RANGE,
PPB_PMEM32_RANGE, and PPB_PMEM64_RANGE cases.
4. MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumerator.c
- Use PCI_BRIDGE_PRIMARY_BUS_REGISTER_OFFSET,
PCI_BRIDGE_SECONDARY_BUS_REGISTER_OFFSET, and
PCI_BRIDGE_SUBORDINATE_BUS_REGISTER_OFFSET instead of 0x18/0x19/0x1A
when programming and reading the bridge bus-number registers.
5. MdeModulePkg/Bus/Pci/PciBusDxe/PciDeviceSupport.c
- Use PCI_INT_LINE_OFFSET instead of 0x3C when writing the device
Interrupt Line register to 0xFF (no connection / unknown).
References:
- PCI Local Bus Specification, Revision 2.2
- PCI-to-PCI Bridge Architecture Specification, Revision 1.2
- PCI Express Base Specification, Revision 7.0
Cc: Sachin Ganesh <sachinganesh@ami.com>
Cc: Dhanaraj V <vdhanaraj@ami.com>
Cc: Sergiy Yakovlev <sergiyy@ami.com>
Cc: Dhiinesh M <dhiineshm@ami.com>
Signed-off-by: Varun G <varung@ami.com>
|
|
Add host-based Google Test coverage for PciParseBar() and
PciIovParseVfBar().
Cover absent BARs, 16-bit and 32-bit I/O BARs, 32-bit memory BARs, and
64-bit memory BARs. Also verify that a resource following a 64-bit BAR
retains its physical BAR number because the upper DWORD consumes the
intermediate BAR register.
Add equivalent SR-IOV VF BAR coverage, including InitialVFs length
scaling, system page alignment, 64-bit VF BAR parsing, and physical VF
BAR numbering after a 64-bit VF BAR.
Provide test-only PCI configuration access and boot service mocks.
Stub unrelated PciBusDxe dependencies pulled in by
PciEnumeratorSupport.c, and register the test application in
MdeModulePkgHostTest.dsc.
Signed-off-by: Aaron Pop <aaronpop@microsoft.com>
|
|
PCI BARs are by six consecutive 32-bit configurationv registers. 64-bit
BARs consume two of those registers: the first contains the low address
bits and the second contains the high address bits. These are
represented in the private PCI_IO_DEVICE as PciBar[PCI_MAX_BAR] and
VfPciBar[PCI_MAX_BAR].
PciBusDxe previously maintained a separate BarIndex while walking the
configuration registers. PciParseBar() and PciIovParseVfBar() advance
the configuration offset by two registers when parsing a 64-bit BAR,
but their callers incremented BarIndex only once. As a result, every
BAR following a 64-bit BAR was stored in the preceding array entry. For
example, a BAR at offset 0x18 following a 64-bit BAR at offset 0x10 was
recorded as PciBar[1] instead of PciBar[2].
This breaks the invariant that PciBar[Index] and VfPciBar[Index]
describe the corresponding physical BAR register. It can cause later
resource handling and diagnostics to associate a BAR with the wrong
hardware slot. VF BAR programming retained the configuration offset in
each entry, which could mask the problem, but its array and resource
node indices were still incorrect.
Derive the BAR index directly from the configuration offset in both
parsers. Remove the redundant BarIndex parameters and let each caller
advance using the offset returned by the parser. This preserves holes
for the upper DWORDs of 64-bit BARs and keeps conventional and SR-IOV
VF BAR numbering aligned with the hardware configuration space.
Signed-off-by: Aaron Pop <aaronpop@microsoft.com>
|
|
InsertResourceNode() keeps the resource list of a bridge sorted by
descending alignment. The new node is inserted at the head of the list
and then moved towards the tail, but it stops in front of the first
node that it does not need to follow. Resources that rank equal, such
as BARs of the same size, therefore end up in the reverse order of
their discovery (LIFO), and the last discovered one is assigned the
lowest address.
Linux also sorts the resources by descending alignment in
pdev_sort_resources() (drivers/pci/setup-bus.c), but it inserts a new
resource after all the resources with the same alignment, so these
keep their discovery order (FIFO).
When the OS reassigns the PCI resources instead of keeping the firmware
assignment (for example Linux on ARM64 ACPI systems, unless the
firmware requests to preserve the PCI boot configuration through _DSM
function 5), this difference makes it swap the addresses of equally
sized BARs. While doing so, a BAR is temporarily programmed with a
range that is still decoded by another device, which is not handled by
some platforms, such as VMMs that do not allow overlapping BARs.
Insert the new node at the tail of the list and move it towards the
head instead, swapping the roles of the two compared nodes, so that
resources that rank equal keep their discovery order, consistent with
Linux.
Resources with the same alignment are also sorted by the remainder of
their length modulo the alignment. In practice, the remainder is only
non-zero for the window of a child bridge, whose length is a multiple
of the window granularity but whose alignment is the largest alignment
of the resources behind it. Such a window leaves a gap in front of the
next resource with the same alignment, so resources without a remainder
should come first. However, the check only ranks a zero remainder first
for the node that is being inserted, not for the existing node that it
is compared with, so the relative order of windows with and without a
remainder also depends on the insertion order. Reversing it can waste
address space. For example, on QEMU q35 with three PCIe root ports,
where the first one has a 3 MB MMIO window aligned to 2 MB and the
other two have a 2 MB window, the 3 MB window would be placed first,
leaving a 1 MB gap and growing the MMIO32 aperture of the root bridge
from 8 MB to 9 MB.
Therefore, rank a zero remainder first for both compared nodes.
Resources without a remainder now always come first, regardless of the
discovery order, which never increases the size of the aperture, and
only resources that rank equal are ordered by their discovery. Update
the description of InsertResourceNode() to document the full ordering.
Signed-off-by: Shubham Aggarwal <shubagga@google.com>
|
|
Commit ee58614bbb ("MdeModulePkg/ScsiDiskDxe: Check Write Caching and
FUA support") added a best-effort FUA-support query to
ScsiDiskDetectMedia(). It issues a MODE SENSE(10) for the Caching mode
page via ScsiDiskFuaMode() and assigns the result to the function's
shared Status variable.
When the device rejects that command, Status is left as
EFI_DEVICE_ERROR and falls through to the function's return, even
though the media was already detected successfully (capacity read,
media present). Callers treat this as fatal:
ScsiDiskDriverBindingStart() skips installing Block I/O, and
ScsiDiskReadBlocks()/WriteBlocks() return EFI_DEVICE_ERROR. For
non-fixed devices DetectMedia() re-runs on every access, so the disk
is never usable.
This is observed on UFS (google/yaviks): the LUN answers the MODE
SENSE with a Target Failure ("UfsExecScsiCmds() fails with Target
Failure"), so a drive that was detected with edk2-stable202602 is no
longer detected with edk2-stable202605.
The FUA query is only used to refine ScsiDiskDevice->FuaMode, which
already defaults to TRUE (the prior always-set-FUA behavior). Its
failure must not affect media detection, so stop assigning its result
to Status and hoist the device-type check out of the retry loop.
Fixes: ee58614bbb ("MdeModulePkg/ScsiDiskDxe: Check Write Caching and
FUA support")
TEST=build/boot google/yaviks Chromebook with UFS, drive is detected
and bootable.
Signed-off-by: Matt DeVillier <matt.devillier@gmail.com>
|
|
Commit b58ce4c226 broke backward compatibility with v2 platform
protocols by incorrectly skipping HCE re-enable for v2 implementations.
When used with a UfsPlatform.efi binary that was compiled against
an older stable tag, (where EDKII_UFS_HC_PLATFORM_PROTOCOL_VERSION
is defined as 2), the code attempted to read the v3-only
SkipHceReenable/SkipLinkStartup fields beyond the v2 struct boundary,
reading garbage memory and potentially skipping initialization.
Add explicit version check to ensure v2 protocols follow normal
initialization path, preventing out-of-bounds struct access.
TEST=build/boot google/yaviks with UFS storage
Signed-off-by: Matt DeVillier <matt.devillier@gmail.com>
|
|
Commit bf0dc7d78701 ("MdeModulePkg: Fix comparison with wider widths")
changed PrpListIndex and PrpEntryIndex from UINTN to UINT64. In
NvmeCreatePrpList(), performing arithmetic with `PrpListIndex * EFI_PAGE_SIZE`
and pointer indexing with `(UINT64 *)PrpListBase + PrpEntryIndex` results
in 64-bit multiplication.
Fix this issue by using MultU64x32() for 64-bit page offset calculations
and casting PrpEntryIndex to UINTN for pointer indexing.
Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
|
|
In NvmeCreatePrpList(), calculating the PRP entry offset via
`PrpEntryIndex * sizeof (UINT64)` uses 64-bit multiplication since
PrpEntryIndex is UINT64. On 32-bit architectures (IA32), 64-bit
multiplication must use BaseLib math functions.
Use MultU64x32() for the 64-bit offset calculation and add BaseLib
to the module INF and header.
Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
|
|
In BuildAdmaDescTable(), Index and Entries were UINT64. Using a 64-bit
Index for array subscripting `Trb->Adma32Desc[Index]`,
`Trb->Adma64V3Desc[Index]`, and `Trb->Adma64V4Desc[Index]` generates
64-bit multiplication on 32-bit architectures (IA32).
Change Index and Entries to UINTN so array indexing and table size
calculations use native integer math.
Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
|
|
In BuildAdmaDescTable(), Index and Entries were UINT64. Using a 64-bit
Index for array subscripting `Trb->AdmaDesc[Index]` generates 64-bit
multiplication on 32-bit architectures (IA32).
Change Index and Entries to UINTN so array indexing uses native integer
math, and add BaseLib to the module INF.
Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
|
|
Raise TPL to TPL_CALLBACK around the ConnectController() call in
UsbBusRecursivelyConnectWantedUsbIo() and restore the original TPL
afterward.
UsbBusRecursivelyConnectWantedUsbIo() is normally reached through the
DriverBinding Start routine invoked by gBS->ConnectController(), which
runs at TPL_APPLICATION. While the wanted UsbIo handle is being
connected, the USB device can be removed. The device removal polling
event in UsbBus runs at TPL_CALLBACK. If the connect runs at
TPL_APPLICATION, that event can preempt the connection and cause
commands to be sent to a stale or non-existent USB device address,
producing a lot of timeout transfers.
This differs from UsbConnectDriver(), which is called from the
enumeration polling event (XHCI async event) and is usually already
at TPL_CALLBACK or TPL_NOTIFY. That function uses RestoreTPL()/
RaiseTPL() to ensure ConnectController() runs at TPL_CALLBACK.
Signed-off-by: Marlboro_Chuang <marlboro.chuang@dell.com>
|
|
Some specific device requires a quirk in the Interface descriptor for
InterfaceNumber to work properly
[Suggested Solution]
Implement the mechanism to ensure the first InterfaceNumber not equal
to zero.
Signed-off-by: Marlboro_Chuang <marlboro.chuang@dell.com>
|
|
DumpUicCmdExecResult & DumpQueryResponseResult are called to dump the
result of UIC commands after a failure. Depending on the nature of the
failure, not all information may have been properly initialized. This is
already handled in callers with existing retry logic, but the assert in
the dump command can cause a crash in debug builds for due to hardware
race conditions on first attempt.
Signed-off-by: Chris Fernald <chfernal@microsoft.com>
|
|
https://github.com/github/codeql/blob/codeql-cli-2.7.3/csharp/ql/src/API%20Abuse/UncheckedReturnValue.qhelp
When a function has a return status, it should
be checked to verify the function completed successfully.
Failing to check the return status can result in null pointer
dereferences or use of uninitialized variables.
Signed-off-by: Aaron Pop <aaronpop@microsoft.com>
|
|
https://github.com/github/codeql/blob/codeql-cli-2.7.3/cpp/ql/src/Critical/MissingNullTest.qhelp
For items which allocate memory, or get a pointer from another
structure, it is important to validate that the pointers
are not null before they are dereferenced.
Signed-off-by: Aaron Pop <aaronpop@microsoft.com>
|
|
https://codeql.github.com/codeql-query-help/cpp/cpp-comparison-with-wider-type
If the narrow type (smaller range) is compared against a wide type
(larger range), the narrow value may overflow before reaching the wide
value. This can cause unexpected behavior, such as:
Infinite loops (loop condition never becomes false).
Incorrect logic (comparison results are misleading).
Signed-off-by: Aaron Pop <aaronpop@microsoft.com>
|
|
Dispatch Shutdown Notification to every NVMe first, then polling
every NVMe t omaake sure all NVMe's shutdown processing is
completed.This will help to save a lot time when BIOS trigger
reset for Servers whose have many NVMes. Tested on a platform
with AMD EPYC cpu with 26 NVMes, this method reduce reset time
from 3 minutes to 10 seconds.
Signed-off-by: Theo <theo.tao@foxmail.com>
|
|
UsbSelectConfig will introduce the UsbConnectDriver call.
If this UsbPortReset is happened in the Usb device driver Start() routine and the device FW can not be recovered by PortReset, the UsbSelectConfig will introduce the recursive loop.
[Suggested solution]
Since UsbPortReset should not change the Bus Topology, the Reset flow should only SetAddress and reconfigure the device.
Signed-off-by: Marlboro Chuang <marlboro.chuang@dell.com>
Signed-off-by: Jared Pan <jared.pan@dell.com>
|
|
Some SuperSpeed-capable devices may fall back to High-Speed
mode and cause subsequent commands to fail.
[Suggested Solution]
Check the BOS descriptor to verify SuperSpeed support and
trigger a port reset if needed to re-enumerate the device
properly.
Signed-off-by: Marlboro Chuang <marlboro.chuang@dell.com>
Signed-off-by: Jared Pan <jared.pan@dell.com>
|
|
USB devices whose configuration descriptor TotalLength exceeds 1024
bytes (e.g. IR cameras with large descriptor tables) previously hit
an EFI_DEVICE_ERROR hard-limit and failed to enumerate in PEI.
Replace the fixed array with a UINT8 * pointer and dynamically
allocate the exact amount of memory required via
PeiServicesAllocatePool() after the TotalLength is learned from the
initial 4-byte descriptor probe.
Signed-off-by: Damien Chen <damien.chen@dell.com>
|
|
When UpdatePciInfo() downgrades a PciBarTypePMem64 BAR to a 32-bit type
via EFI_INCOMPATIBLE_PCI_DEVICE_SUPPORT_PROTOCOL, it unconditionally
assigns PciBarTypePMem32 regardless of SpecificFlag, placing the BAR in
the prefetchable bridge window even when the platform intended the
non-prefetchable window.
The ACPI resource descriptor's SpecificFlag field encodes the intended
prefetchability of the constrained resource, using the bit:
EFI_ACPI_MEMORY_RESOURCE_SPECIFIC_FLAG_CACHEABLE_PREFETCHABLE.
Fix this by checking the bit in SpecificFlag to select PciBarTypePMem32 or
PciBarTypeMem32, consistent with DumpPpbPaddingResource() in
PciEnumeratorSupport.c that uses the bit as the sole discriminator
between the two 32-bit BAR types.
Signed-off-by: Phil Noh <Phil.Noh@amd.com>
|
|
In arguments of EFI_PCI_IO_PROTOCOL member functions, replace the
EfiPciWidth* enum literals from
EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH with the matching
EfiPciIoWidth* values from EFI_PCI_IO_PROTOCOL_WIDTH.
This keeps the call sites aligned with the protocol they actually use.
The old values were copied from EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL code,
so they obscured the intent of the calls and relied on an explicit
cast.
This mimics commit 8ba64a9a9417 ("UefiPayloadPkg: Fix build failure with
CLANGPDB").
Generated by coccinelle script.
``` smpl
@initialize:python@
@@
def to_pci_io_width(name):
return name.replace("EfiPciWidth", "EfiPciIoWidth", 1)
@normalize@
typedef EFI_PCI_IO_PROTOCOL;
typedef EDKII_PCI_DEVICE_PPI;
type T =~ "^EFI_PCI_IO_PROTOCOL_WIDTH$";
EFI_PCI_IO_PROTOCOL *x;
EDKII_PCI_DEVICE_PPI *y;
identifier bad =~ "EfiPciWidth(Uint|FifoUint|FillUint)(8|16|32|64)";
identifier top_op =~ "^(PollMem|PollIo|CopyMem)$";
identifier space =~ "^(Mem|Io|Pci)$";
identifier rw =~ "^(Read|Write)$";
fresh identifier good = script:python(bad) { to_pci_io_width(bad) };
expression first;
expression list rest;
@@
(
x->top_op
|
y->PciIo.top_op
|
x->space.rw
|
y->PciIo.space.rw
) (
first,
- (T)bad
+ good
,
rest
)
```
Verified with:
- `build -p MdeModulePkg/MdeModulePkg.dsc -m MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf -a IA32 -b DEBUG -t GCC`
- `build -p MdeModulePkg/MdeModulePkg.dsc -m MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf -a X64 -b DEBUG -t GCC`
Signed-off-by: Mingjie Shen <shen497@purdue.edu>
|
|
Certain devices require immediate follow-up commands
after reading the LANGID string to fetch Manufacturer,
Product, or SerialNumber strings.
[Suggested Solution]
These strings are now cached after initial retrieval
to allow UsbIoGetStringDescriptor() to return them
directly, improving efficiency and stability.
Signed-off-by: Marlboro Chuang <marlboro.chuang@dell.com>
Signed-off-by: Jared Pan <jared.pan@dell.com>
|
|
The patch enhances the USB enumeration process in EDK2 to improve compatibility with non-standards-compliant devices that may fail during standard enumeration sequences.
The suggested solution is based on USB specifications and references implementations from both Linux and Windows environments.
[Suggested solution]
- Integrated a retry mechanism to sequentially execute enumeration scripts, inspired by the enumeration flows of Windows, Linux, and EDK2. This improves robustness when handling corner-case devices.
- Do sanity check while the device report the device descriptor.
- AMD XHCI might need to wait for more time while sending the CLEAR_FEATURE reuqest.
Signed-off-by: Marlboro Chuang <marlboro.chuang@dell.com>
Signed-off-by: Jared Pan <jared.pan@dell.com>
|
|
IsPciDeviceRejected() masks BAR value with 0xFFFFFFF0 before testing
the type bits (2:1) that mark a 64-bit memory BAR, essentially clears
them, making the 64-bit BAR code path unreachable and treated as if
it were 32-bit.
The function rejects a device when BAR looks unprogrammed by comparing
if its size mask equals its value. When a 64-bit BAR is mistaken for a
32-bit one, only its lower part is compared, possibly leading a valid
BAR being falsely rejected. For example, a 2G BAR with size mask
0x80000000 at 0x180000000 matches and the device is dropped.
This code runs during light enumeration (PciEnumeratorLight), used when
PCI resources are already assigned by the platform (e.g. Xen HVM, where
hvmloader programs the BARs). The rejected device never receives a
PciIo handle, so no driver can bind to it. For example, a virtio-vga
with a 64-bit BAR vanishes under OVMF on Xen, leaving the guest with
no graphics output.
Fix by testing the type bits on the raw BAR value before masking.
Signed-off-by: Jiaqing Zhao <Zhao.Jiaqing@amd.com>
|
|
Update recent changes in MdeModulePkg to follow the latest EDK II
C Coding Standards Specification (5.3) to use '#pragma once' instead
of traditional macro-based include guards in header files.
https://tianocore-docs.github.io/edk2-CCodingStandardsSpecification/draft/5_source_files/53_include_files.html#53-include-files
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
|
|
CxlDxe is currently compiled as part of the MdeModulePkg
IA32 CI. When running CI with VS2022 version 14.44.35228.0,
the CI build fails with:
CxlDxe.lib(CxlDxe.obj) : unresolved external symbol __allmul
CxlDxe(CxlDxe.obj) : unresolved external symbol __allshl
CxlDxe is not intended to run on IA32 DXE systems, as such
systems are legacy, but until edk2 drops build support for
IA32 DXE (or at least CI for it), the build needs to work.
This fixes the 64 bit multiplication/shifting that occurs
in CxlDxe to use the BaseLib functions that avoid the
compiler intrinsics.
Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
|
|
The PCI specification normally requires function 0 to be present
before functions 1 through 7 are used. PciBusDxe therefore stops
scanning a slot when probing function 0 fails.
Some virtualized PCI topologies may expose selected non-zero functions
to a guest while function 0 is hidden. Add an opt-in Feature PCD so a
platform can continue collecting device information for functions 1
through 7 when function 0 is absent.
The default remains FALSE, so existing platform behavior is unchanged
unless the platform explicitly enables the PCD.
Signed-off-by: Dongyan Qian <qiandongyan@loongson.cn>
|
|
In CxlWriteRegblockRegisters() and PciUefiMemReadUInt32Array(),
Status is only assigned inside the for loop but is returned after
the loop exits, causing an uninitialized variable warning. Return
immediately on error to fix this.
Signed-off-by: Tuan Phan <tuan.phan@oss.qualcomm.com>
|
|
In SdPeimIdentification(), the compiler may inline SdPeimHcRwMmio()
because it only performs simple MMIO reads and writes. When inlined, the
fourth argument can appear to follow multiple control-flow paths
(MMIO read versus MMIO write), which may cause the compiler to report
a potential uninitialized variable warning when the value is used
later if it was not initialized up front.
Add an explicit Status check, consistent with other code in this file,
to make the control flow explicit and eliminate the compiler warning.
Signed-off-by: Tuan Phan <tuan.phan@oss.qualcomm.com>
|