From 12b616285238361dd7fa51cb8b4c281c1dcaaeb4 Mon Sep 17 00:00:00 2001 From: german77 Date: Tue, 6 Feb 2024 00:13:19 -0600 Subject: service: irs: Migrate service to new interface --- src/core/hle/service/hid/irs.cpp | 588 +++++++++++++-------------------------- src/core/hle/service/hid/irs.h | 84 ++++-- 2 files changed, 262 insertions(+), 410 deletions(-) (limited to 'src/core') diff --git a/src/core/hle/service/hid/irs.cpp b/src/core/hle/service/hid/irs.cpp index 18e544f2f..7d7368ff9 100644 --- a/src/core/hle/service/hid/irs.cpp +++ b/src/core/hle/service/hid/irs.cpp @@ -9,6 +9,7 @@ #include "core/hle/kernel/k_shared_memory.h" #include "core/hle/kernel/k_transfer_memory.h" #include "core/hle/kernel/kernel.h" +#include "core/hle/service/cmif_serialization.h" #include "core/hle/service/hid/irs.h" #include "core/hle/service/ipc_helpers.h" #include "core/memory.h" @@ -28,24 +29,24 @@ namespace Service::IRS { IRS::IRS(Core::System& system_) : ServiceFramework{system_, "irs"} { // clang-format off static const FunctionInfo functions[] = { - {302, &IRS::ActivateIrsensor, "ActivateIrsensor"}, - {303, &IRS::DeactivateIrsensor, "DeactivateIrsensor"}, - {304, &IRS::GetIrsensorSharedMemoryHandle, "GetIrsensorSharedMemoryHandle"}, - {305, &IRS::StopImageProcessor, "StopImageProcessor"}, - {306, &IRS::RunMomentProcessor, "RunMomentProcessor"}, - {307, &IRS::RunClusteringProcessor, "RunClusteringProcessor"}, - {308, &IRS::RunImageTransferProcessor, "RunImageTransferProcessor"}, - {309, &IRS::GetImageTransferProcessorState, "GetImageTransferProcessorState"}, - {310, &IRS::RunTeraPluginProcessor, "RunTeraPluginProcessor"}, - {311, &IRS::GetNpadIrCameraHandle, "GetNpadIrCameraHandle"}, - {312, &IRS::RunPointingProcessor, "RunPointingProcessor"}, - {313, &IRS::SuspendImageProcessor, "SuspendImageProcessor"}, - {314, &IRS::CheckFirmwareVersion, "CheckFirmwareVersion"}, - {315, &IRS::SetFunctionLevel, "SetFunctionLevel"}, - {316, &IRS::RunImageTransferExProcessor, "RunImageTransferExProcessor"}, - {317, &IRS::RunIrLedProcessor, "RunIrLedProcessor"}, - {318, &IRS::StopImageProcessorAsync, "StopImageProcessorAsync"}, - {319, &IRS::ActivateIrsensorWithFunctionLevel, "ActivateIrsensorWithFunctionLevel"}, + {302, C<&IRS::ActivateIrsensor>, "ActivateIrsensor"}, + {303, C<&IRS::DeactivateIrsensor>, "DeactivateIrsensor"}, + {304, C<&IRS::GetIrsensorSharedMemoryHandle>, "GetIrsensorSharedMemoryHandle"}, + {305, C<&IRS::StopImageProcessor>, "StopImageProcessor"}, + {306, C<&IRS::RunMomentProcessor>, "RunMomentProcessor"}, + {307, C<&IRS::RunClusteringProcessor>, "RunClusteringProcessor"}, + {308, C<&IRS::RunImageTransferProcessor>, "RunImageTransferProcessor"}, + {309, C<&IRS::GetImageTransferProcessorState>, "GetImageTransferProcessorState"}, + {310, C<&IRS::RunTeraPluginProcessor>, "RunTeraPluginProcessor"}, + {311, C<&IRS::GetNpadIrCameraHandle>, "GetNpadIrCameraHandle"}, + {312, C<&IRS::RunPointingProcessor>, "RunPointingProcessor"}, + {313, C<&IRS::SuspendImageProcessor>, "SuspendImageProcessor"}, + {314, C<&IRS::CheckFirmwareVersion>, "CheckFirmwareVersion"}, + {315, C<&IRS::SetFunctionLevel>, "SetFunctionLevel"}, + {316, C<&IRS::RunImageTransferExProcessor>, "RunImageTransferExProcessor"}, + {317, C<&IRS::RunIrLedProcessor>, "RunIrLedProcessor"}, + {318, C<&IRS::StopImageProcessorAsync>, "StopImageProcessorAsync"}, + {319, C<&IRS::ActivateIrsensorWithFunctionLevel>, "ActivateIrsensorWithFunctionLevel"}, }; // clang-format on @@ -57,489 +58,292 @@ IRS::IRS(Core::System& system_) : ServiceFramework{system_, "irs"} { } IRS::~IRS() = default; -void IRS::ActivateIrsensor(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto applet_resource_user_id{rp.Pop()}; - - LOG_WARNING(Service_IRS, "(STUBBED) called, applet_resource_user_id={}", - applet_resource_user_id); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); +Result IRS::ActivateIrsensor(ClientAppletResourceUserId aruid) { + LOG_WARNING(Service_IRS, "(STUBBED) called, applet_resource_user_id={}", aruid.pid); + R_SUCCEED(); } -void IRS::DeactivateIrsensor(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto applet_resource_user_id{rp.Pop()}; - - LOG_WARNING(Service_IRS, "(STUBBED) called, applet_resource_user_id={}", - applet_resource_user_id); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); +Result IRS::DeactivateIrsensor(ClientAppletResourceUserId aruid) { + LOG_WARNING(Service_IRS, "(STUBBED) called, applet_resource_user_id={}", aruid.pid); + R_SUCCEED(); } -void IRS::GetIrsensorSharedMemoryHandle(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto applet_resource_user_id{rp.Pop()}; - - LOG_DEBUG(Service_IRS, "called, applet_resource_user_id={}", applet_resource_user_id); +Result IRS::GetIrsensorSharedMemoryHandle(OutCopyHandle out_shared_memory, + ClientAppletResourceUserId aruid) { + LOG_DEBUG(Service_IRS, "called, applet_resource_user_id={}", aruid.pid); - IPC::ResponseBuilder rb{ctx, 2, 1}; - rb.Push(ResultSuccess); - rb.PushCopyObjects(&system.Kernel().GetIrsSharedMem()); + *out_shared_memory = &system.Kernel().GetIrsSharedMem(); + R_SUCCEED(); } -void IRS::StopImageProcessor(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - Core::IrSensor::IrCameraHandle camera_handle; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - }; - static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); - - const auto parameters{rp.PopRaw()}; - +Result IRS::StopImageProcessor(Core::IrSensor::IrCameraHandle camera_handle, + ClientAppletResourceUserId aruid) { LOG_WARNING(Service_IRS, "(STUBBED) called, npad_type={}, npad_id={}, applet_resource_user_id={}", - parameters.camera_handle.npad_type, parameters.camera_handle.npad_id, - parameters.applet_resource_user_id); - - auto result = IsIrCameraHandleValid(parameters.camera_handle); - if (result.IsSuccess()) { - // TODO: Stop Image processor - npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, - Common::Input::PollingMode::Active); - result = ResultSuccess; - } + camera_handle.npad_type, camera_handle.npad_id, aruid.pid); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); -} - -void IRS::RunMomentProcessor(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - Core::IrSensor::IrCameraHandle camera_handle; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - Core::IrSensor::PackedMomentProcessorConfig processor_config; - }; - static_assert(sizeof(Parameters) == 0x30, "Parameters has incorrect size."); + R_TRY(IsIrCameraHandleValid(camera_handle)); - const auto parameters{rp.PopRaw()}; + // TODO: Stop Image processor + npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, + Common::Input::PollingMode::Active); + R_SUCCEED(); +} +Result IRS::RunMomentProcessor( + Core::IrSensor::IrCameraHandle camera_handle, ClientAppletResourceUserId aruid, + const Core::IrSensor::PackedMomentProcessorConfig& processor_config) { LOG_WARNING(Service_IRS, "(STUBBED) called, npad_type={}, npad_id={}, applet_resource_user_id={}", - parameters.camera_handle.npad_type, parameters.camera_handle.npad_id, - parameters.applet_resource_user_id); - - const auto result = IsIrCameraHandleValid(parameters.camera_handle); - - if (result.IsSuccess()) { - auto& device = GetIrCameraSharedMemoryDeviceEntry(parameters.camera_handle); - MakeProcessorWithCoreContext(parameters.camera_handle, device); - auto& image_transfer_processor = GetProcessor(parameters.camera_handle); - image_transfer_processor.SetConfig(parameters.processor_config); - npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, - Common::Input::PollingMode::IR); - } + camera_handle.npad_type, camera_handle.npad_id, aruid.pid); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); -} + R_TRY(IsIrCameraHandleValid(camera_handle)); -void IRS::RunClusteringProcessor(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - Core::IrSensor::IrCameraHandle camera_handle; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - Core::IrSensor::PackedClusteringProcessorConfig processor_config; - }; - static_assert(sizeof(Parameters) == 0x38, "Parameters has incorrect size."); + auto& device = GetIrCameraSharedMemoryDeviceEntry(camera_handle); + MakeProcessorWithCoreContext(camera_handle, device); + auto& image_transfer_processor = GetProcessor(camera_handle); + image_transfer_processor.SetConfig(processor_config); + npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, + Common::Input::PollingMode::IR); - const auto parameters{rp.PopRaw()}; + R_SUCCEED(); +} +Result IRS::RunClusteringProcessor( + Core::IrSensor::IrCameraHandle camera_handle, ClientAppletResourceUserId aruid, + const Core::IrSensor::PackedClusteringProcessorConfig& processor_config) { LOG_WARNING(Service_IRS, "(STUBBED) called, npad_type={}, npad_id={}, applet_resource_user_id={}", - parameters.camera_handle.npad_type, parameters.camera_handle.npad_id, - parameters.applet_resource_user_id); - - auto result = IsIrCameraHandleValid(parameters.camera_handle); - - if (result.IsSuccess()) { - auto& device = GetIrCameraSharedMemoryDeviceEntry(parameters.camera_handle); - MakeProcessorWithCoreContext(parameters.camera_handle, device); - auto& image_transfer_processor = - GetProcessor(parameters.camera_handle); - image_transfer_processor.SetConfig(parameters.processor_config); - npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, - Common::Input::PollingMode::IR); - } + camera_handle.npad_type, camera_handle.npad_id, aruid.pid); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); -} + R_TRY(IsIrCameraHandleValid(camera_handle)); -void IRS::RunImageTransferProcessor(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - Core::IrSensor::IrCameraHandle camera_handle; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - Core::IrSensor::PackedImageTransferProcessorConfig processor_config; - u32 transfer_memory_size; - }; - static_assert(sizeof(Parameters) == 0x30, "Parameters has incorrect size."); + auto& device = GetIrCameraSharedMemoryDeviceEntry(camera_handle); + MakeProcessorWithCoreContext(camera_handle, device); + auto& image_transfer_processor = GetProcessor(camera_handle); + image_transfer_processor.SetConfig(processor_config); + npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, + Common::Input::PollingMode::IR); - const auto parameters{rp.PopRaw()}; - const auto t_mem_handle{ctx.GetCopyHandle(0)}; + R_SUCCEED(); +} - auto t_mem = ctx.GetObjectFromHandle(t_mem_handle); +Result IRS::RunImageTransferProcessor( + Core::IrSensor::IrCameraHandle camera_handle, ClientAppletResourceUserId aruid, + const Core::IrSensor::PackedImageTransferProcessorConfig& processor_config, + u64 transfer_memory_size, InCopyHandle t_mem) { - if (t_mem.IsNull()) { - LOG_ERROR(Service_IRS, "t_mem is a nullptr for handle=0x{:08X}", t_mem_handle); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultUnknown); - return; - } - - ASSERT_MSG(t_mem->GetSize() == parameters.transfer_memory_size, "t_mem has incorrect size"); + ASSERT_MSG(t_mem->GetSize() == transfer_memory_size, "t_mem has incorrect size"); LOG_INFO(Service_IRS, "called, npad_type={}, npad_id={}, transfer_memory_size={}, transfer_memory_size={}, " "applet_resource_user_id={}", - parameters.camera_handle.npad_type, parameters.camera_handle.npad_id, - parameters.transfer_memory_size, t_mem->GetSize(), parameters.applet_resource_user_id); - - const auto result = IsIrCameraHandleValid(parameters.camera_handle); - - if (result.IsSuccess()) { - auto& device = GetIrCameraSharedMemoryDeviceEntry(parameters.camera_handle); - MakeProcessorWithCoreContext(parameters.camera_handle, device); - auto& image_transfer_processor = - GetProcessor(parameters.camera_handle); - image_transfer_processor.SetConfig(parameters.processor_config); - image_transfer_processor.SetTransferMemoryAddress(t_mem->GetSourceAddress()); - npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, - Common::Input::PollingMode::IR); - } + camera_handle.npad_type, camera_handle.npad_id, transfer_memory_size, t_mem->GetSize(), + aruid.pid); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); -} + R_TRY(IsIrCameraHandleValid(camera_handle)); -void IRS::GetImageTransferProcessorState(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - Core::IrSensor::IrCameraHandle camera_handle; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - }; - static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); + auto& device = GetIrCameraSharedMemoryDeviceEntry(camera_handle); + MakeProcessorWithCoreContext(camera_handle, device); + auto& image_transfer_processor = GetProcessor(camera_handle); + image_transfer_processor.SetConfig(processor_config); + image_transfer_processor.SetTransferMemoryAddress(t_mem->GetSourceAddress()); + npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, + Common::Input::PollingMode::IR); - const auto parameters{rp.PopRaw()}; + R_SUCCEED(); +} +Result IRS::GetImageTransferProcessorState( + Out out_state, + Core::IrSensor::IrCameraHandle camera_handle, ClientAppletResourceUserId aruid, + OutBuffer out_buffer_data) { LOG_DEBUG(Service_IRS, "(STUBBED) called, npad_type={}, npad_id={}, applet_resource_user_id={}", - parameters.camera_handle.npad_type, parameters.camera_handle.npad_id, - parameters.applet_resource_user_id); - - const auto result = IsIrCameraHandleValid(parameters.camera_handle); - if (result.IsError()) { - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); - return; - } + camera_handle.npad_type, camera_handle.npad_id, aruid.pid); - const auto& device = GetIrCameraSharedMemoryDeviceEntry(parameters.camera_handle); + R_TRY(IsIrCameraHandleValid(camera_handle)); - if (device.mode != Core::IrSensor::IrSensorMode::ImageTransferProcessor) { - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(InvalidProcessorState); - return; - } + const auto& device = GetIrCameraSharedMemoryDeviceEntry(camera_handle); + + R_TRY(IsIrCameraHandleValid(camera_handle)); + R_UNLESS(device.mode == Core::IrSensor::IrSensorMode::ImageTransferProcessor, + InvalidProcessorState); - std::vector data{}; - const auto& image_transfer_processor = - GetProcessor(parameters.camera_handle); - const auto& state = image_transfer_processor.GetState(data); + *out_state = GetProcessor(camera_handle).GetState(out_buffer_data); - ctx.WriteBuffer(data); - IPC::ResponseBuilder rb{ctx, 6}; - rb.Push(ResultSuccess); - rb.PushRaw(state); + R_SUCCEED(); } -void IRS::RunTeraPluginProcessor(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - Core::IrSensor::IrCameraHandle camera_handle; - Core::IrSensor::PackedTeraPluginProcessorConfig processor_config; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - }; - static_assert(sizeof(Parameters) == 0x18, "Parameters has incorrect size."); +Result IRS::RunTeraPluginProcessor(Core::IrSensor::IrCameraHandle camera_handle, + Core::IrSensor::PackedTeraPluginProcessorConfig processor_config, + ClientAppletResourceUserId aruid) { + LOG_WARNING(Service_IRS, + "(STUBBED) called, npad_type={}, npad_id={}, mode={}, mcu_version={}.{}, " + "applet_resource_user_id={}", + camera_handle.npad_type, camera_handle.npad_id, processor_config.mode, + processor_config.required_mcu_version.major, + processor_config.required_mcu_version.minor, aruid.pid); - const auto parameters{rp.PopRaw()}; + R_TRY(IsIrCameraHandleValid(camera_handle)); - LOG_WARNING( - Service_IRS, - "(STUBBED) called, npad_type={}, npad_id={}, mode={}, mcu_version={}.{}, " - "applet_resource_user_id={}", - parameters.camera_handle.npad_type, parameters.camera_handle.npad_id, - parameters.processor_config.mode, parameters.processor_config.required_mcu_version.major, - parameters.processor_config.required_mcu_version.minor, parameters.applet_resource_user_id); - - const auto result = IsIrCameraHandleValid(parameters.camera_handle); - - if (result.IsSuccess()) { - auto& device = GetIrCameraSharedMemoryDeviceEntry(parameters.camera_handle); - MakeProcessor(parameters.camera_handle, device); - auto& image_transfer_processor = - GetProcessor(parameters.camera_handle); - image_transfer_processor.SetConfig(parameters.processor_config); - npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, - Common::Input::PollingMode::IR); - } + auto& device = GetIrCameraSharedMemoryDeviceEntry(camera_handle); + MakeProcessor(camera_handle, device); + auto& image_transfer_processor = GetProcessor(camera_handle); + image_transfer_processor.SetConfig(processor_config); + npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, + Common::Input::PollingMode::IR); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_SUCCEED(); } -void IRS::GetNpadIrCameraHandle(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto npad_id{rp.PopEnum()}; - - if (npad_id > Core::HID::NpadIdType::Player8 && npad_id != Core::HID::NpadIdType::Invalid && - npad_id != Core::HID::NpadIdType::Handheld) { - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(Service::HID::ResultInvalidNpadId); - return; - } +Result IRS::GetNpadIrCameraHandle(Out out_camera_handle, + Core::HID::NpadIdType npad_id) { + R_UNLESS(HID::IsNpadIdValid(npad_id), HID::ResultInvalidNpadId); - Core::IrSensor::IrCameraHandle camera_handle{ + *out_camera_handle = { .npad_id = static_cast(HID::NpadIdTypeToIndex(npad_id)), .npad_type = Core::HID::NpadStyleIndex::None, }; LOG_INFO(Service_IRS, "called, npad_id={}, camera_npad_id={}, camera_npad_type={}", npad_id, - camera_handle.npad_id, camera_handle.npad_type); + out_camera_handle->npad_id, out_camera_handle->npad_type); - IPC::ResponseBuilder rb{ctx, 3}; - rb.Push(ResultSuccess); - rb.PushRaw(camera_handle); + R_SUCCEED(); } -void IRS::RunPointingProcessor(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto camera_handle{rp.PopRaw()}; - const auto processor_config{rp.PopRaw()}; - const auto applet_resource_user_id{rp.Pop()}; - +Result IRS::RunPointingProcessor( + Core::IrSensor::IrCameraHandle camera_handle, + const Core::IrSensor::PackedPointingProcessorConfig& processor_config, + ClientAppletResourceUserId aruid) { LOG_WARNING( Service_IRS, "(STUBBED) called, npad_type={}, npad_id={}, mcu_version={}.{}, applet_resource_user_id={}", camera_handle.npad_type, camera_handle.npad_id, processor_config.required_mcu_version.major, - processor_config.required_mcu_version.minor, applet_resource_user_id); + processor_config.required_mcu_version.minor, aruid.pid); - auto result = IsIrCameraHandleValid(camera_handle); + R_TRY(IsIrCameraHandleValid(camera_handle)); - if (result.IsSuccess()) { - auto& device = GetIrCameraSharedMemoryDeviceEntry(camera_handle); - MakeProcessor(camera_handle, device); - auto& image_transfer_processor = GetProcessor(camera_handle); - image_transfer_processor.SetConfig(processor_config); - npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, - Common::Input::PollingMode::IR); - } + auto& device = GetIrCameraSharedMemoryDeviceEntry(camera_handle); + MakeProcessor(camera_handle, device); + auto& image_transfer_processor = GetProcessor(camera_handle); + image_transfer_processor.SetConfig(processor_config); + npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, + Common::Input::PollingMode::IR); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_SUCCEED(); } -void IRS::SuspendImageProcessor(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - Core::IrSensor::IrCameraHandle camera_handle; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - }; - static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); - - const auto parameters{rp.PopRaw()}; - +Result IRS::SuspendImageProcessor(Core::IrSensor::IrCameraHandle camera_handle, + ClientAppletResourceUserId aruid) { LOG_WARNING(Service_IRS, "(STUBBED) called, npad_type={}, npad_id={}, applet_resource_user_id={}", - parameters.camera_handle.npad_type, parameters.camera_handle.npad_id, - parameters.applet_resource_user_id); + camera_handle.npad_type, camera_handle.npad_id, aruid.pid); - auto result = IsIrCameraHandleValid(parameters.camera_handle); - if (result.IsSuccess()) { - // TODO: Suspend image processor - result = ResultSuccess; - } + R_TRY(IsIrCameraHandleValid(camera_handle)); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); -} + // TODO: Suspend image processor -void IRS::CheckFirmwareVersion(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto camera_handle{rp.PopRaw()}; - const auto mcu_version{rp.PopRaw()}; - const auto applet_resource_user_id{rp.Pop()}; + R_SUCCEED(); +} +Result IRS::CheckFirmwareVersion(Core::IrSensor::IrCameraHandle camera_handle, + Core::IrSensor::PackedMcuVersion mcu_version, + ClientAppletResourceUserId aruid) { LOG_WARNING( Service_IRS, "(STUBBED) called, npad_type={}, npad_id={}, applet_resource_user_id={}, mcu_version={}.{}", - camera_handle.npad_type, camera_handle.npad_id, applet_resource_user_id, mcu_version.major, + camera_handle.npad_type, camera_handle.npad_id, aruid.pid, mcu_version.major, mcu_version.minor); - auto result = IsIrCameraHandleValid(camera_handle); - if (result.IsSuccess()) { - // TODO: Check firmware version - result = ResultSuccess; - } + R_TRY(IsIrCameraHandleValid(camera_handle)); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); -} + // TODO: Check firmware version -void IRS::SetFunctionLevel(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto camera_handle{rp.PopRaw()}; - const auto function_level{rp.PopRaw()}; - const auto applet_resource_user_id{rp.Pop()}; + R_SUCCEED(); +} +Result IRS::SetFunctionLevel(Core::IrSensor::IrCameraHandle camera_handle, + Core::IrSensor::PackedFunctionLevel function_level, + ClientAppletResourceUserId aruid) { LOG_WARNING( Service_IRS, "(STUBBED) called, npad_type={}, npad_id={}, function_level={}, applet_resource_user_id={}", - camera_handle.npad_type, camera_handle.npad_id, function_level.function_level, - applet_resource_user_id); + camera_handle.npad_type, camera_handle.npad_id, function_level.function_level, aruid.pid); - auto result = IsIrCameraHandleValid(camera_handle); - if (result.IsSuccess()) { - // TODO: Set Function level - result = ResultSuccess; - } + R_TRY(IsIrCameraHandleValid(camera_handle)); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); -} + // TODO: Set Function level -void IRS::RunImageTransferExProcessor(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - Core::IrSensor::IrCameraHandle camera_handle; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - Core::IrSensor::PackedImageTransferProcessorExConfig processor_config; - u64 transfer_memory_size; - }; - static_assert(sizeof(Parameters) == 0x38, "Parameters has incorrect size."); + R_SUCCEED(); +} - const auto parameters{rp.PopRaw()}; - const auto t_mem_handle{ctx.GetCopyHandle(0)}; +Result IRS::RunImageTransferExProcessor( + Core::IrSensor::IrCameraHandle camera_handle, ClientAppletResourceUserId aruid, + const Core::IrSensor::PackedImageTransferProcessorExConfig& processor_config, + u64 transfer_memory_size, InCopyHandle t_mem) { - auto t_mem = ctx.GetObjectFromHandle(t_mem_handle); + ASSERT_MSG(t_mem->GetSize() == transfer_memory_size, "t_mem has incorrect size"); LOG_INFO(Service_IRS, "called, npad_type={}, npad_id={}, transfer_memory_size={}, " "applet_resource_user_id={}", - parameters.camera_handle.npad_type, parameters.camera_handle.npad_id, - parameters.transfer_memory_size, parameters.applet_resource_user_id); - - auto result = IsIrCameraHandleValid(parameters.camera_handle); - - if (result.IsSuccess()) { - auto& device = GetIrCameraSharedMemoryDeviceEntry(parameters.camera_handle); - MakeProcessorWithCoreContext(parameters.camera_handle, device); - auto& image_transfer_processor = - GetProcessor(parameters.camera_handle); - image_transfer_processor.SetConfig(parameters.processor_config); - image_transfer_processor.SetTransferMemoryAddress(t_mem->GetSourceAddress()); - npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, - Common::Input::PollingMode::IR); - } + camera_handle.npad_type, camera_handle.npad_id, transfer_memory_size, aruid.pid); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); -} + R_TRY(IsIrCameraHandleValid(camera_handle)); + + auto& device = GetIrCameraSharedMemoryDeviceEntry(camera_handle); + MakeProcessorWithCoreContext(camera_handle, device); + auto& image_transfer_processor = GetProcessor(camera_handle); + image_transfer_processor.SetConfig(processor_config); + image_transfer_processor.SetTransferMemoryAddress(t_mem->GetSourceAddress()); + npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, + Common::Input::PollingMode::IR); -void IRS::RunIrLedProcessor(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto camera_handle{rp.PopRaw()}; - const auto processor_config{rp.PopRaw()}; - const auto applet_resource_user_id{rp.Pop()}; + R_SUCCEED(); +} +Result IRS::RunIrLedProcessor(Core::IrSensor::IrCameraHandle camera_handle, + Core::IrSensor::PackedIrLedProcessorConfig processor_config, + ClientAppletResourceUserId aruid) { LOG_WARNING(Service_IRS, "(STUBBED) called, npad_type={}, npad_id={}, light_target={}, mcu_version={}.{} " "applet_resource_user_id={}", camera_handle.npad_type, camera_handle.npad_id, processor_config.light_target, processor_config.required_mcu_version.major, - processor_config.required_mcu_version.minor, applet_resource_user_id); + processor_config.required_mcu_version.minor, aruid.pid); - auto result = IsIrCameraHandleValid(camera_handle); + R_TRY(IsIrCameraHandleValid(camera_handle)); - if (result.IsSuccess()) { - auto& device = GetIrCameraSharedMemoryDeviceEntry(camera_handle); - MakeProcessor(camera_handle, device); - auto& image_transfer_processor = GetProcessor(camera_handle); - image_transfer_processor.SetConfig(processor_config); - npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, - Common::Input::PollingMode::IR); - } + auto& device = GetIrCameraSharedMemoryDeviceEntry(camera_handle); + MakeProcessor(camera_handle, device); + auto& image_transfer_processor = GetProcessor(camera_handle); + image_transfer_processor.SetConfig(processor_config); + npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, + Common::Input::PollingMode::IR); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); + R_SUCCEED(); } -void IRS::StopImageProcessorAsync(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - Core::IrSensor::IrCameraHandle camera_handle; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - }; - static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); - - const auto parameters{rp.PopRaw()}; - +Result IRS::StopImageProcessorAsync(Core::IrSensor::IrCameraHandle camera_handle, + ClientAppletResourceUserId aruid) { LOG_WARNING(Service_IRS, "(STUBBED) called, npad_type={}, npad_id={}, applet_resource_user_id={}", - parameters.camera_handle.npad_type, parameters.camera_handle.npad_id, - parameters.applet_resource_user_id); - - auto result = IsIrCameraHandleValid(parameters.camera_handle); - if (result.IsSuccess()) { - // TODO: Stop image processor async - npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, - Common::Input::PollingMode::Active); - result = ResultSuccess; - } + camera_handle.npad_type, camera_handle.npad_id, aruid.pid); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); -} + R_TRY(IsIrCameraHandleValid(camera_handle)); -void IRS::ActivateIrsensorWithFunctionLevel(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - struct Parameters { - Core::IrSensor::PackedFunctionLevel function_level; - INSERT_PADDING_WORDS_NOINIT(1); - u64 applet_resource_user_id; - }; - static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); + // TODO: Stop image processor async + npad_device->SetPollingMode(Core::HID::EmulatedDeviceIndex::RightIndex, + Common::Input::PollingMode::Active); - const auto parameters{rp.PopRaw()}; + R_SUCCEED(); +} +Result IRS::ActivateIrsensorWithFunctionLevel(Core::IrSensor::PackedFunctionLevel function_level, + ClientAppletResourceUserId aruid) { LOG_WARNING(Service_IRS, "(STUBBED) called, function_level={}, applet_resource_user_id={}", - parameters.function_level.function_level, parameters.applet_resource_user_id); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + function_level.function_level, aruid.pid); + R_SUCCEED(); } Result IRS::IsIrCameraHandleValid(const Core::IrSensor::IrCameraHandle& camera_handle) const { diff --git a/src/core/hle/service/hid/irs.h b/src/core/hle/service/hid/irs.h index 06b7279ee..58dfee6c3 100644 --- a/src/core/hle/service/hid/irs.h +++ b/src/core/hle/service/hid/irs.h @@ -4,6 +4,7 @@ #pragma once #include "core/core.h" +#include "core/hle/service/cmif_types.h" #include "core/hle/service/service.h" #include "hid_core/hid_types.h" #include "hid_core/irsensor/irs_types.h" @@ -35,26 +36,73 @@ private: }; static_assert(sizeof(StatusManager) == 0x8000, "StatusManager is an invalid size"); - void ActivateIrsensor(HLERequestContext& ctx); - void DeactivateIrsensor(HLERequestContext& ctx); - void GetIrsensorSharedMemoryHandle(HLERequestContext& ctx); - void StopImageProcessor(HLERequestContext& ctx); - void RunMomentProcessor(HLERequestContext& ctx); - void RunClusteringProcessor(HLERequestContext& ctx); - void RunImageTransferProcessor(HLERequestContext& ctx); - void GetImageTransferProcessorState(HLERequestContext& ctx); - void RunTeraPluginProcessor(HLERequestContext& ctx); - void GetNpadIrCameraHandle(HLERequestContext& ctx); - void RunPointingProcessor(HLERequestContext& ctx); - void SuspendImageProcessor(HLERequestContext& ctx); - void CheckFirmwareVersion(HLERequestContext& ctx); - void SetFunctionLevel(HLERequestContext& ctx); - void RunImageTransferExProcessor(HLERequestContext& ctx); - void RunIrLedProcessor(HLERequestContext& ctx); - void StopImageProcessorAsync(HLERequestContext& ctx); - void ActivateIrsensorWithFunctionLevel(HLERequestContext& ctx); + Result ActivateIrsensor(ClientAppletResourceUserId aruid); + + Result DeactivateIrsensor(ClientAppletResourceUserId aruid); + + Result GetIrsensorSharedMemoryHandle(OutCopyHandle out_shared_memory, + ClientAppletResourceUserId aruid); + Result StopImageProcessor(Core::IrSensor::IrCameraHandle camera_handle, + ClientAppletResourceUserId aruid); + + Result RunMomentProcessor(Core::IrSensor::IrCameraHandle camera_handle, + ClientAppletResourceUserId aruid, + const Core::IrSensor::PackedMomentProcessorConfig& processor_config); + + Result RunClusteringProcessor( + Core::IrSensor::IrCameraHandle camera_handle, ClientAppletResourceUserId aruid, + const Core::IrSensor::PackedClusteringProcessorConfig& processor_config); + + Result RunImageTransferProcessor( + Core::IrSensor::IrCameraHandle camera_handle, ClientAppletResourceUserId aruid, + const Core::IrSensor::PackedImageTransferProcessorConfig& processor_config, + u64 transfer_memory_size, InCopyHandle t_mem); + + Result GetImageTransferProcessorState( + Out out_state, + Core::IrSensor::IrCameraHandle camera_handle, ClientAppletResourceUserId aruid, + OutBuffer out_buffer_data); + + Result RunTeraPluginProcessor(Core::IrSensor::IrCameraHandle camera_handle, + Core::IrSensor::PackedTeraPluginProcessorConfig processor_config, + ClientAppletResourceUserId aruid); + + Result GetNpadIrCameraHandle(Out out_camera_handle, + Core::HID::NpadIdType npad_id); + + Result RunPointingProcessor( + Core::IrSensor::IrCameraHandle camera_handle, + const Core::IrSensor::PackedPointingProcessorConfig& processor_config, + ClientAppletResourceUserId aruid); + + Result SuspendImageProcessor(Core::IrSensor::IrCameraHandle camera_handle, + ClientAppletResourceUserId aruid); + + Result CheckFirmwareVersion(Core::IrSensor::IrCameraHandle camera_handle, + Core::IrSensor::PackedMcuVersion mcu_version, + ClientAppletResourceUserId aruid); + + Result SetFunctionLevel(Core::IrSensor::IrCameraHandle camera_handle, + Core::IrSensor::PackedFunctionLevel function_level, + ClientAppletResourceUserId aruid); + + Result RunImageTransferExProcessor( + Core::IrSensor::IrCameraHandle camera_handle, ClientAppletResourceUserId aruid, + const Core::IrSensor::PackedImageTransferProcessorExConfig& processor_config, + u64 transfer_memory_size, InCopyHandle t_mem); + + Result RunIrLedProcessor(Core::IrSensor::IrCameraHandle camera_handle, + Core::IrSensor::PackedIrLedProcessorConfig processor_config, + ClientAppletResourceUserId aruid); + + Result StopImageProcessorAsync(Core::IrSensor::IrCameraHandle camera_handle, + ClientAppletResourceUserId aruid); + + Result ActivateIrsensorWithFunctionLevel(Core::IrSensor::PackedFunctionLevel function_level, + ClientAppletResourceUserId aruid); Result IsIrCameraHandleValid(const Core::IrSensor::IrCameraHandle& camera_handle) const; + Core::IrSensor::DeviceFormat& GetIrCameraSharedMemoryDeviceEntry( const Core::IrSensor::IrCameraHandle& camera_handle); -- cgit v1.2.3