35 changes: 22 additions & 13 deletions Source/Core/Core/IOS/USB/USB_HID/HIDv4.cpp
Expand Up @@ -22,7 +22,8 @@

namespace IOS::HLE
{
USB_HIDv4::USB_HIDv4(Kernel& ios, const std::string& device_name) : USBHost(ios, device_name)
USB_HIDv4::USB_HIDv4(EmulationKernel& ios, const std::string& device_name)
: USBHost(ios, device_name)
{
}

Expand All @@ -33,7 +34,7 @@ USB_HIDv4::~USB_HIDv4()

std::optional<IPCReply> USB_HIDv4::IOCtl(const IOCtlRequest& request)
{
auto& system = Core::System::GetInstance();
auto& system = GetSystem();
auto& memory = system.GetMemory();

request.Log(GetDeviceName(), Common::Log::LogType::IOS_USB);
Expand Down Expand Up @@ -64,7 +65,7 @@ std::optional<IPCReply> USB_HIDv4::IOCtl(const IOCtlRequest& request)
[&, this]() { return SubmitTransfer(*device, request); });
}
default:
request.DumpUnknown(GetDeviceName(), Common::Log::LogType::IOS_USB);
request.DumpUnknown(GetSystem(), GetDeviceName(), Common::Log::LogType::IOS_USB);
return IPCReply(IPC_SUCCESS);
}
}
Expand All @@ -74,7 +75,7 @@ IPCReply USB_HIDv4::CancelInterrupt(const IOCtlRequest& request)
if (request.buffer_in == 0 || request.buffer_in_size != 8)
return IPCReply(IPC_EINVAL);

auto& system = Core::System::GetInstance();
auto& system = GetSystem();
auto& memory = system.GetMemory();

auto device = GetDeviceByIOSID(memory.Read_U32(request.buffer_in));
Expand All @@ -90,7 +91,7 @@ std::optional<IPCReply> USB_HIDv4::GetDeviceChange(const IOCtlRequest& request)
if (request.buffer_out == 0 || request.buffer_out_size != 0x600)
return IPCReply(IPC_EINVAL);

