powerpc: Add Initiate Coprocessor Store Word (icswx) support
PATCH 1/1 powerpc: Add Initiate Coprocessor Store Word (icswx) support
From: Tseng-Hui (Frank) Lin <[email protected]>
Icswx is a PowerPC instruction to send data to a co-processor. On Book-S processors the LPAR_ID and process ID (PID) of the owning process are registered in the window context of the co-processor at initialization time. When the icswx instruction is executed the L2 generates a cop-reg transaction on PowerBus. The transaction has no address and the processor does not perform an MMU access to authenticate the transaction. The co-processor compares the LPAR_ID and the PID included in the transaction and the LPAR_ID and PID held in the window context to determine if the process is authorized to generate the transaction.
The OS needs to assign a 16-bit PID for the process. This cop-PID needs to be updated during context switch. The cop-PID needs to be destroyed when the context is destroyed.
---
Changes:
- By including linux/spinlock_types.h we can remove the dynamic allocation of the spinlock hack and simplify things a lot.
- We had a nasty bug with threaded applications. We weren't ensuring all running threads saw the updates from a use_cop or drop_cop call. We could even reuse an active PID if one threaded app did a drop_cop and had other running threads. In that case we return the PID to the pool even though some running threads are using it. We now call sync_cop() on all cpus if the app is threaded, ensuring everyone sees the updates of a use_cop or drop_cop call.
arch/powerpc/include/asm/cputable.h +3 -1
@@ -202,6 +202,7 @@ extern const char *powerpc_base_platform;#define CPU_FTR_STCX_CHECKS_ADDRESS LONG_ASM_CONST(0x0200000000000000)#define CPU_FTR_POPCNTB LONG_ASM_CONST(0x0400000000000000)#define CPU_FTR_POPCNTD LONG_ASM_CONST(0x0800000000000000) +#define CPU_FTR_ICSWX LONG_ASM_CONST(0x1000000000000000)#ifndef __ASSEMBLY__
@@ -421,7 +422,8 @@ extern const char *powerpc_base_platform; CPU_FTR_COHERENT_ICACHE | CPU_FTR_LOCKLESS_TLBIE | \ CPU_FTR_PURR | CPU_FTR_SPURR | CPU_FTR_REAL_LE | \ CPU_FTR_DSCR | CPU_FTR_SAO | CPU_FTR_ASYM_SMT | \ - CPU_FTR_STCX_CHECKS_ADDRESS | CPU_FTR_POPCNTB | CPU_FTR_POPCNTD) + CPU_FTR_STCX_CHECKS_ADDRESS | CPU_FTR_POPCNTB | CPU_FTR_POPCNTD | \ + CPU_FTR_ICSWX)#define CPU_FTRS_CELL (CPU_FTR_USE_TB | CPU_FTR_LWSYNC | \ CPU_FTR_PPCAS_ARCH_V2 | CPU_FTR_CTRL | \ CPU_FTR_ALTIVEC_COMP | CPU_FTR_MMCRA | CPU_FTR_SMT | \
arch/powerpc/include/asm/mmu-hash64.h +7 -0
@@ -32,6 +32,8 @@#define STAB0_PHYS_ADDR (STAB0_OFFSET + PHYSICAL_START)#ifndef __ASSEMBLY__ +#include <linux/spinlock_types.h> +extern char initial_stab[];#endif /* ! __ASSEMBLY */
@@ -423,6 +425,11 @@ typedef struct {#ifdef CONFIG_PPC_SUBPAGE_PROT struct subpage_prot_table spt;#endif /* CONFIG_PPC_SUBPAGE_PROT */ +#ifdef CONFIG_PPC_ICSWX +struct spinlock cop_lock;/* guard acop and cop_pid */ +unsigned long acop;/* mask of enabled coprocessor types */ +unsigned int cop_pid;/* pid value used with coprocessors */ +#endif /* CONFIG_PPC_ICSWX */ } mm_context_t;
arch/powerpc/include/asm/mmu_context.h +10 -0
@@ -32,6 +32,10 @@ extern void __destroy_context(unsigned long context_id);extern void mmu_context_init (void );#endif +extern void switch_cop (struct mm_struct *next); +extern int use_cop (unsigned long acop,struct mm_struct *mm); +extern void drop_cop (unsigned long acop,struct mm_struct *mm); +/* * switch_mm is the entry point called from the architecture independent * code in kernel/sched.c
@@ -55,6 +59,12 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,if (prev == next)return ; +#ifdef CONFIG_PPC_ICSWX +/* Switch coprocessor context only if prev or next uses a coprocessor */ +if (prev->context.acop || next->context.acop) +switch_cop (next); +#endif /* CONFIG_PPC_ICSWX */ +/* We must stop all altivec streams before changing the HW * context */
arch/powerpc/include/asm/reg.h +1 -0
@@ -182,6 +182,7 @@#define SPRN_CTR 0x009/* Count Register */ #define SPRN_DSCR 0x11 +#define SPRN_ACOP 0x1F/* Available Coprocessor Register */ #define SPRN_CTRLF 0x088#define SPRN_CTRLT 0x098#define CTRL_CT 0xc0000000/* current thread */
arch/powerpc/mm/mmu_context_hash64.c +202 -0
223 lines not on this page · raw message
arch/powerpc/platforms/Kconfig.cputype +18 -0
@@ -226,6 +226,24 @@ config VSX If in doubt, say Y here. +config PPC_ICSWX + bool "Support for PowerPC icswx coprocessor instruction" + depends on POWER4 + default n + ---help--- + + This option enables kernel support for the PowerPC Initiate + Coprocessor Store Word (icswx) coprocessor instruction on POWER7 + or newer processors. + + This option is only useful if you have a processor that supports + the icswx coprocessor instruction. It does not have any effect + on processors without the icswx coprocessor instruction. + + This option slightly increases kernel memory usage. + + If in doubt, say N here. + config SPE bool "SPE Support" depends on E200 || (E500 && !PPC_E500MC)
Quoted 3 lines · Anton Blanchard
- By including
linux/spinlock_types.hwe can remove the dynamic allocation
of the spinlock hack and simplify things a lot.
Causes all sort of hell for me on some configs. Lockdep is not happy for example and there's some nasty include dependency circles. Not sure that's fixable at least not without some important cleanup of how mmu_context_t is defined.
Ben.