summaryrefslogtreecommitdiffstats
path: root/hw
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2011-08-29 12:49:46 +0200
committerGerd Hoffmann <kraxel@redhat.com>2012-01-17 09:44:50 +0100
commitd8e17efdecaaa1a2d5c8f422fc44ae229e7f4fb4 (patch)
tree367a6b5453fc02d0b9b2b33d1a6da607fe1d83a4 /hw
parent62c6ae04cf4334ef2ab5ef04581394850f4ea714 (diff)
downloadhqemu-d8e17efdecaaa1a2d5c8f422fc44ae229e7f4fb4.zip
hqemu-d8e17efdecaaa1a2d5c8f422fc44ae229e7f4fb4.tar.gz
usb: add USBEndpoint
Start maintaining endpoint state at USBDevice level. Add USBEndpoint struct and some helper functions to deal with it. For now it contains the endpoint type only. Moved over some bits from usb-linux.c Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Diffstat (limited to 'hw')
-rw-r--r--hw/usb-bus.c1
-rw-r--r--hw/usb.c30
-rw-r--r--hw/usb.h14
3 files changed, 45 insertions, 0 deletions
diff --git a/hw/usb-bus.c b/hw/usb-bus.c
index bd4afa7..016a3f2 100644
--- a/hw/usb-bus.c
+++ b/hw/usb-bus.c
@@ -75,6 +75,7 @@ static int usb_qdev_init(DeviceState *qdev, DeviceInfo *base)
dev->info = info;
dev->auto_attach = 1;
QLIST_INIT(&dev->strings);
+ usb_ep_init(dev);
rc = usb_claim_port(dev);
if (rc != 0) {
return rc;
diff --git a/hw/usb.c b/hw/usb.c
index 2216efe..5d6baaf 100644
--- a/hw/usb.c
+++ b/hw/usb.c
@@ -414,3 +414,33 @@ void usb_packet_cleanup(USBPacket *p)
{
qemu_iovec_destroy(&p->iov);
}
+
+void usb_ep_init(USBDevice *dev)
+{
+ int ep;
+
+ for (ep = 0; ep < USB_MAX_ENDPOINTS; ep++) {
+ dev->ep_in[ep].type = USB_ENDPOINT_XFER_INVALID;
+ dev->ep_out[ep].type = USB_ENDPOINT_XFER_INVALID;
+ }
+}
+
+struct USBEndpoint *usb_ep_get(USBDevice *dev, int pid, int ep)
+{
+ struct USBEndpoint *eps = pid == USB_TOKEN_IN ? dev->ep_in : dev->ep_out;
+ assert(pid == USB_TOKEN_IN || pid == USB_TOKEN_OUT);
+ assert(ep > 0 && ep <= USB_MAX_ENDPOINTS);
+ return eps + ep - 1;
+}
+
+uint8_t 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)
+{
+ struct USBEndpoint *uep = usb_ep_get(dev, pid, ep);
+ uep->type = type;
+}
diff --git a/hw/usb.h b/hw/usb.h
index b2c9479..85cbe71 100644
--- a/hw/usb.h
+++ b/hw/usb.h
@@ -144,6 +144,7 @@
#define USB_ENDPOINT_XFER_ISOC 1
#define USB_ENDPOINT_XFER_BULK 2
#define USB_ENDPOINT_XFER_INT 3
+#define USB_ENDPOINT_XFER_INVALID 255
typedef struct USBBus USBBus;
typedef struct USBBusOps USBBusOps;
@@ -151,6 +152,7 @@ typedef struct USBPort USBPort;
typedef struct USBDevice USBDevice;
typedef struct USBDeviceInfo USBDeviceInfo;
typedef struct USBPacket USBPacket;
+typedef struct USBEndpoint USBEndpoint;
typedef struct USBDesc USBDesc;
typedef struct USBDescID USBDescID;
@@ -171,6 +173,10 @@ struct USBDescString {
#define USB_MAX_ENDPOINTS 15
#define USB_MAX_INTERFACES 16
+struct USBEndpoint {
+ uint8_t type;
+};
+
/* definition of a USB device */
struct USBDevice {
DeviceState qdev;
@@ -196,6 +202,9 @@ struct USBDevice {
int32_t setup_len;
int32_t setup_index;
+ USBEndpoint ep_in[USB_MAX_ENDPOINTS];
+ USBEndpoint ep_out[USB_MAX_ENDPOINTS];
+
QLIST_HEAD(, USBDescString) strings;
const USBDescDevice *device;
@@ -322,6 +331,11 @@ int usb_handle_packet(USBDevice *dev, USBPacket *p);
void usb_packet_complete(USBDevice *dev, USBPacket *p);
void usb_cancel_packet(USBPacket * p);
+void usb_ep_init(USBDevice *dev);
+struct USBEndpoint *usb_ep_get(USBDevice *dev, int pid, int ep);
+uint8_t usb_ep_get_type(USBDevice *dev, int pid, int ep);
+void usb_ep_set_type(USBDevice *dev, int pid, int ep, uint8_t type);
+
void usb_attach(USBPort *port);
void usb_detach(USBPort *port);
void usb_reset(USBPort *port);
OpenPOWER on IntegriCloud