Linux如何映射物理内存到内核空间

在setup_arch()中:
 
1. parse_cmdline(): 根据uboot传递的mem信息,调用early_mem()通过arm_add_memory()把物理内存信息添加到meminfo结构体中。
 
2. paging_init(): 这个就是关键的初始化页表的函数,在里面会调用bootmem_init()->bootmem_init_node()->map_memory_bank(),在这里会根据meminfo的信息调用create_mapping()来为物理内存建立内核空间的映射,一般是从0xc0000000开始。下面是arm linux的虚拟地址映射表:
 
Start       End     Use
--------------------------------------------------------------------------
ffff8000 ffffffff   copy_user_page / clear_user_page use.
ffff1000 ffff7fff   Reserved.
    
ffff0000 ffff0fff CPU vector page.
    The CPU vectors are mapped here if the  CPU supports vector relocation (control
    register V bit.)
 
ffc00000 fffeffff DMA memory mapping region.  Memory returned by the dma_alloc_xxx functions will be dynamically mapped here.
 
ff000000 ffbfffff Reserved for future expansion of DMA mapping region.
 
VMALLOC_END feffffff Free for platform use, recommended.
    VMALLOC_END must be aligned to a 2MB
    boundary.
 
VMALLOC_START VMALLOC_END-1 vmalloc() / ioremap() space.
    Memory returned by vmalloc/ioremap will
    be dynamically placed in this region.
    VMALLOC_START may be based upon the value
    of the high_memory variable.
 
PAGE_OFFSET high_memory-1 Kernel direct-mapped RAM region.
    This maps the platforms RAM, and typically
    maps all platform RAM in a 1:1 relationship.
 
TASK_SIZE PAGE_OFFSET-1 Kernel module space
    Kernel modules inserted via insmod are
    placed here using dynamic mappings.
 
00001000 TASK_SIZE-1 User space mappings
    Per-thread mappings are placed here via
    the mmap() system call.
 
00000000 00000fff CPU vector page / null pointer trap
    CPUs which do not support vector remapping
    place their vector page here.  NULL pointer
    dereferences by both the kernel and user
    space are also caught via this mapping.
虽然后面这个表我不知道什么意思,但是上面的对我还是蛮有用的,至少我知道了,物理内存是如何映射到内核空间的。

你可能感兴趣的:(Linux如何映射物理内存到内核空间)