diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/CMakeLists.txt | 4 | ||||
| -rw-r--r-- | src/core/hle/service/hid/active_vibration_device_list.cpp | 53 | ||||
| -rw-r--r-- | src/core/hle/service/hid/active_vibration_device_list.h | 39 | ||||
| -rw-r--r-- | src/core/hle/service/hid/applet_resource.cpp | 34 | ||||
| -rw-r--r-- | src/core/hle/service/hid/applet_resource.h | 36 | ||||
| -rw-r--r-- | src/core/hle/service/hid/hid_server.cpp | 64 | ||||
| -rw-r--r-- | src/hid_core/resource_manager.cpp | 26 | ||||
| -rw-r--r-- | src/hid_core/resource_manager.h | 13 |
8 files changed, 169 insertions, 100 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 75beacf70..93e403b26 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt | |||
| @@ -666,6 +666,10 @@ add_library(core STATIC | |||
| 666 | hle/service/glue/time/worker.h | 666 | hle/service/glue/time/worker.h |
| 667 | hle/service/grc/grc.cpp | 667 | hle/service/grc/grc.cpp |
| 668 | hle/service/grc/grc.h | 668 | hle/service/grc/grc.h |
| 669 | hle/service/hid/active_vibration_device_list.cpp | ||
| 670 | hle/service/hid/active_vibration_device_list.h | ||
| 671 | hle/service/hid/applet_resource.cpp | ||
| 672 | hle/service/hid/applet_resource.h | ||
| 669 | hle/service/hid/hid.cpp | 673 | hle/service/hid/hid.cpp |
| 670 | hle/service/hid/hid.h | 674 | hle/service/hid/hid.h |
| 671 | hle/service/hid/hid_debug_server.cpp | 675 | hle/service/hid/hid_debug_server.cpp |
diff --git a/src/core/hle/service/hid/active_vibration_device_list.cpp b/src/core/hle/service/hid/active_vibration_device_list.cpp new file mode 100644 index 000000000..c440f8382 --- /dev/null +++ b/src/core/hle/service/hid/active_vibration_device_list.cpp | |||
| @@ -0,0 +1,53 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-3.0-or-later | ||
| 3 | |||
| 4 | #include "common/logging/log.h" | ||
| 5 | #include "core/hle/service/cmif_serialization.h" | ||
| 6 | #include "core/hle/service/hid/active_vibration_device_list.h" | ||
| 7 | #include "hid_core/hid_result.h" | ||
| 8 | #include "hid_core/hid_util.h" | ||
| 9 | #include "hid_core/resource_manager.h" | ||
| 10 | #include "hid_core/resources/vibration/vibration_device.h" | ||
| 11 | |||
| 12 | namespace Service::HID { | ||
| 13 | |||
| 14 | IActiveVibrationDeviceList::IActiveVibrationDeviceList(Core::System& system_, | ||
| 15 | std::shared_ptr<ResourceManager> resource) | ||
| 16 | : ServiceFramework{system_, "IActiveVibrationDeviceList"}, resource_manager(resource) { | ||
| 17 | // clang-format off | ||
| 18 | static const FunctionInfo functions[] = { | ||
| 19 | {0, C<&IActiveVibrationDeviceList::ActivateVibrationDevice>, "ActivateVibrationDevice"}, | ||
| 20 | }; | ||
| 21 | // clang-format on | ||
| 22 | |||
| 23 | RegisterHandlers(functions); | ||
| 24 | } | ||
| 25 | |||
| 26 | IActiveVibrationDeviceList::~IActiveVibrationDeviceList() = default; | ||
| 27 | |||
| 28 | Result IActiveVibrationDeviceList::ActivateVibrationDevice( | ||
| 29 | Core::HID::VibrationDeviceHandle vibration_device_handle) { | ||
| 30 | LOG_DEBUG(Service_HID, "called, npad_type={}, npad_id={}, device_index={}", | ||
| 31 | vibration_device_handle.npad_type, vibration_device_handle.npad_id, | ||
| 32 | vibration_device_handle.device_index); | ||
| 33 | |||
| 34 | std::scoped_lock lock{mutex}; | ||
| 35 | |||
| 36 | R_TRY(IsVibrationHandleValid(vibration_device_handle)); | ||
| 37 | |||
| 38 | for (std::size_t i = 0; i < list_size; i++) { | ||
| 39 | if (vibration_device_handle.device_index == vibration_device_list[i].device_index && | ||
| 40 | vibration_device_handle.npad_id == vibration_device_list[i].npad_id && | ||
| 41 | vibration_device_handle.npad_type == vibration_device_list[i].npad_type) { | ||
| 42 | R_SUCCEED(); | ||
| 43 | } | ||
| 44 | } | ||
| 45 | |||
| 46 | R_UNLESS(list_size < MaxVibrationDevicesHandles, ResultVibrationDeviceIndexOutOfRange); | ||
| 47 | R_TRY(resource_manager->GetVibrationDevice(vibration_device_handle)->Activate()); | ||
| 48 | |||
| 49 | vibration_device_list[list_size++] = vibration_device_handle; | ||
| 50 | R_SUCCEED(); | ||
| 51 | } | ||
| 52 | |||
| 53 | } // namespace Service::HID | ||
diff --git a/src/core/hle/service/hid/active_vibration_device_list.h b/src/core/hle/service/hid/active_vibration_device_list.h new file mode 100644 index 000000000..beaa44d97 --- /dev/null +++ b/src/core/hle/service/hid/active_vibration_device_list.h | |||
| @@ -0,0 +1,39 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-3.0-or-later | ||
| 3 | |||
| 4 | #pragma once | ||
| 5 | |||
| 6 | #include <array> | ||
| 7 | #include <memory> | ||
| 8 | #include <mutex> | ||
| 9 | |||
| 10 | #include "core/hle/service/cmif_types.h" | ||
| 11 | #include "core/hle/service/service.h" | ||
| 12 | #include "hid_core/hid_types.h" | ||
| 13 | |||
| 14 | namespace Core { | ||
| 15 | class System; | ||
| 16 | } | ||
| 17 | |||
| 18 | namespace Service::HID { | ||
| 19 | class ResourceManager; | ||
| 20 | |||
| 21 | class IActiveVibrationDeviceList final : public ServiceFramework<IActiveVibrationDeviceList> { | ||
| 22 | public: | ||
| 23 | explicit IActiveVibrationDeviceList(Core::System& system_, | ||
| 24 | std::shared_ptr<ResourceManager> resource); | ||
| 25 | ~IActiveVibrationDeviceList() override; | ||
| 26 | |||
| 27 | private: | ||
| 28 | static constexpr std::size_t MaxVibrationDevicesHandles{0x100}; | ||
| 29 | |||
| 30 | Result ActivateVibrationDevice(Core::HID::VibrationDeviceHandle vibration_device_handle); | ||
| 31 | |||
| 32 | mutable std::mutex mutex; | ||
| 33 | std::size_t list_size{}; | ||
| 34 | std::array<Core::HID::VibrationDeviceHandle, MaxVibrationDevicesHandles> | ||
| 35 | vibration_device_list{}; | ||
| 36 | std::shared_ptr<ResourceManager> resource_manager; | ||
| 37 | }; | ||
| 38 | |||
| 39 | } // namespace Service::HID | ||
diff --git a/src/core/hle/service/hid/applet_resource.cpp b/src/core/hle/service/hid/applet_resource.cpp new file mode 100644 index 000000000..4814d7ad5 --- /dev/null +++ b/src/core/hle/service/hid/applet_resource.cpp | |||
| @@ -0,0 +1,34 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-3.0-or-later | ||
| 3 | |||
| 4 | #include "common/logging/log.h" | ||
| 5 | #include "core/hle/kernel/k_shared_memory.h" | ||
| 6 | #include "core/hle/service/cmif_serialization.h" | ||
| 7 | #include "core/hle/service/hid/applet_resource.h" | ||
| 8 | #include "hid_core/resource_manager.h" | ||
| 9 | |||
| 10 | namespace Service::HID { | ||
| 11 | |||
| 12 | IAppletResource::IAppletResource(Core::System& system_, std::shared_ptr<ResourceManager> resource, | ||
| 13 | u64 applet_resource_user_id) | ||
| 14 | : ServiceFramework{system_, "IAppletResource"}, aruid{applet_resource_user_id}, | ||
| 15 | resource_manager{resource} { | ||
| 16 | static const FunctionInfo functions[] = { | ||
| 17 | {0, C<&IAppletResource::GetSharedMemoryHandle>, "GetSharedMemoryHandle"}, | ||
| 18 | }; | ||
| 19 | RegisterHandlers(functions); | ||
| 20 | } | ||
| 21 | |||
| 22 | IAppletResource::~IAppletResource() { | ||
| 23 | resource_manager->FreeAppletResourceId(aruid); | ||
| 24 | } | ||
| 25 | |||
| 26 | Result IAppletResource::GetSharedMemoryHandle( | ||
| 27 | OutCopyHandle<Kernel::KSharedMemory> out_shared_memory_handle) { | ||
| 28 | const auto result = resource_manager->GetSharedMemoryHandle(out_shared_memory_handle, aruid); | ||
| 29 | |||
| 30 | LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}, result=0x{:X}", aruid, result.raw); | ||
| 31 | R_RETURN(result); | ||
| 32 | } | ||
| 33 | |||
| 34 | } // namespace Service::HID | ||
diff --git a/src/core/hle/service/hid/applet_resource.h b/src/core/hle/service/hid/applet_resource.h new file mode 100644 index 000000000..d1e7db9b1 --- /dev/null +++ b/src/core/hle/service/hid/applet_resource.h | |||
| @@ -0,0 +1,36 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-3.0-or-later | ||
| 3 | |||
| 4 | #pragma once | ||
| 5 | |||
| 6 | #include <memory> | ||
| 7 | |||
| 8 | #include "common/common_types.h" | ||
| 9 | #include "core/hle/service/cmif_types.h" | ||
| 10 | #include "core/hle/service/service.h" | ||
| 11 | |||
| 12 | namespace Core { | ||
| 13 | class System; | ||
| 14 | } | ||
| 15 | |||
| 16 | namespace Kernel { | ||
| 17 | class KSharedMemory; | ||
| 18 | } | ||
| 19 | |||
| 20 | namespace Service::HID { | ||
| 21 | class ResourceManager; | ||
| 22 | |||
| 23 | class IAppletResource final : public ServiceFramework<IAppletResource> { | ||
| 24 | public: | ||
| 25 | explicit IAppletResource(Core::System& system_, std::shared_ptr<ResourceManager> resource, | ||
| 26 | u64 applet_resource_user_id); | ||
| 27 | ~IAppletResource() override; | ||
| 28 | |||
| 29 | private: | ||
| 30 | Result GetSharedMemoryHandle(OutCopyHandle<Kernel::KSharedMemory> out_shared_memory_handle); | ||
| 31 | |||
| 32 | u64 aruid{}; | ||
| 33 | std::shared_ptr<ResourceManager> resource_manager; | ||
| 34 | }; | ||
| 35 | |||
| 36 | } // namespace Service::HID | ||
diff --git a/src/core/hle/service/hid/hid_server.cpp b/src/core/hle/service/hid/hid_server.cpp index 3603d8ccf..6942f6e82 100644 --- a/src/core/hle/service/hid/hid_server.cpp +++ b/src/core/hle/service/hid/hid_server.cpp | |||
| @@ -2,6 +2,7 @@ | |||
| 2 | // SPDX-License-Identifier: GPL-3.0-or-later | 2 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 3 | 3 | ||
| 4 | #include <array> | 4 | #include <array> |
| 5 | |||
| 5 | #include "common/common_types.h" | 6 | #include "common/common_types.h" |
| 6 | #include "common/logging/log.h" | 7 | #include "common/logging/log.h" |
| 7 | #include "common/settings.h" | 8 | #include "common/settings.h" |
| @@ -10,6 +11,8 @@ | |||
| 10 | #include "core/hle/kernel/kernel.h" | 11 | #include "core/hle/kernel/kernel.h" |
| 11 | #include "core/hle/service/cmif_serialization.h" | 12 | #include "core/hle/service/cmif_serialization.h" |
| 12 | #include "core/hle/service/hid/hid_server.h" | 13 | #include "core/hle/service/hid/hid_server.h" |
| 14 | #include "core/hle/service/hid/active_vibration_device_list.h" | ||
| 15 | #include "core/hle/service/hid/applet_resource.h" | ||
| 13 | #include "core/hle/service/ipc_helpers.h" | 16 | #include "core/hle/service/ipc_helpers.h" |
| 14 | #include "core/memory.h" | 17 | #include "core/memory.h" |
| 15 | #include "hid_core/hid_result.h" | 18 | #include "hid_core/hid_result.h" |
| @@ -36,67 +39,6 @@ | |||
| 36 | 39 | ||
| 37 | namespace Service::HID { | 40 | namespace Service::HID { |
| 38 | 41 | ||
| 39 | class IActiveVibrationDeviceList final : public ServiceFramework<IActiveVibrationDeviceList> { | ||
| 40 | public: | ||
| 41 | explicit IActiveVibrationDeviceList(Core::System& system_, | ||
| 42 | std::shared_ptr<ResourceManager> resource) | ||
| 43 | : ServiceFramework{system_, "IActiveVibrationDeviceList"}, resource_manager(resource) { | ||
| 44 | // clang-format off | ||
| 45 | static const FunctionInfo functions[] = { | ||
| 46 | {0, &IActiveVibrationDeviceList::ActivateVibrationDevice, "ActivateVibrationDevice"}, | ||
| 47 | }; | ||
| 48 | // clang-format on | ||
| 49 | |||
| 50 | RegisterHandlers(functions); | ||
| 51 | } | ||
| 52 | |||
| 53 | private: | ||
| 54 | void ActivateVibrationDevice(HLERequestContext& ctx) { | ||
| 55 | IPC::RequestParser rp{ctx}; | ||
| 56 | const auto vibration_device_handle{rp.PopRaw<Core::HID::VibrationDeviceHandle>()}; | ||
| 57 | |||
| 58 | LOG_DEBUG(Service_HID, "called, npad_type={}, npad_id={}, device_index={}", | ||
| 59 | vibration_device_handle.npad_type, vibration_device_handle.npad_id, | ||
| 60 | vibration_device_handle.device_index); | ||
| 61 | |||
| 62 | const auto result = ActivateVibrationDeviceImpl(vibration_device_handle); | ||
| 63 | |||
| 64 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 65 | rb.Push(result); | ||
| 66 | } | ||
| 67 | |||
| 68 | Result ActivateVibrationDeviceImpl(const Core::HID::VibrationDeviceHandle& handle) { | ||
| 69 | std::scoped_lock lock{mutex}; | ||
| 70 | |||
| 71 | const Result is_valid = IsVibrationHandleValid(handle); | ||
| 72 | if (is_valid.IsError()) { | ||
| 73 | return is_valid; | ||
| 74 | } | ||
| 75 | |||
| 76 | for (std::size_t i = 0; i < list_size; i++) { | ||
| 77 | if (handle.device_index == vibration_device_list[i].device_index && | ||
| 78 | handle.npad_id == vibration_device_list[i].npad_id && | ||
| 79 | handle.npad_type == vibration_device_list[i].npad_type) { | ||
| 80 | return ResultSuccess; | ||
| 81 | } | ||
| 82 | } | ||
| 83 | if (list_size == vibration_device_list.size()) { | ||
| 84 | return ResultVibrationDeviceIndexOutOfRange; | ||
| 85 | } | ||
| 86 | const Result result = resource_manager->GetVibrationDevice(handle)->Activate(); | ||
| 87 | if (result.IsError()) { | ||
| 88 | return result; | ||
| 89 | } | ||
| 90 | vibration_device_list[list_size++] = handle; | ||
| 91 | return ResultSuccess; | ||
| 92 | } | ||
| 93 | |||
| 94 | mutable std::mutex mutex; | ||
| 95 | std::size_t list_size{}; | ||
| 96 | std::array<Core::HID::VibrationDeviceHandle, 0x100> vibration_device_list{}; | ||
| 97 | std::shared_ptr<ResourceManager> resource_manager; | ||
| 98 | }; | ||
| 99 | |||
| 100 | IHidServer::IHidServer(Core::System& system_, std::shared_ptr<ResourceManager> resource, | 42 | IHidServer::IHidServer(Core::System& system_, std::shared_ptr<ResourceManager> resource, |
| 101 | std::shared_ptr<HidFirmwareSettings> settings) | 43 | std::shared_ptr<HidFirmwareSettings> settings) |
| 102 | : ServiceFramework{system_, "hid"}, resource_manager{resource}, firmware_settings{settings} { | 44 | : ServiceFramework{system_, "hid"}, resource_manager{resource}, firmware_settings{settings} { |
diff --git a/src/hid_core/resource_manager.cpp b/src/hid_core/resource_manager.cpp index 01261ba97..62fec03b1 100644 --- a/src/hid_core/resource_manager.cpp +++ b/src/hid_core/resource_manager.cpp | |||
| @@ -4,7 +4,6 @@ | |||
| 4 | #include "common/logging/log.h" | 4 | #include "common/logging/log.h" |
| 5 | #include "core/core.h" | 5 | #include "core/core.h" |
| 6 | #include "core/core_timing.h" | 6 | #include "core/core_timing.h" |
| 7 | #include "core/hle/kernel/k_shared_memory.h" | ||
| 8 | #include "core/hle/service/ipc_helpers.h" | 7 | #include "core/hle/service/ipc_helpers.h" |
| 9 | #include "core/hle/service/set/system_settings_server.h" | 8 | #include "core/hle/service/set/system_settings_server.h" |
| 10 | #include "core/hle/service/sm/sm.h" | 9 | #include "core/hle/service/sm/sm.h" |
| @@ -501,29 +500,4 @@ void ResourceManager::UpdateMotion(std::chrono::nanoseconds ns_late) { | |||
| 501 | console_six_axis->OnUpdate(core_timing); | 500 | console_six_axis->OnUpdate(core_timing); |
| 502 | } | 501 | } |
| 503 | 502 | ||
| 504 | IAppletResource::IAppletResource(Core::System& system_, std::shared_ptr<ResourceManager> resource, | ||
| 505 | u64 applet_resource_user_id) | ||
| 506 | : ServiceFramework{system_, "IAppletResource"}, aruid{applet_resource_user_id}, | ||
| 507 | resource_manager{resource} { | ||
| 508 | static const FunctionInfo functions[] = { | ||
| 509 | {0, &IAppletResource::GetSharedMemoryHandle, "GetSharedMemoryHandle"}, | ||
| 510 | }; | ||
| 511 | RegisterHandlers(functions); | ||
| 512 | } | ||
| 513 | |||
| 514 | IAppletResource::~IAppletResource() { | ||
| 515 | resource_manager->FreeAppletResourceId(aruid); | ||
| 516 | } | ||
| 517 | |||
| 518 | void IAppletResource::GetSharedMemoryHandle(HLERequestContext& ctx) { | ||
| 519 | Kernel::KSharedMemory* handle; | ||
| 520 | const auto result = resource_manager->GetSharedMemoryHandle(&handle, aruid); | ||
| 521 | |||
| 522 | LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}, result=0x{:X}", aruid, result.raw); | ||
| 523 | |||
| 524 | IPC::ResponseBuilder rb{ctx, 2, 1}; | ||
| 525 | rb.Push(result); | ||
| 526 | rb.PushCopyObjects(handle); | ||
| 527 | } | ||
| 528 | |||
| 529 | } // namespace Service::HID | 503 | } // namespace Service::HID |
diff --git a/src/hid_core/resource_manager.h b/src/hid_core/resource_manager.h index dc3ff01f8..5abd7e044 100644 --- a/src/hid_core/resource_manager.h +++ b/src/hid_core/resource_manager.h | |||
| @@ -174,17 +174,4 @@ private: | |||
| 174 | KernelHelpers::ServiceContext service_context; | 174 | KernelHelpers::ServiceContext service_context; |
| 175 | }; | 175 | }; |
| 176 | 176 | ||
| 177 | class IAppletResource final : public ServiceFramework<IAppletResource> { | ||
| 178 | public: | ||
| 179 | explicit IAppletResource(Core::System& system_, std::shared_ptr<ResourceManager> resource, | ||
| 180 | u64 applet_resource_user_id); | ||
| 181 | ~IAppletResource() override; | ||
| 182 | |||
| 183 | private: | ||
| 184 | void GetSharedMemoryHandle(HLERequestContext& ctx); | ||
| 185 | |||
| 186 | u64 aruid{}; | ||
| 187 | std::shared_ptr<ResourceManager> resource_manager; | ||
| 188 | }; | ||
| 189 | |||
| 190 | } // namespace Service::HID | 177 | } // namespace Service::HID |