2018-01-13 22:22:39 +01:00
|
|
|
// Copyright 2018 yuzu emulator team
|
2018-01-08 03:25:57 +01:00
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <memory>
|
2018-01-09 16:41:13 +01:00
|
|
|
#include <string>
|
2018-01-09 03:30:22 +01:00
|
|
|
#include "core/hle/service/nvdrv/nvdrv.h"
|
2018-01-09 16:41:13 +01:00
|
|
|
#include "core/hle/service/service.h"
|
2018-01-08 03:25:57 +01:00
|
|
|
|
|
|
|
namespace Service {
|
|
|
|
namespace NVDRV {
|
|
|
|
|
2018-01-09 16:41:13 +01:00
|
|
|
namespace Devices {
|
|
|
|
class nvdevice;
|
|
|
|
}
|
|
|
|
|
2018-01-08 03:25:57 +01:00
|
|
|
class NVDRV_A final : public ServiceFramework<NVDRV_A> {
|
|
|
|
public:
|
|
|
|
NVDRV_A();
|
|
|
|
~NVDRV_A() = default;
|
|
|
|
|
2018-01-09 03:30:22 +01:00
|
|
|
/// 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);
|
|
|
|
}
|
|
|
|
|
2018-01-08 03:25:57 +01:00
|
|
|
private:
|
|
|
|
void Open(Kernel::HLERequestContext& ctx);
|
|
|
|
void Ioctl(Kernel::HLERequestContext& ctx);
|
|
|
|
void Initialize(Kernel::HLERequestContext& ctx);
|
|
|
|
|
2018-01-09 16:41:13 +01:00
|
|
|
/// Id to use for the next open file descriptor.
|
2018-01-08 03:25:57 +01:00
|
|
|
u32 next_fd = 1;
|
|
|
|
|
2018-01-09 16:41:13 +01:00
|
|
|
/// 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;
|
2018-01-08 03:25:57 +01:00
|
|
|
};
|
|
|
|
|
2018-01-09 03:30:22 +01:00
|
|
|
extern std::weak_ptr<NVDRV_A> nvdrv_a;
|
|
|
|
|
2018-01-08 03:25:57 +01:00
|
|
|
} // namespace NVDRV
|
|
|
|
} // namespace Service
|