ARM Linux静态映射分析(4)

static struct map_desc s3c_iodesc[] __initdata = {
                {
                        .virtual = S3C24XX_VA_GPIO,
                        .physical = S3C24XX_PA_GPIO,
                        .length = S3C24XX_SZ_GPIO,
                        .type = MT_DEVICE
                },
                ……
        };

至此,我们可以比较清晰看到GPIO被静态映射的过程,由于我们在前面的静态映射中已经做好了GPIO的映射,也就是我们写GPIO相关驱动的时候可以如下配置引脚的原因:
        s3c2410_gpio_cfgpin(xxx,xxx);

其实,s3c2410_gpio_cfgpin定义如下:

void s3c2410_gpio_cfgpin(unsigned int pin, unsigned int function)
        {
                void __iomem *base = S3C2410_GPIO_BASE(pin);
                unsigned long mask;
                unsigned long con;
                unsigned long flags;

if (pin < S3C2410_GPIO_BANKB) {
                        mask = 1 << S3C2410_GPIO_OFFSET(pin);
                } else {
                        mask = 3 << S3C2410_GPIO_OFFSET(pin)*2;
                }

local_irq_save(flags);

con = __raw_readl(base + 0x00);
                con &= ~mask;
                con |= function;

__raw_writel(con, base + 0x00);

local_irq_restore(flags);
        }

其中,比较关键的一个地方:
        void __iomem *base = S3C2410_GPIO_BASE(pin);
        这一行中,S3C2410_GPIO_BASE定义如下:

#define S3C2410_GPIO_BASE(pin) ((((pin) & ~31) >> 1) + S3C24XX_VA_GPIO)

至此,GPIO的静态映射就看得很明白了。

下面来看其他外设的静态映射:

在s3c24xx_init_io()函数中,除了iotable_init()以为,还会在最后调用,
        (cpu->map_io)(mach_desc, size);

而CPU的这个map_io在arch/arm/mach-s3c2410/cpu.c里面定义如下:

static struct cpu_table cpu_ids[] __initdata = {
                {
                        .idcode = 0x32410000,
                        .idmask = 0xffffffff,
                        .map_io = s3c2410_map_io,
                        .init_clocks = s3c2410_init_clocks,
                        .init_uarts = s3c2410_init_uarts,
                        .init = s3c2410_init,
                        .name = name_s3c2410
                },
                        ...
         }

再查看s3c2410_map_io(),函数代码如下:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wwxfzf.html