Linux 内核启动信息的打印 --- dev_driver_string函数/dev_name函数

内核启动时,常会打印出一些信息:开头是 "驱动模块的名字: + 具体的信息"

如:在运行的linux系统设备上,插入鼠标,就会打印出鼠标的相关信息;

[ 402.134068] input: USB Optical Mouse as /devices/soc0/soc/2100000.aips-bus/2184000.usb/ci_hdrc.0/usb1/1-1/1-1:1.0/0003:0461:4D81.0003/input/input3
[ 402.149618] hid-generic 0003:0461:4D81.0003: input: USB HID v1.11 Mouse [USB Optical Mouse] on usb-ci_hdrc.0-1/input0
红色标注的 "input: " 是鼠标插入式,内核检测到,鼠标是输入设备,于是就把将鼠标与输入模块的驱动。

红色标注的"hid-generic 0003:0461:4D81.0003" 是鼠标匹配的驱动是输入模块的hid-generic驱动。

这样的信息输出通常都是有 dev_info/dev_err/dev_notice/...., 具体可参考:linux/include/linux/device.h文件中这些函数的定义。

这些函数的定义格式都是相同的,只是输出等级不同,即print_level不同。

dev_info(dev, “%s[%d] \n”, __func__, __LINE__);

这是第一个参数不同,后两个就是printk的参数相同,格式也相同。

第一个参数dev: 就是将这个设备的模块的名字等信息相同, 最终还是调用printk打印出来.

通常,dev第一个参数的打信息,是用两个函数从dev中获取信息。

const char *dev_driver_string(const struct device *dev)
{
        struct device_driver *drv;


        /* dev->driver can change to NULL underneath us because of unbinding,
         * so be careful about accessing it.  dev->bus and dev->class should
         * never change once they are set, so they don't need special care.
         */
        drv = ACCESS_ONCE(dev->driver);
        return drv ? drv->name :
                        (dev->bus ? dev->bus->name :
                        (dev->class ? dev->class->name : ""));

}

调用这个函数可以输出 "hid-generic"

static inline const char *dev_name(const struct device *dev)
{
        /* Use the init name until the kobject becomes available */
        if (dev->init_name)
                return dev->init_name;


        return kobject_name(&dev->kobj);

}

调用这个函数,可以输出" 0003: ......"

dev_driver_string() / dev_name() 是内核调试打印信息中常用的输出函数
---------------------
作者:香雨亭榭
来源:CSDN
原文:https://blog.csdn.net/hpu11/article/details/80688565
版权声明:本文为博主原创文章,转载请附上博文链接!

 

struct usb_interface {
/* array of alternate settings for this interface,
* stored in no particular order */
struct usb_host_interface *altsetting;

struct usb_host_interface *cur_altsetting; /* the currently
* active alternate setting */
unsigned num_altsetting; /* number of alternate settings */

/* If there is an interface association descriptor then it will list
* the associated interfaces */
struct usb_interface_assoc_descriptor *intf_assoc;

int minor; /* minor number this interface is
* bound to */
enum usb_interface_condition condition; /* state of binding */
unsigned sysfs_files_created:1; /* the sysfs attributes exist */
unsigned ep_devs_created:1; /* endpoint "devices" exist */
unsigned unregistering:1; /* unregistration is in progress */
unsigned needs_remote_wakeup:1; /* driver requires remote wakeup */
unsigned needs_altsetting0:1; /* switch to altsetting 0 is pending */
unsigned needs_binding:1; /* needs delayed unbind/rebind */
unsigned resetting_device:1; /* true: bandwidth alloc after reset */
unsigned authorized:1; /* used for interface authorization */

struct device dev; /* interface specific device info */
struct device *usb_dev;
atomic_t pm_usage_cnt; /* usage counter for autosuspend */
struct work_struct reset_ws; /* for resets in atomic context */
};

dev_name(&intf->dev)对应着USB的四元组信息,可以用这个信息,来判断设备的具体位置,然后根据该信息,给设备固定名字

cdc_acm 3-1:1.0: ttyACM0: USB ACM device

转载于:https://www.cnblogs.com/erhu-67786482/p/11045145.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值