简体   繁体   中英

How Control Registers are accessed in Linux

i have been reading Linux source code ported on to a propriety platform based on ARM Cortex -A7 MPCore - NEON Architecture

The code below shows how a control register of a module is modified up on calling an API

drivers\module\module-specific_file.c
static inline void API(....)
{
    if (set)
        __raw_writel(msk, (void *)((u32) (reg) + 0x1000));
    else
    {
        __raw_writel(msk, (void *)((u32) (reg) + 0x2000));
    }
}

in the above code reg is actually a virtual address and msk is a mask lets say x7FF and set is a parameter passed which conveys request of set/clear

but actually my doubt is how does modifying the control register address is modifying the value to be written to register ... ?? further if i look at the api which is been called it looks like below

arch\arm\include\asm\Io.h
static inline void __raw_writel(u32 val, volatile void __iomem *addr)
{
    asm volatile("str %1, %0"
             : "+Qo" (*(volatile u32 __force *)addr)
             : "r" (val));
}

if any one have come across this kind of accessing control registers please let me know how actually content of registers are modified by modifying the virtual address.

As I know, registers are mapped in virtual address space. Have a look at /proc/iomem for example, you'll see mapped registers addresses and what hardware they are belong. The addresses of registers are strictly determined by hardware developers. Typically, to map register address one should call ioremap function. It returns the address. Often this address is the base address, where the register addresses begin. To write something in register you just need to write the data in this address plus the resister offset. Eg: On ARM PXA320, there is a set of LCD registers. Somewhere ion driver code one may see - ioremap(BASE_ADDR, SIZE_OF_ADDR_SET); In order to write __raw_write(value, base_addr + offset) function is used.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM