2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2019-01-24 18:51:33 +08:00
|
|
|
* Copyright (C) 2017-2019 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
|
|
|
|
#include "drm_gem_close_worker.h"
|
|
|
|
#include "runtime/memory_manager/memory_manager.h"
|
|
|
|
#include "runtime/os_interface/linux/drm_allocation.h"
|
2018-11-16 02:43:12 +08:00
|
|
|
#include "runtime/os_interface/linux/drm_buffer_object.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "runtime/os_interface/linux/drm_neo.h"
|
2018-11-16 02:43:12 +08:00
|
|
|
#include "runtime/os_interface/linux/drm_limited_range.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#include <map>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
|
|
|
|
namespace OCLRT {
|
|
|
|
class BufferObject;
|
|
|
|
class Drm;
|
|
|
|
|
|
|
|
class DrmMemoryManager : public MemoryManager {
|
|
|
|
public:
|
2018-10-01 22:10:54 +08:00
|
|
|
DrmMemoryManager(Drm *drm, gemCloseWorkerMode mode, bool forcePinAllowed, bool validateHostPtrMemory, ExecutionEnvironment &executionEnvironment);
|
2017-12-21 07:45:38 +08:00
|
|
|
~DrmMemoryManager() override;
|
|
|
|
|
|
|
|
BufferObject *getPinBB() const;
|
2018-05-08 16:00:23 +08:00
|
|
|
void addAllocationToHostPtrManager(GraphicsAllocation *gfxAllocation) override;
|
|
|
|
void removeAllocationFromHostPtrManager(GraphicsAllocation *gfxAllocation) override;
|
2017-12-21 07:45:38 +08:00
|
|
|
void freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation) override;
|
2018-11-16 02:43:12 +08:00
|
|
|
DrmAllocation *allocateGraphicsMemoryForNonSvmHostPtr(size_t size, void *cpuPtr) override;
|
2018-08-29 20:50:36 +08:00
|
|
|
GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, bool requireSpecificBitness) override;
|
2017-12-21 07:45:38 +08:00
|
|
|
GraphicsAllocation *createPaddedAllocation(GraphicsAllocation *inputGraphicsAllocation, size_t sizeWithPadding) override;
|
|
|
|
GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle) override { return nullptr; }
|
|
|
|
|
|
|
|
uint64_t getSystemSharedMemory() override;
|
|
|
|
uint64_t getMaxApplicationAddress() override;
|
2018-03-12 22:24:46 +08:00
|
|
|
uint64_t getInternalHeapBaseAddress() override;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2018-02-28 19:09:48 +08:00
|
|
|
AllocationStatus populateOsHandles(OsHandleStorage &handleStorage) override;
|
2017-12-21 07:45:38 +08:00
|
|
|
void cleanOsHandles(OsHandleStorage &handleStorage) override;
|
|
|
|
|
|
|
|
// drm/i915 ioctl wrappers
|
|
|
|
uint32_t unreference(BufferObject *bo, bool synchronousDestroy = false);
|
|
|
|
|
|
|
|
DrmAllocation *createGraphicsAllocation(OsHandleStorage &handleStorage, size_t hostPtrSize, const void *hostPtr) override;
|
2018-02-28 19:09:48 +08:00
|
|
|
bool isValidateHostMemoryEnabled() const {
|
|
|
|
return validateHostPtrMemory;
|
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2018-05-11 15:57:59 +08:00
|
|
|
DrmGemCloseWorker *peekGemCloseWorker() { return this->gemCloseWorker.get(); }
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
protected:
|
|
|
|
BufferObject *findAndReferenceSharedBufferObject(int boHandle);
|
|
|
|
BufferObject *createSharedBufferObject(int boHandle, size_t size, bool requireSpecificBitness);
|
|
|
|
void eraseSharedBufferObject(BufferObject *bo);
|
|
|
|
void pushSharedBufferObject(BufferObject *bo);
|
|
|
|
BufferObject *allocUserptr(uintptr_t address, size_t size, uint64_t flags, bool softpin);
|
2018-02-27 06:23:43 +08:00
|
|
|
bool setDomainCpu(GraphicsAllocation &graphicsAllocation, bool writeEnable);
|
2018-11-16 02:43:12 +08:00
|
|
|
uint64_t acquireGpuRange(size_t &size, StorageAllocatorType &allocType, bool requireSpecificBitness);
|
|
|
|
void releaseGpuRange(void *address, size_t unmapSize, StorageAllocatorType allocatorType);
|
|
|
|
void initInternalRangeAllocator(size_t range);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2018-11-30 18:01:33 +08:00
|
|
|
DrmAllocation *allocateGraphicsMemoryWithAlignment(const AllocationData &allocationData) override;
|
|
|
|
DrmAllocation *allocateGraphicsMemoryWithHostPtr(const AllocationData &allocationData) override;
|
2018-12-06 22:03:06 +08:00
|
|
|
DrmAllocation *allocateGraphicsMemory64kb(AllocationData allocationData) override;
|
2019-01-22 19:40:17 +08:00
|
|
|
GraphicsAllocation *allocateGraphicsMemoryForImageImpl(const AllocationData &allocationData, std::unique_ptr<Gmm> gmm) override;
|
2018-11-30 18:01:33 +08:00
|
|
|
|
2019-01-24 18:51:33 +08:00
|
|
|
void *lockResourceImpl(GraphicsAllocation &graphicsAllocation) override;
|
|
|
|
void unlockResourceImpl(GraphicsAllocation &graphicsAllocation) override;
|
2018-12-21 17:16:27 +08:00
|
|
|
DrmAllocation *allocate32BitGraphicsMemoryImpl(const AllocationData &allocationData) override;
|
2019-01-24 18:51:33 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
Drm *drm;
|
|
|
|
BufferObject *pinBB;
|
|
|
|
size_t pinThreshold = 8 * 1024 * 1024;
|
2018-02-28 19:09:48 +08:00
|
|
|
bool forcePinEnabled = false;
|
|
|
|
const bool validateHostPtrMemory;
|
2017-12-21 07:45:38 +08:00
|
|
|
std::unique_ptr<DrmGemCloseWorker> gemCloseWorker;
|
|
|
|
decltype(&lseek) lseekFunction = lseek;
|
|
|
|
decltype(&mmap) mmapFunction = mmap;
|
|
|
|
decltype(&munmap) munmapFunction = munmap;
|
|
|
|
decltype(&close) closeFunction = close;
|
|
|
|
std::vector<BufferObject *> sharingBufferObjects;
|
2018-08-01 20:47:14 +08:00
|
|
|
std::mutex mtx;
|
2018-02-28 16:56:54 +08:00
|
|
|
std::unique_ptr<Allocator32bit> internal32bitAllocator;
|
2018-11-16 02:43:12 +08:00
|
|
|
std::unique_ptr<AllocatorLimitedRange> limitedGpuAddressRangeAllocator;
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
|
|
|
} // namespace OCLRT
|