From 30657f9ca1485dcf9611d3c4ea3c74d52b350dec Mon Sep 17 00:00:00 2001 From: Subv Date: Mon, 15 Jan 2018 17:39:00 -0500 Subject: NV: Move the nvdrv classes into the Nvidia namespace, and move the functionality to a s single module that services call. --- src/core/hle/service/nvdrv/nvdrv.h | 124 +++++++++---------------------------- 1 file changed, 30 insertions(+), 94 deletions(-) (limited to 'src/core/hle/service/nvdrv/nvdrv.h') 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& input, std::vector& 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& input, std::vector& output) override; + Module(); + ~Module() = default; + + /// Returns a pointer to one of the available devices, identified by its name. + template + std::shared_ptr GetDevice(std::string name) { + auto itr = devices.find(name); + if (itr == devices.end()) + return nullptr; + return std::static_pointer_cast(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& input, std::vector& 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> 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> open_files; - struct IocParamParams { - // Input - u32_le handle; - u32_le type; - // Output - u32_le value; - }; - - u32 IocCreate(const std::vector& input, std::vector& output); - u32 IocAlloc(const std::vector& input, std::vector& output); - u32 IocGetId(const std::vector& input, std::vector& output); - u32 IocFromId(const std::vector& input, std::vector& output); - u32 IocParam(const std::vector& input, std::vector& output); -}; - -class nvdisp_disp0 : public nvdevice { -public: - nvdisp_disp0(std::shared_ptr nvmap_dev) : nvdevice(), nvmap_dev(std::move(nvmap_dev)) {} - ~nvdisp_disp0() = default; - - u32 ioctl(u32 command, const std::vector& input, std::vector& 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_dev; + /// Mapping of device node names to their implementation. + std::unordered_map> devices; }; /// Registers all NVDRV services with the specified service manager. void InstallInterfaces(SM::ServiceManager& service_manager); -} // namespace NVDRV +extern std::weak_ptr nvdrv; + +} // namespace Nvidia } // namespace Service -- cgit v1.2.3