(1) llseek(file,oset, whence):修改文件的读写指针 (2)read(fle, buf, count, offset):从设备文件的oiet处开始读出 count个字 节,然后增加* offset的值。 3)wite(file,buf; count, offset):从设备文件的ofet处写入 count个字节, 然后增加* offset的值。 (4) ioctl( inode,fle,cmd,arg):向一个硬件设备发命令,对设备进行控制 (5)mmap(fle,vma):将设备空间映射到进程地址空间 (6) open(inode,fle):打开并初始化设备。 (7) release( inode,file):关闭设备并释放资源 (8) fsync(file, dentry):实现内存与设备之间的同步通信。 (9) fasync(file,on):实现内存与设备之间的异步通信。 Linux Device module 6
Linux Device & Module 6 (1) llseek(file, offset, whence):修改文件的读写指针。 (2) read(file, buf, count, offset):从设备文件的offset 处开始读出count个字 节,然后增加*offset的值。 (3) write(file, buf, count, offset):从设备文件的offset处写入count个字节, 然后增加*offset的值。 (4) ioctl(inode, file, cmd, arg):向一个硬件设备发命令,对设备进行控制。 (5) mmap(file, vma):将设备空间映射到进程地址空间。 (6) open(inode, file):打开并初始化设备。 (7) release(inode, file):关闭设备并释放资源。 (8) fsync(file, dentry):实现内存与设备之间的同步通信。 (9) fasync(file, on):实现内存与设备之间的异步通信
字符设备的注册与管理 fs/devices. c struct device struct const char name struct file operations* fops static struct device struct chrdevs MAX Chrdevi 注册与注销函数: int register chrdevlunsigned int major, const char name, struct file operations*fops int unregister chrdevlunsigned int major, const char* name) 注:maor即设备的主设备号,注册后就是访问数组 chrdevs 的索引(下标) Linux Device module 7
Linux Device & Module 7 fs/devices.c struct device_struct { const char * name; struct file_operations * fops; }; static struct device_struct chrdevs[MAX_CHRDEV]; 注册与注销函数: int register_chrdev(unsigned int major, const char * name, struct file_operations *fops) int unregister_chrdev(unsigned int major, const char * name); 注:major即设备的主设备号,注册后就是访问数组chrdevs 的索引(下标)。 字符设备的注册与管理
PCI设备(驱动实现见word文档) Pc总线0 C总线1 上 下 游游 ::::RAM Pc|PC桥 Pc|桥 CPU 以太网卡 PCH-ISA桥 显卡 多功能Jo控制器 sA总线 Linux内核启动时会对所有PCI设备进行扫描、登录和分配资源等初始化 操作,建立起系统中所有PCI设备的拓扑结构 √此后当内核欲初始化某设备时,调用 module init加载该设备的驱动程 序 Linux Device module 8
Linux Device & Module 8 PCI设备(驱动实现见word文档) ✓Linux内核启动时会对所有PCI设备进行扫描、登录和分配资源等初始化 操作,建立起系统中所有PCI设备的拓扑结构 ✓此后当内核欲初始化某设备时,调用module_init加载该设备的驱动程 序
块设备 fs/block dev.c static struct const char name struct block device operations *bops blkdevsMAX blkdevi Linux Device module 9
Linux Device & Module 9 块设备 fs/block_dev.c static struct { const char *name; struct block_device_operations *bdops; } blkdevs[MAX_BLKDEV];