from the command line run uname -r to find your current running kernel version
$ uname -r
2.6.31-14-generic
I/O Memory Access
Unlike on most typical embedded systems, accessing I/O memory on Linux cannot be done directly. This is due to the wide range of different memory types and maps present on the wide range of processors on which Linux runs. To access I/O memory in a portable manner, you must call ioremap() to gain access to a memory region and iounmap() to release access.
void __iomem *ioremap(unsigned long offset, unsigned long size);
You pass in a starting offset of the region you wish to access and the size of the region in bytes. You cannot just use
the return value as a memory location to read and write from directly, but rather it is a token that must be passed to different functions to read and write data.
The functions to read and write data using memory mapped by ioremap() are:
unsigned char readb(const volatile void __iomem *addr); /* read 8 bits */
unsigned short readw(const volatile void __iomem *addr); /* read 16 bits */
unsigned int readl(const volatile void __iomem *addr); /* read 32 bits */
void writeb (unsigned char value, volatile void __iomem *addr); /* write 8 bits */
void writew (unsigned short value, volatile void __iomem *addr); /* write 16 bits */
void writel (unsigned int value, volatile void __iomem *addr); /* write 32 bits */
After you are finished accessing memory, you must call
iounmap() to free up the memory so that others can use it if they want to.
使用如下方法操作一个地址为0x56000020的端口
unsigned long port_addr;
port_addr = (unsigned long)ioremap(0x56000020, 0x8);
the function ioremap_nocache allocates the physical memory and gives the virtual address for it
syntax:
void* ioremap_nocache(physical address, pagesize);
example:
void * virt;
virt=ioremap_nocache(0x4c00000c,4096);
to reffer that address use
*((unsigned long *)virt)=0x2; //writeb(0x2,virt);
> ioremap gives you a new mapping for I/O addresses that you can access
> with functions like inb() and the like.
>
> phy_to_virt() is rarely used at all, it only serves to convert a physical
> address for main memory (RAM) into the address used inside of the kernel.