From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alexander Gordeev Subject: Re: [PATCH v2 4/9] x86: Introduce lib/x86/asm/io.h Date: Wed, 27 Apr 2016 18:23:28 +0200 Message-ID: <20160427162327.GA14081@dhcp-27-118.brq.redhat.com> References: <01e172ff45592be617dc1b16c2c98325f187eba1.1461762418.git.agordeev@redhat.com> <20160427134657.2ws4wmm4sdrmhlgr@hawk.localdomain> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: kvm@vger.kernel.org, Thomas Huth , Radim =?utf-8?B?S3LEjW3DocWZ?= To: Andrew Jones Return-path: Received: from mx1.redhat.com ([209.132.183.28]:38167 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752346AbcD0QXd (ORCPT ); Wed, 27 Apr 2016 12:23:33 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0AFF863157 for ; Wed, 27 Apr 2016 16:23:32 +0000 (UTC) Content-Disposition: inline In-Reply-To: <20160427134657.2ws4wmm4sdrmhlgr@hawk.localdomain> Sender: kvm-owner@vger.kernel.org List-ID: On Wed, Apr 27, 2016 at 03:46:57PM +0200, Andrew Jones wrote: > On Wed, Apr 27, 2016 at 03:13:53PM +0200, Alexander Gordeev wrote: > > Make x86 consistent with other architectures and put > > IO specific defines to lib/x86/asm/io.h > >=20 > > Cc: Andrew Jones > > Cc: Thomas Huth > > Cc: Radim Kr=C4=8Dm=C3=A1=C5=99 > > Signed-off-by: Alexander Gordeev > > --- > > lib/x86/asm/io.h | 52 +++++++++++++++++++++++++++++++++++++++++= +++++++++++ > > lib/x86/asm/pci.h | 2 +- > > lib/x86/io.c | 2 +- > > lib/x86/io.h | 40 ---------------------------------------- > > lib/x86/vm.h | 12 +----------- > > x86/eventinj.c | 7 +------ > > x86/hyperv.c | 1 + > > x86/hyperv.h | 1 - > > x86/hyperv_stimer.c | 1 - > > x86/hyperv_synic.c | 1 - > > x86/init.c | 2 +- > > x86/svm.c | 1 - > > x86/vmexit.c | 1 - > > x86/vmx.c | 1 - > > x86/vmx_tests.c | 1 - > > 15 files changed, 58 insertions(+), 67 deletions(-) > > create mode 100644 lib/x86/asm/io.h > > delete mode 100644 lib/x86/io.h > >=20 > > diff --git a/lib/x86/asm/io.h b/lib/x86/asm/io.h > > new file mode 100644 > > index 0000000..68b10e5 > > --- /dev/null > > +++ b/lib/x86/asm/io.h > > @@ -0,0 +1,52 @@ > > +#ifndef _ASM_X86_IO_H_ > > +#define _ASM_X86_IO_H_ > > + > > +#include "asm/page.h" >=20 > why is this include here? Just to conform to other archs which also include it. But probably it needs revising in the other archs instead.. > > + > > +static inline unsigned char inb(unsigned short port) > > +{ > > + unsigned char value; > > + asm volatile("inb %w1, %0" : "=3Da" (value) : "Nd" (port)); > > + return value; > > +} > > + > > +static inline unsigned short inw(unsigned short port) > > +{ > > + unsigned short value; > > + asm volatile("inw %w1, %0" : "=3Da" (value) : "Nd" (port)); > > + return value; > > +} > > + > > +static inline unsigned int inl(unsigned short port) > > +{ > > + unsigned int value; > > + asm volatile("inl %w1, %0" : "=3Da" (value) : "Nd" (port)); > > + return value; > > +} > > + > > +static inline void outb(unsigned char value, unsigned short port) > > +{ > > + asm volatile("outb %b0, %w1" : : "a"(value), "Nd"(port)); > > +} > > + > > +static inline void outw(unsigned short value, unsigned short port) > > +{ > > + asm volatile("outw %w0, %w1" : : "a"(value), "Nd"(port)); > > +} > > + > > +static inline void outl(unsigned int value, unsigned short port) > > +{ > > + asm volatile("outl %0, %w1" : : "a"(value), "Nd"(port)); > > +} > > + > > +static inline unsigned long virt_to_phys(const void *virt) > > +{ > > + return (unsigned long)virt; > > +} > > + > > +static inline void *phys_to_virt(unsigned long phys) > > +{ > > + return (void *)phys; > > +} > > + > > +#endif > > diff --git a/lib/x86/asm/pci.h b/lib/x86/asm/pci.h > > index 4ec20e1..cddde41 100644 > > --- a/lib/x86/asm/pci.h > > +++ b/lib/x86/asm/pci.h > > @@ -7,7 +7,7 @@ > > */ > > #include "libcflat.h" > > #include "pci.h" > > -#include "x86/io.h" > > +#include "x86/asm/io.h" > > =20 > > static inline uint32_t pci_config_read(pcidevaddr_t dev, uint8_t r= eg) > > { > > diff --git a/lib/x86/io.c b/lib/x86/io.c > > index d3b971e..d396d42 100644 > > --- a/lib/x86/io.c > > +++ b/lib/x86/io.c > > @@ -1,6 +1,6 @@ > > #include "libcflat.h" > > #include "smp.h" > > -#include "io.h" > > +#include "asm/io.h" > > #ifndef USE_SERIAL > > #define USE_SERIAL > > #endif > > diff --git a/lib/x86/io.h b/lib/x86/io.h > > deleted file mode 100644 > > index bd6341c..0000000 > > --- a/lib/x86/io.h > > +++ /dev/null > > @@ -1,40 +0,0 @@ > > -#ifndef IO_H > > -#define IO_H > > - > > -static inline unsigned char inb(unsigned short port) > > -{ > > - unsigned char value; > > - asm volatile("inb %w1, %0" : "=3Da" (value) : "Nd" (port)); > > - return value; > > -} > > - > > -static inline unsigned short inw(unsigned short port) > > -{ > > - unsigned short value; > > - asm volatile("inw %w1, %0" : "=3Da" (value) : "Nd" (port)); > > - return value; > > -} > > - > > -static inline unsigned int inl(unsigned short port) > > -{ > > - unsigned int value; > > - asm volatile("inl %w1, %0" : "=3Da" (value) : "Nd" (port)); > > - return value; > > -} > > - > > -static inline void outb(unsigned char value, unsigned short port) > > -{ > > - asm volatile("outb %b0, %w1" : : "a"(value), "Nd"(port)); > > -} > > - > > -static inline void outw(unsigned short value, unsigned short port) > > -{ > > - asm volatile("outw %w0, %w1" : : "a"(value), "Nd"(port)); > > -} > > - > > -static inline void outl(unsigned int value, unsigned short port) > > -{ > > - asm volatile("outl %0, %w1" : : "a"(value), "Nd"(port)); > > -} > > - > > -#endif > > diff --git a/lib/x86/vm.h b/lib/x86/vm.h > > index 72f84e6..21ed2b6 100644 > > --- a/lib/x86/vm.h > > +++ b/lib/x86/vm.h > > @@ -2,7 +2,7 @@ > > #define VM_H > > =20 > > #include "processor.h" > > -#include "asm/page.h" > > +#include "asm/io.h" > > =20 > > void setup_vm(); > > =20 > > @@ -27,14 +27,4 @@ unsigned long *install_large_page(unsigned long = *cr3,unsigned long phys, > > void *virt); > > unsigned long *install_page(unsigned long *cr3, unsigned long phys= , void *virt); > > =20 > > -static inline unsigned long virt_to_phys(const void *virt) > > -{ > > - return (unsigned long)virt; > > -} > > - > > -static inline void *phys_to_virt(unsigned long phys) > > -{ > > - return (void *)phys; > > -} > > - > > #endif > > diff --git a/x86/eventinj.c b/x86/eventinj.c > > index 57c2a2d..84dfe71 100644 > > --- a/x86/eventinj.c > > +++ b/x86/eventinj.c > > @@ -16,11 +16,6 @@ static inline void io_delay(void) > > { > > } > > =20 > > -static inline void outl(int addr, int val) > > -{ > > - asm volatile ("outl %1, %w0" : : "d" (addr), "a" (val)); > > -} > > - > > void apic_self_ipi(u8 v) > > { > > apic_icr_write(APIC_DEST_SELF | APIC_DEST_PHYSICAL | APIC_DM_FIXE= D | > > @@ -32,7 +27,7 @@ void apic_self_nmi(void) > > apic_icr_write(APIC_DEST_PHYSICAL | APIC_DM_NMI | APIC_INT_ASSERT= , 0); > > } > > =20 > > -#define flush_phys_addr(__s) outl(0xe4, __s) > > +#define flush_phys_addr(__s) outl(__s, 0xe4) > > #define flush_stack() do { \ > > int __l; \ > > flush_phys_addr(virt_to_phys(&__l)); \ > > diff --git a/x86/hyperv.c b/x86/hyperv.c > > index 824773d..2511aa2 100644 > > --- a/x86/hyperv.c > > +++ b/x86/hyperv.c > > @@ -1,4 +1,5 @@ > > #include "hyperv.h" > > +#include "asm/io.h" > > =20 > > static void synic_ctl(u8 ctl, u8 vcpu_id, u8 sint) > > { > > diff --git a/x86/hyperv.h b/x86/hyperv.h > > index faf931b..434a933 100644 > > --- a/x86/hyperv.h > > +++ b/x86/hyperv.h > > @@ -3,7 +3,6 @@ > > =20 > > #include "libcflat.h" > > #include "processor.h" > > -#include "io.h" > > =20 > > #define HYPERV_CPUID_FEATURES 0x40000003 > > =20 > > diff --git a/x86/hyperv_stimer.c b/x86/hyperv_stimer.c > > index bf2e429..9a971ef 100644 > > --- a/x86/hyperv_stimer.c > > +++ b/x86/hyperv_stimer.c > > @@ -5,7 +5,6 @@ > > #include "vm.h" > > #include "apic.h" > > #include "desc.h" > > -#include "io.h" > > #include "smp.h" > > #include "atomic.h" > > #include "hyperv.h" > > diff --git a/x86/hyperv_synic.c b/x86/hyperv_synic.c > > index 6e08894..4bd07c3 100644 > > --- a/x86/hyperv_synic.c > > +++ b/x86/hyperv_synic.c > > @@ -5,7 +5,6 @@ > > #include "vm.h" > > #include "apic.h" > > #include "desc.h" > > -#include "io.h" > > #include "smp.h" > > #include "atomic.h" > > #include "hyperv.h" > > diff --git a/x86/init.c b/x86/init.c > > index 344dc1c..f47d671 100644 > > --- a/x86/init.c > > +++ b/x86/init.c > > @@ -1,6 +1,6 @@ > > #include "libcflat.h" > > #include "apic.h" > > -#include "io.h" > > +#include "asm/io.h" > > =20 > > #define KBD_CCMD_READ_OUTPORT 0xD0 /* read output port */ > > #define KBD_CCMD_WRITE_OUTPORT 0xD1 /* write output port */ > > diff --git a/x86/svm.c b/x86/svm.c > > index 934b2ae..401ff6c 100644 > > --- a/x86/svm.c > > +++ b/x86/svm.c > > @@ -6,7 +6,6 @@ > > #include "vm.h" > > #include "smp.h" > > #include "types.h" > > -#include "io.h" > > =20 > > /* for the nested page table*/ > > u64 *pml4e; > > diff --git a/x86/vmexit.c b/x86/vmexit.c > > index 9e04975..db7dbd8 100644 > > --- a/x86/vmexit.c > > +++ b/x86/vmexit.c > > @@ -6,7 +6,6 @@ > > #include "x86/vm.h" > > #include "x86/desc.h" > > #include "x86/acpi.h" > > -#include "x86/io.h" > > =20 > > struct test { > > void (*func)(void); > > diff --git a/x86/vmx.c b/x86/vmx.c > > index 6618008..411ed32 100644 > > --- a/x86/vmx.c > > +++ b/x86/vmx.c > > @@ -35,7 +35,6 @@ > > #include "vmx.h" > > #include "msr.h" > > #include "smp.h" > > -#include "io.h" > > =20 > > u64 *vmxon_region; > > struct vmcs *vmcs_root; > > diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c > > index 71c571c..e83c8a2 100644 > > --- a/x86/vmx_tests.c > > +++ b/x86/vmx_tests.c > > @@ -7,7 +7,6 @@ > > #include "msr.h" > > #include "processor.h" > > #include "vm.h" > > -#include "io.h" > > #include "fwcfg.h" > > #include "isr.h" > > #include "apic.h" > > --=20 > > 1.8.3.1 >=20 > Thanks, > drew