2018-01-13 22:22:39 +01:00
|
|
|
// Copyright 2018 yuzu emulator team
|
2018-01-09 16:41:13 +01:00
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2018-02-08 03:31:06 +01:00
|
|
|
#include <memory>
|
|
|
|
#include <utility>
|
2018-01-09 16:41:13 +01:00
|
|
|
#include <vector>
|
|
|
|
#include "common/common_types.h"
|
Extra nvdrv support (#162)
* FinishInitalize needed for 3.0.1+ games
* nvdrv:s and nvdrv:t both use NVDRV
* Most settings return 0 on hardware, disabled NV_MEMORY_PROFILER for now.
NVN_THROUGH_OPENGL & NVRM_GPU_PREVENT_USE are a few interesting settings to look at. Carefully choosing settings can help with drawing graphics later on
* Initial /dev/nvhost-gpu support
* ZCullBind
* Stubbed SetErrorNotifier
* Fixed SetErrorNotifier log, Added SetChannelPriority
* Allocate GPFIFO Ex2, Allocate Obj Ctx, Submit GPFIFO
* oops
* Fixed up naming/structs/enums. Used vector instead of array for "gpfifo_entry"
* Added missing fixes
* /dev/nvhost-ctrl-gpu
* unneeded struct
* Forgot u32 in enum class
* Automatic descriptor swapping for ioctls, fixed nvgpu_gpu_get_tpc_masks_args being incorrect size
* nvdrv#QueryEvent
* Renamed logs for nvdrv
* Refactor ioctl so nv_result isn't needed
* /dev/nvhost-as-gpu
* Fixed Log service naming, CtxObjects now u32, renamed all structs, added static_asserts to structs, used INSERT_PADDING_WORDS instead of u32s
* nvdevices now uses "Ioctl" union,
* IoctlGpfifoEntry now uses bit field
* final changes
2018-02-06 03:19:31 +01:00
|
|
|
#include "common/swap.h"
|
2018-01-09 16:41:13 +01:00
|
|
|
#include "core/hle/service/nvdrv/devices/nvdevice.h"
|
2018-02-08 04:03:04 +01:00
|
|
|
#include "core/hle/service/nvdrv/memory_manager.h"
|
2018-01-09 16:41:13 +01:00
|
|
|
|
|
|
|
namespace Service {
|
2018-01-15 23:39:00 +01:00
|
|
|
namespace Nvidia {
|
2018-01-09 16:41:13 +01:00
|
|
|
namespace Devices {
|
|
|
|
|
2018-02-08 03:31:06 +01:00
|
|
|
class nvmap;
|
|
|
|
|
2018-01-09 16:41:13 +01:00
|
|
|
class nvhost_as_gpu final : public nvdevice {
|
|
|
|
public:
|
2018-02-12 03:30:23 +01:00
|
|
|
nvhost_as_gpu(std::shared_ptr<nvmap> nvmap_dev, std::shared_ptr<MemoryManager> memory_manager)
|
|
|
|
: nvdevice(), nvmap_dev(std::move(nvmap_dev)), memory_manager(std::move(memory_manager)) {}
|
2018-01-09 16:41:13 +01:00
|
|
|
~nvhost_as_gpu() override = default;
|
|
|
|
|
Extra nvdrv support (#162)
* FinishInitalize needed for 3.0.1+ games
* nvdrv:s and nvdrv:t both use NVDRV
* Most settings return 0 on hardware, disabled NV_MEMORY_PROFILER for now.
NVN_THROUGH_OPENGL & NVRM_GPU_PREVENT_USE are a few interesting settings to look at. Carefully choosing settings can help with drawing graphics later on
* Initial /dev/nvhost-gpu support
* ZCullBind
* Stubbed SetErrorNotifier
* Fixed SetErrorNotifier log, Added SetChannelPriority
* Allocate GPFIFO Ex2, Allocate Obj Ctx, Submit GPFIFO
* oops
* Fixed up naming/structs/enums. Used vector instead of array for "gpfifo_entry"
* Added missing fixes
* /dev/nvhost-ctrl-gpu
* unneeded struct
* Forgot u32 in enum class
* Automatic descriptor swapping for ioctls, fixed nvgpu_gpu_get_tpc_masks_args being incorrect size
* nvdrv#QueryEvent
* Renamed logs for nvdrv
* Refactor ioctl so nv_result isn't needed
* /dev/nvhost-as-gpu
* Fixed Log service naming, CtxObjects now u32, renamed all structs, added static_asserts to structs, used INSERT_PADDING_WORDS instead of u32s
* nvdevices now uses "Ioctl" union,
* IoctlGpfifoEntry now uses bit field
* final changes
2018-02-06 03:19:31 +01:00
|
|
|
u32 ioctl(Ioctl command, const std::vector<u8>& input, std::vector<u8>& output) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
enum class IoctlCommand : u32_le {
|
|
|
|
IocInitalizeExCommand = 0x40284109,
|
|
|
|
IocAllocateSpaceCommand = 0xC0184102,
|
|
|
|
IocMapBufferExCommand = 0xC0284106,
|
|
|
|
IocBindChannelCommand = 0x40044101,
|
|
|
|
IocGetVaRegionsCommand = 0xC0404108,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct IoctlInitalizeEx {
|
|
|
|
u32_le big_page_size; // depends on GPU's available_big_page_sizes; 0=default
|
|
|
|
s32_le as_fd; // ignored; passes 0
|
|
|
|
u32_le flags; // passes 0
|
|
|
|
u32_le reserved; // ignored; passes 0
|
|
|
|
u64_le unk0;
|
|
|
|
u64_le unk1;
|
|
|
|
u64_le unk2;
|
|
|
|
};
|
|
|
|
static_assert(sizeof(IoctlInitalizeEx) == 40, "IoctlInitalizeEx is incorrect size");
|
|
|
|
|
|
|
|
struct IoctlAllocSpace {
|
|
|
|
u32_le pages;
|
|
|
|
u32_le page_size;
|
|
|
|
u32_le flags;
|
|
|
|
INSERT_PADDING_WORDS(1);
|
|
|
|
union {
|
|
|
|
u64_le offset;
|
|
|
|
u64_le align;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
static_assert(sizeof(IoctlAllocSpace) == 24, "IoctlInitalizeEx is incorrect size");
|
|
|
|
|
|
|
|
struct IoctlMapBufferEx {
|
|
|
|
u32_le flags; // bit0: fixed_offset, bit2: cacheable
|
|
|
|
u32_le kind; // -1 is default
|
|
|
|
u32_le nvmap_handle;
|
|
|
|
u32_le page_size; // 0 means don't care
|
|
|
|
u64_le buffer_offset;
|
|
|
|
u64_le mapping_size;
|
|
|
|
u64_le offset;
|
|
|
|
};
|
|
|
|
static_assert(sizeof(IoctlMapBufferEx) == 40, "IoctlMapBufferEx is incorrect size");
|
|
|
|
|
|
|
|
struct IoctlBindChannel {
|
|
|
|
u32_le fd;
|
|
|
|
};
|
|
|
|
static_assert(sizeof(IoctlBindChannel) == 4, "IoctlBindChannel is incorrect size");
|
|
|
|
|
|
|
|
struct IoctlVaRegion {
|
|
|
|
u64_le offset;
|
|
|
|
u32_le page_size;
|
|
|
|
INSERT_PADDING_WORDS(1);
|
|
|
|
u64_le pages;
|
|
|
|
};
|
|
|
|
static_assert(sizeof(IoctlVaRegion) == 24, "IoctlVaRegion is incorrect size");
|
|
|
|
|
|
|
|
struct IoctlGetVaRegions {
|
|
|
|
u64_le buf_addr; // (contained output user ptr on linux, ignored)
|
|
|
|
u32_le buf_size; // forced to 2*sizeof(struct va_region)
|
|
|
|
u32_le reserved;
|
|
|
|
IoctlVaRegion regions[2];
|
|
|
|
};
|
|
|
|
static_assert(sizeof(IoctlGetVaRegions) == 16 + sizeof(IoctlVaRegion) * 2,
|
|
|
|
"IoctlGetVaRegions is incorrect size");
|
|
|
|
|
|
|
|
u32 channel{};
|
|
|
|
|
|
|
|
u32 InitalizeEx(const std::vector<u8>& input, std::vector<u8>& output);
|
|
|
|
u32 AllocateSpace(const std::vector<u8>& input, std::vector<u8>& output);
|
|
|
|
u32 MapBufferEx(const std::vector<u8>& input, std::vector<u8>& output);
|
|
|
|
u32 BindChannel(const std::vector<u8>& input, std::vector<u8>& output);
|
|
|
|
u32 GetVARegions(const std::vector<u8>& input, std::vector<u8>& output);
|
2018-02-08 03:31:06 +01:00
|
|
|
|
|
|
|
std::shared_ptr<nvmap> nvmap_dev;
|
2018-02-08 04:03:04 +01:00
|
|
|
std::shared_ptr<MemoryManager> memory_manager;
|
2018-01-09 16:41:13 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Devices
|
2018-01-15 23:39:00 +01:00
|
|
|
} // namespace Nvidia
|
2018-01-09 16:41:13 +01:00
|
|
|
} // namespace Service
|