Linuxでは, USB デバイスとホストコントローラをサポートするために特定のAPI を持つ「USB コア」と呼ばれるサブシステムが存在する. その目的は, 関数, マクロ, データ構造体のセットを定義することにより すべてのハードウエアやデバイスに依存しない部分を抽象化するためである. USB コアはすべての USB デバイスドライバとホストコントローラドライバーに共通のルーチンを含んでいる.
struct usb_device { int devnum; /* Device number on USB bus */ int slow; /* Slow device? */ atomic_t refcnt; /* Reference count */ unsigned int toggle[2]; /* one bit for each endpoint ([0] = IN, [1] = OUT) */ unsigned int halted[2]; /* endpoint halts; one bit per endpoint # & direction; */ /* [0] = IN, [1] = OUT */ int epmaxpacketin[16]; /* INput endpoint specific maximums */ int epmaxpacketout[16]; /* OUTput endpoint specific maximums */ struct usb_device *parent; struct usb_bus *bus; /* Bus we're part of */ struct usb_device_descriptor descriptor;/* Descriptor */ struct usb_config_descriptor *config; /* All of the configs */ struct usb_config_descriptor *actconfig;/* the active configuration */ char **rawdescriptors; /* Raw descriptors for each config */ int have_langid; /* whether string_langid is valid yet */ int string_langid; /* language ID for strings */ void *hcpriv; /* Host Controller private data */ /* usbdevfs inode list */ struct list_head inodes; struct list_head filelist; /* * Child devices - these can be either new devices * (if this is a hub device), or different instances * of this same device. * * Each instance needs its own set of data structures. */ int maxchild; /* Number of ports if hub */ struct usb_device *children[USB_MAXCHILDREN]; };次に usb_driver 構造体を示す.
struct usb_driver { const char *name; void *(*probe)( struct usb_device *dev, /* the device */ unsigned intf, /* what interface */ const struct usb_device_id *id /* from id_table */ ); void (*disconnect)(struct usb_device *, void *); struct list_head driver_list; struct file_operations *fops; int minor; struct semaphore serialize; /* ioctl -- userspace apps can talk to drivers through usbdevfs */ int (*ioctl)(struct usb_device *dev, unsigned int code, void *buf); /* support for "new-style" USB hotplugging * binding policy can be driven from user mode too */ const struct usb_device_id *id_table; /* suspend before the bus suspends; * disconnect or resume when the bus resumes */ // void (*suspend)(struct usb_device *dev); // void (*resume)(struct usb_device *dev); };
static struct usb_driver xxx_driver = { name: "xxx", probe: usb_xxx_probe, disconnect: usb_xxx_disconnect, fops: &usb_xxx_file_operations, minor: USB_XXX_MINOR_BASE, };