Files
eden/src/core/hle/service/nvdrv/nvdrv.h
T

122 lines
3.2 KiB
C++
Raw Normal View History

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