summaryrefslogtreecommitdiffstats
path: root/src/core/hle/service/nvdrv
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/hle/service/nvdrv')
-rw-r--r--src/core/hle/service/nvdrv/devices/nvdevice.h4
-rw-r--r--src/core/hle/service/nvdrv/devices/nvdisp_disp0.cpp4
-rw-r--r--src/core/hle/service/nvdrv/devices/nvdisp_disp0.h4
-rw-r--r--src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp4
-rw-r--r--src/core/hle/service/nvdrv/devices/nvhost_as_gpu.h4
-rw-r--r--src/core/hle/service/nvdrv/devices/nvmap.cpp4
-rw-r--r--src/core/hle/service/nvdrv/devices/nvmap.h4
-rw-r--r--src/core/hle/service/nvdrv/interface.cpp (renamed from src/core/hle/service/nvdrv/nvdrv_a.cpp)41
-rw-r--r--src/core/hle/service/nvdrv/interface.h29
-rw-r--r--src/core/hle/service/nvdrv/nvdrv.cpp47
-rw-r--r--src/core/hle/service/nvdrv/nvdrv.h124
-rw-r--r--src/core/hle/service/nvdrv/nvdrv_a.h51
12 files changed, 126 insertions, 194 deletions
diff --git a/src/core/hle/service/nvdrv/devices/nvdevice.h b/src/core/hle/service/nvdrv/devices/nvdevice.h
index 1ee2787c6..5ee33b3d6 100644
--- a/src/core/hle/service/nvdrv/devices/nvdevice.h
+++ b/src/core/hle/service/nvdrv/devices/nvdevice.h
@@ -8,7 +8,7 @@
#include "common/common_types.h"
namespace Service {
-namespace NVDRV {
+namespace Nvidia {
namespace Devices {
/// Represents an abstract nvidia device node. It is to be subclassed by concrete device nodes to
@@ -29,5 +29,5 @@ public:
};
} // namespace Devices
-} // namespace NVDRV
+} // namespace Nvidia
} // namespace Service
diff --git a/src/core/hle/service/nvdrv/devices/nvdisp_disp0.cpp b/src/core/hle/service/nvdrv/devices/nvdisp_disp0.cpp
index 992f70b45..c42a65b36 100644
--- a/src/core/hle/service/nvdrv/devices/nvdisp_disp0.cpp
+++ b/src/core/hle/service/nvdrv/devices/nvdisp_disp0.cpp
@@ -10,7 +10,7 @@
#include "video_core/video_core.h"
namespace Service {
-namespace NVDRV {
+namespace Nvidia {
namespace Devices {
u32 nvdisp_disp0::ioctl(u32 command, const std::vector<u8>& input, std::vector<u8>& output) {
@@ -32,5 +32,5 @@ void nvdisp_disp0::flip(u32 buffer_handle, u32 offset, u32 format, u32 width, u3
}
} // namespace Devices
-} // namespace NVDRV
+} // namespace Nvidia
} // namespace Service
diff --git a/src/core/hle/service/nvdrv/devices/nvdisp_disp0.h b/src/core/hle/service/nvdrv/devices/nvdisp_disp0.h
index 601068af1..f5f9de3f4 100644
--- a/src/core/hle/service/nvdrv/devices/nvdisp_disp0.h
+++ b/src/core/hle/service/nvdrv/devices/nvdisp_disp0.h
@@ -10,7 +10,7 @@
#include "core/hle/service/nvdrv/devices/nvdevice.h"
namespace Service {
-namespace NVDRV {
+namespace Nvidia {
namespace Devices {
class nvmap;
@@ -30,5 +30,5 @@ private:
};
} // namespace Devices
-} // namespace NVDRV
+} // namespace Nvidia
} // namespace Service
diff --git a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp
index c7bf79050..9db08339a 100644
--- a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp
+++ b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp
@@ -7,7 +7,7 @@
#include "core/hle/service/nvdrv/devices/nvhost_as_gpu.h"
namespace Service {
-namespace NVDRV {
+namespace Nvidia {
namespace Devices {
u32 nvhost_as_gpu::ioctl(u32 command, const std::vector<u8>& input, std::vector<u8>& output) {
@@ -16,5 +16,5 @@ u32 nvhost_as_gpu::ioctl(u32 command, const std::vector<u8>& input, std::vector<
}
} // namespace Devices
-} // namespace NVDRV
+} // namespace Nvidia
} // namespace Service
diff --git a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.h b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.h
index 6f441b020..01f8861c8 100644
--- a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.h
+++ b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.h
@@ -9,7 +9,7 @@
#include "core/hle/service/nvdrv/devices/nvdevice.h"
namespace Service {
-namespace NVDRV {
+namespace Nvidia {
namespace Devices {
class nvhost_as_gpu final : public nvdevice {
@@ -21,5 +21,5 @@ public:
};
} // namespace Devices
-} // namespace NVDRV
+} // namespace Nvidia
} // namespace Service
diff --git a/src/core/hle/service/nvdrv/devices/nvmap.cpp b/src/core/hle/service/nvdrv/devices/nvmap.cpp
index 2d6f30e3e..d37b5b159 100644
--- a/src/core/hle/service/nvdrv/devices/nvmap.cpp
+++ b/src/core/hle/service/nvdrv/devices/nvmap.cpp
@@ -9,7 +9,7 @@
#include "core/hle/service/nvdrv/devices/nvmap.h"
namespace Service {
-namespace NVDRV {
+namespace Nvidia {
namespace Devices {
VAddr nvmap::GetObjectAddress(u32 handle) const {
@@ -151,5 +151,5 @@ u32 nvmap::IocParam(const std::vector<u8>& input, std::vector<u8>& output) {
}
} // namespace Devices
-} // namespace NVDRV
+} // namespace Nvidia
} // namespace Service
diff --git a/src/core/hle/service/nvdrv/devices/nvmap.h b/src/core/hle/service/nvdrv/devices/nvmap.h
index e74f356e5..6954c0324 100644
--- a/src/core/hle/service/nvdrv/devices/nvmap.h
+++ b/src/core/hle/service/nvdrv/devices/nvmap.h
@@ -13,7 +13,7 @@
#include "core/hle/service/nvdrv/devices/nvdevice.h"
namespace Service {
-namespace NVDRV {
+namespace Nvidia {
namespace Devices {
class nvmap final : public nvdevice {
@@ -104,5 +104,5 @@ private:
};
} // namespace Devices
-} // namespace NVDRV
+} // namespace Nvidia
} // namespace Service
diff --git a/src/core/hle/service/nvdrv/nvdrv_a.cpp b/src/core/hle/service/nvdrv/interface.cpp
index 84d89cb49..0670ca155 100644
--- a/src/core/hle/service/nvdrv/nvdrv_a.cpp
+++ b/src/core/hle/service/nvdrv/interface.cpp
@@ -4,35 +4,27 @@
#include "common/logging/log.h"
#include "core/hle/ipc_helpers.h"
-#include "core/hle/service/nvdrv/devices/nvdevice.h"
-#include "core/hle/service/nvdrv/devices/nvdisp_disp0.h"
-#include "core/hle/service/nvdrv/devices/nvhost_as_gpu.h"
-#include "core/hle/service/nvdrv/devices/nvmap.h"
+#include "core/hle/service/nvdrv/interface.h"
#include "core/hle/service/nvdrv/nvdrv.h"
-#include "core/hle/service/nvdrv/nvdrv_a.h"
namespace Service {
-namespace NVDRV {
+namespace Nvidia {
-void NVDRV_A::Open(Kernel::HLERequestContext& ctx) {
+void NVDRV::Open(Kernel::HLERequestContext& ctx) {
LOG_WARNING(Service, "(STUBBED) called");
auto buffer = ctx.BufferDescriptorA()[0];
std::string device_name = Memory::ReadCString(buffer.Address(), buffer.Size());
- auto device = devices[device_name];
- u32 fd = next_fd++;
-
- open_files[fd] = device;
-
+ u32 fd = nvdrv->Open(device_name);
IPC::RequestBuilder rb{ctx, 4};
rb.Push(RESULT_SUCCESS);
rb.Push<u32>(fd);
rb.Push<u32>(0);
}
-void NVDRV_A::Ioctl(Kernel::HLERequestContext& ctx) {
+void NVDRV::Ioctl(Kernel::HLERequestContext& ctx) {
LOG_WARNING(Service, "(STUBBED) called");
IPC::RequestParser rp{ctx};
@@ -46,11 +38,8 @@ void NVDRV_A::Ioctl(Kernel::HLERequestContext& ctx) {
std::vector<u8> output(output_buffer.Size());
Memory::ReadBlock(input_buffer.Address(), input.data(), input_buffer.Size());
- auto itr = open_files.find(fd);
- ASSERT_MSG(itr != open_files.end(), "Tried to talk to an invalid device");
- auto device = itr->second;
- u32 nv_result = device->ioctl(command, input, output);
+ u32 nv_result = nvdrv->Ioctl(fd, command, input, output);
Memory::WriteBlock(output_buffer.Address(), output.data(), output_buffer.Size());
@@ -59,26 +48,22 @@ void NVDRV_A::Ioctl(Kernel::HLERequestContext& ctx) {
rb.Push(nv_result);
}
-void NVDRV_A::Initialize(Kernel::HLERequestContext& ctx) {
+void NVDRV::Initialize(Kernel::HLERequestContext& ctx) {
LOG_WARNING(Service, "(STUBBED) called");
IPC::RequestBuilder rb{ctx, 3};
rb.Push(RESULT_SUCCESS);
rb.Push<u32>(0);
}
-NVDRV_A::NVDRV_A() : ServiceFramework("nvdrv:a") {
+NVDRV::NVDRV(std::shared_ptr<Module> nvdrv, const char* name)
+ : ServiceFramework(name), nvdrv(std::move(nvdrv)) {
static const FunctionInfo functions[] = {
- {0, &NVDRV_A::Open, "Open"},
- {1, &NVDRV_A::Ioctl, "Ioctl"},
- {3, &NVDRV_A::Initialize, "Initialize"},
+ {0, &NVDRV::Open, "Open"},
+ {1, &NVDRV::Ioctl, "Ioctl"},
+ {3, &NVDRV::Initialize, "Initialize"},
};
RegisterHandlers(functions);
-
- auto nvmap_dev = std::make_shared<Devices::nvmap>();
- devices["/dev/nvhost-as-gpu"] = std::make_shared<Devices::nvhost_as_gpu>();
- devices["/dev/nvmap"] = nvmap_dev;
- devices["/dev/nvdisp_disp0"] = std::make_shared<Devices::nvdisp_disp0>(nvmap_dev);
}
-} // namespace NVDRV
+} // namespace Nvidia
} // namespace Service
diff --git a/src/core/hle/service/nvdrv/interface.h b/src/core/hle/service/nvdrv/interface.h
new file mode 100644
index 000000000..8c95b7217
--- /dev/null
+++ b/src/core/hle/service/nvdrv/interface.h
@@ -0,0 +1,29 @@
+// Copyright 2018 yuzu emulator team
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include <memory>
+#include <string>
+#include "core/hle/service/nvdrv/nvdrv.h"
+#include "core/hle/service/service.h"
+
+namespace Service {
+namespace Nvidia {
+
+class NVDRV final : public ServiceFramework<NVDRV> {
+public:
+ NVDRV(std::shared_ptr<Module> nvdrv, const char* name);
+ ~NVDRV() = default;
+
+private:
+ void Open(Kernel::HLERequestContext& ctx);
+ void Ioctl(Kernel::HLERequestContext& ctx);
+ void Initialize(Kernel::HLERequestContext& ctx);
+
+ std::shared_ptr<Module> nvdrv;
+};
+
+} // namespace Nvidia
+} // namespace Service
diff --git a/src/core/hle/service/nvdrv/nvdrv.cpp b/src/core/hle/service/nvdrv/nvdrv.cpp
index c874e6395..cf525a875 100644
--- a/src/core/hle/service/nvdrv/nvdrv.cpp
+++ b/src/core/hle/service/nvdrv/nvdrv.cpp
@@ -2,19 +2,52 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
+#include "core/hle/ipc_helpers.h"
+#include "core/hle/service/nvdrv/devices/nvdevice.h"
+#include "core/hle/service/nvdrv/devices/nvdisp_disp0.h"
+#include "core/hle/service/nvdrv/devices/nvhost_as_gpu.h"
+#include "core/hle/service/nvdrv/devices/nvmap.h"
#include "core/hle/service/nvdrv/nvdrv.h"
-#include "core/hle/service/nvdrv/nvdrv_a.h"
+#include "core/hle/service/nvdrv/interface.h"
namespace Service {
-namespace NVDRV {
+namespace Nvidia {
-std::weak_ptr<NVDRV_A> nvdrv_a;
+std::weak_ptr<Module> nvdrv;
void InstallInterfaces(SM::ServiceManager& service_manager) {
- auto nvdrv = std::make_shared<NVDRV_A>();
- nvdrv->InstallAsService(service_manager);
- nvdrv_a = nvdrv;
+ auto module_ = std::make_shared<Module>();
+ std::make_shared<NVDRV>(module_, "nvdrv")->InstallAsService(service_manager);
+ std::make_shared<NVDRV>(module_, "nvdrv:a")->InstallAsService(service_manager);
+ nvdrv = module_;
}
-} // namespace NVDRV
+Module::Module() {
+ auto nvmap_dev = std::make_shared<Devices::nvmap>();
+ devices["/dev/nvhost-as-gpu"] = std::make_shared<Devices::nvhost_as_gpu>();
+ devices["/dev/nvmap"] = nvmap_dev;
+ devices["/dev/nvdisp_disp0"] = std::make_shared<Devices::nvdisp_disp0>(nvmap_dev);
+}
+
+u32 Module::Open(std::string device_name) {
+ ASSERT_MSG(devices.find(device_name) != devices.end(), "Trying to open unknown device %s",
+ device_name.c_str());
+
+ auto device = devices[device_name];
+ u32 fd = next_fd++;
+
+ open_files[fd] = device;
+
+ return fd;
+}
+
+u32 Module::Ioctl(u32 fd, u32 command, const std::vector<u8>& input, std::vector<u8>& output) {
+ auto itr = open_files.find(fd);
+ ASSERT_MSG(itr != open_files.end(), "Tried to talk to an invalid device");
+
+ auto device = itr->second;
+ return device->ioctl(command, input, output);
+}
+
+} // namespace Nvidia
} // namespace Service
diff --git a/src/core/hle/service/nvdrv/nvdrv.h b/src/core/hle/service/nvdrv/nvdrv.h
index a1c050416..1940ced99 100644
--- a/src/core/hle/service/nvdrv/nvdrv.h
+++ b/src/core/hle/service/nvdrv/nvdrv.h
@@ -11,110 +11,46 @@
#include "core/hle/service/service.h"
namespace Service {
-namespace NVDRV {
+namespace Nvidia {
-class nvdevice {
-public:
- virtual ~nvdevice() = default;
-
- virtual u32 ioctl(u32 command, const std::vector<u8>& input, std::vector<u8>& output) = 0;
-};
+namespace Devices {
+class nvdevice;
+}
-class nvmap : public nvdevice {
+class Module final {
public:
- /// Returns the allocated address of an nvmap object given its handle.
- VAddr GetObjectAddress(u32 handle) const;
-
- u32 ioctl(u32 command, const std::vector<u8>& input, std::vector<u8>& output) override;
+ Module();
+ ~Module() = default;
+
+ /// Returns a pointer to one of the available devices, identified by its name.
+ template <typename T>
+ std::shared_ptr<T> GetDevice(std::string name) {
+ auto itr = devices.find(name);
+ if (itr == devices.end())
+ return nullptr;
+ return std::static_pointer_cast<T>(itr->second);
+ }
+
+ /// Opens a device node and returns a file descriptor to it.
+ u32 Open(std::string device_name);
+ /// Sends an ioctl command to the specified file descriptor.
+ u32 Ioctl(u32 fd, u32 command, const std::vector<u8>& input, std::vector<u8>& output);
private:
- // Represents an nvmap object.
- struct Object {
- enum class Status { Created, Allocated };
- u32 id;
- u32 size;
- u32 flags;
- u32 align;
- u8 kind;
- VAddr addr;
- Status status;
- };
-
- u32 next_handle = 1;
- u32 next_id = 1;
- std::unordered_map<u32, std::shared_ptr<Object>> handles;
-
- enum IoctlCommands {
- IocCreateCommand = 0xC0080101,
- IocFromIdCommand = 0xC0080103,
- IocAllocCommand = 0xC0200104,
- IocParamCommand = 0xC00C0109,
- IocGetIdCommand = 0xC008010E
- };
-
- struct IocCreateParams {
- // Input
- u32_le size;
- // Output
- u32_le handle;
- };
-
- struct IocAllocParams {
- // Input
- u32_le handle;
- u32_le heap_mask;
- u32_le flags;
- u32_le align;
- u8 kind;
- INSERT_PADDING_BYTES(7);
- u64_le addr;
- };
-
- struct IocGetIdParams {
- // Output
- u32_le id;
- // Input
- u32_le handle;
- };
+ /// Id to use for the next open file descriptor.
+ u32 next_fd = 1;
- struct IocFromIdParams {
- // Input
- u32_le id;
- // Output
- u32_le handle;
- };
+ /// Mapping of file descriptors to the devices they reference.
+ std::unordered_map<u32, std::shared_ptr<Devices::nvdevice>> open_files;
- struct IocParamParams {
- // Input
- u32_le handle;
- u32_le type;
- // Output
- u32_le value;
- };
-
- u32 IocCreate(const std::vector<u8>& input, std::vector<u8>& output);
- u32 IocAlloc(const std::vector<u8>& input, std::vector<u8>& output);
- u32 IocGetId(const std::vector<u8>& input, std::vector<u8>& output);
- u32 IocFromId(const std::vector<u8>& input, std::vector<u8>& output);
- u32 IocParam(const std::vector<u8>& input, std::vector<u8>& output);
-};
-
-class nvdisp_disp0 : public nvdevice {
-public:
- nvdisp_disp0(std::shared_ptr<nvmap> nvmap_dev) : nvdevice(), nvmap_dev(std::move(nvmap_dev)) {}
- ~nvdisp_disp0() = default;
-
- u32 ioctl(u32 command, const std::vector<u8>& input, std::vector<u8>& output) override;
-
- /// Performs a screen flip, drawing the buffer pointed to by the handle.
- void flip(u32 buffer_handle, u32 offset, u32 format, u32 width, u32 height, u32 stride);
-
-private:
- std::shared_ptr<nvmap> nvmap_dev;
+ /// Mapping of device node names to their implementation.
+ std::unordered_map<std::string, std::shared_ptr<Devices::nvdevice>> devices;
};
/// Registers all NVDRV services with the specified service manager.
void InstallInterfaces(SM::ServiceManager& service_manager);
-} // namespace NVDRV
+extern std::weak_ptr<Module> nvdrv;
+
+} // namespace Nvidia
} // namespace Service
diff --git a/src/core/hle/service/nvdrv/nvdrv_a.h b/src/core/hle/service/nvdrv/nvdrv_a.h
deleted file mode 100644
index 62f10e9f6..000000000
--- a/src/core/hle/service/nvdrv/nvdrv_a.h
+++ /dev/null
@@ -1,51 +0,0 @@
-// Copyright 2018 yuzu emulator team
-// Licensed under GPLv2 or any later version
-// Refer to the license.txt file included.
-
-#pragma once
-
-#include <memory>
-#include <string>
-#include "core/hle/service/nvdrv/nvdrv.h"
-#include "core/hle/service/service.h"
-
-namespace Service {
-namespace NVDRV {
-
-namespace Devices {
-class nvdevice;
-}
-
-class NVDRV_A final : public ServiceFramework<NVDRV_A> {
-public:
- NVDRV_A();
- ~NVDRV_A() = default;
-
- /// Returns a pointer to one of the available devices, identified by its name.
- template <typename T>
- std::shared_ptr<T> GetDevice(std::string name) {
- auto itr = devices.find(name);
- if (itr == devices.end())
- return nullptr;
- return std::static_pointer_cast<T>(itr->second);
- }
-
-private:
- void Open(Kernel::HLERequestContext& ctx);
- void Ioctl(Kernel::HLERequestContext& ctx);
- void Initialize(Kernel::HLERequestContext& ctx);
-
- /// Id to use for the next open file descriptor.
- u32 next_fd = 1;
-
- /// Mapping of file descriptors to the devices they reference.
- std::unordered_map<u32, std::shared_ptr<Devices::nvdevice>> open_files;
-
- /// Mapping of device node names to their implementation.
- std::unordered_map<std::string, std::shared_ptr<Devices::nvdevice>> devices;
-};
-
-extern std::weak_ptr<NVDRV_A> nvdrv_a;
-
-} // namespace NVDRV
-} // namespace Service