From 49b17b42d0487786b6db08074c498a599ba28b41 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 | 29 +++++++++++++++++------------ src/core/hle/service/mm/mm_u.h | 19 ++++++++++++++++--- 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/src/core/hle/service/mm/mm_u.cpp b/src/core/hle/service/mm/mm_u.cpp index f8b406d827..3e2534b11d 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,22 +31,23 @@ public: private: void InitializeOld(HLERequestContext& ctx) { - LOG_WARNING(Service_MM, "(STUBBED) called."); - IPC::RequestParser rp{ctx}; - module = rp.PopEnum(); - priority = rp.Pop(); - event_clear_mode = rp.Pop(); + 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}; - module = rp.PopEnum(); + const auto module = rp.PopEnum(); + + LOG_WARNING(Service_MM, "(STUBBED) called, module={:d}", static_cast(module)); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); @@ -55,20 +57,23 @@ private: LOG_WARNING(Service_MM, "(STUBBED) called."); IPC::RequestParser rp{ctx}; - module = rp.PopEnum(); + 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}; rb.Push(ResultSuccess); } void GetOld(HLERequestContext& ctx) { - LOG_WARNING(Service_MM, "(STUBBED) called."); - IPC::RequestParser rp{ctx}; - module = rp.PopEnum(); + 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 350b166a08..f6849e7726 100644 --- a/src/core/hle/service/mm/mm_u.h +++ b/src/core/hle/service/mm/mm_u.h @@ -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 #pragma once @@ -20,11 +21,23 @@ enum class Module : u32 { NVDEC = 5, NVENC = 6, NVJPG = 7, - TEST = 8 + TEST = 8, }; -typedef u32 Priority; -typedef u32 Setting; +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);