From 6e83fe47edc1781126db1fabd840400e285e66b9 Mon Sep 17 00:00:00 2001 From: Manoj Takasi Date: Sat, 20 Jul 2024 06:01:34 +0000 Subject: [PATCH] Initial changes to remove hardcoded cu size check in shim.cpp Signed-off-by: Manoj Takasi (cherry picked from commit 2e4cc9081dc7b902e50644700da27a24627ec9b9) --- src/runtime_src/core/edge/user/shim.cpp | 19 ++++++++++--------- src/runtime_src/core/edge/user/shim.h | 2 +- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/runtime_src/core/edge/user/shim.cpp b/src/runtime_src/core/edge/user/shim.cpp index ceda5ffd43e..bd7de9dabee 100644 --- a/src/runtime_src/core/edge/user/shim.cpp +++ b/src/runtime_src/core/edge/user/shim.cpp @@ -120,7 +120,7 @@ shim(unsigned index) : mCoreDevice(xrt_core::edge_linux::get_userpf_device(this, index)) , mBoardNumber(index) , mKernelClockFreq(100) - , mCuMaps(128, nullptr) + , mCuMaps(128, {nullptr, 0}) { xclLog(XRT_INFO, "%s", __func__); @@ -151,8 +151,8 @@ shim:: } for (auto p : mCuMaps) { - if (p) - (void) munmap(p, mCuMapSize); + if (p.first) + (void) munmap(p.first, p.second); } } @@ -1169,10 +1169,10 @@ xclCloseContext(const uuid_t xclbinId, unsigned int ipIndex) if (ipIndex < mCuMaps.size()) { // Make sure no MMIO register space access when CU is released. - uint32_t *p = mCuMaps[ipIndex]; + uint32_t *p = mCuMaps[ipIndex].first; if (p) { - (void) munmap(p, mCuMapSize); - mCuMaps[ipIndex] = nullptr; + (void) munmap(p, mCuMaps[ipIndex].second); + mCuMaps[ipIndex] = {nullptr, 0}; } } @@ -1201,16 +1201,17 @@ xclRegRW(bool rd, uint32_t ipIndex, uint32_t offset, uint32_t *datap) return -EINVAL; } - if (mCuMaps[ipIndex] == nullptr) { + if (mCuMaps[ipIndex].first == nullptr) { drm_zocl_info_cu info = {0, -1, (int)ipIndex}; int result = ioctl(mKernelFD, DRM_IOCTL_ZOCL_INFO_CU, &info); void *p = mmap(0, mCuMapSize, PROT_READ | PROT_WRITE, MAP_SHARED, mKernelFD, info.apt_idx * getpagesize()); if (p != MAP_FAILED) - mCuMaps[ipIndex] = (uint32_t *)p; + mCuMaps[ipIndex].first = (uint32_t *)p; + mCuMaps[ipIndex].second = mCuMapSize; } - uint32_t *cumap = mCuMaps[ipIndex]; + uint32_t *cumap = mCuMaps[ipIndex].first; if (cumap == nullptr) { xclLog(XRT_ERROR, "%s: can't map CU: %d", __func__, ipIndex); return -EINVAL; diff --git a/src/runtime_src/core/edge/user/shim.h b/src/runtime_src/core/edge/user/shim.h index 4ee00b1a980..5d55ebeba14 100644 --- a/src/runtime_src/core/edge/user/shim.h +++ b/src/runtime_src/core/edge/user/shim.h @@ -378,7 +378,7 @@ class shim { * Mapped CU register space for xclRegRead/Write(). We support at most * 128 CUs and each map is of 64k bytes. Does not support debug IP access. */ - std::vector mCuMaps; + std::vector> mCuMaps; const size_t mCuMapSize = 64 * 1024; std::mutex mCuMapLock; int xclRegRW(bool rd, uint32_t cu_index, uint32_t offset, uint32_t *datap);