On Fri, Apr 29, 2016 at 01:38:05PM +0200, Alexander Gordeev wrote: > Cc: Andrew Jones <drjones@xxxxxxxxxx> > Cc: Thomas Huth <thuth@xxxxxxxxxx> > Cc: Radim Krčmář <rkrcmar@xxxxxxxxxx> > Signed-off-by: Alexander Gordeev <agordeev@xxxxxxxxxx> > --- > lib/x86/asm/io.h | 2 ++ > lib/x86/asm/page.h | 1 + > lib/x86/io.c | 15 ++++++++++++++- > x86/vmexit.c | 10 ++-------- > 4 files changed, 19 insertions(+), 9 deletions(-) > > diff --git a/lib/x86/asm/io.h b/lib/x86/asm/io.h > index 83387b5..2436822 100644 > --- a/lib/x86/asm/io.h > +++ b/lib/x86/asm/io.h > @@ -49,4 +49,6 @@ static inline void *phys_to_virt(unsigned long phys) > return (void *)phys; > } > > +void __iomem *ioremap(phys_addr_t phys_addr, size_t size); > + > #endif > diff --git a/lib/x86/asm/page.h b/lib/x86/asm/page.h > index 54f6471..db834ba 100644 > --- a/lib/x86/asm/page.h > +++ b/lib/x86/asm/page.h > @@ -7,6 +7,7 @@ > #else > #define LARGE_PAGE_SIZE (1024 * PAGE_SIZE) > #endif > +#define PAGE_MASK (~(PAGE_SIZE-1)) Hmm... I see two x86 unit tests have their own PAGE_MASK definitions (x86/vmx.h, x86/access.c). I agree it should be in asm/page.h instead, but looks like more cleaning is in order then... > > #define PTE_PRESENT (1ull << 0) > #define PTE_PSE (1ull << 7) > diff --git a/lib/x86/io.c b/lib/x86/io.c > index d396d42..9a84e6b 100644 > --- a/lib/x86/io.c > +++ b/lib/x86/io.c > @@ -1,6 +1,6 @@ > #include "libcflat.h" > +#include "vm.h" > #include "smp.h" > -#include "asm/io.h" Why remove this include? io.c uses stuff from asm/io.h. I wouldn't remove it just because vm.h also includes it. Also, I guess io.c should include asm/page.h now. > #ifndef USE_SERIAL > #define USE_SERIAL > #endif > @@ -81,3 +81,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 = phys_addr & PAGE_MASK; > + phys_addr_t off = phys_addr - base; > + ulong nr = (off + size + (PAGE_SIZE - 1)) / PAGE_SIZE; nit: I prefer nr = ALIGN(off + size, PAGE_SIZE) >> PAGE_SHIFT hmm, x86 doesn't have a PAGE_SHIFT yet. Should probably add that along with PAGE_MASK to asm/page.h > + 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 > > -- > To unsubscribe from this list: send the line "unsubscribe kvm" in > the body of a message to majordomo@xxxxxxxxxxxxxxx > More majordomo info at http://vger.kernel.org/majordomo-info.html -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html