热门关键字:  ubuntu  分区  函数  Fedora  linux系统进程

linux2.4.18 MIZI下IO端口、内存寻址的具体实现

来源:/blog.chinaunix.net 作者:xiezheng 时间:2007-12-03 Tag: 点击:

linux2.4.18 MIZI下IO端口、内存寻址的具体实现
 
   分析由serial_8250.c串口驱动源代码serial_in()函数出发:
一:mizi linux2.4.18 inb、inbw、inl
static _INLINE_ unsigned int serial_in(struct uart_port *port, int offset)
{
       offset <<= port->regshift;
 
       switch (port->iotype) {
#ifdef CONFIG_SERIAL_8250_HUB6
       case SERIAL_IO_HUB6:
              outb(port->hub6 - 1 + offset, port->iobase);
              return inb(port->iobase + 1);
#endif
 
       case SERIAL_IO_MEM:
              return readb((unsigned long)port->membase + offset);
 
       default:
              return inb(port->iobase + offset);
       }
}
   先分析inb(port->iobase+offset),inb函数的定义为:
 /*
 * Now, pick up the machine-defined IO definitions
 */
#include <asm/arch/io.h>
 
/*
 * IO definitions.  We define {out,in,outs,ins}[bwl] if __io is defined
 * by the machine. Otherwise, these definitions are left for the machine
 * specific header files to pick up.
 *
 * Note that we prevent GCC re-ordering or caching values in expressions
 * by introducing sequence points into the in*() definitions. Note that
 * __raw_* do not guarantee this behaviour.
 */
#ifdef __io
#define outb(v,p)                  __raw_writeb(v,__io(p))
#define outw(v,p)                 __raw_writew(v,__io(p))
#define outl(v,p)                   __raw_writel(v,__io(p))
 
#define inb(p)              ({ unsigned int __v = __raw_readb(__io(p)); __v; })
#define inw(p)              ({ unsigned int __v = __raw_readw(__io(p)); __v; })
#define inl(p)         ({ unsigned int __v = __raw_readl(__io(p)); __v; })
 
#define outsb(p,d,l)                     __raw_writesb(__io(p),d,l)
#define outsw(p,d,l)                    __raw_writesw(__io(p),d,l)
#define outsl(p,d,l)               __raw_writesl(__io(p),d,l)
 
#define insb(p,d,l)                __raw_readsb(__io(p),d,l)
#define insw(p,d,l)               __raw_readsw(__io(p),d,l)
#define insl(p,d,l)                 __raw_readsl(__io(p),d,l)
#endif
   其中,__io(p)定义为:
/*
 * We don't actually have real ISA nor PCI buses, but there is so many
 * drivers out there that might just work if we fake them...
 */    兼容问题
#define __io(a)            (PCIO_BASE + (a))
#define __mem_pci(a)   ((unsigned long)(a))
#define __mem_isa(a)    ((unsigned long)(a))
而PCIO_BASE定义为:#define PCIO_BASE        0
 
 __raw_readb()定义为:
#define __raw_readb(a)                    __arch_getb(a)
 
#define __arch_getb(a)                     (*(volatile unsigned char *)(a))
同理inw,inl。

最新评论共有 4 位网友发表了评论
发表评论
评论内容:不能超过250字,需审核,请自觉遵守互联网相关政策法规。
用户名: 密码:
匿名?
注册