《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 ...
随机推荐
- debian 下的vi 上下左右键问题
小白一只,查了一下vi的版本信息 发现好像是vim 于是把~/.vimrc 变量设置了一下就好了。 将set compatible 设置成set nocompatible . 这是因为系统会默认vim ...
- Oracle 11gR2 静默安装奇怪错误
在静默安装Oracle 11gR2 的时候发现的奇怪错误,有点摸不着头脑 【步骤一】配置静默文件只安装软件 #--------------------------------------------- ...
- [Javascript Natural] Break up language strings into parts using Natural
A part of Natural Language Processing (NLP) is processing text by “tokenizing” language strings. Thi ...
- Giraph源代码分析(六)——Edge 分析
HamaWhite 原创,转载请注明出处.欢迎大家增加Giraph 技术交流群: 228591158 欢迎訪问: 西北工业大学 - 大数据与知识管理研究室 (Northwestern Polytech ...
- ZOJ Special AC String 水
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3702 题目大意: 对于给定的一个字符串,满足如下要求输出AC,否则WA(好吧我 ...
- PatentTips - Highly-available OSPF routing protocol
BACKGROUND OF THE INVENTION FIG. 1A is a simplified block diagram schematically representing a typic ...
- ios开发网络学习AFN三:AFN的序列化
#import "ViewController.h" #import "AFNetworking.h" @interface ViewController () ...
- 三列自适应布局的实现方式(兼容IE6+)
1.绝对定位方式 <div class="nm-3-lr"> <div class="aside-f"> <p>侧边栏1固定 ...
- [CSS] Re-order the appearance of grid items using the order property
As with flex items, we can set an order value on grid items. Let’s see how this affects the DOM and ...
- [SVG] Optimize SVGs for Better Performance using svgo
Just like a bitmap image, you can compress an SVG by removing various pieces of code that aren’t nec ...