yuzu/src/core/hle/service/nvdrv/nvdrv.h

122 lines
3.2 KiB
C
Raw Normal View History

2022-06-30 05:24:05 +04:00
// SPDX-FileCopyrightText: 2021 yuzu Emulator Project
// SPDX-FileCopyrightText: 2021 Skyline Team and Contributors
// SPDX-License-Identifier: GPL-3.0-or-later
2020-12-28 19:15:37 +04:00
#pragma once
2022-06-16 05:46:18 +04:00
#include <functional>
#include <list>
2020-12-28 19:15:37 +04:00
#include <memory>
2022-06-16 05:46:18 +04:00
#include <string>
2020-12-28 19:15:37 +04:00
#include <unordered_map>
#include <vector>
2021-02-04 03:41:27 +04:00
2020-12-28 19:15:37 +04:00
#include "common/common_types.h"
2021-07-03 13:00:06 +04:00
#include "core/hle/service/kernel_helpers.h"
2022-06-16 05:46:18 +04:00
#include "core/hle/service/nvdrv/core/container.h"
2020-12-28 19:15:37 +04:00
#include "core/hle/service/nvdrv/nvdata.h"
2022-06-06 06:39:45 +04:00
#include "core/hle/service/nvflinger/ui/fence.h"
2020-12-28 19:15:37 +04:00
#include "core/hle/service/service.h"
namespace Core {
class System;
}
2021-02-04 03:41:27 +04:00
namespace Kernel {
class KEvent;
}
2020-12-28 19:15:37 +04:00
namespace Service::NVFlinger {
class NVFlinger;
}
namespace Service::Nvidia {
2022-06-16 05:46:18 +04:00
namespace NvCore {
class Container;
2020-12-28 19:15:37 +04:00
class SyncpointManager;
2022-06-16 05:46:18 +04:00
} // namespace NvCore
2020-12-28 19:15:37 +04:00
namespace Devices {
class nvdevice;
2022-06-16 05:46:18 +04:00
class nvhost_ctrl;
} // namespace Devices
2020-12-28 19:15:37 +04:00
2022-06-16 05:46:18 +04:00
class Module;
2020-12-28 19:15:37 +04:00
2022-06-16 05:46:18 +04:00
class EventInterface {
public:
EventInterface(Module& module_);
~EventInterface();
Kernel::KEvent* CreateEvent(std::string name);
void FreeEvent(Kernel::KEvent* event);
private:
Module& module;
std::mutex guard;
std::list<Devices::nvhost_ctrl*> on_signal;
2020-12-28 19:15:37 +04:00
};
class Module final {
public:
explicit Module(Core::System& system_);
~Module();
/// Returns a pointer to one of the available devices, identified by its name.
template <typename T>
2022-06-16 05:46:18 +04:00
std::shared_ptr<T> GetDevice(DeviceFD fd) {
auto itr = open_files.find(fd);
if (itr == open_files.end())
2020-12-28 19:15:37 +04:00
return nullptr;
return std::static_pointer_cast<T>(itr->second);
}
NvResult VerifyFD(DeviceFD fd) const;
/// Opens a device node and returns a file descriptor to it.
DeviceFD Open(const std::string& device_name);
/// Sends an ioctl command to the specified file descriptor.
NvResult Ioctl1(DeviceFD fd, Ioctl command, const std::vector<u8>& input,
2020-12-30 05:38:14 +04:00
std::vector<u8>& output);
2020-12-28 19:15:37 +04:00
NvResult Ioctl2(DeviceFD fd, Ioctl command, const std::vector<u8>& input,
2020-12-30 05:38:14 +04:00
const std::vector<u8>& inline_input, std::vector<u8>& output);
2020-12-28 19:15:37 +04:00
NvResult Ioctl3(DeviceFD fd, Ioctl command, const std::vector<u8>& input,
2020-12-30 05:38:14 +04:00
std::vector<u8>& output, std::vector<u8>& inline_output);
2020-12-28 19:15:37 +04:00
/// Closes a device file descriptor and returns operation success.
NvResult Close(DeviceFD fd);
2022-06-16 05:46:18 +04:00
NvResult QueryEvent(DeviceFD fd, u32 event_id, Kernel::KEvent*& event);
2020-12-28 19:15:37 +04:00
private:
2022-06-16 05:46:18 +04:00
friend class EventInterface;
2022-06-28 01:04:31 +04:00
friend class Service::NVFlinger::NVFlinger;
2020-12-28 19:15:37 +04:00
/// Id to use for the next open file descriptor.
DeviceFD next_fd = 1;
2022-06-16 05:46:18 +04:00
using FilesContainerType = std::unordered_map<DeviceFD, std::shared_ptr<Devices::nvdevice>>;
2020-12-28 19:15:37 +04:00
/// Mapping of file descriptors to the devices they reference.
2022-06-16 05:46:18 +04:00
FilesContainerType open_files;
2020-12-28 19:15:37 +04:00
2022-06-16 05:46:18 +04:00
KernelHelpers::ServiceContext service_context;
2020-12-28 19:15:37 +04:00
EventInterface events_interface;
2021-07-03 13:00:06 +04:00
2022-06-16 05:46:18 +04:00
/// Manages syncpoints on the host
NvCore::Container container;
std::unordered_map<std::string, std::function<FilesContainerType::iterator(DeviceFD)>> builders;
2020-12-28 19:15:37 +04:00
};
/// Registers all NVDRV services with the specified service manager.
void InstallInterfaces(SM::ServiceManager& service_manager, NVFlinger::NVFlinger& nvflinger,
Core::System& system);
} // namespace Service::Nvidia