2018-01-13 16:22:39 -05:00
|
|
|
// Copyright 2018 yuzu emulator team
|
2018-01-07 21:25:57 -05:00
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2018-01-08 21:30:22 -05:00
|
|
|
#include <memory>
|
|
|
|
#include <unordered_map>
|
2018-01-07 21:25:57 -05:00
|
|
|
#include <vector>
|
|
|
|
#include "common/common_types.h"
|
|
|
|
#include "core/hle/service/service.h"
|
|
|
|
|
2018-08-07 09:17:09 -04:00
|
|
|
namespace Service::NVFlinger {
|
|
|
|
class NVFlinger;
|
|
|
|
}
|
|
|
|
|
2018-04-19 21:41:44 -04:00
|
|
|
namespace Service::Nvidia {
|
2018-01-07 21:25:57 -05:00
|
|
|
|
2018-01-15 17:39:00 -05:00
|
|
|
namespace Devices {
|
|
|
|
class nvdevice;
|
|
|
|
}
|
2018-01-07 21:25:57 -05:00
|
|
|
|
2018-02-13 22:12:46 -05:00
|
|
|
struct IoctlFence {
|
|
|
|
u32 id;
|
|
|
|
u32 value;
|
|
|
|
};
|
|
|
|
|
|
|
|
static_assert(sizeof(IoctlFence) == 8, "IoctlFence has wrong size");
|
|
|
|
|
2018-01-15 17:39:00 -05:00
|
|
|
class Module final {
|
2018-01-08 21:30:22 -05:00
|
|
|
public:
|
2018-01-15 17:39:00 -05:00
|
|
|
Module();
|
|
|
|
~Module() = default;
|
|
|
|
|
|
|
|
/// Returns a pointer to one of the available devices, identified by its name.
|
|
|
|
template <typename T>
|
2018-07-19 11:39:39 -04:00
|
|
|
std::shared_ptr<T> GetDevice(const std::string& name) {
|
2018-01-15 17:39:00 -05:00
|
|
|
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.
|
2018-07-25 17:37:41 -04:00
|
|
|
u32 Open(const std::string& device_name);
|
2018-01-15 17:39:00 -05:00
|
|
|
/// Sends an ioctl command to the specified file descriptor.
|
|
|
|
u32 Ioctl(u32 fd, u32 command, const std::vector<u8>& input, std::vector<u8>& output);
|
2018-01-17 11:08:46 -05:00
|
|
|
/// Closes a device file descriptor and returns operation success.
|
|
|
|
ResultCode Close(u32 fd);
|
2018-01-16 13:05:21 -05:00
|
|
|
|
2018-01-08 21:30:22 -05:00
|
|
|
private:
|
2018-01-15 17:39:00 -05:00
|
|
|
/// Id to use for the next open file descriptor.
|
|
|
|
u32 next_fd = 1;
|
2018-01-08 21:30:22 -05:00
|
|
|
|
2018-01-15 17:39:00 -05:00
|
|
|
/// Mapping of file descriptors to the devices they reference.
|
|
|
|
std::unordered_map<u32, std::shared_ptr<Devices::nvdevice>> open_files;
|
2018-01-08 21:30:22 -05:00
|
|
|
|
2018-01-15 17:39:00 -05:00
|
|
|
/// Mapping of device node names to their implementation.
|
|
|
|
std::unordered_map<std::string, std::shared_ptr<Devices::nvdevice>> devices;
|
2018-01-08 21:30:22 -05:00
|
|
|
};
|
|
|
|
|
2018-01-07 21:25:57 -05:00
|
|
|
/// Registers all NVDRV services with the specified service manager.
|
2018-08-07 09:17:09 -04:00
|
|
|
void InstallInterfaces(SM::ServiceManager& service_manager, NVFlinger::NVFlinger& nvflinger);
|
2018-01-15 17:39:00 -05:00
|
|
|
|
2018-04-19 21:41:44 -04:00
|
|
|
} // namespace Service::Nvidia
|