From 73796fe6228ae1e294b4946c6c90337141cacc42 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Tue, 10 Jan 2012 16:59:28 +0100 Subject: usb: add usb_find_device() Add usb_find_device(). This function will check whenever a device with a specific address is connected to the specified port. Usually this will just check state and address of the device hooked up to the port, but in case of a hub it will ask the hub to check all hub ports for a matching device. This patch doesn't put the code into use yet, see the following patches for details. The master plan is to separate device lookup and packet processing. Right now the usb code simply walks all devices, calls usb_handle_packet() on each until one accepts the packet (by returning something different that USB_RET_NODEV). I want to have a device lookup first, then call usb_handle_packet() once, for the device which actually processes the packet. Signed-off-by: Gerd Hoffmann --- hw/usb.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'hw/usb.h') diff --git a/hw/usb.h b/hw/usb.h index 61271768bc..1beb4b32a9 100644 --- a/hw/usb.h +++ b/hw/usb.h @@ -228,6 +228,12 @@ typedef struct USBDeviceClass { int (*init)(USBDevice *dev); + /* + * Walk (enabled) downstream ports, check for a matching device. + * Only hubs implement this. + */ + USBDevice *(*find_device)(USBDevice *dev, uint8_t addr); + /* * Process USB packet. * Called by the HC (Host Controller). @@ -332,6 +338,8 @@ void usb_packet_copy(USBPacket *p, void *ptr, size_t bytes); void usb_packet_skip(USBPacket *p, size_t bytes); void usb_packet_cleanup(USBPacket *p); +USBDevice *usb_find_device(USBPort *port, uint8_t addr); + int usb_handle_packet(USBDevice *dev, USBPacket *p); void usb_packet_complete(USBDevice *dev, USBPacket *p); void usb_cancel_packet(USBPacket * p); @@ -446,6 +454,8 @@ extern const VMStateDescription vmstate_usb_device; .offset = vmstate_offset_value(_state, _field, USBDevice), \ } +USBDevice *usb_device_find_device(USBDevice *dev, uint8_t addr); + int usb_device_handle_packet(USBDevice *dev, USBPacket *p); void usb_device_cancel_packet(USBDevice *dev, USBPacket *p); -- cgit v1.2.3