Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Functions | Variables
usb.c File Reference
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/string.h>
#include <linux/bitops.h>
#include <linux/slab.h>
#include <linux/interrupt.h>
#include <linux/kmod.h>
#include <linux/init.h>
#include <linux/spinlock.h>
#include <linux/errno.h>
#include <linux/usb.h>
#include <linux/usb/hcd.h>
#include <linux/mutex.h>
#include <linux/workqueue.h>
#include <linux/debugfs.h>
#include <asm/io.h>
#include <linux/scatterlist.h>
#include <linux/mm.h>
#include <linux/dma-mapping.h>
#include "usb.h"

Go to the source code of this file.

Data Structures

struct  find_interface_arg
 

Macros

#define usb_autosuspend_delay   0
 

Functions

struct usb_host_interface * usb_find_alt_setting (struct usb_host_config *config, unsigned int iface_num, unsigned int alt_num)
 
 EXPORT_SYMBOL_GPL (usb_find_alt_setting)
 
struct usb_interfaceusb_ifnum_to_if (const struct usb_device *dev, unsigned ifnum)
 
 EXPORT_SYMBOL_GPL (usb_ifnum_to_if)
 
struct usb_host_interface * usb_altnum_to_altsetting (const struct usb_interface *intf, unsigned int altnum)
 
 EXPORT_SYMBOL_GPL (usb_altnum_to_altsetting)
 
struct usb_interfaceusb_find_interface (struct usb_driver *drv, int minor)
 
 EXPORT_SYMBOL_GPL (usb_find_interface)
 
struct usb_device * usb_alloc_dev (struct usb_device *parent, struct usb_bus *bus, unsigned port1)
 
struct usb_device * usb_get_dev (struct usb_device *dev)
 
 EXPORT_SYMBOL_GPL (usb_get_dev)
 
void usb_put_dev (struct usb_device *dev)
 
 EXPORT_SYMBOL_GPL (usb_put_dev)
 
struct usb_interfaceusb_get_intf (struct usb_interface *intf)
 
 EXPORT_SYMBOL_GPL (usb_get_intf)
 
void usb_put_intf (struct usb_interface *intf)
 
 EXPORT_SYMBOL_GPL (usb_put_intf)
 
int usb_lock_device_for_reset (struct usb_device *udev, const struct usb_interface *iface)
 
 EXPORT_SYMBOL_GPL (usb_lock_device_for_reset)
 
int usb_get_current_frame_number (struct usb_device *dev)
 
 EXPORT_SYMBOL_GPL (usb_get_current_frame_number)
 
int __usb_get_extra_descriptor (char *buffer, unsigned size, unsigned char type, void **ptr)
 
 EXPORT_SYMBOL_GPL (__usb_get_extra_descriptor)
 
voidusb_alloc_coherent (struct usb_device *dev, size_t size, gfp_t mem_flags, dma_addr_t *dma)
 
 EXPORT_SYMBOL_GPL (usb_alloc_coherent)
 
void usb_free_coherent (struct usb_device *dev, size_t size, void *addr, dma_addr_t dma)
 
 EXPORT_SYMBOL_GPL (usb_free_coherent)
 
 core_param (nousb, nousb, bool, 0444)
 
int usb_disabled (void)
 
 EXPORT_SYMBOL_GPL (usb_disabled)
 
 EXPORT_SYMBOL_GPL (usb_debug_root)
 
 subsys_initcall (usb_init)
 
 module_exit (usb_exit)
 
 MODULE_LICENSE ("GPL")
 

Variables

const charusbcore_name = "usbcore"
 
struct device_type usb_device_type
 
struct dentryusb_debug_root
 

Macro Definition Documentation

#define usb_autosuspend_delay   0

Definition at line 59 of file usb.c.

Function Documentation

int __usb_get_extra_descriptor ( char buffer,
unsigned  size,
unsigned char  type,
void **  ptr 
)

Definition at line 627 of file usb.c.

core_param ( nousb  ,
nousb  ,
bool  ,
0444   
)

usb_buffer_map - create DMA mapping(s) for an urb : urb whose transfer_buffer/setup_packet will be mapped

Return value is either null (indicating no buffer could be mapped), or the parameter. URB_NO_TRANSFER_DMA_MAP is added to urb->transfer_flags if the operation succeeds. If the device is connected to this system through a non-DMA controller, this operation always succeeds.

