From f003397ce95441cd8de01a728affb3de7accd1dd Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Wed, 31 Aug 2011 16:09:27 +0200 Subject: usb: add max_packet_size to USBEndpoint Signed-off-by: Gerd Hoffmann --- hw/usb-desc.c | 2 ++ hw/usb.c | 37 +++++++++++++++++++++++++++++++++---- hw/usb.h | 4 ++++ 3 files changed, 39 insertions(+), 4 deletions(-) (limited to 'hw') diff --git a/hw/usb-desc.c b/hw/usb-desc.c index 0768334..b3eb97b 100644 --- a/hw/usb-desc.c +++ b/hw/usb-desc.c @@ -248,6 +248,8 @@ static void usb_desc_ep_init(USBDevice *dev) ep = iface->eps[e].bEndpointAddress & 0x0f; usb_ep_set_type(dev, pid, ep, iface->eps[e].bmAttributes & 0x03); usb_ep_set_ifnum(dev, pid, ep, iface->bInterfaceNumber); + usb_ep_set_max_packet_size(dev, pid, ep, + iface->eps[e].wMaxPacketSize); } } } diff --git a/hw/usb.c b/hw/usb.c index f07cb9d..0f163b4 100644 --- a/hw/usb.c +++ b/hw/usb.c @@ -449,8 +449,9 @@ void usb_ep_dump(USBDevice *dev) fprintf(stderr, " Interface %d, alternative %d\n", ifnum, dev->altsetting[ifnum]); } - fprintf(stderr, " Endpoint %d, IN, %s\n", ep, - tname[dev->ep_in[ep].type]); + fprintf(stderr, " Endpoint %d, IN, %s, %d max\n", ep, + tname[dev->ep_in[ep].type], + dev->ep_in[ep].max_packet_size); } if (dev->ep_out[ep].type != USB_ENDPOINT_XFER_INVALID && dev->ep_out[ep].ifnum == ifnum) { @@ -459,8 +460,9 @@ void usb_ep_dump(USBDevice *dev) fprintf(stderr, " Interface %d, alternative %d\n", ifnum, dev->altsetting[ifnum]); } - fprintf(stderr, " Endpoint %d, OUT, %s\n", ep, - tname[dev->ep_out[ep].type]); + fprintf(stderr, " Endpoint %d, OUT, %s, %d max\n", ep, + tname[dev->ep_out[ep].type], + dev->ep_out[ep].max_packet_size); } } } @@ -498,3 +500,30 @@ void usb_ep_set_ifnum(USBDevice *dev, int pid, int ep, uint8_t ifnum) struct USBEndpoint *uep = usb_ep_get(dev, pid, ep); uep->ifnum = ifnum; } + +void usb_ep_set_max_packet_size(USBDevice *dev, int pid, int ep, + uint16_t raw) +{ + struct USBEndpoint *uep = usb_ep_get(dev, pid, ep); + int size, microframes; + + size = raw & 0x7ff; + switch ((raw >> 11) & 3) { + case 1: + microframes = 2; + break; + case 2: + microframes = 3; + break; + default: + microframes = 1; + break; + } + uep->max_packet_size = size * microframes; +} + +int usb_ep_get_max_packet_size(USBDevice *dev, int pid, int ep) +{ + struct USBEndpoint *uep = usb_ep_get(dev, pid, ep); + return uep->max_packet_size; +} diff --git a/hw/usb.h b/hw/usb.h index c35ff74..5ea984c 100644 --- a/hw/usb.h +++ b/hw/usb.h @@ -176,6 +176,7 @@ struct USBDescString { struct USBEndpoint { uint8_t type; uint8_t ifnum; + int max_packet_size; }; /* definition of a USB device */ @@ -339,6 +340,9 @@ uint8_t usb_ep_get_type(USBDevice *dev, int pid, int ep); uint8_t usb_ep_get_ifnum(USBDevice *dev, int pid, int ep); void usb_ep_set_type(USBDevice *dev, int pid, int ep, uint8_t type); void usb_ep_set_ifnum(USBDevice *dev, int pid, int ep, uint8_t ifnum); +void usb_ep_set_max_packet_size(USBDevice *dev, int pid, int ep, + uint16_t raw); +int usb_ep_get_max_packet_size(USBDevice *dev, int pid, int ep); void usb_attach(USBPort *port); void usb_detach(USBPort *port); -- cgit v1.1