《Linux Device Drivers》第十一章 核心数据类型——note
- 基本介绍
- 因为Linux多平台特性,不管是哪一个重要驱动力应该是便携
- 与内核代码相关的核心问题应该是访问的同时是数据项的已知长度。能力和利用不同的处理器
- 内核使用的数据类型主要分为三类
- 类似int这种标准C语言类型
- 类似u32这种有确定大小的类型
- 像pid_t这种用于特定内核对象的类型
- 本章将讨论在什么情况下使用这三种类型以及怎样使用
- 使用标准C语言类型
- 当我们须要“两个字节的填充符”或者“用四个字节字符串表示的某个东西”时。我们不能使用标准类型,由于在不同的体系架构上。普通C语言的数据类型所占空间在大小并不同样
- 内核中的普通内存地址一般是unsigned long。在当前Linux支持的全部平台上,指针和long整形的大小总是同样的
- C99标准定义了intptr_t和uintptr_t类型,它们是可以保存指针值的整形变量
- 为数据项分配确定的空间大小
- <asm/types.h>
- <linux/types.h>
- u8, s8
- u16, s16
- u32, s32
- u64, s64
- 假设一个用户空间程序须要使用这些类型,它能够在名字前加上两个下划线作为前缀
- __u8
- __u32
- 使用新编译器的系统将支持C99标准类型,如uint8_t和uint32_t
- 接口特定的类型
- 内核中最经常使用的数据类型由它们自己的typedef声明。这样能够防止出现不论什么移植性问题
- “接口特定(interface-specific)”是指由某个库定义的一种数据类型,以便为某个特定的数据结构提供接口
- 完整的_t类型在<linux/types.h>中定义
- _t数据项的主要问题是在我们须要打印它们的时候,不太easy选择正确的printk或者printf的输出格式
- 其它有关移植的问题
- 一个通用的原则是要避免使用显式的常量值
- 时间间隔
- 使用jiffies计算时间间隔的时候,应该用HZ来衡量
- 页大小
- 内存页的大小是PAGE_SIZE字节
- PAGE_SHIFT
- <asm/page.h>
- getpagesize库函数
- get_order函数
- 字节序
- <asm/byteorder.h>
- __BIG_ENDIAN
- __LITTLE_ENDIAN
- u32 cpu_to_le32 (u32);
- u32 le32_to_cpu(u32);
- be64_to_cpu
- le16_to_cpus
- cpu_to_le32p
- <asm/byteorder.h>
- 数据对齐
- <asm/unaligned.h>
- get_unaligned(ptr);
- put_unaligned(val, ptr);
- <asm/unaligned.h>
- 指针和错误值
- 很多内核接口通过把错误值编码到一个指针值中来返回错误信息
- <linux/err.h>
- void *ERR_PTR(long error);
- long IS_ERR(const void *ptr);
- long PTR_ERR(const void *ptr);
- 链表
- <linux/list.h>
- struct list_head
- struct list_head *next, *prev;
- INIT_LIST_HEAD(&list);
- LIST_HEAD(list);
- list_add(struct list_head *new, struct list_head *head);
- list_add_tail(struct list_head *new, struct list_head *head);
- list_del(struct list_head *entry);
- list_del_init(struct list_head *entry);
- list_move(struct list_head *entry, struct list_head *head);
- list_move_tail(struct list_head *entry, struct list_head *head);
- list_empty(struct list_head *head);
- list_splice(struct list_head *list, struct list_head *head);
- list_entry(struct list_head *ptr, type_of_struct, field_name);
- list_for_each(struct list_head *cursor, struct list_head *list)
- list_for_each_prev(struct list_head *cursor, struct list_head *list)
- list_for_each_safe(struct list_head *cursor, struct list_head *next, struct list_head *list)
- list_for_each_entry(type *cursor, struct list_head *list, member)
- list_for_each_entry_safe(type *cursor, type *next, struct list_head *list, member)
- struct list_head
- <linux/list.h>
版权声明:本文博客原创文章,博客,未经同意,不得转载。
《Linux Device Drivers》第十一章 核心数据类型——note的更多相关文章
- 《Linux Device Drivers》第八章 分配内存——note
本章主要介绍Linux内核的内存管理. kmalloc函数的内幕 不正确所获取的内存空间清零 分配的区域在物理内存中也是连续的 flags參数 <linux/slab.h> <lin ...
- 《Linux Device Drivers》第十四章 Linux 设备型号
基本介绍 2.6内核设备模型来提供的抽象叙述性描述的一般系统的结构,为了支持各种不同的任务 电源管理和系统关机 用户空间与通信 热插拔设备 设备类型 kobject.kset和子系统 kobject是 ...
- 《Linux Device Drivers》第十二章 PCI司机——note
一个简短的引论 它给这一章总线架构的高级概述 集中访问讨论Peripheral Component Interconnect(PCI,外围组件互连)外设内核函数 PCI公交车是最好的支持的内核总线 本 ...
- 《Linux Device Drivers》 第十七章 网络驱动程序——note
基本介绍 第三类是标准的网络接口Linux设备,本章介绍的内核,其余的交互网络接口描述 网络接口,必须使用特定的内核数据结构本身注册,与外部分组交换数据线打电话时准备 经常使用的文件上的网络接口操作是 ...
- 《Linux Device Drivers》第十五章 内存映射和DMA——note
简单介绍 很多类型的驱动程序编程都须要了解一些虚拟内存子系统怎样工作的知识 当遇到更为复杂.性能要求更为苛刻的子系统时,本章所讨论的内容迟早都要用到 本章的内容分成三个部分 讲述mmap系统调用的实现 ...
- 《Linux Device Drivers》第十六章 块设备驱动程序——note
基本介绍 块设备驱动程序通过主传动固定大小数据的随机访问设备 Linux核心Visual块设备作为基本设备和不同的字符设备类型 Linux块设备驱动程序接口,使块设备最大限度地发挥其效用.一个问题 一 ...
- 《Linux Device Drivers》第十八章 TTY驱动程序——note
简单介绍 tty设备的名称是从过去的电传打字机缩写而来,最初是指连接到Unix系统上的物理或虚拟终端 Linux tty驱动程序的核心紧挨在标准字符设备驱动层之下,并提供了一系列的功能,作为接口被终端 ...
- 《Linux Device Drivers》第十章 中断处理——note
概述:系统要及时的感知硬件的状态,通常有两种方式:一种是轮询.一种是通过响应硬件中断.前者会浪费处理器的时间,而后者不会. 准备并口 在没有节设定产生中断之前,并口是不会产生中断的 并口的标准规定设置 ...
- linux device drivers ch03
ch03.字符设备驱动程序 编写驱动程序的第一步就是定义驱动程序为用户程序提供的能力(机制).接下来以scull(“Simple Character Utility for Loading Local ...
随机推荐
- C#判断操作系统类型
操作系统 PlatformID 主版本号 副版本号 Windows95 1 4 0 Windows98 1 4 10 WindowsMe 1 4 90 WindowsN ...
- POJ 1012 Joseph 约瑟夫问题
http://poj.org/problem?id=1012 早上去图书馆复习苦逼的复习....万恶的数逻.T T我还要自我安慰的说复习完了奖励回来刷水题~ 10点多的时候外面校运会大吼撑杆跳的那个. ...
- mac os 虚拟机安装
https://blog.csdn.net/u011415782/article/details/78505422 感谢
- 移动web处理input输入框输入银行卡号四位一空格
由于项目上有需求要求输入银行卡号四位一空格的需求,改过好几版发现都有bug,最后优化了一版看起来效果还行,发帖留存. 难点是从中间插入和删除处理光标问题. 首先需要用到获取光标和设置光标的方法. // ...
- debian安装git管理本地代码
debian安装git管理本地代码 安装git # aptitude install git-core # aptitude install git-doc git-svn git-email git ...
- perl对比两个文件的行
perl对比两个文件的行 对比两个文件的各行,得到A与B相同的行/A与B不相同的行 主要功能 得到相同行 得到A中包含,B不包含的行 得到B中包含,A中不包含的行 具体执行情况 Perl代码 #!/u ...
- ios开发runtime学习二:runtime交换方法
#import "ViewController.h" /* Runtime(交换方法):主要想修改系统的方法实现 需求: 比如说有一个项目,已经开发了2年,忽然项目负责人添加一个功 ...
- [Angular Unit Testing] Testing Component methods
import {ComponentFixture, TestBed} from '@angular/core/testing'; import {BrowserDynamicTestingModule ...
- QT学习记录之控件布局
作者:朱金灿 来源:http://blog.csdn.net/clever101 想到控件布局就会想到Windows编程中要实现对话框上的控件的合理布局是一件多么艰难的事情.对此QT提出了一个很方便的 ...
- COCOS学习笔记--单点触控
这篇博客来总结下cocos单点触控的相关内容: 我们在Layer类的源代码中能够看到.Layer类提供了一下4个与屏幕单点触控相关的回调方法: onTouchBegan().onTouchMoved( ...