From: Andrew Jones Subject: [kvm-unit-tests PATCH v3 4/8] x86: use common portio accessors from io.h Date: Mon, 18 Jan 2016 19:01:00 +0100 Message-ID: <1453140064-9040-5-git-send-email-drjones@redhat.com> References: <1453140064-9040-1-git-send-email-drjones@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: pbonzini@redhat.com, mst@redhat.com, agordeev@redhat.com, rkrcmar@redhat.com To: kvm@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:57360 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756111AbcARSBS (ORCPT ); Mon, 18 Jan 2016 13:01:18 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id 5086D8E3C0 for ; Mon, 18 Jan 2016 18:01:18 +0000 (UTC) In-Reply-To: <1453140064-9040-1-git-send-email-drjones@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: x86 code reinvents io*/out* in a few places. To prepare for a common pci driver use the common accessors from io.h in pci.c and vmexit.c. Now we use the correct order (value, port) for out* too. Signed-off-by: Andrew Jones Reviewed-by: Radim Kr=C4=8Dm=C3=A1=C5=99 --- lib/x86/pci.c | 14 ++------------ x86/vmexit.c | 40 ++++++---------------------------------- 2 files changed, 8 insertions(+), 46 deletions(-) diff --git a/lib/x86/pci.c b/lib/x86/pci.c index 231668a72101f..6aa6d70353127 100644 --- a/lib/x86/pci.c +++ b/lib/x86/pci.c @@ -1,21 +1,11 @@ #include #include "pci.h" +#include "io.h" =20 -static void outl(unsigned short port, unsigned val) -{ - asm volatile("outl %0, %w1" : : "a"(val), "Nd"(port)); -} - -static unsigned inl(unsigned short port) -{ - unsigned data; - asm volatile("inl %w1, %0" : "=3Da"(data) : "Nd"(port)); - return data; -} static uint32_t pci_config_read(pcidevaddr_t dev, uint8_t reg) { uint32_t index =3D reg | (dev << 8) | (0x1 << 31);=20 - outl(0xCF8, index); + outl(index, 0xCF8); return inl(0xCFC); } =20 diff --git a/x86/vmexit.c b/x86/vmexit.c index 1413454d9ccb6..e9f240872788a 100644 --- a/x86/vmexit.c +++ b/x86/vmexit.c @@ -6,6 +6,7 @@ #include "x86/desc.h" #include "x86/pci.h" #include "x86/acpi.h" +#include "x86/io.h" =20 struct test { void (*func)(void); @@ -15,35 +16,6 @@ struct test { bool (*next)(struct test *); }; =20 -static void outb(unsigned short port, unsigned val) -{ - asm volatile("outb %b0, %w1" : : "a"(val), "Nd"(port)); -} - -static void outw(unsigned short port, unsigned val) -{ - asm volatile("outw %w0, %w1" : : "a"(val), "Nd"(port)); -} - -static void outl(unsigned short port, unsigned val) -{ - asm volatile("outl %0, %w1" : : "a"(val), "Nd"(port)); -} - -static unsigned int inb(unsigned short port) -{ - unsigned int val; - asm volatile("xorl %0, %0; inb %w1, %b0" : "=3Da"(val) : "Nd"(port= )); - return val; -} - -static unsigned int inl(unsigned short port) -{ - unsigned int val; - asm volatile("inl %w1, %0" : "=3Da"(val) : "Nd"(port)); - return val; -} - #define GOAL (1ull << 30) =20 static int nr_cpus; @@ -123,7 +95,7 @@ static void inl_nop_kernel(void) =20 static void outl_elcr_kernel(void) { - outb(0x4d0, 0); + outb(0, 0x4d0); } =20 static void mov_dr(void) @@ -201,17 +173,17 @@ static void pci_mem_testl(void) =20 static void pci_io_testb(void) { - outb(pci_test.ioport, pci_test.data); + outb(pci_test.data, pci_test.ioport); } =20 static void pci_io_testw(void) { - outw(pci_test.ioport, pci_test.data); + outw(pci_test.data, pci_test.ioport); } =20 static void pci_io_testl(void) { - outl(pci_test.ioport, pci_test.data); + outl(pci_test.data, pci_test.ioport); } =20 static uint8_t ioreadb(unsigned long addr, bool io) @@ -236,7 +208,7 @@ static uint32_t ioreadl(unsigned long addr, bool io= ) static void iowriteb(unsigned long addr, uint8_t data, bool io) { if (io) { - outb(addr, data); + outb(data, addr); } else { *(volatile uint8_t *)addr =3D data; } --=20 2.4.3