Linux 设备驱动之 UIO 机制(基本概念)

http://blog.csdn.net/xy010902100449/article/details/46917623

一个设备驱动的主要任务有两个:
1. 存取设备的内存
2. 处理设备产生的中断

对于第一个任务,UIO 核心实现了mmap()可以处理物理内存(physical memory),逻辑内存(logical memory),
虚拟内存(virtual memory)。UIO驱动的编写是就不需要再考虑这些繁琐的细节。

第二个任务,对于设备中断的应答必须在内核空间进行。所以在内核空间有一小部分代码
用来应答中断和禁止中断,但是其余的工作全部留给用户空间处理。

如果用户空间要等待一个设备中断,它只需要简单的阻塞在对 /dev/uioX的read()操作上。
当设备产生中断时,read()操作立即返回。UIO 也实现了poll()系统调用,你可以使用
select()来等待中断的发生。select()有一个超时参数可以用来实现有限时间内等待中断。

对设备的控制还可以通过/sys/class/uio下的各个文件的读写来完成。你注册的uio设备将会出现在该目录下。
假如你的uio设备是uio0那么映射的设备内存文件出现在 /sys/class/uio/uio0/maps/mapX,对该文件的读写就是
对设备内存的读写。
如下的图描述了uio驱动的内核部分,用户空间部分,和uio 框架以及内核内部函数的关系。
这里写图片描述

这里写图片描述

 struct uio_portio {
    struct kobject kobj;
    struct uio_port *port;
};

/**
 * struct uio_port - description of a UIO port region
 * @name:       name of the port region for identification
 * @start:      start of port region
 * @size:       size of port region
 * @porttype:       type of port (see UIO_PORT_* below)
 * @portio:     for use by the UIO core only.
 */
struct uio_port {
    const char      *name;
    unsigned long       start;
    unsigned long       size;
    int         porttype;
    struct uio_portio   *portio;
};

/* defines for uio_port->porttype */
#define UIO_PORT_NONE   0
#define UIO_PORT_X86    1
#define UIO_PORT_GPIO   2
#define UIO_PORT_OTHER  3


  /*
  * struct uio_mem - description of a UIO memory region
 * @name:       name of the memory region for identification
 * @addr:       address of the device's memory
 * @size:       size of IO
 * @memtype:        type of memory addr points to
 * @internal_addr:  ioremap-ped version of addr, for driver internal use
 * @map:        for use by the UIO core only.
 */
struct uio_mem {
    const char      *name;// 内存映射的名字
    unsigned long       addr; // 内存块的地址
    unsigned long       size; //addr所指向的内存块的大小
    int         memtype; //UIO_MEM_PHYS,UIO_MEM_LOGICAL(kmalloc()),UIO_MEM_VIRTUAL( virtual memory)
    void __iomem        *internal_addr; // If you have to access this memory region from within your kernel module,
                                                               // you will want to map it internally by using something like ioremap().

    struct uio_map      *map;
};

 struct uio_map {
    struct kobject kobj;
    struct uio_mem *mem;
};


 static const struct vm_operations_struct uio_vm_ops = {
    .open = uio_vma_open,
    .close = uio_vma_close,
    .fault = uio_vma_fault,
};
 static struct device_attribute uio_class_attributes[] = {
    __ATTR(name, S_IRUGO, show_name, NULL),
    __ATTR(version, S_IRUGO, show_version, NULL),
    __ATTR(event, S_IRUGO, show_event, NULL),
    {}
};
 /* UIO class infrastructure */
static struct class uio_class = {
    .name = "uio",// /sys/class/uio
    .dev_attrs = uio_class_attributes,
};

static const struct file_operations uio_fops = {
    .owner      = THIS_MODULE,
    .open       = uio_open,
    .release    = uio_release,
    .read       = uio_read,
    .write      = uio_write,
    .mmap       = uio_mmap,
    .poll       = uio_poll,
    .fasync     = uio_fasync,
    .llseek     = noop_llseek,
};

/* Protect idr accesses */
static DEFINE_MUTEX(minor_lock);
static DEFINE_IDR(uio_idr);
//关于idr机制,参见 http://blog.csdn.net/ganggexiongqi/article/details/6737389

