1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
|
/*
* Copyright (C) 2021-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/debug_settings/debug_settings_manager.h"
#include "shared/source/helpers/common_types.h"
#include "shared/source/helpers/constants.h"
#include "shared/source/os_interface/linux/cache_info.h"
#include "shared/source/os_interface/linux/drm_wrappers.h"
#include "shared/source/os_interface/linux/i915.h"
#include "shared/source/os_interface/linux/ioctl_helper.h"
namespace NEO {
bool IoctlHelperUpstream::initialize() {
detectExtSetPatSupport();
initializeGetGpuTimeFunction();
return true;
}
bool IoctlHelperUpstream::isSetPairAvailable() {
return false;
}
bool IoctlHelperUpstream::isChunkingAvailable() {
return false;
}
bool IoctlHelperUpstream::isVmBindAvailable() {
return false;
}
int IoctlHelperUpstream::createGemExt(const MemRegionsVec &memClassInstances, size_t allocSize, uint32_t &handle, uint64_t patIndex, std::optional<uint32_t> vmId, int32_t pairHandle, bool isChunked, uint32_t numOfChunks, std::optional<uint32_t> memPolicyMode, std::optional<std::vector<unsigned long>> memPolicyNodemask, std::optional<bool> isCoherent) {
bool isPatIndexValid = (patIndex != CommonConstants::unsupportedPatIndex) && (patIndex <= std::numeric_limits<uint32_t>::max());
bool useSetPat = this->isSetPatSupported && isPatIndexValid;
uint32_t regionsSize = static_cast<uint32_t>(memClassInstances.size());
std::vector<drm_i915_gem_memory_class_instance> regions(regionsSize);
for (uint32_t i = 0; i < regionsSize; i++) {
regions[i].memory_class = memClassInstances[i].memoryClass;
regions[i].memory_instance = memClassInstances[i].memoryInstance;
}
drm_i915_gem_create_ext_memory_regions memRegions{};
memRegions.num_regions = regionsSize;
memRegions.regions = reinterpret_cast<uintptr_t>(regions.data());
memRegions.base.name = I915_GEM_CREATE_EXT_MEMORY_REGIONS;
drm_i915_gem_create_ext_set_pat setPat{};
setPat.pat_index = static_cast<uint32_t>(patIndex);
setPat.base.name = I915_GEM_CREATE_EXT_SET_PAT;
drm_i915_gem_create_ext createExt{};
createExt.size = allocSize;
createExt.extensions = reinterpret_cast<uintptr_t>(&memRegions);
if (useSetPat) {
memRegions.base.next_extension = reinterpret_cast<uintptr_t>(&setPat);
}
if (debugManager.flags.PrintBOCreateDestroyResult.get()) {
printDebugString(debugManager.flags.PrintBOCreateDestroyResult.get(), stdout, "Performing GEM_CREATE_EXT with { size: %lu",
allocSize);
for (uint32_t i = 0; i < regionsSize; i++) {
auto region = regions[i];
printDebugString(debugManager.flags.PrintBOCreateDestroyResult.get(), stdout, ", memory class: %d, memory instance: %d",
region.memory_class, region.memory_instance);
}
if (useSetPat) {
printDebugString(debugManager.flags.PrintBOCreateDestroyResult.get(), stdout, ", pat index: %lu", patIndex);
}
printDebugString(debugManager.flags.PrintBOCreateDestroyResult.get(), stdout, "%s", " }\n");
}
auto ret = ioctl(DrmIoctl::gemCreateExt, &createExt);
handle = createExt.handle;
printDebugString(debugManager.flags.PrintBOCreateDestroyResult.get(), stdout, "GEM_CREATE_EXT with EXT_MEMORY_REGIONS%s has returned: %d BO-%u with size: %lu\n",
(useSetPat) ? " with EXT_SET_PAT" : "",
ret, createExt.handle, createExt.size);
return ret;
}
void IoctlHelperUpstream::detectExtSetPatSupport() {
drm_i915_gem_create_ext_set_pat setPat{};
setPat.pat_index = 0;
setPat.base.name = I915_GEM_CREATE_EXT_SET_PAT;
drm_i915_gem_create_ext createExt{};
createExt.size = 1;
createExt.extensions = reinterpret_cast<uintptr_t>(&setPat);
auto isSetPatDisabled = debugManager.flags.DisableGemCreateExtSetPat.get();
if (!isSetPatDisabled) {
int returnValue = ioctl(DrmIoctl::gemCreateExt, &createExt);
this->isSetPatSupported = (returnValue == 0);
if (returnValue == 0) {
GemClose close{};
close.handle = createExt.handle;
returnValue = ioctl(DrmIoctl::gemClose, &close);
UNRECOVERABLE_IF(returnValue);
}
}
printDebugString(debugManager.flags.PrintBOCreateDestroyResult.get(), stdout, "EXT_SET_PAT support is: %s\n",
this->isSetPatSupported ? "enabled" : "disabled");
}
CacheRegion IoctlHelperUpstream::closAlloc(CacheLevel cacheLevel) {
return CacheRegion::none;
}
uint16_t IoctlHelperUpstream::closAllocWays(CacheRegion closIndex, uint16_t cacheLevel, uint16_t numWays) {
return 0;
}
CacheRegion IoctlHelperUpstream::closFree(CacheRegion closIndex) {
return CacheRegion::none;
}
int IoctlHelperUpstream::waitUserFence(uint32_t ctxId, uint64_t address, uint64_t value, uint32_t dataWidth, int64_t timeout, uint16_t flags,
bool userInterrupt, uint32_t externalInterruptId, GraphicsAllocation *allocForInterruptWait) {
return 0;
}
uint32_t IoctlHelperUpstream::getAtomicAdvise(bool isNonAtomic) {
return 0;
}
uint32_t IoctlHelperUpstream::getAtomicAccess(AtomicAccessMode mode) {
return 0;
}
uint64_t IoctlHelperUpstream::getPreferredLocationArgs(MemAdvise memAdviseOp) {
return 0;
}
uint32_t IoctlHelperUpstream::getPreferredLocationAdvise() {
return 0;
}
std::optional<MemoryClassInstance> IoctlHelperUpstream::getPreferredLocationRegion(PreferredLocation memoryLocation, uint32_t memoryInstance) {
return std::nullopt;
}
bool IoctlHelperUpstream::setVmBoAdvise(int32_t handle, uint32_t attribute, void *region) {
return true;
}
bool IoctlHelperUpstream::setVmBoAdviseForChunking(int32_t handle, uint64_t start, uint64_t length, uint32_t attribute, void *region) {
return true;
}
bool IoctlHelperUpstream::setVmPrefetch(uint64_t start, uint64_t length, uint32_t region, uint32_t vmId) {
return true;
}
uint32_t IoctlHelperUpstream::getDirectSubmissionFlag() {
return 0u;
}
std::unique_ptr<uint8_t[]> IoctlHelperUpstream::prepareVmBindExt(const StackVec<uint32_t, 2> &bindExtHandles, uint64_t cookie) {
return {};
}
uint64_t IoctlHelperUpstream::getFlagsForVmBind(bool bindCapture, bool bindImmediate, bool bindMakeResident, bool bindLockedMemory, bool readOnlyResource) {
return 0u;
}
int IoctlHelperUpstream::queryDistances(std::vector<QueryItem> &queryItems, std::vector<DistanceInfo> &distanceInfos) {
for (auto &query : queryItems) {
query.length = -EINVAL;
}
return 0;
}
uint16_t IoctlHelperUpstream::getWaitUserFenceSoftFlag() {
return 0;
}
int IoctlHelperUpstream::execBuffer(ExecBuffer *execBuffer, uint64_t completionGpuAddress, TaskCountType counterValue) {
return ioctl(DrmIoctl::gemExecbuffer2, execBuffer);
}
bool IoctlHelperUpstream::completionFenceExtensionSupported(const bool isVmBindAvailable) {
return false;
}
bool IoctlHelperUpstream::isPageFaultSupported() {
return false;
};
bool IoctlHelperUpstream::isEuStallSupported() {
return false;
}
uint32_t IoctlHelperUpstream::getEuStallFdParameter() {
return 0u;
}
bool IoctlHelperUpstream::perfOpenEuStallStream(uint32_t euStallFdParameter, uint32_t &samplingPeriodNs, uint64_t engineInstance, uint64_t notifyNReports, uint64_t gpuTimeStampfrequency, int32_t *stream) {
return false;
}
bool IoctlHelperUpstream::perfDisableEuStallStream(int32_t *stream) {
return false;
}
std::unique_ptr<uint8_t[]> IoctlHelperUpstream::createVmControlExtRegion(const std::optional<MemoryClassInstance> ®ionInstanceClass) {
return {};
}
uint32_t IoctlHelperUpstream::getFlagsForVmCreate(bool disableScratch, bool enablePageFault, bool useVmBind) {
return 0u;
}
uint32_t IoctlHelperUpstream::createContextWithAccessCounters(GemContextCreateExt &gcc) {
return EINVAL;
}
uint32_t IoctlHelperUpstream::createCooperativeContext(GemContextCreateExt &gcc) {
return EINVAL;
}
void IoctlHelperUpstream::fillVmBindExtSetPat(VmBindExtSetPatT &vmBindExtSetPat, uint64_t patIndex, uint64_t nextExtension) {}
void IoctlHelperUpstream::fillVmBindExtUserFence(VmBindExtUserFenceT &vmBindExtUserFence, uint64_t fenceAddress, uint64_t fenceValue, uint64_t nextExtension) {}
void IoctlHelperUpstream::setVmBindUserFence(VmBindParams &vmBind, VmBindExtUserFenceT vmBindUserFence){};
std::optional<uint32_t> IoctlHelperUpstream::getVmAdviseAtomicAttribute() {
return 0;
}
int IoctlHelperUpstream::vmBind(const VmBindParams &vmBindParams) {
return 0;
}
int IoctlHelperUpstream::vmUnbind(const VmBindParams &vmBindParams) {
return 0;
}
int IoctlHelperUpstream::getResetStats(ResetStats &resetStats, uint32_t *status, ResetStatsFault *resetStatsFault) {
return ioctl(DrmIoctl::getResetStats, &resetStats);
}
UuidRegisterResult IoctlHelperUpstream::registerUuid(const std::string &uuid, uint32_t uuidClass, uint64_t ptr, uint64_t size) {
return {0, 0};
}
UuidRegisterResult IoctlHelperUpstream::registerStringClassUuid(const std::string &uuid, uint64_t ptr, uint64_t size) {
return {0, 0};
}
int IoctlHelperUpstream::unregisterUuid(uint32_t handle) {
return 0;
}
bool IoctlHelperUpstream::isContextDebugSupported() {
return false;
}
int IoctlHelperUpstream::setContextDebugFlag(uint32_t drmContextId) {
return 0;
}
bool IoctlHelperUpstream::isDebugAttachAvailable() {
return false;
}
unsigned int IoctlHelperUpstream::getIoctlRequestValue(DrmIoctl ioctlRequest) const {
switch (ioctlRequest) {
case DrmIoctl::gemCreateExt:
return DRM_IOCTL_I915_GEM_CREATE_EXT;
default:
return IoctlHelperI915::getIoctlRequestValue(ioctlRequest);
}
}
int IoctlHelperUpstream::getDrmParamValue(DrmParam drmParam) const {
switch (drmParam) {
case DrmParam::engineClassCompute:
return 4;
case DrmParam::queryHwconfigTable:
return DRM_I915_QUERY_HWCONFIG_BLOB;
case DrmParam::queryComputeSlices:
return 0;
default:
return IoctlHelperI915::getDrmParamValueBase(drmParam);
}
}
std::string IoctlHelperUpstream::getIoctlString(DrmIoctl ioctlRequest) const {
switch (ioctlRequest) {
case DrmIoctl::gemCreateExt:
return "DRM_IOCTL_I915_GEM_CREATE_EXT";
default:
return IoctlHelperI915::getIoctlString(ioctlRequest);
}
}
bool IoctlHelperUpstream::getFabricLatency(uint32_t fabricId, uint32_t &latency, uint32_t &bandwidth) {
return false;
}
bool IoctlHelperUpstream::requiresUserFenceSetup(bool bind) const {
return false;
}
} // namespace NEO
|