mirror of
https://github.com/Creased/RCM-Emulator.git
synced 2026-12-06 02:48:11 +01:00
Model USB device mode, with an emulated PC on the cable
Both USB controllers were plain register caches: USBCMD.RESET never cleared, so bdk's usb_device_init() timed out and none of Nyx's USB tools could even wait for a cable. - The Erista USB2 controller (USB1, 0x7D000000, bdk usbd.c): queue heads at ENDPOINTLISTADDR (bdk's are in the controller at +0x1000), transfer descriptors in DRAM, ENDPTPRIME / ENDPTSTATUS / ENDPTCOMPLETE, SETUP packets in queue head 0 with ENDPTSETUPSTAT, a self-clearing controller reset and the PHY's clock-valid bit. Byte and halfword accesses work, since bdk memcpy()s SETUP packets out. - The Mariko XUSB device controller (0x700D0000, bdk xusbd.c): endpoint contexts and TRB rings with Link TRBs and cycle bits, the doorbell, a two-segment event ring with Port Status Change, Setup and Transfer events, EP_HALT / EP_STCHG, EP_RELOAD, and PORTSC's write-1-to-clear changes and link-state writes. - The host (--usb-host, [usb] host, or the config window) plays the PC on whichever controller attaches: debounce, bus reset at high speed, enumeration with SET_ADDRESS recovery, then after 100 ms for its class driver to bind - bdk's XUSB driver stalls an early GET_MAX_LUN - the class. For mass storage it runs Bulk-Only Transport: GET_MAX_LUN, INQUIRY, TEST UNIT READY with REQUEST SENSE for the unit attention, READ CAPACITY, READ(10) of the first 64 and last 8 blocks with their CRC32s, checked against the SD image when the size matches, then allow removal, eject, and poll until the gadget detaches. For HID it reads the report descriptor, sets idle 0 and polls the interrupt endpoint. It only reads, and it runs on the controllers' register accesses, so runs repeat. [usb-host] lines log it; RCM_USB_TRACE=1 logs every descriptor, TRB and doorbell. With hekate 6.5.3, Nyx's SD card mass storage enumerates as 11EC:A7E0, reads back identical to the SD image and ends at "Disk ejected" on both Erista and Mariko; the gamepad enumerates and serves its report descriptor (with no Joy-Cons it has nothing to report). Without a host Nyx waits and reports a timeout, as with no cable. tests/usb/ runs a mass storage gadget over a RAM disk on each controller and a HID gadget on the USB2 one, checks what the host logs - the enumeration, the SCSI commands, CRC32s equal to the payload's, the eject and the detach - and a run with nothing on the cable. The Windows pread/pwrite shim moves from mmio.cpp to platform.h, as the host reads the SD image too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YYewwDPujjo5B2xRyC5Grb
This commit is contained in:
16 files changed
+2342
-34
No files matched your search
@@ -193,6 +193,16 @@ constexpr uint64_t SE_SIZE = 0x2000;
|
||||
constexpr uint64_t MSELECT_BASE = 0x50060000;
|
||||
constexpr uint64_t MSELECT_SIZE = 0x1000;
|
||||
|
||||
// USB2 controller USB1 ("OTG"): the device controller bdk's usbd.c drives on
|
||||
// Erista. Registers, the UTMI PHY at +0x400/+0x800, queue heads at +0x1000.
|
||||
constexpr uint64_t USB_OTG_BASE = 0x7D000000;
|
||||
constexpr uint64_t USB_OTG_SIZE = 0x4000;
|
||||
|
||||
// XUSB device controller: bdk's xusbd.c on Mariko. XHCI registers, then its
|
||||
// PCI configuration space at +0x8000 and device registers at +0x9000.
|
||||
constexpr uint64_t XUSB_DEV_BASE = 0x700D0000;
|
||||
constexpr uint64_t XUSB_DEV_SIZE = 0xA000;
|
||||
|
||||
// XUSB pad controller. Owns the UPHY SERDES lanes shared by PCIe (pcie-0..4)
|
||||
// and USB 3.0 SuperSpeed (pcie-5/6 on this board), plus UPHY PLL P0.
|
||||
constexpr uint64_t XUSB_PADCTL_BASE = 0x7009F000;
|
||||
|
||||
+12
-20
@@ -8,6 +8,7 @@
|
||||
#include "bpmp.h"
|
||||
#include "ccplex.h"
|
||||
#include "pcie.h"
|
||||
#include "usb.h"
|
||||
#include "regcache.h"
|
||||
#include "se_engine.h"
|
||||
#include "tegra_bl.h"
|
||||
@@ -24,26 +25,6 @@
|
||||
#include <vector>
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
// pread/pwrite are POSIX and MinGW does not have them, so the SD/eMMC image
|
||||
// access below would not compile for Windows. Seek-then-read is equivalent
|
||||
// here: the emulated storage is touched only from the CPU thread, so the
|
||||
// atomicity real pread() buys against a shared file offset is not in play.
|
||||
// Kept next to the includes rather than in a header because these four call
|
||||
// sites are the only users in the tree.
|
||||
#ifdef _WIN32
|
||||
#include <io.h>
|
||||
static inline ssize_t pread(int fd, void *buf, size_t n, long long off) {
|
||||
if (_lseeki64(fd, off, SEEK_SET) < 0)
|
||||
return -1;
|
||||
return _read(fd, buf, (unsigned int)n);
|
||||
}
|
||||
static inline ssize_t pwrite(int fd, const void *buf, size_t n, long long off) {
|
||||
if (_lseeki64(fd, off, SEEK_SET) < 0)
|
||||
return -1;
|
||||
return _write(fd, buf, (unsigned int)n);
|
||||
}
|
||||
#endif
|
||||
|
||||
#define BIT(n) (1U << (n))
|
||||
|
||||
static RegCache mmio_regs;
|
||||
@@ -4618,6 +4599,10 @@ uint32_t mmio_bus_read(EmuState *state, uint64_t address, unsigned size) {
|
||||
if (address >= XUSB_PADCTL_BASE &&
|
||||
address < XUSB_PADCTL_BASE + XUSB_PADCTL_SIZE)
|
||||
return padctl_read(state, address);
|
||||
if (address >= USB_OTG_BASE && address < USB_OTG_BASE + USB_OTG_SIZE)
|
||||
return usb2d_read(state, address, size);
|
||||
if (address >= XUSB_DEV_BASE && address < XUSB_DEV_BASE + XUSB_DEV_SIZE)
|
||||
return xusbd_read(state, address, size);
|
||||
if (address >= MSELECT_BASE && address < MSELECT_BASE + MSELECT_SIZE)
|
||||
return mselect_read(state, address);
|
||||
if (address >= VIC_BASE && address < VIC_BASE + VIC_SIZE)
|
||||
@@ -4777,6 +4762,10 @@ void mmio_bus_write(EmuState *state, uint64_t address, unsigned size,
|
||||
} else if (address >= XUSB_PADCTL_BASE &&
|
||||
address < XUSB_PADCTL_BASE + XUSB_PADCTL_SIZE) {
|
||||
padctl_write(state, address, val);
|
||||
} else if (address >= USB_OTG_BASE && address < USB_OTG_BASE + USB_OTG_SIZE) {
|
||||
usb2d_write(state, address, size, val);
|
||||
} else if (address >= XUSB_DEV_BASE && address < XUSB_DEV_BASE + XUSB_DEV_SIZE) {
|
||||
xusbd_write(state, address, size, val);
|
||||
} else if (address >= MSELECT_BASE && address < MSELECT_BASE + MSELECT_SIZE) {
|
||||
mselect_write(state, address, val);
|
||||
} else if ((address >= SDMMC1_BASE && address < SDMMC1_BASE + 0x200) ||
|
||||
@@ -4947,6 +4936,8 @@ const struct {
|
||||
{SYSCTR0_BASE, SYSCTR0_SIZE},
|
||||
{BPMP_CACHE_BASE, BPMP_CACHE_SIZE},
|
||||
{XUSB_PADCTL_BASE, XUSB_PADCTL_SIZE},
|
||||
{USB_OTG_BASE, USB_OTG_SIZE},
|
||||
{XUSB_DEV_BASE, XUSB_DEV_SIZE},
|
||||
{MSELECT_BASE, MSELECT_SIZE},
|
||||
// PCIe. T210 puts the root complex at the BOTTOM of the address map,
|
||||
// below every other peripheral.
|
||||
@@ -5056,6 +5047,7 @@ void mmio_soft_reset(EmuState *state, bool power_cycle) {
|
||||
pcie_reset(state);
|
||||
se_engine_reset();
|
||||
i2c3_reset(state);
|
||||
usb_reset(state);
|
||||
|
||||
mmio_regs.clear();
|
||||
for (auto &u : uart_ports)
|
||||
|
||||
+1464
File diff suppressed because it is too large.
Load diff
+18
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
struct EmuState;
|
||||
|
||||
// USB device mode (see usb.cpp): the Erista USB2 device controller, and the
|
||||
// PC a --usb-host run plugs into it.
|
||||
uint32_t usb2d_read(EmuState *state, uint64_t addr, unsigned size);
|
||||
void usb2d_write(EmuState *state, uint64_t addr, unsigned size, uint32_t val);
|
||||
|
||||
// The Mariko XUSB device controller (XHCI registers, PCI config at +0x8000,
|
||||
// the device block at +0x9000).
|
||||
uint32_t xusbd_read(EmuState *state, uint64_t addr, unsigned size);
|
||||
void xusbd_write(EmuState *state, uint64_t addr, unsigned size, uint32_t val);
|
||||
|
||||
// SoC reset: the controller back to its reset state, the host unplugged.
|
||||
void usb_reset(EmuState *state);
|
||||
Reference in new issue
Block a user