All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexander Gordeev <agordeev@redhat.com>
To: kvm@vger.kernel.org
Cc: "Alexander Gordeev" <agordeev@redhat.com>,
	"Andrew Jones" <drjones@redhat.com>,
	"Thomas Huth" <thuth@redhat.com>,
	"Radim Krčmář" <rkrcmar@redhat.com>
Subject: [PATCH v2 8/9] io/x86: Factor out ioremap()
Date: Wed, 27 Apr 2016 15:13:57 +0200	[thread overview]
Message-ID: <f5b91dac5f23e7d79404c16543ab0860e7778d29.1461762419.git.agordeev@redhat.com> (raw)
In-Reply-To: <cover.1461762418.git.agordeev@redhat.com>

Cc: Andrew Jones <drjones@redhat.com>
Cc: Thomas Huth <thuth@redhat.com>
Cc: Radim Krčmář <rkrcmar@redhat.com>
Signed-off-by: Alexander Gordeev <agordeev@redhat.com>
---
 lib/x86/asm/io.h |  3 +++
 lib/x86/io.c     | 14 ++++++++++++++
 x86/vmexit.c     | 10 ++--------
 3 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/lib/x86/asm/io.h b/lib/x86/asm/io.h
index c37450f..d8c5dbd 100644
--- a/lib/x86/asm/io.h
+++ b/lib/x86/asm/io.h
@@ -42,6 +42,9 @@ static inline void outl(unsigned int value, unsigned short port)
     asm volatile("outl %0, %w1" : : "a"(value), "Nd"(port));
 }
 
+#define ioremap ioremap
+void __iomem *ioremap(phys_addr_t phys_addr, size_t size);
+
 #include <asm-generic/io.h>
 
 #endif
diff --git a/lib/x86/io.c b/lib/x86/io.c
index d396d42..a699509 100644
--- a/lib/x86/io.c
+++ b/lib/x86/io.c
@@ -1,4 +1,5 @@
 #include "libcflat.h"
+#include "vm.h"
 #include "smp.h"
 #include "asm/io.h"
 #ifndef USE_SERIAL
@@ -81,3 +82,16 @@ void exit(int code)
         asm volatile("out %0, %1" : : "a"(code), "d"((short)0xf4));
 #endif
 }
+
+void __iomem *ioremap(phys_addr_t phys_addr, size_t size)
+{
+	phys_addr_t base = ALIGN(phys_addr, PAGE_SIZE);
+	phys_addr_t off = phys_addr - base;
+	ulong nr = ALIGN(off + size + (PAGE_SIZE - 1), PAGE_SIZE) / PAGE_SIZE;
+	void *page = alloc_vpages(nr);
+
+	install_page((void *)read_cr3(), base, page);
+
+	return page + off;
+}
+
diff --git a/x86/vmexit.c b/x86/vmexit.c
index db7dbd8..c2e1e49 100644
--- a/x86/vmexit.c
+++ b/x86/vmexit.c
@@ -371,8 +371,7 @@ int main(int ac, char **av)
 {
 	struct fadt_descriptor_rev1 *fadt;
 	int i;
-	unsigned long membar = 0, base, offset;
-	void *m;
+	unsigned long membar = 0;
 	pcidevaddr_t pcidev;
 
 	smp_init();
@@ -394,12 +393,7 @@ int main(int ac, char **av)
 			}
 			if (pci_bar_is_memory(pcidev, i)) {
 				membar = pci_bar_addr(pcidev, i);
-				base = membar & ~4095;
-				offset = membar - base;
-				m = alloc_vpages(1);
-				
-				install_page((void *)read_cr3(), base, m);
-				pci_test.memaddr = m + offset;
+				pci_test.memaddr = ioremap(membar, PAGE_SIZE);
 			} else {
 				pci_test.iobar = pci_bar_addr(pcidev, i);
 			}
-- 
1.8.3.1


  parent reply	other threads:[~2016-04-27 13:14 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-27 13:13 [PATCH v2 0/9] Cleanup low-level arch code Alexander Gordeev
2016-04-27 13:13 ` [PATCH v2 1/9] Remove unused and unnecessary PHYS32 macro Alexander Gordeev
2016-04-27 13:13 ` [PATCH v2 2/9] Move phys_addr_t type definition to lib/libcflat.h Alexander Gordeev
2016-04-27 13:42   ` Andrew Jones
2016-04-27 13:13 ` [PATCH v2 3/9] x86: Introduce lib/x86/asm/page.h Alexander Gordeev
2016-04-27 13:45   ` Andrew Jones
2016-04-27 13:13 ` [PATCH v2 4/9] x86: Introduce lib/x86/asm/io.h Alexander Gordeev
2016-04-27 13:46   ` Andrew Jones
2016-04-27 16:23     ` Alexander Gordeev
2016-04-28  9:24       ` Alexander Gordeev
2016-04-28 11:13         ` Andrew Jones
2016-04-27 13:51   ` Andrew Jones
2016-04-27 13:13 ` [PATCH v2 5/9] x86: Introduce lib/x86/asm/barrier.h Alexander Gordeev
2016-04-27 13:52   ` Andrew Jones
2016-04-27 16:26     ` Alexander Gordeev
2016-04-28 16:23       ` Alexander Gordeev
2016-04-28 17:00         ` Andrew Jones
2016-04-27 13:13 ` [PATCH v2 6/9] x86: Optimize virt_to_phys() and phys_to_virt() Alexander Gordeev
2016-04-27 13:58   ` Andrew Jones
2016-04-27 16:54     ` Alexander Gordeev
2016-04-27 18:19       ` Andrew Jones
2016-04-27 13:13 ` [PATCH v2 7/9] io: Make ioremap() prototype conform to Linux one Alexander Gordeev
2016-04-27 13:59   ` Andrew Jones
2016-04-27 13:13 ` Alexander Gordeev [this message]
2016-04-27 14:11   ` [PATCH v2 8/9] io/x86: Factor out ioremap() Andrew Jones
2016-04-27 13:13 ` [PATCH v2 9/9] io: Disable memory re-ordering for generic memory barriers Alexander Gordeev
2016-04-27 14:14   ` Andrew Jones
2016-04-27 13:34 ` [PATCH v2 0/9] Cleanup low-level arch code Andrew Jones

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=f5b91dac5f23e7d79404c16543ab0860e7778d29.1461762419.git.agordeev@redhat.com \
    --to=agordeev@redhat.com \
    --cc=drjones@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=rkrcmar@redhat.com \
    --cc=thuth@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.