linux中S3C2440的物理地址映射到虚拟地址详解
目录
linux中S3C2440的物理地址映射到虚拟地址详解
linux-2.6.30.4\arch\arm\plat-s3c\include\plat\ map-base.h
#defineS3C_ADDR_BASE (0xF4000000)
#ifndef __ASSEMBLY__
#define S3C_ADDR(x) ((void__iomem __force *)S3C_ADDR_BASE+ (x))
#else
#defineS3C_ADDR(x) (S3C_ADDR_BASE+ (x))
#endif
#define S3C_VA_IRQ S3C_ADDR(0x00000000) /* irq controller(s) */
#define S3C_VA_SYS S3C_ADDR(0x00100000) /* system control Clock and Power management*/
#define S3C_VA_MEM S3C_ADDR(0x00200000) /* system control memoery*/
#define S3C_VA_TIMER S3C_ADDR(0x00300000) /* timer block --PWM Timer*/
#define S3C_VA_WATCHDOG S3C_ADDR(0x00400000) /* watchdog */
#define S3C_VA_UART S3C_ADDR(0x01000000) /*UART */
linux-2.6.30.4\arch\arm\plat-s3c24xx\include\plat\ map.h
/* UARTs */
#defineS3C24XX_VA_UART S3C_VA_UART
#define S3C2410_PA_UART (0x50000000)
#define S3C24XX_SZ_UART SZ_1M
#define S3C_UART_OFFSET (0x4000)
UART映射后的虚拟地址是0xF4000000+0x01000000
linux-2.6.30.4\arch\arm\plat-s3c24xx\include\plat\ map.h
/* GPIO ports */
#define S3C2410_PA_GPIO (0x56000000)
#defineS3C24XX_VA_GPIO ((S3C24XX_PA_GPIO- S3C24XX_PA_UART) + S3C24XX_VA_UART)//GPIO的虚拟地址
#define S3C24XX_SZ_GPIO SZ_1M
在linux内核中,只能访问虚拟地址空间,所以访问硬件寄存器,常常需要采用物理地址映射为虚拟地址的方式。
在定时器中寄存器访问,采用如下方式
#define S3C_TIMERREG(x) (S3C_VA_TIMER + (x))
#define S3C_TIMERREG2(tmr,reg) S3C_TIMERREG((reg)+0x0c+((tmr)*0x0c))
#define S3C2410_TCFG0 S3C_TIMERREG(0x00)
#define S3C2410_TCFG1 S3C_TIMERREG(0x04)
#define S3C2410_TCON S3C_TIMERREG(0x08)
#define S3C64XX_TINT_CSTAT S3C_TIMERREG(0x44)
#define S3C2410_TCFG_PRESCALER0_MASK (255<<0)
#define S3C2410_TCFG_PRESCALER1_MASK (255<<8)