diff mbox

[U-Boot,37/69] x86: Allow I/O functions to use pointers

Message ID 1457317732-18406-38-git-send-email-sjg@chromium.org
State Accepted
Commit 005174d661e0860a2af1be3025c2214142916ab4
Delegated to: Bin Meng
Headers show

Commit Message

Simon Glass March 7, 2016, 2:28 a.m. UTC
It is common with memory-mapped I/O to use the address of a structure member
to access memory, as in:

   struct some_regs {
      u32 ctrl;
      u32 data;
   }

   struct some_regs *regs = (struct some_regs *)BASE_ADDRESS;

   writel(1, &reg->ctrl);
   writel(2, &reg->data);

This does not currently work with inl(), outl(), etc. Add a cast to permit
this.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 arch/x86/include/asm/io.h | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

Comments

Bin Meng March 11, 2016, 6:38 a.m. UTC | #1
On Mon, Mar 7, 2016 at 10:28 AM, Simon Glass <sjg@chromium.org> wrote:
> It is common with memory-mapped I/O to use the address of a structure member
> to access memory, as in:
>
>    struct some_regs {
>       u32 ctrl;
>       u32 data;
>    }
>
>    struct some_regs *regs = (struct some_regs *)BASE_ADDRESS;
>
>    writel(1, &reg->ctrl);
>    writel(2, &reg->data);
>
> This does not currently work with inl(), outl(), etc. Add a cast to permit
> this.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>  arch/x86/include/asm/io.h | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
>

Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
diff mbox

Patch

diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
index 38b543d..d2c6e2e 100644
--- a/arch/x86/include/asm/io.h
+++ b/arch/x86/include/asm/io.h
@@ -202,7 +202,7 @@  out:
  * Talk about misusing macros..
  */
 #define __OUT1(s,x) \
-static inline void out##s(unsigned x value, unsigned short port) {
+static inline void _out##s(unsigned x value, unsigned short port) {
 
 #define __OUT2(s,s1,s2) \
 __asm__ __volatile__ ("out" #s " %" s1 "0,%" s2 "1"
@@ -213,7 +213,7 @@  __OUT1(s,x) __OUT2(s,s1,"w") : : "a" (value), "Nd" (port)); } \
 __OUT1(s##_p,x) __OUT2(s,s1,"w") __FULL_SLOW_DOWN_IO : : "a" (value), "Nd" (port));}
 
 #define __IN1(s) \
-static inline RETURN_TYPE in##s(unsigned short port) { RETURN_TYPE _v;
+static inline RETURN_TYPE _in##s(unsigned short port) { RETURN_TYPE _v;
 
 #define __IN2(s,s1,s2) \
 __asm__ __volatile__ ("in" #s " %" s2 "1,%" s1 "0"
@@ -242,10 +242,18 @@  __IN(w,"")
 __IN(l,"")
 #undef RETURN_TYPE
 
+#define inb(port)	_inb((uintptr_t)(port))
+#define inw(port)	_inw((uintptr_t)(port))
+#define inl(port)	_inl((uintptr_t)(port))
+
 __OUT(b,"b",char)
 __OUT(w,"w",short)
 __OUT(l,,int)
 
+#define outb(val, port)	_outb(val, (uintptr_t)(port))
+#define outw(val, port)	_outw(val, (uintptr_t)(port))
+#define outl(val, port)	_outl(val, (uintptr_t)(port))
+
 __INS(b)
 __INS(w)
 __INS(l)