ppc: Enable full Xen build
v5 cover ppc: Enable full Xen build
Hello all,
This patch series performs all of the additions necessary to drop the build overrides for PPC and enable the full Xen build. Except in cases where compatibile implementations already exist (e.g. atomic.h and bitops.h), the newly added definitions are simple, unimplemented stubs that just call BUG_ON("unimplemented").
Thanks,
Shawn
Shawn Anastasio (5):
xen/ppc: Implement atomic.h
xen/ppc: Implement bitops.h
xen/ppc: Define minimal stub headers required for full build xen/ppc: Add stub function and symbol definitions xen/ppc: Enable full Xen build
xen/arch/ppc/Kconfig | 1 + xen/arch/ppc/Makefile | 17 +- xen/arch/ppc/arch.mk | 3 - xen/arch/ppc/include/asm/Makefile | 2 + xen/arch/ppc/include/asm/altp2m.h | 25 ++ xen/arch/ppc/include/asm/atomic.h | 385 +++++++++++++++++++++++ xen/arch/ppc/include/asm/bitops.h | 332 ++++++++++++++++++- xen/arch/ppc/include/asm/bug.h | 9 + xen/arch/ppc/include/asm/cache.h | 2 + xen/arch/ppc/include/asm/config.h | 10 + xen/arch/ppc/include/asm/cpufeature.h | 10 + xen/arch/ppc/include/asm/current.h | 43 +++ xen/arch/ppc/include/asm/delay.h | 12 + xen/arch/ppc/include/asm/device.h | 53 ++++ xen/arch/ppc/include/asm/div64.h | 14 + xen/arch/ppc/include/asm/domain.h | 47 +++ xen/arch/ppc/include/asm/event.h | 36 +++ xen/arch/ppc/include/asm/flushtlb.h | 24 ++ xen/arch/ppc/include/asm/grant_table.h | 5 + xen/arch/ppc/include/asm/guest_access.h | 68 ++++ xen/arch/ppc/include/asm/guest_atomics.h | 23 ++ xen/arch/ppc/include/asm/hardirq.h | 19 ++ xen/arch/ppc/include/asm/hypercall.h | 5 + xen/arch/ppc/include/asm/io.h | 16 + xen/arch/ppc/include/asm/iocap.h | 8 + xen/arch/ppc/include/asm/iommu.h | 8 + xen/arch/ppc/include/asm/irq.h | 33 ++ xen/arch/ppc/include/asm/mem_access.h | 5 + xen/arch/ppc/include/asm/memory.h | 14 + xen/arch/ppc/include/asm/mm.h | 243 +++++++++++++- xen/arch/ppc/include/asm/monitor.h | 43 +++ xen/arch/ppc/include/asm/nospec.h | 15 + xen/arch/ppc/include/asm/numa.h | 26 ++ xen/arch/ppc/include/asm/p2m.h | 95 ++++++ xen/arch/ppc/include/asm/page.h | 18 ++ xen/arch/ppc/include/asm/paging.h | 7 + xen/arch/ppc/include/asm/pci.h | 7 + xen/arch/ppc/include/asm/percpu.h | 24 ++ xen/arch/ppc/include/asm/processor.h | 10 + xen/arch/ppc/include/asm/random.h | 9 + xen/arch/ppc/include/asm/setup.h | 6 + xen/arch/ppc/include/asm/smp.h | 18 ++ xen/arch/ppc/include/asm/softirq.h | 8 + xen/arch/ppc/include/asm/spinlock.h | 15 + xen/arch/ppc/include/asm/system.h | 219 ++++++++++++- xen/arch/ppc/include/asm/time.h | 23 ++ xen/arch/ppc/include/asm/xenoprof.h | 0 xen/arch/ppc/mm-radix.c | 44 ++- xen/arch/ppc/setup.c | 8 + xen/arch/ppc/stubs.c | 339 ++++++++++++++++++++ xen/arch/ppc/tlb-radix.c | 2 +- xen/include/public/hvm/save.h | 2 + xen/include/public/pmu.h | 2 + xen/include/public/xen.h | 2 + 54 files changed, 2403 insertions(+), 11 deletions(-) create mode 100644 xen/arch/ppc/include/asm/Makefile create mode 100644 xen/arch/ppc/include/asm/altp2m.h create mode 100644 xen/arch/ppc/include/asm/atomic.h create mode 100644 xen/arch/ppc/include/asm/cpufeature.h create mode 100644 xen/arch/ppc/include/asm/current.h create mode 100644 xen/arch/ppc/include/asm/delay.h create mode 100644 xen/arch/ppc/include/asm/device.h create mode 100644 xen/arch/ppc/include/asm/div64.h create mode 100644 xen/arch/ppc/include/asm/domain.h create mode 100644 xen/arch/ppc/include/asm/event.h create mode 100644 xen/arch/ppc/include/asm/flushtlb.h create mode 100644 xen/arch/ppc/include/asm/grant_table.h create mode 100644 xen/arch/ppc/include/asm/guest_access.h create mode 100644 xen/arch/ppc/include/asm/guest_atomics.h create mode 100644 xen/arch/ppc/include/asm/hardirq.h create mode 100644 xen/arch/ppc/include/asm/hypercall.h create mode 100644 xen/arch/ppc/include/asm/io.h create mode 100644 xen/arch/ppc/include/asm/iocap.h create mode 100644 xen/arch/ppc/include/asm/iommu.h create mode 100644 xen/arch/ppc/include/asm/irq.h create mode 100644 xen/arch/ppc/include/asm/mem_access.h create mode 100644 xen/arch/ppc/include/asm/memory.h create mode 100644 xen/arch/ppc/include/asm/monitor.h create mode 100644 xen/arch/ppc/include/asm/nospec.h create mode 100644 xen/arch/ppc/include/asm/numa.h create mode 100644 xen/arch/ppc/include/asm/p2m.h create mode 100644 xen/arch/ppc/include/asm/paging.h create mode 100644 xen/arch/ppc/include/asm/pci.h create mode 100644 xen/arch/ppc/include/asm/percpu.h create mode 100644 xen/arch/ppc/include/asm/random.h create mode 100644 xen/arch/ppc/include/asm/setup.h create mode 100644 xen/arch/ppc/include/asm/smp.h create mode 100644 xen/arch/ppc/include/asm/softirq.h create mode 100644 xen/arch/ppc/include/asm/spinlock.h create mode 100644 xen/arch/ppc/include/asm/time.h create mode 100644 xen/arch/ppc/include/asm/xenoprof.h create mode 100644 xen/arch/ppc/stubs.c
--
2.30.2
PATCH v5 1/5 xen/ppc: Implement atomic.h
Implement atomic.h for PPC, based off of the original Xen 3.2 implementation. This implementation depends on some functions that are not yet defined (notably __cmpxchg), so it can't yet be used.
---
v5: No changes.
v4:
- Clarify dependency on __cmpxchg which doesn't get implemented until future patch
- Drop !CONFIG_SMP case for PPC_ATOMIC_{ENTRY,EXIT}_BARRIER macro definitions
- Add missing newlines to inline asm instructions preceeding PPC_ATOMIC_EXIT_BARRIER. This was only discovered by the change to drop the !CONFIG_SMP definitions of those macros.
- Fix line wrapping in atomic_compareandswap
- Fix formatting of arch_cmpxchg macro
v3:
- Drop full copyright text headers
- Drop unnecessary spaces after casts
- const-ize write_atomic_size
- Don't use GNU 0-length array extension in read_atomic
- Use "+m" asm constraint instead of separate "=m" and "m"
- Fix line-continuing backslash formatting in arch_cmpxchg
v2:
- Fix style of asm block constraints to include required spaces
- Fix macro local variable naming (use trailing underscore instead of leading)
- Drop unnecessary parens in __atomic_add_unless
xen/arch/ppc/include/asm/atomic.h | 385 ++++++++++++++++++++++++++++++ xen/arch/ppc/include/asm/memory.h | 14 ++ 2 files changed, 399 insertions(+) create mode 100644 xen/arch/ppc/include/asm/atomic.h create mode 100644 xen/arch/ppc/include/asm/memory.h
xen/arch/ppc/include/asm/atomic.h new file +385 -0
@@ -0,0 +1,385 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* PowerPC64 atomic operations +* +* Copyright (C) 2001 Paul Mackerras <[email protected]>, IBM +* Copyright (C) 2001 Anton Blanchard <[email protected]>, IBM +* Copyright Raptor Engineering LLC +*/ + +#ifndef _ASM_PPC64_ATOMIC_H_ +#define _ASM_PPC64_ATOMIC_H_ + +#include <xen/atomic.h> + +#include <asm/memory.h> + +static inline int atomic_read (const atomic_t *v) +{ +return *(volatile int *)&v->counter; +} + +static inline int _atomic_read (atomic_t v) +{ +return v.counter; +} + +static inline void atomic_set (atomic_t *v,int i) +{ + v->counter = i; +} + +static inline void _atomic_set (atomic_t *v,int i) +{ + v->counter = i; +} + +void __bad_atomic_read (const volatile void *p,void *res); +void __bad_atomic_size (void ); + +#define build_atomic_read (name, insn, type) \ + static inline type name(const volatile type *addr) \ + { \ + type ret; \ + asm volatile ( insn "%U1%X1 %0,%1" : "=r" (ret) : "m<>" (*addr) ); \ + return ret; \ + } + +#define build_atomic_write (name, insn, type) \ + static inline void name(volatile type *addr, type val) \ + { \ + asm volatile ( insn "%U0%X0 %1,%0" : "=m<>" (*addr) : "r" (val) ); \ + } + +#define build_add_sized (name, ldinsn, stinsn, type) \ + static inline void name(volatile type *addr, type val) \ + { \ + type t; \ + asm volatile ( "1: " ldinsn " %0,0,%3\n" \ + "add%I2 %0,%0,%2\n" \ + stinsn " %0,0,%3 \n" \ + "bne- 1b\n" \ + : "=&r" (t), "+m" (*addr) \ + : "r" (val), "r" (addr) \ + : "cc" ); \ + } + +build_atomic_read(read_u8_atomic, "lbz", uint8_t) +build_atomic_read(read_u16_atomic, "lhz", uint16_t) +build_atomic_read(read_u32_atomic, "lwz", uint32_t) +build_atomic_read(read_u64_atomic, "ldz", uint64_t) + +build_atomic_write(write_u8_atomic, "stb", uint8_t) +build_atomic_write(write_u16_atomic, "sth", uint16_t) +build_atomic_write(write_u32_atomic, "stw", uint32_t) +build_atomic_write(write_u64_atomic, "std", uint64_t) + +build_add_sized(add_u8_sized, "lbarx", "stbcx.",uint8_t) +build_add_sized(add_u16_sized, "lharx", "sthcx.", uint16_t) +build_add_sized(add_u32_sized, "lwarx", "stwcx.", uint32_t) + +#undef build_atomic_read +#undef build_atomic_write +#undef build_add_sized + +static always_inline void read_atomic_size(const volatile void *p, void *res, +unsigned int size) +{ +ASSERT (IS_ALIGNED ((vaddr_t )p, size)); +switch ( size ) + { +case 1 : + *(uint8_t *)res =read_u8_atomic (p); +break ; +case 2 : + *(uint16_t *)res =read_u16_atomic (p); +break ; +case 4 : + *(uint32_t *)res =read_u32_atomic (p); +break ; +case 8 : + *(uint64_t *)res =read_u64_atomic (p); +break ; +default : +__bad_atomic_read (p, res); +break ; + } +} + +static always_inline void write_atomic_size(volatile void *p, const void *val, +unsigned int size) +{ +ASSERT (IS_ALIGNED ((vaddr_t )p, size)); +switch ( size ) + { +case 1 : +write_u8_atomic (p, *(const uint8_t *)val); +break ; +case 2 : +write_u16_atomic (p, *(const uint16_t *)val); +break ; +case 4 : +write_u32_atomic (p, *(const uint32_t *)val); +break ; +case 8 : +write_u64_atomic (p, *(const uint64_t *)val); +break ; +default : +__bad_atomic_size (); +break ; + } +} + +#define read_atomic (p) \ + ({ \ + union { \ + typeof(*(p)) val; \ + char c[sizeof(*(p))]; \ + } x_; \ + read_atomic_size(p, x_.c, sizeof(*(p))); \ + x_.val; \ + }) + +#define write_atomic (p, x) \ + do \ + { \ + typeof(*(p)) x_ = (x); \ + write_atomic_size(p, &x_, sizeof(*(p))); \ + } while ( 0 ) + +#define add_sized (p, x) \ + ({ \ + typeof(*(p)) x_ = (x); \ + switch ( sizeof(*(p)) ) \ + { \ + case 1: \ + add_u8_sized((uint8_t *)(p), x_); \ + break; \ + case 2: \ + add_u16_sized((uint16_t *)(p), x_); \ + break; \ + case 4: \ + add_u32_sized((uint32_t *)(p), x_); \ + break; \ + default: \ + __bad_atomic_size(); \ + break; \ + } \ + }) + +static inline void atomic_add (int a,atomic_t *v) +{ +int t; + + asmvolatile ("1: lwarx %0,0,%3\n" +"add %0,%2,%0\n" +"stwcx. %0,0,%3\n" +"bne- 1b" + :"=&r" (t),"+m" (v->counter) + :"r" (a),"r" (&v->counter) + :"cc" ); +} + +static inline int atomic_add_return (int a,atomic_t *v) +{ +int t; + + asmvolatile (PPC_ATOMIC_ENTRY_BARRIER +"1: lwarx %0,0,%2\n" +"add %0,%1,%0\n" +"stwcx. %0,0,%2\n" +"bne- 1b\n" +PPC_ATOMIC_EXIT_BARRIER + :"=&r" (t) + :"r" (a),"r" (&v->counter) + :"cc" ,"memory" ); + +return t; +} + +static inline void atomic_sub (int a,atomic_t *v) +{ +int t; + + asmvolatile ("1: lwarx %0,0,%3\n" +"subf %0,%2,%0\n" +"stwcx. %0,0,%3\n" +"bne- 1b" + :"=&r" (t),"+m" (v->counter) + :"r" (a),"r" (&v->counter) + :"cc" ); +} + +static inline int atomic_sub_return (int a,atomic_t *v) +{ +int t; + + asmvolatile (PPC_ATOMIC_ENTRY_BARRIER +"1: lwarx %0,0,%2\n" +"subf %0,%1,%0\n" +"stwcx. %0,0,%2\n" +"bne- 1b\n" +PPC_ATOMIC_EXIT_BARRIER + :"=&r" (t) + :"r" (a),"r" (&v->counter) + :"cc" ,"memory" ); + +return t; +} + +static inline void atomic_inc (atomic_t *v) +{ +int t; + + asmvolatile ("1: lwarx %0,0,%2\n" +"addic %0,%0,1\n" +"stwcx. %0,0,%2\n" +"bne- 1b" + :"=&r" (t),"+m" (v->counter) + :"r" (&v->counter) + :"cc" ); +} + +static inline int atomic_inc_return (atomic_t *v) +{ +int t; + + asmvolatile (PPC_ATOMIC_ENTRY_BARRIER +"1: lwarx %0,0,%1\n" +"addic %0,%0,1\n" +"stwcx. %0,0,%1\n" +"bne- 1b\n" +PPC_ATOMIC_EXIT_BARRIER + :"=&r" (t) + :"r" (&v->counter) + :"cc" ,"memory" ); + +return t; +} + +static inline void atomic_dec (atomic_t *v) +{ +int t; + + asmvolatile ("1: lwarx %0,0,%2\n" +"addic %0,%0,-1\n" +"stwcx. %0,0,%2\n" +"bne- 1b" + :"=&r" (t),"+m" (v->counter) + :"r" (&v->counter) + :"cc" ); +} + +static inline int atomic_dec_return (atomic_t *v) +{ +int t; + + asmvolatile (PPC_ATOMIC_ENTRY_BARRIER +"1: lwarx %0,0,%1\n" +"addic %0,%0,-1\n" +"stwcx. %0,0,%1\n" +"bne- 1b\n" +PPC_ATOMIC_EXIT_BARRIER + :"=&r" (t) + :"r" (&v->counter) + :"cc" ,"memory" ); + +return t; +} + +/* +* Atomically test *v and decrement if it is greater than 0. +* The function returns the old value of *v minus 1. +*/ +static inline int atomic_dec_if_positive (atomic_t *v) +{ +int t; + + asmvolatile (PPC_ATOMIC_ENTRY_BARRIER +"1: lwarx %0,0,%1 # atomic_dec_if_positive\n" +"addic. %0,%0,-1\n" +"blt- 2f\n" +"stwcx. %0,0,%1\n" +"bne- 1b\n" +PPC_ATOMIC_EXIT_BARRIER +"2:" + :"=&r" (t) + :"r" (&v->counter) + :"cc" ,"memory" ); + +return t; +} + +static inline atomic_t atomic_compareandswap (atomic_t old,atomic_t new, +atomic_t *v) +{ +atomic_t rc; + rc.counter =__cmpxchg (&v->counter, old.counter, new.counter, +sizeof (v->counter)); +return rc; +} + +#define arch_cmpxchg (ptr, o, n) \ + ({ \ + __typeof__(*(ptr)) o_ = (o); \ + __typeof__(*(ptr)) n_ = (n); \ + (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)o_, \ + (unsigned long)n_, sizeof(*(ptr))); \ + }) + +static inline int atomic_cmpxchg (atomic_t *v,int old,int new) +{ +return arch_cmpxchg (&v->counter, old, new); +} + +#define ATOMIC_OP (op, insn, suffix, sign) \ + static inline void atomic_##op(int a, atomic_t *v) \ + { \ + int t; \ + asm volatile ( "1: lwarx %0,0,%3\n" \ + insn "%I2" suffix " %0,%0,%2\n" \ + "stwcx. %0,0,%3 \n" \ + "bne- 1b\n" \ + : "=&r" (t), "+m" (v->counter) \ + : "r" #sign (a), "r" (&v->counter) \ + : "cc" ); \ + } + +ATOMIC_OP(and, "and", ".", K) + +static inline int atomic_sub_and_test (int i,atomic_t *v) +{ +return atomic_sub_return (i, v) ==0 ; +} + +static inline int atomic_inc_and_test (atomic_t *v) +{ +return atomic_add_return (1 , v) ==0 ; +} + +static inline int atomic_dec_and_test (atomic_t *v) +{ +return atomic_sub_return (1 , v) ==0 ; +} + +static inline int atomic_add_negative (int i,atomic_t *v) +{ +return atomic_add_return (i, v) <0 ; +} + +static inline int __atomic_add_unless (atomic_t *v,int a,int u) +{ +int c, old; + + c =atomic_read (v); +while (c != u && (old =atomic_cmpxchg (v, c, c + a)) != c) + c = old; +return c; +} + +static inline int atomic_add_unless (atomic_t *v,int a,int u) +{ +return __atomic_add_unless (v, a, u); +} + +#endif /* _ASM_PPC64_ATOMIC_H_ */
xen/arch/ppc/include/asm/memory.h new file +14 -0
@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* Copyright (C) IBM Corp. 2005 +* +* Authors: Jimi Xenidis <[email protected]> +*/ + +#ifndef _ASM_MEMORY_H_ +#define _ASM_MEMORY_H_ + +#define PPC_ATOMIC_ENTRY_BARRIER "sync\n" +#define PPC_ATOMIC_EXIT_BARRIER "sync\n" + +#endif
--
2.30.2
PATCH v5 2/5 xen/ppc: Implement bitops.h
In reply to Shawn AnastasioImplement bitops.h, based on Linux's implementation as of commit 5321d1b1afb9a17302c6cec79f0cbf823eb0d3fc. Though it is based off of Linux's implementation, this code diverges significantly in a number of ways:
- Bitmap entries changed to 32-bit words to match X86 and Arm on Xen
- PPC32-specific code paths dropped
- Formatting completely re-done to more closely line up with Xen. Including 4 space indentation.
- Use GCC's __builtin_popcount* for hweight* implementation
---
v5:
- Switch lingering ulong bitop parameters/return values to uint.
v4:
- Mention __builtin_popcount impelmentation of hweight* in message
- Change type of BITOP_MASK expression from unsigned long to unsigned int
- Fix remaining underscore-prefixed macro params/vars
- Fix line wrapping in test_and_clear_bit{,s}
- Change type of test_and_clear_bits' pointer parameter from void * to unsigned int *. This was already done for other functions but missed here.
- De-macroize test_and_set_bits.
- Fix formatting of ffs{,l} macro's unary operators
- Drop extra blank in ffz() macro definition
v3:
- Fix style of inline asm blocks.
- Fix underscore-prefixed macro parameters/variables
- Use __builtin_popcount for hweight* implementation
- Update C functions to use proper Xen coding style
v2:
- Clarify changes from Linux implementation in commit message
- Use PPC_ATOMIC_{ENTRY,EXIT}_BARRIER macros from <asm/memory.h> instead of hardcoded "sync" instructions in inline assembly blocks.
- Fix macro line-continuing backslash spacing
- Fix hard-tab usage in find_*_bit C functions.
xen/arch/ppc/include/asm/bitops.h | 332 +++++++++++++++++++++++++++++- 1 file changed, 329 insertions(+), 3 deletions(-)
xen/arch/ppc/include/asm/bitops.h +329 -3
@@ -1,9 +1,335 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* Adapted from Linux's arch/powerpc/include/asm/bitops.h. +* +* Merged version by David Gibson <[email protected]>. +* Based on ppc64 versions by: Dave Engebretsen, Todd Inglett, Don +* Reed, Pat McCarthy, Peter Bergner, Anton Blanchard. They +* originally took it from the ppc32 code. +*/ #ifndef _ASM_PPC_BITOPS_H#define _ASM_PPC_BITOPS_H +#include <asm/memory.h> + +#define __set_bit (n, p) set_bit(n, p) +#define __clear_bit (n, p) clear_bit(n, p) + +#define BITOP_BITS_PER_WORD 32 +#define BITOP_MASK (nr) (1U << ((nr) % BITOP_BITS_PER_WORD)) +#define BITOP_WORD (nr) ((nr) / BITOP_BITS_PER_WORD) +#define BITS_PER_BYTE 8 +/* PPC bit number conversion */ -#define PPC_BITLSHIFT (be) (BITS_PER_LONG - 1 - (be)) -#define PPC_BIT (bit) (1UL << PPC_BITLSHIFT(bit)) -#define PPC_BITMASK (bs, be) ((PPC_BIT(bs) - PPC_BIT(be)) | PPC_BIT(bs)) +#define PPC_BITLSHIFT (be) (BITS_PER_LONG - 1 - (be)) +#define PPC_BIT (bit) (1UL << PPC_BITLSHIFT(bit)) +#define PPC_BITMASK (bs, be) ((PPC_BIT(bs) - PPC_BIT(be)) | PPC_BIT(bs)) + +/* Macro for generating the ***_bits() functions */ +#define DEFINE_BITOP (fn, op, prefix) \ +static inline void fn(unsigned int mask, \ + volatile unsigned int *p_) \ +{ \ + unsigned int old; \ + unsigned int *p = (unsigned int *)p_; \ + asm volatile ( prefix \ + "1: lwarx %0,0,%3,0\n" \ + #op "%I2 %0,%0,%2\n" \ + "stwcx. %0,0,%3\n" \ + "bne- 1b\n" \ + : "=&r" (old), "+m" (*p) \ + : "rK" (mask), "r" (p) \ + : "cc", "memory" ); \ +} + +DEFINE_BITOP(set_bits, or, "") +DEFINE_BITOP(change_bits, xor, "") + +#define DEFINE_CLROP (fn, prefix) \ +static inline void fn(unsigned int mask, volatile unsigned int *p_) \ +{ \ + unsigned int old; \ + unsigned int *p = (unsigned int *)p_; \ + asm volatile ( prefix \ + "1: lwarx %0,0,%3,0\n" \ + "andc %0,%0,%2\n" \ + "stwcx. %0,0,%3\n" \ + "bne- 1b\n" \ + : "=&r" (old), "+m" (*p) \ + : "r" (mask), "r" (p) \ + : "cc", "memory" ); \ +} + +DEFINE_CLROP(clear_bits, "") + +static inline void set_bit (int nr,volatile void *addr) +{ +set_bits (BITOP_MASK (nr), (volatile unsigned int *)addr +BITOP_WORD (nr)); +} +static inline void clear_bit (int nr,volatile void *addr) +{ +clear_bits (BITOP_MASK (nr), (volatile unsigned int *)addr +BITOP_WORD (nr)); +} + +/** +* test_bit - Determine whether a bit is set +* @nr: bit number to test +* @addr: Address to start counting from +*/ +static inline int test_bit (int nr,const volatile void *addr) +{ +const volatile unsigned int *p = addr; +return 1 & (p[BITOP_WORD (nr)] >> (nr & (BITOP_BITS_PER_WORD -1 ))); +} + +static inline unsigned int test_and_clear_bits ( +unsigned int mask, +volatile unsigned int *p) +{ +unsigned int old, t; + + asmvolatile (PPC_ATOMIC_ENTRY_BARRIER +"1: lwarx %0,0,%3,0\n" +"andc %1,%0,%2\n" +"stwcx. %1,0,%3\n" +"bne- 1b\n" +PPC_ATOMIC_EXIT_BARRIER + :"=&r" (old),"=&r" (t) + :"r" (mask),"r" (p) + :"cc" ,"memory" ); + +return (old & mask); +} + +static inline int test_and_clear_bit (unsigned int nr, +volatile void *addr) +{ +return test_and_clear_bits (BITOP_MASK (nr), (volatile unsigned int *)addr + +BITOP_WORD (nr)) !=0 ; +} + +static inline unsigned int test_and_set_bits ( +unsigned int mask, +volatile unsigned int *p) +{ +unsigned int old, t; + + asmvolatile (PPC_ATOMIC_ENTRY_BARRIER +"1: lwarx %0,0,%3,0\n" +"or%I2 %1,%0,%2\n" +"stwcx. %1,0,%3\n" +"bne- 1b\n" +PPC_ATOMIC_EXIT_BARRIER + :"=&r" (old),"=&r" (t) + :"rK" (mask),"r" (p) + :"cc" ,"memory" ); + +return (old & mask); +} + +static inline int test_and_set_bit (unsigned int nr,volatile void *addr) +{ +return test_and_set_bits (BITOP_MASK (nr), (volatile unsigned int *)addr + +BITOP_WORD (nr)) !=0 ; +} + +/** +* __test_and_set_bit - Set a bit and return its old value +* @nr: Bit to set +* @addr: Address to count from +* +* This operation is non-atomic and can be reordered. +* If two examples of this operation race, one can appear to succeed +* but actually fail. You must protect multiple accesses with a lock. +*/ +static inline int __test_and_set_bit (int nr,volatile void *addr) +{ +unsigned int mask =BITOP_MASK (nr); +volatile unsigned int *p = ((volatile unsigned int *)addr) +BITOP_WORD (nr); +unsigned int old = *p; + + *p = old | mask; +return (old & mask) !=0 ; +} + +/** +* __test_and_clear_bit - Clear a bit and return its old value +* @nr: Bit to clear +* @addr: Address to count from +* +* This operation is non-atomic and can be reordered. +* If two examples of this operation race, one can appear to succeed +* but actually fail. You must protect multiple accesses with a lock. +*/ +static inline int __test_and_clear_bit (int nr,volatile void *addr) +{ +unsigned int mask =BITOP_MASK (nr); +volatile unsigned int *p = ((volatile unsigned int *)addr) +BITOP_WORD (nr); +unsigned int old = *p; + + *p = old & ~mask; +return (old & mask) !=0 ; +} + +#define flsl (x) generic_flsl(x) +#define fls (x) generic_fls(x) +#define ffs (x) ({ unsigned int t_ = (x); fls(t_ & -t_); }) +#define ffsl (x) ({ unsigned long t_ = (x); flsl(t_ & -t_); }) + +/* Based on linux/include/asm-generic/bitops/ffz.h */ +/* +* ffz - find first zero in word. +* @word: The word to search +* +* Undefined if no zero exists, so code should check against ~0UL first. +*/ +#define ffz (x) __ffs(~(x)) + +/** +* hweightN - returns the hamming weight of a N-bit word +* @x: the word to weigh +* +* The Hamming Weight of a number is the total number of bits set in it. +*/ +#define hweight64 (x) __builtin_popcountll(x) +#define hweight32 (x) __builtin_popcount(x) +#define hweight16 (x) __builtin_popcount((uint16_t)(x)) +#define hweight8 (x) __builtin_popcount((uint8_t)(x)) + +/* Based on linux/include/asm-generic/bitops/builtin-__ffs.h */ +/** +* __ffs - find first bit in word. +* @word: The word to search +* +* Undefined if no bit exists, so code should check against 0 first. +*/ +static always_inline unsigned long __ffs (unsigned long word) +{ +return __builtin_ctzl (word); +} + +/** +* find_first_set_bit - find the first set bit in @word +* @word: the word to search +* +* Returns the bit-number of the first set bit (first bit being 0). +* The input must *not* be zero. +*/ +#define find_first_set_bit (x) (ffsl(x) - 1) + +/* +* Find the first set bit in a memory region. +*/ +static inline unsigned long find_first_bit (const unsigned long *addr, +unsigned long size) +{ +const unsigned long *p = addr; +unsigned long result =0 ; +unsigned long tmp; + +while ( size & ~(BITS_PER_LONG -1 ) ) + { +if ( (tmp = *(p++)) ) + goto found; + result +=BITS_PER_LONG ; + size -=BITS_PER_LONG ; + } +if ( !size ) +return result; + + tmp = (*p) & (~0UL >> (BITS_PER_LONG - size)); +if ( tmp ==0UL )/* Are any bits set? */ +return result + size;/* Nope. */ + found: +return result +__ffs (tmp); +} + +static inline unsigned long find_next_bit (const unsigned long *addr, +unsigned long size, +unsigned long offset) +{ +const unsigned long *p = addr +BITOP_WORD (offset); +unsigned long result = offset & ~(BITS_PER_LONG -1 ); +unsigned long tmp; + +if ( offset >= size ) +return size; + size -= result; + offset %=BITS_PER_LONG ; +if ( offset ) + { + tmp = *(p++); + tmp &= (~0UL << offset); +if ( size <BITS_PER_LONG ) + goto found_first; +if ( tmp ) + goto found_middle; + size -=BITS_PER_LONG ; + result +=BITS_PER_LONG ; + } +while ( size & ~(BITS_PER_LONG -1 ) ) + { +if ( (tmp = *(p++)) ) + goto found_middle; + result +=BITS_PER_LONG ; + size -=BITS_PER_LONG ; + } +if ( !size ) +return result; + tmp = *p; + + found_first: + tmp &= (~0UL >> (BITS_PER_LONG - size)); +if ( tmp ==0UL )/* Are any bits set? */ +return result + size;/* Nope. */ + found_middle: +return result +__ffs (tmp); +} + +/* +* This implementation of find_{first,next}_zero_bit was stolen from +* Linus' asm-alpha/bitops.h. +*/ +static inline unsigned long find_next_zero_bit (const unsigned long *addr, +unsigned long size, +unsigned long offset) +{ +const unsigned long *p = addr +BITOP_WORD (offset); +unsigned long result = offset & ~(BITS_PER_LONG -1 ); +unsigned long tmp; + +if ( offset >= size ) +return size; + size -= result; + offset %=BITS_PER_LONG ; +if ( offset ) + { + tmp = *(p++); + tmp |= ~0UL >> (BITS_PER_LONG - offset); +if ( size <BITS_PER_LONG ) + goto found_first; +if ( ~tmp ) + goto found_middle; + size -=BITS_PER_LONG ; + result +=BITS_PER_LONG ; + } +while ( size & ~(BITS_PER_LONG -1 ) ) + { +if ( ~(tmp = *(p++)) ) + goto found_middle; + result +=BITS_PER_LONG ; + size -=BITS_PER_LONG ; + } +if ( !size ) +return result; + tmp = *p; + + found_first: + tmp |= ~0UL << size; +if ( tmp == ~0UL )/* Are any bits zero? */ +return result + size;/* Nope. */ + found_middle: +return result +ffz (tmp); +}#endif /* _ASM_PPC_BITOPS_H */
--
2.30.2
Re: [PATCH v5 2/5] xen/ppc: Implement bitops.h
Quoted 77 lines · Shawn Anastasio
Implement
bitops.h, based on Linux's implementation as of commit5321d1b1afb9a17302c6cec79f0cbf823eb0d3fc. Though it is based off of Linux's implementation, this code diverges significantly in a number of ways:
- Bitmap entries changed to 32-bit words to match X86 and Arm on Xen
- PPC32-specific code paths dropped
- Formatting completely re-done to more closely line up with Xen. Including 4 space indentation.
- Use GCC's __builtin_popcount* for hweight* implementationSigned-off-by Shawn Anastasio <[email protected]>Acked-by Jan Beulich <[email protected]>---
v5:
- Switch lingering ulong bitop parameters/return values to uint.v4:
- Mention__builtin_popcountimpelmentation of hweight* in message
- Change type ofBITOP_MASKexpression from unsigned long to unsigned int
- Fix remaining underscore-prefixed macro params/vars
- Fix line wrapping in test_and_clear_bit{,s}
- Change type oftest_and_clear_bits' pointer parameter from void * to unsigned int *. This was already done for other functions but missed here.
- De-macroizetest_and_set_bits.
- Fix formatting of ffs{,l} macro's unary operators
- Drop extra blank inffz()macro definitionv3:
- Fix style of inline asm blocks.
- Fix underscore-prefixed macro parameters/variables
- Use__builtin_popcountfor hweight* implementation
- Update C functions to use proper Xen coding stylev2:
- Clarify changes from Linux implementation in commit message
- Use PPC_ATOMIC_{ENTRY,EXIT}_BARRIER macros from <asm/memory.h> instead of hardcoded "sync" instructions in inline assembly blocks.
- Fix macro line-continuing backslash spacing
- Fix hard-tab usage in find_*_bit C functions.xen/arch/ppc/include/asm/bitops.h | 332 +++++++++++++++++++++++++++++- 1 file changed, 329 insertions(+), 3 deletions(-)xen/arch/ppc/include/asm/bitops.h +20
-3@@ -1,9 +1,335 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* Adapted from Linux's arch/powerpc/include/asm/bitops.h. +* +* Merged version by David Gibson <[email protected]>. +* Based on ppc64 versions by: Dave Engebretsen, Todd Inglett, Don +* Reed, Pat McCarthy, Peter Bergner, Anton Blanchard. They +* originally took it from the ppc32 code. +*/ #ifndef _ASM_PPC_BITOPS_H#define _ASM_PPC_BITOPS_H +#include <asm/memory.h> + +#define __set_bit (n, p) set_bit(n, p) +#define __clear_bit (n, p) clear_bit(n, p) + +#define BITOP_BITS_PER_WORD 32 +#define BITOP_MASK (nr) (1U << ((nr) % BITOP_BITS_PER_WORD)) +#define BITOP_WORD (nr) ((nr) / BITOP_BITS_PER_WORD) +#define BITS_PER_BYTE 8 +/* PPC bit number conversion */ -#define PPC_BITLSHIFT (be) (BITS_PER_LONG - 1 - (be)) -#define PPC_BIT (bit) (1UL << PPC_BITLSHIFT(bit)) -#define PPC_BITMASK (bs, be) ((PPC_BIT(bs) - PPC_BIT(be)) | PPC_BIT(bs)) +#define PPC_BITLSHIFT (be) (BITS_PER_LONG - 1 - (be))
xen/arch/ppc/include/asm/bitops.h line 34
Quoted 10 lines
xen/arch/ppc/include/asm/bitops.h +10
-0+#define PPC_BIT (bit) (1UL << PPC_BITLSHIFT(bit)) +#define PPC_BITMASK (bs, be) ((PPC_BIT(bs) - PPC_BIT(be)) | PPC_BIT(bs)) + +/* Macro for generating the ***_bits() functions */ +#define DEFINE_BITOP (fn, op, prefix) \ +static inline void fn(unsigned int mask, \ + volatile unsigned int *p_) \ +{ \ + unsigned int old; \ + unsigned int *p = (unsigned int *)p_; \
What use is this, when ...
xen/arch/ppc/include/asm/bitops.h line 40
Quoted 6 lines
xen/arch/ppc/include/asm/bitops.h +6
-0+ asm volatile ( prefix \ + "1: lwarx %0,0,%3,0\n" \ +#op "%I2 %0,%0,%2\n" \ + "stwcx. %0,0,%3\n" \ + "bne- 1b\n" \ + : "=&r" (old), "+m" (*p) \
... the "+m" operand isn't used and ...
xen/arch/ppc/include/asm/bitops.h line 42
Quoted 2 lines
xen/arch/ppc/include/asm/bitops.h +2
-0+ : "rK" (mask), "r" (p) \ + : "cc", "memory" ); \
... there's a memory clobber anyway?
Also (nit) note that the long -> int change has caused some of the backslashes to no longer align.
xen/arch/ppc/include/asm/bitops.h line 46
Quoted 4 lines
xen/arch/ppc/include/asm/bitops.h +4
-0+} + +DEFINE_BITOP(set_bits, or, "") +DEFINE_BITOP (change_bits, xor,"" )
Are there further plans to add uses of DEFINE_BITOP() with the last argument not an empty string? If not, how about simplifying things by dropping the macro parameter?
Quoted 6 lines
xen/arch/ppc/include/asm/bitops.h +6
-0+#define DEFINE_CLROP (fn, prefix) \ +static inline void fn(unsigned int mask, volatile unsigned int *p_) \ +{ \ + unsigned int old; \ + unsigned int *p = (unsigned int *)p_; \ + asm volatile ( prefix \
xen/arch/ppc/include/asm/bitops.h line 63
Quoted 10 lines
xen/arch/ppc/include/asm/bitops.h +10
-0+"1: lwarx %0,0,%3,0\n" \ +"andc %0,%0,%2\n" \ +"stwcx. %0,0,%3\n" \ +"bne- 1b\n" \ + : "=&r" (old), "+m" (*p) \ +: " r" (mask), " r" (p) \ +: " cc", " memory" ); \ +} + +DEFINE_CLROP (clear_bits,"" )
Same question here.
Quoted 34 lines
xen/arch/ppc/include/asm/bitops.h +34
-0+static inline void set_bit (int nr,volatile void *addr) +{ +set_bits (BITOP_MASK (nr), (volatile unsigned int *)addr +BITOP_WORD (nr)); +} +static inline void clear_bit (int nr,volatile void *addr) +{ +clear_bits (BITOP_MASK (nr), (volatile unsigned int *)addr +BITOP_WORD (nr)); +} + +/** +* test_bit - Determine whether a bit is set +* @nr: bit number to test +* @addr: Address to start counting from +*/ +static inline int test_bit (int nr,const volatile void *addr) +{ +const volatile unsigned int *p = addr; +return 1 & (p[BITOP_WORD (nr)] >> (nr & (BITOP_BITS_PER_WORD -1 ))); +} + +static inline unsigned int test_and_clear_bits ( +unsigned int mask, +volatile unsigned int *p) +{ +unsigned int old, t; + + asmvolatile (PPC_ATOMIC_ENTRY_BARRIER +"1: lwarx %0,0,%3,0\n" +"andc %1,%0,%2\n" +"stwcx. %1,0,%3\n" +"bne- 1b\n" +PPC_ATOMIC_EXIT_BARRIER + :"=&r" (old),"=&r" (t) + : "r" (mask), "r" (p)
xen/arch/ppc/include/asm/bitops.h line 108
Quoted 10 lines
xen/arch/ppc/include/asm/bitops.h +10
-0+ : "cc", "memory" ); + +return (old & mask); +} + +static inline int test_and_clear_bit (unsigned int nr, +volatile void *addr) +{ +return test_and_clear_bits (BITOP_MASK (nr), (volatile unsigned int *)addr + +BITOP_WORD (nr)) !=0 ;
Didn't you indicate you'd adjust the odd wrapping?
Quoted 15 lines
xen/arch/ppc/include/asm/bitops.h +15
-0+} + +static inline unsigned int test_and_set_bits ( +unsigned int mask, +volatile unsigned int *p) +{ +unsigned int old, t; + + asmvolatile (PPC_ATOMIC_ENTRY_BARRIER +"1: lwarx %0,0,%3,0\n" +"or%I2 %1,%0,%2\n" +"stwcx. %1,0,%3\n" +"bne- 1b\n" +PPC_ATOMIC_EXIT_BARRIER + : "=&r" (old), "=&r" (t)
xen/arch/ppc/include/asm/bitops.h line 133
Quoted 10 lines
xen/arch/ppc/include/asm/bitops.h +10
-0+ : "rK" (mask), "r" (p) + : "cc", "memory" ); + +return (old & mask); +} + +static inline int test_and_set_bit (unsigned int nr,volatile void *addr) +{ +return test_and_set_bits (BITOP_MASK (nr), (volatile unsigned int *)addr + +BITOP_WORD (nr)) !=0 ;
Same here then.
Jan
Re: [PATCH v5 2/5] xen/ppc: Implement bitops.h
Quoted 98 lines · Jan Beulich
Quoted 77 lines · Shawn Anastasio
Implement
bitops.h, based on Linux's implementation as of commit5321d1b1afb9a17302c6cec79f0cbf823eb0d3fc. Though it is based off of Linux's implementation, this code diverges significantly in a number of ways:
- Bitmap entries changed to 32-bit words to match X86 and Arm on Xen
- PPC32-specific code paths dropped
- Formatting completely re-done to more closely line up with Xen. Including 4 space indentation.
- Use GCC's __builtin_popcount* for hweight* implementationSigned-off-by Shawn Anastasio <[email protected]>Acked-by Jan Beulich <[email protected]>---
v5:
- Switch lingering ulong bitop parameters/return values to uint.v4:
- Mention__builtin_popcountimpelmentation of hweight* in message
- Change type ofBITOP_MASKexpression from unsigned long to unsigned int
- Fix remaining underscore-prefixed macro params/vars
- Fix line wrapping in test_and_clear_bit{,s}
- Change type oftest_and_clear_bits' pointer parameter from void * to unsigned int *. This was already done for other functions but missed here.
- De-macroizetest_and_set_bits.
- Fix formatting of ffs{,l} macro's unary operators
- Drop extra blank inffz()macro definitionv3:
- Fix style of inline asm blocks.
- Fix underscore-prefixed macro parameters/variables
- Use__builtin_popcountfor hweight* implementation
- Update C functions to use proper Xen coding stylev2:
- Clarify changes from Linux implementation in commit message
- Use PPC_ATOMIC_{ENTRY,EXIT}_BARRIER macros from <asm/memory.h> instead of hardcoded "sync" instructions in inline assembly blocks.
- Fix macro line-continuing backslash spacing
- Fix hard-tab usage in find_*_bit C functions.xen/arch/ppc/include/asm/bitops.h | 332 +++++++++++++++++++++++++++++- 1 file changed, 329 insertions(+), 3 deletions(-)xen/arch/ppc/include/asm/bitops.h +20
-3@@ -1,9 +1,335 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* Adapted from Linux's arch/powerpc/include/asm/bitops.h. +* +* Merged version by David Gibson <[email protected]>. +* Based on ppc64 versions by: Dave Engebretsen, Todd Inglett, Don +* Reed, Pat McCarthy, Peter Bergner, Anton Blanchard. They +* originally took it from the ppc32 code. +*/ #ifndef _ASM_PPC_BITOPS_H#define _ASM_PPC_BITOPS_H +#include <asm/memory.h> + +#define __set_bit (n, p) set_bit(n, p) +#define __clear_bit (n, p) clear_bit(n, p) + +#define BITOP_BITS_PER_WORD 32 +#define BITOP_MASK (nr) (1U << ((nr) % BITOP_BITS_PER_WORD)) +#define BITOP_WORD (nr) ((nr) / BITOP_BITS_PER_WORD) +#define BITS_PER_BYTE 8 +/* PPC bit number conversion */ -#define PPC_BITLSHIFT (be) (BITS_PER_LONG - 1 - (be)) -#define PPC_BIT (bit) (1UL << PPC_BITLSHIFT(bit)) -#define PPC_BITMASK (bs, be) ((PPC_BIT(bs) - PPC_BIT(be)) | PPC_BIT(bs)) +#define PPC_BITLSHIFT (be) (BITS_PER_LONG - 1 - (be))xen/arch/ppc/include/asm/bitops.h line 34
Quoted 10 lines
xen/arch/ppc/include/asm/bitops.h +10
-0+#define PPC_BIT (bit) (1UL << PPC_BITLSHIFT(bit)) +#define PPC_BITMASK (bs, be) ((PPC_BIT(bs) - PPC_BIT(be)) | PPC_BIT(bs)) + +/* Macro for generating the ***_bits() functions */ +#define DEFINE_BITOP (fn, op, prefix) \ +static inline void fn(unsigned int mask, \ + volatile unsigned int *p_) \ +{ \ + unsigned int old; \ + unsigned int *p = (unsigned int *)p_; \What use is this, when ...
xen/arch/ppc/include/asm/bitops.h line 40
Quoted 6 lines
xen/arch/ppc/include/asm/bitops.h +6
-0+ asm volatile ( prefix \ + "1: lwarx %0,0,%3,0\n" \ +#op "%I2 %0,%0,%2\n" \ + "stwcx. %0,0,%3\n" \ + "bne- 1b\n" \ + : "=&r" (old), "+m" (*p) \
Quoted 7 lines
... the "+m" operand isn't used and ...
xen/arch/ppc/include/asm/bitops.h line 42
Quoted 2 lines
xen/arch/ppc/include/asm/bitops.h +2
-0+ : "rK" (mask), "r" (p) \ + : "cc", "memory" ); \... there's a memory clobber anyway?
I see what you're saying, and I'm not sure why it was written this way in Linux. That said, this is the kind of thing that I'm hesitant to change without knowing the rationale of the original author. If you are confident that the this can be dropped given that there is already a memory clobber, I could drop it. Otherwise I'm inclined to leave it in a state that matches Linux.
Quoted 3 lines
Also (nit) note that the long -> int change has caused some of the backslashes to no longer align.
Will fix the backslash alignment.
Quoted 9 lines
xen/arch/ppc/include/asm/bitops.h line 46
Quoted 4 lines
xen/arch/ppc/include/asm/bitops.h +4
-0+} + +DEFINE_BITOP(set_bits, or, "") +DEFINE_BITOP (change_bits, xor,"" )Are there further plans to add uses of
DEFINE_BITOP()with the last argument not an empty string? If not, how about simplifying things by dropping the macro parameter?
Sure, I can drop the last parameter.
Quoted 10 lines
Quoted 10 lines
xen/arch/ppc/include/asm/bitops.h +10
-0+#define DEFINE_CLROP (fn, prefix) \ +static inline void fn(unsigned int mask, volatile unsigned int *p_) \ +{ \ + unsigned int old; \ + unsigned int *p = (unsigned int *)p_; \ + asm volatile ( prefix \ + "1: lwarx %0,0,%3,0\n" \ + "andc %0,%0,%2\n" \ + "stwcx. %0,0,%3\n" \ + "bne- 1b\n" \
Quoted 9 lines
xen/arch/ppc/include/asm/bitops.h line 63
Quoted 6 lines
xen/arch/ppc/include/asm/bitops.h +6
-0+ : "=&r" (old), "+m" (*p) \ + : "r" (mask), "r" (p) \ + : "cc", "memory" ); \ +} + +DEFINE_CLROP (clear_bits,"" )Same question here.
Ditto.
Quoted 38 lines
Quoted 38 lines
xen/arch/ppc/include/asm/bitops.h +38
-0+static inline void set_bit (int nr,volatile void *addr) +{ +set_bits (BITOP_MASK (nr), (volatile unsigned int *)addr +BITOP_WORD (nr)); +} +static inline void clear_bit (int nr,volatile void *addr) +{ +clear_bits (BITOP_MASK (nr), (volatile unsigned int *)addr +BITOP_WORD (nr)); +} + +/** +* test_bit - Determine whether a bit is set +* @nr: bit number to test +* @addr: Address to start counting from +*/ +static inline int test_bit (int nr,const volatile void *addr) +{ +const volatile unsigned int *p = addr; +return 1 & (p[BITOP_WORD (nr)] >> (nr & (BITOP_BITS_PER_WORD -1 ))); +} + +static inline unsigned int test_and_clear_bits ( +unsigned int mask, +volatile unsigned int *p) +{ +unsigned int old, t; + + asmvolatile (PPC_ATOMIC_ENTRY_BARRIER +"1: lwarx %0,0,%3,0\n" +"andc %1,%0,%2\n" +"stwcx. %1,0,%3\n" +"bne- 1b\n" +PPC_ATOMIC_EXIT_BARRIER + :"=&r" (old),"=&r" (t) + :"r" (mask),"r" (p) + :"cc" ,"memory" ); + +return (old & mask); +}
Quoted 9 lines
xen/arch/ppc/include/asm/bitops.h line 108
Quoted 6 lines
xen/arch/ppc/include/asm/bitops.h +6
-0+ +static inline int test_and_clear_bit (unsigned int nr, +volatile void *addr) +{ +return test_and_clear_bits (BITOP_MASK (nr), (volatile unsigned int *)addr + +BITOP_WORD (nr)) !=0 ;Didn't you indicate you'd adjust the odd wrapping?
Apologies, will fix.
Quoted 19 lines
Quoted 19 lines
xen/arch/ppc/include/asm/bitops.h +19
-0+} + +static inline unsigned int test_and_set_bits ( +unsigned int mask, +volatile unsigned int *p) +{ +unsigned int old, t; + + asmvolatile (PPC_ATOMIC_ENTRY_BARRIER +"1: lwarx %0,0,%3,0\n" +"or%I2 %1,%0,%2\n" +"stwcx. %1,0,%3\n" +"bne- 1b\n" +PPC_ATOMIC_EXIT_BARRIER + :"=&r" (old),"=&r" (t) + :"rK" (mask),"r" (p) + :"cc" ,"memory" ); + +return (old & mask);
Quoted 9 lines
xen/arch/ppc/include/asm/bitops.h line 133
Quoted 6 lines
xen/arch/ppc/include/asm/bitops.h +6
-0+} + +static inline int test_and_set_bit (unsigned int nr,volatile void *addr) +{ +return test_and_set_bits (BITOP_MASK (nr), (volatile unsigned int *)addr + +BITOP_WORD (nr)) !=0 ;Same here then.
Ditto.
Quoted 1 line
Jan
Thanks,
Shawn
Re: [PATCH v5 2/5] xen/ppc: Implement bitops.h
Quoted 60 lines · Shawn Anastasio
Quoted 51 lines · Jan Beulich
Quoted 30 lines · Shawn Anastasio
xen/arch/ppc/include/asm/bitops.h +20
-3@@ -1,9 +1,335 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* Adapted from Linux's arch/powerpc/include/asm/bitops.h. +* +* Merged version by David Gibson <[email protected]>. +* Based on ppc64 versions by: Dave Engebretsen, Todd Inglett, Don +* Reed, Pat McCarthy, Peter Bergner, Anton Blanchard. They +* originally took it from the ppc32 code. +*/ #ifndef _ASM_PPC_BITOPS_H#define _ASM_PPC_BITOPS_H +#include <asm/memory.h> + +#define __set_bit (n, p) set_bit(n, p) +#define __clear_bit (n, p) clear_bit(n, p) + +#define BITOP_BITS_PER_WORD 32 +#define BITOP_MASK (nr) (1U << ((nr) % BITOP_BITS_PER_WORD)) +#define BITOP_WORD (nr) ((nr) / BITOP_BITS_PER_WORD) +#define BITS_PER_BYTE 8 +/* PPC bit number conversion */ -#define PPC_BITLSHIFT (be) (BITS_PER_LONG - 1 - (be)) -#define PPC_BIT (bit) (1UL << PPC_BITLSHIFT(bit)) -#define PPC_BITMASK (bs, be) ((PPC_BIT(bs) - PPC_BIT(be)) | PPC_BIT(bs)) +#define PPC_BITLSHIFT (be) (BITS_PER_LONG - 1 - (be))xen/arch/ppc/include/asm/bitops.h line 34
Quoted 10 lines
xen/arch/ppc/include/asm/bitops.h +10
-0+#define PPC_BIT (bit) (1UL << PPC_BITLSHIFT(bit)) +#define PPC_BITMASK (bs, be) ((PPC_BIT(bs) - PPC_BIT(be)) | PPC_BIT(bs)) + +/* Macro for generating the ***_bits() functions */ +#define DEFINE_BITOP (fn, op, prefix) \ +static inline void fn(unsigned int mask, \ + volatile unsigned int *p_) \ +{ \ + unsigned int old; \ + unsigned int *p = (unsigned int *)p_; \What use is this, when ...
xen/arch/ppc/include/asm/bitops.h line 40
Quoted 6 lines
xen/arch/ppc/include/asm/bitops.h +6
-0+ asm volatile ( prefix \ + "1: lwarx %0,0,%3,0\n" \ +#op "%I2 %0,%0,%2\n" \ + "stwcx. %0,0,%3\n" \ + "bne- 1b\n" \ + : "=&r" (old), "+m" (*p) \Quoted 7 lines
... the "+m" operand isn't used and ...
xen/arch/ppc/include/asm/bitops.h line 42
Quoted 2 lines
xen/arch/ppc/include/asm/bitops.h +2
-0+ : "rK" (mask), "r" (p) \ + : "cc", "memory" ); \... there's a memory clobber anyway?
Quoted 6 lines
I see what you're saying, and I'm not sure why it was written this way in Linux. That said, this is the kind of thing that I'm hesitant to change without knowing the rationale of the original author. If you are confident that the this can be dropped given that there is already a memory clobber, I could drop it. Otherwise I'm inclined to leave it in a state that matches Linux.
This being an arch-independent property, I am confident. Yet still you're the maintainer, so if you want to keep it like this initially, that'll be okay. If I feel bothered enough, I could always send a patch afterwards.
Jan
Re: [PATCH v5 2/5] xen/ppc: Implement bitops.h
Quoted 68 lines · Jan Beulich
Quoted 60 lines · Shawn Anastasio
Quoted 51 lines · Jan Beulich
Quoted 30 lines · Shawn Anastasio
xen/arch/ppc/include/asm/bitops.h +20
-3@@ -1,9 +1,335 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* Adapted from Linux's arch/powerpc/include/asm/bitops.h. +* +* Merged version by David Gibson <[email protected]>. +* Based on ppc64 versions by: Dave Engebretsen, Todd Inglett, Don +* Reed, Pat McCarthy, Peter Bergner, Anton Blanchard. They +* originally took it from the ppc32 code. +*/ #ifndef _ASM_PPC_BITOPS_H#define _ASM_PPC_BITOPS_H +#include <asm/memory.h> + +#define __set_bit (n, p) set_bit(n, p) +#define __clear_bit (n, p) clear_bit(n, p) + +#define BITOP_BITS_PER_WORD 32 +#define BITOP_MASK (nr) (1U << ((nr) % BITOP_BITS_PER_WORD)) +#define BITOP_WORD (nr) ((nr) / BITOP_BITS_PER_WORD) +#define BITS_PER_BYTE 8 +/* PPC bit number conversion */ -#define PPC_BITLSHIFT (be) (BITS_PER_LONG - 1 - (be)) -#define PPC_BIT (bit) (1UL << PPC_BITLSHIFT(bit)) -#define PPC_BITMASK (bs, be) ((PPC_BIT(bs) - PPC_BIT(be)) | PPC_BIT(bs)) +#define PPC_BITLSHIFT (be) (BITS_PER_LONG - 1 - (be))xen/arch/ppc/include/asm/bitops.h line 34
Quoted 10 lines
xen/arch/ppc/include/asm/bitops.h +10
-0+#define PPC_BIT (bit) (1UL << PPC_BITLSHIFT(bit)) +#define PPC_BITMASK (bs, be) ((PPC_BIT(bs) - PPC_BIT(be)) | PPC_BIT(bs)) + +/* Macro for generating the ***_bits() functions */ +#define DEFINE_BITOP (fn, op, prefix) \ +static inline void fn(unsigned int mask, \ + volatile unsigned int *p_) \ +{ \ + unsigned int old; \ + unsigned int *p = (unsigned int *)p_; \What use is this, when ...
xen/arch/ppc/include/asm/bitops.h line 40
Quoted 6 lines
xen/arch/ppc/include/asm/bitops.h +6
-0+ asm volatile ( prefix \ + "1: lwarx %0,0,%3,0\n" \ +#op "%I2 %0,%0,%2\n" \ + "stwcx. %0,0,%3\n" \ + "bne- 1b\n" \ + : "=&r" (old), "+m" (*p) \Quoted 7 lines
... the "+m" operand isn't used and ...
xen/arch/ppc/include/asm/bitops.h line 42
Quoted 2 lines
xen/arch/ppc/include/asm/bitops.h +2
-0+ : "rK" (mask), "r" (p) \ + : "cc", "memory" ); \... there's a memory clobber anyway?
Quoted 6 lines
I see what you're saying, and I'm not sure why it was written this way in Linux. That said, this is the kind of thing that I'm hesitant to change without knowing the rationale of the original author. If you are confident that the this can be dropped given that there is already a memory clobber, I could drop it. Otherwise I'm inclined to leave it in a state that matches Linux.
Quoted 4 lines
This being an arch-independent property, I am confident. Yet still you're the maintainer, so if you want to keep it like this initially, that'll be okay. If I feel bothered enough, I could always send a patch afterwards.
Okay, for now then I will leave it as-is.
Quoted 1 line
Jan
Thanks,
Shawn
PATCH v5 3/5 xen/ppc: Define minimal stub headers required for full build
In reply to Shawn AnastasioAdditionally, change inclusion of asm/ headers to corresponding xen/ ones throughout arch/ppc now that they work.
---
v5:
- Drop vm_event.h in favor of asm-generic variant
- (numa.h) Fix lingering reference to Arm
v4:
- (device.h) Fix underscore prefixes in DT_DEVICE_START macro
- (mm.h) Fix padding blanks in newly added *_to_* macros
- (mm.h) Drop inaccurate comment for virt_to_mfn/mfn_to_virt. The implementation of these macros remains unchanged.
- (mm.h) s/zero/NULL/g in comment of page_info::v::inuse::domain
- (mm.h) Use uint<N>_t instead of u<N> types in struct page_info
- (p2m.h) Drop ARM-specific p2m_type_t enumerations
- (system.h) Fix hard tabs in xchg() macro
- (system.h) Add missing '\n' in build_xchg inline assembly before PPC_ATOMIC_EXIT_BARRIER.
- (system.h) Fix formatting of switch statements.
- (system.h) Fix formatting of cmpxchg() macro.
- (system.h) Fix formatting of mb/rmb/wmb macros
- (system.h) Drop dead !CONFIG_SMP definition of smp memory barriers
- (system.h) Replace hand-coded asm memory barriers w/ barrier()
- (time.h) Fix overly-long definition of force_update_vcpu_system_time
v3:
- Drop procarea.h
- Add SPDX headers to all headers touched or added by this patch
- (altp2m.h) Use ASSERT_UNREACHABLE for function that is meant to stay unimplemented
- (current.h) Consistently use plain C types in struct cpu_info
- (current.h) Fix formatting of inline asm in get_cpu_info()
- (device.h) Drop unnecessary DEVICE_GIC enumeration inherited from ARM
- (div64.h) Drop underscore-prefixed macro variables, fix formatting
- (domain.h) Drop unnecessary space after cast in guest_mode()
- (guest_access.h) Clean up line wrapping of functions w/ many parameters
- (guest_atomics.h) Avoid overly-long stub macros
- (grant_table.h) Add include guard + SPDX
- (hypercall.h) Add include guard + SPDX
- (mem_access.h) Add include guard + SPDX
- (mm.h) BUG_ON("unimplemented") for mfn_to_gfn/set_gpfn_from_mfn
- (mm.h) Define PDX_GROUP_SHIFT in terms of XEN_PT_SHIFT_LVL_3
- (monitor.h) BUG_ON("unimplemented") for arch_monitor_get_capabilities
- (system.h) Fix formatting of inline assembly + macros
- (time.h) Fix too-deep indentation
v2:
- Use BUG_ON("unimplemented") instead of BUG() for unimplemented functions to make searching easier.
- (altp2m.h) Drop Intel license in favor of an SPDX header
- (altp2m.h) Drop <xen/sched.h> include in favor of <xen/bug.h> and forward declarations of struct domain and struct vcpu.
- (bug.h) Add TODO comments above BUG and BUG_FRAME implementations
- (desc.h) Drop desc.h
- (mm.h) Drop <asm/config.h> include
- (mm.h) Drop PGC_static definition
- (mm.h) Drop max_page definition
- (mm.h/mm-radix.c) Drop total_pages definition
- (monitor.h) Drop <xen/sched.h> and <public/domctl.h> includes in favor of just <xen/errno.h>
- (page.h) Drop PAGE_ALIGN definition
- (percpu.h) Drop <xen/types.h> include
- (procarea.h) Drop license text in favor of SPDX header
- (procarea.h) Drop unnecessary forward declarations and <xen/types.h> include
- (processor.h) Fix macro parameter naming (drop leading underscore)
- (processor.h) Add explanation comment to cpu_relax()
- (regs.h) Drop stray hunk adding <xen/types.h> include
- (system.h) Drop license text in favor of SPDX header
- (system.h) Drop <xen/config.h> include
- (opal.c) Drop stray hunk changing opal.c includes
xen/arch/ppc/Kconfig | 1 + xen/arch/ppc/include/asm/Makefile | 2 + xen/arch/ppc/include/asm/altp2m.h | 25 +++ xen/arch/ppc/include/asm/bug.h | 9 + xen/arch/ppc/include/asm/cache.h | 2 + xen/arch/ppc/include/asm/config.h | 10 + xen/arch/ppc/include/asm/cpufeature.h | 10 + xen/arch/ppc/include/asm/current.h | 43 ++++ xen/arch/ppc/include/asm/delay.h | 12 ++ xen/arch/ppc/include/asm/device.h | 53 +++++ xen/arch/ppc/include/asm/div64.h | 14 ++ xen/arch/ppc/include/asm/domain.h | 47 +++++ xen/arch/ppc/include/asm/event.h | 36 ++++ xen/arch/ppc/include/asm/flushtlb.h | 24 +++ xen/arch/ppc/include/asm/grant_table.h | 5 + xen/arch/ppc/include/asm/guest_access.h | 68 +++++++ xen/arch/ppc/include/asm/guest_atomics.h | 23 +++ xen/arch/ppc/include/asm/hardirq.h | 19 ++ xen/arch/ppc/include/asm/hypercall.h | 5 + xen/arch/ppc/include/asm/io.h | 16 ++ xen/arch/ppc/include/asm/iocap.h | 8 + xen/arch/ppc/include/asm/iommu.h | 8 + xen/arch/ppc/include/asm/irq.h | 33 +++ xen/arch/ppc/include/asm/mem_access.h | 5 + xen/arch/ppc/include/asm/mm.h | 243 ++++++++++++++++++++++- xen/arch/ppc/include/asm/monitor.h | 43 ++++ xen/arch/ppc/include/asm/nospec.h | 15 ++ xen/arch/ppc/include/asm/numa.h | 26 +++ xen/arch/ppc/include/asm/p2m.h | 95 +++++++++ xen/arch/ppc/include/asm/page.h | 18 ++ xen/arch/ppc/include/asm/paging.h | 7 + xen/arch/ppc/include/asm/pci.h | 7 + xen/arch/ppc/include/asm/percpu.h | 24 +++ xen/arch/ppc/include/asm/processor.h | 10 + xen/arch/ppc/include/asm/random.h | 9 + xen/arch/ppc/include/asm/setup.h | 6 + xen/arch/ppc/include/asm/smp.h | 18 ++ xen/arch/ppc/include/asm/softirq.h | 8 + xen/arch/ppc/include/asm/spinlock.h | 15 ++ xen/arch/ppc/include/asm/system.h | 219 +++++++++++++++++++- xen/arch/ppc/include/asm/time.h | 23 +++ xen/arch/ppc/include/asm/xenoprof.h | 0 xen/arch/ppc/mm-radix.c | 2 +- xen/arch/ppc/tlb-radix.c | 2 +- xen/include/public/hvm/save.h | 2 + xen/include/public/pmu.h | 2 + xen/include/public/xen.h | 2 + 47 files changed, 1270 insertions(+), 4 deletions(-) create mode 100644 xen/arch/ppc/include/asm/Makefile create mode 100644 xen/arch/ppc/include/asm/altp2m.h create mode 100644 xen/arch/ppc/include/asm/cpufeature.h create mode 100644 xen/arch/ppc/include/asm/current.h create mode 100644 xen/arch/ppc/include/asm/delay.h create mode 100644 xen/arch/ppc/include/asm/device.h create mode 100644 xen/arch/ppc/include/asm/div64.h create mode 100644 xen/arch/ppc/include/asm/domain.h create mode 100644 xen/arch/ppc/include/asm/event.h create mode 100644 xen/arch/ppc/include/asm/flushtlb.h create mode 100644 xen/arch/ppc/include/asm/grant_table.h create mode 100644 xen/arch/ppc/include/asm/guest_access.h create mode 100644 xen/arch/ppc/include/asm/guest_atomics.h create mode 100644 xen/arch/ppc/include/asm/hardirq.h create mode 100644 xen/arch/ppc/include/asm/hypercall.h create mode 100644 xen/arch/ppc/include/asm/io.h create mode 100644 xen/arch/ppc/include/asm/iocap.h create mode 100644 xen/arch/ppc/include/asm/iommu.h create mode 100644 xen/arch/ppc/include/asm/irq.h create mode 100644 xen/arch/ppc/include/asm/mem_access.h create mode 100644 xen/arch/ppc/include/asm/monitor.h create mode 100644 xen/arch/ppc/include/asm/nospec.h create mode 100644 xen/arch/ppc/include/asm/numa.h create mode 100644 xen/arch/ppc/include/asm/p2m.h create mode 100644 xen/arch/ppc/include/asm/paging.h create mode 100644 xen/arch/ppc/include/asm/pci.h create mode 100644 xen/arch/ppc/include/asm/percpu.h create mode 100644 xen/arch/ppc/include/asm/random.h create mode 100644 xen/arch/ppc/include/asm/setup.h create mode 100644 xen/arch/ppc/include/asm/smp.h create mode 100644 xen/arch/ppc/include/asm/softirq.h create mode 100644 xen/arch/ppc/include/asm/spinlock.h create mode 100644 xen/arch/ppc/include/asm/time.h create mode 100644 xen/arch/ppc/include/asm/xenoprof.h
xen/arch/ppc/Kconfig +1 -0
@@ -1,6 +1,7 @@ config PPC def_bool y select HAS_DEVICE_TREE + select HAS_PDX config PPC64 def_bool y
xen/arch/ppc/include/asm/Makefile new file +2 -0
@@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0-only +generic-y += vm_event.h
xen/arch/ppc/include/asm/altp2m.h new file +25 -0
@@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __ASM_PPC_ALTP2M_H__ +#define __ASM_PPC_ALTP2M_H__ + +#include <xen/bug.h> + +struct domain ; +struct vcpu ; + +/* Alternate p2m on/off per domain */ +static inline bool altp2m_active (const struct domain *d) +{ +/* Not implemented on PPC. */ +return false; +} + +/* Alternate p2m VCPU */ +static inline uint16_t altp2m_vcpu_idx (const struct vcpu *v) +{ +/* Not implemented on PPC, should not be reached. */ +ASSERT_UNREACHABLE (); +return 0 ; +} + +#endif /* __ASM_PPC_ALTP2M_H__ */
xen/arch/ppc/include/asm/bug.h +9 -0
@@ -4,6 +4,7 @@#define _ASM_PPC_BUG_H#include <xen/stringify.h> +#include <asm/processor.h> /* * Power ISA guarantees that an instruction consisting of all zeroes is
@@ -15,4 +16,12 @@#define BUG_FN_REG r0 +/* TODO: implement this properly */ +#define BUG () do { \ + die(); \ +} while (0) + +/* TODO: implement this properly */ +#define BUG_FRAME (type, line, ptr, second_frame, msg) do { } while (0) +#endif /* _ASM_PPC_BUG_H */
xen/arch/ppc/include/asm/cache.h +2 -0
@@ -3,4 +3,6 @@#ifndef _ASM_PPC_CACHE_H#define _ASM_PPC_CACHE_H +#define __read_mostly __section(".data.read_mostly") +#endif /* _ASM_PPC_CACHE_H */
xen/arch/ppc/include/asm/config.h +10 -0
@@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ #ifndef __PPC_CONFIG_H__#define __PPC_CONFIG_H__
@@ -41,6 +42,15 @@#define XEN_VIRT_START _AC(0xc000000000000000, UL) +#define VMAP_VIRT_START (XEN_VIRT_START + GB(1)) +#define VMAP_VIRT_SIZE GB(1) + +#define FRAMETABLE_VIRT_START (XEN_VIRT_START + GB(32)) +#define FRAMETABLE_SIZE GB(32) +#define FRAMETABLE_NR (FRAMETABLE_SIZE / sizeof(*frame_table)) + +#define HYPERVISOR_VIRT_START XEN_VIRT_START +#define SMP_CACHE_BYTES (1 << 6)#define STACK_ORDER 0
xen/arch/ppc/include/asm/cpufeature.h new file +10 -0
@@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __ASM_PPC_CPUFEATURE_H__ +#define __ASM_PPC_CPUFEATURE_H__ + +static inline int cpu_nr_siblings (unsigned int cpu) +{ +return 1 ; +} + +#endif /* __ASM_PPC_CPUFEATURE_H__ */
xen/arch/ppc/include/asm/current.h new file +43 -0
43 lines not on this page · raw message
xen/arch/ppc/include/asm/delay.h new file +12 -0
@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __ASM_PPC_DELAY_H__ +#define __ASM_PPC_DELAY_H__ + +#include <xen/lib.h> + +static inline void udelay (unsigned long usecs) +{ +BUG_ON ("unimplemented" ); +} + +#endif /* __ASM_PPC_DELAY_H__ */
xen/arch/ppc/include/asm/device.h new file +53 -0
53 lines not on this page · raw message
xen/arch/ppc/include/asm/div64.h new file +14 -0
@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __ASM_PPC_DIV64_H__ +#define __ASM_PPC_DIV64_H__ + +#include <xen/types.h> + +#define do_div (n, base) ({ \ + uint32_t base_ = (base); \ + uint32_t rem_ = (uint64_t)(n) % base_; \ + (n) = (uint64_t)(n) / base_; \ + rem_; \ +}) + +#endif /* __ASM_PPC_DIV64_H__ */
xen/arch/ppc/include/asm/domain.h new file +47 -0
47 lines not on this page · raw message
xen/arch/ppc/include/asm/event.h new file +36 -0
@@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __ASM_PPC_EVENT_H__ +#define __ASM_PPC_EVENT_H__ + +#include <xen/lib.h> + +/* TODO: implement */ +static inline void vcpu_kick (struct vcpu *v) {BUG_ON ("unimplemented" ); } +static inline void vcpu_mark_events_pending (struct vcpu *v) {BUG_ON ("unimplemented" ); } +static inline void vcpu_update_evtchn_irq (struct vcpu *v) {BUG_ON ("unimplemented" ); } +static inline void vcpu_block_unless_event_pending (struct vcpu *v) {BUG_ON ("unimplemented" ); } + +static inline int vcpu_event_delivery_is_enabled (struct vcpu *v) +{ +BUG_ON ("unimplemented" ); +return 0 ; +} + +/* No arch specific virq definition now. Default to global. */ +static inline bool arch_virq_is_global (unsigned int virq) +{ +return true; +} + +static inline int local_events_need_delivery (void ) +{ +BUG_ON ("unimplemented" ); +return 0 ; +} + +static inline void local_event_delivery_enable (void ) +{ +BUG_ON ("unimplemented" ); +} + +#endif /* __ASM_PPC_EVENT_H__ */
xen/arch/ppc/include/asm/flushtlb.h new file +24 -0
@@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __ASM_PPC_FLUSHTLB_H__ +#define __ASM_PPC_FLUSHTLB_H__ + +#include <xen/cpumask.h> + +/* +* Filter the given set of CPUs, removing those that definitely flushed their +* TLB since @page_timestamp. +*/ +/* XXX lazy implementation just doesn't clear anything.... */ +static inline void tlbflush_filter (cpumask_t *mask,uint32_t page_timestamp) {} + +#define tlbflush_current_time () (0) + +static inline void page_set_tlbflush_timestamp (struct page_info *page) +{ + page->tlbflush_timestamp =tlbflush_current_time (); +} + +/* Flush specified CPUs' TLBs */ +void arch_flush_tlb_mask (const cpumask_t *mask); + +#endif /* __ASM_PPC_FLUSHTLB_H__ */
xen/arch/ppc/include/asm/grant_table.h new file +5 -0
@@ -0,0 +1,5 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __ASM_PPC_GRANT_TABLE_H__ +#define __ASM_PPC_GRANT_TABLE_H__ + +#endif /* __ASM_PPC_GRANT_TABLE_H__ */
xen/arch/ppc/include/asm/guest_access.h new file +68 -0
68 lines not on this page · raw message
xen/arch/ppc/include/asm/guest_atomics.h new file +23 -0
@@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __ASM_PPC_GUEST_ATOMICS_H__ +#define __ASM_PPC_GUEST_ATOMICS_H__ + +#include <xen/lib.h> + +/* TODO: implement */ +#define unimplemented_guest_bit_op (d, nr, p) ({ \ + (void)(d); \ + (void)(nr); \ + (void)(p); \ + BUG_ON("unimplemented"); \ + false; \ +}) + +#define guest_test_bit (d, nr, p) unimplemented_guest_bit_op(d, nr, p) +#define guest_clear_bit (d, nr, p) unimplemented_guest_bit_op(d, nr, p) +#define guest_set_bit (d, nr, p) unimplemented_guest_bit_op(d, nr, p) +#define guest_test_and_set_bit (d, nr, p) unimplemented_guest_bit_op(d, nr, p) +#define guest_test_and_clear_bit (d, nr, p) unimplemented_guest_bit_op(d, nr, p) +#define guest_test_and_change_bit (d, nr, p) unimplemented_guest_bit_op(d, nr, p) + +#endif /* __ASM_PPC_GUEST_ATOMICS_H__ */
xen/arch/ppc/include/asm/hardirq.h new file +19 -0
@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __ASM_PPC_HARDIRQ_H__ +#define __ASM_PPC_HARDIRQ_H__ + +#include <xen/cache.h> + +typedef struct { +unsigned long __softirq_pending; +unsigned int __local_irq_count; +} __cacheline_aligned irq_cpustat_t; + +#include <xen/irq_cpustat.h> /* Standard mappings for irq_cpustat_t above */ + +#define in_irq () (local_irq_count(smp_processor_id()) != 0) + +#define irq_enter () (local_irq_count(smp_processor_id())++) +#define irq_exit () (local_irq_count(smp_processor_id())--) + +#endif /* __ASM_PPC_HARDIRQ_H__ */
xen/arch/ppc/include/asm/hypercall.h new file +5 -0
@@ -0,0 +1,5 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __ASM_PPC_HYPERCALL_H__ +#define __ASM_PPC_HYPERCALL_H__ + +#endif /* __ASM_PPC_HYPERCALL_H__ */
xen/arch/ppc/include/asm/io.h new file +16 -0
@@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __ASM_PPC_IO_H__ +#define __ASM_PPC_IO_H__ + +#include <xen/lib.h> + +/* TODO */ +#define readb (c) ({ (void)(c); BUG_ON("unimplemented"); 0; }) +#define readw (c) ({ (void)(c); BUG_ON("unimplemented"); 0; }) +#define readl (c) ({ (void)(c); BUG_ON("unimplemented"); 0; }) + +#define writeb (v,c) ({ (void)(v); (void)(c); BUG_ON("unimplemented"); }) +#define writew (v,c) ({ (void)(v); (void)(c); BUG_ON("unimplemented"); }) +#define writel (v,c) ({ (void)(v); (void)(c); BUG_ON("unimplemented"); }) + +#endif /* __ASM_PPC_IO_H__ */
xen/arch/ppc/include/asm/iocap.h new file +8 -0
@@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __ASM_PPC_IOCAP_H__ +#define __ASM_PPC_IOCAP_H__ + +#define cache_flush_permitted (d) \ + (!rangeset_is_empty((d)->iomem_caps)) + +#endif /* __ASM_PPC_IOCAP_H__ */
xen/arch/ppc/include/asm/iommu.h new file +8 -0
@@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __ASM_PPC_IOMMU_H__ +#define __ASM_PPC_IOMMU_H__ + +struct arch_iommu { +}; + +#endif /* __ASM_PPC_IOMMU_H__ */
xen/arch/ppc/include/asm/irq.h new file +33 -0
@@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __ASM_PPC_IRQ_H__ +#define __ASM_PPC_IRQ_H__ + +#include <xen/lib.h> +#include <xen/device_tree.h> +#include <public/device_tree_defs.h> + +/* TODO */ +#define nr_irqs 0U +#define nr_static_irqs 0 +#define arch_hwdom_irqs (domid) 0U + +#define domain_pirq_to_irq (d, pirq) (pirq) + +struct arch_pirq { +}; + +struct arch_irq_desc { +unsigned int type; +}; + +static inline void arch_move_irqs (struct vcpu *v) +{ +BUG_ON ("unimplemented" ); +} + +static inline int platform_get_irq (const struct dt_device_node *device,int index) +{ +BUG_ON ("unimplemented" ); +} + +#endif /* __ASM_PPC_IRQ_H__ */
xen/arch/ppc/include/asm/mem_access.h new file +5 -0
@@ -0,0 +1,5 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __ASM_PPC_MEM_ACCESS_H__ +#define __ASM_PPC_MEM_ACCESS_H__ + +#endif /* __ASM_PPC_MEM_ACCESS_H__ */
xen/arch/ppc/include/asm/mm.h +242 -1
258 lines not on this page · raw message
xen/arch/ppc/include/asm/monitor.h new file +43 -0
43 lines not on this page · raw message
xen/arch/ppc/include/asm/nospec.h new file +15 -0
@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* From arch/arm/include/asm/nospec.h. */ +#ifndef __ASM_PPC_NOSPEC_H__ +#define __ASM_PPC_NOSPEC_H__ + +static inline bool evaluate_nospec (bool condition) +{ +return condition; +} + +static inline void block_speculation (void ) +{ +} + +#endif /* __ASM_PPC_NOSPEC_H__ */
xen/arch/ppc/include/asm/numa.h new file +26 -0
@@ -0,0 +1,26 @@ +#ifndef __ASM_PPC_NUMA_H__ +#define __ASM_PPC_NUMA_H__ + +#include <xen/types.h> +#include <xen/mm.h> + +typedef uint8_t nodeid_t ; + +/* Fake one node for now. See also node_online_map. */ +#define cpu_to_node (cpu) 0 +#define node_to_cpumask (node) (cpu_online_map) + +/* +* TODO: make first_valid_mfn static when NUMA is supported on PPC, this +* is required because the dummy helpers are using it. +*/ +extern mfn_t first_valid_mfn; + +/* XXX: implement NUMA support */ +#define node_spanned_pages (nid) (max_page - mfn_x(first_valid_mfn)) +#define node_start_pfn (nid) (mfn_x(first_valid_mfn)) +#define __node_distance (a, b) (20) + +#define arch_want_default_dmazone () (false) + +#endif /* __ASM_PPC_NUMA_H__ */
xen/arch/ppc/include/asm/p2m.h new file +95 -0
95 lines not on this page · raw message
xen/arch/ppc/include/asm/page.h +18 -0
@@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ #ifndef _ASM_PPC_PAGE_H#define _ASM_PPC_PAGE_H
@@ -36,6 +37,9 @@#define PTE_XEN_RO (PTE_XEN_BASE | PTE_EAA_READ)#define PTE_XEN_RX (PTE_XEN_BASE | PTE_EAA_READ | PTE_EAA_EXECUTE) +/* TODO */ +#define PAGE_HYPERVISOR 0 +/* * Radix Tree layout for 64KB pages: *
@@ -178,4 +182,18 @@ struct prtb_entry {void tlbie_all (void ); +static inline void invalidate_icache (void ) +{ +BUG_ON ("unimplemented" ); +} + +#define clear_page (page) memset(page, 0, PAGE_SIZE) +#define copy_page (dp, sp) memcpy(dp, sp, PAGE_SIZE) + +/* TODO: Flush the dcache for an entire page. */ +static inline void flush_page_to_ram (unsigned long mfn,bool sync_icache) +{ +BUG_ON ("unimplemented" ); +} +#endif /* _ASM_PPC_PAGE_H */
xen/arch/ppc/include/asm/paging.h new file +7 -0
@@ -0,0 +1,7 @@ +#ifndef __ASM_PPC_PAGING_H__ +#define __ASM_PPC_PAGING_H__ + +#define paging_mode_translate (d) (1) +#define paging_mode_external (d) (1) + +#endif /* __ASM_PPC_PAGING_H__ */
xen/arch/ppc/include/asm/pci.h new file +7 -0
@@ -0,0 +1,7 @@ +#ifndef __ASM_PPC_PCI_H__ +#define __ASM_PPC_PCI_H__ + +struct arch_pci_dev { +}; + +#endif /* __ASM_PPC_PCI_H__ */
xen/arch/ppc/include/asm/percpu.h new file +24 -0
@@ -0,0 +1,24 @@ +#ifndef __PPC_PERCPU_H__ +#define __PPC_PERCPU_H__ + +#ifndef __ASSEMBLY__ + +extern char __per_cpu_start[], __per_cpu_data_end[]; +extern unsigned long __per_cpu_offset[NR_CPUS ]; +void percpu_init_areas (void ); + +#define smp_processor_id () 0/* TODO: Fix this */ + +#define per_cpu (var, cpu) \ + (*RELOC_HIDE(&per_cpu__##var, __per_cpu_offset[cpu])) +#define this_cpu (var) \ + (*RELOC_HIDE(&per_cpu__##var, smp_processor_id())) + +#define per_cpu_ptr (var, cpu) \ + (*RELOC_HIDE(var, __per_cpu_offset[cpu])) +#define this_cpu_ptr (var) \ + (*RELOC_HIDE(var, smp_processor_id())) + +#endif + +#endif /* __PPC_PERCPU_H__ */
xen/arch/ppc/include/asm/processor.h +10 -0
@@ -110,6 +110,10 @@/* Macro to adjust thread priority for hardware multithreading */ #define HMT_very_low () asm volatile ( "or %r31, %r31, %r31" ) +/* TODO: This isn't correct */ +#define cpu_to_core (cpu) (0) +#define cpu_to_socket (cpu) (0) +/* * User-accessible registers: most of these need to be saved/restored * for every nested Xen invocation.
@@ -178,6 +182,12 @@ static inline void noreturn die(void)HMT_very_low (); } +/* +* Implemented on pre-POWER10 by setting HMT to low then to medium using +* the special OR forms. See HMT_very_low above. +*/ +#define cpu_relax () asm volatile ( "or %r1, %r1, %r1; or %r2, %r2, %r2" ) +#endif /* __ASSEMBLY__ */ #endif /* _ASM_PPC_PROCESSOR_H */
xen/arch/ppc/include/asm/random.h new file +9 -0
@@ -0,0 +1,9 @@ +#ifndef __ASM_PPC_RANDOM_H__ +#define __ASM_PPC_RANDOM_H__ + +static inline unsigned int arch_get_random (void ) +{ +return 0 ; +} + +#endif /* __ASM_PPC_RANDOM_H__ */
xen/arch/ppc/include/asm/setup.h new file +6 -0
@@ -0,0 +1,6 @@ +#ifndef __ASM_PPC_SETUP_H__ +#define __ASM_PPC_SETUP_H__ + +#define max_init_domid (0) + +#endif /* __ASM_PPC_SETUP_H__ */
xen/arch/ppc/include/asm/smp.h new file +18 -0
@@ -0,0 +1,18 @@ +#ifndef __ASM_SMP_H +#define __ASM_SMP_H + +#include <xen/cpumask.h> +#include <xen/percpu.h> + +DECLARE_PER_CPU (cpumask_var_t, cpu_sibling_mask); +DECLARE_PER_CPU (cpumask_var_t, cpu_core_mask); + +#define cpu_is_offline (cpu) unlikely(!cpu_online(cpu)) + +/* +* Do we, for platform reasons, need to actually keep CPUs online when we +* would otherwise prefer them to be off? +*/ +#define park_offline_cpus false + +#endif
xen/arch/ppc/include/asm/softirq.h new file +8 -0
@@ -0,0 +1,8 @@ +#ifndef __ASM_PPC_SOFTIRQ_H__ +#define __ASM_PPC_SOFTIRQ_H__ + +#define NR_ARCH_SOFTIRQS 0 + +#define arch_skip_send_event_check (cpu) 0 + +#endif /* __ASM_PPC_SOFTIRQ_H__ */
xen/arch/ppc/include/asm/spinlock.h new file +15 -0
@@ -0,0 +1,15 @@ +#ifndef __ASM_SPINLOCK_H +#define __ASM_SPINLOCK_H + +#define arch_lock_acquire_barrier () smp_mb() +#define arch_lock_release_barrier () smp_mb() + +#define arch_lock_relax () cpu_relax() +#define arch_lock_signal () +#define arch_lock_signal_wmb () \ +({ \ + smp_wmb(); \ + arch_lock_signal(); \ +}) + +#endif /* __ASM_SPINLOCK_H */
xen/arch/ppc/include/asm/system.h +218 -1
224 lines not on this page · raw message
xen/arch/ppc/include/asm/time.h new file +23 -0
@@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __ASM_PPC_TIME_H__ +#define __ASM_PPC_TIME_H__ + +#include <xen/lib.h> +#include <asm/processor.h> +#include <asm/regs.h> + +struct vcpu ; + +/* TODO: implement */ +static inline void force_update_vcpu_system_time (struct vcpu *v) { +BUG_ON ("unimplemented" ); +} + +typedef unsigned long cycles_t ; + +static inline cycles_t get_cycles (void ) +{ +return mfspr (SPRN_TBRL ); +} + +#endif /* __ASM_PPC_TIME_H__ */
xen/arch/ppc/include/asm/xenoprof.h new file +0 -0
xen/arch/ppc/mm-radix.c +1 -1
@@ -1,13 +1,13 @@/* SPDX-License-Identifier: GPL-2.0-or-later */ #include <xen/init.h> #include <xen/kernel.h> +#include <xen/mm.h> #include <xen/types.h> #include <xen/lib.h> #include <asm/bitops.h> #include <asm/byteorder.h> #include <asm/early_printk.h> -#include <asm/mm.h> #include <asm/page.h> #include <asm/processor.h> #include <asm/regs.h>
xen/arch/ppc/tlb-radix.c +1 -1
@@ -5,9 +5,9 @@* * Copyright 2015-2016, Aneesh Kumar K.V, IBM Corporation. */ +#include <xen/bitops.h> #include <xen/stringify.h> -#include <asm/bitops.h> #include <asm/msr.h> #include <asm/processor.h>
xen/include/public/hvm/save.h +2 -0
@@ -89,6 +89,8 @@ DECLARE_HVM_SAVE_TYPE(END, 0, struct hvm_save_end);#include "../arch-x86/hvm/save.h" #elif defined(__arm__) || defined(__aarch64__)#include "../arch-arm/hvm/save.h" +#elif defined(__powerpc64__) +#include "../arch-ppc.h" #else #error "unsupported architecture"#endif
xen/include/public/pmu.h +2 -0
@@ -11,6 +11,8 @@#include "arch-x86/pmu.h" #elif defined (__arm__) || defined (__aarch64__)#include "arch-arm.h" +#elif defined (__powerpc64__) +#include "arch-ppc.h" #else #error "Unsupported architecture"#endif
xen/include/public/xen.h +2 -0
@@ -16,6 +16,8 @@#include "arch-x86/xen.h" #elif defined(__arm__) || defined (__aarch64__)#include "arch-arm.h" +#elif defined(__powerpc64__) +#include "arch-ppc.h" #else #error "Unsupported architecture"#endif
--
2.30.2
PATCH v5 4/5 xen/ppc: Add stub function and symbol definitions
In reply to Shawn AnastasioAdd stub function and symbol definitions required by common code. If the file that the definition is supposed to be located in doesn't already exist yet, temporarily place its definition in the new stubs.c
---
v5: No changes.
v4: No changes.
v3:
- (stubs.c) Drop ack_none hook definition
v2:
- Use BUG_ON("unimplemented") instead of BUG() for unimplemented functions to make searching easier.
- (mm-radix.c) Drop total_pages definition
- (mm-radix.c) Move __read_mostly from after variable name to before it in declaration of frametable_base_pdx
- (setup.c) Fix include order
- (stubs.c) Drop stub .end hw_irq_controller hook
xen/arch/ppc/Makefile | 1 + xen/arch/ppc/mm-radix.c | 42 +++++ xen/arch/ppc/setup.c | 8 + xen/arch/ppc/stubs.c | 339 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 390 insertions(+) create mode 100644 xen/arch/ppc/stubs.c
xen/arch/ppc/Makefile +1 -0
@@ -4,6 +4,7 @@ obj-$(CONFIG_EARLY_PRINTK) += early_printk.init.o obj-y += mm-radix.o obj-y += opal.o obj-y += setup.o +obj-y += stubs.o obj-y += tlb-radix.o $(TARGET): $(TARGET)-syms
xen/arch/ppc/mm-radix.c +42 -0
45 lines not on this page · raw message
xen/arch/ppc/setup.c +8 -0
@@ -1,5 +1,8 @@/* SPDX-License-Identifier: GPL-2.0-or-later */ #include <xen/init.h> +#include <xen/lib.h> +#include <xen/mm.h> +#include <public/version.h> #include <asm/boot.h> #include <asm/early_printk.h> #include <asm/mm.h>
@@ -33,3 +36,8 @@ void __init noreturn start_xen(unsigned long r3, unsigned long r4,unreachable (); } + +void arch_get_xen_caps (xen_capabilities_info_t *info) +{ +BUG_ON ("unimplemented" ); +}
xen/arch/ppc/stubs.c new file +339 -0
339 lines not on this page · raw message
--
2.30.2
PATCH v5 5/5 xen/ppc: Enable full Xen build
In reply to Shawn AnastasioBring ppc's Makefile and arch.mk in line with arm and x86 to disable the build overrides and enable the full Xen build.
--- xen/arch/ppc/Makefile | 16 +++++++++++++++- xen/arch/ppc/arch.mk | 3 --- 2 files changed, 15 insertions(+), 4 deletions(-)
xen/arch/ppc/Makefile +15 -1
@@ -11,10 +11,24 @@ $(TARGET): $(TARGET)-syms cp -f $< $@ $(TARGET)-syms: $(objtree)/prelink.o $(obj)/xen.lds - $(LD) $(XEN_LDFLAGS) -T $(obj)/xen.lds -N $< $(build_id_linker) -o $@ + $(LD) $(XEN_LDFLAGS) -T $(obj)/xen.lds -N $< \ + $(objtree)/common/symbols-dummy.o -o $(dot-target).0 + $(NM) -pa --format=sysv $(dot-target).0 \ + | $(objtree)/tools/symbols $(all_symbols) --sysv --sort \ + > $(dot-target).0.S + $(MAKE) $(build)=$(@D) $(dot-target).0.o + $(LD) $(XEN_LDFLAGS) -T $(obj)/xen.lds -N $< \ + $(dot-target).0.o -o $(dot-target).1 + $(NM) -pa --format=sysv $(dot-target).1 \ + | $(objtree)/tools/symbols $(all_symbols) --sysv --sort \ + > $(dot-target).1.S + $(MAKE) $(build)=$(@D) $(dot-target).1.o + $(LD) $(XEN_LDFLAGS) -T $(obj)/xen.lds -N $< $(build_id_linker) \ + $(dot-target).1.o -o $@ $(NM) -pa --format=sysv $@ \ | $(objtree)/tools/symbols --all-symbols --xensyms --sysv --sort \ > [email protected] + rm -f $(@D)/.$(@F).[0-9]* $(obj)/xen.lds: $(src)/xen.lds.S FORCE $(call if_changed_dep,cpp_lds_S)
xen/arch/ppc/arch.mk +0 -3
@@ -7,6 +7,3 @@ CFLAGS += -m64 -mlittle-endian -mcpu=$(ppc-march-y) CFLAGS += -mstrict-align -mcmodel=medium -mabi=elfv2 -fPIC -mno-altivec -mno-vsx -msoft-float LDFLAGS += -m elf64lppc - -# TODO: Drop override when more of the build is working -override ALL_OBJS-y = arch/$(SRCARCH)/built_in.o common/libfdt/built_in.o lib/built_in.o
Signature · 1 line
2.30.2