io端口
io端口
- drivers/input/serio/hp_sdc.c
- -------------------------------------
- if (request_region(hp_sdc.data_io, 2, hp_sdc_driver.name))
- goto err0;
- 如果request_region 分配端口成功,返回非空指针。
- request_region
- -------------------------------------
- ->./include/linux/ioport.h:
- #define request_region(start,n,name) \
- __request_region(&ioport_resource, (start), (n), (name), 0)
- =====================================
- ioport_resource
- -------------------------------------
- -->kernel/resource.c
- struct resource ioport_resource = {
- .name = "PCI IO",
- .start = 0,
- .end = IO_SPACE_LIMIT,
- .flags = IORESOURCE_IO,
- };
- EXPORT_SYMBOL(ioport_resource);
- __request_region
- -------------------------------------
- -->kernel/resource.c
- struct resource * __request_region(struct resource *parent,
- resource_size_t start, resource_size_t n,
- const char *name, int flags)
- {
- struct resource *res = kzalloc(sizeof(*res), GFP_KERNEL);
- if (!res)return NULL;
- res->name = name;
- res->start = start;
- res->end = start + n - 1;
- res->flags = IORESOURCE_BUSY;
- res->flags |= flags;
- write_lock(&resource_lock);
- for (;;) {
- struct resource *conflict;
- conflict = __request_resource(parent, res);
- if (!conflict) break; //申请成功
- if (conflict != parent) {
- parent = conflict;
- if (!(conflict->flags & IORESOURCE_BUSY))
- continue;
- }
- /* Uhhuh, that didn't work out.. */
- kfree(res);
- res = NULL;
- break;
- }
- write_unlock(&resource_lock);
- return res;
- }
- EXPORT_SYMBOL(__request_region);
- =====================================
- kzalloc
- -------------------------------------
- --->include/linux/slab.h
- static inline void *kzalloc(size_t size, gfp_t flags)
- {
- return kmalloc(size, flags | __GFP_ZERO);
- }
- __request_resource
- -------------------------------------
- --->kernel/resource.c
- static struct resource *
- __request_resource(struct resource *root,
- struct resource *new)
- {
- resource_size_t start = new->start;
- resource_size_t end = new->end;
- struct resource *tmp, **p;
- if (end < start) return root;
- if (start < root->start) return root;
- if (end > root->end) return root;
- p = &root->child;
- for (;;) {
- tmp = *p;
- if (!tmp || tmp->start > end) {
- new->sibling = tmp;
- *p = new;
- new->parent = root;
- return NULL; //成功
- }
- p = &tmp->sibling;
- if (tmp->end < start) continue;
- return tmp;
- }
- }
- =====================================
- lib/iomap.c
- -------------------------------------
- #define PIO_OFFSET 0x10000UL //64k
- #define PIO_MASK 0x0ffffUL
- #define PIO_RESERVED 0x40000UL //256K
- #endif
- void __iomem *ioport_map(unsigned long port, unsigned int nr)
- {
- if (port > PIO_MASK)
- return NULL;
- return (void __iomem *) (unsigned long) (port + PIO_OFFSET);
- }
- void ioport_unmap(void __iomem *addr)
- {
- /* Nothing to do */
- }
- __iomem
- -------------------------------------
- include/linux/compiler.h
- # define __iomem __attribute__((noderef, address_space(2)))
- //对iomem地址进行检查
- -------------------------------------
- ioport_map ioport_unmap 小结
- -------------------------------------
- 从port的范围(0-0xffff) 可以看到,映射的地址是10000-0x1ffff, 即(64k) -> (128k-1)的空间。
- 还有一个是PIO_RESERVED 40000,是保留的空间。
- 在搜代码的时候,同时也会在include/asm-generic/io.h文件中出现。而其上方有 #ifndef CONFIG_GENERIC_IOMAP,个人理解是这文件处理的是没有iomap的功能情况。里面的函数大都是空。
- ==============================================================================
- ***********************************************************
- ioread8() iowrite8()
- ***********************************************************
- lib/iomap.c
- -------------------------------------
- #define PIO_RESERVED 0x40000UL
- #define PIO_OFFSET 0x10000UL
- unsigned int ioread8(void __iomem *addr)
- {
- IO_COND(addr, return inb(port), return readb(addr));
- return 0xff;
- }
- void iowrite8(u8 val, void __iomem *addr)
- {
- IO_COND(addr, outb(val,port), writeb(val, addr));
- }
- EXPORT_SYMBOL(ioread8);
- EXPORT_SYMBOL(iowrite8);
- #define IO_COND(addr, is_pio, is_mmio) do { \
- unsigned long port = (unsigned long __force)addr; \
- if (port >= PIO_RESERVED) { \
- is_mmio; \
- } else if (port > PIO_OFFSET) { \
- port &= PIO_MASK; \
- is_pio; \
- } else \
- bad_io_access(port, #is_pio ); \
- } while (0)
- static void bad_io_access(unsigned long port, const char *access)
- {
- static int count = 10;
- if (count) {
- count--;
- WARN(1, KERN_ERR "Bad IO access at port %#lx (%s)\n", port, access);
- }
- }
- WARN
- -------------------------------------
- ->include/asm-generic/bug.h
- #define WARN(condition, format...) ({ \
- int __ret_warn_on = !!(condition); \
- unlikely(__ret_warn_on); \
- })
- ioread8(addr)意思就是
- if addr>=256K then readb(addr)
- else if addr >64K then inb(addr - 64K)
- else 打印错误
- 继续追踪 inb 和 readb
- =====================================
- include/asm-generic/io.h
- -------------------------------------
- #define readb __raw_readb
- static inline u8 __raw_readb(const volatile void __iomem *addr)
- {
- return *(const volatile u8 __force *) addr;
- }
- #define writeb __raw_writeb
- static inline void __raw_writeb(u8 b, volatile void __iomem *addr)
- {
- *(volatile u8 __force *) addr = b;
- }
- -------------------------------------
- static inline u8 inb(unsigned long addr)
- {
- return readb((volatile void __iomem *) addr);
- }
- static inline void outb(u8 b, unsigned long addr)
- {
- writeb(b, (volatile void __iomem *) addr);
- }
- arch/x86/boot.c
- -------------------------------------
- static inline u8 inb(u16 port)
- {
- u8 v;
- asm volatile("inb %1,%0" : "=a" (v) : "dN" (port));
- return v;
- }
- static inline void outb(u8 v, u16 port)
- {
- asm volatile("outb %0,%1" : : "a" (v), "dN" (port));
- }
不过应该确认的是,端口和申请的resource地址无关,resource只是用来记录申请的端口
io端口的更多相关文章
- io端口与io内存详解
(一)地址的概念 1)物理地址:CPU地址总线传来的地址,由硬件电路控制其具体含义.物理地址中很大一部分是留给内存条中的内存的,但也常被映射到其他存储器上(如显存.BIOS等).在程序指令中的虚拟地址 ...
- IO端口、IO内存、IO空间、内存空间的含义和联系
1,IO空间:X86一个特有的空间,与内存空间独立的空间,同样利用IO空间可以操作数据,只不过是利用对应的IO端口操作函数,例如inb(), inbw(), inl(); outb(), outw() ...
- IO端口和IO内存的区别及分别使用的函数接口
每个外设都是通过读写其寄存器来控制的.外设寄存器也称为I/O端口,通常包括:控制寄存器.状态寄存器和数据寄存器三大类.根据访问外设寄存器的不同方式,可以把CPU分成两大类.一类CPU(如M68K,Po ...
- IO端口和IO内存
为什么会有IO端口和IO内存 这主要原因是因为处理器的架构不同,这里我们使用arm来代表典型的使用IO内存架构,intel 80x86代表典型的使用IO端口架构.简单来说arm把所有寄存器(包括外部设 ...
- 驱动笔记 - IO端口和IO内存
访问IO端口 (#include <asm/io.h>) 设备资源struct resource{ resource_size_t start; //资源起始物理地址 resource_s ...
- IO端口和IO内存的区别 转
目录(?)[-] Linux系统对IO端口和IO内存的管理 一.I/O端口 二.IO内存 三.IO端口和IO内存的区分及联系 四.外设IO端口物理地址的编址方式 统一编址 独立编址 优缺点 五.L ...
- X86 IO端口和MMIO
X86 IO端口和MMIO I/O作为CPU和外设交流的一个渠道,主要分为两种,一种是Port I/O,一种是MMIO(Memory mapping I/O).前者就是我们常说的I/O端口,它实际上的 ...
- linux中的 IO端口映射和IO内存映射
参考自:http://blog.csdn.net/zyhorse2010/article/details/6590488 CPU地址空间 (一)地址的概念 1)物理地址:CPU地址总线传来的地址,由硬 ...
- Linux系统对IO端口和IO内存的管理
引用:http://blog.csdn.net/ce123_zhouwei/article/details/7204458 一.I/O端口 端口(port)是接口电路中能被CPU直接访问的寄存器的地址 ...
随机推荐
- LeetCode——TwoSum
题目: Given an array of integers, find two numbers such that they add up to a specific target number. ...
- Log4Net五步走
本文不是教你全面了解log4net,本文只是希望教会你按步就班,照糊芦画瓢般就会用log4net1,引入log4net.dll组件2,建立一个配置文件两种方法,一种是在Web.Config或App.C ...
- House Robber 分类: leetcode 算法 2015-07-09 20:53 2人阅读 评论(0) 收藏
DP 对于第i个状态(房子),有两种选择:偷(rob).不偷(not rob) 递推公式为: f(i)=max⎧⎩⎨⎪⎪{f(i−1)+vali,f(i−2)+vali,robi−1==0robi−1 ...
- Ext.net中常用的三种交互方式
http://www.ext.net.cn/forum.php?mod=viewthread&tid=10433
- Python 第二篇:python字符串、列表和字典的基本操作方法
本文基于python 3.5.1 python常见的数据类型有字串.列表.元组.字典等,本文将详细介绍每一种数据类型的操作方法. 一:str字串的操作方法: 1.capitalize()--> ...
- 用来解析,格式化,存储和验证国际电话号码:libphonenumber
用来解析,格式化,存储和验证国际电话号码:libphonenumber libphonenumber是Google的公共Java.C++和Javascript库用来解析,格式化,存储和验证国际电话号码 ...
- GDSOI2015 task2 覆盖半径
题目大意 一个\(n\times m\)的矩阵中有\(p\)个已经确定圆心的圆,并且每个格子有一定的分数,如果一个格子被任意一个或以上的圆覆盖,那么就可以得到这个格子的分数.现在求最小的半径,使得得分 ...
- 统一横轴墨卡托投影(UTM)
UTM 坐标系统使用基于网格的方法表示坐标.UTM 系统将地球分为 60 个区,每一个区基于横轴墨卡托投影.画图法中的地图投影方法能够在平面中表示一个两维的曲面,比如一个标准地图.图 1 展示了一个横 ...
- 杭电OJ——1007 Quoit Design(最近点对问题)
Quoit Design Problem Description Have you ever played quoit in a playground? Quoit is a game in whic ...
- NodeJs 实时压缩 项目js文件
+ 1. 下载nodejs : "http://nodejs.org/". + 2. 以administrator权限打开cmd.+ 3. cmd路径定位到要压缩的目录: &quo ...