11. 从scull看驱动设计
驱动程序的机制设计——提供用户程序接口
scull驱动实现的设备
– scull0 – scull3 : each consisting of a memory
area that is both global and persistent
– scullpipe0 – scullpipe3 : FIFO devices, work like
pipes
– scullsingle : allow only one process to use at a
time
北京大学微处理器研究开发中心
12. 从scull看驱动设计
scull驱动实现的设备
– scullpriv : private to each virtual console,
different memory area assigned
– sculluid/scullwuid : can be opened multiple times,
but only by one user at a time.
北京大学微处理器研究开发中心
13. 设备的Major number 和 Minor number
Major number : identifies the driver
associated with the device
Minor number : used by the kernel to
determine exactly which device is being
referred to.
Linux 内核使用dev_t类型来表示major
number(12 bits)和minor number(20
bits)
北京大学微处理器研究开发中心
14. Device Number 的分配和释放
使用register_chrdev_region函数来获得指定的
register_chrdev_region
Device Number
– 需确定指定的Device Number尚未被占用,否则出错
使用alloc_chrdev_region函数来从内核获得一个当
alloc_chrdev_region
前可用的Device Number
使用unregister_chrdev_region来释放当前被占用
unregister_chrdev_region
的Device Number
详见LDD 3rd P45
北京大学微处理器研究开发中心
21. References ——for more details
Linux Device Drivers 3rd Edition
– JONATHAN CORBET, ALESSANDRO RUBINI & GREG
KROAH-HARTMAN
– O’REILLY & 东南大学出版社
Understanding the Linux Kernel
– DANIEL P. BOVET & MARCO CESATI
– O’REILLY & 东南大学出版社
Wikipedia –The Free Encyclopedia
– http://en.wikipedia.org/
北京大学微处理器研究开发中心