m_devicechange_hook_request = std::make_unique<IOCtlRequest>(request.address);
m_devicechange_hook_request = std::make_unique<IOCtlRequest>(GetSystem(), request.address);
// On the first call, the reply is sent immediately (instead of on device insertion/removal)
if (m_devicechange_first_call)
{
Expand All @@ -105,10 +106,10 @@ IPCReply USB_HIDv4::Shutdown(const IOCtlRequest& request)
std::lock_guard lk{m_devicechange_hook_address_mutex};
if (m_devicechange_hook_request != nullptr)
{
auto& system = Core::System::GetInstance();
auto& system = GetSystem();
auto& memory = system.GetMemory();
memory.Write_U32(0xffffffff, m_devicechange_hook_request->buffer_out);
m_ios.EnqueueIPCReply(*m_devicechange_hook_request, -1);
GetEmulationKernel().EnqueueIPCReply(*m_devicechange_hook_request, -1);
m_devicechange_hook_request.reset();
}
return IPCReply(IPC_SUCCESS);
Expand All @@ -119,12 +120,15 @@ s32 USB_HIDv4::SubmitTransfer(USB::Device& device, const IOCtlRequest& request)
switch (request.request)
{
case USB::IOCTL_USBV4_CTRLMSG:
return device.SubmitTransfer(std::make_unique<USB::V4CtrlMessage>(m_ios, request));
return device.SubmitTransfer(
std::make_unique<USB::V4CtrlMessage>(GetEmulationKernel(), request));
case USB::IOCTL_USBV4_GET_US_STRING:
return device.SubmitTransfer(std::make_unique<USB::V4GetUSStringMessage>(m_ios, request));
return device.SubmitTransfer(
std::make_unique<USB::V4GetUSStringMessage>(GetEmulationKernel(), request));
case USB::IOCTL_USBV4_INTRMSG_IN:
case USB::IOCTL_USBV4_INTRMSG_OUT:
return device.SubmitTransfer(std::make_unique<USB::V4IntrMessage>(m_ios, request));
return device.SubmitTransfer(
std::make_unique<USB::V4IntrMessage>(GetEmulationKernel(), request));
default:
return IPC_EINVAL;
}
Expand All @@ -136,9 +140,13 @@ void USB_HIDv4::DoState(PointerWrap& p)
u32 hook_address = m_devicechange_hook_request ? m_devicechange_hook_request->address : 0;
p.Do(hook_address);
if (hook_address != 0)
m_devicechange_hook_request = std::make_unique<IOCtlRequest>(hook_address);
{
m_devicechange_hook_request = std::make_unique<IOCtlRequest>(GetSystem(), hook_address);
}
else
{
m_devicechange_hook_request.reset();
}

p.Do(m_ios_ids);
p.Do(m_device_ids);
Expand Down Expand Up @@ -191,7 +199,7 @@ void USB_HIDv4::TriggerDeviceChangeReply()
if (!m_devicechange_hook_request)
return;

auto& system = Core::System::GetInstance();
auto& system = GetSystem();
auto& memory = system.GetMemory();

{
Expand All @@ -213,7 +221,8 @@ void USB_HIDv4::TriggerDeviceChangeReply()
memory.Write_U32(0xffffffff, dest + offset);
}

m_ios.EnqueueIPCReply(*m_devicechange_hook_request, IPC_SUCCESS, 0, CoreTiming::FromThread::ANY);
GetEmulationKernel().EnqueueIPCReply(*m_devicechange_hook_request, IPC_SUCCESS, 0,
CoreTiming::FromThread::ANY);
m_devicechange_hook_request.reset();
}

Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/IOS/USB/USB_HID/HIDv4.h
Expand Up @@ -20,7 +20,7 @@ namespace IOS::HLE
class USB_HIDv4 final : public USBHost
{
public:
USB_HIDv4(Kernel& ios, const std::string& device_name);
USB_HIDv4(EmulationKernel& ios, const std::string& device_name);
~USB_HIDv4() override;

std::optional<IPCReply> IOCtl(const IOCtlRequest& request) override;
Expand Down
17 changes: 9 additions & 8 deletions Source/Core/Core/IOS/USB/USB_HID/HIDv5.cpp
Expand Up @@ -25,7 +25,7 @@ USB_HIDv5::~USB_HIDv5()

std::optional<IPCReply> USB_HIDv5::IOCtl(const IOCtlRequest& request)
{
auto& system = Core::System::GetInstance();
auto& system = GetSystem();
auto& memory = system.GetMemory();

request.Log(GetDeviceName(), Common::Log::LogType::IOS_USB);
Expand All @@ -50,15 +50,14 @@ std::optional<IPCReply> USB_HIDv5::IOCtl(const IOCtlRequest& request)
return HandleDeviceIOCtl(request,
[&](USBV5Device& device) { return CancelEndpoint(device, request); });
default:
request.DumpUnknown(GetDeviceName(), Common::Log::LogType::IOS_USB,
request.DumpUnknown(GetSystem(), GetDeviceName(), Common::Log::LogType::IOS_USB,
Common::Log::LogLevel::LERROR);
return IPCReply(IPC_SUCCESS);
}
}

std::optional<IPCReply> USB_HIDv5::IOCtlV(const IOCtlVRequest& request)
{
request.DumpUnknown(GetDeviceName(), Common::Log::LogType::IOS_USB);
switch (request.request)
{
// TODO: HIDv5 seems to be able to queue transfers depending on the transfer length (unlike VEN).
Expand All @@ -82,6 +81,7 @@ std::optional<IPCReply> USB_HIDv5::IOCtlV(const IOCtlVRequest& request)
[&, this]() { return SubmitTransfer(*device, *host_device, request); });
}
default:
request.DumpUnknown(GetSystem(), GetDeviceName(), Common::Log::LogType::IOS_USB);
return IPCReply(IPC_EINVAL);
}
}
Expand All @@ -92,12 +92,13 @@ s32 USB_HIDv5::SubmitTransfer(USBV5Device& device, USB::Device& host_device,
switch (ioctlv.request)
{
case USB::IOCTLV_USBV5_CTRLMSG:
return host_device.SubmitTransfer(std::make_unique<USB::V5CtrlMessage>(m_ios, ioctlv));
return host_device.SubmitTransfer(
std::make_unique<USB::V5CtrlMessage>(GetEmulationKernel(), ioctlv));
case USB::IOCTLV_USBV5_INTRMSG:
{
auto message = std::make_unique<USB::V5IntrMessage>(m_ios, ioctlv);
auto message = std::make_unique<USB::V5IntrMessage>(GetEmulationKernel(), ioctlv);

auto& system = Core::System::GetInstance();
auto& system = GetSystem();
auto& memory = system.GetMemory();

// Unlike VEN, the endpoint is determined by the value at 8-12.
Expand All @@ -118,7 +119,7 @@ s32 USB_HIDv5::SubmitTransfer(USBV5Device& device, USB::Device& host_device,

IPCReply USB_HIDv5::CancelEndpoint(USBV5Device& device, const IOCtlRequest& request)
{
auto& system = Core::System::GetInstance();
auto& system = GetSystem();
auto& memory = system.GetMemory();

const u8 value = memory.Read_U8(request.buffer_in + 8);
Expand Down Expand Up @@ -148,7 +149,7 @@ IPCReply USB_HIDv5::GetDeviceInfo(USBV5Device& device, const IOCtlRequest& reque
if (request.buffer_out == 0 || request.buffer_out_size != 0x60)
return IPCReply(IPC_EINVAL);

auto& system = Core::System::GetInstance();
auto& system = GetSystem();
auto& memory = system.GetMemory();

const std::shared_ptr<USB::Device> host_device = GetDeviceById(device.host_id);
Expand Down
5 changes: 3 additions & 2 deletions Source/Core/Core/IOS/USB/USB_KBD.cpp
Expand Up @@ -184,7 +184,8 @@ USB_KBD::MessageData::MessageData(MessageType type, u8 modifiers_, PressedKeyDat

// TODO: support in netplay/movies.

USB_KBD::USB_KBD(Kernel& ios, const std::string& device_name) : Device(ios, device_name)
USB_KBD::USB_KBD(EmulationKernel& ios, const std::string& device_name)
: EmulationDevice(ios, device_name)
{
}

Expand Down Expand Up @@ -214,7 +215,7 @@ std::optional<IPCReply> USB_KBD::IOCtl(const IOCtlRequest& request)
if (Config::Get(Config::MAIN_WII_KEYBOARD) && !Core::WantsDeterminism() &&
ControlReference::GetInputGate() && !m_message_queue.empty())
{
auto& system = Core::System::GetInstance();
auto& system = GetSystem();
auto& memory = system.GetMemory();
memory.CopyToEmu(request.buffer_out, &m_message_queue.front(), sizeof(MessageData));
m_message_queue.pop();
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/Core/IOS/USB/USB_KBD.h
Expand Up @@ -14,10 +14,10 @@

namespace IOS::HLE
{
class USB_KBD : public Device
class USB_KBD : public EmulationDevice
{
public:
USB_KBD(Kernel& ios, const std::string& device_name);
USB_KBD(EmulationKernel& ios, const std::string& device_name);

std::optional<IPCReply> Open(const OpenRequest& request) override;
std::optional<IPCReply> Write(const ReadWriteRequest& request) override;
Expand Down
19 changes: 11 additions & 8 deletions Source/Core/Core/IOS/USB/USB_VEN/VEN.cpp
Expand Up @@ -25,7 +25,7 @@ USB_VEN::~USB_VEN()

std::optional<IPCReply> USB_VEN::IOCtl(const IOCtlRequest& request)
{
auto& system = Core::System::GetInstance();
auto& system = GetSystem();
auto& memory = system.GetMemory();

request.Log(GetDeviceName(), Common::Log::LogType::IOS_USB);
Expand Down Expand Up @@ -53,7 +53,7 @@ std::optional<IPCReply> USB_VEN::IOCtl(const IOCtlRequest& request)
return HandleDeviceIOCtl(request,
[&](USBV5Device& device) { return CancelEndpoint(device, request); });
default:
request.DumpUnknown(GetDeviceName(), Common::Log::LogType::IOS_USB,
request.DumpUnknown(GetSystem(), GetDeviceName(), Common::Log::LogType::IOS_USB,
Common::Log::LogLevel::LERROR);
return IPCReply(IPC_SUCCESS);
}
Expand Down Expand Up @@ -100,21 +100,24 @@ s32 USB_VEN::SubmitTransfer(USB::Device& device, const IOCtlVRequest& ioctlv)
switch (ioctlv.request)
{
case USB::IOCTLV_USBV5_CTRLMSG:
return device.SubmitTransfer(std::make_unique<USB::V5CtrlMessage>(m_ios, ioctlv));
return device.SubmitTransfer(
std::make_unique<USB::V5CtrlMessage>(GetEmulationKernel(), ioctlv));
case USB::IOCTLV_USBV5_INTRMSG:
return device.SubmitTransfer(std::make_unique<USB::V5IntrMessage>(m_ios, ioctlv));
return device.SubmitTransfer(
std::make_unique<USB::V5IntrMessage>(GetEmulationKernel(), ioctlv));
case USB::IOCTLV_USBV5_BULKMSG:
return device.SubmitTransfer(std::make_unique<USB::V5BulkMessage>(m_ios, ioctlv));
return device.SubmitTransfer(
std::make_unique<USB::V5BulkMessage>(GetEmulationKernel(), ioctlv));
case USB::IOCTLV_USBV5_ISOMSG:
return device.SubmitTransfer(std::make_unique<USB::V5IsoMessage>(m_ios, ioctlv));
return device.SubmitTransfer(std::make_unique<USB::V5IsoMessage>(GetEmulationKernel(), ioctlv));
default:
return IPC_EINVAL;
}
}

IPCReply USB_VEN::CancelEndpoint(USBV5Device& device, const IOCtlRequest& request)
{
auto& system = Core::System::GetInstance();
auto& system = GetSystem();
auto& memory = system.GetMemory();

const u8 endpoint = memory.Read_U8(request.buffer_in + 8);
Expand All @@ -129,7 +132,7 @@ IPCReply USB_VEN::GetDeviceInfo(USBV5Device& device, const IOCtlRequest& request
if (request.buffer_out == 0 || request.buffer_out_size != 0xc0)
return IPCReply(IPC_EINVAL);

auto& system = Core::System::GetInstance();
auto& system = GetSystem();
auto& memory = system.GetMemory();

const std::shared_ptr<USB::Device> host_device = GetDeviceById(device.host_id);
Expand Down
15 changes: 8 additions & 7 deletions Source/Core/Core/IOS/WFS/WFSI.cpp
Expand Up @@ -94,7 +94,8 @@ void ARCUnpacker::Extract(const WriteCallback& callback)
}
}

WFSIDevice::WFSIDevice(Kernel& ios, const std::string& device_name) : Device(ios, device_name)
WFSIDevice::WFSIDevice(EmulationKernel& ios, const std::string& device_name)
: EmulationDevice(ios, device_name)
{
}

Expand Down Expand Up @@ -128,7 +129,7 @@ std::optional<IPCReply> WFSIDevice::IOCtl(const IOCtlRequest& request)
{
s32 return_error_code = IPC_SUCCESS;

auto& system = Core::System::GetInstance();
auto& system = GetSystem();
auto& memory = system.GetMemory();

switch (request.request)
Expand Down Expand Up @@ -351,7 +352,7 @@ std::optional<IPCReply> WFSIDevice::IOCtl(const IOCtlRequest& request)
return_error_code = -3;
if (homedir_path_len > 0x1FD)
break;
auto device = GetIOS()->GetDeviceByName("/dev/usb/wfssrv");
auto device = GetEmulationKernel().GetDeviceByName("/dev/usb/wfssrv");
if (!device)
break;
std::static_pointer_cast<WFSSRVDevice>(device)->SetHomeDir(homedir_path);
Expand Down Expand Up @@ -384,14 +385,14 @@ std::optional<IPCReply> WFSIDevice::IOCtl(const IOCtlRequest& request)
{
INFO_LOG_FMT(IOS_WFS, "IOCTL_WFSI_INIT");
u64 tid;
if (GetIOS()->GetES()->GetTitleId(&tid) < 0)
if (GetEmulationKernel().GetES()->GetTitleId(&tid) < 0)
{
ERROR_LOG_FMT(IOS_WFS, "IOCTL_WFSI_INIT: Could not get title id.");
return_error_code = IPC_EINVAL;
break;
}

const ES::TMDReader tmd = GetIOS()->GetES()->FindInstalledTMD(tid);
const ES::TMDReader tmd = GetEmulationKernel().GetES()->FindInstalledTMD(tid);
SetCurrentTitleIdAndGroupId(tmd.GetTitleId(), tmd.GetGroupId());
break;
}
Expand Down Expand Up @@ -543,7 +544,7 @@ std::optional<IPCReply> WFSIDevice::IOCtl(const IOCtlRequest& request)
// TODO(wfs): Should be returning an error. However until we have
// everything properly stubbed it's easier to simulate the methods
// succeeding.
request.DumpUnknown(GetDeviceName(), Common::Log::LogType::IOS_WFS,
request.DumpUnknown(system, GetDeviceName(), Common::Log::LogType::IOS_WFS,
Common::Log::LogLevel::LWARNING);
memory.Memset(request.buffer_out, 0, request.buffer_out_size);
break;
Expand All @@ -564,7 +565,7 @@ u32 WFSIDevice::GetTmd(u16 group_id, u32 title_id, u64 subtitle_id, u32 address,
}
if (address)
{
auto& system = Core::System::GetInstance();
auto& system = GetSystem();
auto& memory = system.GetMemory();
fp.ReadBytes(memory.GetPointer(address), fp.GetSize());
}
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/Core/IOS/WFS/WFSI.h
Expand Up @@ -31,10 +31,10 @@ class ARCUnpacker
std::vector<u8> m_whole_file;
};

class WFSIDevice : public Device
class WFSIDevice : public EmulationDevice
{
public:
WFSIDevice(Kernel& ios, const std::string& device_name);
WFSIDevice(EmulationKernel& ios, const std::string& device_name);

std::optional<IPCReply> IOCtl(const IOCtlRequest& request) override;

Expand Down
11 changes: 6 additions & 5 deletions Source/Core/Core/IOS/WFS/WFSSRV.cpp
Expand Up @@ -25,7 +25,8 @@ std::string NativePath(const std::string& wfs_path)
}
} // namespace WFS

WFSSRVDevice::WFSSRVDevice(Kernel& ios, const std::string& device_name) : Device(ios, device_name)
WFSSRVDevice::WFSSRVDevice(EmulationKernel& ios, const std::string& device_name)
: EmulationDevice(ios, device_name)
{
m_device_name = "msc01";
}
Expand All @@ -34,7 +35,7 @@ std::optional<IPCReply> WFSSRVDevice::IOCtl(const IOCtlRequest& request)
{
int return_error_code = IPC_SUCCESS;

auto& system = Core::System::GetInstance();
auto& system = GetSystem();
auto& memory = system.GetMemory();

switch (request.request)
Expand All @@ -57,11 +58,11 @@ std::optional<IPCReply> WFSSRVDevice::IOCtl(const IOCtlRequest& request)
// Close all hanging attach/detach ioctls with an appropriate error code.
for (auto address : m_hanging)
{
IOCtlRequest hanging_request{address};
IOCtlRequest hanging_request{system, address};
memory.Write_U32(0x80000000, hanging_request.buffer_out);
memory.Write_U32(0, hanging_request.buffer_out + 4);
memory.Write_U32(0, hanging_request.buffer_out + 8);
m_ios.EnqueueIPCReply(hanging_request, 0);
GetEmulationKernel().EnqueueIPCReply(hanging_request, 0);
}
break;

Expand Down Expand Up @@ -355,7 +356,7 @@ std::optional<IPCReply> WFSSRVDevice::IOCtl(const IOCtlRequest& request)
default:
// TODO(wfs): Should be returning -3. However until we have everything
// properly stubbed it's easier to simulate the methods succeeding.
request.DumpUnknown(GetDeviceName(), Common::Log::LogType::IOS_WFS,
request.DumpUnknown(system, GetDeviceName(), Common::Log::LogType::IOS_WFS,
Common::Log::LogLevel::LWARNING);
memory.Memset(request.buffer_out, 0, request.buffer_out_size);
break;
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/Core/IOS/WFS/WFSSRV.h
Expand Up @@ -28,10 +28,10 @@ enum
WFS_FILE_IS_OPENED = -10032, // Cannot perform operation on an opened file.
};

class WFSSRVDevice : public Device
class WFSSRVDevice : public EmulationDevice
{
public:
WFSSRVDevice(Kernel& ios, const std::string& device_name);
WFSSRVDevice(EmulationKernel& ios, const std::string& device_name);

std::optional<IPCReply> IOCtl(const IOCtlRequest& request) override;

Expand Down