From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alexander Gordeev Subject: [PATCH v2 8/9] io/x86: Factor out ioremap() Date: Wed, 27 Apr 2016 15:13:57 +0200 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: Alexander Gordeev , Andrew Jones , Thomas Huth , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= To: kvm@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:43342 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752490AbcD0NOO (ORCPT ); Wed, 27 Apr 2016 09:14:14 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (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 710947F0A7 for ; Wed, 27 Apr 2016 13:14:14 +0000 (UTC) In-Reply-To: Sender: kvm-owner@vger.kernel.org List-ID: 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 | 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)); } =20 +#define ioremap ioremap +void __iomem *ioremap(phys_addr_t phys_addr, size_t size); + #include =20 #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 =3D ALIGN(phys_addr, PAGE_SIZE); + phys_addr_t off =3D phys_addr - base; + ulong nr =3D ALIGN(off + size + (PAGE_SIZE - 1), PAGE_SIZE) / PAGE_SI= ZE; + void *page =3D 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 =3D 0, base, offset; - void *m; + unsigned long membar =3D 0; pcidevaddr_t pcidev; =20 smp_init(); @@ -394,12 +393,7 @@ int main(int ac, char **av) } if (pci_bar_is_memory(pcidev, i)) { membar =3D pci_bar_addr(pcidev, i); - base =3D membar & ~4095; - offset =3D membar - base; - m =3D alloc_vpages(1); - =09 - install_page((void *)read_cr3(), base, m); - pci_test.memaddr =3D m + offset; + pci_test.memaddr =3D ioremap(membar, PAGE_SIZE); } else { pci_test.iobar =3D pci_bar_addr(pcidev, i); } --=20 1.8.3.1