[Y2R] Add transfer event

This commit is contained in:
wheremyfoodat 2023-04-10 21:55:14 +03:00
parent 5a8416f87e
commit 82b986bbc0
3 changed files with 22 additions and 2 deletions

View file

@ -1,23 +1,30 @@
#pragma once
#include <optional>
#include "helpers.hpp"
#include "kernel_types.hpp"
#include "logger.hpp"
#include "memory.hpp"
// Circular dependencies go br
class Kernel;
class Y2RService {
Handle handle = KernelHandles::Y2R;
Memory& mem;
Kernel& kernel;
MAKE_LOG_FUNCTION(log, y2rLogger)
std::optional<Handle> transferEndEvent;
bool transferEndInterruptEnabled;
// Service commands
void driverInitialize(u32 messagePointer);
void pingProcess(u32 messagePointer);
void setTransferEndInterrupt(u32 messagePointer);
void getTransferEndEvent(u32 messagePointer);
public:
Y2RService(Memory& mem) : mem(mem) {}
Y2RService(Memory& mem, Kernel& kernel) : mem(mem), kernel(kernel) {}
void reset();
void handleSyncRequest(u32 messagePointer);
};

View file

@ -5,7 +5,7 @@
ServiceManager::ServiceManager(std::array<u32, 16>& regs, Memory& mem, GPU& gpu, u32& currentPID, Kernel& kernel)
: regs(regs), mem(mem), kernel(kernel), ac(mem), am(mem), boss(mem), apt(mem, kernel), cam(mem), cecd(mem), cfg(mem),
dsp(mem), hid(mem), frd(mem), fs(mem, kernel), gsp_gpu(mem, gpu, currentPID), gsp_lcd(mem), ldr(mem), mic(mem),
nim(mem), ndm(mem), ptm(mem), y2r(mem) {}
nim(mem), ndm(mem), ptm(mem), y2r(mem, kernel) {}
static constexpr int MAX_NOTIFICATION_COUNT = 16;

View file

@ -1,8 +1,10 @@
#include "services/y2r.hpp"
#include "kernel.hpp"
namespace Y2RCommands {
enum : u32 {
SetTransferEndInterrupt = 0x000D0040,
GetTransferEndEvent = 0x000F0000,
PingProcess = 0x002A0000,
DriverInitialize = 0x002B0000
};
@ -16,12 +18,14 @@ namespace Result {
void Y2RService::reset() {
transferEndInterruptEnabled = false;
transferEndEvent = std::nullopt;
}
void Y2RService::handleSyncRequest(u32 messagePointer) {
const u32 command = mem.read32(messagePointer);
switch (command) {
case Y2RCommands::DriverInitialize: driverInitialize(messagePointer); break;
case Y2RCommands::GetTransferEndEvent: getTransferEndEvent(messagePointer); break;
case Y2RCommands::PingProcess: pingProcess(messagePointer); break;
case Y2RCommands::SetTransferEndInterrupt: setTransferEndInterrupt(messagePointer); break;
default: Helpers::panic("Y2R service requested. Command: %08X\n", command);
@ -39,6 +43,15 @@ void Y2RService::driverInitialize(u32 messagePointer) {
mem.write32(messagePointer + 4, Result::Success);
}
void Y2RService::getTransferEndEvent(u32 messagePointer) {
log("Y2R::GetTransferEndEvent\n");
if (!transferEndEvent.has_value())
transferEndEvent = kernel.makeEvent(ResetType::OneShot);
mem.write32(messagePointer + 4, Result::Success);
mem.write32(messagePointer + 12, transferEndEvent.value());
}
void Y2RService::setTransferEndInterrupt(u32 messagePointer) {
const bool enable = mem.read32(messagePointer + 4) != 0;
log("Y2R::SetTransferEndInterrupt (enabled: %s)\n", enable ? "yes" : "no");