x86: Cleanup low-level arch code
Subsystems (2)
cover x86: Cleanup low-level arch code
Hi all,
This is an attempt to make mainly x86 IO code more consistent with other architectures. The series paves the way for the PCI update I sent earlier, but it also may be of interest by itself.
Thanks!
Alexander Gordeev (9):
Remove unused and unnecessary PHYS32 macro Move phys_addr_t type definition to lib/libcflat.h
x86: Introduce lib/x86/asm/page.h
x86: Introduce lib/x86/asm/io.h
x86: Introduce lib/x86/asm/barrier.h
x86: Optimize virt_to_phys() and phys_to_virt()
io: Introduce generic IO accessors
io: Make ioremap() prototype conform to Linux one io/x86: Factor out ioremap()
arm/selftest.c | 1 - lib/alloc.h | 7 ------- lib/arm/asm/page.h | 2 -- lib/arm/asm/setup.h | 1 - lib/arm/setup.c | 1 - lib/asm-generic/io.h | 48 ++++++++++++++++++++++++++++++++++++++++-- lib/libcflat.h | 3 +++ lib/powerpc/asm/setup.h | 1 - lib/x86/asm/barrier.h | 8 +++++++ lib/x86/asm/io.h | 56 +++++++++++++++++++++++++++++++++++++++++++++++++ lib/x86/asm/page.h | 30 ++++++++++++++++++++++++++ lib/x86/asm/pci.h | 2 +- lib/x86/io.c | 16 +++++++++++++- lib/x86/io.h | 40 ----------------------------------- lib/x86/smp.h | 4 ---- lib/x86/vm.c | 17 --------------- lib/x86/vm.h | 24 +-------------------- x86/eventinj.c | 7 +------ x86/hyperv.c | 1 + x86/hyperv.h | 1 - x86/hyperv_stimer.c | 1 - x86/hyperv_synic.c | 1 - x86/init.c | 2 +- x86/kvmclock.c | 1 + x86/svm.c | 1 - x86/vmexit.c | 11 ++-------- x86/vmx.c | 1 - x86/vmx_tests.c | 1 - 28 files changed, 166 insertions(+), 123 deletions(-) create mode 100644 lib/x86/asm/barrier.h create mode 100644 lib/x86/asm/io.h create mode 100644 lib/x86/asm/page.h delete mode 100644 lib/x86/io.h
Signature · 1 line
1.8.3.1
PATCH 1/9 Remove unused and unnecessary PHYS32 macro
--- lib/alloc.h | 4 ---- 1 file changed, 4 deletions(-)
lib/alloc.h +0 -4
@@ -58,11 +58,7 @@ static inline void *memalign(size_t alignment, size_t size)return alloc_ops->memalign (alignment, size); } -#ifdef PHYS32 -typedef u32 phys_addr_t ; -#else typedef u64 phys_addr_t ; -#endif #define INVALID_PHYS_ADDR (~(phys_addr_t)0)/*
Signature · 1 line
1.8.3.1
Re: [PATCH 1/9] Remove unused and unnecessary PHYS32 macro
Quoted 5 lines · Alexander Gordeev
Cc Andrew Jones <[email protected]>Cc Thomas Huth <[email protected]>Cc Radim Krčmář <[email protected]>Suggested-by Andrew Jones <[email protected]>Signed-off-by Alexander Gordeev <[email protected]>
Quoted 27 lines
--- lib/alloc.h | 4 ---- 1 file changed, 4 deletions(-)lib/alloc.h +0
-4@@ -58,11 +58,7 @@ static inline void *memalign(size_t alignment, size_t size)return alloc_ops->memalign (alignment, size); } -#ifdef PHYS32 -typedef u32 phys_addr_t ; -#else typedef u64 phys_addr_t ; -#endif #define INVALID_PHYS_ADDR (~(phys_addr_t)0)/* Signature · 6 lines
1.8.3.1 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 2/9 Move phys_addr_t type definition to lib/libcflat.h
In reply to Alexander GordeevThis change leads to removing '#include <alloc.h>'s from several places that only included alloc.h to get the typedef.
--- arm/selftest.c | 1 - lib/alloc.h | 3 --- lib/arm/asm/page.h | 2 -- lib/arm/asm/setup.h | 1 - lib/arm/setup.c | 1 - lib/libcflat.h | 3 +++ lib/powerpc/asm/setup.h | 1 - 7 files changed, 3 insertions(+), 9 deletions(-)
arm/selftest.c +0 -1
@@ -7,7 +7,6 @@*/ #include <libcflat.h> #include <util.h> -#include <alloc.h> #include <devicetree.h> #include <asm/setup.h> #include <asm/ptrace.h>
lib/alloc.h +0 -3
@@ -58,9 +58,6 @@ static inline void *memalign(size_t alignment, size_t size)return alloc_ops->memalign (alignment, size); } -typedef u64 phys_addr_t ; -#define INVALID_PHYS_ADDR (~(phys_addr_t)0) -/* * phys_alloc is a very simple allocator which allows physical memory * to be partitioned into regions until all memory is allocated.
lib/arm/asm/page.h +0 -2
@@ -16,8 +16,6 @@#define PAGE_ALIGN (addr) ALIGN(addr, PAGE_SIZE) -#include <alloc.h> -typedef u64 pteval_t ;typedef u64 pmdval_t ;typedef u64 pgdval_t ;
lib/arm/asm/setup.h +0 -1
@@ -6,7 +6,6 @@* This work is licensed under the terms of the GNU LGPL, version 2. */ #include <libcflat.h> -#include <alloc.h> /* phys_addr_t */ #include <asm/page.h> #include <asm/pgtable-hwdef.h>
lib/arm/setup.c +0 -1
@@ -13,7 +13,6 @@#include <libcflat.h> #include <libfdt/libfdt.h> #include <devicetree.h> -#include <alloc.h> #include <asm/thread_info.h> #include <asm/setup.h> #include <asm/page.h>
lib/libcflat.h +3 -0
@@ -60,6 +60,9 @@ typedef _Bool bool;#define PRIx64 __PRI64_PREFIX "x"#define PRIxPTR __PRIPTR_PREFIX "x" +typedef u64 phys_addr_t ; +#define INVALID_PHYS_ADDR (~(phys_addr_t)0) +extern void puts (const char *s);extern void exit (int code);extern void abort (void );
lib/powerpc/asm/setup.h +0 -1
@@ -6,7 +6,6 @@* This work is licensed under the terms of the GNU LGPL, version 2. */ #include <libcflat.h> -#include <alloc.h> /* phys_addr_t */ #define NR_CPUS 8/* arbitrarily set for now */ extern u32 cpus[NR_CPUS ];
Signature · 1 line
1.8.3.1
Re: [PATCH 2/9] Move phys_addr_t type definition to lib/libcflat.h
Quoted 35 lines · Alexander Gordeev
This change leads to removing '#include <alloc.h>'s from several places that only included
alloc.hto get the typedef.Cc Andrew Jones <[email protected]>Cc Thomas Huth <[email protected]>Cc Radim Krčmář <[email protected]>Suggested-by Andrew Jones <[email protected]>Signed-off-by Alexander Gordeev <[email protected]>--- arm/selftest.c | 1 - lib/alloc.h | 3 --- lib/arm/asm/page.h | 2 -- lib/arm/asm/setup.h | 1 - lib/arm/setup.c | 1 - lib/libcflat.h | 3 +++ lib/powerpc/asm/setup.h | 1 - 7 files changed, 3 insertions(+), 9 deletions(-)arm/selftest.c +0
-1@@ -7,7 +7,6 @@*/ #include <libcflat.h> #include <util.h> -#include <alloc.h> #include <devicetree.h> #include <asm/setup.h> #include <asm/ptrace.h> lib/alloc.h +0
-0
lib/alloc.h static inline void *memalign(size_t alignment, size_t size) · line 62
Quoted 5 lines
lib/alloc.h +0
-2@@ -58,9 +58,6 @@ static inline void *memalign(size_t alignment, size_t size)return alloc_ops->memalign (alignment, size); } -typedef u64 phys_addr_t ; -#define INVALID_PHYS_ADDR (~(phys_addr_t)0)
Moving the typedef is fine, but INVALID_PHYS_ADDR is an arbitrary address chosen by the phys-mem-alloc subsystem. In practice it's probably invalid for everything else too, but it should probably stay in alloc.h. I realize the naming isn't great, as it doesn't convey the connection to alloc, but I'm not sure we want to rename it now.
Quoted 70 lines
lib/alloc.h +0
-1-/* * phys_alloc is a very simple allocator which allows physical memory * to be partitioned into regions until all memory is allocated. lib/arm/asm/page.h +0
-2@@ -16,8 +16,6 @@#define PAGE_ALIGN (addr) ALIGN(addr, PAGE_SIZE) -#include <alloc.h> -typedef u64 pteval_t ;typedef u64 pmdval_t ;typedef u64 pgdval_t ;lib/arm/asm/setup.h +0
-1@@ -6,7 +6,6 @@* This work is licensed under the terms of the GNU LGPL, version 2. */ #include <libcflat.h> -#include <alloc.h> /* phys_addr_t */ #include <asm/page.h> #include <asm/pgtable-hwdef.h> lib/arm/setup.c +0
-1@@ -13,7 +13,6 @@#include <libcflat.h> #include <libfdt/libfdt.h> #include <devicetree.h> -#include <alloc.h> #include <asm/thread_info.h> #include <asm/setup.h> #include <asm/page.h> lib/libcflat.h +3
-0@@ -60,6 +60,9 @@ typedef _Bool bool;#define PRIx64 __PRI64_PREFIX "x"#define PRIxPTR __PRIPTR_PREFIX "x" +typedef u64 phys_addr_t ; +#define INVALID_PHYS_ADDR (~(phys_addr_t)0) +extern void puts (const char *s);extern void exit (int code);extern void abort (void );lib/powerpc/asm/setup.h +0
-1@@ -6,7 +6,6 @@* This work is licensed under the terms of the GNU LGPL, version 2. */ #include <libcflat.h> -#include <alloc.h> /* phys_addr_t */ #define NR_CPUS 8/* arbitrarily set for now */ extern u32 cpus[NR_CPUS ];Signature · 1 line
1.8.3.1
Thanks,
drew
PATCH 3/9 x86: Introduce lib/x86/asm/page.h
In reply to Alexander GordeevMake x86 consistent with other architectures and put memory page specific defines to lib/x86/asm/page.h
--- lib/x86/asm/page.h | 27 +++++++++++++++++++++++++++ lib/x86/vm.c | 17 ----------------- lib/x86/vm.h | 14 +------------- 3 files changed, 28 insertions(+), 30 deletions(-) create mode 100644 lib/x86/asm/page.h
lib/x86/asm/page.h new file +27 -0
@@ -0,0 +1,27 @@ +#ifndef _ASM_X86_PAGE_H_ +#define _ASM_X86_PAGE_H_ + +#define PAGE_SIZE 4096ul +#ifdef __x86_64__ +#define LARGE_PAGE_SIZE (512 * PAGE_SIZE) +#else +#define LARGE_PAGE_SIZE (1024 * PAGE_SIZE) +#endif + +#define PTE_PRESENT (1ull << 0) +#define PTE_PSE (1ull << 7) +#define PTE_WRITE (1ull << 1) +#define PTE_USER (1ull << 2) +#define PTE_ADDR (0xffffffffff000ull) + +#ifdef __x86_64__ +#define PAGE_LEVEL 4 +#define PGDIR_WIDTH 9 +#define PGDIR_MASK 511 +#else +#define PAGE_LEVEL 2 +#define PGDIR_WIDTH 10 +#define PGDIR_MASK 1023 +#endif + +#endif
lib/x86/vm.c +0 -17
@@ -2,13 +2,6 @@#include "vm.h" #include "libcflat.h" -#define PAGE_SIZE 4096ul -#ifdef __x86_64__ -#define LARGE_PAGE_SIZE (512 * PAGE_SIZE) -#else -#define LARGE_PAGE_SIZE (1024 * PAGE_SIZE) -#endif -static void *free =0 ;static void *vfree_top =0 ;
@@ -44,16 +37,6 @@ void free_page(void *page)extern char edata;static unsigned long end_of_memory; -#ifdef __x86_64__ -#define PAGE_LEVEL 4 -#define PGDIR_WIDTH 9 -#define PGDIR_MASK 511 -#else -#define PAGE_LEVEL 2 -#define PGDIR_WIDTH 10 -#define PGDIR_MASK 1023 -#endif - unsigned long *install_pte(unsigned long *cr3, int pte_level, void *virt,
lib/x86/vm.h +1 -13
@@ -2,19 +2,7 @@#define VM_H #include "processor.h" - -#define PAGE_SIZE 4096ul -#ifdef __x86_64__ -#define LARGE_PAGE_SIZE (512 * PAGE_SIZE) -#else -#define LARGE_PAGE_SIZE (1024 * PAGE_SIZE) -#endif - -#define PTE_PRESENT (1ull << 0) -#define PTE_PSE (1ull << 7) -#define PTE_WRITE (1ull << 1) -#define PTE_USER (1ull << 2) -#define PTE_ADDR (0xffffffffff000ull) +#include "asm/page.h" void setup_vm ();
Signature · 1 line
1.8.3.1
PATCH 4/9 x86: Introduce lib/x86/asm/io.h
In reply to Alexander GordeevMake x86 consistent with other architectures and put IO specific defines to lib/x86/asm/io.h
--- lib/x86/asm/io.h | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/x86/asm/pci.h | 2 +- lib/x86/io.c | 2 +- lib/x86/io.h | 40 ---------------------------------------- lib/x86/vm.h | 12 +----------- x86/eventinj.c | 7 +------ x86/hyperv.c | 1 + x86/hyperv.h | 1 - x86/hyperv_stimer.c | 1 - x86/hyperv_synic.c | 1 - x86/init.c | 2 +- x86/svm.c | 1 - x86/vmexit.c | 1 - x86/vmx.c | 1 - x86/vmx_tests.c | 1 - 15 files changed, 58 insertions(+), 67 deletions(-) create mode 100644 lib/x86/asm/io.h delete mode 100644 lib/x86/io.h
lib/x86/asm/io.h new file +52 -0
@@ -0,0 +1,52 @@ +#ifndef _ASM_X86_IO_H_ +#define _ASM_X86_IO_H_ + +#include "asm/page.h" + +static inline unsigned char inb (unsigned short port) +{ +unsigned char value; + asmvolatile ("inb %w1, %0" :"=a" (value) :"Nd" (port)); +return value; +} + +static inline unsigned short inw (unsigned short port) +{ +unsigned short value; + asmvolatile ("inw %w1, %0" :"=a" (value) :"Nd" (port)); +return value; +} + +static inline unsigned int inl (unsigned short port) +{ +unsigned int value; + asmvolatile ("inl %w1, %0" :"=a" (value) :"Nd" (port)); +return value; +} + +static inline void outb (unsigned char value,unsigned short port) +{ + asmvolatile ("outb %b0, %w1" : :"a" (value),"Nd" (port)); +} + +static inline void outw (unsigned short value,unsigned short port) +{ + asmvolatile ("outw %w0, %w1" : :"a" (value),"Nd" (port)); +} + +static inline void outl (unsigned int value,unsigned short port) +{ + asmvolatile ("outl %0, %w1" : :"a" (value),"Nd" (port)); +} + +static inline unsigned long virt_to_phys (const void *virt) +{ +return (unsigned long )virt; +} + +static inline void *phys_to_virt (unsigned long phys) +{ +return (void *)phys; +} + +#endif
lib/x86/asm/pci.h +1 -1
@@ -7,7 +7,7 @@*/ #include "libcflat.h" #include "pci.h" -#include "x86/io.h" +#include "x86/asm/io.h" static inline uint32_t pci_config_read (pcidevaddr_t dev,uint8_t reg) {
lib/x86/io.c +1 -1
@@ -1,6 +1,6 @@#include "libcflat.h" #include "smp.h" -#include "io.h" +#include "asm/io.h" #ifndef USE_SERIAL #define USE_SERIAL #endif
lib/x86/io.h deleted +0 -40
@@ -1,40 +0,0 @@ -#ifndef IO_H -#define IO_H - -static inline unsigned char inb (unsigned short port) -{ -unsigned char value; - asmvolatile ("inb %w1, %0" :"=a" (value) :"Nd" (port)); -return value; -} - -static inline unsigned short inw (unsigned short port) -{ -unsigned short value; - asmvolatile ("inw %w1, %0" :"=a" (value) :"Nd" (port)); -return value; -} - -static inline unsigned int inl (unsigned short port) -{ -unsigned int value; - asmvolatile ("inl %w1, %0" :"=a" (value) :"Nd" (port)); -return value; -} - -static inline void outb (unsigned char value,unsigned short port) -{ - asmvolatile ("outb %b0, %w1" : :"a" (value),"Nd" (port)); -} - -static inline void outw (unsigned short value,unsigned short port) -{ - asmvolatile ("outw %w0, %w1" : :"a" (value),"Nd" (port)); -} - -static inline void outl (unsigned int value,unsigned short port) -{ - asmvolatile ("outl %0, %w1" : :"a" (value),"Nd" (port)); -} - -#endif
lib/x86/vm.h +1 -11
@@ -2,7 +2,7 @@#define VM_H #include "processor.h" -#include "asm/page.h" +#include "asm/io.h" void setup_vm ();
@@ -27,14 +27,4 @@ unsigned long *install_large_page(unsigned long *cr3,unsigned long phys, void *virt);unsigned long *install_page (unsigned long *cr3,unsigned long phys,void *virt); -static inline unsigned long virt_to_phys (const void *virt) -{ -return (unsigned long )virt; -} - -static inline void *phys_to_virt (unsigned long phys) -{ -return (void *)phys; -} -#endif
x86/eventinj.c +1 -6
@@ -16,11 +16,6 @@ static inline void io_delay(void) { } -static inline void outl (int addr,int val) -{ - asmvolatile ("outl %1, %w0" : :"d" (addr),"a" (val)); -} -void apic_self_ipi (u8 v) { apic_icr_write(APIC_DEST_SELF | APIC_DEST_PHYSICAL | APIC_DM_FIXED |
@@ -32,7 +27,7 @@ void apic_self_nmi(void)apic_icr_write (APIC_DEST_PHYSICAL |APIC_DM_NMI |APIC_INT_ASSERT ,0 ); } -#define flush_phys_addr (__s) outl(0xe4, __s) +#define flush_phys_addr (__s) outl(__s, 0xe4)#define flush_stack () do { \ int __l; \ flush_phys_addr(virt_to_phys(&__l)); \
x86/hyperv.c +1 -0
@@ -1,4 +1,5 @@#include "hyperv.h" +#include "asm/io.h" static void synic_ctl (u8 ctl,u8 vcpu_id,u8 sint) {
x86/hyperv.h +0 -1
@@ -3,7 +3,6 @@#include "libcflat.h" #include "processor.h" -#include "io.h" #define HYPERV_CPUID_FEATURES 0x40000003
x86/hyperv_stimer.c +0 -1
@@ -5,7 +5,6 @@#include "vm.h" #include "apic.h" #include "desc.h" -#include "io.h" #include "smp.h" #include "atomic.h" #include "hyperv.h"
x86/hyperv_synic.c +0 -1
@@ -5,7 +5,6 @@#include "vm.h" #include "apic.h" #include "desc.h" -#include "io.h" #include "smp.h" #include "atomic.h" #include "hyperv.h"
x86/init.c +1 -1
@@ -1,6 +1,6 @@#include "libcflat.h" #include "apic.h" -#include "io.h" +#include "asm/io.h" #define KBD_CCMD_READ_OUTPORT 0xD0/* read output port */ #define KBD_CCMD_WRITE_OUTPORT 0xD1/* write output port */
x86/svm.c +0 -1
@@ -6,7 +6,6 @@#include "vm.h" #include "smp.h" #include "types.h" -#include "io.h" /* for the nested page table*/ u64 *pml4e;
x86/vmexit.c +0 -1
@@ -6,7 +6,6 @@#include "x86/vm.h" #include "x86/desc.h" #include "x86/acpi.h" -#include "x86/io.h" struct test {void (*func)(void );
x86/vmx.c +0 -1
@@ -35,7 +35,6 @@#include "vmx.h" #include "msr.h" #include "smp.h" -#include "io.h" u64 *vmxon_region;struct vmcs *vmcs_root;
x86/vmx_tests.c +0 -1
@@ -7,7 +7,6 @@#include "msr.h" #include "processor.h" #include "vm.h" -#include "io.h" #include "fwcfg.h" #include "isr.h" #include "apic.h"
Signature · 1 line
1.8.3.1
PATCH 5/9 x86: Introduce lib/x86/asm/barrier.h
In reply to Alexander GordeevMake x86 consistent with other architectures and put memory barrier defines to lib/x86/asm/barrier.h
--- lib/x86/asm/barrier.h | 8 ++++++++ lib/x86/asm/io.h | 1 + lib/x86/smp.h | 4 ---- x86/kvmclock.c | 1 + 4 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 lib/x86/asm/barrier.h
lib/x86/asm/barrier.h new file +8 -0
@@ -0,0 +1,8 @@ +#ifndef _ASM_X86_BARRIER_H_ +#define _ASM_X86_BARRIER_H_ + +#define mb () asm volatile("mfence":::"memory") +#define rmb () asm volatile("lfence":::"memory") +#define wmb () asm volatile("sfence" ::: "memory") + +#endif
lib/x86/asm/io.h +1 -0
@@ -2,6 +2,7 @@#define _ASM_X86_IO_H_#include "asm/page.h" +#include "asm/barrier.h" static inline unsigned char inb (unsigned short port) {
lib/x86/smp.h +0 -4
@@ -2,10 +2,6 @@#define __SMP_H#include <asm/spinlock.h> -#define mb () asm volatile("mfence":::"memory") -#define rmb () asm volatile("lfence":::"memory") -#define wmb () asm volatile("sfence" ::: "memory") -void smp_init (void );int cpu_count (void );
x86/kvmclock.c +1 -0
@@ -3,6 +3,7 @@#include "atomic.h" #include "processor.h" #include "kvmclock.h" +#include "asm/barrier.h" #define unlikely (x) __builtin_expect(!!(x), 0)#define likely (x) __builtin_expect(!!(x), 1)
Signature · 1 line
1.8.3.1
PATCH 6/9 x86: Optimize virt_to_phys() and phys_to_virt()
In reply to Alexander GordeevMake use of generic implementations and remove x86 specific virt_to_phys() and phys_to_virt() functions.
--- lib/asm-generic/io.h | 2 ++ lib/x86/asm/io.h | 10 +--------- lib/x86/asm/page.h | 3 +++ 3 files changed, 6 insertions(+), 9 deletions(-)
lib/asm-generic/io.h +2 -0
@@ -165,7 +165,9 @@ static inline unsigned long virt_to_phys(volatile void *address) {return __pa ((unsigned long )address); } +#endif +#ifndef phys_to_virtstatic inline void *phys_to_virt (unsigned long address) {return __va (address);
lib/x86/asm/io.h +1 -9
@@ -40,14 +40,6 @@ static inline void outl(unsigned int value, unsigned short port) asm volatile("outl %0, %w1" : : "a"(value), "Nd"(port)); } -static inline unsigned long virt_to_phys (const void *virt) -{ -return (unsigned long )virt; -} - -static inline void *phys_to_virt (unsigned long phys) -{ -return (void *)phys; -} +#include <asm-generic/io.h> #endif
lib/x86/asm/page.h +3 -0
@@ -24,4 +24,7 @@#define PGDIR_MASK 1023#endif +#define __va (x) ((void *)((unsigned long) (x))) +#define __pa (x) ((unsigned long) (x)) +#endif
Signature · 1 line
1.8.3.1
PATCH 7/9 io: Introduce generic IO accessors
In reply to Alexander Gordeev--- lib/asm-generic/io.h | 42 ++++++++++++++++++++++++++++++++++++++++++ lib/x86/asm/io.h | 30 ++++++++++++++++++------------ 2 files changed, 60 insertions(+), 12 deletions(-)
lib/asm-generic/io.h +42 -0
@@ -152,6 +152,48 @@ static inline u64 __bswap64(u64 x)#define writeq (b, addr) \ ({ wmb(); __raw_writeq(cpu_to_le64(b), addr); }) +#ifndef inb +static inline uint8_t inb (unsigned long port) +{ +return readb ((const volatile void __iomem *)port); +} +#endif + +#ifndef inw +static inline uint16_t inw (unsigned long port) +{ +return readw ((const volatile void __iomem *)port); +} +#endif + +#ifndef inl +static inline uint32_t inl (unsigned long port) +{ +return readl ((const volatile void __iomem *)port); +} +#endif + +#ifndef outb +static inline void outb (uint8_t value,unsigned long port) +{ +writeb (value, (volatile void __iomem *)port); +} +#endif + +#ifndef outw +static inline void outw (uint16_t value,unsigned long port) +{ +writew (value, (volatile void __iomem *)port); +} +#endif + +#ifndef outl +static inline void outl (uint32_t value,unsigned long port) +{ +writel (value, (volatile void __iomem *)port); +} +#endif +#ifndef ioremap static inline void *ioremap(u64 phys_addr, size_t size __unused) {
lib/x86/asm/io.h +18 -12
@@ -4,40 +4,46 @@#include "asm/page.h" #include "asm/barrier.h" -static inline unsigned char inb (unsigned short port) +#define inb inb +static inline uint8_t inb (unsigned long port) {unsigned char value; - asmvolatile ("inb %w1, %0" :"=a" (value) :"Nd" (port)); + asmvolatile ("inb %w1, %0" :"=a" (value) :"Nd" ((unsigned short )port));return value; } -static inline unsigned short inw (unsigned short port) +#define inw inw +static inline uint16_t inw (unsigned long port) {unsigned short value; - asmvolatile ("inw %w1, %0" :"=a" (value) :"Nd" (port)); + asmvolatile ("inw %w1, %0" :"=a" (value) :"Nd" ((unsigned short )port));return value; } -static inline unsigned int inl (unsigned short port) +#define inl inl +static inline uint32_t inl (unsigned long port) {unsigned int value; - asmvolatile ("inl %w1, %0" :"=a" (value) :"Nd" (port)); + asmvolatile ("inl %w1, %0" :"=a" (value) :"Nd" ((unsigned short )port));return value; } -static inline void outb (unsigned char value,unsigned short port) +#define outb outb +static inline void outb (uint8_t value,unsigned long port) { - asmvolatile ("outb %b0, %w1" : :"a" (value),"Nd" (port)); + asmvolatile ("outb %b0, %w1" : :"a" (value),"Nd" ((unsigned short )port)); } -static inline void outw (unsigned short value,unsigned short port) +#define outw outw +static inline void outw (uint16_t value,unsigned long port) { - asmvolatile ("outw %w0, %w1" : :"a" (value),"Nd" (port)); + asmvolatile ("outw %w0, %w1" : :"a" (value),"Nd" ((unsigned short )port)); } -static inline void outl (unsigned int value,unsigned short port) +#define outl outl +static inline void outl (uint32_t value,unsigned long port) { - asmvolatile ("outl %0, %w1" : :"a" (value),"Nd" (port)); + asmvolatile ("outl %0, %w1" : :"a" (value),"Nd" ((unsigned short )port)); }#include <asm-generic/io.h>
Signature · 1 line
1.8.3.1
Re: [PATCH 7/9] io: Introduce generic IO accessors
Quoted 128 lines · Alexander Gordeev
Cc Andrew Jones <[email protected]>Cc Thomas Huth <[email protected]>Cc Radim Krčmář <[email protected]>Signed-off-by Alexander Gordeev <[email protected]>--- lib/asm-generic/io.h | 42 ++++++++++++++++++++++++++++++++++++++++++ lib/x86/asm/io.h | 30 ++++++++++++++++++------------ 2 files changed, 60 insertions(+), 12 deletions(-)lib/asm-generic/io.h +42
-0@@ -152,6 +152,48 @@ static inline u64 __bswap64(u64 x)#define writeq (b, addr) \ ({ wmb(); __raw_writeq(cpu_to_le64(b), addr); }) +#ifndef inb +static inline uint8_t inb (unsigned long port) +{ +return readb ((const volatile void __iomem *)port); +} +#endif + +#ifndef inw +static inline uint16_t inw (unsigned long port) +{ +return readw ((const volatile void __iomem *)port); +} +#endif + +#ifndef inl +static inline uint32_t inl (unsigned long port) +{ +return readl ((const volatile void __iomem *)port); +} +#endif + +#ifndef outb +static inline void outb (uint8_t value,unsigned long port) +{ +writeb (value, (volatile void __iomem *)port); +} +#endif + +#ifndef outw +static inline void outw (uint16_t value,unsigned long port) +{ +writew (value, (volatile void __iomem *)port); +} +#endif + +#ifndef outl +static inline void outl (uint32_t value,unsigned long port) +{ +writel (value, (volatile void __iomem *)port); +} +#endif +#ifndef ioremap static inline void *ioremap(u64 phys_addr, size_t size __unused) {lib/x86/asm/io.h +18
-12@@ -4,40 +4,46 @@#include "asm/page.h" #include "asm/barrier.h" -static inline unsigned char inb (unsigned short port) +#define inb inb +static inline uint8_t inb (unsigned long port) {unsigned char value; - asmvolatile ("inb %w1, %0" :"=a" (value) :"Nd" (port)); + asmvolatile ("inb %w1, %0" :"=a" (value) :"Nd" ((unsigned short )port));return value; } -static inline unsigned short inw (unsigned short port) +#define inw inw +static inline uint16_t inw (unsigned long port) {unsigned short value; - asmvolatile ("inw %w1, %0" :"=a" (value) :"Nd" (port)); + asmvolatile ("inw %w1, %0" :"=a" (value) :"Nd" ((unsigned short )port));return value; } -static inline unsigned int inl (unsigned short port) +#define inl inl +static inline uint32_t inl (unsigned long port) {unsigned int value; - asmvolatile ("inl %w1, %0" :"=a" (value) :"Nd" (port)); + asmvolatile ("inl %w1, %0" :"=a" (value) :"Nd" ((unsigned short )port));return value; } -static inline void outb (unsigned char value,unsigned short port) +#define outb outb +static inline void outb (uint8_t value,unsigned long port) { - asmvolatile ("outb %b0, %w1" : :"a" (value),"Nd" (port)); + asmvolatile ("outb %b0, %w1" : :"a" (value),"Nd" ((unsigned short )port)); } -static inline void outw (unsigned short value,unsigned short port) +#define outw outw +static inline void outw (uint16_t value,unsigned long port) { - asmvolatile ("outw %w0, %w1" : :"a" (value),"Nd" (port)); + asmvolatile ("outw %w0, %w1" : :"a" (value),"Nd" ((unsigned short )port)); } -static inline void outl (unsigned int value,unsigned short port) +#define outl outl +static inline void outl (uint32_t value,unsigned long port) { - asmvolatile ("outl %0, %w1" : :"a" (value),"Nd" (port)); + asmvolatile ("outl %0, %w1" : :"a" (value),"Nd" ((unsigned short )port)); }#include <asm-generic/io.h> Signature · 1 line
1.8.3.1
I'm not sure we need this patch, and I know Radim didn't like it when I've proposed it in the past :-)
drew
Re: [PATCH 7/9] io: Introduce generic IO accessors
Quoted 125 lines · Andrew Jones
Quoted 124 lines · Alexander Gordeev
Cc Andrew Jones <[email protected]>Cc Thomas Huth <[email protected]>Cc Radim Krčmář <[email protected]>Signed-off-by Alexander Gordeev <[email protected]>--- lib/asm-generic/io.h | 42 ++++++++++++++++++++++++++++++++++++++++++ lib/x86/asm/io.h | 30 ++++++++++++++++++------------ 2 files changed, 60 insertions(+), 12 deletions(-)lib/asm-generic/io.h +42
-0@@ -152,6 +152,48 @@ static inline u64 __bswap64(u64 x)#define writeq (b, addr) \ ({ wmb(); __raw_writeq(cpu_to_le64(b), addr); }) +#ifndef inb +static inline uint8_t inb (unsigned long port) +{ +return readb ((const volatile void __iomem *)port); +} +#endif + +#ifndef inw +static inline uint16_t inw (unsigned long port) +{ +return readw ((const volatile void __iomem *)port); +} +#endif + +#ifndef inl +static inline uint32_t inl (unsigned long port) +{ +return readl ((const volatile void __iomem *)port); +} +#endif + +#ifndef outb +static inline void outb (uint8_t value,unsigned long port) +{ +writeb (value, (volatile void __iomem *)port); +} +#endif + +#ifndef outw +static inline void outw (uint16_t value,unsigned long port) +{ +writew (value, (volatile void __iomem *)port); +} +#endif + +#ifndef outl +static inline void outl (uint32_t value,unsigned long port) +{ +writel (value, (volatile void __iomem *)port); +} +#endif +#ifndef ioremap static inline void *ioremap(u64 phys_addr, size_t size __unused) {lib/x86/asm/io.h +18
-12@@ -4,40 +4,46 @@#include "asm/page.h" #include "asm/barrier.h" -static inline unsigned char inb (unsigned short port) +#define inb inb +static inline uint8_t inb (unsigned long port) {unsigned char value; - asmvolatile ("inb %w1, %0" :"=a" (value) :"Nd" (port)); + asmvolatile ("inb %w1, %0" :"=a" (value) :"Nd" ((unsigned short )port));return value; } -static inline unsigned short inw (unsigned short port) +#define inw inw +static inline uint16_t inw (unsigned long port) {unsigned short value; - asmvolatile ("inw %w1, %0" :"=a" (value) :"Nd" (port)); + asmvolatile ("inw %w1, %0" :"=a" (value) :"Nd" ((unsigned short )port));return value; } -static inline unsigned int inl (unsigned short port) +#define inl inl +static inline uint32_t inl (unsigned long port) {unsigned int value; - asmvolatile ("inl %w1, %0" :"=a" (value) :"Nd" (port)); + asmvolatile ("inl %w1, %0" :"=a" (value) :"Nd" ((unsigned short )port));return value; } -static inline void outb (unsigned char value,unsigned short port) +#define outb outb +static inline void outb (uint8_t value,unsigned long port) { - asmvolatile ("outb %b0, %w1" : :"a" (value),"Nd" (port)); + asmvolatile ("outb %b0, %w1" : :"a" (value),"Nd" ((unsigned short )port)); } -static inline void outw (unsigned short value,unsigned short port) +#define outw outw +static inline void outw (uint16_t value,unsigned long port) { - asmvolatile ("outw %w0, %w1" : :"a" (value),"Nd" (port)); + asmvolatile ("outw %w0, %w1" : :"a" (value),"Nd" ((unsigned short )port)); } -static inline void outl (unsigned int value,unsigned short port) +#define outl outl +static inline void outl (uint32_t value,unsigned long port) { - asmvolatile ("outl %0, %w1" : :"a" (value),"Nd" (port)); + asmvolatile ("outl %0, %w1" : :"a" (value),"Nd" ((unsigned short )port)); }
Quoted 7 lines
Quoted 4 lines
lib/x86/asm/io.h +0
-0#include <asm-generic/io.h> Signature · 1 line
1.8.3.1I'm not sure we need this patch, and I know Radim didn't like it when I've proposed it in the past :-)
It is not required for this series as there are no consumers, indeed. But it will be needed for the PCI series anyway :)
Quoted 1 line
drew
PATCH 8/9 io: Make ioremap() prototype conform to Linux one
In reply to Alexander GordeevThis update also adds missing __iomem specificator which has been used by existing IO accessors.
--- lib/asm-generic/io.h | 4 ++-- lib/x86/asm/io.h | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-)
lib/asm-generic/io.h +2 -2
@@ -195,10 +195,10 @@ static inline void outl(uint32_t value, unsigned long port)#endif #ifndef ioremap -static inline void *ioremap(u64 phys_addr, size_t size __unused) +static inline void __iomem *ioremap(phys_addr_t phys_addr, size_t size __unused) {assert (sizeof (long ) ==8 || !(phys_addr >>32 )); -return (void *)(unsigned long )phys_addr; +return (void __iomem *)phys_addr; }#endif
lib/x86/asm/io.h +2 -0
@@ -4,6 +4,8 @@#include "asm/page.h" #include "asm/barrier.h" +#define __iomem +#define inb inbstatic inline uint8_t inb (unsigned long port) {
Signature · 1 line
1.8.3.1
Re: [PATCH 8/9] io: Make ioremap() prototype conform to Linux one
Quoted 17 lines · Alexander Gordeev
This update also adds missing
__iomemspecificator which has been used by existing IO accessors.Cc Andrew Jones <[email protected]>Cc Thomas Huth <[email protected]>Cc Radim Krčmář <[email protected]>Signed-off-by Alexander Gordeev <[email protected]>--- lib/asm-generic/io.h | 4 ++-- lib/x86/asm/io.h | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-)lib/asm-generic/io.h +0
-0
lib/asm-generic/io.h static inline void outl(uint32_t value, unsigned long port) · line 201
Quoted 9 lines
lib/asm-generic/io.h +2
-2@@ -195,10 +195,10 @@ static inline void outl(uint32_t value, unsigned long port)#endif #ifndef ioremap -static inline void *ioremap(u64 phys_addr, size_t size __unused) +static inline void __iomem *ioremap(phys_addr_t phys_addr, size_t size __unused) {assert (sizeof (long ) ==8 || !(phys_addr >>32 )); -return (void *)(unsigned long )phys_addr; +return (void __iomem *)phys_addr;
Now that you've removed the unsigned long cast, what happens on 32bit builds here? Doesn't it fail to compile due to a bad cast?
Quoted 23 lines
lib/asm-generic/io.h +0
-0}#endif lib/x86/asm/io.h +2
-0@@ -4,6 +4,8 @@#include "asm/page.h" #include "asm/barrier.h" +#define __iomem +#define inb inbstatic inline uint8_t inb (unsigned long port) {Signature · 6 lines
1.8.3.1 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 8/9] io: Make ioremap() prototype conform to Linux one
Quoted 20 lines · Andrew Jones
Quoted 19 lines · Alexander Gordeev
This update also adds missing
__iomemspecificator which has been used by existing IO accessors.Cc Andrew Jones <[email protected]>Cc Thomas Huth <[email protected]>Cc Radim Krčmář <[email protected]>Signed-off-by Alexander Gordeev <[email protected]>--- lib/asm-generic/io.h | 4 ++-- lib/x86/asm/io.h | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-)lib/asm-generic/io.h +0
-0@@ -195,10 +195,10 @@ static inline void outl(uint32_t value, unsigned long port)#endif
Quoted 10 lines
lib/asm-generic/io.h static inline void outl(uint32_t value, unsigned long port) · line 201
Quoted 7 lines
lib/asm-generic/io.h +2
-2#ifndef ioremap -static inline void *ioremap(u64 phys_addr, size_t size __unused) +static inline void __iomem *ioremap(phys_addr_t phys_addr, size_t size __unused) {assert (sizeof (long ) ==8 || !(phys_addr >>32 )); -return (void *)(unsigned long )phys_addr; +return (void __iomem *)phys_addr;Now that you've removed the unsigned long cast, what happens on 32bit builds here? Doesn't it fail to compile due to a bad cast?
Indeed, it does :/
Quoted 23 lines
Quoted 23 lines
lib/asm-generic/io.h +0
-0}#endif lib/x86/asm/io.h +2
-0@@ -4,6 +4,8 @@#include "asm/page.h" #include "asm/barrier.h" +#define __iomem +#define inb inbstatic inline uint8_t inb (unsigned long port) {Signature · 6 lines
1.8.3.1 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 9/9 io/x86: Factor out ioremap()
In reply to Alexander Gordeev--- lib/x86/asm/io.h | 3 +++ lib/x86/io.c | 14 ++++++++++++++ x86/vmexit.c | 10 ++-------- 3 files changed, 19 insertions(+), 8 deletions(-)
lib/x86/asm/io.h +3 -0
@@ -48,6 +48,9 @@ static inline void outl(uint32_t value, unsigned long port) asm volatile("outl %0, %w1" : : "a"(value), "Nd"((unsigned short)port)); } +#define ioremap ioremap +void __iomem *ioremap (phys_addr_t phys_addr,size_t size); +#include <asm-generic/io.h> #endif
lib/x86/io.c +14 -0
@@ -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) asmvolatile ("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; +} +
x86/vmexit.c +2 -8
@@ -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); }
Signature · 1 line
1.8.3.1
Quoted 13 lines · Alexander Gordeev
Hi all,
This is an attempt to make mainly x86 IO code more consistent with other architectures. The series paves the way for the PCI update I sent earlier, but it also may be of interest by itself.
Thanks!
Cc Andrew Jones <[email protected]>Cc Thomas Huth <[email protected]>Cc Radim Krčmář <[email protected]>
Quoted 10 lines
Alexander Gordeev (9):
Remove unused and unnecessary PHYS32 macro Movephys_addr_ttype definition tolib/libcflat.h
x86: Introducelib/x86/asm/page.h
x86: Introducelib/x86/asm/io.h
x86: Introducelib/x86/asm/barrier.h
x86: Optimizevirt_to_phys()andphys_to_virt()
io: Introduce generic IO accessors
io: Makeioremap()prototype conform to Linux one io/x86: Factor outioremap()
All the patches look pretty good to me (minus a few comments I had). Let's see what x86 people say.
drew
Quoted 42 lines
arm/selftest.c | 1 - lib/alloc.h | 7 ------- lib/arm/asm/page.h | 2 -- lib/arm/asm/setup.h | 1 - lib/arm/setup.c | 1 - lib/asm-generic/io.h | 48 ++++++++++++++++++++++++++++++++++++++++-- lib/libcflat.h | 3 +++ lib/powerpc/asm/setup.h | 1 - lib/x86/asm/barrier.h | 8 +++++++ lib/x86/asm/io.h | 56 +++++++++++++++++++++++++++++++++++++++++++++++++ lib/x86/asm/page.h | 30 ++++++++++++++++++++++++++ lib/x86/asm/pci.h | 2 +- lib/x86/io.c | 16 +++++++++++++- lib/x86/io.h | 40 ----------------------------------- lib/x86/smp.h | 4 ---- lib/x86/vm.c | 17 --------------- lib/x86/vm.h | 24 +-------------------- x86/eventinj.c | 7 +------ x86/hyperv.c | 1 + x86/hyperv.h | 1 - x86/hyperv_stimer.c | 1 - x86/hyperv_synic.c | 1 - x86/init.c | 2 +- x86/kvmclock.c | 1 + x86/svm.c | 1 - x86/vmexit.c | 11 ++-------- x86/vmx.c | 1 - x86/vmx_tests.c | 1 - 28 files changed, 166 insertions(+), 123 deletions(-) create mode 100644 lib/x86/asm/barrier.h create mode 100644 lib/x86/asm/io.h create mode 100644 lib/x86/asm/page.h delete mode 100644 lib/x86/io.hSignature · 6 lines
1.8.3.1 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html