2024-02-23 22:32:32 +01:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
2023-08-17 09:10:13 +02:00
|
|
|
#pragma once
|
2023-10-22 16:10:25 +02:00
|
|
|
|
2024-02-23 21:57:57 +01:00
|
|
|
#include <condition_variable>
|
2023-10-22 16:10:25 +02:00
|
|
|
#include <mutex>
|
2023-08-17 09:10:13 +02:00
|
|
|
#include <string>
|
2023-09-05 13:28:52 +02:00
|
|
|
#include <vector>
|
2023-11-06 00:11:54 +01:00
|
|
|
#include "common/types.h"
|
2023-08-17 09:10:13 +02:00
|
|
|
|
2024-04-13 23:35:48 +02:00
|
|
|
namespace Libraries::Kernel {
|
2023-09-05 08:13:14 +02:00
|
|
|
|
|
|
|
constexpr s16 EVFILT_READ = -1;
|
|
|
|
constexpr s16 EVFILT_WRITE = -2;
|
2024-02-23 21:57:57 +01:00
|
|
|
constexpr s16 EVFILT_AIO = -3; // attached to aio requests
|
|
|
|
constexpr s16 EVFILT_VNODE = -4; // attached to vnodes
|
|
|
|
constexpr s16 EVFILT_PROC = -5; // attached to struct proc
|
|
|
|
constexpr s16 EVFILT_SIGNAL = -6; // attached to struct proc
|
|
|
|
constexpr s16 EVFILT_TIMER = -7; // timers
|
|
|
|
constexpr s16 EVFILT_FS = -9; // filesystem events
|
|
|
|
constexpr s16 EVFILT_LIO = -10; // attached to lio requests
|
|
|
|
constexpr s16 EVFILT_USER = -11; // User events
|
2023-09-05 08:13:14 +02:00
|
|
|
constexpr s16 EVFILT_POLLING = -12;
|
|
|
|
constexpr s16 EVFILT_VIDEO_OUT = -13;
|
|
|
|
constexpr s16 EVFILT_GRAPHICS_CORE = -14;
|
|
|
|
constexpr s16 EVFILT_HRTIMER = -15;
|
|
|
|
constexpr s16 EVFILT_UVD_TRAP = -16;
|
|
|
|
constexpr s16 EVFILT_VCE_TRAP = -17;
|
|
|
|
constexpr s16 EVFILT_SDMA_TRAP = -18;
|
|
|
|
constexpr s16 EVFILT_REG_EV = -19;
|
|
|
|
constexpr s16 EVFILT_GPU_EXCEPTION = -20;
|
|
|
|
constexpr s16 EVFILT_GPU_SYSTEM_EXCEPTION = -21;
|
|
|
|
constexpr s16 EVFILT_GPU_DBGGC_EV = -22;
|
|
|
|
constexpr s16 EVFILT_SYSCOUNT = 22;
|
|
|
|
|
|
|
|
class EqueueInternal;
|
|
|
|
struct EqueueEvent;
|
|
|
|
|
2023-09-05 13:01:47 +02:00
|
|
|
using TriggerFunc = void (*)(EqueueEvent* event, void* trigger_data);
|
|
|
|
using ResetFunc = void (*)(EqueueEvent* event);
|
2023-11-06 00:11:54 +01:00
|
|
|
using DeleteFunc = void (*)(EqueueInternal* eq, EqueueEvent* event);
|
2023-09-05 08:13:14 +02:00
|
|
|
|
2023-09-08 07:28:01 +02:00
|
|
|
struct SceKernelEvent {
|
2023-09-05 08:13:14 +02:00
|
|
|
u64 ident = 0; /* identifier for this event */
|
|
|
|
s16 filter = 0; /* filter for event */
|
|
|
|
u16 flags = 0;
|
|
|
|
u32 fflags = 0;
|
|
|
|
s64 data = 0;
|
|
|
|
void* udata = nullptr; /* opaque user data identifier */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Filter {
|
|
|
|
void* data = nullptr;
|
2023-09-05 13:01:47 +02:00
|
|
|
TriggerFunc trigger_event_func = nullptr;
|
2023-09-10 00:06:14 +02:00
|
|
|
ResetFunc reset_event_func = nullptr;
|
2023-09-05 13:01:47 +02:00
|
|
|
DeleteFunc delete_event_func = nullptr;
|
2023-09-05 08:13:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct EqueueEvent {
|
|
|
|
bool isTriggered = false;
|
2023-09-08 07:28:01 +02:00
|
|
|
SceKernelEvent event;
|
2023-09-05 08:13:14 +02:00
|
|
|
Filter filter;
|
|
|
|
};
|
|
|
|
|
2023-08-17 09:10:13 +02:00
|
|
|
class EqueueInternal {
|
2024-02-23 21:57:57 +01:00
|
|
|
public:
|
2023-08-17 09:10:13 +02:00
|
|
|
EqueueInternal() = default;
|
|
|
|
virtual ~EqueueInternal();
|
2024-02-23 21:57:57 +01:00
|
|
|
void setName(const std::string& m_name) {
|
|
|
|
this->m_name = m_name;
|
|
|
|
}
|
2023-09-05 13:28:52 +02:00
|
|
|
int addEvent(const EqueueEvent& event);
|
2023-09-10 00:06:14 +02:00
|
|
|
int waitForEvents(SceKernelEvent* ev, int num, u32 micros);
|
2023-09-11 12:14:13 +02:00
|
|
|
bool triggerEvent(u64 ident, s16 filter, void* trigger_data);
|
2023-09-10 00:06:14 +02:00
|
|
|
int getTriggeredEvents(SceKernelEvent* ev, int num);
|
2024-02-23 21:57:57 +01:00
|
|
|
|
|
|
|
private:
|
2023-08-17 09:10:13 +02:00
|
|
|
std::string m_name;
|
2024-02-23 21:57:57 +01:00
|
|
|
std::mutex m_mutex;
|
2023-09-05 13:28:52 +02:00
|
|
|
std::vector<EqueueEvent> m_events;
|
2023-10-22 16:10:25 +02:00
|
|
|
std::condition_variable m_cond;
|
2023-08-17 09:10:13 +02:00
|
|
|
};
|
2023-11-06 00:11:54 +01:00
|
|
|
|
2024-04-13 23:35:48 +02:00
|
|
|
} // namespace Libraries::Kernel
|