linux 4.15 aarch32
qemu vexpress-v2p-ca9.dtb
Linux的物理内存配置在dts中的memory 节点如下所示物理内存起始地址为0x60000000大小为1G
memory@60000000 {
device_type = "memory";
reg = <0x60000000 0x40000000>;
};
内核初始化物理内存的代码路径如下,dt_scan_nodes会优先读取chosen / 和memory节点的信息
处理memory节点的信息过程是要求device_type 为memory,然后再根据reg属性的值调用early_init_dt_add_memory_arch
start_kernel
->setup_arch
-->setup_machine_fdt
--->early_init_dt_scan_nodes
---->early_init_dt_scan_nodes
void __init early_init_dt_scan_nodes(void)
{
/* Retrieve various information from the /chosen node */
of_scan_flat_dt(early_init_dt_scan_chosen, boot_command_line);
/* Initialize {size,address}-cells info */
of_scan_flat_dt(early_init_dt_scan_root, NULL);
/* Setup memory, calling early_init_dt_add_memory_arch */
of_scan_flat_dt(early_init_dt_scan_memory, NULL);
}
early_init_dt_scan_memory
->early_init_dt_add_memory_arch
-->memblock_add
将这块内存添加到memblock中,用来后面的调用过程对内存初始化
Linux的config文件中的PAGE_OFFSET代表内核虚拟地址的起始地址,与VMSPLIT_2G相对应,VMSPLIT_1G代表user3G kernel1G,VMSPLIT是arm32只有4G虚拟内存的条件下的产物
# CONFIG_VMSPLIT_3G is not set
CONFIG_VMSPLIT_2G=y
# CONFIG_VMSPLIT_1G is not set
CONFIG_PAGE_OFFSET=0x80000000
.config
/* PAGE_OFFSET - the virtual address of the start of the kernel image */
#define PAGE_OFFSET UL(CONFIG_PAGE_OFFSET)
arch/arm/include/asm/memory.h
arm64 的物理和虚拟地址配置的config已经换成如下,dts中的memory节点仍然沿用
CONFIG_ARM64_VA_BITS_48=y
CONFIG_ARM64_VA_BITS=48
CONFIG_ARM64_PA_BITS_48=y
CONFIG_ARM64_PA_BITS=48
/*
* PAGE_OFFSET - the virtual address of the start of the linear map (top
* (VA_BITS - 1))
* KIMAGE_VADDR - the virtual address of the start of the kernel image
* VA_BITS - the maximum number of bits for virtual addresses.
* VA_START - the first kernel virtual address.
*/
#define VA_BITS (CONFIG_ARM64_VA_BITS)
#define VA_START (UL(0xffffffffffffffff) - \
(UL(1) << VA_BITS) + 1)
#define PAGE_OFFSET (UL(0xffffffffffffffff) - \
(UL(1) << (VA_BITS - 1)) + 1)
#define KIMAGE_VADDR (MODULES_END)
#define MODULES_END (MODULES_VADDR + MODULES_VSIZE)
#define MODULES_VADDR (VA_START + KASAN_SHADOW_SIZE)
#define MODULES_VSIZE (SZ_128M)
#define VMEMMAP_START (PAGE_OFFSET - VMEMMAP_SIZE)