2017-12-21 00:45:38 +01:00
|
|
|
/*
|
2021-05-16 20:51:16 +02:00
|
|
|
* Copyright (C) 2018-2021 Intel Corporation
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
2018-09-18 09:11:08 +02:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
2020-07-28 07:48:41 +02:00
|
|
|
|
2021-10-20 16:16:59 +00:00
|
|
|
#include "shared/source/gmm_helper/gmm_helper.h"
|
2021-06-29 16:23:56 +00:00
|
|
|
#include "shared/source/memory_manager/definitions/engine_limits.h"
|
2021-01-29 22:23:06 +00:00
|
|
|
#include "shared/source/os_interface/linux/cache_info.h"
|
2020-09-14 13:28:47 +02:00
|
|
|
#include "shared/source/utilities/stackvec.h"
|
|
|
|
|
2020-06-09 10:00:59 +02:00
|
|
|
#include "drm/i915_drm.h"
|
|
|
|
|
2020-07-28 07:48:41 +02:00
|
|
|
#include <array>
|
2017-12-21 00:45:38 +01:00
|
|
|
#include <atomic>
|
2019-07-17 15:38:14 +02:00
|
|
|
#include <cstddef>
|
2019-02-27 11:39:32 +01:00
|
|
|
#include <stdint.h>
|
2020-08-11 14:00:41 +02:00
|
|
|
#include <vector>
|
2020-05-06 03:37:15 -07:00
|
|
|
|
|
|
|
struct drm_i915_gem_exec_object2;
|
|
|
|
struct drm_i915_gem_relocation_entry;
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
namespace NEO {
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
class DrmMemoryManager;
|
|
|
|
class Drm;
|
2020-08-11 14:00:41 +02:00
|
|
|
class OsContext;
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
class BufferObject {
|
|
|
|
public:
|
2020-08-20 13:20:20 +02:00
|
|
|
BufferObject(Drm *drm, int handle, size_t size, size_t maxOsContextCount);
|
2020-09-17 13:27:32 +02:00
|
|
|
MOCKABLE_VIRTUAL ~BufferObject() = default;
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2020-07-17 13:40:52 +02:00
|
|
|
struct Deleter {
|
|
|
|
void operator()(BufferObject *bo) {
|
|
|
|
bo->close();
|
|
|
|
delete bo;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
bool setTiling(uint32_t mode, uint32_t stride);
|
|
|
|
|
2020-10-16 13:46:25 +02: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 12:09:48 +01:00
|
|
|
|
2020-08-11 14:00:41 +02:00
|
|
|
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);
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2020-10-16 12:59:27 +02:00
|
|
|
int bind(OsContext *osContext, uint32_t vmHandleId);
|
|
|
|
int unbind(OsContext *osContext, uint32_t vmHandleId);
|
2020-07-02 11:49:46 +02:00
|
|
|
|
2020-08-13 10:10:48 +02:00
|
|
|
void printExecutionBuffer(drm_i915_gem_execbuffer2 &execbuf, const size_t &residencyCount, drm_i915_gem_exec_object2 *execObjectsStorage, BufferObject *const residency[]);
|
2020-06-09 10:00:59 +02:00
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
int wait(int64_t timeoutNs);
|
|
|
|
bool close();
|
|
|
|
|
|
|
|
inline void reference() {
|
|
|
|
this->refCount++;
|
|
|
|
}
|
2021-10-21 11:49:50 +00:00
|
|
|
inline uint32_t unreference() {
|
|
|
|
return this->refCount.fetch_sub(1);
|
|
|
|
}
|
2017-12-21 00:45:38 +01:00
|
|
|
uint32_t getRefCount() const;
|
|
|
|
|
2018-02-26 23:23:43 +01:00
|
|
|
size_t peekSize() const { return size; }
|
|
|
|
int peekHandle() const { return handle; }
|
2021-10-21 11:49:50 +00:00
|
|
|
const Drm *peekDrm() const { return drm; }
|
2019-02-20 15:08:03 +01:00
|
|
|
uint64_t peekAddress() const { return gpuAddress; }
|
2021-10-20 16:16:59 +00:00
|
|
|
void setAddress(uint64_t address) { this->gpuAddress = GmmHelper::canonize(address); }
|
2018-02-26 23:23:43 +01:00
|
|
|
void *peekLockedAddress() const { return lockedAddress; }
|
|
|
|
void setLockedAddress(void *cpuAddress) { this->lockedAddress = cpuAddress; }
|
2017-12-21 00:45:38 +01:00
|
|
|
void setUnmapSize(uint64_t unmapSize) { this->unmapSize = unmapSize; }
|
2018-02-26 23:23:43 +01:00
|
|
|
uint64_t peekUnmapSize() const { return unmapSize; }
|
2020-05-06 03:37:15 -07:00
|
|
|
bool peekIsReusableAllocation() const { return this->isReused; }
|
2021-10-21 11:49:50 +00:00
|
|
|
void markAsReusableAllocation() { this->isReused = true; }
|
2020-09-14 13:28:47 +02:00
|
|
|
void addBindExtHandle(uint32_t handle);
|
2020-09-18 15:27:06 +02:00
|
|
|
StackVec<uint32_t, 2> &getBindExtHandles() { return bindExtHandles; }
|
2020-10-09 10:48:37 +02:00
|
|
|
void markForCapture() {
|
|
|
|
allowCapture = true;
|
|
|
|
}
|
|
|
|
bool isMarkedForCapture() {
|
|
|
|
return allowCapture;
|
|
|
|
}
|
2021-06-17 12:23:51 +00:00
|
|
|
|
|
|
|
bool isImmediateBindingRequired() {
|
|
|
|
return requiresImmediateBinding;
|
|
|
|
}
|
|
|
|
void requireImmediateBinding(bool required) {
|
|
|
|
requiresImmediateBinding = required;
|
|
|
|
}
|
|
|
|
|
2021-11-02 07:54:20 +00:00
|
|
|
bool isExplicitResidencyRequired() {
|
|
|
|
return requiresExplicitResidency;
|
|
|
|
}
|
|
|
|
void requireExplicitResidency(bool required) {
|
|
|
|
requiresExplicitResidency = required;
|
|
|
|
}
|
|
|
|
|
2021-01-29 22:23:06 +00:00
|
|
|
void setCacheRegion(CacheRegion regionIndex) { cacheRegion = regionIndex; }
|
|
|
|
CacheRegion peekCacheRegion() const { return cacheRegion; }
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2021-10-06 23:22:22 +00:00
|
|
|
void setCachePolicy(CachePolicy memType) { cachePolicy = memType; }
|
|
|
|
CachePolicy peekCachePolicy() const { return cachePolicy; }
|
|
|
|
|
2021-10-20 17:07:51 +00: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;
|
|
|
|
}
|
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
protected:
|
2020-02-11 17:48:40 +01:00
|
|
|
Drm *drm = nullptr;
|
2020-08-11 14:00:41 +02:00
|
|
|
bool perContextVmsUsed = false;
|
2017-12-21 00:45:38 +01:00
|
|
|
std::atomic<uint32_t> refCount;
|
|
|
|
|
|
|
|
int handle; // i915 gem object handle
|
2019-10-22 10:26:23 +02:00
|
|
|
uint64_t size;
|
2017-12-21 00:45:38 +01:00
|
|
|
bool isReused;
|
|
|
|
|
|
|
|
//Tiling
|
|
|
|
uint32_t tiling_mode;
|
2020-10-09 10:48:37 +02:00
|
|
|
bool allowCapture = false;
|
2021-06-17 12:23:51 +00:00
|
|
|
bool requiresImmediateBinding = false;
|
2021-11-02 07:54:20 +00:00
|
|
|
bool requiresExplicitResidency = false;
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2020-10-15 08:48:58 +02:00
|
|
|
uint32_t getOsContextId(OsContext *osContext);
|
2020-08-11 14:00:41 +02:00
|
|
|
MOCKABLE_VIRTUAL void fillExecObject(drm_i915_gem_exec_object2 &execObject, OsContext *osContext, uint32_t vmHandleId, uint32_t drmContextId);
|
2021-01-27 13:40:33 +00:00
|
|
|
void fillExecObjectImpl(drm_i915_gem_exec_object2 &execObject, OsContext *osContext, uint32_t vmHandleId);
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2018-02-26 23:23:43 +01:00
|
|
|
void *lockedAddress; // CPU side virtual address
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
uint64_t unmapSize = 0;
|
2020-07-28 07:48:41 +02:00
|
|
|
|
2021-01-29 22:23:06 +00:00
|
|
|
CacheRegion cacheRegion = CacheRegion::Default;
|
2021-10-06 23:22:22 +00:00
|
|
|
CachePolicy cachePolicy = CachePolicy::WriteBack;
|
2021-01-29 22:23:06 +00:00
|
|
|
|
2020-08-11 14:00:41 +02:00
|
|
|
std::vector<std::array<bool, EngineLimits::maxHandleCount>> bindInfo;
|
2020-09-14 13:28:47 +02:00
|
|
|
StackVec<uint32_t, 2> bindExtHandles;
|
2021-10-21 11:49:50 +00:00
|
|
|
|
2021-10-20 17:07:51 +00:00
|
|
|
bool colourWithBind = false;
|
|
|
|
size_t colourChunk = 0;
|
|
|
|
std::vector<uint64_t> bindAddresses;
|
|
|
|
|
2021-10-21 11:49:50 +00:00
|
|
|
private:
|
|
|
|
uint64_t gpuAddress = 0llu;
|
2017-12-21 00:45:38 +01:00
|
|
|
};
|
2019-03-26 11:59:46 +01:00
|
|
|
} // namespace NEO
|