From 425cf18bf7973a5b23607bf7827421f28911c584 Mon Sep 17 00:00:00 2001 From: Pierre Bourdon Date: Sun, 6 Aug 2017 22:17:51 +0200 Subject: [PATCH] USB: Add a stub HIDv5 implementation and use it for IOS59. --- Source/Core/Core/CMakeLists.txt | 1 + Source/Core/Core/Core.vcxproj | 2 + Source/Core/Core/Core.vcxproj.filters | 6 +++ Source/Core/Core/IOS/IOS.cpp | 6 ++- Source/Core/Core/IOS/USB/USB_HID/HIDv5.cpp | 63 ++++++++++++++++++++++ Source/Core/Core/IOS/USB/USB_HID/HIDv5.h | 37 +++++++++++++ 6 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 Source/Core/Core/IOS/USB/USB_HID/HIDv5.cpp create mode 100644 Source/Core/Core/IOS/USB/USB_HID/HIDv5.h diff --git a/Source/Core/Core/CMakeLists.txt b/Source/Core/Core/CMakeLists.txt index 04dbcf5848..9fd579888b 100644 --- a/Source/Core/Core/CMakeLists.txt +++ b/Source/Core/Core/CMakeLists.txt @@ -186,6 +186,7 @@ set(SRCS IOS/USB/OH0/OH0.cpp IOS/USB/OH0/OH0Device.cpp IOS/USB/USB_HID/HIDv4.cpp + IOS/USB/USB_HID/HIDv5.cpp IOS/USB/USB_VEN/VEN.cpp IOS/USB/USBV0.cpp IOS/USB/USBV4.cpp diff --git a/Source/Core/Core/Core.vcxproj b/Source/Core/Core/Core.vcxproj index 8968495f03..5e275711de 100644 --- a/Source/Core/Core/Core.vcxproj +++ b/Source/Core/Core/Core.vcxproj @@ -221,6 +221,7 @@ + @@ -468,6 +469,7 @@ + diff --git a/Source/Core/Core/Core.vcxproj.filters b/Source/Core/Core/Core.vcxproj.filters index 0f5eff13f5..167fcec007 100644 --- a/Source/Core/Core/Core.vcxproj.filters +++ b/Source/Core/Core/Core.vcxproj.filters @@ -826,6 +826,9 @@ IOS\USB + + IOS\USB + IOS\USB @@ -1469,6 +1472,9 @@ IOS\USB + + IOS\USB + IOS\USB diff --git a/Source/Core/Core/IOS/IOS.cpp b/Source/Core/Core/IOS/IOS.cpp index 06c8e4ecd1..3d372c7688 100644 --- a/Source/Core/Core/IOS/IOS.cpp +++ b/Source/Core/Core/IOS/IOS.cpp @@ -47,6 +47,7 @@ #include "Core/IOS/USB/OH0/OH0.h" #include "Core/IOS/USB/OH0/OH0Device.h" #include "Core/IOS/USB/USB_HID/HIDv4.h" +#include "Core/IOS/USB/USB_HID/HIDv5.h" #include "Core/IOS/USB/USB_KBD.h" #include "Core/IOS/USB/USB_VEN/VEN.h" #include "Core/IOS/WFS/WFSI.h" @@ -361,7 +362,10 @@ void Kernel::AddStaticDevices() AddDevice(std::make_unique(*this, "/dev/usb/kbd")); AddDevice(std::make_unique(*this, "/dev/sdio/slot0")); AddDevice(std::make_unique(*this, "/dev/sdio/slot1")); - AddDevice(std::make_unique(*this, "/dev/usb/hid")); + if (GetVersion() == 59) + AddDevice(std::make_unique(*this, "/dev/usb/hid")); + else + AddDevice(std::make_unique(*this, "/dev/usb/hid")); AddDevice(std::make_unique(*this, "/dev/usb/oh0")); AddDevice(std::make_unique(*this, "/dev/usb/oh1")); AddDevice(std::make_unique(*this, "/dev/usb/ven")); diff --git a/Source/Core/Core/IOS/USB/USB_HID/HIDv5.cpp b/Source/Core/Core/IOS/USB/USB_HID/HIDv5.cpp new file mode 100644 index 0000000000..d51d648c66 --- /dev/null +++ b/Source/Core/Core/IOS/USB/USB_HID/HIDv5.cpp @@ -0,0 +1,63 @@ +// Copyright 2017 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include "Core/IOS/USB/USB_HID/HIDv5.h" + +#include + +#include "Core/HW/Memmap.h" +#include "Core/IOS/Device.h" +#include "Core/IOS/USB/Common.h" +#include "Core/IOS/USB/USBV5.h" + +namespace IOS +{ +namespace HLE +{ +namespace Device +{ +USB_HIDv5::USB_HIDv5(Kernel& ios, const std::string& device_name) : USBHost(ios, device_name) +{ +} + +USB_HIDv5::~USB_HIDv5() +{ + StopThreads(); +} + +IPCCommandResult USB_HIDv5::IOCtl(const IOCtlRequest& request) +{ + request.Log(GetDeviceName(), LogTypes::IOS_USB); + switch (request.request) + { + case USB::IOCTL_USBV5_GETVERSION: + Memory::Write_U32(VERSION, request.buffer_out); + return GetDefaultReply(IPC_SUCCESS); + case USB::IOCTL_USBV5_SHUTDOWN: + if (m_hanging_request) + { + IOCtlRequest hanging_request{m_hanging_request}; + m_ios.EnqueueIPCReply(hanging_request, IPC_SUCCESS); + } + return GetDefaultReply(IPC_SUCCESS); + case USB::IOCTL_USBV5_GETDEVICECHANGE: + if (m_devicechange_replied) + { + m_hanging_request = request.address; + return GetNoReply(); + } + else + { + m_devicechange_replied = true; + return GetDefaultReply(IPC_SUCCESS); + } + default: + request.DumpUnknown(GetDeviceName(), LogTypes::IOS_USB); + return GetDefaultReply(IPC_SUCCESS); + } +} + +} // namespace Device +} // namespace HLE +} // namespace IOS diff --git a/Source/Core/Core/IOS/USB/USB_HID/HIDv5.h b/Source/Core/Core/IOS/USB/USB_HID/HIDv5.h new file mode 100644 index 0000000000..069651ff6e --- /dev/null +++ b/Source/Core/Core/IOS/USB/USB_HID/HIDv5.h @@ -0,0 +1,37 @@ +// Copyright 2017 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#pragma once + +#include + +#include "Common/CommonTypes.h" +#include "Core/IOS/IOS.h" +#include "Core/IOS/USB/Host.h" + +namespace IOS +{ +namespace HLE +{ +namespace Device +{ +// Stub implementation that only gets DQX to boot. +class USB_HIDv5 : public USBHost +{ +public: + USB_HIDv5(Kernel& ios, const std::string& device_name); + ~USB_HIDv5() override; + + IPCCommandResult IOCtl(const IOCtlRequest& request) override; + +private: + static constexpr u32 VERSION = 0x50001; + + u32 m_hanging_request = 0; + bool m_devicechange_replied = false; +}; + +} // namespace Device +} // namespace HLE +} // namespace IOS