linux 配置物理内存

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)

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

shenhuxi_yu

感谢投币,继续输出

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值