技术开发 频道

史上最经典的Linux内核学习方法论

  先看看Kconfig文件,可以看到下面的选项。

15 config USB_DEVICEFS

16 bool "USB device filesystem"

17 depends on USB

18 ---help---

19 If you say Y here (and to "/proc file system support" in the "File

20 systems" section, above), you will get a file /proc/bus/usb/devices

21 which lists the devices currently connected to your USB bus or

22 busses, and for every connected device a file named

23 "/proc/bus/usb/xxx/yyy", where xxx is the bus number and yyy the

24 device number; the latter files can be used by user space programs

25 to talk directly to the device. These files are "virtual", meaning

26 they are generated on the fly and not stored on the hard drive.

27

28 You may need to mount the usbfs file system to see the files, use

29 mount -t usbfs none /proc/bus/usb

30

31 For the format of the various /proc/bus/usb/ files, please read

32 <file:Documentation/usb/proc_usb_info.txt>.

33

34 Usbfs files can't handle Access Control Lists (ACL), which are the

35 default way to grant access to USB devices for untrusted users of a

36 desktop system. The usbfs functionality is replaced by real

37 device-nodes managed by udev. These nodes live in /dev/bus/usb and

38 are used by libusb.

  选项USB_DEVICEFS与usbfs文件系统有关。usbfs文件系统挂载在/proc/bus/usb目录,显示了当前连接的所有USB 设 备及总线的各种信息,每个连接的USB设备在其中都会有一个对应的文件进行描述。比如文件/proc/bus/usb/xxx/yyy,xxx表示总__________线的 序号,yyy表示设备所在总线的地址。不过不能够依赖它们来稳定地访问设备,因为同一设备两次连接对应的描述文件可能会不同,比如,第一次连接一个设备 时,它可能是002/027,一段时间后再次连接,它可能就已经改变为002/048。

  就好比好不容易你暗恋的mm今天见你的时候对你抛了个媚眼,你心花怒放,赶快去买了100块彩票庆祝,到第二天再见到她的时候,她对你说你是谁啊,你悲痛欲绝的刮开那100块彩票,上面清一色的谢谢你。

  因为usbfs文件系统并不属于USB子系统实现的核心部分,与之相关的代码我们可以不必关注。

74 config USB_SUSPEND

75 bool "USB selective suspend/resume and wakeup (EXPERIMENTAL)"

76 depends on USB && PM && EXPERIMENTAL

77 help

78 If you say Y here, you can use driver calls or the sysfs

79 "power/state" file to suspend or resume individual USB

80 peripherals.

81

82 Also, USB "remote wakeup" signaling is supported, whereby some

83 USB devices (like keyboards and network adapters) can wake up

84 their parent hub. That wakeup cascades up the USB tree, and

85 could wake the system from states like suspend-to-RAM.

86

87 If you are unsure about this, say N here.

  这一项是有关USB设备的挂起和恢复。开发USB的人都是节电节能的好孩子,所以协议里就规定了,所有的设备都必须支持挂起状态,就是说为了达到节 电的目的,当设备在指定的时间内,如果没有发生总线传输,就要进入挂起状态。当它收到一个non-idle的信号时,就会被唤醒。节约用电从USB做起。 不过这个与主题也没太大关系,相关代码也可以不用关注了。

  剩下的还有几项,不过似乎与咱们关系也不大,还是去看看Makefile。

5 usbcore-objs := usb.o hub.o hcd.o urb.o message.o driver.o \

6 config.o file.o buffer.o sysfs.o endpoint.o \

7 devio.o notify.o generic.o quirks.o

8

9 ifeq ($(CONFIG_PCI),y)

10 usbcore-objs += hcd-pci.o

11 endif

12

13 ifeq ($(CONFIG_USB_DEVICEFS),y)

14 usbcore-objs += inode.o devices.o

15 endif

16

17 obj-$(CONFIG_USB) += usbcore.o

18

19 ifeq ($(CONFIG_USB_DEBUG),y)

20 EXTRA_CFLAGS += -DDEBUG

21 endif

  Makefile可比Kconfig简略多了,所以看起来也更亲切点,咱们总是拿的money越多越好,看的代码越少越好。这里之所以会出现 CONFIG_PCI,是因为通常USB的Root Hub包含在一个PCI设备中。hcd-pci和hcd顾名而思义就知道是说主机控制器的,它们实现了主机控制器公共部分,按

  协议里的说法它们就是 HCDI(HCD的公共接口),host目录下则实现了各种不同的主机控制器。CONFIG_USB_DEVICEFS前面的Kconfig文件里也见到了,关于usbfs的,与咱们的主题无关,inode.c和devices.c两个文件也可以不用管了。

  那么我们可以得出结论,为了理解内核对USB子系统的实现,我们需要研究

  buffer.c、config.c、driver.c、 endpoint.c、file.c、generic.c、hcd.c

  hcd.h、hub.c、message.c、notify.c、otg_whitelist.h、quirks.c、sysfs.c、urb.c 和usb.c文件。

  这么看来,好像大都需要关注的样子,没有减轻多少压力,不过这里本身就是USB Core部分,是要做很多的事为咱们分忧的,所以多点也是可以理解的。

6
相关文章