Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down
20 changes: 11 additions & 9 deletions MdeModulePkg/Bus/Pci/PciBusDxe/PciIo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
8 changes: 6 additions & 2 deletions MdeModulePkg/Bus/Pci/XhciPei/XhciSched.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,9 @@ XhcPeiFreeUrb (
return;
}

IoMmuUnmap (Urb->DataMap);
if (IoMmuIsPresent ()) {
IoMmuUnmap (Urb->DataMap);
}

FreePool (Urb);
}
Expand Down Expand Up @@ -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"));
Expand Down
Loading