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.
|
|
|
|
|
2018-08-07 14:42:18 +02:00
|
|
|
#include <cstring>
|
hle/service: Default constructors and destructors in the cpp file where applicable
When a destructor isn't defaulted into a cpp file, it can cause the use
of forward declarations to seemingly fail to compile for non-obvious
reasons. It also allows inlining of the construction/destruction logic
all over the place where a constructor or destructor is invoked, which
can lead to code bloat. This isn't so much a worry here, given the
services won't be created and destroyed frequently.
The cause of the above mentioned non-obvious errors can be demonstrated
as follows:
------- Demonstrative example, if you know how the described error happens, skip forwards -------
Assume we have the following in the header, which we'll call "thing.h":
\#include <memory>
// Forward declaration. For example purposes, assume the definition
// of Object is in some header named "object.h"
class Object;
class Thing {
public:
// assume no constructors or destructors are specified here,
// or the constructors/destructors are defined as:
//
// Thing() = default;
// ~Thing() = default;
//
// ... Some interface member functions would be defined here
private:
std::shared_ptr<Object> obj;
};
If this header is included in a cpp file, (which we'll call "main.cpp"),
this will result in a compilation error, because even though no
destructor is specified, the destructor will still need to be generated by
the compiler because std::shared_ptr's destructor is *not* trivial (in
other words, it does something other than nothing), as std::shared_ptr's
destructor needs to do two things:
1. Decrement the shared reference count of the object being pointed to,
and if the reference count decrements to zero,
2. Free the Object instance's memory (aka deallocate the memory it's
pointing to).
And so the compiler generates the code for the destructor doing this inside main.cpp.
Now, keep in mind, the Object forward declaration is not a complete type. All it
does is tell the compiler "a type named Object exists" and allows us to
use the name in certain situations to avoid a header dependency. So the
compiler needs to generate destruction code for Object, but the compiler
doesn't know *how* to destruct it. A forward declaration doesn't tell
the compiler anything about Object's constructor or destructor. So, the
compiler will issue an error in this case because it's undefined
behavior to try and deallocate (or construct) an incomplete type and
std::shared_ptr and std::unique_ptr make sure this isn't the case
internally.
Now, if we had defaulted the destructor in "thing.cpp", where we also
include "object.h", this would never be an issue, as the destructor
would only have its code generated in one place, and it would be in a
place where the full class definition of Object would be visible to the
compiler.
---------------------- End example ----------------------------
Given these service classes are more than certainly going to change in
the future, this defaults the constructors and destructors into the
relevant cpp files to make the construction and destruction of all of
the services consistent and unlikely to run into cases where forward
declarations are indirectly causing compilation errors. It also has the
plus of avoiding the need to rebuild several services if destruction
logic changes, since it would only be necessary to recompile the single
cpp file.
2018-09-11 03:20:52 +02:00
|
|
|
#include <utility>
|
|
|
|
|
2018-01-09 16:41:13 +01:00
|
|
|
#include "common/assert.h"
|
|
|
|
#include "common/logging/log.h"
|
2018-02-12 05:44:12 +01:00
|
|
|
#include "core/core.h"
|
2018-01-09 16:41:13 +01:00
|
|
|
#include "core/hle/service/nvdrv/devices/nvhost_as_gpu.h"
|
2018-02-08 03:31:06 +01:00
|
|
|
#include "core/hle/service/nvdrv/devices/nvmap.h"
|
2018-08-07 14:42:18 +02:00
|
|
|
#include "video_core/memory_manager.h"
|
|
|
|
#include "video_core/rasterizer_interface.h"
|
2018-07-01 17:50:06 +02:00
|
|
|
#include "video_core/renderer_base.h"
|
2018-01-09 16:41:13 +01:00
|
|
|
|
2018-04-20 03:41:44 +02:00
|
|
|
namespace Service::Nvidia::Devices {
|
2018-01-09 16:41:13 +01:00
|
|
|
|
hle/service: Default constructors and destructors in the cpp file where applicable
When a destructor isn't defaulted into a cpp file, it can cause the use
of forward declarations to seemingly fail to compile for non-obvious
reasons. It also allows inlining of the construction/destruction logic
all over the place where a constructor or destructor is invoked, which
can lead to code bloat. This isn't so much a worry here, given the
services won't be created and destroyed frequently.
The cause of the above mentioned non-obvious errors can be demonstrated
as follows:
------- Demonstrative example, if you know how the described error happens, skip forwards -------
Assume we have the following in the header, which we'll call "thing.h":
\#include <memory>
// Forward declaration. For example purposes, assume the definition
// of Object is in some header named "object.h"
class Object;
class Thing {
public:
// assume no constructors or destructors are specified here,
// or the constructors/destructors are defined as:
//
// Thing() = default;
// ~Thing() = default;
//
// ... Some interface member functions would be defined here
private:
std::shared_ptr<Object> obj;
};
If this header is included in a cpp file, (which we'll call "main.cpp"),
this will result in a compilation error, because even though no
destructor is specified, the destructor will still need to be generated by
the compiler because std::shared_ptr's destructor is *not* trivial (in
other words, it does something other than nothing), as std::shared_ptr's
destructor needs to do two things:
1. Decrement the shared reference count of the object being pointed to,
and if the reference count decrements to zero,
2. Free the Object instance's memory (aka deallocate the memory it's
pointing to).
And so the compiler generates the code for the destructor doing this inside main.cpp.
Now, keep in mind, the Object forward declaration is not a complete type. All it
does is tell the compiler "a type named Object exists" and allows us to
use the name in certain situations to avoid a header dependency. So the
compiler needs to generate destruction code for Object, but the compiler
doesn't know *how* to destruct it. A forward declaration doesn't tell
the compiler anything about Object's constructor or destructor. So, the
compiler will issue an error in this case because it's undefined
behavior to try and deallocate (or construct) an incomplete type and
std::shared_ptr and std::unique_ptr make sure this isn't the case
internally.
Now, if we had defaulted the destructor in "thing.cpp", where we also
include "object.h", this would never be an issue, as the destructor
would only have its code generated in one place, and it would be in a
place where the full class definition of Object would be visible to the
compiler.
---------------------- End example ----------------------------
Given these service classes are more than certainly going to change in
the future, this defaults the constructors and destructors into the
relevant cpp files to make the construction and destruction of all of
the services consistent and unlikely to run into cases where forward
declarations are indirectly causing compilation errors. It also has the
plus of avoiding the need to rebuild several services if destruction
logic changes, since it would only be necessary to recompile the single
cpp file.
2018-09-11 03:20:52 +02:00
|
|
|
nvhost_as_gpu::nvhost_as_gpu(std::shared_ptr<nvmap> nvmap_dev) : nvmap_dev(std::move(nvmap_dev)) {}
|
|
|
|
nvhost_as_gpu::~nvhost_as_gpu() = 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 nvhost_as_gpu::ioctl(Ioctl command, const std::vector<u8>& input, std::vector<u8>& output) {
|
2018-07-02 18:13:26 +02:00
|
|
|
LOG_DEBUG(Service_NVDRV, "called, command=0x{:08X}, input_size=0x{:X}, output_size=0x{:X}",
|
2018-07-02 18:20:50 +02:00
|
|
|
command.raw, input.size(), output.size());
|
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
|
|
|
|
|
|
|
switch (static_cast<IoctlCommand>(command.raw)) {
|
|
|
|
case IoctlCommand::IocInitalizeExCommand:
|
|
|
|
return InitalizeEx(input, output);
|
|
|
|
case IoctlCommand::IocAllocateSpaceCommand:
|
|
|
|
return AllocateSpace(input, output);
|
|
|
|
case IoctlCommand::IocMapBufferExCommand:
|
|
|
|
return MapBufferEx(input, output);
|
|
|
|
case IoctlCommand::IocBindChannelCommand:
|
|
|
|
return BindChannel(input, output);
|
|
|
|
case IoctlCommand::IocGetVaRegionsCommand:
|
|
|
|
return GetVARegions(input, output);
|
2018-05-20 21:21:06 +02:00
|
|
|
case IoctlCommand::IocUnmapBufferCommand:
|
|
|
|
return UnmapBuffer(input, output);
|
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
|
|
|
}
|
2018-04-23 18:06:07 +02:00
|
|
|
|
|
|
|
if (static_cast<IoctlCommand>(command.cmd.Value()) == IoctlCommand::IocRemapCommand)
|
|
|
|
return Remap(input, output);
|
|
|
|
|
|
|
|
UNIMPLEMENTED_MSG("Unimplemented ioctl command");
|
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
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 nvhost_as_gpu::InitalizeEx(const std::vector<u8>& input, std::vector<u8>& output) {
|
|
|
|
IoctlInitalizeEx params{};
|
|
|
|
std::memcpy(¶ms, input.data(), input.size());
|
2018-07-02 18:13:26 +02:00
|
|
|
LOG_WARNING(Service_NVDRV, "(STUBBED) called, big_page_size=0x{:X}", params.big_page_size);
|
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
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 nvhost_as_gpu::AllocateSpace(const std::vector<u8>& input, std::vector<u8>& output) {
|
|
|
|
IoctlAllocSpace params{};
|
|
|
|
std::memcpy(¶ms, input.data(), input.size());
|
2018-07-02 18:13:26 +02:00
|
|
|
LOG_DEBUG(Service_NVDRV, "called, pages={:X}, page_size={:X}, flags={:X}", params.pages,
|
2018-07-02 18:20:50 +02:00
|
|
|
params.page_size, params.flags);
|
2018-02-08 04:03:04 +01:00
|
|
|
|
2018-02-12 05:44:12 +01:00
|
|
|
auto& gpu = Core::System::GetInstance().GPU();
|
2018-02-08 04:03:04 +01:00
|
|
|
const u64 size{static_cast<u64>(params.pages) * static_cast<u64>(params.page_size)};
|
|
|
|
if (params.flags & 1) {
|
2018-08-28 16:57:56 +02:00
|
|
|
params.offset = gpu.MemoryManager().AllocateSpace(params.offset, size, 1);
|
2018-02-08 04:03:04 +01:00
|
|
|
} else {
|
2018-08-28 16:57:56 +02:00
|
|
|
params.offset = gpu.MemoryManager().AllocateSpace(size, params.align);
|
2018-02-08 04:03:04 +01:00
|
|
|
}
|
|
|
|
|
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
|
|
|
std::memcpy(output.data(), ¶ms, output.size());
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-04-23 18:06:07 +02:00
|
|
|
u32 nvhost_as_gpu::Remap(const std::vector<u8>& input, std::vector<u8>& output) {
|
|
|
|
size_t num_entries = input.size() / sizeof(IoctlRemapEntry);
|
|
|
|
|
2018-07-02 18:13:26 +02:00
|
|
|
LOG_WARNING(Service_NVDRV, "(STUBBED) called, num_entries=0x{:X}", num_entries);
|
2018-04-23 18:06:07 +02:00
|
|
|
|
|
|
|
std::vector<IoctlRemapEntry> entries(num_entries);
|
|
|
|
std::memcpy(entries.data(), input.data(), input.size());
|
|
|
|
|
|
|
|
auto& gpu = Core::System::GetInstance().GPU();
|
|
|
|
|
|
|
|
for (const auto& entry : entries) {
|
2018-07-02 18:13:26 +02:00
|
|
|
LOG_WARNING(Service_NVDRV, "remap entry, offset=0x{:X} handle=0x{:X} pages=0x{:X}",
|
2018-07-02 18:20:50 +02:00
|
|
|
entry.offset, entry.nvmap_handle, entry.pages);
|
2018-04-23 18:06:07 +02:00
|
|
|
Tegra::GPUVAddr offset = static_cast<Tegra::GPUVAddr>(entry.offset) << 0x10;
|
|
|
|
|
|
|
|
auto object = nvmap_dev->GetObject(entry.nvmap_handle);
|
|
|
|
ASSERT(object);
|
|
|
|
|
|
|
|
ASSERT(object->status == nvmap::Object::Status::Allocated);
|
|
|
|
|
|
|
|
u64 size = static_cast<u64>(entry.pages) << 0x10;
|
|
|
|
ASSERT(size <= object->size);
|
|
|
|
|
2018-08-28 16:57:56 +02:00
|
|
|
Tegra::GPUVAddr returned = gpu.MemoryManager().MapBufferEx(object->addr, offset, size);
|
2018-04-23 18:06:07 +02:00
|
|
|
ASSERT(returned == offset);
|
|
|
|
}
|
|
|
|
std::memcpy(output.data(), entries.data(), output.size());
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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 nvhost_as_gpu::MapBufferEx(const std::vector<u8>& input, std::vector<u8>& output) {
|
|
|
|
IoctlMapBufferEx params{};
|
|
|
|
std::memcpy(¶ms, input.data(), input.size());
|
|
|
|
|
2018-07-02 18:13:26 +02:00
|
|
|
LOG_DEBUG(Service_NVDRV,
|
2018-07-02 18:20:50 +02:00
|
|
|
"called, flags={:X}, nvmap_handle={:X}, buffer_offset={}, mapping_size={}"
|
|
|
|
", offset={}",
|
|
|
|
params.flags, params.nvmap_handle, params.buffer_offset, params.mapping_size,
|
|
|
|
params.offset);
|
2018-02-08 04:03:04 +01:00
|
|
|
|
|
|
|
if (!params.nvmap_handle) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto object = nvmap_dev->GetObject(params.nvmap_handle);
|
|
|
|
ASSERT(object);
|
|
|
|
|
2018-04-23 18:10:00 +02:00
|
|
|
// We can only map objects that have already been assigned a CPU address.
|
|
|
|
ASSERT(object->status == nvmap::Object::Status::Allocated);
|
|
|
|
|
|
|
|
ASSERT(params.buffer_offset == 0);
|
|
|
|
|
|
|
|
// The real nvservices doesn't make a distinction between handles and ids, and
|
|
|
|
// object can only have one handle and it will be the same as its id. Assert that this is the
|
|
|
|
// case to prevent unexpected behavior.
|
|
|
|
ASSERT(object->id == params.nvmap_handle);
|
|
|
|
|
2018-02-12 05:44:12 +01:00
|
|
|
auto& gpu = Core::System::GetInstance().GPU();
|
|
|
|
|
2018-02-08 04:03:04 +01:00
|
|
|
if (params.flags & 1) {
|
2018-08-28 16:57:56 +02:00
|
|
|
params.offset = gpu.MemoryManager().MapBufferEx(object->addr, params.offset, object->size);
|
2018-02-08 04:03:04 +01:00
|
|
|
} else {
|
2018-08-28 16:57:56 +02:00
|
|
|
params.offset = gpu.MemoryManager().MapBufferEx(object->addr, object->size);
|
2018-02-08 04:03:04 +01:00
|
|
|
}
|
|
|
|
|
2018-05-20 21:21:06 +02:00
|
|
|
// Create a new mapping entry for this operation.
|
|
|
|
ASSERT_MSG(buffer_mappings.find(params.offset) == buffer_mappings.end(),
|
|
|
|
"Offset is already mapped");
|
|
|
|
|
|
|
|
BufferMapping mapping{};
|
|
|
|
mapping.nvmap_handle = params.nvmap_handle;
|
|
|
|
mapping.offset = params.offset;
|
|
|
|
mapping.size = object->size;
|
|
|
|
|
|
|
|
buffer_mappings[params.offset] = mapping;
|
|
|
|
|
|
|
|
std::memcpy(output.data(), ¶ms, output.size());
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 nvhost_as_gpu::UnmapBuffer(const std::vector<u8>& input, std::vector<u8>& output) {
|
|
|
|
IoctlUnmapBuffer params{};
|
|
|
|
std::memcpy(¶ms, input.data(), input.size());
|
|
|
|
|
2018-07-02 18:13:26 +02:00
|
|
|
LOG_DEBUG(Service_NVDRV, "called, offset=0x{:X}", params.offset);
|
2018-05-20 21:21:06 +02:00
|
|
|
|
2018-08-03 18:55:58 +02:00
|
|
|
const auto itr = buffer_mappings.find(params.offset);
|
2018-05-20 21:21:06 +02:00
|
|
|
ASSERT_MSG(itr != buffer_mappings.end(), "Tried to unmap invalid mapping");
|
|
|
|
|
2018-08-03 18:55:58 +02:00
|
|
|
auto& system_instance = Core::System::GetInstance();
|
|
|
|
|
2018-07-01 17:50:06 +02:00
|
|
|
// Remove this memory region from the rasterizer cache.
|
2018-08-03 19:56:33 +02:00
|
|
|
system_instance.Renderer().Rasterizer().FlushAndInvalidateRegion(params.offset,
|
|
|
|
itr->second.size);
|
2018-07-01 17:50:06 +02:00
|
|
|
|
2018-08-03 18:55:58 +02:00
|
|
|
auto& gpu = system_instance.GPU();
|
2018-08-28 16:57:56 +02:00
|
|
|
params.offset = gpu.MemoryManager().UnmapBuffer(params.offset, itr->second.size);
|
2018-05-20 21:21:06 +02:00
|
|
|
|
|
|
|
buffer_mappings.erase(itr->second.offset);
|
|
|
|
|
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
|
|
|
std::memcpy(output.data(), ¶ms, output.size());
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 nvhost_as_gpu::BindChannel(const std::vector<u8>& input, std::vector<u8>& output) {
|
|
|
|
IoctlBindChannel params{};
|
|
|
|
std::memcpy(¶ms, input.data(), input.size());
|
2018-07-02 18:13:26 +02:00
|
|
|
LOG_DEBUG(Service_NVDRV, "called, fd={:X}", params.fd);
|
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
|
|
|
channel = params.fd;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 nvhost_as_gpu::GetVARegions(const std::vector<u8>& input, std::vector<u8>& output) {
|
|
|
|
IoctlGetVaRegions params{};
|
|
|
|
std::memcpy(¶ms, input.data(), input.size());
|
2018-07-02 18:13:26 +02:00
|
|
|
LOG_WARNING(Service_NVDRV, "(STUBBED) called, buf_addr={:X}, buf_size={:X}", params.buf_addr,
|
2018-07-02 18:20:50 +02:00
|
|
|
params.buf_size);
|
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
|
|
|
|
|
|
|
params.buf_size = 0x30;
|
|
|
|
params.regions[0].offset = 0x04000000;
|
|
|
|
params.regions[0].page_size = 0x1000;
|
|
|
|
params.regions[0].pages = 0x3fbfff;
|
|
|
|
|
|
|
|
params.regions[1].offset = 0x04000000;
|
|
|
|
params.regions[1].page_size = 0x10000;
|
|
|
|
params.regions[1].pages = 0x1bffff;
|
|
|
|
// TODO(ogniK): This probably can stay stubbed but should add support way way later
|
|
|
|
std::memcpy(output.data(), ¶ms, output.size());
|
2018-01-09 16:41:13 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-04-20 03:41:44 +02:00
|
|
|
} // namespace Service::Nvidia::Devices
|