Mapping physical addresses to virtual address linux

后端 未结 3 1074
迷失自我
迷失自我 2020-12-31 17:45

I am working on a small embedded system. When my linux boots up into user space, I know where are my devices in the physical memory. I want to map them into user space virtu

3条回答
  •  滥情空心
    2020-12-31 18:06

    What you are trying to do is accessing what is called IO memory. I can only encourage you to read the Linux Device Drivers (LDD) book and more specifically the chapter 9.

    To "allocate" such an area, you need to call

    struct resource *request_mem_region(unsigned long start, unsigned long len, char *name)
    

    . Before your driver can access it, you have to assign it a virtual address, this is done with a call to

    void *ioremap(unsigned long phys_addr, unsigned long size)
    

    To ensure that your driver will then work on different architectures/platforms, be sure to use some accessor function to such areas ( ioread8/16/32 or iowrite8/16/32 and all of their variants).

提交回复
热议问题