All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Jones <drjones@redhat.com>
To: kvm@vger.kernel.org
Cc: pbonzini@redhat.com, mst@redhat.com, agordeev@redhat.com,
	rkrcmar@redhat.com
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	[thread overview]
Message-ID: <1453140064-9040-5-git-send-email-drjones@redhat.com> (raw)
In-Reply-To: <1453140064-9040-1-git-send-email-drjones@redhat.com>

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 <drjones@redhat.com>
Reviewed-by: Radim Krčmář <rkrcmar@redhat.com>
---
 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 <linux/pci_regs.h>
 #include "pci.h"
+#include "io.h"
 
-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" : "=a"(data) : "Nd"(port));
-    return data;
-}
 static uint32_t pci_config_read(pcidevaddr_t dev, uint8_t reg)
 {
     uint32_t index = reg | (dev << 8) | (0x1 << 31); 
-    outl(0xCF8, index);
+    outl(index, 0xCF8);
     return inl(0xCFC);
 }
 
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"
 
 struct test {
 	void (*func)(void);
@@ -15,35 +16,6 @@ struct test {
 	bool (*next)(struct test *);
 };
 
-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" : "=a"(val) : "Nd"(port));
-    return val;
-}
-
-static unsigned int inl(unsigned short port)
-{
-    unsigned int val;
-    asm volatile("inl %w1, %0" : "=a"(val) : "Nd"(port));
-    return val;
-}
-
 #define GOAL (1ull << 30)
 
 static int nr_cpus;
@@ -123,7 +95,7 @@ static void inl_nop_kernel(void)
 
 static void outl_elcr_kernel(void)
 {
-    outb(0x4d0, 0);
+    outb(0, 0x4d0);
 }
 
 static void mov_dr(void)
@@ -201,17 +173,17 @@ static void pci_mem_testl(void)
 
 static void pci_io_testb(void)
 {
-	outb(pci_test.ioport, pci_test.data);
+	outb(pci_test.data, pci_test.ioport);
 }
 
 static void pci_io_testw(void)
 {
-	outw(pci_test.ioport, pci_test.data);
+	outw(pci_test.data, pci_test.ioport);
 }
 
 static void pci_io_testl(void)
 {
-	outl(pci_test.ioport, pci_test.data);
+	outl(pci_test.data, pci_test.ioport);
 }
 
 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 = data;
 	}
-- 
2.4.3


  parent reply	other threads:[~2016-01-18 18:01 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-18 18:00 [kvm-unit-tests PATCH v3 0/8] share pci-testdev with the framework Andrew Jones
2016-01-18 18:00 ` [kvm-unit-tests PATCH v3 1/8] lib: add linux dir for kernel uapi headers Andrew Jones
2016-01-18 18:00 ` [kvm-unit-tests PATCH v3 2/8] Revert "arm/arm64: import include/uapi/linux/psci.h" Andrew Jones
2016-01-18 18:00 ` [kvm-unit-tests PATCH v3 3/8] lib/linux: import pci_regs.h Andrew Jones
2016-01-18 18:01 ` Andrew Jones [this message]
2016-01-18 18:01 ` [kvm-unit-tests PATCH v3 5/8] x86: pci.h: remove useless include Andrew Jones
2016-01-18 18:01 ` [kvm-unit-tests PATCH v3 6/8] x86: move x86/pci to the common lib Andrew Jones
2016-01-18 18:01 ` [kvm-unit-tests PATCH v3 7/8] x86: share pci-testdev hdr in " Andrew Jones
2016-01-18 18:01 ` [kvm-unit-tests PATCH v3 8/8] lib/pci: make PCIDEVADDR_INVALID truly invalid Andrew Jones
2016-01-19 14:12 ` [kvm-unit-tests PATCH v3 0/8] share pci-testdev with the framework Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1453140064-9040-5-git-send-email-drjones@redhat.com \
    --to=drjones@redhat.com \
    --cc=agordeev@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=rkrcmar@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.