摘要: 1. serial8250_init serial8250_init 函数是模块的入口, static int __init serial8250_init(void) { int ret; if (nr_uarts == 0) return -ENODEV; serial8250_isa_init 阅读全文
posted @ 2020-08-07 11:30 glob 阅读(1046) 评论(0) 推荐(0) 编辑
摘要: 1. printk.c 中的重要变量 首先介绍一些 kernel/printk/printk.c 中定义的一些十分重要的变量。 /* console_sem用来保护对console_drivers列表的访问 */ static DEFINE_SEMAPHORE(console_sem); /* co 阅读全文
posted @ 2020-08-07 11:29 glob 阅读(797) 评论(0) 推荐(1) 编辑
摘要: 1. echo sdf > /dev/ttyS0 tty_cdev_add 给 tty driver 分配字符设备,设置字符设备的文件操作函数指针指向 tty_fops ,后者的写函数为 tty_write 。 static int tty_cdev_add(struct tty_driver *d 阅读全文
posted @ 2020-08-07 11:27 glob 阅读(477) 评论(0) 推荐(0) 编辑
摘要: 1. workqueue tty 借助 workqueue 实现串口读写操作之间的同步。 tty_port 结构体中的 struct tty_bufhead buf 成员有一个 struct work_struct work 成员, drivers/tty/tty_buffer.c 中的 tty_b 阅读全文
posted @ 2020-08-07 11:25 glob 阅读(769) 评论(0) 推荐(0) 编辑
摘要: 1. tty_init 作为字符设备的一员, tty 设备的初始化函数 tty_init 在 drivers/char/mem.c 中的 chr_dev_init 调用。后者声明为 fs_initcall(chr_dev_init); 。 tty_init 的详细说明如下: int __init t 阅读全文
posted @ 2020-08-07 11:23 glob 阅读(704) 评论(0) 推荐(0) 编辑
摘要: 1. 设置 tty 参数 设置 tty 参数时会设置 tty_struct 内 disc_data 的一些成员变量: struct n_tty_data { ... /* must hold exclusive termios_rwsem to reset these */ unsigned cha 阅读全文
posted @ 2020-08-07 11:22 glob 阅读(849) 评论(0) 推荐(0) 编辑
摘要: 1. line discipline line discipline 介于 TTY 层和具体的串口驱动 ( 比如 serial8250 ) 之间。 发送数据时,应用程序通过系统调用向 TTY 设备文件写入数据,进而调用 TTY 层驱动程序执行写操作。 TTY 层驱动程序调用 line discipl 阅读全文
posted @ 2020-08-07 11:21 glob 阅读(817) 评论(0) 推荐(0) 编辑
摘要: serial8250_init 使用的数据结构很多,按照自顶向下的顺序介绍,即从更一般的 TTY 层到更具体的 8250 层。 介绍这些数据结构时,以 serial8250_init 执行时设置的各个成员变量的值为例进行说明。 每个设备保存自己的 port 信息,用 struct tty_port 阅读全文
posted @ 2020-08-07 11:17 glob 阅读(215) 评论(0) 推荐(0) 编辑
摘要: 本文仍然以slab cache kmalloc_caches 为例,结合 函数的实现,说明slab对象的回收过程。 1. kfree 通过 函数释放 申请的内存时,对应的函数定义在 mm/slub.c 中。 2. slab_free( mm/slub.c ) 如果 的参数地址所在的页面属于slab分 阅读全文
posted @ 2019-10-22 11:26 glob 阅读(1318) 评论(0) 推荐(0) 编辑
摘要: slab cache建立后,就可以从中分配对象。以 kmalloc_caches 为例,执行 函数时会从中分配对象。 1. kmalloc 搞内核的肯定对 不会陌生,和 函数类似,这个函数用来分配内存,定义在 include/linux/slab.h 中: 虽然代码的注释说明 函数通常用于向内核的对 阅读全文
posted @ 2019-10-22 11:25 glob 阅读(886) 评论(0) 推荐(0) 编辑