From 34acf33a10f4ed15d13be9062b246ef085888973 Mon Sep 17 00:00:00 2001 From: Filip Hazubski Date: Tue, 29 Oct 2024 14:37:52 +0100 Subject: [PATCH] feature: Add PCI barrier mmap logic for xe Related-To: NEO-13081 Signed-off-by: Filip Hazubski --- .../os_interface/linux/xe/ioctl_helper_xe.cpp | 12 ++++++++++++ .../source/os_interface/linux/xe/ioctl_helper_xe.h | 1 + third_party/uapi/upstream/xe/xe_drm.h | 13 ++++++++++++- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/shared/source/os_interface/linux/xe/ioctl_helper_xe.cpp b/shared/source/os_interface/linux/xe/ioctl_helper_xe.cpp index ae06e50ee9655..676db1f596cd9 100644 --- a/shared/source/os_interface/linux/xe/ioctl_helper_xe.cpp +++ b/shared/source/os_interface/linux/xe/ioctl_helper_xe.cpp @@ -1703,4 +1703,16 @@ void IoctlHelperXe::querySupportedFeatures() { bool IoctlHelperXe::isEuPerDssTopologyType(uint16_t topologyType) const { return topologyType == DRM_XE_TOPO_EU_PER_DSS; } + +void *IoctlHelperXe::pciBarrierMmap() { + GemMmapOffset mmapOffset = {}; + mmapOffset.flags = DRM_XE_MMAP_OFFSET_FLAG_PCI_BARRIER; + auto ret = ioctl(DrmIoctl::gemMmapOffset, &mmapOffset); + if (ret != 0) { + return false; + } + + return SysCalls::mmap(NULL, MemoryConstants::pageSize, PROT_WRITE, MAP_SHARED, drm.getFileDescriptor(), static_cast(mmapOffset.offset)); +} + } // namespace NEO diff --git a/shared/source/os_interface/linux/xe/ioctl_helper_xe.h b/shared/source/os_interface/linux/xe/ioctl_helper_xe.h index 1bf1091ad8fe4..590b26db412d4 100644 --- a/shared/source/os_interface/linux/xe/ioctl_helper_xe.h +++ b/shared/source/os_interface/linux/xe/ioctl_helper_xe.h @@ -133,6 +133,7 @@ class IoctlHelperXe : public IoctlHelper { bool resourceRegistrationEnabled() override { return true; } bool isPreemptionSupported() override { return true; } virtual bool isEuPerDssTopologyType(uint16_t topologyType) const; + void *pciBarrierMmap() override; protected: static constexpr uint32_t maxContextSetProperties = 4; diff --git a/third_party/uapi/upstream/xe/xe_drm.h b/third_party/uapi/upstream/xe/xe_drm.h index 4b28e5d512ba0..c8578122e3f9c 100644 --- a/third_party/uapi/upstream/xe/xe_drm.h +++ b/third_party/uapi/upstream/xe/xe_drm.h @@ -809,7 +809,18 @@ struct drm_xe_gem_mmap_offset { /** @handle: Handle for the object being mapped. */ __u32 handle; - /** @flags: Must be zero */ +/** + * For user to query special offset we are adding special flag in + * mmap_offset ioctl which needs to be passed as follows, + * struct drm_xe_gem_mmap_offset mmo = { + * .handle = 0, (this must be set to 0) + * .flags = DRM_XE_MMAP_OFFSET_FLAG_PCI_BARRIER, + * }; + * igt_ioctl(fd, DRM_IOCTL_XE_GEM_MMAP_OFFSET, &mmo); + * map = mmap(NULL, size, PROT_WRITE, MAP_SHARED, fd, mmo); +*/ +#define DRM_XE_MMAP_OFFSET_FLAG_PCI_BARRIER (1 << 0) + /** @flags: Flag to indicate if any special offset, zero otherwise */ __u32 flags; /** @offset: The fake offset to use for subsequent mmap call */