这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 嵌入式开发 » 软件与操作系统 » linux U盘中storage_probe()参数从何而来??

共11条 1/2 1 2 跳转至

linux U盘中storage_probe()参数从何而来??

高工
2013-02-23 14:03:30     打赏

看了半天usb驱动中关于U盘的驱动,但是就是不知道这个函数的两个参数是怎么来的??

static int storage_probe(struct usb_interface *intf, const struct usb_device_id *id)

谢谢!!



关键词: linux     盘中     storage     probe     参数    

工程师
2013-02-23 21:26:20     打赏
2楼

参考 /linux/include/linux/usb.h

定义了这2个结构体

struct usb_interface {
  struct usb_host_interface * altsetting;
  struct usb_host_interface * cur_altsetting;
  unsigned num_altsetting;
  struct usb_interface_assoc_descriptor * intf_assoc;
  int minor;
  enum usb_interface_condition condition;
  unsigned is_active:1;
  unsigned sysfs_files_created:1;
  unsigned needs_remote_wakeup:1;
  struct device dev;
  struct device * usb_dev;
  int pm_usage_cnt;
}; 

 

const struct usb_device_id *id指针指向 USB 核心用来做决定的 struct usb_device_id 的指针也被传递到这个函数,


高工
2013-02-25 18:01:29     打赏
3楼
struct usb_interface *intf,这个值从哪来的啊??

工程师
2013-02-25 20:24:07     打赏
4楼
linux-2.6.x/drivers/usb/core/driver.c

/* called from driver core with dev locked */
static int usb_probe_interface(struct device *dev)
{
    struct usb_driver *driver = to_usb_driver(dev->driver);
    struct usb_interface *intf;
    struct usb_device *udev;
    const struct usb_device_id *id;
    int error = -ENODEV;

    dev_dbg(dev, "%s\n", __FUNCTION__);

    if (is_usb_device(dev))     /* Sanity check */
        return error;

    intf = to_usb_interface(dev);
    udev = interface_to_usbdev(intf);

    id = usb_match_id(intf, driver->id_table);
    if (!id)
        id = usb_match_dynamic_id(intf, driver);
    if (id) {
        dev_dbg(dev, "%s - got id\n", __FUNCTION__);

        error = usb_autoresume_device(udev);
        if (error)
            return error;

        /* Interface "power state" doesn't correspond to any hardware
         * state whatsoever. We use it to record when it's bound to
         * a driver that may start I/0: it's not frozen/quiesced.
         */
        mark_active(intf);
        intf->condition = USB_INTERFACE_BINDING;

        /* The interface should always appear to be in use
         * unless the driver suports autosuspend.
         */
        intf->pm_usage_cnt = !(driver->supports_autosuspend);

        error = driver->probe(intf, id);
        if (error) {
            mark_quiesced(intf);
            intf->needs_remote_wakeup = 0;
            intf->condition = USB_INTERFACE_UNBOUND;
        } else
            intf->condition = USB_INTERFACE_BOUND;

        usb_autosuspend_device(udev);
    }

    return error;
}

高工
2013-02-26 08:53:25     打赏
5楼
灰常感谢!!有点眉目了~~

工程师
2013-02-26 20:35:01     打赏
6楼

共同进步, 我也是现读才找到    


高工
2013-02-27 08:33:24     打赏
7楼
你也正在学习usb??有问题继续请教哈!!

工程师
2013-02-27 20:37:24     打赏
8楼
我以前阅读过linux驱动的文档, 也是停留在阅读的水平上。    请教不敢当啊,共同交流 。呵呵

高工
2013-02-28 08:45:33     打赏
9楼
嗯,好的!!共同交流~~    

专家
2013-03-03 21:02:44     打赏
10楼
内核的参数传递

共11条 1/2 1 2 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]