Cc: Andrew Jones <drjones@xxxxxxxxxx> Cc: Thomas Huth <thuth@xxxxxxxxxx> Cc: Paolo Bonzini <pbonzini@xxxxxxxxxx> Cc: Radim Krčmář <rkrcmar@xxxxxxxxxx> Signed-off-by: Alexander Gordeev <agordeev@xxxxxxxxxx> --- lib/asm-generic/barrier.h | 21 +++++++++++++++++++ lib/asm-generic/io.h | 53 ++++++++++++++++++++++++++++++++++++++--------- lib/ppc64/asm/barrier.h | 4 ++++ lib/x86/asm/io.h | 35 ++++++++++++++++++++----------- 4 files changed, 91 insertions(+), 22 deletions(-) create mode 100644 lib/asm-generic/barrier.h create mode 100644 lib/ppc64/asm/barrier.h diff --git a/lib/asm-generic/barrier.h b/lib/asm-generic/barrier.h new file mode 100644 index 000000000000..21c88e9184c5 --- /dev/null +++ b/lib/asm-generic/barrier.h @@ -0,0 +1,21 @@ +#ifndef _ASM_BARRIER_H_ +#define _ASM_BARRIER_H_ +/* + * asm-generic/barrier.h + * + * Copyright (C) 2016, Red Hat Inc, Alexander Gordeev <agordeev@xxxxxxxxxx> + * + * This work is licensed under the terms of the GNU LGPL, version 2. + */ + +#ifndef mb +#define mb() asm volatile("":::"memory") +#endif +#ifndef rmb +#define rmb() asm volatile("":::"memory") +#endif +#ifndef wmb +#define wmb() asm volatile("":::"memory") +#endif + +#endif /* _ASM_BARRIER_H_ */ diff --git a/lib/asm-generic/io.h b/lib/asm-generic/io.h index 41756dbf01bb..91a2d7995d3d 100644 --- a/lib/asm-generic/io.h +++ b/lib/asm-generic/io.h @@ -11,6 +11,7 @@ */ #include "libcflat.h" #include "asm/page.h" +#include "asm/barrier.h" #ifndef __raw_readb static inline u8 __raw_readb(const volatile void *addr) @@ -127,16 +128,6 @@ static inline u64 __bswap64(u64 x) ({ u64 __r = !__cpu_is_be() ? __bswap64(x) : ((u64)x); __r; }) #define cpu_to_be64 be64_to_cpu -#ifndef mb -#define mb() asm volatile("":::"memory") -#endif -#ifndef rmb -#define rmb() asm volatile("":::"memory") -#endif -#ifndef wmb -#define wmb() asm volatile("":::"memory") -#endif - #define readb(addr) \ ({ u8 __r = __raw_readb(addr); rmb(); __r; }) #define readw(addr) \ @@ -155,6 +146,48 @@ static inline u64 __bswap64(u64 x) #define writeq(b, addr) \ ({ wmb(); __raw_writeq(cpu_to_le64(b), addr); }) +#ifndef inb +static inline uint8_t inb(unsigned long port) +{ + return readb((const volatile void __iomem *)port); +} +#endif + +#ifndef inw +static inline uint16_t inw(unsigned long port) +{ + return readw((const volatile void __iomem *)port); +} +#endif + +#ifndef inl +static inline uint32_t inl(unsigned long port) +{ + return readl((const volatile void __iomem *)port); +} +#endif + +#ifndef outb +static inline void outb(uint8_t value, unsigned long port) +{ + writeb(value, (volatile void __iomem *)port); +} +#endif + +#ifndef outw +static inline void outw(uint16_t value, unsigned long port) +{ + writew(value, (volatile void __iomem *)port); +} +#endif + +#ifndef outl +static inline void outl(uint32_t value, unsigned long port) +{ + writel(value, (volatile void __iomem *)port); +} +#endif + #ifndef ioremap static inline void __iomem *ioremap(phys_addr_t phys_addr, size_t size __unused) { diff --git a/lib/ppc64/asm/barrier.h b/lib/ppc64/asm/barrier.h new file mode 100644 index 000000000000..5c772ded52e2 --- /dev/null +++ b/lib/ppc64/asm/barrier.h @@ -0,0 +1,4 @@ +#ifndef _ASMPPC64_BARRIER_H_ +#define _ASMPPC64_BARRIER_H_ +#include <asm-generic/barrier.h> +#endif diff --git a/lib/x86/asm/io.h b/lib/x86/asm/io.h index 2436822162de..35a5c7347411 100644 --- a/lib/x86/asm/io.h +++ b/lib/x86/asm/io.h @@ -3,52 +3,63 @@ #define __iomem -static inline unsigned char inb(unsigned short port) +#define inb inb +static inline uint8_t inb(unsigned long port) { unsigned char value; - asm volatile("inb %w1, %0" : "=a" (value) : "Nd" (port)); + asm volatile("inb %w1, %0" : "=a" (value) : "Nd" ((unsigned short)port)); return value; } -static inline unsigned short inw(unsigned short port) +#define inw inw +static inline uint16_t inw(unsigned long port) { unsigned short value; - asm volatile("inw %w1, %0" : "=a" (value) : "Nd" (port)); + asm volatile("inw %w1, %0" : "=a" (value) : "Nd" ((unsigned short)port)); return value; } -static inline unsigned int inl(unsigned short port) +#define inl inl +static inline uint32_t inl(unsigned long port) { unsigned int value; - asm volatile("inl %w1, %0" : "=a" (value) : "Nd" (port)); + asm volatile("inl %w1, %0" : "=a" (value) : "Nd" ((unsigned short)port)); return value; } -static inline void outb(unsigned char value, unsigned short port) +#define outb outb +static inline void outb(uint8_t value, unsigned long port) { - asm volatile("outb %b0, %w1" : : "a"(value), "Nd"(port)); + asm volatile("outb %b0, %w1" : : "a"(value), "Nd"((unsigned short)port)); } -static inline void outw(unsigned short value, unsigned short port) +#define outw outw +static inline void outw(uint16_t value, unsigned long port) { - asm volatile("outw %w0, %w1" : : "a"(value), "Nd"(port)); + asm volatile("outw %w0, %w1" : : "a"(value), "Nd"((unsigned short)port)); } -static inline void outl(unsigned int value, unsigned short port) +#define outl outl +static inline void outl(uint32_t value, unsigned long port) { - asm volatile("outl %0, %w1" : : "a"(value), "Nd"(port)); + asm volatile("outl %0, %w1" : : "a"(value), "Nd"((unsigned short)port)); } +#define virt_to_phys virt_to_phys static inline unsigned long virt_to_phys(const void *virt) { return (unsigned long)virt; } +#define phys_to_virt phys_to_virt static inline void *phys_to_virt(unsigned long phys) { return (void *)phys; } +#define ioremap ioremap void __iomem *ioremap(phys_addr_t phys_addr, size_t size); +#include <asm-generic/io.h> + #endif -- 1.8.3.1 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html