从/proc/devices
文件中可以看到设备驱动程序的主机号。有没有办法列出设备驱动程序支持的次要编号?我没有源代码,我需要一种从运行的Linux中获取信息的方法。
发布于 2012-03-28 22:53:50
Linux确实会跟踪某个驱动程序分配了哪些区域。否则,在vc、serial (maj 4)和ttyaux (maj 5)区域上发生的主号码的共享将在没有额外的分派模块或类似的东西的情况下是不可能的。在fs/char_dev.c
中,您将发现
kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
因此,Linux确实是通过(主要的,次要的)查找cdev对象,而不仅仅是(主要的)。
例如,请参阅/sys/dev/char/
:
lrwxrwxrwx 1 root root 0 Mar 27 17:34 4:62 -> ../../devices/virtual/tty/tty62
lrwxrwxrwx 1 root root 0 Mar 27 17:34 4:63 -> ../../devices/virtual/tty/tty63
lrwxrwxrwx 1 root root 0 Mar 27 17:34 4:64 -> ../../devices/pnp0/00:06/tty/ttyS0
lrwxrwxrwx 1 root root 0 Mar 27 17:34 4:65 -> ../../devices/platform/serial8250/tty/ttyS1
lrwxrwxrwx 1 root root 0 Mar 27 17:34 4:66 -> ../../devices/platform/serial8250/tty/ttyS2
...
lrwxrwxrwx 1 root root 0 Mar 27 17:34 4:79 -> ../../devices/platform/serial8250/tty/ttyS15
由于我使用CONFIG_SERIAL_8250_NR_UARTS=16
CONFIG_SERIAL_8250_RUNTIME_UARTS=16
配置了内核,因此我将在sysfs目录中看到直到ttyS15的条目。这是设备驱动程序注册为我的配置操作的结果。这可能小于根据Documentation/devices.txt
保留的值。
发布于 2012-03-28 21:59:59
Linux不会跟踪它。
当使用次要编号调用open
时,此编号将传递给设备驱动程序。然后,司机可以随心所欲地使用它。
给定的驱动程序可以实现一个次要编号的表,每个次要编号指向一个状态结构。但它可能会以其他方式处理它。
https://stackoverflow.com/questions/9903650
复制相似问题