virt_to_phys:
weshuai@weshuai-HP-ProBook-4330s:~/Android/kernel/linux-3.19.3/arch/arm64$ grep -nr 'virt_to_phys' ./
./include/asm/kvm_mmu.h:282:#define kvm_virt_to_phys(x) __virt_to_phys((unsigned long)(x))./include/asm/proc-fns.h:42:#define cpu_switch_mm(pgd,mm) cpu_do_switch_mm(virt_to_phys(pgd),mm)
./include/asm/memory.h:70: * file
./ins. Use virt_to_phys/phys_to_virt/__pa/__va instead.
clude/asm/memory.h:123:#define virt_to_phys virt_to_phys
./include/asm/memory.h:124:static inline phys_addr_t virt_to_phys(const volatile void *x)
./include/asm/memory.h:126: return __virt_to_phys((unsigned long)(x));
./include/asm/memory.h:138:#define __pa(x) __virt_to_phys((unsigned long)(x))
./include/asm/memory.h:141:#define virt_to_pfn(x) __phys_to_pfn(__virt_to_phys(x))
./kernel/head.S:49: .macro pgtbl, ttb0, ttb1, virt_to_phys
./kernel/head.S:52: add \ttb1, \ttb1, \virt_to_phys
./kernel/head.S:53: add \ttb0, \ttb0, \virt_to_phys
./kernel/head.S:272: add x12, x12, x28 // __virt_to_phys
./kernel/head.S:644: add x12, x12, x28 // __virt_to_phys
./kernel/suspend.c:26: *save_ptr = virt_to_phys(ptr);
./kernel/suspend.c:155: sleep_save_sp.save_ptr_stash_phys = virt_to_phys(ctx_ptr);
./kernel/suspend.c:156: sleep_idmap_phys = virt_to_phys(idmap_pg_dir);
./kernel/efi.c:404: virtmap_phys = virt_to_phys(virtmap);
./kernel/setup.c:349: kernel_code.start = virt_to_phys(_text);
./kernel/setup.c:350: kernel_code.end = virt_to_phys(_etext - 1);
./kernel/setup.c:351: kernel_data.start = virt_to_phys(_sdata);
./kernel/setup.c:352: kernel_data.end = virt_to_phys(_end - 1);
./kernel/psci.c:517: virt_to_phys(cpu_resume));
./kernel/process.c:63: cpu_soft_restart(virt_to_phys(cpu_reset), addr);
./mm/init.c:150: memblock_reserve(__virt_to_phys(initrd_start), initrd_end - initrd_start);
./mm/dma-mapping.c:66: phys_addr_t phys = gen_pool_virt_to_phys(atomic_pool, val);
/*
* Physical vs virtual RAM address space conversion. These are
* private definitions which should NOT be used outside memory.h
* files. Use virt_to_phys/phys_to_virt/__pa/__va instead.
*/
#define __virt_to_phys(x) (((phys_addr_t)(x) - PAGE_OFFSET + PHYS_OFFSET))
#define __phys_to_virt(x) ((unsigned long)((x) - PHYS_OFFSET + PAGE_OFFSET))
首先,我们先对几个重要的宏进行说明(我们针对有MMU的情况):
宏 |
位置 |
默认值 |
说明 |
KERNEL_RAM_ADDR |
arch/arm/kernel/head.S +26 |
0xc0008000 |
kernel在RAM中的虚拟地址 |
PAGE_OFFSET |
include/asm-arm/memeory.h +50 |
0xc0000000 |
内核空间的起始虚拟地址 |
TEXT_OFFSET |
arch/arm/Makefile +131 |
0x00008000 |
内核在RAM中起始位置相对于 RAM起始地址的偏移 |
TEXTADDR |
arch/arm/kernel/head.S +49 |
0xc0008000 |
kernel的起始虚拟地址 |
PHYS_OFFSET |
include/asm-arm/arch- *** /memory.h |
平台相关 |
RAM的起始物理地址,对于s3c2410来说在include/asm-arm/arch-s3c2410/memory.h下定义,值为0x30000000(ram接在片选6上) |
/*
* PAGE_OFFSET - the virtual address of the start of the kernel image (top
* (VA_BITS - 1))
* VA_BITS - the maximum number of bits for virtual addresses.
* TASK_SIZE - the maximum size of a user space task.
* TASK_UNMAPPED_BASE - the lower boundary of the mmap VM area.
* The module space lives between the addresses given by TASK_SIZE
* and PAGE_OFFSET - it must be within 128MB of the kernel text.
*/
#define VA_BITS (CONFIG_ARM64_VA_BITS)
#define PAGE_OFFSET (UL(0xffffffffffffffff) << (VA_BITS - 1))
#define MODULES_END (PAGE_OFFSET)
#define MODULES_VADDR (MODULES_END - SZ_64M)
#define FIXADDR_TOP (MODULES_VADDR - SZ_2M - PAGE_SIZE)
#define TASK_SIZE_64 (UL(1) << VA_BITS)
extern phys_addr_t memstart_addr;
/* PHYS_OFFSET - the physical address of the start of memory. */
#define ({ ; })
weshuai@weshuai-HP-ProBook-4330s:~/Android/kernel/linux-3.19.3/arch/arm64$ grep -nr 'TEXT_OFFSET' ./
./kernel/head.S:39:#define KERNEL_RAM_VADDR (PAGE_OFFSET + TEXT_OFFSET)
./kernel/head.S:41:#if (TEXT_OFFSET & 0xfff) != 0
./kernel/head.S:42:#error TEXT_OFFSET must be at least 4KB aligned
./kernel/head.S:45:#elif TEXT_OFFSET > 0x1fffff
./kernel/head.S:46:#error TEXT_OFFSET must be less than 2MB
./kernel/head.S:95: * __pa(PAGE_OFFSET + TEXT_OFFSET).
./kernel/image.h:59: _kernel_offset_le = DATA_LE64(TEXT_OFFSET); \
./kernel/vmlinux.lds.S:68: . = PAGE_OFFSET + TEXT_OFFSET;
./kernel/vmlinux.lds.S:161:ASSERT(_text == (PAGE_OFFSET + TEXT_OFFSET), "HEAD is misaligned")
./kernel/Makefile:5:CPPFLAGS_vmlinux.lds := -DTEXT_OFFSET=$(TEXT_OFFSET)
./kernel/Makefile:6:AFLAGS_head.o := -DTEXT_OFFSET=$(TEXT_OFFSET)
./kernel/Makefile:7:CFLAGS_efi-stub.o := -DTEXT_OFFSET=$(TEXT_OFFSET)
./kernel/efi-entry.S:29: * we want to be. The kernel image wants to be placed at TEXT_OFFSET
./kernel/efi-stub.c:29: if (*image_addr != (dram_base + TEXT_OFFSET)) {
./kernel/efi-stub.c:31: status = efi_low_alloc(sys_table, kernel_memsize + TEXT_OFFSET,
./kernel/efi-stub.c:37: memcpy((void *)*reserve_addr + TEXT_OFFSET, (void *)*image_addr,
./kernel/efi-stub.c:39: *image_addr = *reserve_addr + TEXT_OFFSET;
./kernel/efi-stub.c:40: *reserve_size = kernel_memsize + TEXT_OFFSET;
./Makefile:14:CPPFLAGS_vmlinux.lds = -DTEXT_OFFSET=$(TEXT_OFFSET)
./Makefile:39:ifeq ($(CONFIG_ARM64_RANDOMIZE_TEXT_OFFSET), y)
./Makefile:40:TEXT_OFFSET := $(shell awk 'BEGIN {srand(); printf "0x%03x000\n", int(512 * rand())}')
./Makefile:42:TEXT_OFFSET := 0x00080000
./Makefile:45:export TEXT_OFFSET GZFLAGS
./Kconfig.debug:43:config ARM64_RANDOMIZE_TEXT_OFFSET
./Kconfig.debug:44: bool "Randomize TEXT_OFFSET at build time"
./Kconfig.debug:46: Say Y here if you want the image load offset (AKA TEXT_OFFSET)
./Kconfig.debug:48: this option will cause TEXT_OFFSET to be randomized upon any
./Kconfig.debug:55: of TEXT_OFFSET and platforms must not require a specific