This call would normally be used for an urb which is reused, perhaps as the target of a large periodic transfer, with usb_buffer_dmasync() calls to synchronize memory and dma state.

Reverse the effect of this call with usb_buffer_unmap(). usb_buffer_unmap - free DMA mapping(s) for an urb : urb whose transfer_buffer will be unmapped

Reverses the effect of usb_buffer_map().

EXPORT_SYMBOL_GPL ( usb_find_alt_setting  )
EXPORT_SYMBOL_GPL ( usb_ifnum_to_if  )
EXPORT_SYMBOL_GPL ( usb_altnum_to_altsetting  )
EXPORT_SYMBOL_GPL ( usb_find_interface  )
EXPORT_SYMBOL_GPL ( usb_get_dev  )
EXPORT_SYMBOL_GPL ( usb_put_dev  )
EXPORT_SYMBOL_GPL ( usb_get_intf  )
EXPORT_SYMBOL_GPL ( usb_put_intf  )
EXPORT_SYMBOL_GPL ( usb_lock_device_for_reset  )
EXPORT_SYMBOL_GPL ( usb_get_current_frame_number  )
EXPORT_SYMBOL_GPL ( __usb_get_extra_descriptor  )
EXPORT_SYMBOL_GPL ( usb_alloc_coherent  )
EXPORT_SYMBOL_GPL ( usb_free_coherent  )
EXPORT_SYMBOL_GPL ( usb_disabled  )
EXPORT_SYMBOL_GPL ( usb_debug_root  )
module_exit ( usb_exit  )
MODULE_LICENSE ( "GPL"  )
subsys_initcall ( usb_init  )
void* usb_alloc_coherent ( struct usb_device *  dev,
size_t  size,
gfp_t  mem_flags,
dma_addr_t dma 
)

usb_alloc_coherent - allocate dma-consistent buffer for URB_NO_xxx_DMA_MAP : device the buffer will be used with : requested buffer size : affect whether allocation may block : used to return DMA address of buffer

Return value is either null (indicating no buffer could be allocated), or the cpu-space pointer to a buffer that may be used to perform DMA to the specified device. Such cpu-space buffers are returned along with the DMA address (through the pointer provided).

These buffers are used with URB_NO_xxx_DMA_MAP set in urb->transfer_flags to avoid behaviors like using "DMA bounce buffers", or thrashing IOMMU hardware during URB completion/resubmit. The implementation varies between platforms, depending on details of how DMA will work to this device. Using these buffers also eliminates cacheline sharing problems on architectures where CPU caches are not DMA-coherent. On systems without bus-snooping caches, these buffers are uncached.

When the buffer is no longer used, free it with usb_free_coherent().

Definition at line 678 of file usb.c.

struct usb_device* usb_alloc_dev ( struct usb_device *  parent,
struct usb_bus *  bus,
unsigned  port1 
)
read

usb_alloc_dev - usb device constructor (usbcore-internal) : hub to which device is connected; null to allocate a root hub : bus used to access the device : one-based index of port; ignored for root hubs Context: !in_interrupt()

Only hub drivers (including virtual root hub drivers for host controllers) should ever call this.

This call may not be used in a non-sleeping context.

Definition at line 369 of file usb.c.

struct usb_host_interface* usb_altnum_to_altsetting ( const struct usb_interface intf,
unsigned int  altnum 
)
read

usb_altnum_to_altsetting - get the altsetting structure with a given alternate setting number. : the interface containing the altsetting in question : the desired alternate setting number

This searches the altsetting array of the specified interface for an entry with the correct bAlternateSetting value and returns a pointer to that entry, or null.

Note that altsettings need not be stored sequentially by number, so it would be incorrect to assume that the first altsetting entry in the array corresponds to altsetting zero. This routine helps device drivers avoid such mistakes.

Don't call this function unless you are bound to the intf interface or you have locked the device!

Definition at line 153 of file usb.c.

int usb_disabled ( void  )

Definition at line 939 of file usb.c.

struct usb_host_interface* usb_find_alt_setting ( struct usb_host_config *  config,
unsigned int  iface_num,
unsigned int  alt_num 
)
read

usb_find_alt_setting() - Given a configuration, find the alternate setting for the given interface. : the configuration to search (not necessarily the current config). : interface number to search in : alternate interface setting number to search for.

Search the configuration's interface cache for the given alt setting.

Definition at line 72 of file usb.c.

struct usb_interface* usb_find_interface ( struct usb_driver *  drv,
int  minor 
)
read

