[v4,01/21] arm/acpi: Emulate io ports for arm
diff mbox

Message ID 1453540813-15764-2-git-send-email-zhaoshenglong@huawei.com
State New, archived
Headers show

Commit Message

Shannon Zhao Jan. 23, 2016, 9:19 a.m. UTC
From: Shannon Zhao <shannon.zhao@linaro.org>

Add macros to emulate x86 style ports for arm. This avoids modification in
common code for acpi. Here just print a warning on ARM.

Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
---
V4: print warning
---
 xen/include/asm-arm/arm64/io.h | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

Comments

Stefano Stabellini Jan. 27, 2016, 12:52 p.m. UTC | #1
On Sat, 23 Jan 2016, Shannon Zhao wrote:
> From: Shannon Zhao <shannon.zhao@linaro.org>
> 
> Add macros to emulate x86 style ports for arm. This avoids modification in
> common code for acpi. Here just print a warning on ARM.
> 
> Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
> ---
> V4: print warning
> ---
>  xen/include/asm-arm/arm64/io.h | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)
> 
> diff --git a/xen/include/asm-arm/arm64/io.h b/xen/include/asm-arm/arm64/io.h
> index 37abc47..ec5815d 100644
> --- a/xen/include/asm-arm/arm64/io.h
> +++ b/xen/include/asm-arm/arm64/io.h
> @@ -20,6 +20,7 @@
>  #ifndef _ARM_ARM64_IO_H
>  #define _ARM_ARM64_IO_H
>  
> +#include <asm/system.h>
>  #include <asm/byteorder.h>
>  
>  /*
> @@ -109,4 +110,21 @@ static inline u64 __raw_readq(const volatile void __iomem *addr)
>  #define writel(v,c)             ({ __iowmb(); writel_relaxed((v),(c)); })
>  #define writeq(v,c)             ({ __iowmb(); writeq_relaxed((v),(c)); })
>  
> +/*
> + * Emulate x86 io ports for ARM.
> + */
> +static inline void __iomem * __armio(u64 addr)
> +{
> +    printk(XENLOG_G_WARNING "Can't access IO %lx\n", addr);
> +    return (void __iomem *)addr;
> +}
> +
> +#define inb(c) ( readb( __armio(c) ) )
> +#define inw(c) ( readw( __armio(c) ) )
> +#define inl(c) ( readl( __armio(c) ) )
> +
> +#define outb(v, c) ( writeb(v, __armio(c) ) )
> +#define outw(v, c) ( writew(v, __armio(c) ) )
> +#define outl(v, c) ( writel(v, __armio(c) ) )

This is better than before, but it would still end up causing a write to
happen on outb, outw and outl. I would define them in a way so that
only the warning gets printed when they are called and nothing else.
Shannon Zhao Jan. 28, 2016, 12:13 p.m. UTC | #2
On 2016/1/27 20:52, Stefano Stabellini wrote:
> On Sat, 23 Jan 2016, Shannon Zhao wrote:
>> From: Shannon Zhao <shannon.zhao@linaro.org>
>>
>> Add macros to emulate x86 style ports for arm. This avoids modification in
>> common code for acpi. Here just print a warning on ARM.
>>
>> Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
>> ---
>> V4: print warning
>> ---
>>  xen/include/asm-arm/arm64/io.h | 18 ++++++++++++++++++
>>  1 file changed, 18 insertions(+)
>>
>> diff --git a/xen/include/asm-arm/arm64/io.h b/xen/include/asm-arm/arm64/io.h
>> index 37abc47..ec5815d 100644
>> --- a/xen/include/asm-arm/arm64/io.h
>> +++ b/xen/include/asm-arm/arm64/io.h
>> @@ -20,6 +20,7 @@
>>  #ifndef _ARM_ARM64_IO_H
>>  #define _ARM_ARM64_IO_H
>>  
>> +#include <asm/system.h>
>>  #include <asm/byteorder.h>
>>  
>>  /*
>> @@ -109,4 +110,21 @@ static inline u64 __raw_readq(const volatile void __iomem *addr)
>>  #define writel(v,c)             ({ __iowmb(); writel_relaxed((v),(c)); })
>>  #define writeq(v,c)             ({ __iowmb(); writeq_relaxed((v),(c)); })
>>  
>> +/*
>> + * Emulate x86 io ports for ARM.
>> + */
>> +static inline void __iomem * __armio(u64 addr)
>> +{
>> +    printk(XENLOG_G_WARNING "Can't access IO %lx\n", addr);
>> +    return (void __iomem *)addr;
>> +}
>> +
>> +#define inb(c) ( readb( __armio(c) ) )
>> +#define inw(c) ( readw( __armio(c) ) )
>> +#define inl(c) ( readl( __armio(c) ) )
>> +
>> +#define outb(v, c) ( writeb(v, __armio(c) ) )
>> +#define outw(v, c) ( writew(v, __armio(c) ) )
>> +#define outl(v, c) ( writel(v, __armio(c) ) )
> 
> This is better than before, but it would still end up causing a write to
> happen on outb, outw and outl. I would define them in a way so that
> only the warning gets printed when they are called and nothing else.
> 

How about this?

