LINUX资源如何映射到内核虚拟空间

上传人:ji****72 文档编号:46522738 上传时间:2018-06-27 格式:PDF 页数:11 大小:124.31KB
返回 下载 相关 举报
LINUX资源如何映射到内核虚拟空间_第1页
第1页 / 共11页
LINUX资源如何映射到内核虚拟空间_第2页
第2页 / 共11页
LINUX资源如何映射到内核虚拟空间_第3页
第3页 / 共11页
LINUX资源如何映射到内核虚拟空间_第4页
第4页 / 共11页
LINUX资源如何映射到内核虚拟空间_第5页
第5页 / 共11页
点击查看更多>>
资源描述

《LINUX资源如何映射到内核虚拟空间》由会员分享,可在线阅读,更多相关《LINUX资源如何映射到内核虚拟空间(11页珍藏版)》请在金锄头文库上搜索。

1、LINUX I/O 资源如何映射到内核虚拟空间(1)(1) 系统启动初始化时iotable_init()iotable_init()MACHINE_START(AT91SAM9261EK, “ATMEL AT91SAM9261“) .map_io = at91sam9261_map_io, MACHINE_ENDvoid _init at91sam9261_map_io(void)iotable_init(at91sam9261_io_desc, ARRAY_SIZE(at91sam9261_io_desc);/* System peripheral registers mapped at v

2、irtual address.*/static struct map_desc at91sam9261_io_desc _initdata = .virtual = AT91C_VA_BASE_SYS,.pfn = _phys_to_pfn(AT91C_BASE_AIC),.length = SZ_4K,.type = MT_DEVICE,.virtual = AT91C_VA_BASE_EBI,.pfn = _phys_to_pfn(AT91C_BASE_EBI),.length = SZ_4K,.type = MT_DEVICE, ;struct map_desc unsigned lon

3、g virtual;unsigned long pfn;unsigned long length;unsigned int type; /标志位:domain、read、write、cache、buffer;#define _phys_to_pfn(paddr) (paddr) PAGE_SHIFT)#define _pfn_to_phys(pfn) (pfn) 循环调用create_mapping()函数完成IO 的虚拟地址到物理地址的映射。(2)(2) 系统启动后,在驱动中ioremap()ioremap()static struct platform_device *smdk2410_d

4、evices _initdata = struct platform_device s3c_device_lcd = .name = “s3c2410-lcd“, /此处设备的命名应和相应驱动程序命名一致以实现driver bind.id = -1, /-1表示不支持同类多个设备.num_resources = ARRAY_SIZE(s3c_lcd_resource),.resource = s3c_lcd_resource,.dev = .dma_mask = /* LCD Controller */static struct resource s3c_lcd_resource = /LCD

5、 的两个资源0 = .start = S3C2410_PA_LCD,.end = S3C2410_PA_LCD + S3C2410_SZ_LCD,.flags = IORESOURCE_MEM,1 = .start = IRQ_LCD,.end = IRQ_LCD,.flags = IORESOURCE_IRQ,;/* Resource type */#define IORESOURCE_IO 0x00000100#define IORESOURCE_MEM 0x00000200#define IORESOURCE_IRQ 0x00000400#define IORESOURCE_DMA 0x

6、00000800s3c_device_lcd 的resource 中硬件地址#define S3C2410_LCDREG(x) (x)/* LCD control registers */#define S3C2410_LCDCON1 S3C2410_LCDREG(0x00)#define S3C2410_LCDCON2 S3C2410_LCDREG(0x04)#define S3C2410_LCDCON3 S3C2410_LCDREG(0x08)#define S3C2410_LCDCON4 S3C2410_LCDREG(0x0C)#define S3C2410_LCDCON5 S3C241

7、0_LCDREG(0x10)/* LCD controller */#define S3C2410_PA_LCD (0x4D000000)#define S3C24XX_SZ_LCD SZ_1M/* platform_device_register - add a platform-level device* pdev: platform device were adding*/int platform_device_register(struct platform_device * pdev)device_initialize( /初始化设备结构return platform_device_

8、add(pdev); /添加一个片上的设备到设备层/* platform_device_add - add a platform device to device hierarchy* pdev: platform device were adding* This is part 2 of platform_device_register(), though may be called* separately _iff_ pdev was allocated by platform_device_alloc().*/int platform_device_add(struct platform

9、_device *pdev)int i, ret = 0;if (!pdev)return -EINVAL;if (!pdev-dev.parent)pdev-dev.parent = pdev-dev.bus = if (pdev-id != -1)snprintf(pdev-dev.bus_id, BUS_ID_SIZE, “%s.%u“, pdev-name, pdev-id);/* 若支持同类多个设备,则用pdev-name 和pdev-id 在总线上标识该设备*/elsestrlcpy(pdev-dev.bus_id, pdev-name, BUS_ID_SIZE);/* 否则,用p

10、dev-name(即“s3c2410-lcd“)在总线上标识该设备*/for (i = 0; i num_resources; i+) /* 遍历资源数,并为各自在总线地址空间请求分配*/struct resource *p, *r = if (r-name = NULL)r-name = pdev-dev.bus_id;p = r-parent;if (!p) if (r-flags /* LCD 寄存器地址作为IO 内存资源分配*/struct resource iomem_resource = .name = “PCI mem“,.start = 0UL,.end = 0UL,.flag

11、s = IORESOURCE_MEM,;else if (r-flags if (p ret = -EBUSY;goto failed;pr_debug(“Registering platform device %s. Parent at %sn“,pdev-dev.bus_id, pdev-dev.parent-bus_id);ret = device_add(if (ret = 0)return ret;failed:while (-i = 0)if (pdev-resourcei.flags return ret;static struct platform_driver s3c2410

12、fb_driver = .probe = s3c2410fb_probe,.remove = s3c2410fb_remove,.suspend = s3c2410fb_suspend,.resume = s3c2410fb_resume,.driver = .name = “s3c2410-lcd“,.owner = THIS_MODULE,;platform_driver_register(/* 取得LCD 控制寄存器的物理地址*/size = (res-end - res-start)+1;info-mem = request_mem_region(res-start, size,pde

13、v-name);/* 个人理解:设备注册时已经分配区域,驱动这里应该不是必须的*/info-ioinfo-io = = ioremap(res-start,ioremap(res-start, size);size);/* 此时驱动便可以用指针info-io 读写LCD 控制寄存器了*/* eg:readl(info-io + S3C2410_LCDCON1) */ 以下是AT91SAM9261EK 的IOMEM:rootebd9261:# cat /proc/iomem00500000-005fffff : usb-ohci.000500000-005fffff : ohci_hcd00600000-00600fff : sidsa-lcdc.0 /支持同类多个设备,在驱动中未分配I/O 内存区域20000000-23ffffff : System RAM20022000-20225e47 : Kernel text20226000-2028

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 行业资料 > 其它行业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号