• 006_linux驱动之_ioremap函数使用


    (一)学习linux驱动之初,对ioremap函数的个人理解

    (二)博客:实验探究 ioremap 这篇文章作者通过验证来阐述自己的观点,个人觉得挺好的
    (三)函数原型
    基本简介
    void * __ioremap(unsigned long phys_addr, unsigned long size, unsigned long flags)
    void *ioremap(unsigned long phys_addr, unsigned long size)
    入口: phys_addr:要映射的起始的IO地址;
    size:要映射的空间的大小;
    flags:要映射的IO空间的和权限有关的标志;
    phys_addr:是要映射的物理地址
    size:是要映射的长度,单位是字节
    头文件:io.h
    (四)个人理解使用:
    gpfcon = (volatile unsigned long *)ioremap(0x56000050,   16);
    gpfdat = gpfcon + 1;
     
    1. 从上面我们映射的起始地址为0x56000050也就是寄存器GPFCON的地址
    2. 映射长度为16字节,也就是映射地址从:0x56000050~0x5600005C 地址全部映射完了
    3. gpfdat = gpfcon + 1;的意思是 0x56000050 + 4 = 0x56000054 其地址是寄存器GPFDAT的地址
    4. 为什么是加4呢,因为这个是指针加1,unsigned long的字节长度为4,指针加1,其地址就加4
     
    (五)从上面的可以看出,假如我们只使用GPFCON和GPFDAT寄存器的话,我们也可以这样写
    gpfcon = (volatile unsigned long *)ioremap(0x56000050,   8);
    gpfdat = gpfcon + 1;
     
    或者:
    gpfcon = (volatile unsigned long *)ioremap(0x56000050,  4);
    gpfdat = (volatile unsigned long *)ioremap(0x56000054,  4);
     
    查看百度百科的解释可能会更好的理解


     
    (六)当我们需要解除映射的虚拟地址时候我们需要使用函数iounmap();
    释放上面映射的地址使用示例:
    iounmap(gpfcon);      

     

  • 相关阅读:
    Kubernetes+Federation打造跨多云管理服务
    idou老师教你学istio 31:Istio-proxy的report流程
    《软件工程》课程总结(补)
    《软件工程》课程总结
    十二周# 学习进度总结
    十一周# 学习进度总结
    十周# 学习进度总结
    九周# 学习进度总结
    八周# 学习进度总结
    团队项目——编写项目的Spec
  • 原文地址:https://www.cnblogs.com/luxiaoguogege/p/9690219.html
Copyright © 2020-2023  润新知