Skip to content
Merged
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
23 changes: 12 additions & 11 deletions drivers/gpu/drm/img-rogue/physmem_dmabuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1901,22 +1901,14 @@ PhysmemExportDmaBuf(CONNECTION_DATA *psConnection,
PVRSRV_MEMALLOCFLAGS_T ui64Flags = 0;
IMG_BOOL bIsPMRReadable = IMG_FALSE;
IMG_BOOL bIsPMRWritable = IMG_FALSE;

/* Exporting a PMR which was originally created from an imported DmaBuf
* is not supported.
*/
PVR_RETURN_IF_FALSE(PMR_GetType(psPMR) != PMR_TYPE_DMABUF,
PVRSRV_ERROR_PMR_WRONG_PMR_TYPE);
IMG_BOOL bIsExternalDmaBuf = IMG_FALSE;

eError = PMR_IsExportable(psPMR);
PVR_LOG_RETURN_IF_ERROR(eError, "PMR_IsExportable");

eError = PhysmemGetOrCreatePMRWrapper(psPMR, &psPMRWrapper);
PVR_LOG_GOTO_IF_ERROR(eError, "PhysmemExportDmaBuf", fail_get_pmr_wrapper);

eError = PMRRefPMR(psPMR);
PVR_LOG_GOTO_IF_ERROR(eError, "PMRRefPMR", fail_ref_pmr);

/*
* To avoid compatibility issue, CPU and GPU R/W flags are combined to determine
* dma_buf's file permissions. This approach might add GPU's R/W permission to
Expand Down Expand Up @@ -1947,9 +1939,17 @@ PhysmemExportDmaBuf(CONNECTION_DATA *psConnection,
iDmaBufFlags = O_RDONLY;
}

{
if (PMR_GetType(psPMR) == PMR_TYPE_DMABUF) {
psDmaBuf = PhysmemGetDmaBuf(psPMR);
PVR_RETURN_IF_FALSE(psDmaBuf != NULL, PVRSRV_ERROR_PMR_WRONG_PMR_TYPE);
get_dma_buf(psDmaBuf);
bIsExternalDmaBuf = IMG_TRUE;
} else {
DEFINE_DMA_BUF_EXPORT_INFO(sDmaBufExportInfo);

eError = PMRRefPMR(psPMR);
PVR_LOG_GOTO_IF_ERROR(eError, "PMRRefPMR", fail_ref_pmr);

sDmaBufExportInfo.priv = psPMRWrapper;
sDmaBufExportInfo.ops = &sPVRDmaBufOps;
sDmaBufExportInfo.size = PMR_LogicalSize(psPMR);
Expand Down Expand Up @@ -1985,7 +1985,8 @@ PhysmemExportDmaBuf(CONNECTION_DATA *psConnection,
return eError;

fail_export:
(void) PMRUnrefPMR(psPMR);
if (!bIsExternalDmaBuf)
(void) PMRUnrefPMR(psPMR);

fail_ref_pmr:
/* No need to destroy psPMRWrapper here. It will be (or already was)
Expand Down