zoukankan      html  css  js  c++  java
  • linux 驱动寄存器读写

    linux  driver write   writel_relaxed

    readb()和writeb()系列函数

     1 #define readb_relaxed(c) ({ u8  __r = __raw_readb(c); __r; })
     2 #define readw_relaxed(c) ({ u16 __r = le16_to_cpu((__force __le16) \
     3                     __raw_readw(c)); __r; })
     4 #define readl_relaxed(c) ({ u32 __r = le32_to_cpu((__force __le32) \
     5                     __raw_readl(c)); __r; })
     6 
     7 #define writeb_relaxed(v,c)    __raw_writeb(v,c)
     8 #define writew_relaxed(v,c)    __raw_writew((__force u16) cpu_to_le16(v),c)
     9 #define writel_relaxed(v,c)    __raw_writel((__force u32) cpu_to_le32(v),c)
    10 
    11 #define readb(c)        ({ u8  __v = readb_relaxed(c); __iormb(); __v; })
    12 #define readw(c)        ({ u16 __v = readw_relaxed(c); __iormb(); __v; })
    13 #define readl(c)        ({ u32 __v = readl_relaxed(c); __iormb(); __v; })
    14 
    15 #define writeb(v,c)        ({ __iowmb(); writeb_relaxed(v,c); })
    16 #define writew(v,c)        ({ __iowmb(); writew_relaxed(v,c); })
    17 #define writel(v,c)        ({ __iowmb(); writel_relaxed(v,c); })

    此系列函数用于从内存映射的I/O空间读写数据

    readb()和readb_relaxed()从I/O空间读取8位数据(1字节)

    readw()和readb_relaxew()从I/O空间读取16位数据(2字节)

    readl()和readb_relaxel()从I/O空间读取32位数据(4字节)

    writeb()和writeb_relaxed()从I/O空间写入8位数据(1字节)

    writew()和writew_relaxed()从I/O空间写入16位数据(2字节)

    writel()和writel_relaxed()从I/O空间写入32位数据(4字节)

    其中没有relaxed()的系列函数都调用了__iowmb()和__iormb()函数,这两个函数是内存屏障指令,防止编译器优化执行过程。

     访问物理地址

     u32 vaddr, i;

     vaddr = (u32)phys_to_virt(in_be32(&bd->buf));
  • 相关阅读:
    完整的WSDL语法
    WSDL UDDI
    八一八 The Social Network的小细节
    MySQL命令行常用命令
    AspectJ风格的Aop切点表达式
    强大的Mockito测试框架
    MySQL锁定状态查看命令
    Yum本地Rpm库设置
    Sed实例大全
    为何 Emacs 和 Vim 被称为两大神器
  • 原文地址:https://www.cnblogs.com/dream397/p/15562595.html
Copyright © 2011-2022 走看看