2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2022-01-20 02:14:10 +08:00
|
|
|
* Copyright (C) 2018-2022 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
2020-07-28 13:48:41 +08:00
|
|
|
|
2021-10-21 00:16:59 +08:00
|
|
|
#include "shared/source/gmm_helper/gmm_helper.h"
|
2021-06-30 00:23:56 +08:00
|
|
|
#include "shared/source/memory_manager/definitions/engine_limits.h"
|
2022-04-13 18:42:27 +08:00
|
|
|
#include "shared/source/memory_manager/memory_operations_status.h"
|
2021-01-30 06:23:06 +08:00
|
|
|
#include "shared/source/os_interface/linux/cache_info.h"
|
2020-09-14 19:28:47 +08:00
|
|
|
#include "shared/source/utilities/stackvec.h"
|
|
|
|
|
2020-07-28 13:48:41 +08:00
|
|
|
#include <array>
|
2017-12-21 07:45:38 +08:00
|
|
|
#include <atomic>
|
2019-07-17 21:38:14 +08:00
|
|
|
#include <cstddef>
|
2019-02-27 18:39:32 +08:00
|
|
|
#include <stdint.h>
|
2020-08-11 20:00:41 +08:00
|
|
|
#include <vector>
|
2020-05-06 18:37:15 +08:00
|
|
|
|
|
|
|
struct drm_i915_gem_exec_object2;
|
|
|
|
struct drm_i915_gem_relocation_entry;
|
2022-05-11 20:01:41 +08:00
|
|
|
struct drm_i915_gem_execbuffer2;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
class DrmMemoryManager;
|
|
|
|
class Drm;
|
2020-08-11 20:00:41 +08:00
|
|
|
class OsContext;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
class BufferObject {
|
|
|
|
public:
|
2022-04-20 03:24:19 +08:00
|
|
|
BufferObject(Drm *drm, uint64_t patIndex, int handle, size_t size, size_t maxOsContextCount);
|
2020-09-17 19:27:32 +08:00
|
|
|
MOCKABLE_VIRTUAL ~BufferObject() = default;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2020-07-17 19:40:52 +08:00
|
|
|
struct Deleter {
|
|
|
|
void operator()(BufferObject *bo) {
|
|
|
|
bo->close();
|
|
|
|
delete bo;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
bool setTiling(uint32_t mode, uint32_t stride);
|
|
|
|
|
2020-10-16 19:46:25 +08:00
|
|
|
int pin(BufferObject *const boToPin[], size_t numberOfBos, OsContext *osContext, uint32_t vmHandleId, uint32_t drmContextId);
|
|
|
|
MOCKABLE_VIRTUAL int validateHostPtr(BufferObject *const boToPin[], size_t numberOfBos, OsContext *osContext, uint32_t vmHandleId, uint32_t drmContextId);
|
2018-02-28 19:09:48 +08:00
|
|
|
|
2022-01-20 19:07:57 +08:00
|
|
|
MOCKABLE_VIRTUAL int exec(uint32_t used, size_t startOffset, unsigned int flags, bool requiresCoherency, OsContext *osContext, uint32_t vmHandleId, uint32_t drmContextId,
|
|
|
|
BufferObject *const residency[], size_t residencyCount, drm_i915_gem_exec_object2 *execObjectsStorage, uint64_t completionGpuAddress, uint32_t completionValue);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2020-10-16 18:59:27 +08:00
|
|
|
int bind(OsContext *osContext, uint32_t vmHandleId);
|
|
|
|
int unbind(OsContext *osContext, uint32_t vmHandleId);
|
2020-07-02 17:49:46 +08:00
|
|
|
|
2020-08-13 16:10:48 +08:00
|
|
|
void printExecutionBuffer(drm_i915_gem_execbuffer2 &execbuf, const size_t &residencyCount, drm_i915_gem_exec_object2 *execObjectsStorage, BufferObject *const residency[]);
|
2020-06-09 16:00:59 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
int wait(int64_t timeoutNs);
|
|
|
|
bool close();
|
|
|
|
|
|
|
|
inline void reference() {
|
|
|
|
this->refCount++;
|
|
|
|
}
|
2021-10-21 19:49:50 +08:00
|
|
|
inline uint32_t unreference() {
|
|
|
|
return this->refCount.fetch_sub(1);
|
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
uint32_t getRefCount() const;
|
|
|
|
|
2018-02-27 06:23:43 +08:00
|
|
|
size_t peekSize() const { return size; }
|
|
|
|
int peekHandle() const { return handle; }
|
2021-10-21 19:49:50 +08:00
|
|
|
const Drm *peekDrm() const { return drm; }
|
2019-02-20 22:08:03 +08:00
|
|
|
uint64_t peekAddress() const { return gpuAddress; }
|
2022-05-11 22:59:23 +08:00
|
|
|
void setAddress(uint64_t address);
|
2018-02-27 06:23:43 +08:00
|
|
|
void *peekLockedAddress() const { return lockedAddress; }
|
|
|
|
void setLockedAddress(void *cpuAddress) { this->lockedAddress = cpuAddress; }
|
2017-12-21 07:45:38 +08:00
|
|
|
void setUnmapSize(uint64_t unmapSize) { this->unmapSize = unmapSize; }
|
2018-02-27 06:23:43 +08:00
|
|
|
uint64_t peekUnmapSize() const { return unmapSize; }
|
2020-05-06 18:37:15 +08:00
|
|
|
bool peekIsReusableAllocation() const { return this->isReused; }
|
2021-10-21 19:49:50 +08:00
|
|
|
void markAsReusableAllocation() { this->isReused = true; }
|
2020-09-14 19:28:47 +08:00
|
|
|
void addBindExtHandle(uint32_t handle);
|
2022-02-10 00:07:36 +08:00
|
|
|
const StackVec<uint32_t, 2> &getBindExtHandles() const { return bindExtHandles; }
|
2020-10-09 16:48:37 +08:00
|
|
|
void markForCapture() {
|
|
|
|
allowCapture = true;
|
|
|
|
}
|
|
|
|
bool isMarkedForCapture() {
|
|
|
|
return allowCapture;
|
|
|
|
}
|
2021-06-17 20:23:51 +08:00
|
|
|
|
|
|
|
bool isImmediateBindingRequired() {
|
|
|
|
return requiresImmediateBinding;
|
|
|
|
}
|
|
|
|
void requireImmediateBinding(bool required) {
|
|
|
|
requiresImmediateBinding = required;
|
|
|
|
}
|
|
|
|
|
2021-11-02 15:54:20 +08:00
|
|
|
bool isExplicitResidencyRequired() {
|
|
|
|
return requiresExplicitResidency;
|
|
|
|
}
|
|
|
|
void requireExplicitResidency(bool required) {
|
|
|
|
requiresExplicitResidency = required;
|
|
|
|
}
|
2021-09-11 17:37:42 +08:00
|
|
|
void setRootDeviceIndex(uint32_t index) {
|
|
|
|
rootDeviceIndex = index;
|
|
|
|
}
|
|
|
|
uint32_t getRootDeviceIndex() {
|
|
|
|
return rootDeviceIndex;
|
|
|
|
}
|
|
|
|
int getHandle() {
|
|
|
|
return handle;
|
|
|
|
}
|
2021-11-02 15:54:20 +08:00
|
|
|
|
2021-01-30 06:23:06 +08:00
|
|
|
void setCacheRegion(CacheRegion regionIndex) { cacheRegion = regionIndex; }
|
|
|
|
CacheRegion peekCacheRegion() const { return cacheRegion; }
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2021-10-07 07:22:22 +08:00
|
|
|
void setCachePolicy(CachePolicy memType) { cachePolicy = memType; }
|
|
|
|
CachePolicy peekCachePolicy() const { return cachePolicy; }
|
|
|
|
|
2021-10-21 01:07:51 +08:00
|
|
|
void setColourWithBind() {
|
|
|
|
this->colourWithBind = true;
|
|
|
|
}
|
|
|
|
void setColourChunk(size_t size) {
|
|
|
|
this->colourChunk = size;
|
|
|
|
}
|
|
|
|
void addColouringAddress(uint64_t address) {
|
|
|
|
this->bindAddresses.push_back(address);
|
|
|
|
}
|
|
|
|
void reserveAddressVector(size_t size) {
|
|
|
|
this->bindAddresses.reserve(size);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool getColourWithBind() {
|
|
|
|
return this->colourWithBind;
|
|
|
|
}
|
|
|
|
size_t getColourChunk() {
|
|
|
|
return this->colourChunk;
|
|
|
|
}
|
|
|
|
std::vector<uint64_t> &getColourAddresses() {
|
|
|
|
return this->bindAddresses;
|
|
|
|
}
|
2022-04-20 03:24:19 +08:00
|
|
|
uint64_t peekPatIndex() const { return patIndex; }
|
|
|
|
void setPatIndex(uint64_t newPatIndex) { this->patIndex = newPatIndex; }
|
2021-10-21 01:07:51 +08:00
|
|
|
|
2022-05-10 01:40:30 +08:00
|
|
|
static constexpr int gpuHangDetected{-7171};
|
2022-04-13 18:42:27 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
protected:
|
2022-04-13 18:42:27 +08:00
|
|
|
MOCKABLE_VIRTUAL MemoryOperationsStatus evictUnusedAllocations(bool waitForCompletion, bool isLockNeeded);
|
|
|
|
|
2020-02-12 00:48:40 +08:00
|
|
|
Drm *drm = nullptr;
|
2020-08-11 20:00:41 +08:00
|
|
|
bool perContextVmsUsed = false;
|
2017-12-21 07:45:38 +08:00
|
|
|
std::atomic<uint32_t> refCount;
|
|
|
|
|
2021-09-11 17:37:42 +08:00
|
|
|
uint32_t rootDeviceIndex = std::numeric_limits<uint32_t>::max();
|
2017-12-21 07:45:38 +08:00
|
|
|
int handle; // i915 gem object handle
|
2019-10-22 16:26:23 +08:00
|
|
|
uint64_t size;
|
2022-05-10 01:40:30 +08:00
|
|
|
bool isReused = false;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2022-01-21 02:13:07 +08:00
|
|
|
uint32_t tilingMode;
|
2020-10-09 16:48:37 +08:00
|
|
|
bool allowCapture = false;
|
2021-06-17 20:23:51 +08:00
|
|
|
bool requiresImmediateBinding = false;
|
2021-11-02 15:54:20 +08:00
|
|
|
bool requiresExplicitResidency = false;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2020-10-15 14:48:58 +08:00
|
|
|
uint32_t getOsContextId(OsContext *osContext);
|
2020-08-11 20:00:41 +08:00
|
|
|
MOCKABLE_VIRTUAL void fillExecObject(drm_i915_gem_exec_object2 &execObject, OsContext *osContext, uint32_t vmHandleId, uint32_t drmContextId);
|
2022-02-04 23:28:20 +08:00
|
|
|
void printBOBindingResult(OsContext *osContext, uint32_t vmHandleId, bool bind, int retVal);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2018-02-27 06:23:43 +08:00
|
|
|
void *lockedAddress; // CPU side virtual address
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
uint64_t unmapSize = 0;
|
2022-04-20 03:24:19 +08:00
|
|
|
uint64_t patIndex = CommonConstants::unsupportedPatIndex;
|
2020-07-28 13:48:41 +08:00
|
|
|
|
2021-01-30 06:23:06 +08:00
|
|
|
CacheRegion cacheRegion = CacheRegion::Default;
|
2021-10-07 07:22:22 +08:00
|
|
|
CachePolicy cachePolicy = CachePolicy::WriteBack;
|
2021-01-30 06:23:06 +08:00
|
|
|
|
2020-08-11 20:00:41 +08:00
|
|
|
std::vector<std::array<bool, EngineLimits::maxHandleCount>> bindInfo;
|
2020-09-14 19:28:47 +08:00
|
|
|
StackVec<uint32_t, 2> bindExtHandles;
|
2021-10-21 19:49:50 +08:00
|
|
|
|
2021-10-21 01:07:51 +08:00
|
|
|
bool colourWithBind = false;
|
|
|
|
size_t colourChunk = 0;
|
|
|
|
std::vector<uint64_t> bindAddresses;
|
|
|
|
|
2021-10-21 19:49:50 +08:00
|
|
|
private:
|
|
|
|
uint64_t gpuAddress = 0llu;
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|