2022-04-23 08:59:50 +00:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2018-08-07 06:41:43 +00:00
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
#include "common/logging/log.h"
|
2023-02-19 19:42:12 +00:00
|
|
|
#include "core/hle/service/ipc_helpers.h"
|
2023-02-18 21:26:48 +00:00
|
|
|
#include "core/hle/service/server_manager.h"
|
2018-08-07 06:41:43 +00:00
|
|
|
#include "core/hle/service/service.h"
|
|
|
|
#include "core/hle/service/usb/usb.h"
|
|
|
|
|
|
|
|
namespace Service::USB {
|
|
|
|
|
|
|
|
class IDsInterface final : public ServiceFramework<IDsInterface> {
|
|
|
|
public:
|
2020-11-26 20:19:08 +00:00
|
|
|
explicit IDsInterface(Core::System& system_) : ServiceFramework{system_, "IDsInterface"} {
|
2018-08-07 06:41:43 +00:00
|
|
|
// clang-format off
|
|
|
|
static const FunctionInfo functions[] = {
|
2023-02-27 22:56:51 +00:00
|
|
|
{0, nullptr, "AddEndpoint"},
|
|
|
|
{1, nullptr, "GetSetupEvent"},
|
|
|
|
{2, nullptr, "GetSetupPacket"},
|
|
|
|
{3, nullptr, "Enable"},
|
|
|
|
{4, nullptr, "Disable"},
|
|
|
|
{5, nullptr, "CtrlIn"},
|
|
|
|
{6, nullptr, "CtrlOut"},
|
|
|
|
{7, nullptr, "GetCtrlInCompletionEvent"},
|
|
|
|
{8, nullptr, "GetCtrlInUrbReport"},
|
|
|
|
{9, nullptr, "GetCtrlOutCompletionEvent"},
|
|
|
|
{10, nullptr, "GetCtrlOutUrbReport"},
|
|
|
|
{11, nullptr, "CtrlStall"},
|
|
|
|
{12, nullptr, "AppendConfigurationData"},
|
2018-08-07 06:41:43 +00:00
|
|
|
};
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
RegisterHandlers(functions);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-02-27 22:56:51 +00:00
|
|
|
class IDsRootSession final : public ServiceFramework<IDsRootSession> {
|
2022-01-21 21:31:57 +00:00
|
|
|
public:
|
2023-02-27 22:56:51 +00:00
|
|
|
explicit IDsRootSession(Core::System& system_) : ServiceFramework{system_, "usb:ds"} {
|
2022-01-21 21:31:57 +00:00
|
|
|
// clang-format off
|
|
|
|
static const FunctionInfo functions[] = {
|
|
|
|
{0, nullptr, "OpenDsService"},
|
|
|
|
};
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
RegisterHandlers(functions);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-08-07 06:41:43 +00:00
|
|
|
class IClientEpSession final : public ServiceFramework<IClientEpSession> {
|
|
|
|
public:
|
2020-11-26 20:19:08 +00:00
|
|
|
explicit IClientEpSession(Core::System& system_)
|
|
|
|
: ServiceFramework{system_, "IClientEpSession"} {
|
2018-08-07 06:41:43 +00:00
|
|
|
// clang-format off
|
|
|
|
static const FunctionInfo functions[] = {
|
2021-04-08 20:42:53 +00:00
|
|
|
{0, nullptr, "ReOpen"},
|
2018-10-24 23:07:53 +00:00
|
|
|
{1, nullptr, "Close"},
|
2021-04-08 20:42:53 +00:00
|
|
|
{2, nullptr, "GetCompletionEvent"},
|
|
|
|
{3, nullptr, "PopulateRing"},
|
2018-08-07 06:41:43 +00:00
|
|
|
{4, nullptr, "PostBufferAsync"},
|
2018-10-24 23:07:53 +00:00
|
|
|
{5, nullptr, "GetXferReport"},
|
2018-12-02 20:49:37 +00:00
|
|
|
{6, nullptr, "PostBufferMultiAsync"},
|
2021-04-08 20:42:53 +00:00
|
|
|
{7, nullptr, "CreateSmmuSpace"},
|
|
|
|
{8, nullptr, "ShareReportRing"},
|
2018-08-07 06:41:43 +00:00
|
|
|
};
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
RegisterHandlers(functions);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class IClientIfSession final : public ServiceFramework<IClientIfSession> {
|
|
|
|
public:
|
2020-11-26 20:19:08 +00:00
|
|
|
explicit IClientIfSession(Core::System& system_)
|
|
|
|
: ServiceFramework{system_, "IClientIfSession"} {
|
2018-08-07 06:41:43 +00:00
|
|
|
// clang-format off
|
|
|
|
static const FunctionInfo functions[] = {
|
2021-04-08 20:42:53 +00:00
|
|
|
{0, nullptr, "GetStateChangeEvent"},
|
2018-10-24 23:07:53 +00:00
|
|
|
{1, nullptr, "SetInterface"},
|
|
|
|
{2, nullptr, "GetInterface"},
|
|
|
|
{3, nullptr, "GetAlternateInterface"},
|
|
|
|
{4, nullptr, "GetCurrentFrame"},
|
2018-08-07 06:41:43 +00:00
|
|
|
{5, nullptr, "CtrlXferAsync"},
|
2021-09-27 00:26:52 +00:00
|
|
|
{6, nullptr, "GetCtrlXferCompletionEvent"},
|
2018-08-07 06:41:43 +00:00
|
|
|
{7, nullptr, "GetCtrlXferReport"},
|
2018-10-24 23:07:53 +00:00
|
|
|
{8, nullptr, "ResetDevice"},
|
|
|
|
{9, nullptr, "OpenUsbEp"},
|
2018-08-07 06:41:43 +00:00
|
|
|
};
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
RegisterHandlers(functions);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-02-27 22:56:51 +00:00
|
|
|
class IClientRootSession final : public ServiceFramework<IClientRootSession> {
|
2018-08-07 06:41:43 +00:00
|
|
|
public:
|
2023-02-27 22:56:51 +00:00
|
|
|
explicit IClientRootSession(Core::System& system_) : ServiceFramework{system_, "usb:hs"} {
|
2018-08-07 06:41:43 +00:00
|
|
|
// clang-format off
|
|
|
|
static const FunctionInfo functions[] = {
|
|
|
|
{0, nullptr, "BindClientProcess"},
|
2018-10-24 23:07:53 +00:00
|
|
|
{1, nullptr, "QueryAllInterfaces"},
|
|
|
|
{2, nullptr, "QueryAvailableInterfaces"},
|
|
|
|
{3, nullptr, "QueryAcquiredInterfaces"},
|
|
|
|
{4, nullptr, "CreateInterfaceAvailableEvent"},
|
|
|
|
{5, nullptr, "DestroyInterfaceAvailableEvent"},
|
2018-08-07 06:41:43 +00:00
|
|
|
{6, nullptr, "GetInterfaceStateChangeEvent"},
|
2018-10-24 23:07:53 +00:00
|
|
|
{7, nullptr, "AcquireUsbIf"},
|
2023-02-27 22:56:51 +00:00
|
|
|
{8, nullptr, "SetTestMode"},
|
2018-08-07 06:41:43 +00:00
|
|
|
};
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
RegisterHandlers(functions);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class IPdSession final : public ServiceFramework<IPdSession> {
|
|
|
|
public:
|
2020-11-26 20:19:08 +00:00
|
|
|
explicit IPdSession(Core::System& system_) : ServiceFramework{system_, "IPdSession"} {
|
2018-08-07 06:41:43 +00:00
|
|
|
// clang-format off
|
|
|
|
static const FunctionInfo functions[] = {
|
|
|
|
{0, nullptr, "BindNoticeEvent"},
|
2018-10-30 19:23:47 +00:00
|
|
|
{1, nullptr, "UnbindNoticeEvent"},
|
2018-08-07 06:41:43 +00:00
|
|
|
{2, nullptr, "GetStatus"},
|
|
|
|
{3, nullptr, "GetNotice"},
|
2018-10-30 19:23:47 +00:00
|
|
|
{4, nullptr, "EnablePowerRequestNotice"},
|
|
|
|
{5, nullptr, "DisablePowerRequestNotice"},
|
2018-08-07 06:41:43 +00:00
|
|
|
{6, nullptr, "ReplyPowerRequest"},
|
|
|
|
};
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
RegisterHandlers(functions);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-02-27 22:56:51 +00:00
|
|
|
class IPdManager final : public ServiceFramework<IPdManager> {
|
2018-08-07 06:41:43 +00:00
|
|
|
public:
|
2023-02-27 22:56:51 +00:00
|
|
|
explicit IPdManager(Core::System& system_) : ServiceFramework{system_, "usb:pd"} {
|
2018-08-07 06:41:43 +00:00
|
|
|
// clang-format off
|
|
|
|
static const FunctionInfo functions[] = {
|
2023-02-27 22:56:51 +00:00
|
|
|
{0, &IPdManager::OpenSession, "OpenSession"},
|
2018-08-07 06:41:43 +00:00
|
|
|
};
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
RegisterHandlers(functions);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2023-02-27 22:56:51 +00:00
|
|
|
void OpenSession(HLERequestContext& ctx) {
|
2018-11-26 06:06:13 +00:00
|
|
|
LOG_DEBUG(Service_USB, "called");
|
|
|
|
|
2018-08-07 06:41:43 +00:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
2021-05-21 05:05:04 +00:00
|
|
|
rb.Push(ResultSuccess);
|
2020-11-26 20:19:08 +00:00
|
|
|
rb.PushIpcInterface<IPdSession>(system);
|
2018-08-07 06:41:43 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class IPdCradleSession final : public ServiceFramework<IPdCradleSession> {
|
|
|
|
public:
|
2020-11-26 20:19:08 +00:00
|
|
|
explicit IPdCradleSession(Core::System& system_)
|
|
|
|
: ServiceFramework{system_, "IPdCradleSession"} {
|
2018-08-07 06:41:43 +00:00
|
|
|
// clang-format off
|
|
|
|
static const FunctionInfo functions[] = {
|
2021-04-08 20:42:53 +00:00
|
|
|
{0, nullptr, "SetCradleVdo"},
|
|
|
|
{1, nullptr, "GetCradleVdo"},
|
|
|
|
{2, nullptr, "ResetCradleUsbHub"},
|
|
|
|
{3, nullptr, "GetHostPdcFirmwareType"},
|
|
|
|
{4, nullptr, "GetHostPdcFirmwareRevision"},
|
|
|
|
{5, nullptr, "GetHostPdcManufactureId"},
|
|
|
|
{6, nullptr, "GetHostPdcDeviceId"},
|
2021-09-27 00:26:52 +00:00
|
|
|
{7, nullptr, "EnableCradleRecovery"},
|
|
|
|
{8, nullptr, "DisableCradleRecovery"},
|
2018-08-07 06:41:43 +00:00
|
|
|
};
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
RegisterHandlers(functions);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-02-27 22:56:51 +00:00
|
|
|
class IPdCradleManager final : public ServiceFramework<IPdCradleManager> {
|
2018-08-07 06:41:43 +00:00
|
|
|
public:
|
2023-02-27 22:56:51 +00:00
|
|
|
explicit IPdCradleManager(Core::System& system_) : ServiceFramework{system_, "usb:pd:c"} {
|
2018-08-07 06:41:43 +00:00
|
|
|
// clang-format off
|
|
|
|
static const FunctionInfo functions[] = {
|
2023-02-27 22:56:51 +00:00
|
|
|
{0, &IPdCradleManager::OpenCradleSession, "OpenCradleSession"},
|
2018-08-07 06:41:43 +00:00
|
|
|
};
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
RegisterHandlers(functions);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2023-02-27 22:56:51 +00:00
|
|
|
void OpenCradleSession(HLERequestContext& ctx) {
|
|
|
|
LOG_DEBUG(Service_USB, "called");
|
|
|
|
|
2018-08-07 06:41:43 +00:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
2021-05-21 05:05:04 +00:00
|
|
|
rb.Push(ResultSuccess);
|
2020-11-26 20:19:08 +00:00
|
|
|
rb.PushIpcInterface<IPdCradleSession>(system);
|
2018-08-07 06:41:43 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-02-27 22:56:51 +00:00
|
|
|
class IPmMainService final : public ServiceFramework<IPmMainService> {
|
2018-08-07 06:41:43 +00:00
|
|
|
public:
|
2023-02-27 22:56:51 +00:00
|
|
|
explicit IPmMainService(Core::System& system_) : ServiceFramework{system_, "usb:pm"} {
|
2018-08-07 06:41:43 +00:00
|
|
|
// clang-format off
|
|
|
|
static const FunctionInfo functions[] = {
|
2021-04-08 20:42:53 +00:00
|
|
|
{0, nullptr, "GetPowerEvent"},
|
|
|
|
{1, nullptr, "GetPowerState"},
|
|
|
|
{2, nullptr, "GetDataEvent"},
|
|
|
|
{3, nullptr, "GetDataRole"},
|
|
|
|
{4, nullptr, "SetDiagData"},
|
|
|
|
{5, nullptr, "GetDiagData"},
|
2018-08-07 06:41:43 +00:00
|
|
|
};
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
RegisterHandlers(functions);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-02-18 21:26:48 +00:00
|
|
|
void LoopProcess(Core::System& system) {
|
|
|
|
auto server_manager = std::make_unique<ServerManager>(system);
|
|
|
|
|
2023-02-27 22:56:51 +00:00
|
|
|
server_manager->RegisterNamedService("usb:ds", std::make_shared<IDsRootSession>(system));
|
|
|
|
server_manager->RegisterNamedService("usb:hs", std::make_shared<IClientRootSession>(system));
|
|
|
|
server_manager->RegisterNamedService("usb:pd", std::make_shared<IPdManager>(system));
|
|
|
|
server_manager->RegisterNamedService("usb:pd:c", std::make_shared<IPdCradleManager>(system));
|
|
|
|
server_manager->RegisterNamedService("usb:pm", std::make_shared<IPmMainService>(system));
|
2023-02-18 21:26:48 +00:00
|
|
|
ServerManager::RunServer(std::move(server_manager));
|
2018-08-07 06:41:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Service::USB
|