?? 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 + -