struct uio_device {
    struct module       *owner;
    struct device       *dev; //在__uio_register_device中初始化
    int         minor; // 次设备id号,uio_get_minor
    atomic_t        event; //中断事件计数
    struct fasync_struct    *async_queue;//该设备上的异步等待队列//
                                                               // 关于 “异步通知“ //参见LDD3第六章
    wait_queue_head_t   wait; //该设备上的等待队列,在注册设备时(__uio_register_device)初始化
    int         vma_count;
    struct uio_info     *info;// 指向用户注册的uio_info,在__uio_register_device中被赋值的
    struct kobject      *map_dir;
    struct kobject      *portio_dir;
};  
/*
 * struct uio_info - UIO device capabilities
 * @uio_dev:        the UIO device this info belongs to
 * @name:       device name
 * @version:        device driver version
 * @mem:        list of mappable memory regions, size==0 for end of list
 * @port:       list of port regions, size==0 for end of list
 * @irq:        interrupt number or UIO_IRQ_CUSTOM
 * @irq_flags:      flags for request_irq()
 * @priv:       optional private data
 * @handler:        the device's irq handler
 * @mmap:       mmap operation for this uio device
 * @open:       open operation for this uio device
 * @release:        release operation for this uio device
 * @irqcontrol:     disable/enable irqs when 0/1 is written to /dev/uioX
 */     
struct uio_info {
    struct uio_device   *uio_dev; // 在__uio_register_device中初始化
    const char      *name; // 调用__uio_register_device之前必须初始化
    const char      *version; //调用__uio_register_device之前必须初始化
    struct uio_mem      mem[MAX_UIO_MAPS];
    struct uio_port     port[MAX_UIO_PORT_REGIONS];
    long            irq; //分配给uio设备的中断号,调用__uio_register_device之前必须初始化
    unsigned long       irq_flags;// 调用__uio_register_device之前必须初始化
    void            *priv; //
    irqreturn_t (*handler)(int irq, struct uio_info *dev_info); //uio_interrupt中调用,用于中断处理
                                                                // 调用__uio_register_device之前必须初始化
    int (*mmap)(struct uio_info *info, struct vm_area_struct *vma); //在uio_mmap中被调用,
                                                                    // 执行设备打开特定操作
    int (*open)(struct uio_info *info, struct inode *inode);//在uio_open中被调用,执行设备打开特定操作
    int (*release)(struct uio_info *info, struct inode *inode);//在uio_device中被调用,执行设备打开特定操作
    int (*irqcontrol)(struct uio_info *info, s32 irq_on);//在uio_write方法中被调用,执行用户驱动的
                                                                                       //特定操作。
};
  
  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 1、 函数: static int __init uio_init(void)

    功能:申请字符设备号,设备,并注册到系统中,注册uio_class到系统中
    调用模块:init_uio_class()
    执行流程:
    申请字符设备号,设备,并注册到系统中,注册uio_class到系统中 //init_uio_class
    //创建”/sys/class/uio”

  • 2、函数:uio_exit
    功能:注销uio_class,注销字符设备编号,删除设备
    调用模块:release_uio_class
    执行流程:
    注销uio_class,注销字符设备编号,删除设备 //release_uio_class

  • 3、函数:static void release_uio_class(void)
    功能:注销uio_class,注销字符设备编号,删除设备
    执行流程:
    注销uio_class//class_unregister
    注销字符设备编号,删除设备 //uio_major_cleanup

  • 4、函数:static int init_uio_class(void)
    功能:申请字符设备号,设备,并注册到系统中,注册uio_class到系统中
    调用模块: uio_major_init()
    class_register()
    执行流程:
    申请字符设备编号,设备,并初始化//uio_major_init
    注册class 类型全局变量uio_class到系统//class_register
    //ls -l /sys/class 查看

  • 5、函数: static int uio_major_init(void)
    功能:申请字符设备编号,设备,并初始化
    调用模块:
    alloc_chrdev_region()
    cdev_alloc()
    kobject_set_name()
    cdev_add()
    执行流程:
    申请字符设备编号(多个)//alloc_chrdev_region
    //2^UIO_MAX_DEVICES个从设备
    //设备的名字为”uio”
    分配一个表示字符设备的cdev结构//cdev_alloc
    初始化cdev结构的file_operations类型字段//控制cdev设备的各种操作,
    // 如 open, close, read, write…
    设置cdev结构的kobj字段的name为uio //kobject_set_name
    添加字符设备到系统中 //cdev_add,调用成功后,我们的设备就“活了”
    // cat /proc/devices ,可以查看到分配到主设备号
    保存主设备号到全局变量uio_major
    保存设备指针到全局变量uio_cdev

    返回

  • 6、函数:static void uio_major_cleanup(void)
    功能:注销字符设备编号,删除设备
    调用模块:unregister_chrdev_region
    执行流程:
    注销字符设备编号//unregister_chrdev_region
    删除设备uio_cdev //cdev_del

    file_operations

  • 7、 函数:static int uio_open(struct inode *inode, struct file *filep)

    参数:inode:
    filep:
    功能:获得和次设备号关联的uio_device指针,创建一个辅助变量listener, 并调用info指向的uio_info结构中的open方法
    执行流程:
    获得保护uio_idr的锁 //mutex_lock
    从inode 结构中获取次编号 //iminor
    获得和次编号关联的uio_device指针 //idr_find 在那里进行地设置呢???
    // 在 uio_get_minor 中分配的次设备编号并设置的关联
    放弃锁 //mutex_unlock
    增加uio_device类型指针指向的模块的引用计数 //try_module_get
    分配一个uio_listener类型的listener //kmalloc
    关联listener和 uio_device 指针
    获得uio_device 指向设备的事件计数值,并存入listener //atomic_read
    把listener指针保存到filep->private_data字段
    调用uio_device的info字段指向的uio_info中的open方法//*

  • 8、函数:static int uio_release(struct inode *inode, struct file *filep)
    功能:从而调用uio_device的字段info指向的uio_info中的release方法
    释放辅助结构体listener
    执行流程:
    从filep->private_data中获得uio_open中保存的listener指针。
    利用listener指针找到指向uio_device类型结构指针
    从而调用uio_device的字段info指向的uio_info中的release方法。
    减少uio_device类型指针指向的模块的引用计数//module_put
    释放listener结构体 //kfree

  • 9、 函数:static int uio_fasync(int fd, struct file *filep, int on)

    参数:
    fd
    filep
    on : 0, 删除;非零,添加
    功能: 管理uio_device的async_queue
    调用模块:fasync_helper()
    执行流程:
    从filep->private_data中获得uio_open中保存的listener指针。
    利用listener指针找到指向uio_device类型结构指针
    设置uio_device的async_queue//fasync_helper

  • 10、函数:static unsigned int uio_poll(struct file *filep, poll_table *wait)
    功能: 使进程在传递到该系统调用的所有文件描述符对应的等待队列上等待,并返回一个是否可以立即无阻塞执行的位掩码
    执行流程:
    从filep->private_data中获得uio_open中保存的listener指针。
    利用listener指针找到指向uio_device类型结构指针
    判断用uio_device类型指针的info字段(uio_info类型)的irq成员不为0,则继续,
    否则,返回IO错误
    向poll_table类型的wait表中添加uio_device类型指针指向结构的wait等待队列//poll_wait
    //!!!! 注意poll_wait并不阻塞
    如果listener中的事件计数值event_count和uio_device的
    事件计数值count不一致时// uio_interrupt调用了uio_event_notify对
    //中断事件计数器增一
    返回“通常”的数据可读的位掩码

  • 11、函数:static ssize_t uio_read(struct file *filep, char __user *buf,
    size_t count, loff_t *ppos)
    功能:复制uio设备中断事件计数器的值到用户空间

    执行流程:
    从filep->private_data中获得uio_open中保存的listener指针
    利用listener指针找到指向uio_device类型结构指针
    创建一个等待队列的项 //DECLARE_WAITQUEUE
    检查确认uio设备的设备info的中断号(0)不为零
    添加本进程到uio设备的等待队列wait上 // add_wait_queue
    //由uio_interrupt调用uio_event_notify唤醒
    REP: 设置当前进程的 “可中断标志”
    检查是否有中断事件发生,
    如果有(listener中的中断事件计数值event_count)和uio设备中的中断事件
    计数器值不一致),则将设备中断计数器的值复制到用户空间
    并将listener中的中断事件计数值更新为设备的中断事件计数值
    把当前进程设置为TASK_RUNNING状态,
    并将当前进程从uio设备的等待队列wait上删除
    如果文件读时设置了O_NONBLOCK标志,
    那么,把当前进程设置为TASK_RUNNING状态,
    并将当前进程从uio设备的等待队列wait上删除
    返回 -EAGAIN
    检查当前进程是否有信号处理 //signal_pending
    //http://blog.chinaunix.net/space.php?uid=20746501&do=blog&cuid=1820175
    如有,把当前进程设置为TASK_RUNNING状态,
    并将当前进程从uio设备的等待队列wait上删除
    并返回 -ERESTARTSYS
    执行调度 //schedule
    JMP REP

  • 12、uio_register_device
    功能: 调用uio_info中注册的handler中断处理函数,对设备的中断事件计数器增一并通知各读进程,有数据可读
    执行流程:
    从filep->private_data中获得uio_open中保存的listener指针
    调用 uio_device类型指针的info字段(uio_info类型)的handler
    如果属于本设备的中断,并且在handler中已经处理过
    那么对设备的中断事件计数器增一,
    并通知各读进程,有数据可读 //uio_event_notify

  • 13、函数:void uio_event_notify(struct uio_info *info)
    功能:“触发“ 一个中断事件,对设备的中断事件计数器增一,并通知各读进程,有数据可读
    执行流程:
    从filep->private_data中获得uio_open中保存的listener指针
    对中断事件计数器增一
    唤醒阻塞在设备等待队列wait上的读进程 //wake_up_interruptible
    // 该队列上的进程在uio_read中添加
    向异步等待队列async_queue发出可读信号 //kill_fasync

  • 14、 函数:static ssize_t uio_write(struct file *filep, const char __user
    *buf,size_t count, loff_t *ppos)
    功能: 读取用户空间的值,并调用uio_device注册的irqcontrol函数
    执行流程:
    从filep->private_data中获得uio_open中保存的listener指针
    调用 uio_device类型指针的info字段(uio_info类型)的handler
    检验info字段(uio_info类型)的中断号irq
    读取从用户空间传过来的32位的值//copy_from_user
    调用info字段(uio_info类型)的irqcontrol函数,将用户空间传递过来的32位值作为参数传入。

  • 15、函数:static int uio_mmap(struct file *filep, struct vm_area_struct

    *vma)

    执行流程:
    从filep->private_data中获得uio_open中保存的listener指针
    调用 uio_device类型指针的info字段(uio_info类型)的handler
    保存uio_device类型指针到 vma 的vm_private_data
    返回映射区域的索引(比如 mapX,的X) //uio_find_mem_index
    计算实际的页数和请求的页数
    如果实际的页数小于请求的页数那么,返回-EINVAL
    如果uio设备注册有mmap函数,那么就调用它
    当内存区域的类型为UIO_MEM_PHYS时,
    //uio_mmap_physical
    当内存区域的类型为UIO_MEM_LOGICAL、UIO_MEM_VIRTUAL时,
    为虚拟内存区域设置操作,和告诉内存不要将
    该区域交换出去,访问计数器增一//uio_mmap_logical


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
基本信息 原书名: Essential Linux Device Drivers 原出版社: Prentice Hall 作者: (印)Sreekrishnan Venkateswaran 译者: 宋宝华 何昭然 史海滨 吴国成 丛书名: 图灵程序设计丛书 操作系统 出版社:人民邮电出版社 ISBN:9787115221674 出版日期:2010 年6月 页码:468 内容简介   本书是linux设备驱动程序开发领域的权威著作。全书基于2.6内核,不仅透彻讲解了基本概念和技术,更深入探讨了其他书没有涵盖或浅尝辄止的许多重要主题和关键难点,如pcmcia、i2c和usb等外部总线以及视频、音频、无线连网和闪存等驱动程序的开发,并讲解了相关的内核源码文件,给出了完整的开发实例。   本书适合中高级linux开发人员阅读。 目录 第1章 引言1 1.1 演进1 1.2 gnu copyleft2 1.3 kernel.org2 1.4 邮件列表和论坛3 1.5 linux发行版3 1.6 查看源代码4 1.7 编译内核7 1.8 可加载的模块8 1.9 整装待发9 第2章 内核11 2.1 启动过程11 2.1.1 bios-provided physical ram map12 2.1.2 758mb lowmem available14 2.1.3 kernel command line: ro root=/dev/hda114 2.1.4 calibrating delay...1197.46 .bogomips (lpj=2394935)15 2.1.5 checking hlt instruction16 2.1.6 net: registered protocol family 217 2.1.7 freeing initrd memory: 387k freed17 2.1.8 io scheduler anticipatory registered (default)18 2.1.9 setting up standard pci resources18 2.1.10 ext3-fs: mounted filesystem19 2.1.11 init: version 2.85 booting19 2.2 内核模式和用户模式20 2.3 进程上下文和中断上下文20 2.4 内核定时器21 2.4.1 hz和jiffies21 2.4.2 长延时22 2.4.3 短延时24 2.4.4 pentium时间戳计数器24 2.4.5 实时钟25 2.5 内核中的并发26 2.5.1 自旋锁和互斥体26 2.5.2 原子操作30 2.5.3 读—写锁31 2.5.4 调试32 2.6 proc文件系统32 2.7 内存分配33 2.8 查看源代码34 第3章 内核组件37 3.1 内核线程37 3.1.1 创建内核线程37 3.1.2 进程状态和等待队列41 3.1.3 用户模式辅助程序42 3.2 辅助接口43 3.2.1 链表44 3.2.2 散列链表49 3.2.3 工作队列49 3.2.4 通知链51 3.2.5 完成接口54 3.2.6 kthread辅助接口56 3.2.7 错误处理助手57 3.3 查看源代码58 第4章 基本概念61 4.1 设备驱动程序介绍61 4.2 中断处理63 4.2.1 中断上下文63 4.2.2 分配irq号64 4.2.3 设备实例:导航杆65 4.2.4 softirq和tasklet68 4.3 linux设备模型71 4.3.1 udev71 4.3.2 sysfs、kobject和设备类73 4.3.3 热插拔和冷插拔76 4.3.4 微码下载76 4.3.5 模块自动加载77 4.4 内存屏障78 4.5 电源管理79 4.6 查看源代码79 第5章 字符设备驱动程序81 5.1 字符设备驱动程序基础81 5.2 设备实例:系统cmos82 5.2.1 驱动程序初始化83 5.2.2 打开与释放86 5.2.3 数据交换88 5.2.4 查找92 5.2.5 控制94 5.3 检测数据可用性95 5.3.1 轮询95 5.3.2 fasync98 5.4 和并行端口交互99 5.5 rtc子系统108 5.6 伪字符驱动程序109 5.7 混杂驱动程序110 5.8 字符设备驱动程序注意事项115 5.9 查看源代码115 第6章 串行设备驱动程序118 6.1 层次架构119 6.2 uart驱动程序121 6.2.1 设备实例:手机122 6.2.2 rs-485132 6.3 tty驱动程序132 6.4 线路规程134 6.5 查看源代码141 第7章 输入设备驱动程序143 7.1 输入事件驱动程序144 7.2 输入设备驱动程序150 7.2.1 serio150 7.2.2 键盘150 7.2.3 鼠标152 7.2.4 触摸控制器157 7.2.5 加速度传感器158 7.2.6 输出事件158 7.3 调试159 7.4 查看源代码160 第8章 i2c协议161 8.1 i2c/smbus是什么161 8.2 i2c核心162 8.3 总线事务164 8.4 设备实例:eeprom164 8.4.1 初始化165 8.4.2 探测设备167 8.4.3 检查适配器的功能169 8.4.4 访问设备169 8.4.5 其他函数170 8.5 设备实例:实时时钟171 8.6 i2c-dev174 8.7 使用lm-sensors监控硬件174 8.8 spi总线174 8.9 1-wire总线176 8.10 调试176 8.11 查看源代码176 第9章 pcmcia和cf179 9.1 pcmcia/cf是什么179 9.2 linux-pcmcia子系统181 9.3 主机控制器驱动程序183 9.4 pcmcia核心183 9.5 驱动程序服务183 9.6 客户驱动程序183 9.6.1 数据结构184 9.6.2 设备实例:pcmcia卡185 9.7 将零件组装在一起188 9.8 pcmcia存储189 9.9 串行pcmcia189 9.10 调试191 9.11 查看源代码191 第10章 pci193 10.1 pci系列193 10.2 寻址和识别195 10.3 访问pci198 10.3.1 配置区198 10.3.2 i/o和内存199 10.4 dma200 10.5 设备实例:以太网—调制解调器卡203 10.5.1 初始化和探测203 10.5.2 数据传输209 10.6 调试214 10.7 查看源代码214 第11章 usb216 11.1 usb体系架构216 11.1.1 总线速度218 11.1.2 主机控制器218 11.1.3 传输模式219 11.1.4 寻址219 11.2 linux-usb子系统220 11.3 驱动程序的数据结构221 11.3.1 usb_device结构体221 11.3.2 urb222 11.3.3 管道223 11.3.4 描述符结构223 11.4 枚举225 11.5 设备实例:遥测卡225 11.5.1 初始化和探测过程226 11.5.2 卡寄存器的访问230 11.5.3 数据传输233 11.6 类驱动程序236 11.6.1 大容量存储设备236 11.6.2 usb-串行端口转换器241 11.6.3 人机接口设备243 11.6.4 蓝牙243 11.7 gadget驱动程序243 11.8 调试244 11.9 查看源代码245 第12章 视频驱动程序247 12.1 显示架构247 12.2 linux视频子系统249 12.3 显示参数251 12.4 帧缓冲api252 12.5 帧缓冲驱动程序254 12.6 控制台驱动程序265 12.6.1 设备实例:手机266 12.6.2 启动logo270 12.7 调试270 12.8 查看源代码271 第13章 音频驱动程序273 13.1 音频架构273 13.2 linux声音子系统275 13.3 设备实例:mp3播放器277 13.3.1 驱动程序函数和结构体278 13.3.2 alsa编程287 13.4 调试288 13.5 查看源代码289 第14章 块设备驱动程序291 14.1 存储技术291 14.2 linux块i/o层295 14.3 i/o调度器295 14.4 块驱动程序数据结构和方法296 14.5 设备实例:简单存储控制器298 14.5.1 初始化299 14.5.2 块设备操作301 14.5.3 磁盘访问302 14.6 高级主题304 14.7 调试306 14.8 查看源代码306 第15章 网络接口卡308 15.1 驱动程序数据结构308 15.1.1 套接字缓冲区309 15.1.2 网络设备接口310 15.1.3 激活311 15.1.4 数据传输311 15.1.5 看门狗311 15.1.6 统计312 15.1.7 配置313 15.1.8 总线相关内容314 15.2 与协议层会话314 15.2.1 接收路径314 15.2.2 发送路径315 15.2.3 流量控制315 15.3 缓冲区管理和并发控制315 15.4 设备实例:以太网nic316 15.5 isa网络驱动程序321 15.6 atm321 15.7 网络吞吐量322 15.7.1 驱动程序性能322 15.7.2 协议性能323 15.8 查看源代码324 第16章 linux无线设备驱动326 16.1 蓝牙327 16.1.1 bluez328 16.1.2 设备实例:cf卡329 16.1.3 设备实例:usb适配器330 16.1.4 rfcomm331 16.1.5 网络332 16.1.6 hid334 16.1.7 音频334 16.1.8 调试334 16.1.9 关于源代码334 16.2 红外335 16.2.1 linux-irda335 16.2.2 设备实例:超级i/o芯片337 16.2.3 设备实例:ir dongle338 16.2.4 ircomm340 16.2.5 联网340 16.2.6 irda套接字341 16.2.7 lirc341 16.2.8 查看源代码342 16.3 wifi343 16.3.1 配置343 16.3.2 设备驱动程序346 16.3.3 查看源代码347 16.4 蜂窝网络347 16.4.1 gprs347 16.4.2 cdma349 16.5 当前趋势350 第17章 存储技术设备352 17.1 什么是闪存352 17.2 linux-mtd子系统353 17.3 映射驱动程序353 17.4 nor芯片驱动程序358 17.5 nand芯片驱动程序359 17.6 用户模块361 17.6.1 块设备模拟361 17.6.2 字符设备模拟361 17.6.3 jffs2362 17.6.4 yaffs2363 17.7 mtd工具363 17.8 配置mtd363 17.9 xip364 17.10 fwh364 17.11 调试367 17.12 查看源代码367 第18章 嵌入式linux369 18.1 挑战369 18.2 元器件选择370 18.3 工具链371 18.4 bootloader372 18.5 内存布局374 18.6 内核移植375 18.7 嵌入式驱动程序376 18.7.1 闪存377 18.7.2 uart377 18.7.3 按钮和滚轮378 18.7.4 pcmcia/cf378 18.7.5 sd/mmc378 18.7.6 usb378 18.7.7 rtc378 18.7.8 音频378 18.7.9 触摸屏379 18.7.10 视频379 18.7.11 cpld/fpga379 18.7.12 连接性379 18.7.13 专用领域电子器件380 18.7.14 更多驱动程序380 18.8 根文件系统380 18.8.1 nfs挂载的根文件系统381 18.8.2 紧凑型中间件382 18.9 测试基础设施383 18.10 调试383 18.10.1 电路板返工384 18.10.2 调试器385 第19章 用户空间的驱动程序386 19.1 进程调度和响应时间387 19.1.1 原先的调度器387 19.1.2 o(1)调度器387 19.1.3 cfs388 19.1.4 响应时间388 19.2 访问i/o区域390 19.3 访问内存区域393 19.4 用户模式scsi395 19.5 用户模式usb397 19.6 用户模式i2c400 19.7 uio401 19.8 查看源代码402 第20章 其他设备驱动程序403 20.1 ecc报告403 20.2 频率调整407 20.3 嵌入式控制器408 20.4 acpi408 20.5 isa与mca410 20.6 火线410 20.7 智能输入/输出411 20.8 业余无线电411 20.9 voip411 20.10 高速互联412 20.10.1 infiniband413 20.10.2 rapidio413 20.10.3 光纤通道413 20.10.4 iscsi413 第21章 调试设备驱动程序414 21.1 kdb414 21.1.1 进入调试器415 21.1.2 kdb415 21.1.3 kgdb417 21.1.4 gdb420 21.1.5 jtag调试器421 21.1.6 下载423 21.2 内核探测器423 21.2.1 kprobe423 21.2.2 jprobe427 21.2.3 返回探针429 21.2.4 局限性431 21.2.5 查看源代码431 21.3 kexec与kdump431 21.3.1 kexec432 21.3.2 kdump与kexec协同工作432 21.3.3 kdump433 21.3.4 查看源代码437 21.4 性能剖析437 21.4.1 利用oprofile剖析内核性能438 21.4.2 利用gprof剖析应用程序性能440 21.5 跟踪441 21.6 ltp444 21.7 uml444 21.8 诊断工具444 21.9 内核修改配置选项444 21.10 测试设备445 第22章 维护与发布446 22.1 代码风格446 22.2 修改标记446 22.3 版本控制447 22.4 一致性检查447 22.5 构建脚本448 22.6 可移植代码450 第23章 结束语451 23.1 流程一览表451 23.2 下一步该做什么452 附录a linux汇编453 附录b linux与bios457 附录c seq文件461
Prentice.Essential Linux Device Drivers.2008 一个老外写的,写的非常详细 Chapter 1. Introduction Evolution The GNU Copyleft Kernel.org Mailing Lists and Forums Linux Distributions Looking at the Sources Building the Kernel Loadable Modules Before Starting Chapter 2. A Peek Inside the Kernel Booting Up Kernel Mode and User Mode Process Context and Interrupt Context Kernel Timers Concurrency in the Kernel Process Filesystem Allocating Memory Looking at the Sources Chapter 3. Kernel Facilities Kernel Threads Helper Interfaces Looking at the Sources Chapter 4. Laying the Groundwork Introducing Devices and Drivers Interrupt Handling The Linux Device Model Memory Barriers Power Management Looking at the Sources Chapter 5. Character Drivers Char Driver Basics Device Example: System CMOS Sensing Data Availability Talking to the Parallel Port RTC Subsystem Pseudo Char Drivers Misc Drivers Character Caveats Looking at the Sources Chapter 6. Serial Drivers Layered Architecture UART Drivers TTY Drivers Line Disciplines Looking at the Sources Chapter 7. Input Drivers Input Event Drivers Input Device Drivers Debugging Looking at the Sources Chapter 8. The Inter-Integrated Circuit Protocol What's I2C/SMBus? I2C Core Bus Transactions Device Example: EEPROM Device Example: Real Time Clock I2C-dev Hardware Monitoring Using LM-Sensors The Serial Peripheral Interface Bus The 1-Wire Bus Debugging Looking at the Sources Chapter 9. PCMCIA and Compact Flash What's PCMCIA/CF? Linux-PCMCIA Subsystem Host Controller Drivers PCMCIA Core Driver Services Client Drivers Tying the Pieces Together PCMCIA Storage Serial PCMCIA Debugging Looking at the Sources Chapter 10. Peripheral Component Interconnect The PCI Family Addressing and Identification Accessing PCI Regions Direct Memory Access Device Example: Ethernet-Modem Card Debugging Looking at the Sources Chapter 11. Universal Serial Bus USB Architecture Linux-USB Subsystem Driver Data Structures Enumeration Device Example: Telemetry Card Class Drivers Gadget Drivers Debugging Looking at the Sources Chapter 12. Video Drivers Display Architecture Linux-Video Subsystem Display Parameters The Frame Buffer API Frame Buffer Drivers Console Drivers Debugging Looking at the Sources Chapter 13. Audio Drivers Audio Architecture Linux-Sound Subsystem Device Example: MP3 Player Debugging Looking at the Sources Chapter 14. Block Drivers Storage Technologies Linux Block I/O Layer I/O Schedulers Block Driver Data Structures and Methods Device Example: Simple Storage Controller Advanced Topics Debugging Looking at the Sources Chapter 15. Network Interface Cards Driver Data Structures Talking with Protocol Layers Buffer Management and Concurrency Control Device Example: Ethernet NIC ISA Network Drivers Asynchronous Transfer Mode Network Throughput Looking at the Sources Chapter 16. Linux Without Wires Bluetooth Infrared WiFi Cellular Networking Current Trends Chapter 17. Memory Technology Devices What's Flash Memory? Linux-MTD Subsystem Map Drivers NOR Chip Drivers NAND Chip Drivers User Modules MTD-Utils Configuring MTD eXecute In Place The Firmware Hub Debugging Looking at the Sources Chapter 18. Embedding Linux Challenges Component Selection Tool Chains Embedded Bootloaders Memory Layout Kernel Porting Embedded Drivers The Root Filesystem Test Infrastructure Debugging Chapter 19. Drivers in User Space Process Scheduling and Response Times Accessing I/O Regions Accessing Memory Regions User Mode SCSI User Mode USB User Mode I2C UIO Looking at the Sources Chapter 20. More Devices and Drivers ECC Reporting Frequency Scaling Embedded Controllers ACPI ISA and MCA FireWire Intelligent Input/Output Amateur Radio Voice over IP High-Speed Interconnects Chapter 21. Debugging Device Drivers Kernel Debuggers Kernel Probes Kexec and Kdump Profiling Tracing Linux Test Project User Mode Linux Diagnostic Tools Kernel Hacking Config Options Test Equipment Chapter 22. Maintenance and Delivery Coding Style Change Markers Version Control Consistent Checksums Build Scripts Portable Code Chapter 23. Shutting Down Checklist What Next? Appendix A. Linux Assembly Debugging Appendix B. Linux and the BIOS Real Mode Calls Protected Mode Calls BIOS and Legacy Drivers Appendix C. Seq Files The Seq File Advantage Updating the NVRAM Driver Looking at the Sources

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值