频道栏目
首页 > 资讯 > Linux > 正文

linux系统下iotable_init 静态映射与内核页表的建立实例教程

18-07-19        来源:[db:作者]  
收藏   我要投稿

arm32 linux3.18 mach-vexpress

常用的ioremap或者of_iomap都是动态映射,静态映射的接口是iotable_init

void __init iotable_init(struct map_desc *io_desc, int nr)
struct map_desc {
	unsigned long virtual;
	unsigned long pfn;
	unsigned long length;
	unsigned int type;
};

如map_desc所示通过实例化这个结构体我们可以创建对某个物理地址的固定的虚拟地址映射

iotable_init 一般是在machine desc 的map_io的call函数里具体的call stack如下

start_kernel-->setup_arch-->paging_init-->devicemaps_init-->mdesc->map_io()

iotable_init会调用函数create_mapping来创建内核页表和映射关系,不只是iotable_init 包括内核页表的创建都是通过该函数

盗一张3+1的32bit linux 的memeory layout 图帮助后面理解

/*
 * Create the page directory entries and any necessary
 * page tables for the mapping specified by `md'.  We
 * are able to cope here with varying sizes and address
 * offsets, and we take full advantage of sections and
 * supersections.
 */
static void __init create_mapping(struct map_desc *md)
{
	if (md->virtual != vectors_base() && md->virtual < TASK_SIZE) {
		pr_warn("BUG: not creating mapping for 0x%08llx at 0x%08lx in user region\n",
			(long long)__pfn_to_phys((u64)md->pfn), md->virtual);
		return;
	}
//vectors_base是中断向量表的位置0xffff0000  TASK_SIZE是userspace的空间大小为0x7f000000 
//iotable_init 是从vmalloc区域拿地址空间,或者说low memory区,所以先判断所申请的虚拟地址是否在此范围内
	if ((md->type == MT_DEVICE || md->type == MT_ROM) &&
	 md->virtual >= PAGE_OFFSET && md->virtual < FIXADDR_START &&
	 (md->virtual < VMALLOC_START || md->virtual >= VMALLOC_END)) {
		pr_warn("BUG: mapping for 0x%08llx at 0x%08lx out of vmalloc space\n",
			(long long)__pfn_to_phys((u64)md->pfn), md->virtual);
	}
//PAGE_OFFSET是kernel space虚拟地址的起始0x80000000 看起来是2+2的memory分布,跟TASK_SIZE gap 了16M
//FIXADDR_START 是kernel space的永久映射区 
//vmalloc_start 0xa0800000 vmaloc_end 0xff000000 大概1.5G 
//vmalloc区域大小也会有boot cmdline vmalloc=  决定
	__create_mapping(&init_mm, md, early_alloc, false);
}
相关TAG标签
上一篇:Qt中多线程的使用(一)
下一篇:adb不是内部或外部命令,关于Android Studio中ADB命令不能用问题的解决办法
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站