2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2023-12-07 03:30:05 +08:00
|
|
|
* Copyright (C) 2018-2024 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-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/memory_manager/graphics_allocation.h"
|
2021-10-11 17:27:26 +08:00
|
|
|
#include "shared/source/memory_manager/memadvise_flags.h"
|
2020-08-20 19:48:47 +08:00
|
|
|
#include "shared/source/memory_manager/memory_manager.h"
|
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 BufferObject;
|
2020-08-11 20:00:41 +08:00
|
|
|
class OsContext;
|
2020-09-14 19:28:47 +08:00
|
|
|
class Drm;
|
2023-04-06 20:09:57 +08:00
|
|
|
class OsContextLinux;
|
2021-10-07 07:22:22 +08:00
|
|
|
enum class CachePolicy : uint32_t;
|
2021-01-30 06:23:06 +08:00
|
|
|
enum class CacheRegion : uint16_t;
|
2023-09-21 06:34:19 +08:00
|
|
|
enum class AtomicAccessMode : uint32_t;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2021-04-03 01:01:51 +08:00
|
|
|
struct OsHandleLinux : OsHandle {
|
2022-07-07 19:11:29 +08:00
|
|
|
~OsHandleLinux() override = default;
|
2017-12-21 07:45:38 +08:00
|
|
|
BufferObject *bo = nullptr;
|
|
|
|
};
|
|
|
|
|
2021-10-05 18:06:14 +08:00
|
|
|
using BufferObjects = StackVec<BufferObject *, EngineLimits::maxHandleCount>;
|
2019-09-02 03:36:15 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
class DrmAllocation : public GraphicsAllocation {
|
|
|
|
public:
|
2022-01-11 22:13:30 +08:00
|
|
|
using MemoryUnmapFunction = int (*)(void *, size_t);
|
|
|
|
|
|
|
|
struct MemoryToUnmap {
|
|
|
|
void *pointer;
|
|
|
|
size_t size;
|
|
|
|
MemoryUnmapFunction unmapFunction;
|
|
|
|
};
|
|
|
|
|
2022-06-03 19:48:45 +08:00
|
|
|
DrmAllocation(uint32_t rootDeviceIndex, size_t numGmms, AllocationType allocationType, BufferObject *bo, void *ptrIn, size_t sizeIn, osHandle sharedHandle, MemoryPool pool, uint64_t canonizedGpuAddress)
|
|
|
|
: GraphicsAllocation(rootDeviceIndex, numGmms, allocationType, ptrIn, sizeIn, sharedHandle, pool, MemoryManager::maxOsContextCount, canonizedGpuAddress), bufferObjects(EngineLimits::maxHandleCount) {
|
2021-10-05 18:06:14 +08:00
|
|
|
bufferObjects[0] = bo;
|
2022-11-10 10:57:51 +08:00
|
|
|
handles.resize(EngineLimits::maxHandleCount, std::numeric_limits<uint64_t>::max());
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
2019-02-26 18:37:51 +08:00
|
|
|
|
2022-06-02 05:13:52 +08:00
|
|
|
DrmAllocation(uint32_t rootDeviceIndex, size_t numGmms, AllocationType allocationType, BufferObject *bo, void *ptrIn, uint64_t canonizedGpuAddress, size_t sizeIn, MemoryPool pool)
|
2022-05-30 22:18:50 +08:00
|
|
|
: GraphicsAllocation(rootDeviceIndex, numGmms, allocationType, ptrIn, canonizedGpuAddress, 0, sizeIn, pool, MemoryManager::maxOsContextCount), bufferObjects(EngineLimits::maxHandleCount) {
|
2021-10-05 18:06:14 +08:00
|
|
|
bufferObjects[0] = bo;
|
2022-11-10 10:57:51 +08:00
|
|
|
handles.resize(EngineLimits::maxHandleCount, std::numeric_limits<uint64_t>::max());
|
2019-09-02 03:36:15 +08:00
|
|
|
}
|
|
|
|
|
2022-06-02 05:13:52 +08:00
|
|
|
DrmAllocation(uint32_t rootDeviceIndex, size_t numGmms, AllocationType allocationType, BufferObjects &bos, void *ptrIn, uint64_t canonizedGpuAddress, size_t sizeIn, MemoryPool pool)
|
2022-05-30 22:18:50 +08:00
|
|
|
: GraphicsAllocation(rootDeviceIndex, numGmms, allocationType, ptrIn, canonizedGpuAddress, 0, sizeIn, pool, MemoryManager::maxOsContextCount),
|
2019-09-02 03:36:15 +08:00
|
|
|
bufferObjects(bos) {
|
2022-11-10 10:57:51 +08:00
|
|
|
handles.resize(EngineLimits::maxHandleCount, std::numeric_limits<uint64_t>::max());
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2022-01-11 22:13:30 +08:00
|
|
|
~DrmAllocation() override;
|
|
|
|
|
2019-02-14 18:38:04 +08:00
|
|
|
std::string getAllocationInfoString() const override;
|
2024-01-23 19:23:06 +08:00
|
|
|
std::string getPatIndexInfoString() const override;
|
2019-02-14 18:38:04 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
BufferObject *getBO() const {
|
|
|
|
if (fragmentsStorage.fragmentCount) {
|
2021-04-03 01:01:51 +08:00
|
|
|
return static_cast<OsHandleLinux *>(fragmentsStorage.fragmentStorageData[0].osHandleStorage)->bo;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
2019-09-02 03:36:15 +08:00
|
|
|
return this->bufferObjects[0];
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
2019-09-02 03:36:15 +08:00
|
|
|
const BufferObjects &getBOs() const {
|
|
|
|
return this->bufferObjects;
|
|
|
|
}
|
2022-11-10 10:57:51 +08:00
|
|
|
MOCKABLE_VIRTUAL BufferObject *&getBufferObjectToModify(uint32_t handleIndex) {
|
2019-09-02 03:36:15 +08:00
|
|
|
return bufferObjects[handleIndex];
|
|
|
|
}
|
|
|
|
|
2021-10-04 23:23:42 +08:00
|
|
|
void resizeBufferObjects(uint32_t size) {
|
|
|
|
this->bufferObjects.resize(size);
|
|
|
|
}
|
|
|
|
|
2022-02-01 07:29:01 +08:00
|
|
|
uint32_t getNumHandles() override {
|
|
|
|
return this->numHandles;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setNumHandles(uint32_t numHandles) override {
|
|
|
|
this->numHandles = numHandles;
|
|
|
|
}
|
|
|
|
|
2023-04-11 11:24:47 +08:00
|
|
|
uint64_t getHandleAddressBase(uint32_t handleIndex) override;
|
2023-04-07 06:35:11 +08:00
|
|
|
|
2023-04-11 11:24:47 +08:00
|
|
|
size_t getHandleSize(uint32_t handleIndex) override;
|
2023-04-07 10:57:37 +08:00
|
|
|
int createInternalHandle(MemoryManager *memoryManager, uint32_t handleId, uint64_t &handle) override;
|
|
|
|
|
|
|
|
void clearInternalHandle(uint32_t handleId) override;
|
2023-04-07 06:35:11 +08:00
|
|
|
|
2022-11-10 10:57:51 +08:00
|
|
|
int peekInternalHandle(MemoryManager *memoryManager, uint64_t &handle) override;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2022-11-10 10:57:51 +08:00
|
|
|
int peekInternalHandle(MemoryManager *memoryManager, uint32_t handleId, uint64_t &handle) override;
|
2022-02-01 07:29:01 +08:00
|
|
|
|
2021-02-09 08:31:32 +08:00
|
|
|
bool setCacheRegion(Drm *drm, CacheRegion regionIndex);
|
2023-10-12 22:06:59 +08:00
|
|
|
bool setCacheAdvice(Drm *drm, size_t regionSize, CacheRegion regionIndex, bool isSystemMemoryPool);
|
2021-10-07 07:22:22 +08:00
|
|
|
void setCachePolicy(CachePolicy memType);
|
2021-01-30 06:23:06 +08:00
|
|
|
|
2023-04-21 08:36:45 +08:00
|
|
|
bool setPreferredLocation(Drm *drm, PreferredLocation memoryLocation);
|
|
|
|
|
2021-10-11 17:27:26 +08:00
|
|
|
bool setMemAdvise(Drm *drm, MemAdviseFlags flags);
|
2023-09-21 06:34:19 +08:00
|
|
|
bool setAtomicAccess(Drm *drm, size_t size, AtomicAccessMode mode);
|
2022-11-30 08:48:56 +08:00
|
|
|
bool setMemPrefetch(Drm *drm, SubDeviceIdsVec &subDeviceIds);
|
2021-10-11 17:27:26 +08:00
|
|
|
|
2024-01-16 22:15:07 +08:00
|
|
|
void *getMmapPtr() {
|
|
|
|
if (this->importedMmapPtr)
|
|
|
|
return this->importedMmapPtr;
|
|
|
|
else
|
|
|
|
return this->mmapPtr;
|
|
|
|
}
|
2020-10-05 15:57:50 +08:00
|
|
|
void setMmapPtr(void *ptr) { this->mmapPtr = ptr; }
|
2024-01-16 22:15:07 +08:00
|
|
|
void setImportedMmapPtr(void *ptr) { this->importedMmapPtr = ptr; }
|
2020-10-12 21:11:40 +08:00
|
|
|
size_t getMmapSize() { return this->mmapSize; }
|
|
|
|
void setMmapSize(size_t size) { this->mmapSize = size; }
|
2020-10-05 15:57:50 +08:00
|
|
|
|
2023-12-07 03:30:05 +08:00
|
|
|
void setUsmHostAllocation(bool flag) { usmHostAllocation = flag; }
|
|
|
|
bool isUsmHostAllocation() { return usmHostAllocation; }
|
|
|
|
|
2023-04-06 20:09:57 +08:00
|
|
|
OsContextLinux *getOsContext() const {
|
|
|
|
return this->osContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setOsContext(OsContextLinux *context) {
|
|
|
|
this->osContext = context;
|
|
|
|
}
|
|
|
|
|
2023-08-15 00:31:23 +08:00
|
|
|
bool prefetchBOWithChunking(Drm *drm);
|
2022-01-07 22:53:31 +08:00
|
|
|
MOCKABLE_VIRTUAL int makeBOsResident(OsContext *osContext, uint32_t vmHandleId, std::vector<BufferObject *> *bufferObjects, bool bind);
|
|
|
|
MOCKABLE_VIRTUAL int bindBO(BufferObject *bo, OsContext *osContext, uint32_t vmHandleId, std::vector<BufferObject *> *bufferObjects, bool bind);
|
|
|
|
MOCKABLE_VIRTUAL int bindBOs(OsContext *osContext, uint32_t vmHandleId, std::vector<BufferObject *> *bufferObjects, bool bind);
|
2022-11-30 08:48:56 +08:00
|
|
|
MOCKABLE_VIRTUAL bool prefetchBO(BufferObject *bo, uint32_t vmHandleId, uint32_t subDeviceId);
|
2020-11-19 22:11:37 +08:00
|
|
|
MOCKABLE_VIRTUAL void registerBOBindExtHandle(Drm *drm);
|
2024-03-19 07:41:10 +08:00
|
|
|
void addRegisteredBoBindHandle(uint32_t handle) { registeredBoBindHandles.push_back(handle); }
|
2020-09-17 19:27:32 +08:00
|
|
|
void freeRegisteredBOBindExtHandles(Drm *drm);
|
2020-10-17 06:52:18 +08:00
|
|
|
void linkWithRegisteredHandle(uint32_t handle);
|
2021-03-10 07:02:59 +08:00
|
|
|
MOCKABLE_VIRTUAL void markForCapture();
|
2021-11-09 05:42:07 +08:00
|
|
|
MOCKABLE_VIRTUAL bool shouldAllocationPageFault(const Drm *drm);
|
2022-01-11 22:13:30 +08:00
|
|
|
void registerMemoryToUnmap(void *pointer, size_t size, MemoryUnmapFunction unmapFunction);
|
2024-03-27 20:52:30 +08:00
|
|
|
void setAsReadOnly() override;
|
2020-06-26 15:14:36 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
protected:
|
2023-04-06 20:09:57 +08:00
|
|
|
OsContextLinux *osContext = nullptr;
|
2019-09-02 03:36:15 +08:00
|
|
|
BufferObjects bufferObjects{};
|
2020-09-17 19:27:32 +08:00
|
|
|
StackVec<uint32_t, 1> registeredBoBindHandles;
|
2022-01-20 02:51:35 +08:00
|
|
|
StackVec<MemoryToUnmap, 1> memoryToUnmap;
|
2022-10-12 09:33:43 +08:00
|
|
|
std::vector<uint64_t> handles;
|
2020-10-05 15:57:50 +08:00
|
|
|
|
|
|
|
void *mmapPtr = nullptr;
|
2024-01-16 22:15:07 +08:00
|
|
|
void *importedMmapPtr = nullptr;
|
2020-10-12 21:11:40 +08:00
|
|
|
size_t mmapSize = 0u;
|
2024-03-25 22:44:36 +08:00
|
|
|
uint32_t numHandles = 0u;
|
|
|
|
MemAdviseFlags enabledMemAdviseFlags{};
|
2023-12-07 03:30:05 +08:00
|
|
|
|
|
|
|
bool usmHostAllocation = false;
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|