usb_find_interface - find usb_interface pointer for driver and device : the driver whose current configuration is considered : the minor number of the desired device

This walks the bus device list and returns a pointer to the interface with the matching minor and driver. Note, this only works for devices that share the USB major number.

Definition at line 195 of file usb.c.

void usb_free_coherent ( struct usb_device *  dev,
size_t  size,
void addr,
dma_addr_t  dma 
)

usb_free_coherent - free memory allocated with usb_alloc_coherent() : device the buffer was used with : requested buffer size : CPU address of buffer : DMA address of buffer

This reclaims an I/O buffer, letting it be reused. The memory must have been allocated using usb_alloc_coherent(), and the parameters must match those provided in that allocation request.

Definition at line 698 of file usb.c.

int usb_get_current_frame_number ( struct usb_device *  dev)

usb_get_current_frame_number - return current bus frame number : the device whose bus is being queried

Returns the current frame number for the USB host controller used with the given USB device. This can be used when scheduling isochronous requests.

Note that different kinds of host controller have different "scheduling horizons". While one type might support scheduling only 32 frames into the future, others could support scheduling up to 1024 frames into the future.

Definition at line 615 of file usb.c.

struct usb_device* usb_get_dev ( struct usb_device *  dev)
read

usb_get_dev - increments the reference count of the usb device structure : the device being referenced

Each live reference to a device should be refcounted.

Drivers for USB interfaces should normally record such references in their probe() methods, when they bind to an interface, and release them by calling usb_put_dev(), in their disconnect() methods.

A pointer to the device with the incremented reference counter is returned.

Definition at line 481 of file usb.c.

struct usb_interface* usb_get_intf ( struct usb_interface intf)
read

usb_get_intf - increments the reference count of the usb interface structure : the interface being referenced

Each live reference to a interface must be refcounted.

Drivers for USB interfaces should normally record such references in their probe() methods, when they bind to an interface, and release them by calling usb_put_intf(), in their disconnect() methods.

A pointer to the interface with the incremented reference counter is returned.

Definition at line 516 of file usb.c.

struct usb_interface* usb_ifnum_to_if ( const struct usb_device *  dev,
unsigned  ifnum 
)
read

usb_ifnum_to_if - get the interface object with a given interface number : the device whose current configuration is considered : the desired interface

This walks the device descriptor for the currently active configuration and returns a pointer to the interface with that particular interface number, or null.

Note that configuration descriptors are not required to assign interface numbers sequentially, so that it would be incorrect to assume that the first interface in that descriptor corresponds to interface zero. This routine helps device drivers avoid such mistakes. However, you should make sure that you do the right thing with any alternate settings available for this interfaces.

Don't call this function unless you are bound to one of the interfaces on this device or you have locked the device!

Definition at line 119 of file usb.c.

int usb_lock_device_for_reset ( struct usb_device *  udev,
const struct usb_interface iface 
)

usb_lock_device_for_reset - cautiously acquire the lock for a usb device structure : device that's being locked : interface bound to the driver making the request (optional)

Attempts to acquire the device lock, but fails if the device is NOTATTACHED or SUSPENDED, or if iface is specified and the interface is neither BINDING nor BOUND. Rather than sleeping to wait for the lock, the routine polls repeatedly. This is to prevent deadlock with disconnect; in some drivers (such as usb-storage) the disconnect() or suspend() method will block waiting for a device reset to complete.

Returns a negative error code for failure, otherwise 0.

Definition at line 569 of file usb.c.

void usb_put_dev ( struct usb_device *  dev)

usb_put_dev - release a use of the usb device structure : device that's been disconnected

Must be called when a user of a device is finished with it. When the last user of the device calls this function, the memory of the device is freed.

Definition at line 496 of file usb.c.

void usb_put_intf ( struct usb_interface intf)

usb_put_intf - release a use of the usb interface structure : interface that's been decremented

Must be called when a user of an interface is finished with it. When the last user of the interface calls this function, the memory of the interface is freed.

Definition at line 532 of file usb.c.

Variable Documentation

struct dentry* usb_debug_root

Definition at line 975 of file usb.c.

struct device_type usb_device_type
Initial value:
= {
.name = "usb_device",
.release = usb_release_dev,
.uevent = usb_dev_uevent,
.devnode = usb_devnode,
}

Definition at line 338 of file usb.c.

const char* usbcore_name = "usbcore"

Definition at line 48 of file usb.c.