Skip to content

Commit

Permalink
USB: Cleanup usb qemu.
Browse files Browse the repository at this point in the history
Make it suck less.
  • Loading branch information
lightningterror committed Jan 28, 2024
1 parent 63872e6 commit 716d8c0
Show file tree
Hide file tree
Showing 8 changed files with 347 additions and 489 deletions.
38 changes: 19 additions & 19 deletions pcsx2/USB/qemu-usb/USBinternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ typedef struct OHCIState
/* Host Controller Communications Area */
struct ohci_hcca
{
uint32_t intr[32];
uint16_t frame, pad;
uint32_t done;
u32 intr[32];
u16 frame, pad;
u32 done;
};

//ISO C++ forbids declaration of ‘typeof’ with no type
Expand Down Expand Up @@ -158,29 +158,29 @@ struct ohci_hcca
/* endpoint descriptor */
struct ohci_ed
{
uint32_t flags;
uint32_t tail;
uint32_t head;
uint32_t next;
u32 flags;
u32 tail;
u32 head;
u32 next;
};

/* General transfer descriptor */
struct ohci_td
{
uint32_t flags;
uint32_t cbp;
uint32_t next;
uint32_t be;
u32 flags;
u32 cbp;
u32 next;
u32 be;
};

/* Isochronous transfer descriptor */
struct ohci_iso_td
{
uint32_t flags;
uint32_t bp;
uint32_t next;
uint32_t be;
uint16_t offset[8];
u32 flags;
u32 bp;
u32 next;
u32 be;
u16 offset[8];
};

#define USB_HZ 12000000
Expand Down Expand Up @@ -276,10 +276,10 @@ struct ohci_iso_td
#define OHCI_CC_BUFFEROVERRUN 0xc
#define OHCI_CC_BUFFERUNDERRUN 0xd

OHCIState* ohci_create(uint32_t base, int ports);
OHCIState* ohci_create(u32 base, int ports);

uint32_t ohci_mem_read(OHCIState* ohci, uint32_t addr);
void ohci_mem_write(OHCIState* ohci, uint32_t addr, uint32_t value);
u32 ohci_mem_read(OHCIState* ohci, u32 addr);
void ohci_mem_write(OHCIState* ohci, u32 addr, u32 value);
void ohci_frame_boundary(void* opaque);

void ohci_hard_reset(OHCIState* ohci);
Expand Down
34 changes: 1 addition & 33 deletions pcsx2/USB/qemu-usb/bus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,15 @@

#define USB_DEVICE_GET_CLASS(p) (&p->klass)

#if 0
// Unused
static void usb_device_realize(USBDevice* dev /*, Error **errp*/)
{
USBDeviceClass* klass = USB_DEVICE_GET_CLASS(dev);

if (klass->realize)
{
klass->realize(dev /*, errp*/);
}
}
#endif

USBDevice* usb_device_find_device(USBDevice* dev, uint8_t addr)
{
USBDeviceClass* klass = USB_DEVICE_GET_CLASS(dev);
if (klass->find_device)
{
return klass->find_device(dev, addr);
}
return NULL;
}

#if 0
// Unused
static void usb_device_unrealize(USBDevice* dev /*, Error **errp*/)
{
USBDeviceClass* klass = USB_DEVICE_GET_CLASS(dev);

if (klass->unrealize)
{
klass->unrealize(dev /*, errp*/);
}
return nullptr;
}
#endif

void usb_device_cancel_packet(USBDevice* dev, USBPacket* p)
{
Expand Down Expand Up @@ -88,12 +62,6 @@ void usb_device_handle_data(USBDevice* dev, USBPacket* p)
}
}

/*const char *usb_device_get_product_desc(USBDevice *dev)
{
USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev);
return klass->product_desc;
}*/

