From ebcb6ba9a0e28d6cfac72ba036723024b7502544 Mon Sep 17 00:00:00 2001 From: ergo720 <45463469+ergo720@users.noreply.github.com> Date: Fri, 18 Jan 2019 16:19:28 +0100 Subject: [PATCH] Removed xhci-specific and other redundant code --- src/devices/usb/OHCI.cpp | 4 +-- src/devices/usb/USBDevice.cpp | 61 +++-------------------------------- src/devices/usb/USBDevice.h | 6 ++-- src/devices/usb/UsbCommon.h | 12 +++---- 4 files changed, 12 insertions(+), 71 deletions(-) diff --git a/src/devices/usb/OHCI.cpp b/src/devices/usb/OHCI.cpp index 63ef68a2d..9ee619c95 100644 --- a/src/devices/usb/OHCI.cpp +++ b/src/devices/usb/OHCI.cpp @@ -685,7 +685,7 @@ int OHCI::OHCI_ServiceTD(OHCI_ED* Ed) } dev = OHCI_FindDevice(OHCI_BM(Ed->Flags, ED_FA)); ep = m_UsbDevice->USB_GetEP(dev, pid, OHCI_BM(Ed->Flags, ED_EN)); - m_UsbDevice->USB_PacketSetup(&m_UsbPacket, pid, ep, 0, addr, !flag_r, OHCI_BM(td.Flags, TD_DI) == 0); + m_UsbDevice->USB_PacketSetup(&m_UsbPacket, pid, ep, addr, !flag_r, OHCI_BM(td.Flags, TD_DI) == 0); m_UsbDevice->USB_PacketAddBuffer(&m_UsbPacket, m_UsbBuffer, packetlen); m_UsbDevice->USB_HandlePacket(dev, &m_UsbPacket); #ifdef DEBUG_PACKET @@ -1746,7 +1746,7 @@ int OHCI::OHCI_ServiceIsoTD(OHCI_ED* ed, int completion) bool int_req = relative_frame_number == frame_count && OHCI_BM(iso_td.Flags, TD_DI) == 0; dev = OHCI_FindDevice(OHCI_BM(ed->Flags, ED_FA)); ep = m_UsbDevice->USB_GetEP(dev, pid, OHCI_BM(ed->Flags, ED_EN)); - m_UsbDevice->USB_PacketSetup(&m_UsbPacket, pid, ep, 0, addr, false, int_req); + m_UsbDevice->USB_PacketSetup(&m_UsbPacket, pid, ep, addr, false, int_req); m_UsbDevice->USB_PacketAddBuffer(&m_UsbPacket, m_UsbBuffer, len); m_UsbDevice->USB_HandlePacket(dev, &m_UsbPacket); if (m_UsbPacket.Status == USB_RET_ASYNC) { diff --git a/src/devices/usb/USBDevice.cpp b/src/devices/usb/USBDevice.cpp index 3cacd96fd..008664444 100644 --- a/src/devices/usb/USBDevice.cpp +++ b/src/devices/usb/USBDevice.cpp @@ -57,7 +57,6 @@ namespace xboxkrnl #define SETUP_STATE_SETUP 1 #define SETUP_STATE_DATA 2 #define SETUP_STATE_ACK 3 -#define SETUP_STATE_PARAM 4 void USBDevice::Init() @@ -196,18 +195,16 @@ USBEndpoint* USBDevice::USB_GetEP(XboxDeviceState* Dev, int Pid, int Ep) return eps + Ep - 1; } -void USBDevice::USB_PacketSetup(USBPacket* p, int Pid, USBEndpoint* Ep, unsigned int Stream, - uint64_t Id, bool ShortNotOK, bool IntReq) +void USBDevice::USB_PacketSetup(USBPacket* p, int Pid, USBEndpoint* Ep, uint64_t Id, + bool ShortNotOK, bool IntReq) { assert(!USB_IsPacketInflight(p)); assert(p->IoVec.IoVecStruct != nullptr); p->Id = Id; p->Pid = Pid; p->Endpoint = Ep; - p->Stream = Stream; p->Status = USB_RET_SUCCESS; p->ActualLength = 0; - p->Parameter = 0ULL; p->ShortNotOK = ShortNotOK; p->IntReq = IntReq; IoVecReset(&p->IoVec); @@ -241,7 +238,7 @@ void USBDevice::USB_HandlePacket(XboxDeviceState* dev, USBPacket* p) p->Endpoint->Halted = false; } - if (QTAILQ_EMPTY(&p->Endpoint->Queue) || p->Endpoint->Pipeline || p->Stream) { + if (QTAILQ_EMPTY(&p->Endpoint->Queue)) { USB_ProcessOne(p); if (p->Status == USB_RET_ASYNC) { // hcd drivers cannot handle async for isoc @@ -257,8 +254,7 @@ void USBDevice::USB_HandlePacket(XboxDeviceState* dev, USBPacket* p) else { // When pipelining is enabled usb-devices must always return async, // otherwise packets can complete out of order! - assert(p->Stream || !p->Endpoint->Pipeline || - QTAILQ_EMPTY(&p->Endpoint->Queue)); + assert(QTAILQ_EMPTY(&p->Endpoint->Queue)); if (p->Status != USB_RET_NAK) { p->State = USB_PACKET_COMPLETE; } @@ -298,10 +294,6 @@ void USBDevice::USB_ProcessOne(USBPacket* p) if (p->Endpoint->Num == 0) { // Info: All devices must support endpoint zero. This is the endpoint which receives all of the devices control // and status requests during enumeration and throughout the duration while the device is operational on the bus - if (p->Parameter) { - USB_DoParameter(dev, p); - return; - } switch (p->Pid) { case USB_TOKEN_SETUP: { USB_DoTokenSetup(dev, p); @@ -328,46 +320,6 @@ void USBDevice::USB_ProcessOne(USBPacket* p) } } -void USBDevice::USB_DoParameter(XboxDeviceState* s, USBPacket* p) -{ - int i, request, value, index; - - for (i = 0; i < 8; i++) { - s->SetupBuffer[i] = p->Parameter >> (i * 8); - } - - s->SetupState = SETUP_STATE_PARAM; - s->SetupLength = (s->SetupBuffer[7] << 8) | s->SetupBuffer[6]; - s->SetupIndex = 0; - - request = (s->SetupBuffer[0] << 8) | s->SetupBuffer[1]; - value = (s->SetupBuffer[3] << 8) | s->SetupBuffer[2]; - index = (s->SetupBuffer[5] << 8) | s->SetupBuffer[4]; - - if (s->SetupLength > sizeof(s->DataBuffer)) { - DBG_PRINTF("ctrl buffer too small (%d > %zu)\n", s->SetupLength, sizeof(s->DataBuffer)); - p->Status = USB_RET_STALL; - return; - } - - if (p->Pid == USB_TOKEN_OUT) { - USB_PacketCopy(p, s->DataBuffer, s->SetupLength); - } - - USB_DeviceHandleControl(s, p, request, value, index, s->SetupLength, s->DataBuffer); - if (p->Status == USB_RET_ASYNC) { - return; - } - - if (p->ActualLength < s->SetupLength) { - s->SetupLength = p->ActualLength; - } - if (p->Pid == USB_TOKEN_IN) { - p->ActualLength = 0; - USB_PacketCopy(p, s->DataBuffer, s->SetupLength); - } -} - void USBDevice::USB_DoTokenSetup(XboxDeviceState* s, USBPacket* p) { int request, value, index; @@ -700,12 +652,9 @@ void USBDevice::USB_EpReset(XboxDeviceState* dev) dev->EP_ctl.IfNum = 0; dev->EP_ctl.MaxPacketSize = 64; dev->EP_ctl.Dev = dev; - dev->EP_ctl.Pipeline = false; for (int ep = 0; ep < USB_MAX_ENDPOINTS; ep++) { dev->EP_in[ep].Num = ep + 1; dev->EP_out[ep].Num = ep + 1; - dev->EP_in[ep].pid = USB_TOKEN_IN; - dev->EP_out[ep].pid = USB_TOKEN_OUT; dev->EP_in[ep].Type = USB_ENDPOINT_XFER_INVALID; dev->EP_out[ep].Type = USB_ENDPOINT_XFER_INVALID; dev->EP_in[ep].IfNum = USB_INTERFACE_INVALID; @@ -714,8 +663,6 @@ void USBDevice::USB_EpReset(XboxDeviceState* dev) dev->EP_out[ep].MaxPacketSize = 0; dev->EP_in[ep].Dev = dev; dev->EP_out[ep].Dev = dev; - dev->EP_in[ep].Pipeline = false; - dev->EP_out[ep].Pipeline = false; } } diff --git a/src/devices/usb/USBDevice.h b/src/devices/usb/USBDevice.h index 88d13818d..35d9155ac 100644 --- a/src/devices/usb/USBDevice.h +++ b/src/devices/usb/USBDevice.h @@ -94,8 +94,8 @@ class USBDevice : public PCIDevice { // find the requested endpoint in the supplied device USBEndpoint* USB_GetEP(XboxDeviceState* Dev, int Pid, int Ep); // setup a packet for transfer - void USB_PacketSetup(USBPacket* p, int Pid, USBEndpoint* Ep, unsigned int Stream, - uint64_t Id, bool ShortNotOK, bool IntReq); + void USB_PacketSetup(USBPacket* p, int Pid, USBEndpoint* Ep, uint64_t Id, + bool ShortNotOK, bool IntReq); // check if the state of the packet is queued or async bool USB_IsPacketInflight(USBPacket* p); // append the user buffer to the packet @@ -106,8 +106,6 @@ class USBDevice : public PCIDevice { void USB_PacketCheckState(USBPacket* p, USBPacketState expected); // process the packet void USB_ProcessOne(USBPacket* p); - // xhci only? - void USB_DoParameter(XboxDeviceState* s, USBPacket* p); // process a setup token void USB_DoTokenSetup(XboxDeviceState* s, USBPacket* p); // process an input token diff --git a/src/devices/usb/UsbCommon.h b/src/devices/usb/UsbCommon.h index bc64839f5..6279da104 100644 --- a/src/devices/usb/UsbCommon.h +++ b/src/devices/usb/UsbCommon.h @@ -316,11 +316,9 @@ struct USBDescriptor { /* USB endpoint */ struct USBEndpoint { uint8_t Num; // endpoint number - uint8_t pid; uint8_t Type; // the type of this endpoint uint8_t IfNum; // interface number this endpoint belongs to int MaxPacketSize; // maximum packet size supported by this endpoint - bool Pipeline; bool Halted; // indicates that the endpoint is halted XboxDeviceState* Dev; // device this endpoint belongs to QTAILQ_HEAD(, USBPacket) Queue; // queue of packets to this endpoint @@ -403,9 +401,9 @@ struct XboxDeviceState { int32_t SetupLength; // this field specifies the length of the data transferred during the second phase of the control transfer int32_t SetupIndex; // index of the parameter in a setup token? - USBEndpoint EP_ctl; // endpoints for SETUP tokens - USBEndpoint EP_in[USB_MAX_ENDPOINTS]; // endpoints for OUT tokens - USBEndpoint EP_out[USB_MAX_ENDPOINTS]; // endpoints for IN tokens + USBEndpoint EP_ctl; // control endpoint + USBEndpoint EP_in[USB_MAX_ENDPOINTS]; // device endpoint (input direction) + USBEndpoint EP_out[USB_MAX_ENDPOINTS]; // device endpoint (output direction) QLIST_HEAD(, USBDescString) Strings; // strings of the string descriptors const USBDesc* UsbDesc; // Overrides class usb_desc if not nullptr @@ -420,12 +418,10 @@ struct XboxDeviceState { /* Structure used to hold information about an active USB packet */ struct USBPacket { - int Pid; // Packet ID (used to identify the type of packet that is being sent) + int Pid; // Packet ID (used to identify the type of packet that is being processed) uint32_t Id; // Paddr of the TD for this packet USBEndpoint* Endpoint; // endpoint this packet is transferred to - unsigned int Stream; IOVector IoVec; // used to perform vectored I/O - uint64_t Parameter; // this seems to be used only in xhci and it's 0 otherwise. If so, this can be removed bool ShortNotOK; // the bufferRounding mode of the TD for this packet bool IntReq; // whether or not to generate an interrupt for this packet (DelayInterrupt of the TD is zero) int Status; // USB_RET_* status code