内核新特性——Patch physical to virtual translations at runtime

http://blog.csdn.net/remme123/article/details/14139929

Linux/arm 3.4.67 Kernel Configuration中多了一项:

Patch physical to virtual translations at runtime

帮助信息解释如下:

CONFIG_ARM_PATCH_PHYS_VIRT:     
  │                                                                     
  │ Patch phys-to-virt and virt-to-phys translation functions at        
  │ boot and module load time according to the position of the        
  │ kernel in system memory.                                          
  │                                                                  
  │ This can only be used with non-XIP MMU kernels where the base        
  │ of physical memory is at a 16MB boundary.                   
  │                                                                    
  │ Only disable this option if you know that you do not require       
  │ this feature (eg, building a kernel for a single machine) and        
  │ you need to shrink the kernel to the minimal size.  

意思就是对物理-虚拟地址互相转换进行修改,该功能会根据内核在系统中的位置自动计算出相应地址。

体现在代码上的改动可以在

arch/arm/include/asm/memory.h:

[cpp]  view plain copy
  1. #ifndef __virt_to_phys  
  2. #ifdef CONFIG_ARM_PATCH_PHYS_VIRT  
  3.   
  4. /* 
  5.  * Constants used to force the right instruction encodings and shifts 
  6.  * so that all we need to do is modify the 8-bit constant field. 
  7.  */  
  8. #define __PV_BITS_31_24 0x81000000  
  9.   
  10. extern unsigned long __pv_phys_offset;  
  11. #define PHYS_OFFSET __pv_phys_offset  
  12.   
  13. #define __pv_stub(from,to,instr,type)           \  
  14.     __asm__("@ __pv_stub\n"             \  
  15.     "1: " instr "   %0, %1, %2\n"       \  
  16.     "   .pushsection .pv_table,\"a\"\n"     \  
  17.     "   .long   1b\n"               \  
  18.     "   .popsection\n"              \  
  19.     : "=r" (to)                 \  
  20.     : "r" (from), "I" (type))  
  21.   
  22. static inline unsigned long __virt_to_phys(unsigned long x)  
  23. {  
  24.     unsigned long t;  
  25.     __pv_stub(x, t, "add", __PV_BITS_31_24);  
  26.     return t;  
  27. }  
  28.   
  29. static inline unsigned long __phys_to_virt(unsigned long x)  
  30. {  
  31.     unsigned long t;  
  32.     __pv_stub(x, t, "sub", __PV_BITS_31_24);  
  33.     return t;  
  34. }  
  35. #else  
  36. #define __virt_to_phys(x)   ((x) - PAGE_OFFSET + PHYS_OFFSET)  
  37. #define __phys_to_virt(x)   ((x) - PHYS_OFFSET + PAGE_OFFSET)  
  38. #endif  
  39. #endif  

另外,再额外提供一段有用的信息,也是在这个文件里面:

[cpp]  view plain copy
  1. #ifndef PHYS_OFFSET  
  2. #ifdef PLAT_PHYS_OFFSET  
  3. #define PHYS_OFFSET PLAT_PHYS_OFFSET  
  4. #else  
  5. #define PHYS_OFFSET UL(CONFIG_PHYS_OFFSET)  
  6. #endif  
  7. #endif  
  8.   
  9. /* 
  10.  * PFNs are used to describe any physical page; this means 
  11.  * PFN 0 == physical address 0. 
  12.  * 
  13.  * This is the PFN of the first RAM page in the kernel 
  14.  * direct-mapped view.  We assume this is the first page 
  15.  * of RAM in the mem_map as well. 
  16.  */  
  17. #define PHYS_PFN_OFFSET (PHYS_OFFSET >> PAGE_SHIFT)  
  18.   
  19. /* 
  20.  * These are *only* valid on the kernel direct mapped RAM memory. 
  21.  * Note: Drivers should NOT use these.  They are the wrong 
  22.  * translation for translating DMA addresses.  Use the driver 
  23.  * DMA support - see dma-mapping.h. 
  24.  */  
  25. static inline phys_addr_t virt_to_phys(const volatile void *x)  
  26. {  
  27.     return __virt_to_phys((unsigned long)(x));  
  28. }  
  29.   
  30. static inline void *phys_to_virt(phys_addr_t x)  
  31. {  
  32.     return (void *)(__phys_to_virt((unsigned long)(x)));  
  33. }  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值