Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

USB: Allow UsbPspCm passthrough #15540

Merged
merged 2 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions rpcs3/Emu/Cell/lv2/sys_usbd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,9 @@ usb_handler_thread::usb_handler_thread()

// Tony Hawk RIDE Skateboard
check_device(0x12BA, 0x0400, 0x0400, "Tony Hawk RIDE Skateboard Controller");

// PSP in UsbPspCm mode
check_device(0x054C, 0x01CB, 0x01CB, "UsbPspcm");
}

libusb_free_device_list(list, 1);
Expand Down Expand Up @@ -588,7 +591,15 @@ void usb_handler_thread::transfer_complete(struct libusb_transfer* transfer)
case LIBUSB_TRANSFER_CANCELLED:
case LIBUSB_TRANSFER_STALL:
case LIBUSB_TRANSFER_NO_DEVICE:
default: usbd_transfer->result = EHCI_CC_HALTED; break;
default:
usbd_transfer->result = EHCI_CC_HALTED;
if (usbd_transfer->assigned_number && handled_devices.erase(usbd_transfer->assigned_number))
{
send_message(SYS_USBD_DETACH, usbd_transfer->assigned_number);
sys_usbd.warning("USB transfer failed, detach the device %d", usbd_transfer->assigned_number);
usbd_transfer->assigned_number = 0;
}
break;
}

usbd_transfer->count = transfer->actual_length;
Expand Down Expand Up @@ -971,6 +982,7 @@ error_code sys_usbd_register_ldd(ppu_thread& ppu, u32 handle, vm::cptr<char> s_p
// Unsure how many more devices might need similar treatment (i.e. just a compare and force VID/PID add), or if it's worth adding a full promiscuous capability
static const std::unordered_map<std::string, UsbLdd, fmt::string_hash, std::equal_to<>> predefined_ldds
{
{"cellUsbPspcm", {0x054C, 0x01CB, 0x01CB}},
{"guncon3", {0x0B9A, 0x0800, 0x0800}},
{"PS3A-USJ", {0x0B9A, 0x0900, 0x0910}}
};
Expand All @@ -995,11 +1007,12 @@ error_code sys_usbd_unregister_ldd(ppu_thread& ppu, u32 handle, vm::cptr<char> s
}

// TODO: determine what the unknown params are
error_code sys_usbd_open_pipe(ppu_thread& ppu, u32 handle, u32 device_handle, u32 unk1, u64 unk2, u64 unk3, u32 endpoint, u64 unk4)
// attributes (bmAttributes) : 2=Bulk, 3=Interrupt
error_code sys_usbd_open_pipe(ppu_thread& ppu, u32 handle, u32 device_handle, u32 unk1, u64 unk2, u64 unk3, u32 endpoint, u64 attributes)
{
ppu.state += cpu_flag::wait;

sys_usbd.warning("sys_usbd_open_pipe(handle=0x%x, device_handle=0x%x, unk1=0x%x, unk2=0x%x, unk3=0x%x, endpoint=0x%x, unk4=0x%x)", handle, device_handle, unk1, unk2, unk3, endpoint, unk4);
sys_usbd.warning("sys_usbd_open_pipe(handle=0x%x, device_handle=0x%x, unk1=0x%x, unk2=0x%x, unk3=0x%x, endpoint=0x%x, attributes=0x%x)", handle, device_handle, unk1, unk2, unk3, endpoint, attributes);

auto& usbh = g_fxo->get<named_thread<usb_handler_thread>>();

Expand Down Expand Up @@ -1166,6 +1179,8 @@ error_code sys_usbd_transfer_data(ppu_thread& ppu, u32 handle, u32 id_pipe, vm::
const auto& pipe = usbh.get_pipe(id_pipe);
auto&& [transfer_id, transfer] = usbh.get_free_transfer();

transfer.assigned_number = pipe.device->assigned_number;

// Default endpoint is control endpoint
if (pipe.endpoint == 0)
{
Expand Down
4 changes: 2 additions & 2 deletions rpcs3/Emu/Io/usb_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void usb_device_passthrough::send_libusb_transfer(libusb_transfer* transfer)
case LIBUSB_ERROR_BUSY: continue;
default:
{
sys_usbd.error("Unexpected error from libusb_submit_transfer: %d", res);
sys_usbd.error("Unexpected error from libusb_submit_transfer: %d(%s)", res, libusb_error_name(res));
return;
}
}
Expand Down Expand Up @@ -114,7 +114,7 @@ void usb_device_passthrough::read_descriptors()
int ssize = libusb_control_transfer(lusb_handle, +LIBUSB_ENDPOINT_IN | +LIBUSB_REQUEST_TYPE_STANDARD | +LIBUSB_RECIPIENT_DEVICE, LIBUSB_REQUEST_GET_DESCRIPTOR, 0x0200 | index, 0, buf, 1000, 0);
if (ssize < 0)
{
sys_usbd.fatal("Couldn't get the config from the device: %d", ssize);
sys_usbd.fatal("Couldn't get the config from the device: %d(%s)", ssize, libusb_error_name(ssize));
continue;
}

Expand Down
1 change: 1 addition & 0 deletions rpcs3/Emu/Io/usb_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ struct UsbDeviceHID

struct UsbTransfer
{
u32 assigned_number = 0;
u32 transfer_id = 0;

s32 result = 0;
Expand Down