歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> 關於Linux

物理地址到虛擬地址映射

從物理地址到內核虛擬地址的映射
—分析AT91SAM9261EK板子上9261芯片自帶的LCD控制器的驅動程序

  本文分析了AT91SAM9261EK板子上9261芯片自帶的LCD控制器的驅動程序中是如何實現從物理地址到內核虛擬地址的映射。
  當系統執行/drivers/video/atmel_lcdfb.c中的atmel_lcdfb_init()時,調用
platform_driver_probe(&atmel_lcdfb_driver, atmel_lcdfb_probe)函數,首先以atmel_lcdfb_driver中()的name "atmel_lcdfb"為依據來搜索系統注冊的device中有沒有這個platform_device,如果有這個設備,則向系統注冊該設備的驅動。
static struct platform_driver atmel_lcdfb_driver = {
.remove =
__exit_p(atmel_lcdfb_remove),
.driver = {
.name =
"atmel_lcdfb",
.owner = THIS_MODULE,
},
};
由於在/arch/arm/mach-at91/at91sam9261_devices.c中有下面的platform_device at91_lcdc_device,
static struct platform_device at91_lcdc_device = {
.name =
"atmel_lcdfb",
.id = 0,
.dev = {

.dma_mask = &lcdc_dmamask,

.coherent_dma_mask = 0xffffffff,

.platform_data = &lcdc_data,
},
.resource = lcdc_resources,
.num_resources =
ARRAY_SIZE(lcdc_resources),
};
它的name也為"atmel_lcdfb",並且在at91_add_device_lcdc()函數中已經向系統注冊了該設備,所以當執行
atmel_lcdfb_probe()函數中的map = platform_get_resource(pdev, IORESOURCE_MEM, 1)時,即可得到下面定義的lcdc_resources參數,其中AT91SAM9261_LCDC_BASE即為 LCD User Interface 的起始地址0x600000,也即物理地址;AT91SAM9261_LCDC_BASE + SZ_4K
- 1為結束地址。
static struct resource lcdc_resources[] = {
[0] = {
.start =
AT91SAM9261_LCDC_BASE,
.end =
AT91SAM9261_LCDC_BASE + SZ_4K - 1,
.flags =
IORESOURCE_MEM,
},
[1] = {
.start = AT91SAM9261_ID_LCDC,
.end =
AT91SAM9261_ID_LCDC,
.flags =
IORESOURCE_IRQ,
},
#if defined(CONFIG_FB_INTSRAM)
[2] = {
.start =
AT91SAM9261_SRAM_BASE,
.end =
AT91SAM9261_SRAM_BASE + AT91SAM9261_SRAM_SIZE - 1,
.flags =
IORESOURCE_MEM,
},
#endif
};
然後通過ioremap()函數實現從物理地址到內核虛擬地址的映射,也即sinfo->mmio
= ioremap(info->fix.mmio_start, info->fix.mmio_len);其中的
info->fix.mmio_start = regs->start(即AT91SAM9261_LCDC_BASE);
info->fix.mmio_len = regs->end(即AT91SAM9261_LCDC_BASE + SZ_4K - 1)
- regs->start + 1;
 

Copyright © Linux教程網 All Rights Reserved