在include/asm-mips/mach-generic/spaces.h中:
#ifndef PHYS_OFFSET
#define PHYS_OFFSET  _AC(0, UL)
#endif

#ifdef CONFIG_32BIT

#define CAC_BASE  _AC(0x80000000, UL)
#define IO_BASE   _AC(0xa0000000, UL)
#define UNCAC_BASE  _AC(0xa0000000, UL)

#ifndef MAP_BASE
#define MAP_BASE  _AC(0xc0000000, UL)
#endif

/*
 * Memory above this physical address will be considered highmem.
 */
#ifndef HIGHMEM_START
#define HIGHMEM_START  _AC(0x20000000, UL)
#endif

#endif /* CONFIG_32BIT */

#ifdef CONFIG_64BIT

#ifndef CAC_BASE
#ifdef CONFIG_DMA_NONCOHERENT
#define CAC_BASE  _AC(0x9800000000000000, UL)
#else
#define CAC_BASE  _AC(0xa800000000000000, UL)
#endif
#endif

#ifndef IO_BASE
#define IO_BASE   _AC(0x9000000000000000, UL)
#endif

#ifndef UNCAC_BASE
#define UNCAC_BASE  _AC(0x9000000000000000, UL)
#endif

#ifndef MAP_BASE
#define MAP_BASE  _AC(0xc000000000000000, UL)
#endif

/*
 * Memory above this physical address will be considered highmem.
 * Fixme: 59 bits is a fictive number and makes assumptions about processors
 * in the distant future.  Nobody will care for a few years :-)
 */
#ifndef HIGHMEM_START
#define HIGHMEM_START  (_AC(1, UL) << _AC(59, UL))
#endif

#define TO_PHYS(x)  (             ((x) & TO_PHYS_MASK))
#define TO_CAC(x)  (CAC_BASE   | ((x) & TO_PHYS_MASK))
#define TO_UNCAC(x)  (UNCAC_BASE | ((x) & TO_PHYS_MASK))

#endif /* CONFIG_64BIT */

/*
 * This handles the memory map.
 */
#ifndef PAGE_OFFSET
#define PAGE_OFFSET  (CAC_BASE + PHYS_OFFSET)
#endif

其中:_AC的定义见inlude\linux\const.h
#ifdef __ASSEMBLY__
#define _AC(X,Y) X
#define _AT(T,X) X
#else
#define __AC(X,Y) (X##Y)
#define _AC(X,Y) __AC(X,Y)
#define _AT(T,X) ((T)(X))
#endif
在非汇编程序中将两个参数拼接在一起

在include/asm-mips/io.h里:
/*
 *     virt_to_phys    -       map virtual addresses to physical
 *     @address: address to remap
 *
 *     The returned physical address is the physical (CPU) mapping for
 *     the memory address given. It is only valid to use this function on
 *     addresses directly mapped or allocated via kmalloc.
 *
 *     This function does not give bus mappings for DMA transfers. In
 *     almost all conceivable cases a device driver should not be using
 *     this function
 */
static inline unsigned long virt_to_phys(volatile const void *address)
{
 return (unsigned long)address - PAGE_OFFSET + PHYS_OFFSET;
}

/*
 *     phys_to_virt    -       map physical address to virtual
 *     @address: address to remap
 *
 *     The returned virtual address is a current CPU mapping for
 *     the memory address given. It is only valid to use this function on
 *     addresses that have a kernel mapping
 *
 *     This function does not handle bus mappings for DMA transfers. In
 *     almost all conceivable cases a device driver should not be using
 *     this function
 */
static inline void * phys_to_virt(unsigned long address)
{
 return (void *)(address + PAGE_OFFSET - PHYS_OFFSET);
}

/*
 * Change "struct page" to physical address.
 */
#define page_to_phys(page) ((dma_addr_t)page_to_pfn(page) << PAGE_SHIFT

在arch/mips/include/asm里:

/*
 * __pa()/__va() should be used only during mem init.
 */
#ifdef CONFIG_64BIT
#define __pa(x)        \
({         \
    unsigned long __x = (unsigned long)(x);    \
    __x < CKSEG0 ? XPHYSADDR(__x) : CPHYSADDR(__x);   \
})
#else
#define __pa(x)        \
    ((unsigned long)(x) - PAGE_OFFSET + PHYS_OFFSET)
#endif
#define __va(x)  ((void *)((unsigned long)(x) + PAGE_OFFSET - PHYS_OFFSET))

在arch/mips/include/asm/page.h中:
#define ARCH_PFN_OFFSET  PFN_UP(PHYS_OFFSET)

在inclue/asm-generic/memory_model.h中:
#if defined(CONFIG_FLATMEM)
#ifndef ARCH_PFN_OFFSET
#define ARCH_PFN_OFFSET  (0UL)
#endif
...
#endif

#if defined(CONFIG_FLATMEM)
#define __pfn_to_page(pfn) (mem_map + ((pfn) - ARCH_PFN_OFFSET))
#define __page_to_pfn(page) ((unsigned long)((page) - mem_map) + \
     ARCH_PFN_OFFSET)
...
#endif

#define page_to_pfn __page_to_pfn
#define pfn_to_page __pfn_to_page

其中宏__page_to_pfn(page)返回的是数组下标。理解了指针相减就明白了
假如page的实际地址是 p1,   mem_map的地址是 p2;
那么这个宏结果就是  (p1-p2)/sizeof(struct page) + PHYS_PFN_OFFSET;
参考:
//对同类型的结构体指针进行+,-运算,结果是加减多少个结构体.
//1.对于减运算
//两个同类型的结构体指针进行"-"运算,结果为两个单元地址空间之间一共距离多少个这种结构体
//例:page_to_pfn()函数:将mem_map_t类型的页管理单元page,转换为它所管理的页对应的物理页帧号
#define page_to_pfn(page) (((page) - mem_map) + PHYS_PFN_OFFSET)
//page - mem_map=表示从mem_map到page一共有多少个mem_map_t这种结构体,即:一共有多少个页

//2.对于加运算
//对结构体指针进行"+"运算,如:mem_map + 3;结果为mem_map所在地址加上3个mem_map_t结构体大小结构块之后的最终地址
//例:pfn_to_page()函数:将物理页帧号转换为管理该页的mem_map_t类型指针page
#define pfn_to_page(pfn) ((mem_map + (pfn)) - PHYS_PFN_OFFSET)
//变换一种形式可以更容易理解:(mem_map + (pfn - PHYS_PFN_OFFSET))
//其中index = pfn - PHYS_PFN_OFFSET表示物理页帧号pfn对应的偏移索引号index

linux mips架构PHYS_OFFSET、CAC_BASE、HIGHMEM_START、PAGE_OFFSET、virt_to_phys、phys_to_virt、page_to_phys的定义相关推荐

  1. linux arm current_thread_info定义,linux中arm/mips架构current_thread_info定义

    arm架构 current 宏的定义: linux-3.4\arch\arm\include\asm\current.h 中: static inline struct task_struct *ge ...

  2. linux内核信号处理机制--do_signal函数讲解 (适用mips架构)

        Linux为了允许用户态进程之间的通信而引入signal.此外, 内核使用signal给进程通知系统事件 对于信号signal,你要记住的基本点如下:   信号分实时信号(编码值为[32,64 ...

  3. 在qemu中运行mips架构的debian linux

    文章目录 前言 步骤 配置网络 前言 在qemu中运行mips架构的debian linux可以用于在没有mips架构的硬件时做一些相关测试. 本实验环境: 本机:OSX 10.14.4 虚拟机:Ub ...

  4. MIPS架构的医院智能导诊系统设计

    摘要:通过研究基于MIPS架构的SMP8654芯片的硬件架构,并且利用芯片内部的图形加速引擎GFX的方式实现了具有高清视频显示和图片文字处理功能的播放器.系统以嵌入式Linux和MiniGUI为平台设 ...

  5. 基于ar9331 mips架构AP121 uboot分析(3) 启动流程

    mips架构u-boot启动流程 u-boot的启动过程大致做如下工作: 1.cpu初始化 2.时钟.串口.内存(ddr ram)初始化 3.内存划分.分配栈.数据.配置参数.以及u-boot代码在内 ...

  6. MIPS 架构的 AR9331芯片 编译链相关内容

    windows篇============================= 小撸路由是啥?小撸路由顾名思义就是@小撸撸过的 WR703N 之类的路由(系统基于OpenWrt)!因为它使用起来非常方便, ...

  7. MIPS架构的启动地址随笔

    MIPS架构的cpu在上电.重启的入口地址为0xBFC0 0000,这段空间在 kseg1 (0xA000 0000 ~ 0xBFFF FFFF) 512M Bytes.这段地址空间通过把最高三位清零 ...

  8. php mipsl,MIPS系列笔记-交叉编译MIPS架构ASLA

    交叉编译MIPS架构ASLA ../src/.libs/libasound.so: undefined reference to `atomic_sub' 我使用下面的命令进行config: ./co ...

  9. 在openwrt(mips架构上)移植libusb库

    背景 有个项目,需要在openwrt的linux系统中使用libusb与挂载的一颗芯片进行USB通信,我要尝试在应用层通过libusb与外挂芯片进行USB通信. 调研 网上刚开始检索时,有网友说ope ...

最新文章

  1. 机器学习性能优化全解
  2. c/C++计算int / int *数组的长度;sizeof(指针),sizeof(数组名)的区别
  3. 卸载angular版本
  4. can bus 中spn是什么_CP AUTOSAR功能栈简介NM网络管理(Can)
  5. php怎样下载网上的文件,php怎样实现文件下载
  6. 超全超详细的HTTP状态码大全
  7. 通俗理解Spring的IOC和AOP
  8. linux分区理解整理
  9. 架构师到底该不该写代码?
  10. 在weblogic下部署找不到授权文件的解决方法
  11. RabbitMQ学习记录 - Direct之Routing模式
  12. stimulsoft入门教程:报表与页面上的图表(一)
  13. 【计算机网络 12,Java视频下载
  14. SQL 如何查询时竖着的数据横着显示
  15. No fallbackFactory instance of type class com.ruoyi.system.api.factory.RemoteLogFallbackFactory foun
  16. Excel小技巧:合并单元格且不丢失数据
  17. 2016ACM/ICPC亚洲区大连站-补题
  18. 从键盘输入一个字符,如果是小写字母,则将其转换成大写字母输出;如果是大写字母,则将其转换成小写字母输出;如果是其它字符,则原样输出。
  19. 通联支付php7,通联支付接口疑难问题处理开发者文档.pdf
  20. 如何将图片放大不改变清晰度?

热门文章

  1. Springboot + vue 实现导出word
  2. JS实现元素拖拽,简单悬浮框实现
  3. 小马哥 高仿三星w2015主板信息W1201-GW-NB82KK-150812刷机主板图
  4. 音视频开发系列(7):完成本地摄像头直播推流
  5. Knockout.js----使用计算属性(Computed Observable)
  6. html5 特效 banner,精品配饰活动banner html5特效制作教程
  7. 七大室内定位技术PK(转自3Snews)
  8. 为指针分配和释放空间
  9. 组合dp hdu-4489-The King’s Ups and Downs
  10. 大型圆弧怎么处理_这种大圆弧一次成型,回弹怎么计算?低公差