const USBDesc* usb_device_get_usb_desc(USBDevice* dev)
{
USBDeviceClass* klass = USB_DEVICE_GET_CLASS(dev);
Expand Down
36 changes: 18 additions & 18 deletions pcsx2/USB/qemu-usb/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void usb_attach(USBPort* port)
{
USBDevice* dev = port->dev;

assert(dev != NULL);
assert(dev != nullptr);
assert(dev->attached);
assert(dev->state == USB_STATE_NOTATTACHED);
usb_pick_speed(port);
Expand All @@ -74,7 +74,7 @@ void usb_detach(USBPort* port)
{
USBDevice* dev = port->dev;

assert(dev != NULL);
assert(dev != nullptr);
assert(dev->state != USB_STATE_NOTATTACHED);
port->ops->detach(port);
dev->state = USB_STATE_NOTATTACHED;
Expand All @@ -90,15 +90,15 @@ void usb_port_reset(USBPort* port)
{
USBDevice* dev = port->dev;

assert(dev != NULL);
assert(dev != nullptr);
usb_detach(port);
usb_attach(port);
usb_device_reset(dev);
}

void usb_device_reset(USBDevice* dev)
{
if (dev == NULL || !dev->attached)
if (dev == nullptr || !dev->attached)
{
return;
}
Expand Down Expand Up @@ -381,13 +381,13 @@ void usb_generic_async_ctrl_complete(USBDevice* s, USBPacket* p)
usb_packet_complete(s, p);
}

USBDevice* usb_find_device(USBPort* port, uint8_t addr)
USBDevice* usb_find_device(USBPort* port, u8 addr)
{
USBDevice* dev = port->dev;

if (dev == NULL || !dev->attached || dev->state != USB_STATE_DEFAULT)
if (dev == nullptr || !dev->attached || dev->state != USB_STATE_DEFAULT)
{
return NULL;
return nullptr;
}
if (dev->addr == addr)
{
Expand Down Expand Up @@ -449,15 +449,15 @@ static void usb_queue_one(USBPacket* p)
driver will call usb_packet_complete() when done processing it. */
void usb_handle_packet(USBDevice* dev, USBPacket* p)
{
if (dev == NULL)
if (dev == nullptr)
{
p->status = USB_RET_NODEV;
return;
}
assert(dev == p->ep->dev);
assert(dev->state == USB_STATE_DEFAULT);
usb_packet_check_state(p, USB_PACKET_SETUP);
assert(p->ep != NULL);
assert(p->ep != nullptr);

/* Submitting a new packet clears halt */
if (p->ep->halted)
Expand Down Expand Up @@ -632,15 +632,15 @@ void usb_packet_setup(USBPacket* p, int pid,
p->parameter = 0;
p->short_not_ok = short_not_ok;
p->int_req = int_req;
p->buffer_ptr = NULL;
p->buffer_ptr = nullptr;
p->buffer_size = 0;
usb_packet_set_state(p, USB_PACKET_SETUP);
}

void usb_packet_addbuf(USBPacket* p, void* ptr, size_t len)
{
assert(!p->buffer_ptr);
p->buffer_ptr = static_cast<uint8_t*>(ptr);
p->buffer_ptr = static_cast<u8*>(ptr);
p->buffer_size = static_cast<unsigned int>(len);
}

Expand Down Expand Up @@ -785,9 +785,9 @@ struct USBEndpoint* usb_ep_get(USBDevice* dev, int pid, int ep)
{
struct USBEndpoint* eps;

if (dev == NULL)
if (dev == nullptr)
{
return NULL;
return nullptr;
}
eps = (pid == USB_TOKEN_IN) ? dev->ep_in : dev->ep_out;
if (ep == 0)
Expand All @@ -799,19 +799,19 @@ struct USBEndpoint* usb_ep_get(USBDevice* dev, int pid, int ep)
return eps + ep - 1;
}

uint8_t usb_ep_get_type(USBDevice* dev, int pid, int ep)
u8 usb_ep_get_type(USBDevice* dev, int pid, int ep)
{
struct USBEndpoint* uep = usb_ep_get(dev, pid, ep);
return uep->type;
}

void usb_ep_set_type(USBDevice* dev, int pid, int ep, uint8_t type)
void usb_ep_set_type(USBDevice* dev, int pid, int ep, u8 type)
{
struct USBEndpoint* uep = usb_ep_get(dev, pid, ep);
uep->type = type;
}

void usb_ep_set_ifnum(USBDevice* dev, int pid, int ep, uint8_t ifnum)
void usb_ep_set_ifnum(USBDevice* dev, int pid, int ep, u8 ifnum)
{
struct USBEndpoint* uep = usb_ep_get(dev, pid, ep);
uep->ifnum = ifnum;
Expand Down Expand Up @@ -839,7 +839,7 @@ void usb_ep_set_max_packet_size(USBDevice* dev, int pid, int ep,
uep->max_packet_size = size * microframes;
}

void usb_ep_set_max_streams(USBDevice* dev, int pid, int ep, uint8_t raw)
void usb_ep_set_max_streams(USBDevice* dev, int pid, int ep, u8 raw)
{
struct USBEndpoint* uep = usb_ep_get(dev, pid, ep);
int MaxStreams;
Expand Down Expand Up @@ -875,7 +875,7 @@ USBPacket* usb_ep_find_packet_by_id(USBDevice* dev, int pid, int ep,
}
}

return NULL;
return nullptr;
}

void usb_wakeup(USBDevice* dev)
Expand Down
Loading

0 comments on commit 716d8c0

Please sign in to comment.