qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Anthony Liguori <anthony@codemonkey.ws>
To: Max Krasnyansky <maxk@kernel.org>
Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org
Subject: [Qemu-devel] Re: [PATCH 2/5] husb: support for USB host device auto connect.
Date: Thu, 14 Aug 2008 11:41:23 -0500	[thread overview]
Message-ID: <48A46033.3070200@codemonkey.ws> (raw)
In-Reply-To: <bc54baf4e955c96be17282e99323f11dcf070a4e.1218685608.git.maxk@kernel.org>

Max Krasnyansky wrote:
> Anyway, it's implemented using a periodic timer that scans host devices
> and grabs those that match the filter. Timer is started when the first
> filter is added.
>   

Again, there has to be a way to get notified of usb device add/remove in 
Linux.

> +static USBHostDevice *hostdev_find(int bus_num, int addr)
> +{
> +    USBHostDevice *s = hostdev_list;
> +    while (s) {
> +        if (s->bus_num == bus_num && s->addr == addr)
> +            return s;
> +        s = s->next;
> +    }
> +    return NULL;
> +}
>   

There are generic list macros in sys-queue.h.  They aren't universally 
used though so it's up to you whether you think it's appropriate.

>  
> +struct USBAutoFilter {
> +    struct USBAutoFilter *next;
> +    int bus_num;
> +    int addr;
> +    int vendor_id;
> +    int product_id;
> +};
> +
> +static QEMUTimer *usb_auto_timer;
> +static struct USBAutoFilter *usb_auto_filter;
> +
> +static int usb_host_auto_scan(void *opaque, int bus_num, int addr,
> +                     int class_id, int vendor_id, int product_id,
> +                     const char *product_name, int speed)
> +{
> +    struct USBAutoFilter *f;
> +    struct USBDevice *dev;
> +
> +    /* Ignore hubs */
> +    if (class_id == 9)
> +        return 0;
> +
> +    for (f = usb_auto_filter; f; f = f->next) {
> +        // printf("Auto match: bus_num %d addr %d vid %d pid %d\n",
> +	//    bus_num, addr, vendor_id, product_id);
>   

An #ifdef guard would be nicer.

> +	if (f->bus_num >= 0 && f->bus_num != bus_num)
> +            continue;
> +
> +	if (f->addr >= 0 && f->addr != addr)
> +            continue;
> +
> +	if (f->vendor_id >= 0 && f->vendor_id != vendor_id)
> +            continue;
> +
> +	if (f->product_id >= 0 && f->product_id != product_id)
> +            continue;
> +
> +        /* We got a match */
> +
> +        /* Allredy attached ? */
> +        if (hostdev_find(bus_num, addr))
> +            return 0;
> +
> +        printf("Auto open: bus_num %d addr %d\n", bus_num, addr);
>   

Please make this debug too.

> +	dev = usb_host_device_open_addr(bus_num, addr, product_name);
> +	if (dev)
> +	    usb_device_add_dev(dev);
> +    }
> +
> +    return 0;
> +}
> +
> +static void usb_host_auto_timer(void *unused)
> +{
> +    usb_host_scan(NULL, usb_host_auto_scan);
> +    qemu_mod_timer(usb_auto_timer, qemu_get_clock(rt_clock) + 2000);
> +}
> +
> +/*
> + * Add autoconnect filter
> + * -1 means 'any' (device, vendor, etc)
> + */
> +static void usb_host_auto_add(int bus_num, int addr, int vendor_id, int product_id)
> +{
> +    struct USBAutoFilter *f = qemu_mallocz(sizeof(*f));
> +    if (!f) {
> +        printf("Failed to allocate auto filter\n");
> +	return;
> +    }
> +
> +    f->bus_num = bus_num;
> +    f->addr    = addr;
> +    f->vendor_id  = vendor_id;
> +    f->product_id = product_id;
> +
> +    if (!usb_auto_filter) {
> +        /*
> +         * First entry. Init and start the monitor.
> +         * Right now we're using timer to check for new devices.
> +         * If this turns out to be too expensive we can move that into a 
> +         * separate thread.
> +         */
> +	usb_auto_timer = qemu_new_timer(rt_clock, usb_host_auto_timer, NULL);
> +	if (!usb_auto_timer) {
> +            printf("Failed to allocate timer\n");
>   

Please print errors to stderr.

Regards,

Anthony Liguori

  reply	other threads:[~2008-08-14 16:42 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-14  4:22 [Qemu-devel] [PATCH 0/5] Various USB fixes and improvements Max Krasnyansky
2008-08-14  4:22 ` [Qemu-devel] [PATCH 1/5] husb: support for USB host device auto disconnect Max Krasnyansky
2008-08-14 16:28   ` [Qemu-devel] " Anthony Liguori
2008-08-14 19:26     ` Max Krasnyansky
2008-08-14 21:41     ` Max Krasnyansky
2008-08-14  4:22 ` [Qemu-devel] [PATCH 2/5] husb: support for USB host device auto connect Max Krasnyansky
2008-08-14 16:41   ` Anthony Liguori [this message]
2008-08-14 19:38     ` [Qemu-devel] " Max Krasnyansky
2008-08-14 20:21       ` Anthony Liguori
2008-08-14 20:34         ` Max Krasnyansky
2008-08-14 20:41           ` Anthony Liguori
2008-08-14 21:14             ` François Revol
2008-08-15  7:46             ` Guido Günther
2008-08-15 18:24               ` Max Krasnyansky
2008-08-15 18:31                 ` Javier Guerra
2008-08-18 18:21                   ` Max Krasnyansky
2008-08-18 18:52                     ` Javier Guerra
2008-08-18 18:56                       ` Jamie Lokier
2008-08-17  7:52                 ` Avi Kivity
2008-08-18 18:46                   ` Max Krasnyansky
2008-08-18 14:11                 ` Anthony Liguori
2008-08-18 18:16                   ` Max Krasnyansky
2008-08-14  4:22 ` [Qemu-devel] [PATCH 3/5] usb: generic packet handler cleanup and documentation Max Krasnyansky
2008-08-14  4:22 ` [Qemu-devel] [PATCH 4/5] uhci: rewrite UHCI emulator, fully async operation with multiple outstanding transactions Max Krasnyansky
2008-08-14 17:51   ` [Qemu-devel] " Anthony Liguori
2008-08-14 19:49     ` Max Krasnyansky
2008-10-11 23:54   ` [Qemu-devel] " Juergen Lock
2008-10-15 19:54     ` Max Krasnyansky
2008-10-15 22:05       ` andrzej zaborowski
2008-10-16 21:25         ` Juergen Lock
2008-08-14  4:22 ` [Qemu-devel] [PATCH 5/5] husb: rewrite Linux host USB layer, fully async operation Max Krasnyansky
2008-08-15 14:24   ` Paul Brook
2008-08-15 19:04     ` Max Krasnyansky
2008-08-15 19:53       ` Paul Brook
2008-08-18 18:40         ` Max Krasnyansky
2008-08-14 17:55 ` [Qemu-devel] Re: [PATCH 0/5] Various USB fixes and improvements Anthony Liguori
2008-08-14 19:55   ` Max Krasnyansky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=48A46033.3070200@codemonkey.ws \
    --to=anthony@codemonkey.ws \
    --cc=kvm@vger.kernel.org \
    --cc=maxk@kernel.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).