+/*
+ * Emulate x86 io ports for ARM.
+ */
+static inline int emulate_read(u64 addr)
+{
+    printk(XENLOG_G_WARNING "Can't access IO %lx\n", addr);
+    return 0;
+}
+
+static inline void emulate_write(u64 addr)
+{
+    printk(XENLOG_G_WARNING "Can't access IO %lx\n", addr);
+}
+
+#define inb(c) ( emulate_read(c) )
+#define inw(c) ( emulate_read(c) )
+#define inl(c) ( emulate_read(c) )
+
+#define outb(v, c) ( emulate_write(c) )
+#define outw(v, c) ( emulate_write(c) )
+#define outl(v, c) ( emulate_write(c) )

Thanks,
Stefano Stabellini Jan. 28, 2016, 12:35 p.m. UTC | #3
On Thu, 28 Jan 2016, Shannon Zhao wrote:
> On 2016/1/27 20:52, Stefano Stabellini wrote:
> > On Sat, 23 Jan 2016, Shannon Zhao wrote:
> >> From: Shannon Zhao <shannon.zhao@linaro.org>
> >>
> >> Add macros to emulate x86 style ports for arm. This avoids modification in
> >> common code for acpi. Here just print a warning on ARM.
> >>
> >> Signed-off-by: Shannon Zhao <shannon.zhao@linaro.org>
> >> ---
> >> V4: print warning
> >> ---
> >>  xen/include/asm-arm/arm64/io.h | 18 ++++++++++++++++++
> >>  1 file changed, 18 insertions(+)
> >>
> >> diff --git a/xen/include/asm-arm/arm64/io.h b/xen/include/asm-arm/arm64/io.h
> >> index 37abc47..ec5815d 100644
> >> --- a/xen/include/asm-arm/arm64/io.h
> >> +++ b/xen/include/asm-arm/arm64/io.h
> >> @@ -20,6 +20,7 @@
> >>  #ifndef _ARM_ARM64_IO_H
> >>  #define _ARM_ARM64_IO_H
> >>  
> >> +#include <asm/system.h>
> >>  #include <asm/byteorder.h>
> >>  
> >>  /*
> >> @@ -109,4 +110,21 @@ static inline u64 __raw_readq(const volatile void __iomem *addr)
> >>  #define writel(v,c)             ({ __iowmb(); writel_relaxed((v),(c)); })
> >>  #define writeq(v,c)             ({ __iowmb(); writeq_relaxed((v),(c)); })
> >>  
> >> +/*
> >> + * Emulate x86 io ports for ARM.
> >> + */
> >> +static inline void __iomem * __armio(u64 addr)
> >> +{
> >> +    printk(XENLOG_G_WARNING "Can't access IO %lx\n", addr);
> >> +    return (void __iomem *)addr;
> >> +}
> >> +
> >> +#define inb(c) ( readb( __armio(c) ) )
> >> +#define inw(c) ( readw( __armio(c) ) )
> >> +#define inl(c) ( readl( __armio(c) ) )
> >> +
> >> +#define outb(v, c) ( writeb(v, __armio(c) ) )
> >> +#define outw(v, c) ( writew(v, __armio(c) ) )
> >> +#define outl(v, c) ( writel(v, __armio(c) ) )
> > 
> > This is better than before, but it would still end up causing a write to
> > happen on outb, outw and outl. I would define them in a way so that
> > only the warning gets printed when they are called and nothing else.
> > 
> 
> How about this?

That's good


> +/*
> + * Emulate x86 io ports for ARM.
> + */
> +static inline int emulate_read(u64 addr)
> +{
> +    printk(XENLOG_G_WARNING "Can't access IO %lx\n", addr);
> +    return 0;
> +}
> +
> +static inline void emulate_write(u64 addr)
> +{
> +    printk(XENLOG_G_WARNING "Can't access IO %lx\n", addr);
> +}
> +
> +#define inb(c) ( emulate_read(c) )
> +#define inw(c) ( emulate_read(c) )
> +#define inl(c) ( emulate_read(c) )
> +
> +#define outb(v, c) ( emulate_write(c) )
> +#define outw(v, c) ( emulate_write(c) )
> +#define outl(v, c) ( emulate_write(c) )
> 
> Thanks,
> -- 
> Shannon
>

Patch
diff mbox

diff --git a/xen/include/asm-arm/arm64/io.h b/xen/include/asm-arm/arm64/io.h
index 37abc47..ec5815d 100644
--- a/xen/include/asm-arm/arm64/io.h
+++ b/xen/include/asm-arm/arm64/io.h
@@ -20,6 +20,7 @@ 
 #ifndef _ARM_ARM64_IO_H
 #define _ARM_ARM64_IO_H
 
+#include <asm/system.h>
 #include <asm/byteorder.h>
 
 /*
@@ -109,4 +110,21 @@  static inline u64 __raw_readq(const volatile void __iomem *addr)
 #define writel(v,c)             ({ __iowmb(); writel_relaxed((v),(c)); })
 #define writeq(v,c)             ({ __iowmb(); writeq_relaxed((v),(c)); })
 
+/*
+ * Emulate x86 io ports for ARM.
+ */
+static inline void __iomem * __armio(u64 addr)
+{
+    printk(XENLOG_G_WARNING "Can't access IO %lx\n", addr);
+    return (void __iomem *)addr;
+}
+
+#define inb(c) ( readb( __armio(c) ) )
+#define inw(c) ( readw( __armio(c) ) )
+#define inl(c) ( readl( __armio(c) ) )
+
+#define outb(v, c) ( writeb(v, __armio(c) ) )
+#define outw(v, c) ( writew(v, __armio(c) ) )
+#define outl(v, c) ( writel(v, __armio(c) ) )
+
 #endif /* _ARM_ARM64_IO_H */