ia64/xen-unstable

changeset 5072:5bf66e408317

bitkeeper revision 1.1502 (428f0d94bUM6nCIYBQRzeFSs29KMDg)

Clean up droppings that occured when pulling the upgrade to 2.4.30 from 2.0-testing into unstable.


Signed-off-by: ian@xensource.com
author iap10@freefall.cl.cam.ac.uk
date Sat May 21 10:29:40 2005 +0000 (2005-05-21)
parents e869b20358b1
children 6dda721a273a
files .rootkeys linux-2.4.29-xen-sparse/arch/xen/drivers/usbif/Makefile linux-2.4.29-xen-sparse/arch/xen/drivers/usbif/backend/Makefile linux-2.4.29-xen-sparse/arch/xen/drivers/usbif/frontend/Makefile linux-2.4.29-xen-sparse/arch/xen/kernel/ioport.c linux-2.4.29-xen-sparse/arch/xen/kernel/pci-dma.c linux-2.4.29-xen-sparse/drivers/usb/hcd.c
line diff
     1.1 --- a/.rootkeys	Sat May 21 10:12:11 2005 +0000
     1.2 +++ b/.rootkeys	Sat May 21 10:29:40 2005 +0000
     1.3 @@ -123,12 +123,6 @@ 427346bfHJQldVgD-acDy_2toKMhTA freebsd-5
     1.4  423e7e8dVDL1WLfbmQWuXMbetYk4jA freebsd-5.3-xen-sparse/mkbuildtree
     1.5  423e7e8dBrOrAbydK6h49bY0VvDgPw freebsd-5.3-xen-sparse/xenfbsd_kernel_build
     1.6  4187ca95_eQN62ugV1zliQcfzXrHnw install.sh
     1.7 -41ee5e8b_2rt-qHzbDXtIoBzOli0EA linux-2.4.29-xen-sparse/arch/xen/drivers/usbif/Makefile
     1.8 -41ee5e8bUhF4tH7OoJaVbUxdXqneVw linux-2.4.29-xen-sparse/arch/xen/drivers/usbif/backend/Makefile
     1.9 -41ee5e8bSPpxzhGO6TrY20TegW3cZg linux-2.4.29-xen-sparse/arch/xen/drivers/usbif/frontend/Makefile
    1.10 -4241709bNBs1q4Ss32YW0CyFVOGhEg linux-2.4.29-xen-sparse/arch/xen/kernel/ioport.c
    1.11 -4270e964iKFC24KiVm6jC5Eo7MxV6w linux-2.4.29-xen-sparse/arch/xen/kernel/pci-dma.c
    1.12 -41f97f64nW0wmgLxhwzPTzkF4E5ERA linux-2.4.29-xen-sparse/drivers/usb/hcd.c
    1.13  3e5a4e6589G-U42lFKs43plskXoFxQ linux-2.4.30-xen-sparse/Makefile
    1.14  3e5a4e65IEPjnWPZ5w3TxS5scV8Ewg linux-2.4.30-xen-sparse/arch/xen/Makefile
    1.15  3e5a4e65n-KhsEAs-A4ULiStBp-r6w linux-2.4.30-xen-sparse/arch/xen/boot/Makefile
     2.1 --- a/linux-2.4.29-xen-sparse/arch/xen/drivers/usbif/Makefile	Sat May 21 10:12:11 2005 +0000
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,10 +0,0 @@
     2.4 -
     2.5 -O_TARGET := drv.o
     2.6 -
     2.7 -subdir-$(CONFIG_XEN_USB_FRONTEND) += frontend
     2.8 -obj-$(CONFIG_XEN_USB_FRONTEND) += frontend/drv.o
     2.9 -
    2.10 -subdir-$(CONFIG_XEN_USB_BACKEND) += backend
    2.11 -obj-$(CONFIG_XEN_USB_BACKEND)    += backend/drv.o
    2.12 -
    2.13 -include $(TOPDIR)/Rules.make
     3.1 --- a/linux-2.4.29-xen-sparse/arch/xen/drivers/usbif/backend/Makefile	Sat May 21 10:12:11 2005 +0000
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,3 +0,0 @@
     3.4 -O_TARGET := drv.o
     3.5 -obj-y := main.o interface.o control.o # vrh.o don't think I need this!
     3.6 -include $(TOPDIR)/Rules.make
     4.1 --- a/linux-2.4.29-xen-sparse/arch/xen/drivers/usbif/frontend/Makefile	Sat May 21 10:12:11 2005 +0000
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,3 +0,0 @@
     4.4 -O_TARGET := drv.o
     4.5 -obj-y := main.o
     4.6 -include $(TOPDIR)/Rules.make
     5.1 --- a/linux-2.4.29-xen-sparse/arch/xen/kernel/ioport.c	Sat May 21 10:12:11 2005 +0000
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,43 +0,0 @@
     5.4 -#include <linux/sched.h>
     5.5 -#include <linux/kernel.h>
     5.6 -#include <linux/errno.h>
     5.7 -#include <linux/types.h>
     5.8 -#include <linux/ioport.h>
     5.9 -#include <linux/mm.h>
    5.10 -#include <linux/smp.h>
    5.11 -#include <linux/smp_lock.h>
    5.12 -#include <linux/stddef.h>
    5.13 -#include <linux/slab.h>
    5.14 -#include <asm-xen/xen-public/physdev.h>
    5.15 -
    5.16 -asmlinkage long sys_iopl(unsigned int new_io_pl)
    5.17 -{
    5.18 -    unsigned int old_io_pl = current->thread.io_pl;
    5.19 -    physdev_op_t op;
    5.20 -
    5.21 -    if (new_io_pl > 3)
    5.22 -        return -EINVAL;
    5.23 -
    5.24 -	/* Need "raw I/O" privileges for direct port access. */
    5.25 -    if ((new_io_pl > old_io_pl) && !capable(CAP_SYS_RAWIO))
    5.26 -        return -EPERM;
    5.27 -
    5.28 -	/* Maintain OS privileges even if user attempts to relinquish them. */
    5.29 -    if (new_io_pl == 0)
    5.30 -        new_io_pl = 1;
    5.31 -
    5.32 -	/* Change our version of the privilege levels. */
    5.33 -    current->thread.io_pl = new_io_pl;
    5.34 -
    5.35 -    /* Force the change at ring 0. */
    5.36 -    op.cmd             = PHYSDEVOP_SET_IOPL;
    5.37 -    op.u.set_iopl.iopl = new_io_pl;
    5.38 -    HYPERVISOR_physdev_op(&op);
    5.39 -
    5.40 -    return 0;
    5.41 -}
    5.42 -
    5.43 -asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
    5.44 -{
    5.45 -    return turn_on ? sys_iopl(3) : 0;
    5.46 -}
     6.1 --- a/linux-2.4.29-xen-sparse/arch/xen/kernel/pci-dma.c	Sat May 21 10:12:11 2005 +0000
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,137 +0,0 @@
     6.4 -/*
     6.5 - * Dynamic DMA mapping support.
     6.6 - *
     6.7 - * On i386 there is no hardware dynamic DMA address translation,
     6.8 - * so consistent alloc/free are merely page allocation/freeing.
     6.9 - * The rest of the dynamic DMA mapping interface is implemented
    6.10 - * in asm/pci.h.
    6.11 - */
    6.12 -
    6.13 -#include <linux/types.h>
    6.14 -#include <linux/mm.h>
    6.15 -#include <linux/string.h>
    6.16 -#include <linux/pci.h>
    6.17 -#include <linux/version.h>
    6.18 -#include <asm/io.h>
    6.19 -#include <asm-xen/balloon.h>
    6.20 -
    6.21 -#define pte_offset_kernel pte_offset
    6.22 -
    6.23 -struct dma_coherent_mem {
    6.24 -	void		*virt_base;
    6.25 -	u32		device_base;
    6.26 -	int		size;
    6.27 -	int		flags;
    6.28 -	unsigned long	*bitmap;
    6.29 -};
    6.30 -
    6.31 -static void
    6.32 -xen_contig_memory(unsigned long vstart, unsigned int order)
    6.33 -{
    6.34 -	/*
    6.35 -	 * Ensure multi-page extents are contiguous in machine memory.
    6.36 -	 * This code could be cleaned up some, and the number of
    6.37 -	 * hypercalls reduced.
    6.38 -	 */
    6.39 -	pgd_t         *pgd; 
    6.40 -	pmd_t         *pmd;
    6.41 -	pte_t         *pte;
    6.42 -	unsigned long  pfn, i, flags;
    6.43 -
    6.44 -	scrub_pages(vstart, 1 << order);
    6.45 -
    6.46 -        balloon_lock(flags);
    6.47 -
    6.48 -	/* 1. Zap current PTEs, giving away the underlying pages. */
    6.49 -	for (i = 0; i < (1<<order); i++) {
    6.50 -		pgd = pgd_offset_k(   (vstart + (i*PAGE_SIZE)));
    6.51 -		pmd = pmd_offset(pgd, (vstart + (i*PAGE_SIZE)));
    6.52 -		pte = pte_offset_kernel(pmd, (vstart + (i*PAGE_SIZE)));
    6.53 -		pfn = pte->pte_low >> PAGE_SHIFT;
    6.54 -		HYPERVISOR_update_va_mapping(
    6.55 -			vstart + (i*PAGE_SIZE), __pte_ma(0), 0);
    6.56 -		phys_to_machine_mapping[(__pa(vstart)>>PAGE_SHIFT)+i] =
    6.57 -			INVALID_P2M_ENTRY;
    6.58 -		if (HYPERVISOR_dom_mem_op(MEMOP_decrease_reservation, 
    6.59 -					  &pfn, 1, 0) != 1) BUG();
    6.60 -	}
    6.61 -	/* 2. Get a new contiguous memory extent. */
    6.62 -	if (HYPERVISOR_dom_mem_op(MEMOP_increase_reservation,
    6.63 -				  &pfn, 1, order) != 1) BUG();
    6.64 -	/* 3. Map the new extent in place of old pages. */
    6.65 -	for (i = 0; i < (1<<order); i++) {
    6.66 -		pgd = pgd_offset_k(   (vstart + (i*PAGE_SIZE)));
    6.67 -		pmd = pmd_offset(pgd, (vstart + (i*PAGE_SIZE)));
    6.68 -		pte = pte_offset_kernel(pmd, (vstart + (i*PAGE_SIZE)));
    6.69 -		HYPERVISOR_update_va_mapping(
    6.70 -			vstart + (i*PAGE_SIZE),
    6.71 -			__pte_ma(((pfn+i)<<PAGE_SHIFT)|__PAGE_KERNEL), 0);
    6.72 -		xen_machphys_update(
    6.73 -			pfn+i, (__pa(vstart)>>PAGE_SHIFT)+i);
    6.74 -		phys_to_machine_mapping[(__pa(vstart)>>PAGE_SHIFT)+i] =
    6.75 -			pfn+i;
    6.76 -	}
    6.77 -	/* Flush updates through and flush the TLB. */
    6.78 -	flush_tlb_all();
    6.79 -
    6.80 -        balloon_unlock(flags);
    6.81 -}
    6.82 -
    6.83 -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
    6.84 -void *pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
    6.85 -			   dma_addr_t *dma_handle)
    6.86 -#else
    6.87 -void *dma_alloc_coherent(struct device *dev, size_t size,
    6.88 -			   dma_addr_t *dma_handle, int gfp)
    6.89 -#endif
    6.90 -{
    6.91 -	void *ret;
    6.92 -	unsigned int order = get_order(size);
    6.93 -	unsigned long vstart;
    6.94 -
    6.95 -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
    6.96 -	int gfp = GFP_ATOMIC;
    6.97 -
    6.98 -	if (hwdev == NULL || ((u32)hwdev->dma_mask < 0xffffffff))
    6.99 -		gfp |= GFP_DMA;
   6.100 -#else
   6.101 -	struct dma_coherent_mem *mem = dev ? dev->dma_mem : NULL;
   6.102 -
   6.103 -	/* ignore region specifiers */
   6.104 -	gfp &= ~(__GFP_DMA | __GFP_HIGHMEM);
   6.105 -
   6.106 -	if (mem) {
   6.107 -		int page = bitmap_find_free_region(mem->bitmap, mem->size,
   6.108 -						     order);
   6.109 -		if (page >= 0) {
   6.110 -			*dma_handle = mem->device_base + (page << PAGE_SHIFT);
   6.111 -			ret = mem->virt_base + (page << PAGE_SHIFT);
   6.112 -			memset(ret, 0, size);
   6.113 -			return ret;
   6.114 -		}
   6.115 -		if (mem->flags & DMA_MEMORY_EXCLUSIVE)
   6.116 -			return NULL;
   6.117 -	}
   6.118 -
   6.119 -	if (dev == NULL || (dev->coherent_dma_mask < 0xffffffff))
   6.120 -		gfp |= GFP_DMA;
   6.121 -#endif
   6.122 -
   6.123 -	vstart = __get_free_pages(gfp, order);
   6.124 -	ret = (void *)vstart;
   6.125 -	if (ret == NULL)
   6.126 -		return ret;
   6.127 -
   6.128 -	xen_contig_memory(vstart, order);
   6.129 -
   6.130 -	memset(ret, 0, size);
   6.131 -	*dma_handle = virt_to_bus(ret);
   6.132 -
   6.133 -	return ret;
   6.134 -}
   6.135 -
   6.136 -void pci_free_consistent(struct pci_dev *hwdev, size_t size,
   6.137 -			 void *vaddr, dma_addr_t dma_handle)
   6.138 -{
   6.139 -	free_pages((unsigned long)vaddr, get_order(size));
   6.140 -}
     7.1 --- a/linux-2.4.29-xen-sparse/drivers/usb/hcd.c	Sat May 21 10:12:11 2005 +0000
     7.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.3 @@ -1,1511 +0,0 @@
     7.4 -/*
     7.5 - * Copyright (c) 2001-2002 by David Brownell
     7.6 - * 
     7.7 - * This program is free software; you can redistribute it and/or modify it
     7.8 - * under the terms of the GNU General Public License as published by the
     7.9 - * Free Software Foundation; either version 2 of the License, or (at your
    7.10 - * option) any later version.
    7.11 - *
    7.12 - * This program is distributed in the hope that it will be useful, but
    7.13 - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
    7.14 - * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    7.15 - * for more details.
    7.16 - *
    7.17 - * You should have received a copy of the GNU General Public License
    7.18 - * along with this program; if not, write to the Free Software Foundation,
    7.19 - * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    7.20 - */
    7.21 -
    7.22 -#include <linux/config.h>
    7.23 -#include <linux/module.h>
    7.24 -#include <linux/pci.h>
    7.25 -#include <linux/kernel.h>
    7.26 -#include <linux/delay.h>
    7.27 -#include <linux/ioport.h>
    7.28 -#include <linux/sched.h>
    7.29 -#include <linux/slab.h>
    7.30 -#include <linux/smp_lock.h>
    7.31 -#include <linux/errno.h>
    7.32 -#include <linux/kmod.h>
    7.33 -#include <linux/init.h>
    7.34 -#include <linux/timer.h>
    7.35 -#include <linux/list.h>
    7.36 -#include <linux/interrupt.h>
    7.37 -#include <linux/completion.h>
    7.38 -#include <linux/uts.h>			/* for UTS_SYSNAME */
    7.39 -
    7.40 -
    7.41 -#ifdef CONFIG_USB_DEBUG
    7.42 -	#define DEBUG
    7.43 -#else
    7.44 -	#undef DEBUG
    7.45 -#endif
    7.46 -
    7.47 -#include <linux/usb.h>
    7.48 -#include "hcd.h"
    7.49 -
    7.50 -#include <asm/io.h>
    7.51 -#include <asm/irq.h>
    7.52 -#include <asm/system.h>
    7.53 -#include <asm/unaligned.h>
    7.54 -
    7.55 -
    7.56 -/*-------------------------------------------------------------------------*/
    7.57 -
    7.58 -/*
    7.59 - * USB Host Controller Driver framework
    7.60 - *
    7.61 - * Plugs into usbcore (usb_bus) and lets HCDs share code, minimizing
    7.62 - * HCD-specific behaviors/bugs.  Think of it as the "upper level" of
    7.63 - * some drivers, where the "lower level" is hardware-specific.
    7.64 - *
    7.65 - * This does error checks, tracks devices and urbs, and delegates to a
    7.66 - * "hc_driver" only for code (and data) that really needs to know about
    7.67 - * hardware differences.  That includes root hub registers, i/o queues,
    7.68 - * and so on ... but as little else as possible.
    7.69 - *
    7.70 - * Shared code includes most of the "root hub" code (these are emulated,
    7.71 - * though each HC's hardware works differently) and PCI glue, plus request
    7.72 - * tracking overhead.  The HCD code should only block on spinlocks or on
    7.73 - * hardware handshaking; blocking on software events (such as other kernel
    7.74 - * threads releasing resources, or completing actions) is all generic.
    7.75 - *
    7.76 - * Happens the USB 2.0 spec says this would be invisible inside the "USBD",
    7.77 - * and includes mostly a "HCDI" (HCD Interface) along with some APIs used
    7.78 - * only by the hub driver ... and that neither should be seen or used by
    7.79 - * usb client device drivers.
    7.80 - *
    7.81 - * Contributors of ideas or unattributed patches include: David Brownell,
    7.82 - * Roman Weissgaerber, Rory Bolt, ...
    7.83 - *
    7.84 - * HISTORY:
    7.85 - * 2002-sept	Merge some 2.5 updates so we can share hardware level HCD
    7.86 - * 	code between the 2.4.20+ and 2.5 trees.
    7.87 - * 2002-feb	merge to 2.4.19
    7.88 - * 2001-12-12	Initial patch version for Linux 2.5.1 kernel.
    7.89 - */
    7.90 -
    7.91 -/*-------------------------------------------------------------------------*/
    7.92 -
    7.93 -/* host controllers we manage */
    7.94 -static LIST_HEAD (hcd_list);
    7.95 -
    7.96 -/* used when updating list of hcds */
    7.97 -static DECLARE_MUTEX (hcd_list_lock);
    7.98 -
    7.99 -/* used when updating hcd data */
   7.100 -static spinlock_t hcd_data_lock = SPIN_LOCK_UNLOCKED;
   7.101 -
   7.102 -static struct usb_operations hcd_operations;
   7.103 -
   7.104 -/*-------------------------------------------------------------------------*/
   7.105 -
   7.106 -/*
   7.107 - * Sharable chunks of root hub code.
   7.108 - */
   7.109 -
   7.110 -/*-------------------------------------------------------------------------*/
   7.111 -
   7.112 -#define KERNEL_REL	((LINUX_VERSION_CODE >> 16) & 0x0ff)
   7.113 -#define KERNEL_VER	((LINUX_VERSION_CODE >> 8) & 0x0ff)
   7.114 -
   7.115 -/* usb 2.0 root hub device descriptor */
   7.116 -static const u8 usb2_rh_dev_descriptor [18] = {
   7.117 -	0x12,       /*  __u8  bLength; */
   7.118 -	0x01,       /*  __u8  bDescriptorType; Device */
   7.119 -	0x00, 0x02, /*  __u16 bcdUSB; v2.0 */
   7.120 -
   7.121 -	0x09,	    /*  __u8  bDeviceClass; HUB_CLASSCODE */
   7.122 -	0x00,	    /*  __u8  bDeviceSubClass; */
   7.123 -	0x01,       /*  __u8  bDeviceProtocol; [ usb 2.0 single TT ]*/
   7.124 -	0x08,       /*  __u8  bMaxPacketSize0; 8 Bytes */
   7.125 -
   7.126 -	0x00, 0x00, /*  __u16 idVendor; */
   7.127 - 	0x00, 0x00, /*  __u16 idProduct; */
   7.128 -	KERNEL_VER, KERNEL_REL, /*  __u16 bcdDevice */
   7.129 -
   7.130 -	0x03,       /*  __u8  iManufacturer; */
   7.131 -	0x02,       /*  __u8  iProduct; */
   7.132 -	0x01,       /*  __u8  iSerialNumber; */
   7.133 -	0x01        /*  __u8  bNumConfigurations; */
   7.134 -};
   7.135 -
   7.136 -/* no usb 2.0 root hub "device qualifier" descriptor: one speed only */
   7.137 -
   7.138 -/* usb 1.1 root hub device descriptor */
   7.139 -static const u8 usb11_rh_dev_descriptor [18] = {
   7.140 -	0x12,       /*  __u8  bLength; */
   7.141 -	0x01,       /*  __u8  bDescriptorType; Device */
   7.142 -	0x10, 0x01, /*  __u16 bcdUSB; v1.1 */
   7.143 -
   7.144 -	0x09,	    /*  __u8  bDeviceClass; HUB_CLASSCODE */
   7.145 -	0x00,	    /*  __u8  bDeviceSubClass; */
   7.146 -	0x00,       /*  __u8  bDeviceProtocol; [ low/full speeds only ] */
   7.147 -	0x08,       /*  __u8  bMaxPacketSize0; 8 Bytes */
   7.148 -
   7.149 -	0x00, 0x00, /*  __u16 idVendor; */
   7.150 - 	0x00, 0x00, /*  __u16 idProduct; */
   7.151 -	KERNEL_VER, KERNEL_REL, /*  __u16 bcdDevice */
   7.152 -
   7.153 -	0x03,       /*  __u8  iManufacturer; */
   7.154 -	0x02,       /*  __u8  iProduct; */
   7.155 -	0x01,       /*  __u8  iSerialNumber; */
   7.156 -	0x01        /*  __u8  bNumConfigurations; */
   7.157 -};
   7.158 -
   7.159 -
   7.160 -/*-------------------------------------------------------------------------*/
   7.161 -
   7.162 -/* Configuration descriptors for our root hubs */
   7.163 -
   7.164 -static const u8 fs_rh_config_descriptor [] = {
   7.165 -
   7.166 -	/* one configuration */
   7.167 -	0x09,       /*  __u8  bLength; */
   7.168 -	0x02,       /*  __u8  bDescriptorType; Configuration */
   7.169 -	0x19, 0x00, /*  __u16 wTotalLength; */
   7.170 -	0x01,       /*  __u8  bNumInterfaces; (1) */
   7.171 -	0x01,       /*  __u8  bConfigurationValue; */
   7.172 -	0x00,       /*  __u8  iConfiguration; */
   7.173 -	0x40,       /*  __u8  bmAttributes; 
   7.174 -				 Bit 7: Bus-powered,
   7.175 -				     6: Self-powered,
   7.176 -				     5 Remote-wakwup,
   7.177 -				     4..0: resvd */
   7.178 -	0x00,       /*  __u8  MaxPower; */
   7.179 -      
   7.180 -	/* USB 1.1:
   7.181 -	 * USB 2.0, single TT organization (mandatory):
   7.182 -	 *	one interface, protocol 0
   7.183 -	 *
   7.184 -	 * USB 2.0, multiple TT organization (optional):
   7.185 -	 *	two interfaces, protocols 1 (like single TT)
   7.186 -	 *	and 2 (multiple TT mode) ... config is
   7.187 -	 *	sometimes settable
   7.188 -	 *	NOT IMPLEMENTED
   7.189 -	 */
   7.190 -
   7.191 -	/* one interface */
   7.192 -	0x09,       /*  __u8  if_bLength; */
   7.193 -	0x04,       /*  __u8  if_bDescriptorType; Interface */
   7.194 -	0x00,       /*  __u8  if_bInterfaceNumber; */
   7.195 -	0x00,       /*  __u8  if_bAlternateSetting; */
   7.196 -	0x01,       /*  __u8  if_bNumEndpoints; */
   7.197 -	0x09,       /*  __u8  if_bInterfaceClass; HUB_CLASSCODE */
   7.198 -	0x00,       /*  __u8  if_bInterfaceSubClass; */
   7.199 -	0x00,       /*  __u8  if_bInterfaceProtocol; [usb1.1 or single tt] */
   7.200 -	0x00,       /*  __u8  if_iInterface; */
   7.201 -     
   7.202 -	/* one endpoint (status change endpoint) */
   7.203 -	0x07,       /*  __u8  ep_bLength; */
   7.204 -	0x05,       /*  __u8  ep_bDescriptorType; Endpoint */
   7.205 -	0x81,       /*  __u8  ep_bEndpointAddress; IN Endpoint 1 */
   7.206 - 	0x03,       /*  __u8  ep_bmAttributes; Interrupt */
   7.207 - 	0x02, 0x00, /*  __u16 ep_wMaxPacketSize; 1 + (MAX_ROOT_PORTS / 8) */
   7.208 -	0xff        /*  __u8  ep_bInterval; (255ms -- usb 2.0 spec) */
   7.209 -};
   7.210 -
   7.211 -static const u8 hs_rh_config_descriptor [] = {
   7.212 -
   7.213 -	/* one configuration */
   7.214 -	0x09,       /*  __u8  bLength; */
   7.215 -	0x02,       /*  __u8  bDescriptorType; Configuration */
   7.216 -	0x19, 0x00, /*  __u16 wTotalLength; */
   7.217 -	0x01,       /*  __u8  bNumInterfaces; (1) */
   7.218 -	0x01,       /*  __u8  bConfigurationValue; */
   7.219 -	0x00,       /*  __u8  iConfiguration; */
   7.220 -	0x40,       /*  __u8  bmAttributes; 
   7.221 -				 Bit 7: Bus-powered,
   7.222 -				     6: Self-powered,
   7.223 -				     5 Remote-wakwup,
   7.224 -				     4..0: resvd */
   7.225 -	0x00,       /*  __u8  MaxPower; */
   7.226 -      
   7.227 -	/* USB 1.1:
   7.228 -	 * USB 2.0, single TT organization (mandatory):
   7.229 -	 *	one interface, protocol 0
   7.230 -	 *
   7.231 -	 * USB 2.0, multiple TT organization (optional):
   7.232 -	 *	two interfaces, protocols 1 (like single TT)
   7.233 -	 *	and 2 (multiple TT mode) ... config is
   7.234 -	 *	sometimes settable
   7.235 -	 *	NOT IMPLEMENTED
   7.236 -	 */
   7.237 -
   7.238 -	/* one interface */
   7.239 -	0x09,       /*  __u8  if_bLength; */
   7.240 -	0x04,       /*  __u8  if_bDescriptorType; Interface */
   7.241 -	0x00,       /*  __u8  if_bInterfaceNumber; */
   7.242 -	0x00,       /*  __u8  if_bAlternateSetting; */
   7.243 -	0x01,       /*  __u8  if_bNumEndpoints; */
   7.244 -	0x09,       /*  __u8  if_bInterfaceClass; HUB_CLASSCODE */
   7.245 -	0x00,       /*  __u8  if_bInterfaceSubClass; */
   7.246 -	0x00,       /*  __u8  if_bInterfaceProtocol; [usb1.1 or single tt] */
   7.247 -	0x00,       /*  __u8  if_iInterface; */
   7.248 -     
   7.249 -	/* one endpoint (status change endpoint) */
   7.250 -	0x07,       /*  __u8  ep_bLength; */
   7.251 -	0x05,       /*  __u8  ep_bDescriptorType; Endpoint */
   7.252 -	0x81,       /*  __u8  ep_bEndpointAddress; IN Endpoint 1 */
   7.253 - 	0x03,       /*  __u8  ep_bmAttributes; Interrupt */
   7.254 - 	0x02, 0x00, /*  __u16 ep_wMaxPacketSize; 1 + (MAX_ROOT_PORTS / 8) */
   7.255 -	0x0c        /*  __u8  ep_bInterval; (256ms -- usb 2.0 spec) */
   7.256 -};
   7.257 -
   7.258 -/*-------------------------------------------------------------------------*/
   7.259 -
   7.260 -/*
   7.261 - * helper routine for returning string descriptors in UTF-16LE
   7.262 - * input can actually be ISO-8859-1; ASCII is its 7-bit subset
   7.263 - */
   7.264 -static int ascii2utf (char *s, u8 *utf, int utfmax)
   7.265 -{
   7.266 -	int retval;
   7.267 -
   7.268 -	for (retval = 0; *s && utfmax > 1; utfmax -= 2, retval += 2) {
   7.269 -		*utf++ = *s++;
   7.270 -		*utf++ = 0;
   7.271 -	}
   7.272 -	return retval;
   7.273 -}
   7.274 -
   7.275 -/*
   7.276 - * rh_string - provides manufacturer, product and serial strings for root hub
   7.277 - * @id: the string ID number (1: serial number, 2: product, 3: vendor)
   7.278 - * @pci_desc: PCI device descriptor for the relevant HC
   7.279 - * @type: string describing our driver 
   7.280 - * @data: return packet in UTF-16 LE
   7.281 - * @len: length of the return packet
   7.282 - *
   7.283 - * Produces either a manufacturer, product or serial number string for the
   7.284 - * virtual root hub device.
   7.285 - */
   7.286 -static int rh_string (
   7.287 -	int		id,
   7.288 -	struct usb_hcd	*hcd,
   7.289 -	u8		*data,
   7.290 -	int		len
   7.291 -) {
   7.292 -	char buf [100];
   7.293 -
   7.294 -	// language ids
   7.295 -	if (id == 0) {
   7.296 -		*data++ = 4; *data++ = 3;	/* 4 bytes string data */
   7.297 -		*data++ = 0; *data++ = 0;	/* some language id */
   7.298 -		return 4;
   7.299 -
   7.300 -	// serial number
   7.301 -	} else if (id == 1) {
   7.302 -		strcpy (buf, hcd->bus->bus_name);
   7.303 -
   7.304 -	// product description
   7.305 -	} else if (id == 2) {
   7.306 -                strcpy (buf, hcd->product_desc);
   7.307 -
   7.308 - 	// id 3 == vendor description
   7.309 -	} else if (id == 3) {
   7.310 -                sprintf (buf, "%s %s %s", UTS_SYSNAME, UTS_RELEASE,
   7.311 -			hcd->description);
   7.312 -
   7.313 -	// unsupported IDs --> "protocol stall"
   7.314 -	} else
   7.315 -	    return 0;
   7.316 -
   7.317 -	data [0] = 2 * (strlen (buf) + 1);
   7.318 -	data [1] = 3;	/* type == string */
   7.319 -	return 2 + ascii2utf (buf, data + 2, len - 2);
   7.320 -}
   7.321 -
   7.322 -
   7.323 -/* Root hub control transfers execute synchronously */
   7.324 -static int rh_call_control (struct usb_hcd *hcd, struct urb *urb)
   7.325 -{
   7.326 -	struct usb_ctrlrequest *cmd = (struct usb_ctrlrequest *) urb->setup_packet;
   7.327 - 	u16		typeReq, wValue, wIndex, wLength;
   7.328 -	const u8	*bufp = 0;
   7.329 -	u8		*ubuf = urb->transfer_buffer;
   7.330 -	int		len = 0;
   7.331 -
   7.332 -	typeReq  = (cmd->bRequestType << 8) | cmd->bRequest;
   7.333 -	wValue   = le16_to_cpu (cmd->wValue);
   7.334 -	wIndex   = le16_to_cpu (cmd->wIndex);
   7.335 -	wLength  = le16_to_cpu (cmd->wLength);
   7.336 -
   7.337 -	if (wLength > urb->transfer_buffer_length)
   7.338 -		goto error;
   7.339 -
   7.340 -	/* set up for success */
   7.341 -	urb->status = 0;
   7.342 -	urb->actual_length = wLength;
   7.343 -	switch (typeReq) {
   7.344 -
   7.345 -	/* DEVICE REQUESTS */
   7.346 -
   7.347 -	case DeviceRequest | USB_REQ_GET_STATUS:
   7.348 -		// DEVICE_REMOTE_WAKEUP
   7.349 -		ubuf [0] = 1; // selfpowered
   7.350 -		ubuf [1] = 0;
   7.351 -			/* FALLTHROUGH */
   7.352 -	case DeviceOutRequest | USB_REQ_CLEAR_FEATURE:
   7.353 -	case DeviceOutRequest | USB_REQ_SET_FEATURE:
   7.354 -		dbg ("no device features yet yet");
   7.355 -		break;
   7.356 -	case DeviceRequest | USB_REQ_GET_CONFIGURATION:
   7.357 -		ubuf [0] = 1;
   7.358 -			/* FALLTHROUGH */
   7.359 -	case DeviceOutRequest | USB_REQ_SET_CONFIGURATION:
   7.360 -		break;
   7.361 -	case DeviceRequest | USB_REQ_GET_DESCRIPTOR:
   7.362 -		switch (wValue & 0xff00) {
   7.363 -		case USB_DT_DEVICE << 8:
   7.364 -			if (hcd->driver->flags & HCD_USB2)
   7.365 -				bufp = usb2_rh_dev_descriptor;
   7.366 -			else if (hcd->driver->flags & HCD_USB11)
   7.367 -				bufp = usb11_rh_dev_descriptor;
   7.368 -			else
   7.369 -				goto error;
   7.370 -			len = 18;
   7.371 -			break;
   7.372 -		case USB_DT_CONFIG << 8:
   7.373 -			if (hcd->driver->flags & HCD_USB2) {
   7.374 -				bufp = hs_rh_config_descriptor;
   7.375 -				len = sizeof hs_rh_config_descriptor;
   7.376 -			} else {
   7.377 -				bufp = fs_rh_config_descriptor;
   7.378 -				len = sizeof fs_rh_config_descriptor;
   7.379 -			}
   7.380 -			break;
   7.381 -		case USB_DT_STRING << 8:
   7.382 -			urb->actual_length = rh_string (
   7.383 -				wValue & 0xff, hcd,
   7.384 -				ubuf, wLength);
   7.385 -			break;
   7.386 -		default:
   7.387 -			goto error;
   7.388 -		}
   7.389 -		break;
   7.390 -	case DeviceRequest | USB_REQ_GET_INTERFACE:
   7.391 -		ubuf [0] = 0;
   7.392 -			/* FALLTHROUGH */
   7.393 -	case DeviceOutRequest | USB_REQ_SET_INTERFACE:
   7.394 -		break;
   7.395 -	case DeviceOutRequest | USB_REQ_SET_ADDRESS:
   7.396 -		// wValue == urb->dev->devaddr
   7.397 -		dbg ("%s root hub device address %d",
   7.398 -			hcd->bus->bus_name, wValue);
   7.399 -		break;
   7.400 -
   7.401 -	/* INTERFACE REQUESTS (no defined feature/status flags) */
   7.402 -
   7.403 -	/* ENDPOINT REQUESTS */
   7.404 -
   7.405 -	case EndpointRequest | USB_REQ_GET_STATUS:
   7.406 -		// ENDPOINT_HALT flag
   7.407 -		ubuf [0] = 0;
   7.408 -		ubuf [1] = 0;
   7.409 -			/* FALLTHROUGH */
   7.410 -	case EndpointOutRequest | USB_REQ_CLEAR_FEATURE:
   7.411 -	case EndpointOutRequest | USB_REQ_SET_FEATURE:
   7.412 -		dbg ("no endpoint features yet");
   7.413 -		break;
   7.414 -
   7.415 -	/* CLASS REQUESTS (and errors) */
   7.416 -
   7.417 -	default:
   7.418 -		/* non-generic request */
   7.419 -		urb->status = hcd->driver->hub_control (hcd,
   7.420 -			typeReq, wValue, wIndex,
   7.421 -			ubuf, wLength);
   7.422 -		break;
   7.423 -error:
   7.424 -		/* "protocol stall" on error */
   7.425 -		urb->status = -EPIPE;
   7.426 -		dbg ("unsupported hub control message (maxchild %d)",
   7.427 -				urb->dev->maxchild);
   7.428 -	}
   7.429 -	if (urb->status) {
   7.430 -		urb->actual_length = 0;
   7.431 -		dbg ("CTRL: TypeReq=0x%x val=0x%x idx=0x%x len=%d ==> %d",
   7.432 -			typeReq, wValue, wIndex, wLength, urb->status);
   7.433 -	}
   7.434 -	if (bufp) {
   7.435 -		if (urb->transfer_buffer_length < len)
   7.436 -			len = urb->transfer_buffer_length;
   7.437 -		urb->actual_length = len;
   7.438 -		// always USB_DIR_IN, toward host
   7.439 -		memcpy (ubuf, bufp, len);
   7.440 -	}
   7.441 -
   7.442 -	/* any errors get returned through the urb completion */
   7.443 -	usb_hcd_giveback_urb (hcd, urb, 0);
   7.444 -	return 0;
   7.445 -}
   7.446 -
   7.447 -/*-------------------------------------------------------------------------*/
   7.448 -
   7.449 -/*
   7.450 - * Root Hub interrupt transfers are synthesized with a timer.
   7.451 - * Completions are called in_interrupt() but not in_irq().
   7.452 - */
   7.453 -
   7.454 -static void rh_report_status (unsigned long ptr);
   7.455 -
   7.456 -static int rh_status_urb (struct usb_hcd *hcd, struct urb *urb) 
   7.457 -{
   7.458 -	int	len = 1 + (urb->dev->maxchild / 8);
   7.459 -
   7.460 -	/* rh_timer protected by hcd_data_lock */
   7.461 -	if (timer_pending (&hcd->rh_timer)
   7.462 -			|| urb->status != -EINPROGRESS
   7.463 -			|| !HCD_IS_RUNNING (hcd->state)
   7.464 -			|| urb->transfer_buffer_length < len) {
   7.465 -		dbg ("not queuing status urb, stat %d", urb->status);
   7.466 -		return -EINVAL;
   7.467 -	}
   7.468 -
   7.469 -	urb->hcpriv = hcd;	/* nonzero to indicate it's queued */
   7.470 -	init_timer (&hcd->rh_timer);
   7.471 -	hcd->rh_timer.function = rh_report_status;
   7.472 -	hcd->rh_timer.data = (unsigned long) urb;
   7.473 -	/* USB 2.0 spec says 256msec; this is close enough */
   7.474 -	hcd->rh_timer.expires = jiffies + HZ/4;
   7.475 -	add_timer (&hcd->rh_timer);
   7.476 -	return 0;
   7.477 -}
   7.478 -
   7.479 -/* timer callback */
   7.480 -
   7.481 -static void rh_report_status (unsigned long ptr)
   7.482 -{
   7.483 -	struct urb	*urb;
   7.484 -	struct usb_hcd	*hcd;
   7.485 -	int		length;
   7.486 -	unsigned long	flags;
   7.487 -
   7.488 -	urb = (struct urb *) ptr;
   7.489 -	spin_lock_irqsave (&urb->lock, flags);
   7.490 -	if (!urb->dev) {
   7.491 -		spin_unlock_irqrestore (&urb->lock, flags);
   7.492 -		return;
   7.493 -	}
   7.494 -
   7.495 -	hcd = urb->dev->bus->hcpriv;
   7.496 -	if (urb->status == -EINPROGRESS) {
   7.497 -		if (HCD_IS_RUNNING (hcd->state)) {
   7.498 -			length = hcd->driver->hub_status_data (hcd,
   7.499 -					urb->transfer_buffer);
   7.500 -			spin_unlock_irqrestore (&urb->lock, flags);
   7.501 -			if (length > 0) {
   7.502 -				urb->actual_length = length;
   7.503 -				urb->status = 0;
   7.504 -				urb->complete (urb);
   7.505 -			}
   7.506 -			spin_lock_irqsave (&hcd_data_lock, flags);
   7.507 -			urb->status = -EINPROGRESS;
   7.508 -			if (HCD_IS_RUNNING (hcd->state)
   7.509 -					&& rh_status_urb (hcd, urb) != 0) {
   7.510 -				/* another driver snuck in? */
   7.511 -				dbg ("%s, can't resubmit roothub status urb?",
   7.512 -					hcd->bus->bus_name);
   7.513 -				spin_unlock_irqrestore (&hcd_data_lock, flags);
   7.514 -				BUG ();
   7.515 -			}
   7.516 -			spin_unlock_irqrestore (&hcd_data_lock, flags);
   7.517 -		} else
   7.518 -			spin_unlock_irqrestore (&urb->lock, flags);
   7.519 -	} else {
   7.520 -		/* this urb's been unlinked */
   7.521 -		urb->hcpriv = 0;
   7.522 -		spin_unlock_irqrestore (&urb->lock, flags);
   7.523 -
   7.524 -		usb_hcd_giveback_urb (hcd, urb, 0);
   7.525 -	}
   7.526 -}
   7.527 -
   7.528 -/*-------------------------------------------------------------------------*/
   7.529 -
   7.530 -static int rh_urb_enqueue (struct usb_hcd *hcd, struct urb *urb)
   7.531 -{
   7.532 -	if (usb_pipeint (urb->pipe)) {
   7.533 -		int		retval;
   7.534 -		unsigned long	flags;
   7.535 -
   7.536 -		spin_lock_irqsave (&hcd_data_lock, flags);
   7.537 -		retval = rh_status_urb (hcd, urb);
   7.538 -		spin_unlock_irqrestore (&hcd_data_lock, flags);
   7.539 -		return retval;
   7.540 -	}
   7.541 -	if (usb_pipecontrol (urb->pipe))
   7.542 -		return rh_call_control (hcd, urb);
   7.543 -	else
   7.544 -		return -EINVAL;
   7.545 -}
   7.546 -
   7.547 -/*-------------------------------------------------------------------------*/
   7.548 -
   7.549 -static void rh_status_dequeue (struct usb_hcd *hcd, struct urb *urb)
   7.550 -{
   7.551 -	unsigned long	flags;
   7.552 -
   7.553 -	spin_lock_irqsave (&hcd_data_lock, flags);
   7.554 -	del_timer_sync (&hcd->rh_timer);
   7.555 -	hcd->rh_timer.data = 0;
   7.556 -	spin_unlock_irqrestore (&hcd_data_lock, flags);
   7.557 -
   7.558 -	/* we rely on RH callback code not unlinking its URB! */
   7.559 -	usb_hcd_giveback_urb (hcd, urb, 0);
   7.560 -}
   7.561 -
   7.562 -/*-------------------------------------------------------------------------*/
   7.563 -
   7.564 -#ifdef CONFIG_PCI
   7.565 -
   7.566 -/* PCI-based HCs are normal, but custom bus glue should be ok */
   7.567 -
   7.568 -static void hcd_irq (int irq, void *__hcd, struct pt_regs *r);
   7.569 -static void hc_died (struct usb_hcd *hcd);
   7.570 -
   7.571 -/*-------------------------------------------------------------------------*/
   7.572 -
   7.573 -/* configure so an HC device and id are always provided */
   7.574 -/* always called with process context; sleeping is OK */
   7.575 -
   7.576 -/**
   7.577 - * usb_hcd_pci_probe - initialize PCI-based HCDs
   7.578 - * @dev: USB Host Controller being probed
   7.579 - * @id: pci hotplug id connecting controller to HCD framework
   7.580 - * Context: !in_interrupt()
   7.581 - *
   7.582 - * Allocates basic PCI resources for this USB host controller, and
   7.583 - * then invokes the start() method for the HCD associated with it
   7.584 - * through the hotplug entry's driver_data.
   7.585 - *
   7.586 - * Store this function in the HCD's struct pci_driver as probe().
   7.587 - */
   7.588 -int usb_hcd_pci_probe (struct pci_dev *dev, const struct pci_device_id *id)
   7.589 -{
   7.590 -	struct hc_driver	*driver;
   7.591 -	unsigned long		resource, len;
   7.592 -	void			*base;
   7.593 -	struct usb_bus		*bus;
   7.594 -	struct usb_hcd		*hcd;
   7.595 -	int			retval, region;
   7.596 -	char			buf [8], *bufp = buf;
   7.597 -
   7.598 -	if (!id || !(driver = (struct hc_driver *) id->driver_data))
   7.599 -		return -EINVAL;
   7.600 -
   7.601 -	if (pci_enable_device (dev) < 0)
   7.602 -		return -ENODEV;
   7.603 -	
   7.604 -        if (!dev->irq) {
   7.605 -        	err ("Found HC with no IRQ.  Check BIOS/PCI %s setup!",
   7.606 -			dev->slot_name);
   7.607 -   	        return -ENODEV;
   7.608 -        }
   7.609 -	
   7.610 -	if (driver->flags & HCD_MEMORY) {	// EHCI, OHCI
   7.611 -		region = 0;
   7.612 -		resource = pci_resource_start (dev, 0);
   7.613 -		len = pci_resource_len (dev, 0);
   7.614 -		if (!request_mem_region (resource, len, driver->description)) {
   7.615 -			dbg ("controller already in use");
   7.616 -			return -EBUSY;
   7.617 -		}
   7.618 -		base = ioremap_nocache (resource, len);
   7.619 -		if (base == NULL) {
   7.620 -			dbg ("error mapping memory");
   7.621 -			retval = -EFAULT;
   7.622 -clean_1:
   7.623 -			release_mem_region (resource, len);
   7.624 -			err ("init %s fail, %d", dev->slot_name, retval);
   7.625 -			return retval;
   7.626 -		}
   7.627 -
   7.628 -	} else { 				// UHCI
   7.629 -		resource = len = 0;
   7.630 -		for (region = 0; region < PCI_ROM_RESOURCE; region++) {
   7.631 -			if (!(pci_resource_flags (dev, region) & IORESOURCE_IO))
   7.632 -				continue;
   7.633 -
   7.634 -			resource = pci_resource_start (dev, region);
   7.635 -			len = pci_resource_len (dev, region);
   7.636 -			if (request_region (resource, len,
   7.637 -					driver->description))
   7.638 -				break;
   7.639 -		}
   7.640 -		if (region == PCI_ROM_RESOURCE) {
   7.641 -			dbg ("no i/o regions available");
   7.642 -			return -EBUSY;
   7.643 -		}
   7.644 -		base = (void *) resource;
   7.645 -	}
   7.646 -
   7.647 -	// driver->start(), later on, will transfer device from
   7.648 -	// control by SMM/BIOS to control by Linux (if needed)
   7.649 -
   7.650 -	pci_set_master (dev);
   7.651 -	hcd = driver->hcd_alloc ();
   7.652 -	if (hcd == NULL){
   7.653 -		dbg ("hcd alloc fail");
   7.654 -		retval = -ENOMEM;
   7.655 -clean_2:
   7.656 -		if (driver->flags & HCD_MEMORY) {
   7.657 -			iounmap (base);
   7.658 -			goto clean_1;
   7.659 -		} else {
   7.660 -			release_region (resource, len);
   7.661 -			err ("init %s fail, %d", dev->slot_name, retval);
   7.662 -			return retval;
   7.663 -		}
   7.664 -	}
   7.665 -	pci_set_drvdata(dev, hcd);
   7.666 -	hcd->driver = driver;
   7.667 -	hcd->description = driver->description;
   7.668 -	hcd->pdev = dev;
   7.669 -	printk (KERN_INFO "%s %s: %s\n",
   7.670 -			hcd->description,  dev->slot_name, dev->name);
   7.671 -
   7.672 -#ifndef __sparc__
   7.673 -	sprintf (buf, "%d", dev->irq);
   7.674 -#else
   7.675 -	bufp = __irq_itoa(dev->irq);
   7.676 -#endif
   7.677 -	if (request_irq (dev->irq, hcd_irq, SA_SHIRQ, hcd->description, hcd)
   7.678 -			!= 0) {
   7.679 -		err ("request interrupt %s failed", bufp);
   7.680 -		retval = -EBUSY;
   7.681 -clean_3:
   7.682 -		driver->hcd_free (hcd);
   7.683 -		goto clean_2;
   7.684 -	}
   7.685 -	hcd->irq = dev->irq;
   7.686 -
   7.687 -	hcd->regs = base;
   7.688 -	hcd->region = region;
   7.689 -	printk (KERN_INFO "%s %s: irq %s, %s %p\n",
   7.690 -		hcd->description,  dev->slot_name, bufp,
   7.691 -		(driver->flags & HCD_MEMORY) ? "pci mem" : "io base",
   7.692 -		base);
   7.693 -
   7.694 -// FIXME simpler: make "bus" be that data, not pointer to it.
   7.695 -// (fixed in 2.5)
   7.696 -	bus = usb_alloc_bus (&hcd_operations);
   7.697 -	if (bus == NULL) {
   7.698 -		dbg ("usb_alloc_bus fail");
   7.699 -		retval = -ENOMEM;
   7.700 -		free_irq (dev->irq, hcd);
   7.701 -		goto clean_3;
   7.702 -	}
   7.703 -	hcd->bus = bus;
   7.704 -	bus->bus_name = dev->slot_name;
   7.705 -	hcd->product_desc = dev->name;
   7.706 -	bus->hcpriv = (void *) hcd;
   7.707 -
   7.708 -	INIT_LIST_HEAD (&hcd->dev_list);
   7.709 -	INIT_LIST_HEAD (&hcd->hcd_list);
   7.710 -
   7.711 -	down (&hcd_list_lock);
   7.712 -	list_add (&hcd->hcd_list, &hcd_list);
   7.713 -	up (&hcd_list_lock);
   7.714 -
   7.715 -	usb_register_bus (bus);
   7.716 -
   7.717 -	if ((retval = driver->start (hcd)) < 0)
   7.718 -		usb_hcd_pci_remove (dev);
   7.719 -
   7.720 -	return retval;
   7.721 -} 
   7.722 -EXPORT_SYMBOL (usb_hcd_pci_probe);
   7.723 -
   7.724 -
   7.725 -/* may be called without controller electrically present */
   7.726 -/* may be called with controller, bus, and devices active */
   7.727 -
   7.728 -/**
   7.729 - * usb_hcd_pci_remove - shutdown processing for PCI-based HCDs
   7.730 - * @dev: USB Host Controller being removed
   7.731 - * Context: !in_interrupt()
   7.732 - *
   7.733 - * Reverses the effect of usb_hcd_pci_probe(), first invoking
   7.734 - * the HCD's stop() method.  It is always called from a thread
   7.735 - * context, normally "rmmod", "apmd", or something similar.
   7.736 - *
   7.737 - * Store this function in the HCD's struct pci_driver as remove().
   7.738 - */
   7.739 -void usb_hcd_pci_remove (struct pci_dev *dev)
   7.740 -{
   7.741 -	struct usb_hcd		*hcd;
   7.742 -	struct usb_device	*hub;
   7.743 -
   7.744 -	hcd = pci_get_drvdata(dev);
   7.745 -	if (!hcd)
   7.746 -		return;
   7.747 -	printk (KERN_INFO "%s %s: remove state %x\n",
   7.748 -		hcd->description,  dev->slot_name, hcd->state);
   7.749 -
   7.750 -	if (in_interrupt ()) BUG ();
   7.751 -
   7.752 -	hub = hcd->bus->root_hub;
   7.753 -	hcd->state = USB_STATE_QUIESCING;
   7.754 -
   7.755 -	dbg ("%s: roothub graceful disconnect", hcd->bus->bus_name);
   7.756 -	usb_disconnect (&hub);
   7.757 -	// usb_disconnect (&hcd->bus->root_hub);
   7.758 -
   7.759 -	hcd->driver->stop (hcd);
   7.760 -	hcd->state = USB_STATE_HALT;
   7.761 -
   7.762 -	free_irq (hcd->irq, hcd);
   7.763 -	if (hcd->driver->flags & HCD_MEMORY) {
   7.764 -		iounmap (hcd->regs);
   7.765 -		release_mem_region (pci_resource_start (dev, 0),
   7.766 -			pci_resource_len (dev, 0));
   7.767 -	} else {
   7.768 -		release_region (pci_resource_start (dev, hcd->region),
   7.769 -			pci_resource_len (dev, hcd->region));
   7.770 -	}
   7.771 -
   7.772 -	down (&hcd_list_lock);
   7.773 -	list_del (&hcd->hcd_list);
   7.774 -	up (&hcd_list_lock);
   7.775 -
   7.776 -	usb_deregister_bus (hcd->bus);
   7.777 -	usb_free_bus (hcd->bus);
   7.778 -	hcd->bus = NULL;
   7.779 -
   7.780 -	hcd->driver->hcd_free (hcd);
   7.781 -}
   7.782 -EXPORT_SYMBOL (usb_hcd_pci_remove);
   7.783 -
   7.784 -
   7.785 -#ifdef	CONFIG_PM
   7.786 -
   7.787 -/*
   7.788 - * Some "sleep" power levels imply updating struct usb_driver
   7.789 - * to include a callback asking hcds to do their bit by checking
   7.790 - * if all the drivers can suspend.  Gets involved with remote wakeup.
   7.791 - *
   7.792 - * If there are pending urbs, then HCs will need to access memory,
   7.793 - * causing extra power drain.  New sleep()/wakeup() PM calls might
   7.794 - * be needed, beyond PCI suspend()/resume().  The root hub timer
   7.795 - * still be accessing memory though ...
   7.796 - *
   7.797 - * FIXME:  USB should have some power budgeting support working with
   7.798 - * all kinds of hubs.
   7.799 - *
   7.800 - * FIXME:  This assumes only D0->D3 suspend and D3->D0 resume.
   7.801 - * D1 and D2 states should do something, yes?
   7.802 - *
   7.803 - * FIXME:  Should provide generic enable_wake(), calling pci_enable_wake()
   7.804 - * for all supported states, so that USB remote wakeup can work for any
   7.805 - * devices that support it (and are connected via powered hubs).
   7.806 - *
   7.807 - * FIXME:  resume doesn't seem to work right any more...
   7.808 - */
   7.809 -
   7.810 -
   7.811 -// 2.4 kernels have issued concurrent resumes (w/APM)
   7.812 -// we defend against that error; PCI doesn't yet.
   7.813 -
   7.814 -/**
   7.815 - * usb_hcd_pci_suspend - power management suspend of a PCI-based HCD
   7.816 - * @dev: USB Host Controller being suspended
   7.817 - *
   7.818 - * Store this function in the HCD's struct pci_driver as suspend().
   7.819 - */
   7.820 -int usb_hcd_pci_suspend (struct pci_dev *dev, u32 state)
   7.821 -{
   7.822 -	struct usb_hcd		*hcd;
   7.823 -	int			retval;
   7.824 -
   7.825 -	hcd = pci_get_drvdata(dev);
   7.826 -	printk (KERN_INFO "%s %s: suspend to state %d\n",
   7.827 -		hcd->description,  dev->slot_name, state);
   7.828 -
   7.829 -	pci_save_state (dev, hcd->pci_state);
   7.830 -
   7.831 -	// FIXME for all connected devices, leaf-to-root:
   7.832 -	// driver->suspend()
   7.833 -	// proposed "new 2.5 driver model" will automate that
   7.834 -
   7.835 -	/* driver may want to disable DMA etc */
   7.836 -	retval = hcd->driver->suspend (hcd, state);
   7.837 -	hcd->state = USB_STATE_SUSPENDED;
   7.838 -
   7.839 - 	pci_set_power_state (dev, state);
   7.840 -	return retval;
   7.841 -}
   7.842 -EXPORT_SYMBOL (usb_hcd_pci_suspend);
   7.843 -
   7.844 -/**
   7.845 - * usb_hcd_pci_resume - power management resume of a PCI-based HCD
   7.846 - * @dev: USB Host Controller being resumed
   7.847 - *
   7.848 - * Store this function in the HCD's struct pci_driver as resume().
   7.849 - */
   7.850 -int usb_hcd_pci_resume (struct pci_dev *dev)
   7.851 -{
   7.852 -	struct usb_hcd		*hcd;
   7.853 -	int			retval;
   7.854 -
   7.855 -	hcd = pci_get_drvdata(dev);
   7.856 -	printk (KERN_INFO "%s %s: resume\n",
   7.857 -		hcd->description,  dev->slot_name);
   7.858 -
   7.859 -	/* guard against multiple resumes (APM bug?) */
   7.860 -	atomic_inc (&hcd->resume_count);
   7.861 -	if (atomic_read (&hcd->resume_count) != 1) {
   7.862 -		err ("concurrent PCI resumes for %s", hcd->bus->bus_name);
   7.863 -		retval = 0;
   7.864 -		goto done;
   7.865 -	}
   7.866 -
   7.867 -	retval = -EBUSY;
   7.868 -	if (hcd->state != USB_STATE_SUSPENDED) {
   7.869 -		dbg ("can't resume, not suspended!");
   7.870 -		goto done;
   7.871 -	}
   7.872 -	hcd->state = USB_STATE_RESUMING;
   7.873 -
   7.874 -	pci_set_power_state (dev, 0);
   7.875 -	pci_restore_state (dev, hcd->pci_state);
   7.876 -
   7.877 -	retval = hcd->driver->resume (hcd);
   7.878 -	if (!HCD_IS_RUNNING (hcd->state)) {
   7.879 -		dbg ("resume %s failure, retval %d",
   7.880 -			hcd->bus->bus_name, retval);
   7.881 -		hc_died (hcd);
   7.882 -// FIXME:  recover, reset etc.
   7.883 -	} else {
   7.884 -		// FIXME for all connected devices, root-to-leaf:
   7.885 -		// driver->resume ();
   7.886 -		// proposed "new 2.5 driver model" will automate that
   7.887 -	}
   7.888 -
   7.889 -done:
   7.890 -	atomic_dec (&hcd->resume_count);
   7.891 -	return retval;
   7.892 -}
   7.893 -EXPORT_SYMBOL (usb_hcd_pci_resume);
   7.894 -
   7.895 -#endif	/* CONFIG_PM */
   7.896 -
   7.897 -#endif
   7.898 -
   7.899 -/*-------------------------------------------------------------------------*/
   7.900 -
   7.901 -/*
   7.902 - * Generic HC operations.
   7.903 - */
   7.904 -
   7.905 -/*-------------------------------------------------------------------------*/
   7.906 -
   7.907 -/* called from khubd, or root hub init threads for hcd-private init */
   7.908 -static int hcd_alloc_dev (struct usb_device *udev)
   7.909 -{
   7.910 -	struct hcd_dev		*dev;
   7.911 -	struct usb_hcd		*hcd;
   7.912 -	unsigned long		flags;
   7.913 -
   7.914 -	if (!udev || udev->hcpriv)
   7.915 -		return -EINVAL;
   7.916 -	if (!udev->bus || !udev->bus->hcpriv)
   7.917 -		return -ENODEV;
   7.918 -	hcd = udev->bus->hcpriv;
   7.919 -	if (hcd->state == USB_STATE_QUIESCING)
   7.920 -		return -ENOLINK;
   7.921 -
   7.922 -	dev = (struct hcd_dev *) kmalloc (sizeof *dev, GFP_KERNEL);
   7.923 -	if (dev == NULL)
   7.924 -		return -ENOMEM;
   7.925 -	memset (dev, 0, sizeof *dev);
   7.926 -
   7.927 -	INIT_LIST_HEAD (&dev->dev_list);
   7.928 -	INIT_LIST_HEAD (&dev->urb_list);
   7.929 -
   7.930 -	spin_lock_irqsave (&hcd_data_lock, flags);
   7.931 -	list_add (&dev->dev_list, &hcd->dev_list);
   7.932 -	// refcount is implicit
   7.933 -	udev->hcpriv = dev;
   7.934 -	spin_unlock_irqrestore (&hcd_data_lock, flags);
   7.935 -
   7.936 -	return 0;
   7.937 -}
   7.938 -
   7.939 -/*-------------------------------------------------------------------------*/
   7.940 -
   7.941 -static void hcd_panic (void *_hcd)
   7.942 -{
   7.943 -	struct usb_hcd *hcd = _hcd;
   7.944 -	hcd->driver->stop (hcd);
   7.945 -}
   7.946 -
   7.947 -static void hc_died (struct usb_hcd *hcd)
   7.948 -{
   7.949 -	struct list_head	*devlist, *urblist;
   7.950 -	struct hcd_dev		*dev;
   7.951 -	struct urb		*urb;
   7.952 -	unsigned long		flags;
   7.953 -	
   7.954 -	/* flag every pending urb as done */
   7.955 -	spin_lock_irqsave (&hcd_data_lock, flags);
   7.956 -	list_for_each (devlist, &hcd->dev_list) {
   7.957 -		dev = list_entry (devlist, struct hcd_dev, dev_list);
   7.958 -		list_for_each (urblist, &dev->urb_list) {
   7.959 -			urb = list_entry (urblist, struct urb, urb_list);
   7.960 -			dbg ("shutdown %s urb %p pipe %x, current status %d",
   7.961 -				hcd->bus->bus_name,
   7.962 -				urb, urb->pipe, urb->status);
   7.963 -			if (urb->status == -EINPROGRESS)
   7.964 -				urb->status = -ESHUTDOWN;
   7.965 -		}
   7.966 -	}
   7.967 -	urb = (struct urb *) hcd->rh_timer.data;
   7.968 -	if (urb)
   7.969 -		urb->status = -ESHUTDOWN;
   7.970 -	spin_unlock_irqrestore (&hcd_data_lock, flags);
   7.971 -
   7.972 -	if (urb)
   7.973 -		rh_status_dequeue (hcd, urb);
   7.974 -
   7.975 -	/* hcd->stop() needs a task context */
   7.976 -	INIT_TQUEUE (&hcd->work, hcd_panic, hcd);
   7.977 -	(void) schedule_task (&hcd->work);
   7.978 -}
   7.979 -
   7.980 -/*-------------------------------------------------------------------------*/
   7.981 -
   7.982 -static void urb_unlink (struct urb *urb)
   7.983 -{
   7.984 -	unsigned long		flags;
   7.985 -	struct usb_device	*dev;
   7.986 -
   7.987 -	/* Release any periodic transfer bandwidth */
   7.988 -	if (urb->bandwidth)
   7.989 -		usb_release_bandwidth (urb->dev, urb,
   7.990 -			usb_pipeisoc (urb->pipe));
   7.991 -
   7.992 -	/* clear all state linking urb to this dev (and hcd) */
   7.993 -
   7.994 -	spin_lock_irqsave (&hcd_data_lock, flags);
   7.995 -	list_del_init (&urb->urb_list);
   7.996 -	dev = urb->dev;
   7.997 -	urb->dev = NULL;
   7.998 -	usb_dec_dev_use (dev);
   7.999 -	spin_unlock_irqrestore (&hcd_data_lock, flags);
  7.1000 -}
  7.1001 -
  7.1002 -
  7.1003 -/* may be called in any context with a valid urb->dev usecount */
  7.1004 -/* caller surrenders "ownership" of urb */
  7.1005 -
  7.1006 -static int hcd_submit_urb (struct urb *urb)
  7.1007 -{
  7.1008 -	int			status;
  7.1009 -	struct usb_hcd		*hcd;
  7.1010 -	struct hcd_dev		*dev;
  7.1011 -	unsigned long		flags;
  7.1012 -	int			pipe, temp, max;
  7.1013 -	int			mem_flags;
  7.1014 -
  7.1015 -	if (!urb || urb->hcpriv || !urb->complete)
  7.1016 -		return -EINVAL;
  7.1017 -
  7.1018 -	urb->status = -EINPROGRESS;
  7.1019 -	urb->actual_length = 0;
  7.1020 -	urb->bandwidth = 0;
  7.1021 -	INIT_LIST_HEAD (&urb->urb_list);
  7.1022 -
  7.1023 -	if (!urb->dev || !urb->dev->bus || urb->dev->devnum <= 0)
  7.1024 -		return -ENODEV;
  7.1025 -	hcd = urb->dev->bus->hcpriv;
  7.1026 -	dev = urb->dev->hcpriv;
  7.1027 -	if (!hcd || !dev)
  7.1028 -		return -ENODEV;
  7.1029 -
  7.1030 -	/* can't submit new urbs when quiescing, halted, ... */
  7.1031 -	if (hcd->state == USB_STATE_QUIESCING || !HCD_IS_RUNNING (hcd->state))
  7.1032 -		return -ESHUTDOWN;
  7.1033 -	pipe = urb->pipe;
  7.1034 -	temp = usb_pipetype (urb->pipe);
  7.1035 -	if (usb_endpoint_halted (urb->dev, usb_pipeendpoint (pipe),
  7.1036 -			usb_pipeout (pipe)))
  7.1037 -		return -EPIPE;
  7.1038 -
  7.1039 -	/* NOTE: 2.5 passes this value explicitly in submit() */
  7.1040 -	mem_flags = GFP_ATOMIC;
  7.1041 -
  7.1042 -	/* FIXME there should be a sharable lock protecting us against
  7.1043 -	 * config/altsetting changes and disconnects, kicking in here.
  7.1044 -	 */
  7.1045 -
  7.1046 -	/* Sanity check, so HCDs can rely on clean data */
  7.1047 -	max = usb_maxpacket (urb->dev, pipe, usb_pipeout (pipe));
  7.1048 -	if (max <= 0) {
  7.1049 -		err ("bogus endpoint (bad maxpacket)");
  7.1050 -		return -EINVAL;
  7.1051 -	}
  7.1052 -
  7.1053 -	/* "high bandwidth" mode, 1-3 packets/uframe? */
  7.1054 -	if (urb->dev->speed == USB_SPEED_HIGH) {
  7.1055 -		int	mult;
  7.1056 -		switch (temp) {
  7.1057 -		case PIPE_ISOCHRONOUS:
  7.1058 -		case PIPE_INTERRUPT:
  7.1059 -			mult = 1 + ((max >> 11) & 0x03);
  7.1060 -			max &= 0x03ff;
  7.1061 -			max *= mult;
  7.1062 -		}
  7.1063 -	}
  7.1064 -
  7.1065 -	/* periodic transfers limit size per frame/uframe */
  7.1066 -	switch (temp) {
  7.1067 -	case PIPE_ISOCHRONOUS: {
  7.1068 -		int	n, len;
  7.1069 -
  7.1070 -		if (urb->number_of_packets <= 0)		    
  7.1071 -			return -EINVAL;
  7.1072 -		for (n = 0; n < urb->number_of_packets; n++) {
  7.1073 -			len = urb->iso_frame_desc [n].length;
  7.1074 -			if (len < 0 || len > max) 
  7.1075 -				return -EINVAL;
  7.1076 -		}
  7.1077 -
  7.1078 -		}
  7.1079 -		break;
  7.1080 -	case PIPE_INTERRUPT:
  7.1081 -		if (urb->transfer_buffer_length > max)
  7.1082 -			return -EINVAL;
  7.1083 -	}
  7.1084 -
  7.1085 -	/* the I/O buffer must usually be mapped/unmapped */
  7.1086 -	if (urb->transfer_buffer_length < 0)
  7.1087 -		return -EINVAL;
  7.1088 -
  7.1089 -	if (urb->next) {
  7.1090 -		warn ("use explicit queuing not urb->next");
  7.1091 -		return -EINVAL;
  7.1092 -	}
  7.1093 -
  7.1094 -#ifdef DEBUG
  7.1095 -	/* stuff that drivers shouldn't do, but which shouldn't
  7.1096 -	 * cause problems in HCDs if they get it wrong.
  7.1097 -	 */
  7.1098 -	{
  7.1099 -	unsigned int	orig_flags = urb->transfer_flags;
  7.1100 -	unsigned int	allowed;
  7.1101 -
  7.1102 -	/* enforce simple/standard policy */
  7.1103 -	allowed = USB_ASYNC_UNLINK;	// affects later unlinks
  7.1104 -	allowed |= USB_NO_FSBR;		// only affects UHCI
  7.1105 -	switch (temp) {
  7.1106 -	case PIPE_CONTROL:
  7.1107 -		allowed |= USB_DISABLE_SPD;
  7.1108 -		break;
  7.1109 -	case PIPE_BULK:
  7.1110 -		allowed |= USB_DISABLE_SPD | USB_QUEUE_BULK
  7.1111 -				| USB_ZERO_PACKET | URB_NO_INTERRUPT;
  7.1112 -		break;
  7.1113 -	case PIPE_INTERRUPT:
  7.1114 -		allowed |= USB_DISABLE_SPD;
  7.1115 -		break;
  7.1116 -	case PIPE_ISOCHRONOUS:
  7.1117 -		allowed |= USB_ISO_ASAP;
  7.1118 -		break;
  7.1119 -	}
  7.1120 -	urb->transfer_flags &= allowed;
  7.1121 -
  7.1122 -	/* fail if submitter gave bogus flags */
  7.1123 -	if (urb->transfer_flags != orig_flags) {
  7.1124 -		err ("BOGUS urb flags, %x --> %x",
  7.1125 -			orig_flags, urb->transfer_flags);
  7.1126 -		return -EINVAL;
  7.1127 -	}
  7.1128 -	}
  7.1129 -#endif
  7.1130 -	/*
  7.1131 -	 * Force periodic transfer intervals to be legal values that are
  7.1132 -	 * a power of two (so HCDs don't need to).
  7.1133 -	 *
  7.1134 -	 * FIXME want bus->{intr,iso}_sched_horizon values here.  Each HC
  7.1135 -	 * supports different values... this uses EHCI/UHCI defaults (and
  7.1136 -	 * EHCI can use smaller non-default values).
  7.1137 -	 */
  7.1138 -	switch (temp) {
  7.1139 -	case PIPE_ISOCHRONOUS:
  7.1140 -	case PIPE_INTERRUPT:
  7.1141 -		/* too small? */
  7.1142 -		if (urb->interval <= 0)
  7.1143 -			return -EINVAL;
  7.1144 -		/* too big? */
  7.1145 -		switch (urb->dev->speed) {
  7.1146 -		case USB_SPEED_HIGH:	/* units are microframes */
  7.1147 -			// NOTE usb handles 2^15
  7.1148 -			if (urb->interval > (1024 * 8))
  7.1149 -				urb->interval = 1024 * 8;
  7.1150 -			temp = 1024 * 8;
  7.1151 -			break;
  7.1152 -		case USB_SPEED_FULL:	/* units are frames/msec */
  7.1153 -		case USB_SPEED_LOW:
  7.1154 -			if (temp == PIPE_INTERRUPT) {
  7.1155 -				if (urb->interval > 255)
  7.1156 -					return -EINVAL;
  7.1157 -				// NOTE ohci only handles up to 32
  7.1158 -				temp = 128;
  7.1159 -			} else {
  7.1160 -				if (urb->interval > 1024)
  7.1161 -					urb->interval = 1024;
  7.1162 -				// NOTE usb and ohci handle up to 2^15
  7.1163 -				temp = 1024;
  7.1164 -			}
  7.1165 -			break;
  7.1166 -		default:
  7.1167 -			return -EINVAL;
  7.1168 -		}
  7.1169 -		/* power of two? */
  7.1170 -		while (temp > urb->interval)
  7.1171 -			temp >>= 1;
  7.1172 -		urb->interval = temp;
  7.1173 -	}
  7.1174 -
  7.1175 -
  7.1176 -	/*
  7.1177 -	 * FIXME:  make urb timeouts be generic, keeping the HCD cores
  7.1178 -	 * as simple as possible.
  7.1179 -	 */
  7.1180 -
  7.1181 -	// NOTE:  a generic device/urb monitoring hook would go here.
  7.1182 -	// hcd_monitor_hook(MONITOR_URB_SUBMIT, urb)
  7.1183 -	// It would catch submission paths for all urbs.
  7.1184 -
  7.1185 -	/*
  7.1186 -	 * Atomically queue the urb,  first to our records, then to the HCD.
  7.1187 -	 * Access to urb->status is controlled by urb->lock ... changes on
  7.1188 -	 * i/o completion (normal or fault) or unlinking.
  7.1189 -	 */
  7.1190 -
  7.1191 -	// FIXME:  verify that quiescing hc works right (RH cleans up)
  7.1192 -
  7.1193 -	spin_lock_irqsave (&hcd_data_lock, flags);
  7.1194 -	if (HCD_IS_RUNNING (hcd->state) && hcd->state != USB_STATE_QUIESCING) {
  7.1195 -		usb_inc_dev_use (urb->dev);
  7.1196 -		list_add (&urb->urb_list, &dev->urb_list);
  7.1197 -		status = 0;
  7.1198 -	} else {
  7.1199 -		INIT_LIST_HEAD (&urb->urb_list);
  7.1200 -		status = -ESHUTDOWN;
  7.1201 -	}
  7.1202 -	spin_unlock_irqrestore (&hcd_data_lock, flags);
  7.1203 -	if (status)
  7.1204 -		return status;
  7.1205 -
  7.1206 -	// NOTE:  2.5 does this if !URB_NO_DMA_MAP transfer flag
  7.1207 -	
  7.1208 -	/* For 2.4, don't map bounce buffer if it's a root hub operation. */
  7.1209 -	if (urb->dev == hcd->bus->root_hub) {
  7.1210 -		status = rh_urb_enqueue (hcd, urb);
  7.1211 -	} else {
  7.1212 -#ifdef CONFIG_PCI
  7.1213 -		if (usb_pipecontrol (urb->pipe))
  7.1214 -			urb->setup_dma = pci_map_single (
  7.1215 -					hcd->pdev,
  7.1216 -					urb->setup_packet,
  7.1217 -					sizeof (struct usb_ctrlrequest),
  7.1218 -					PCI_DMA_TODEVICE);
  7.1219 -		if (urb->transfer_buffer_length != 0)
  7.1220 -			urb->transfer_dma = pci_map_single (
  7.1221 -					hcd->pdev,
  7.1222 -					urb->transfer_buffer,
  7.1223 -					urb->transfer_buffer_length,
  7.1224 -					usb_pipein (urb->pipe)
  7.1225 -					    ? PCI_DMA_FROMDEVICE
  7.1226 -					    : PCI_DMA_TODEVICE);
  7.1227 -#endif
  7.1228 -		status = hcd->driver->urb_enqueue (hcd, urb, mem_flags);
  7.1229 -	}
  7.1230 -	return status;
  7.1231 -}
  7.1232 -
  7.1233 -/*-------------------------------------------------------------------------*/
  7.1234 -
  7.1235 -/* called in any context */
  7.1236 -static int hcd_get_frame_number (struct usb_device *udev)
  7.1237 -{
  7.1238 -	struct usb_hcd	*hcd = (struct usb_hcd *)udev->bus->hcpriv;
  7.1239 -	return hcd->driver->get_frame_number (hcd);
  7.1240 -}
  7.1241 -
  7.1242 -/*-------------------------------------------------------------------------*/
  7.1243 -
  7.1244 -struct completion_splice {		// modified urb context:
  7.1245 -	/* did we complete? */
  7.1246 -	struct completion	done;
  7.1247 -
  7.1248 -	/* original urb data */
  7.1249 -	void			(*complete)(struct urb *);
  7.1250 -	void			*context;
  7.1251 -};
  7.1252 -
  7.1253 -static void unlink_complete (struct urb *urb)
  7.1254 -{
  7.1255 -	struct completion_splice	*splice;
  7.1256 -
  7.1257 -	splice = (struct completion_splice *) urb->context;
  7.1258 -
  7.1259 -	/* issue original completion call */
  7.1260 -	urb->complete = splice->complete;
  7.1261 -	urb->context = splice->context;
  7.1262 -	urb->complete (urb);
  7.1263 -
  7.1264 -	/* then let the synchronous unlink call complete */
  7.1265 -	complete (&splice->done);
  7.1266 -}
  7.1267 -
  7.1268 -/*
  7.1269 - * called in any context; note ASYNC_UNLINK restrictions
  7.1270 - *
  7.1271 - * caller guarantees urb won't be recycled till both unlink()
  7.1272 - * and the urb's completion function return
  7.1273 - */
  7.1274 -static int hcd_unlink_urb (struct urb *urb)
  7.1275 -{
  7.1276 -	struct hcd_dev			*dev;
  7.1277 -	struct usb_hcd			*hcd = 0;
  7.1278 -	unsigned long			flags;
  7.1279 -	struct completion_splice	splice;
  7.1280 -	int				retval;
  7.1281 -
  7.1282 -	if (!urb)
  7.1283 -		return -EINVAL;
  7.1284 -
  7.1285 -	/*
  7.1286 -	 * we contend for urb->status with the hcd core,
  7.1287 -	 * which changes it while returning the urb.
  7.1288 -	 *
  7.1289 -	 * Caller guaranteed that the urb pointer hasn't been freed, and
  7.1290 -	 * that it was submitted.  But as a rule it can't know whether or
  7.1291 -	 * not it's already been unlinked ... so we respect the reversed
  7.1292 -	 * lock sequence needed for the usb_hcd_giveback_urb() code paths
  7.1293 -	 * (urb lock, then hcd_data_lock) in case some other CPU is now
  7.1294 -	 * unlinking it.
  7.1295 -	 */
  7.1296 -	spin_lock_irqsave (&urb->lock, flags);
  7.1297 -	spin_lock (&hcd_data_lock);
  7.1298 -	if (!urb->hcpriv || urb->transfer_flags & USB_TIMEOUT_KILLED) {
  7.1299 -		retval = -EINVAL;
  7.1300 -		goto done;
  7.1301 -	}
  7.1302 -
  7.1303 -	if (!urb->dev || !urb->dev->bus) {
  7.1304 -		retval = -ENODEV;
  7.1305 -		goto done;
  7.1306 -	}
  7.1307 -
  7.1308 -	/* giveback clears dev; non-null means it's linked at this level */
  7.1309 -	dev = urb->dev->hcpriv;
  7.1310 -	hcd = urb->dev->bus->hcpriv;
  7.1311 -	if (!dev || !hcd) {
  7.1312 -		retval = -ENODEV;
  7.1313 -		goto done;
  7.1314 -	}
  7.1315 -
  7.1316 -	/* Any status except -EINPROGRESS means the HCD has already started
  7.1317 -	 * to return this URB to the driver.  In that case, there's no
  7.1318 -	 * more work for us to do.
  7.1319 -	 *
  7.1320 -	 * There's much magic because of "automagic resubmit" of interrupt
  7.1321 -	 * transfers, stopped only by explicit unlinking.  We won't issue
  7.1322 -	 * an "it's unlinked" callback more than once, but device drivers
  7.1323 -	 * can need to retry (SMP, -EAGAIN) an unlink request as well as
  7.1324 -	 * fake out the "not yet completed" state (set -EINPROGRESS) if
  7.1325 -	 * unlinking from complete().  Automagic eventually vanishes.
  7.1326 -	 *
  7.1327 -	 * FIXME use an URB_UNLINKED flag to match URB_TIMEOUT_KILLED
  7.1328 -	 */
  7.1329 -	if (urb->status != -EINPROGRESS) {
  7.1330 -		if (usb_pipetype (urb->pipe) == PIPE_INTERRUPT)
  7.1331 -			retval = -EAGAIN;
  7.1332 -		else
  7.1333 -			retval = -EBUSY;
  7.1334 -		goto done;
  7.1335 -	}
  7.1336 -
  7.1337 -	/* maybe set up to block on completion notification */
  7.1338 -	if ((urb->transfer_flags & USB_TIMEOUT_KILLED))
  7.1339 -		urb->status = -ETIMEDOUT;
  7.1340 -	else if (!(urb->transfer_flags & USB_ASYNC_UNLINK)) {
  7.1341 -		if (in_interrupt ()) {
  7.1342 -			dbg ("non-async unlink in_interrupt");
  7.1343 -			retval = -EWOULDBLOCK;
  7.1344 -			goto done;
  7.1345 -		}
  7.1346 -		/* synchronous unlink: block till we see the completion */
  7.1347 -		init_completion (&splice.done);
  7.1348 -		splice.complete = urb->complete;
  7.1349 -		splice.context = urb->context;
  7.1350 -		urb->complete = unlink_complete;
  7.1351 -		urb->context = &splice;
  7.1352 -		urb->status = -ENOENT;
  7.1353 -	} else {
  7.1354 -		/* asynchronous unlink */
  7.1355 -		urb->status = -ECONNRESET;
  7.1356 -	}
  7.1357 -	spin_unlock (&hcd_data_lock);
  7.1358 -	spin_unlock_irqrestore (&urb->lock, flags);
  7.1359 -
  7.1360 -	if (urb == (struct urb *) hcd->rh_timer.data) {
  7.1361 -		rh_status_dequeue (hcd, urb);
  7.1362 -		retval = 0;
  7.1363 -	} else {
  7.1364 -		retval = hcd->driver->urb_dequeue (hcd, urb);
  7.1365 -// FIXME:  if retval and we tried to splice, whoa!!
  7.1366 -if (retval && urb->status == -ENOENT) err ("whoa! retval %d", retval);
  7.1367 -	}
  7.1368 -
  7.1369 -    	/* block till giveback, if needed */
  7.1370 -	if (!(urb->transfer_flags & (USB_ASYNC_UNLINK|USB_TIMEOUT_KILLED))
  7.1371 -			&& HCD_IS_RUNNING (hcd->state)
  7.1372 -			&& !retval) {
  7.1373 -		wait_for_completion (&splice.done);
  7.1374 -	} else if ((urb->transfer_flags & USB_ASYNC_UNLINK) && retval == 0) {
  7.1375 -		return -EINPROGRESS;
  7.1376 -	}
  7.1377 -	goto bye;
  7.1378 -done:
  7.1379 -	spin_unlock (&hcd_data_lock);
  7.1380 -	spin_unlock_irqrestore (&urb->lock, flags);
  7.1381 -bye:
  7.1382 -	if (retval)
  7.1383 -		dbg ("%s: hcd_unlink_urb fail %d",
  7.1384 -		    hcd ? hcd->bus->bus_name : "(no bus?)",
  7.1385 -		    retval);
  7.1386 -	return retval;
  7.1387 -}
  7.1388 -
  7.1389 -/*-------------------------------------------------------------------------*/
  7.1390 -
  7.1391 -/* called by khubd, rmmod, apmd, or other thread for hcd-private cleanup */
  7.1392 -
  7.1393 -// FIXME:  likely best to have explicit per-setting (config+alt)
  7.1394 -// setup primitives in the usbcore-to-hcd driver API, so nothing
  7.1395 -// is implicit.  kernel 2.5 needs a bunch of config cleanup...
  7.1396 -
  7.1397 -static int hcd_free_dev (struct usb_device *udev)
  7.1398 -{
  7.1399 -	struct hcd_dev		*dev;
  7.1400 -	struct usb_hcd		*hcd;
  7.1401 -	unsigned long		flags;
  7.1402 -
  7.1403 -	if (!udev || !udev->hcpriv)
  7.1404 -		return -EINVAL;
  7.1405 -
  7.1406 -	if (!udev->bus || !udev->bus->hcpriv)
  7.1407 -		return -ENODEV;
  7.1408 -
  7.1409 -	// should udev->devnum == -1 ??
  7.1410 -
  7.1411 -	dev = udev->hcpriv;
  7.1412 -	hcd = udev->bus->hcpriv;
  7.1413 -
  7.1414 -	/* device driver problem with refcounts? */
  7.1415 -	if (!list_empty (&dev->urb_list)) {
  7.1416 -		dbg ("free busy dev, %s devnum %d (bug!)",
  7.1417 -			hcd->bus->bus_name, udev->devnum);
  7.1418 -		return -EINVAL;
  7.1419 -	}
  7.1420 -
  7.1421 -	hcd->driver->free_config (hcd, udev);
  7.1422 -
  7.1423 -	spin_lock_irqsave (&hcd_data_lock, flags);
  7.1424 -	list_del (&dev->dev_list);
  7.1425 -	udev->hcpriv = NULL;
  7.1426 -	spin_unlock_irqrestore (&hcd_data_lock, flags);
  7.1427 -
  7.1428 -	kfree (dev);
  7.1429 -	return 0;
  7.1430 -}
  7.1431 -
  7.1432 -static struct usb_operations hcd_operations = {
  7.1433 -	allocate:		hcd_alloc_dev,
  7.1434 -	get_frame_number:	hcd_get_frame_number,
  7.1435 -	submit_urb:		hcd_submit_urb,
  7.1436 -	unlink_urb:		hcd_unlink_urb,
  7.1437 -	deallocate:		hcd_free_dev,
  7.1438 -};
  7.1439 -
  7.1440 -/*-------------------------------------------------------------------------*/
  7.1441 -
  7.1442 -static void hcd_irq (int irq, void *__hcd, struct pt_regs * r)
  7.1443 -{
  7.1444 -	struct usb_hcd		*hcd = __hcd;
  7.1445 -	int			start = hcd->state;
  7.1446 -
  7.1447 -	if (unlikely (hcd->state == USB_STATE_HALT))	/* irq sharing? */
  7.1448 -		return;
  7.1449 -
  7.1450 -	hcd->driver->irq (hcd, r);
  7.1451 -	if (hcd->state != start && hcd->state == USB_STATE_HALT)
  7.1452 -		hc_died (hcd);
  7.1453 -}
  7.1454 -
  7.1455 -/*-------------------------------------------------------------------------*/
  7.1456 -
  7.1457 -/**
  7.1458 - * usb_hcd_giveback_urb - return URB from HCD to device driver
  7.1459 - * @hcd: host controller returning the URB
  7.1460 - * @urb: urb being returned to the USB device driver.
  7.1461 - * @regs: saved hardware registers (ignored on 2.4 kernels)
  7.1462 - * Context: in_interrupt()
  7.1463 - *
  7.1464 - * This hands the URB from HCD to its USB device driver, using its
  7.1465 - * completion function.  The HCD has freed all per-urb resources
  7.1466 - * (and is done using urb->hcpriv).  It also released all HCD locks;
  7.1467 - * the device driver won't cause deadlocks if it resubmits this URB,
  7.1468 - * and won't confuse things by modifying and resubmitting this one.
  7.1469 - * Bandwidth and other resources will be deallocated.
  7.1470 - *
  7.1471 - * HCDs must not use this for periodic URBs that are still scheduled
  7.1472 - * and will be reissued.  They should just call their completion handlers
  7.1473 - * until the urb is returned to the device driver by unlinking.
  7.1474 - *
  7.1475 - * NOTE that no urb->next processing is done, even for isochronous URBs.
  7.1476 - * ISO streaming functionality can be achieved by having completion handlers
  7.1477 - * re-queue URBs.  Such explicit queuing doesn't discard error reports.
  7.1478 - */
  7.1479 -void usb_hcd_giveback_urb (struct usb_hcd *hcd, struct urb *urb, struct pt_regs *regs)
  7.1480 -{
  7.1481 -	int is_root_hub_operation;
  7.1482 -
  7.1483 -	/* Work this out here as urb_unlink clears urb->dev */
  7.1484 -	is_root_hub_operation = (urb->dev == hcd->bus->root_hub);
  7.1485 -
  7.1486 -	urb_unlink (urb);
  7.1487 -
  7.1488 -	// NOTE:  a generic device/urb monitoring hook would go here.
  7.1489 -	// hcd_monitor_hook(MONITOR_URB_FINISH, urb, dev)
  7.1490 -	// It would catch exit/unlink paths for all urbs, but non-exit
  7.1491 -	// completions for periodic urbs need hooks inside the HCD.
  7.1492 -	// hcd_monitor_hook(MONITOR_URB_UPDATE, urb, dev)
  7.1493 -
  7.1494 -	// NOTE:  2.5 does this if !URB_NO_DMA_MAP transfer flag
  7.1495 -
  7.1496 -#ifdef CONFIG_PCI	
  7.1497 -	/* For 2.4, don't unmap bounce buffer if it's a root hub operation. */
  7.1498 -	if (usb_pipecontrol (urb->pipe) && !is_root_hub_operation)
  7.1499 -		pci_unmap_single (hcd->pdev, urb->setup_dma,
  7.1500 -				sizeof (struct usb_ctrlrequest),
  7.1501 -				PCI_DMA_TODEVICE);
  7.1502 -
  7.1503 -	if ((urb->transfer_buffer_length != 0) && !is_root_hub_operation)
  7.1504 -		pci_unmap_single (hcd->pdev, urb->transfer_dma,
  7.1505 -				urb->transfer_buffer_length,
  7.1506 -				usb_pipein (urb->pipe)
  7.1507 -				    ? PCI_DMA_FROMDEVICE
  7.1508 -				    : PCI_DMA_TODEVICE);
  7.1509 -#endif
  7.1510 -
  7.1511 -	/* pass ownership to the completion handler */
  7.1512 -	urb->complete (urb);
  7.1513 -}
  7.1514 -EXPORT_SYMBOL (usb_hcd_giveback_urb);