📄 s3c2410---page_offset.txt
字号:
在/kernel/include/asm-arm/arch-s3c2410/memory.h 文件中:
/*
* Page offset: 3GB
*/
#define PAGE_OFFSET (0xc0000000UL)
#define PHYS_OFFSET (0x30000000UL)
/*
* We take advantage of the fact that physical and virtual address can be the
* saem. Thu NUMA code is handling the large holes that might exist between
* all memory banks.
*/
#define __virt_to_phys__is_a_macro
#define __phys_to_virt__is_a_macro
#define __virt_to_phys(x) ((x) - PAGE_OFFSET + PHYS_OFFSET)
#define __phys_to_virt(x) ((x) - PHYS_OFFSET + PAGE_OFFSET)
由此可见: 起始点地址 PHYS_OFFSET PAGE_OFFSET
| |
|--0x30000000--|------间隔------|
PHYS_OFFSET(物理地址起始点): |--------------|...........................
|
|-----------0xc0000000----------|
PAGE_OFFSET(虚拟地址起始点): |-------------------------------|..........
物理地址与虚拟地址的间隔为:PAGE_OFFSET - PHYS_OFFSET。这样一来,以上对物理
地址和虚拟地址之间转换的宏定义就很好理解了。
虚拟地址转为物理地址宏:__virt_to_phys(x)
= (x) - (PAGE_OFFSET - PHYS_OFFSET) = (x) - PAGE_OFFSET + PHYS_OFFSET
物理地址转为虚拟地址宏:__phys_to_virt(x)
= (x) + (PAGE_OFFSET - PHYS_OFFSET) = (x) + PAGE_OFFSET - PHYS_OFFSET
内核虚拟地址和实际物理地址仅仅是相差一个偏移量(PAGE_OFFSET),可以很方便的
将其转化为物理内存地址,同时内核也提供了virt_to_phys() 函数将内核虚拟空间中的物理
影射区地址转化为物理地址。
/*
* Virtual view <-> DMA view memory address translations
* virt_to_bus: Used to translate the virtual address to an
* address suitable to be passed to set_dma_addr
* bus_to_virt: Used to convert an address for DMA operations
* to an address that the kernel can use.
*/
#define __virt_to_bus__is_a_macro
#define __bus_to_virt__is_a_macro
#define __virt_to_bus(x) __virt_to_phys(x)
#define __bus_to_virt(x) __phys_to_virt(x)
这里注意:__virt_to_bus(x) 就等于__virt_to_phys(x)。此结论 为下面的继续分析作准备
*************************************************************************************
在/kernel/include/asm-arm/memory.h 文件中:
/*
* These are *only* valid on the kernel direct mapped RAM memory.
*/
static inline unsigned long virt_to_phys(volatile void *x)
{
return __virt_to_phys((unsigned long)(x));
}
/*
* Virtual <-> DMA view memory address translations
* Again, these are *only* valid on the kernel direct mapped RAM
* memory.
*/
#define virt_to_bus(x) (__virt_to_bus((unsigned long)(x))) //利用上面的结论__virt_to_bus(x) 就等于__virt_to_phys(x)
由上面的分析可知:virt_to_bus(x) 和virt_to_phys(volatile void *x) 这两个函数调用的都是_
_virt_to_phys(x) 即((x) - PAGE_OFFSET + PHYS_OFFSET)。所以这两个调用都是将虚拟地址
转换为了物理地址。
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -