diff --git a/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceIo.c b/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceIo.c index 7bba4b94e2e..3a57cb620d2 100644 --- a/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceIo.c +++ b/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceIo.c @@ -848,37 +848,41 @@ CoherentPciIoMap ( IoMmuOperation += EdkiiIoMmuOperationBusMasterRead64; } - Status = IoMmuMap ( - IoMmuOperation, - IoMmuHostAddress, - NumberOfBytes, - DeviceAddress, - &MapInfo->IoMmuContext - ); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a - IoMmuMap failed.\n", __func__)); - ASSERT (FALSE); - goto FreeMapInfo; - } + if (IoMmuIsPresent ()) { + Status = IoMmuMap ( + IoMmuOperation, + IoMmuHostAddress, + NumberOfBytes, + DeviceAddress, + &MapInfo->IoMmuContext + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a - IoMmuMap failed.\n", __func__)); + ASSERT (FALSE); + goto FreeMapInfo; + } - Status = IoMmuSetAttribute ( - NULL, - MapInfo->IoMmuContext, - IoMmuAttribute - ); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a - IoMmuSetAttribute failed.\n", __func__)); - ASSERT (FALSE); - goto Unmap; + Status = IoMmuSetAttribute ( + NULL, + MapInfo->IoMmuContext, + IoMmuAttribute + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a - IoMmuSetAttribute failed.\n", __func__)); + ASSERT (FALSE); + goto Unmap; + } } return EFI_SUCCESS; Unmap: - Status = IoMmuUnmap (MapInfo->IoMmuContext); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a - IoMmuUnmap failed.\n", __func__)); - ASSERT (FALSE); + if (IoMmuIsPresent ()) { + Status = IoMmuUnmap (MapInfo->IoMmuContext); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a - IoMmuUnmap failed.\n", __func__)); + ASSERT (FALSE); + } } FreeMapInfo: @@ -916,18 +920,20 @@ CoherentPciIoUnmap ( MapInfo = Mapping; - Status = IoMmuSetAttribute (NULL, MapInfo->IoMmuContext, 0); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a - IoMmuSetAttribute failed.\n", __func__)); - ASSERT (FALSE); - return Status; - } + if (IoMmuIsPresent ()) { + Status = IoMmuSetAttribute (NULL, MapInfo->IoMmuContext, 0); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a - IoMmuSetAttribute failed.\n", __func__)); + ASSERT (FALSE); + return Status; + } - Status = IoMmuUnmap (MapInfo->IoMmuContext); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a - IoMmuUnmap failed.\n", __func__)); - ASSERT (FALSE); - return Status; + Status = IoMmuUnmap (MapInfo->IoMmuContext); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a - IoMmuUnmap failed.\n", __func__)); + ASSERT (FALSE); + return Status; + } } // Only copy the data back and free for the bounce buffer case. @@ -1542,37 +1548,41 @@ NonCoherentPciIoMap ( IoMmuOperation += EdkiiIoMmuOperationBusMasterRead64; } - Status = IoMmuMap ( - IoMmuOperation, - IoMmuHostAddress, - NumberOfBytes, - DeviceAddress, - &MapInfo->IoMmuContext - ); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a - IoMmuMap failed.\n", __func__)); - ASSERT (FALSE); - goto FreeMapInfo; - } + if (IoMmuIsPresent ()) { + Status = IoMmuMap ( + IoMmuOperation, + IoMmuHostAddress, + NumberOfBytes, + DeviceAddress, + &MapInfo->IoMmuContext + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a - IoMmuMap failed.\n", __func__)); + ASSERT (FALSE); + goto FreeMapInfo; + } - Status = IoMmuSetAttribute ( - NULL, - MapInfo->IoMmuContext, - IoMmuAttribute - ); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a - IoMmuSetAttribute failed.\n", __func__)); - ASSERT (FALSE); - goto Unmap; + Status = IoMmuSetAttribute ( + NULL, + MapInfo->IoMmuContext, + IoMmuAttribute + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a - IoMmuSetAttribute failed.\n", __func__)); + ASSERT (FALSE); + goto Unmap; + } } return EFI_SUCCESS; Unmap: - Status = IoMmuUnmap (MapInfo->IoMmuContext); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a - IoMmuUnmap failed.\n", __func__)); - ASSERT (FALSE); + if (IoMmuIsPresent ()) { + Status = IoMmuUnmap (MapInfo->IoMmuContext); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a - IoMmuUnmap failed.\n", __func__)); + ASSERT (FALSE); + } } // MU_CHANGE [END] @@ -1610,18 +1620,20 @@ NonCoherentPciIoUnmap ( MapInfo = Mapping; // MU_CHANGE [BEGIN] - Status = IoMmuSetAttribute (NULL, MapInfo->IoMmuContext, 0); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a - IoMmuSetAttribute failed.\n", __func__)); - ASSERT (FALSE); - return Status; - } + if (IoMmuIsPresent ()) { + Status = IoMmuSetAttribute (NULL, MapInfo->IoMmuContext, 0); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a - IoMmuSetAttribute failed.\n", __func__)); + ASSERT (FALSE); + return Status; + } - Status = IoMmuUnmap (MapInfo->IoMmuContext); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a - IoMmuUnmap failed.\n", __func__)); - ASSERT (FALSE); - return Status; + Status = IoMmuUnmap (MapInfo->IoMmuContext); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a - IoMmuUnmap failed.\n", __func__)); + ASSERT (FALSE); + return Status; + } } // MU_CHANGE [END] diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciIo.c b/MdeModulePkg/Bus/Pci/PciBusDxe/PciIo.c index abb8e752707..b17c3a1a15a 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciIo.c +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciIo.c @@ -1100,15 +1100,17 @@ PciIoUnmap ( // MU_CHANGE [END] // MU_CHANGE [BEGIN] - Use IoMmuLib - Status = IoMmuSetAttribute ( - PciIoDevice->Handle, - Mapping, - 0 - ); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a - IoMmuSetAttribute failed.\n", __func__)); - ASSERT (FALSE); - return Status; + if (IoMmuIsPresent ()) { + Status = IoMmuSetAttribute ( + PciIoDevice->Handle, + Mapping, + 0 + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a - IoMmuSetAttribute failed.\n", __func__)); + ASSERT (FALSE); + return Status; + } } // MU_CHANGE [END] diff --git a/MdeModulePkg/Bus/Pci/XhciPei/XhciSched.c b/MdeModulePkg/Bus/Pci/XhciPei/XhciSched.c index 158749b53c0..89085b4aacf 100644 --- a/MdeModulePkg/Bus/Pci/XhciPei/XhciSched.c +++ b/MdeModulePkg/Bus/Pci/XhciPei/XhciSched.c @@ -194,7 +194,9 @@ XhcPeiFreeUrb ( return; } - IoMmuUnmap (Urb->DataMap); + if (IoMmuIsPresent ()) { + IoMmuUnmap (Urb->DataMap); + } FreePool (Urb); } @@ -260,7 +262,9 @@ XhcPeiCreateTransferTrb ( } Len = Urb->DataLen; - Status = IoMmuMap (MapOp, Urb->Data, &Len, &PhyAddr, &Map); + if (IoMmuIsPresent ()) { + Status = IoMmuMap (MapOp, Urb->Data, &Len, &PhyAddr, &Map); + } if (EFI_ERROR (Status) || (Len != Urb->DataLen)) { DEBUG ((DEBUG_ERROR, "XhcCreateTransferTrb: Fail to map Urb->Data.\n"));