From 0adeac26af77c7fb0605b08ab858a7c8262ffc88 Mon Sep 17 00:00:00 2001 From: Zephyron Date: Sat, 25 Jan 2025 14:23:22 +1000 Subject: [PATCH] service: mm: Implement proper parameter handling for MM service Add proper type definitions and parameter handling for the Memory Management (mm:u) service based on the Switch documentation: - Add Module enum for hardware components (CPU, GPU, EMC, etc) - Add Priority and Setting type definitions as u32 - Add EventClearMode enum for initialization - Implement proper parameter handling for all IPC calls - Add detailed logging with parameter values The Module enum now properly reflects the documented hardware components: CPU, GPU, EMC, System Bus, Memory Select, and NVIDIA modules (NVDEC, NVENC, NVJPG). This makes the implementation match the documented nn::mmnv::IRequest interface. Refs: switchbrew.org/wiki/Display_services#mm:u --- src/core/hle/service/mm/mm_u.cpp | 28 ++++++++++++++++++++++------ src/core/hle/service/mm/mm_u.h | 30 ++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/src/core/hle/service/mm/mm_u.cpp b/src/core/hle/service/mm/mm_u.cpp index 6f43b1968..64e3c3eea 100644 --- a/src/core/hle/service/mm/mm_u.cpp +++ b/src/core/hle/service/mm/mm_u.cpp @@ -1,4 +1,5 @@ // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project +// SPDX-FileCopyrightText: Copyright 2025 citron Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later #include "common/logging/log.h" @@ -30,14 +31,23 @@ public: private: void InitializeOld(HLERequestContext& ctx) { - LOG_WARNING(Service_MM, "(STUBBED) called"); + IPC::RequestParser rp{ctx}; + const auto module = rp.PopEnum(); + const auto priority = rp.Pop(); + const auto event_clear_mode = rp.PopEnum(); + + LOG_WARNING(Service_MM, "(STUBBED) called, module={:d}, priority={:d}, event_clear_mode={:d}", + static_cast(module), priority, static_cast(event_clear_mode)); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } void FinalizeOld(HLERequestContext& ctx) { - LOG_WARNING(Service_MM, "(STUBBED) called"); + IPC::RequestParser rp{ctx}; + const auto module = rp.PopEnum(); + + LOG_WARNING(Service_MM, "(STUBBED) called, module={:d}", static_cast(module)); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); @@ -45,9 +55,12 @@ private: void SetAndWaitOld(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; - min = rp.Pop(); - max = rp.Pop(); - LOG_DEBUG(Service_MM, "(STUBBED) called, min=0x{:X}, max=0x{:X}", min, max); + const auto module = rp.PopEnum(); + min = rp.Pop(); + max = rp.Pop(); + + LOG_DEBUG(Service_MM, "(STUBBED) called, module={:d}, min=0x{:X}, max=0x{:X}", + static_cast(module), min, max); current = min; IPC::ResponseBuilder rb{ctx, 2}; @@ -55,7 +68,10 @@ private: } void GetOld(HLERequestContext& ctx) { - LOG_DEBUG(Service_MM, "(STUBBED) called"); + IPC::RequestParser rp{ctx}; + const auto module = rp.PopEnum(); + + LOG_DEBUG(Service_MM, "(STUBBED) called, module={:d}", static_cast(module)); IPC::ResponseBuilder rb{ctx, 3}; rb.Push(ResultSuccess); diff --git a/src/core/hle/service/mm/mm_u.h b/src/core/hle/service/mm/mm_u.h index 43117c9b1..bae9eabf8 100644 --- a/src/core/hle/service/mm/mm_u.h +++ b/src/core/hle/service/mm/mm_u.h @@ -1,14 +1,44 @@ // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project +// SPDX-FileCopyrightText: Copyright 2025 citron Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later #pragma once +#include "common/common_types.h" + namespace Core { class System; } namespace Service::MM { +enum class Module : u32 { + Cpu = 0, + Gpu = 1, + Emc = 2, + SysBus = 3, + Mselect = 4, + Nvdec = 5, + Nvenc = 6, + Nvjpg = 7, + Test = 8, +}; + +using Priority = u32; +using Setting = u32; + +enum class EventClearMode : u32 { + // TODO: Add specific clear mode values when documented +}; + +// Consolidate settings into a struct for better organization +struct Settings { + Setting min{0}; + Setting max{0}; + Setting current{0}; + u32 id{1}; // Used by newer API versions +}; + void LoopProcess(Core::System& system); } // namespace Service::MM