NVDRV: Implement QueryEvent.
This commit is contained in:
parent
39a5ce4e69
commit
d30b885d71
@ -11,6 +11,10 @@ namespace Core {
|
|||||||
class System;
|
class System;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace Kernel {
|
||||||
|
class KEvent;
|
||||||
|
}
|
||||||
|
|
||||||
namespace Service::Nvidia::Devices {
|
namespace Service::Nvidia::Devices {
|
||||||
|
|
||||||
/// Represents an abstract nvidia device node. It is to be subclassed by concrete device nodes to
|
/// Represents an abstract nvidia device node. It is to be subclassed by concrete device nodes to
|
||||||
@ -64,6 +68,10 @@ public:
|
|||||||
*/
|
*/
|
||||||
virtual void OnClose(DeviceFD fd) = 0;
|
virtual void OnClose(DeviceFD fd) = 0;
|
||||||
|
|
||||||
|
virtual Kernel::KEvent* QueryEvent(u32 event_id) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Core::System& system;
|
Core::System& system;
|
||||||
};
|
};
|
||||||
|
@ -255,4 +255,27 @@ NvResult nvhost_ctrl::IocCtrlClearEventWait(const std::vector<u8>& input, std::v
|
|||||||
return NvResult::Success;
|
return NvResult::Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Kernel::KEvent* nvhost_ctrl::QueryEvent(u32 event_id) {
|
||||||
|
const auto event = SyncpointEventValue{.raw = event_id};
|
||||||
|
|
||||||
|
const bool allocated = event.event_allocated.Value() != 0;
|
||||||
|
const u32 slot{allocated ? event.partial_slot.Value() : static_cast<u32>(event.slot)};
|
||||||
|
if (slot >= MaxNvEvents) {
|
||||||
|
ASSERT(false);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
const u32 syncpoint_id{allocated ? event.syncpoint_id_for_allocation.Value()
|
||||||
|
: event.syncpoint_id.Value()};
|
||||||
|
|
||||||
|
auto lock = events_interface.Lock();
|
||||||
|
|
||||||
|
if (events_interface.registered[slot] &&
|
||||||
|
events_interface.assigned_syncpt[slot] == syncpoint_id) {
|
||||||
|
ASSERT(events_interface.events[slot]);
|
||||||
|
return events_interface.events[slot];
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Service::Nvidia::Devices
|
} // namespace Service::Nvidia::Devices
|
||||||
|
@ -28,6 +28,8 @@ public:
|
|||||||
void OnOpen(DeviceFD fd) override;
|
void OnOpen(DeviceFD fd) override;
|
||||||
void OnClose(DeviceFD fd) override;
|
void OnClose(DeviceFD fd) override;
|
||||||
|
|
||||||
|
Kernel::KEvent* QueryEvent(u32 event_id) override;
|
||||||
|
|
||||||
union SyncpointEventValue {
|
union SyncpointEventValue {
|
||||||
u32 raw;
|
u32 raw;
|
||||||
|
|
||||||
|
@ -7,10 +7,15 @@
|
|||||||
#include "core/core.h"
|
#include "core/core.h"
|
||||||
#include "core/core_timing.h"
|
#include "core/core_timing.h"
|
||||||
#include "core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.h"
|
#include "core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.h"
|
||||||
|
#include "core/hle/service/nvdrv/nvdrv.h"
|
||||||
|
|
||||||
namespace Service::Nvidia::Devices {
|
namespace Service::Nvidia::Devices {
|
||||||
|
|
||||||
nvhost_ctrl_gpu::nvhost_ctrl_gpu(Core::System& system_) : nvdevice{system_} {}
|
nvhost_ctrl_gpu::nvhost_ctrl_gpu(Core::System& system_, EventInterface& events_interface_)
|
||||||
|
: nvdevice{system_}, events_interface{events_interface_} {
|
||||||
|
error_notifier_event = events_interface.CreateNonCtrlEvent("CtrlGpuErrorNotifier");
|
||||||
|
unknown_event = events_interface.CreateNonCtrlEvent("CtrlGpuUknownEvent");
|
||||||
|
}
|
||||||
nvhost_ctrl_gpu::~nvhost_ctrl_gpu() = default;
|
nvhost_ctrl_gpu::~nvhost_ctrl_gpu() = default;
|
||||||
|
|
||||||
NvResult nvhost_ctrl_gpu::Ioctl1(DeviceFD fd, Ioctl command, const std::vector<u8>& input,
|
NvResult nvhost_ctrl_gpu::Ioctl1(DeviceFD fd, Ioctl command, const std::vector<u8>& input,
|
||||||
@ -286,4 +291,17 @@ NvResult nvhost_ctrl_gpu::GetGpuTime(const std::vector<u8>& input, std::vector<u
|
|||||||
return NvResult::Success;
|
return NvResult::Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Kernel::KEvent* nvhost_ctrl_gpu::QueryEvent(u32 event_id) {
|
||||||
|
switch (event_id) {
|
||||||
|
case 1:
|
||||||
|
return error_notifier_event;
|
||||||
|
case 2:
|
||||||
|
return unknown_event;
|
||||||
|
default: {
|
||||||
|
LOG_CRITICAL(Service_NVDRV, "Unknown Ctrl GPU Event {}", event_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Service::Nvidia::Devices
|
} // namespace Service::Nvidia::Devices
|
||||||
|
@ -10,11 +10,15 @@
|
|||||||
#include "common/swap.h"
|
#include "common/swap.h"
|
||||||
#include "core/hle/service/nvdrv/devices/nvdevice.h"
|
#include "core/hle/service/nvdrv/devices/nvdevice.h"
|
||||||
|
|
||||||
|
namespace Service::Nvidia {
|
||||||
|
class EventInterface;
|
||||||
|
}
|
||||||
|
|
||||||
namespace Service::Nvidia::Devices {
|
namespace Service::Nvidia::Devices {
|
||||||
|
|
||||||
class nvhost_ctrl_gpu final : public nvdevice {
|
class nvhost_ctrl_gpu final : public nvdevice {
|
||||||
public:
|
public:
|
||||||
explicit nvhost_ctrl_gpu(Core::System& system_);
|
explicit nvhost_ctrl_gpu(Core::System& system_, EventInterface& events_interface_);
|
||||||
~nvhost_ctrl_gpu() override;
|
~nvhost_ctrl_gpu() override;
|
||||||
|
|
||||||
NvResult Ioctl1(DeviceFD fd, Ioctl command, const std::vector<u8>& input,
|
NvResult Ioctl1(DeviceFD fd, Ioctl command, const std::vector<u8>& input,
|
||||||
@ -27,6 +31,8 @@ public:
|
|||||||
void OnOpen(DeviceFD fd) override;
|
void OnOpen(DeviceFD fd) override;
|
||||||
void OnClose(DeviceFD fd) override;
|
void OnClose(DeviceFD fd) override;
|
||||||
|
|
||||||
|
Kernel::KEvent* QueryEvent(u32 event_id) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct IoctlGpuCharacteristics {
|
struct IoctlGpuCharacteristics {
|
||||||
u32_le arch; // 0x120 (NVGPU_GPU_ARCH_GM200)
|
u32_le arch; // 0x120 (NVGPU_GPU_ARCH_GM200)
|
||||||
@ -160,6 +166,12 @@ private:
|
|||||||
NvResult ZBCQueryTable(const std::vector<u8>& input, std::vector<u8>& output);
|
NvResult ZBCQueryTable(const std::vector<u8>& input, std::vector<u8>& output);
|
||||||
NvResult FlushL2(const std::vector<u8>& input, std::vector<u8>& output);
|
NvResult FlushL2(const std::vector<u8>& input, std::vector<u8>& output);
|
||||||
NvResult GetGpuTime(const std::vector<u8>& input, std::vector<u8>& output);
|
NvResult GetGpuTime(const std::vector<u8>& input, std::vector<u8>& output);
|
||||||
|
|
||||||
|
EventInterface& events_interface;
|
||||||
|
|
||||||
|
// Events
|
||||||
|
Kernel::KEvent* error_notifier_event;
|
||||||
|
Kernel::KEvent* unknown_event;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Service::Nvidia::Devices
|
} // namespace Service::Nvidia::Devices
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include "common/logging/log.h"
|
#include "common/logging/log.h"
|
||||||
#include "core/core.h"
|
#include "core/core.h"
|
||||||
#include "core/hle/service/nvdrv/devices/nvhost_gpu.h"
|
#include "core/hle/service/nvdrv/devices/nvhost_gpu.h"
|
||||||
|
#include "core/hle/service/nvdrv/nvdrv.h"
|
||||||
#include "core/hle/service/nvdrv/syncpoint_manager.h"
|
#include "core/hle/service/nvdrv/syncpoint_manager.h"
|
||||||
#include "core/memory.h"
|
#include "core/memory.h"
|
||||||
#include "video_core/gpu.h"
|
#include "video_core/gpu.h"
|
||||||
@ -21,10 +22,16 @@ Tegra::CommandHeader BuildFenceAction(Tegra::GPU::FenceOperation op, u32 syncpoi
|
|||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
nvhost_gpu::nvhost_gpu(Core::System& system_, std::shared_ptr<nvmap> nvmap_dev_,
|
nvhost_gpu::nvhost_gpu(Core::System& system_, std::shared_ptr<nvmap> nvmap_dev_,
|
||||||
SyncpointManager& syncpoint_manager_)
|
EventInterface& events_interface_, SyncpointManager& syncpoint_manager_)
|
||||||
: nvdevice{system_}, nvmap_dev{std::move(nvmap_dev_)}, syncpoint_manager{syncpoint_manager_} {
|
: nvdevice{system_}, nvmap_dev{std::move(nvmap_dev_)}, events_interface{events_interface_},
|
||||||
|
syncpoint_manager{syncpoint_manager_} {
|
||||||
channel_fence.id = syncpoint_manager_.AllocateSyncpoint();
|
channel_fence.id = syncpoint_manager_.AllocateSyncpoint();
|
||||||
channel_fence.value = system_.GPU().GetSyncpointValue(channel_fence.id);
|
channel_fence.value = system_.GPU().GetSyncpointValue(channel_fence.id);
|
||||||
|
sm_exception_breakpoint_int_report_event =
|
||||||
|
events_interface.CreateNonCtrlEvent("GpuChannelSMExceptionBreakpointInt");
|
||||||
|
sm_exception_breakpoint_pause_report_event =
|
||||||
|
events_interface.CreateNonCtrlEvent("GpuChannelSMExceptionBreakpointPause");
|
||||||
|
error_notifier_event = events_interface.CreateNonCtrlEvent("GpuChannelErrorNotifier");
|
||||||
}
|
}
|
||||||
|
|
||||||
nvhost_gpu::~nvhost_gpu() = default;
|
nvhost_gpu::~nvhost_gpu() = default;
|
||||||
@ -328,4 +335,19 @@ NvResult nvhost_gpu::ChannelSetTimeslice(const std::vector<u8>& input, std::vect
|
|||||||
return NvResult::Success;
|
return NvResult::Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Kernel::KEvent* nvhost_gpu::QueryEvent(u32 event_id) {
|
||||||
|
switch (event_id) {
|
||||||
|
case 1:
|
||||||
|
return sm_exception_breakpoint_int_report_event;
|
||||||
|
case 2:
|
||||||
|
return sm_exception_breakpoint_pause_report_event;
|
||||||
|
case 3:
|
||||||
|
return error_notifier_event;
|
||||||
|
default: {
|
||||||
|
LOG_CRITICAL(Service_NVDRV, "Unknown Ctrl GPU Event {}", event_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Service::Nvidia::Devices
|
} // namespace Service::Nvidia::Devices
|
||||||
|
@ -15,7 +15,8 @@
|
|||||||
|
|
||||||
namespace Service::Nvidia {
|
namespace Service::Nvidia {
|
||||||
class SyncpointManager;
|
class SyncpointManager;
|
||||||
}
|
class EventInterface;
|
||||||
|
} // namespace Service::Nvidia
|
||||||
|
|
||||||
namespace Service::Nvidia::Devices {
|
namespace Service::Nvidia::Devices {
|
||||||
|
|
||||||
@ -23,7 +24,7 @@ class nvmap;
|
|||||||
class nvhost_gpu final : public nvdevice {
|
class nvhost_gpu final : public nvdevice {
|
||||||
public:
|
public:
|
||||||
explicit nvhost_gpu(Core::System& system_, std::shared_ptr<nvmap> nvmap_dev_,
|
explicit nvhost_gpu(Core::System& system_, std::shared_ptr<nvmap> nvmap_dev_,
|
||||||
SyncpointManager& syncpoint_manager_);
|
EventInterface& events_interface_, SyncpointManager& syncpoint_manager_);
|
||||||
~nvhost_gpu() override;
|
~nvhost_gpu() override;
|
||||||
|
|
||||||
NvResult Ioctl1(DeviceFD fd, Ioctl command, const std::vector<u8>& input,
|
NvResult Ioctl1(DeviceFD fd, Ioctl command, const std::vector<u8>& input,
|
||||||
@ -36,6 +37,8 @@ public:
|
|||||||
void OnOpen(DeviceFD fd) override;
|
void OnOpen(DeviceFD fd) override;
|
||||||
void OnClose(DeviceFD fd) override;
|
void OnClose(DeviceFD fd) override;
|
||||||
|
|
||||||
|
Kernel::KEvent* QueryEvent(u32 event_id) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum class CtxObjects : u32_le {
|
enum class CtxObjects : u32_le {
|
||||||
Ctx2D = 0x902D,
|
Ctx2D = 0x902D,
|
||||||
@ -192,8 +195,14 @@ private:
|
|||||||
NvResult ChannelSetTimeslice(const std::vector<u8>& input, std::vector<u8>& output);
|
NvResult ChannelSetTimeslice(const std::vector<u8>& input, std::vector<u8>& output);
|
||||||
|
|
||||||
std::shared_ptr<nvmap> nvmap_dev;
|
std::shared_ptr<nvmap> nvmap_dev;
|
||||||
|
EventInterface& events_interface;
|
||||||
SyncpointManager& syncpoint_manager;
|
SyncpointManager& syncpoint_manager;
|
||||||
NvFence channel_fence;
|
NvFence channel_fence;
|
||||||
|
|
||||||
|
// Events
|
||||||
|
Kernel::KEvent* sm_exception_breakpoint_int_report_event;
|
||||||
|
Kernel::KEvent* sm_exception_breakpoint_pause_report_event;
|
||||||
|
Kernel::KEvent* error_notifier_event;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Service::Nvidia::Devices
|
} // namespace Service::Nvidia::Devices
|
||||||
|
@ -96,6 +96,12 @@ u32 EventInterface::FindFreeEvent(u32 syncpoint_id) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Kernel::KEvent* EventInterface::CreateNonCtrlEvent(std::string name) {
|
||||||
|
Kernel::KEvent* new_event = module.service_context.CreateEvent(std::move(name));
|
||||||
|
basic_events.push_back(new_event);
|
||||||
|
return new_event;
|
||||||
|
}
|
||||||
|
|
||||||
void InstallInterfaces(SM::ServiceManager& service_manager, NVFlinger::NVFlinger& nvflinger,
|
void InstallInterfaces(SM::ServiceManager& service_manager, NVFlinger::NVFlinger& nvflinger,
|
||||||
Core::System& system) {
|
Core::System& system) {
|
||||||
auto module_ = std::make_shared<Module>(system);
|
auto module_ = std::make_shared<Module>(system);
|
||||||
@ -119,9 +125,10 @@ Module::Module(Core::System& system)
|
|||||||
}
|
}
|
||||||
auto nvmap_dev = std::make_shared<Devices::nvmap>(system);
|
auto nvmap_dev = std::make_shared<Devices::nvmap>(system);
|
||||||
devices["/dev/nvhost-as-gpu"] = std::make_shared<Devices::nvhost_as_gpu>(system, nvmap_dev);
|
devices["/dev/nvhost-as-gpu"] = std::make_shared<Devices::nvhost_as_gpu>(system, nvmap_dev);
|
||||||
devices["/dev/nvhost-gpu"] =
|
devices["/dev/nvhost-gpu"] = std::make_shared<Devices::nvhost_gpu>(
|
||||||
std::make_shared<Devices::nvhost_gpu>(system, nvmap_dev, syncpoint_manager);
|
system, nvmap_dev, events_interface, syncpoint_manager);
|
||||||
devices["/dev/nvhost-ctrl-gpu"] = std::make_shared<Devices::nvhost_ctrl_gpu>(system);
|
devices["/dev/nvhost-ctrl-gpu"] =
|
||||||
|
std::make_shared<Devices::nvhost_ctrl_gpu>(system, events_interface);
|
||||||
devices["/dev/nvmap"] = nvmap_dev;
|
devices["/dev/nvmap"] = nvmap_dev;
|
||||||
devices["/dev/nvdisp_disp0"] = std::make_shared<Devices::nvdisp_disp0>(system, nvmap_dev);
|
devices["/dev/nvdisp_disp0"] = std::make_shared<Devices::nvdisp_disp0>(system, nvmap_dev);
|
||||||
devices["/dev/nvhost-ctrl"] =
|
devices["/dev/nvhost-ctrl"] =
|
||||||
@ -255,31 +262,24 @@ void Module::SignalSyncpt(const u32 syncpoint_id, const u32 value) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Kernel::KEvent* Module::GetEvent(u32 event_id) {
|
NvResult Module::QueryEvent(DeviceFD fd, u32 event_id, Kernel::KEvent*& event) {
|
||||||
const auto event = Devices::nvhost_ctrl::SyncpointEventValue{.raw = event_id};
|
if (fd < 0) {
|
||||||
|
LOG_ERROR(Service_NVDRV, "Invalid DeviceFD={}!", fd);
|
||||||
const bool allocated = event.event_allocated.Value() != 0;
|
return NvResult::InvalidState;
|
||||||
const u32 slot{allocated ? event.partial_slot.Value() : static_cast<u32>(event.slot)};
|
|
||||||
if (slot >= MaxNvEvents) {
|
|
||||||
ASSERT(false);
|
|
||||||
return nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const u32 syncpoint_id{allocated ? event.syncpoint_id_for_allocation.Value()
|
const auto itr = open_files.find(fd);
|
||||||
: event.syncpoint_id.Value()};
|
|
||||||
|
|
||||||
auto lock = events_interface.Lock();
|
if (itr == open_files.end()) {
|
||||||
|
LOG_ERROR(Service_NVDRV, "Could not find DeviceFD={}!", fd);
|
||||||
if (events_interface.registered[slot] &&
|
return NvResult::NotImplemented;
|
||||||
events_interface.assigned_syncpt[slot] == syncpoint_id) {
|
|
||||||
ASSERT(events_interface.events[slot]);
|
|
||||||
return events_interface.events[slot];
|
|
||||||
}
|
}
|
||||||
// Temporary hack.
|
|
||||||
events_interface.Create(slot);
|
event = itr->second->QueryEvent(event_id);
|
||||||
events_interface.assigned_syncpt[slot] = syncpoint_id;
|
if (!event) {
|
||||||
ASSERT(false);
|
return NvResult::BadParameter;
|
||||||
return events_interface.events[slot];
|
}
|
||||||
|
return NvResult::Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Service::Nvidia
|
} // namespace Service::Nvidia
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -79,9 +80,12 @@ public:
|
|||||||
|
|
||||||
u32 FindFreeEvent(u32 syncpoint_id);
|
u32 FindFreeEvent(u32 syncpoint_id);
|
||||||
|
|
||||||
|
Kernel::KEvent* CreateNonCtrlEvent(std::string name);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::mutex events_mutex;
|
std::mutex events_mutex;
|
||||||
Module& module;
|
Module& module;
|
||||||
|
std::vector<Kernel::KEvent*> basic_events;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Module final {
|
class Module final {
|
||||||
@ -118,7 +122,7 @@ public:
|
|||||||
|
|
||||||
void SignalSyncpt(const u32 syncpoint_id, const u32 value);
|
void SignalSyncpt(const u32 syncpoint_id, const u32 value);
|
||||||
|
|
||||||
Kernel::KEvent* GetEvent(u32 event_id);
|
NvResult QueryEvent(DeviceFD fd, u32 event_id, Kernel::KEvent*& event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class EventInterface;
|
friend class EventInterface;
|
||||||
|
@ -173,25 +173,20 @@ void NVDRV::QueryEvent(Kernel::HLERequestContext& ctx) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto nv_result = nvdrv->VerifyFD(fd);
|
Kernel::KEvent* event = nullptr;
|
||||||
if (nv_result != NvResult::Success) {
|
NvResult result = nvdrv->QueryEvent(fd, event_id, event);
|
||||||
LOG_ERROR(Service_NVDRV, "Invalid FD specified DeviceFD={}!", fd);
|
|
||||||
ServiceError(ctx, nv_result);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto* event = nvdrv->GetEvent(event_id);
|
if (result == NvResult::Success) {
|
||||||
|
|
||||||
if (event) {
|
|
||||||
IPC::ResponseBuilder rb{ctx, 3, 1};
|
IPC::ResponseBuilder rb{ctx, 3, 1};
|
||||||
rb.Push(ResultSuccess);
|
rb.Push(ResultSuccess);
|
||||||
auto& readable_event = event->GetReadableEvent();
|
auto& readable_event = event->GetReadableEvent();
|
||||||
rb.PushCopyObjects(readable_event);
|
rb.PushCopyObjects(readable_event);
|
||||||
rb.PushEnum(NvResult::Success);
|
rb.PushEnum(NvResult::Success);
|
||||||
} else {
|
} else {
|
||||||
|
LOG_ERROR(Service_NVDRV, "Invalid event request!");
|
||||||
IPC::ResponseBuilder rb{ctx, 3};
|
IPC::ResponseBuilder rb{ctx, 3};
|
||||||
rb.Push(ResultSuccess);
|
rb.Push(ResultSuccess);
|
||||||
rb.PushEnum(NvResult::BadParameter);
|
rb.PushEnum(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user