2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2020-01-07 14:42:40 +08:00
|
|
|
* Copyright (C) 2017-2020 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/memory_manager.h"
|
|
|
|
#include "shared/source/os_interface/linux/drm_allocation.h"
|
|
|
|
#include "shared/source/os_interface/linux/drm_buffer_object.h"
|
|
|
|
#include "shared/source/os_interface/linux/drm_neo.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
|
|
|
#include "drm_gem_close_worker.h"
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
#include <map>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2017-12-21 07:45:38 +08:00
|
|
|
class BufferObject;
|
|
|
|
class Drm;
|
|
|
|
|
|
|
|
class DrmMemoryManager : public MemoryManager {
|
|
|
|
public:
|
2019-03-25 20:12:55 +08:00
|
|
|
DrmMemoryManager(gemCloseWorkerMode mode,
|
2019-03-12 06:06:30 +08:00
|
|
|
bool forcePinAllowed,
|
|
|
|
bool validateHostPtrMemory,
|
|
|
|
ExecutionEnvironment &executionEnvironment);
|
2017-12-21 07:45:38 +08:00
|
|
|
~DrmMemoryManager() override;
|
|
|
|
|
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;
|
2019-03-04 21:50:26 +08:00
|
|
|
void handleFenceCompletion(GraphicsAllocation *allocation) override;
|
2019-04-01 20:04:50 +08:00
|
|
|
GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness) override;
|
2017-12-21 07:45:38 +08:00
|
|
|
GraphicsAllocation *createPaddedAllocation(GraphicsAllocation *inputGraphicsAllocation, size_t sizeWithPadding) override;
|
2019-10-22 16:26:23 +08:00
|
|
|
GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex) override { return nullptr; }
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2020-01-07 14:42:40 +08:00
|
|
|
uint64_t getSystemSharedMemory(uint32_t rootDeviceIndex) override;
|
|
|
|
uint64_t getLocalMemorySize(uint32_t rootDeviceIndex) override;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2020-01-07 14:42:40 +08:00
|
|
|
AllocationStatus populateOsHandles(OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) override;
|
2019-11-15 16:59:48 +08:00
|
|
|
void cleanOsHandles(OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) override;
|
2020-02-12 00:48:40 +08:00
|
|
|
void commonCleanup() override;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
// drm/i915 ioctl wrappers
|
2019-08-27 21:33:58 +08:00
|
|
|
MOCKABLE_VIRTUAL uint32_t unreference(BufferObject *bo, bool synchronousDestroy);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2018-02-28 19:09:48 +08:00
|
|
|
bool isValidateHostMemoryEnabled() const {
|
|
|
|
return validateHostPtrMemory;
|
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-02-25 21:11:34 +08:00
|
|
|
DrmGemCloseWorker *peekGemCloseWorker() const { return this->gemCloseWorker.get(); }
|
2019-07-08 02:33:17 +08:00
|
|
|
bool copyMemoryToAllocation(GraphicsAllocation *graphicsAllocation, const void *memoryToCopy, size_t sizeToCopy) override;
|
2018-05-11 15:57:59 +08:00
|
|
|
|
2020-01-07 14:42:40 +08:00
|
|
|
int obtainFdFromHandle(int boHandle, uint32_t rootDeviceindex);
|
2019-06-06 22:26:47 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
protected:
|
|
|
|
BufferObject *findAndReferenceSharedBufferObject(int boHandle);
|
2019-10-22 16:26:23 +08:00
|
|
|
BufferObject *createSharedBufferObject(int boHandle, size_t size, bool requireSpecificBitness, uint32_t rootDeviceIndex);
|
2017-12-21 07:45:38 +08:00
|
|
|
void eraseSharedBufferObject(BufferObject *bo);
|
|
|
|
void pushSharedBufferObject(BufferObject *bo);
|
2019-10-22 16:26:23 +08:00
|
|
|
BufferObject *allocUserptr(uintptr_t address, size_t size, uint64_t flags, uint32_t rootDeviceIndex);
|
2018-02-27 06:23:43 +08:00
|
|
|
bool setDomainCpu(GraphicsAllocation &graphicsAllocation, bool writeEnable);
|
2020-03-12 16:25:09 +08:00
|
|
|
uint64_t acquireGpuRange(size_t &size, bool requireSpecificBitness, uint32_t rootDeviceIndex, bool requiresStandard64KBHeap);
|
2019-10-22 16:26:23 +08:00
|
|
|
MOCKABLE_VIRTUAL void releaseGpuRange(void *address, size_t size, uint32_t rootDeviceIndex);
|
2019-02-25 21:11:34 +08:00
|
|
|
void emitPinningRequest(BufferObject *bo, const AllocationData &allocationData) const;
|
2019-07-17 21:38:14 +08:00
|
|
|
uint32_t getDefaultDrmContextId() const;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-02-25 21:11:34 +08:00
|
|
|
DrmAllocation *createGraphicsAllocation(OsHandleStorage &handleStorage, const AllocationData &allocationData) override;
|
2019-03-12 19:00:41 +08:00
|
|
|
DrmAllocation *allocateGraphicsMemoryForNonSvmHostPtr(const AllocationData &allocationData) override;
|
2018-11-30 18:01:33 +08:00
|
|
|
DrmAllocation *allocateGraphicsMemoryWithAlignment(const AllocationData &allocationData) override;
|
|
|
|
DrmAllocation *allocateGraphicsMemoryWithHostPtr(const AllocationData &allocationData) override;
|
2019-02-28 21:12:13 +08:00
|
|
|
DrmAllocation *allocateGraphicsMemory64kb(const AllocationData &allocationData) override;
|
2019-11-14 17:08:59 +08:00
|
|
|
GraphicsAllocation *allocateShareableMemory(const 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;
|
2019-07-08 02:33:17 +08:00
|
|
|
void *lockResourceInLocalMemoryImpl(GraphicsAllocation &graphicsAllocation);
|
2019-09-02 03:36:15 +08:00
|
|
|
MOCKABLE_VIRTUAL void *lockResourceInLocalMemoryImpl(BufferObject *bo);
|
|
|
|
MOCKABLE_VIRTUAL void unlockResourceInLocalMemoryImpl(BufferObject *bo);
|
2019-01-24 18:51:33 +08:00
|
|
|
void unlockResourceImpl(GraphicsAllocation &graphicsAllocation) override;
|
2018-12-21 17:16:27 +08:00
|
|
|
DrmAllocation *allocate32BitGraphicsMemoryImpl(const AllocationData &allocationData) override;
|
2019-02-27 04:12:26 +08:00
|
|
|
GraphicsAllocation *allocateGraphicsMemoryInDevicePool(const AllocationData &allocationData, AllocationStatus &status) override;
|
2019-01-24 18:51:33 +08:00
|
|
|
|
2020-01-07 14:42:40 +08:00
|
|
|
Drm &getDrm(uint32_t rootDeviceIndex) const;
|
|
|
|
|
2020-02-21 20:41:02 +08:00
|
|
|
std::vector<BufferObject *> pinBBs;
|
|
|
|
std::vector<void *> memoryForPinBBs;
|
2017-12-21 07:45:38 +08:00
|
|
|
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(&close) closeFunction = close;
|
|
|
|
std::vector<BufferObject *> sharingBufferObjects;
|
2018-08-01 20:47:14 +08:00
|
|
|
std::mutex mtx;
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|