POWER8 Coherent Accelerator device driver
Subsystems (5)
v4 cover POWER8 Coherent Accelerator device driver
This is the latest version of the cxl driver. Change log below:
v4:
- Updates based on comments from mpe (offline and online).
- Refactor the sstp lock to be an entry lock.
- Fixed error paths on new status_mutex in start_work
- added some missing include files
- moved associating pid/mm from open() to start_work ioctl.
- improved IDR setup and destroy
- fix block comments.
- remove #undef at top of files
- wed -> work_element_descriptor on user visible interfaces
- Lots of documentation updates.
- Device name changes.
- No longer has a default dev name /dev/afuM.N for each mode.
- Dedicated, slave and master all have distinct char devs.
- Prevent AFU reset when contexts active.
- Endian bug fix for find_free_sste().
- Fix locking on reset_store_afu.
- Make CXL_IOCTL_GET_PROCESS_ELEMENT return a __u32 instead of int.
- Rename event.afu_err.err to error
- Fixed master specific sysfs attribute creation
- fix sparse errors with debugfs. Was passing iomem ptrs to userspace.
v3:
- Updates based on comments from mpe, benh, aneesh and offline reviews.
- Fixed bug freeing AFU IRQs that also freed the multiplexed PSL IRQ
- Change copro_flush_all_slbs to a static inline as suggested by mpe
- Implement sanitisation routines to clear out more registers and do full adapter wide tlbia and slbia when initialising hardware
- Add self testcase to msi_bitmap to test allocations are aligned to a power of 2 and cleanup comment as suggested by mpe
- Clean up cxl_use_count
- Split out detach_process_native into two logical functions
- Improve comment in set_msi_irq_chip as requested by mpe
- Move cxl functions in pci-ioda.c to be under just one #ifdef CONFIG_CXL_BASE
- Cleanup hash_page and hash_page_mm from mpes and Aneesh' reviews
- Remove dead code in cxl_alloc_sst
- Add timeout in afu_slbia_native
- Remove cxl backend and driver ops abstractions
- Removed separate cxl-pci module
- Merged cxl pci module init calls into main driver init
- Refactor afu_read() to be a bit simpler and more closely follow exising patterns in the kernel
- Userspace API updates from reviews:
- Added ioctl to get the process element number, and removed it as a return from the start work ioctl
- Alter cxl_event to have one common header struct
- Dropped check error ioctl
- Added current and binary compatible API version numbers to sysfs
- read() now takes a 4K (or greater) buffer
- Pack event structs to reduce unecessary reserved fields
- Event sizes can now differ
- All event sizes are 64bit multiples to allow future event coalescing
- Add flags fields to indicate which fields contain valid data
- Add BUILD_BUG_ONs to protect against inadvertantly changing API without bumping version number and/or flags
- Update documentation
- Skip CXL SLBIA codepath if CXL is not in use
- Split cxl_slbia_core into two functions to be easier to read
- Refactor copro_data_segment (renamed to copro_calc_slb) since we are no longer merging with hash_page and cleaned up parameters.
- Some renames:
- struct cxl_t -> struct cxl
- struct cxl_afu_t -> struct cxl_afu
- struct cxl_context_t -> struct cxl_context
- copro_data_segment -> copro_calc_slb
- ctx->ph -> ctx->pe
- Added ctx->status mutex lock around for start and release context
v2:
- Updates based on comments from, Anton, Gavin, Aneesh, jk and offline reviews
- Simplified copro_data_segment() and merged code with hash_page_mm()
(New patch 10/17)
- PCIe code simplifications based on Gavin's review
- Removed redundant comment in msi_bitmap_alloc_hwirqs()
- Fix for locking in idr_remove in core driver
- Ensure PSL is enabled when PHB is flipped to CXL mode
- Added CONFIG_PPC_COPRO_BASE to compile copro_fault.c
- Merged SPU and cxl slb flushing calls into copro_flush_all_slbs()
(New patch 03/17) - Moved slb_vsid_shift() to static inline from #define
- Don't write paca->context when demoting segments and mm != current
- Fix minor typos in documentation
v1:
- Initial post
This add support for the Coherent Accelerator (cxl) attached to POWER8 processors. This coherent accelerator interface is designed to allow the coherent connection of FPGA based accelerators (and other devices) to a POWER systems.
IBM refers to this as the Coherent Accelerator Processor Interface or CAPI. In this driver it's referred to by the name cxl to avoid confusion with the ISDN CAPI subsystem.
An overview of the patches:
Patches 1-3: Split some of the old Cell co-processor code out so it can be
reused.
Patches 4-10: Add infrastructure to arch/powerpc needed by cxl. Patches 11: Add call backs needed for invalidating cxl mm contexts. Patch 12: Add cxl specific support that needs to be built in to the
kernel (can't be a module).
Patches 13-15: Add the majority of the device driver and API header.
Patch 16: Documentation.
The documentation in this last patch gives an overview of the hardware architecture as well as the userspace API.
The cxl driver has a user-space interface described in include/uapi/misc/cxl.h and Documentation/powerpc/cxl.txt. There are two ioctls which can be used to talk to the driver once the new /dev/cxl/afu0.0 device is opened. This device can also be read and mmaped.
There's also sysfs entries used to communicate information about the cxl configuration to userspace. These are documented in Documentation/ABI/testing/sysfs-class-cxl.
Many contributed to this device driver but Ian Munsie is the principal author.
Driver can also be found here (based on 3.17-rc5):
git://github.com/mikey/linux.git cxl
https://github.com/mikey/linux/commits/cxl
(Series rebases on recent linux-next with one trivial include file conflict)
Please consider for inclusion. Feedback welcome!
Regards,
Mikey
PATCH v4 1/16 powerpc/cell: Move spu_handle_mm_fault() out of cell platform
From: Ian Munsie <[email protected]>
Currently spu_handle_mm_fault() is in the cell platform.
This code is generically useful for other non-cell co-processors on powerpc.
This patch moves this function out of the cell platform into arch/powerpc/mm so that others may use it.
---
arch/powerpc/Kconfig | 4 ++++
arch/powerpc/include/asm/copro.h | 16 ++++++++++++++++
arch/powerpc/include/asm/spu.h | 5 ++---
arch/powerpc/mm/Makefile | 1 +
.../{platforms/cell/spu_fault.c => mm/copro_fault.c} | 14 ++++++--------
arch/powerpc/platforms/cell/Kconfig | 1 +
arch/powerpc/platforms/cell/Makefile | 2 +-
arch/powerpc/platforms/cell/spufs/fault.c | 4 ++--
8 files changed, 33 insertions(+), 14 deletions(-)
create mode 100644 arch/powerpc/include/asm/copro.h
rename arch/powerpc/{platforms/cell/spu_fault.c => mm/copro_fault.c} (89%)arch/powerpc/Kconfig +4 -0
@@ -603,6 +603,10 @@ config PPC_SUBPAGE_PROT to set access permissions (read/write, readonly, or no access) on the 4k subpages of each 64k page. +config PPC_COPRO_BASE + bool + default n + config SCHED_SMT bool "SMT (Hyperthreading) scheduler support" depends on PPC64 && SMP
arch/powerpc/include/asm/copro.h new file +16 -0
@@ -0,0 +1,16 @@ +/* +* Copyright 2014 IBM Corp. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version +* 2 of the License, or (at your option) any later version. +*/ + +#ifndef _ASM_POWERPC_COPRO_H +#define _ASM_POWERPC_COPRO_H + +int copro_handle_mm_fault (struct mm_struct *mm,unsigned long ea, +unsigned long dsisr,unsigned *flt); + +#endif /* _ASM_POWERPC_COPRO_H */
arch/powerpc/include/asm/spu.h +2 -3
@@ -27,6 +27,8 @@#include <linux/workqueue.h> #include <linux/device.h> #include <linux/mutex.h> +#include <asm/reg.h> +#include <asm/copro.h> #define LS_SIZE (256 * 1024)#define LS_ADDR_MASK (LS_SIZE - 1)
@@ -277,9 +279,6 @@ void spu_remove_dev_attr(struct device_attribute *attr);int spu_add_dev_attr_group (struct attribute_group *attrs);void spu_remove_dev_attr_group (struct attribute_group *attrs); -int spu_handle_mm_fault (struct mm_struct *mm,unsigned long ea, -unsigned long dsisr,unsigned *flt); -/* * Notifier blocks: *
arch/powerpc/mm/Makefile +1 -0
@@ -34,3 +34,4 @@ obj-$(CONFIG_TRANSPARENT_HUGEPAGE) += hugepage-hash64.o obj-$(CONFIG_PPC_SUBPAGE_PROT) += subpage-prot.o obj-$(CONFIG_NOT_COHERENT_CACHE) += dma-noncoherent.o obj-$(CONFIG_HIGHMEM) += highmem.o +obj-$(CONFIG_PPC_COPRO_BASE) += copro_fault.o
arch/powerpc/mm/copro_fault.c renamed from arch/powerpc/platforms/cell/spu_fault.c +6 -8
@@ -1,5 +1,5 @@/* -* SPU mm fault handler +* CoProcessor (SPU/AFU) mm fault handler * * (C) Copyright IBM Deutschland Entwicklung GmbH 2007 *
@@ -23,16 +23,14 @@#include <linux/sched.h> #include <linux/mm.h> #include <linux/export.h> - -#include <asm/spu.h> -#include <asm/spu_csa.h> +#include <asm/reg.h> /* * This ought to be kept in sync with the powerpc specific do_page_fault * function. Currently, there are a few corner cases that we haven't had * to handle fortunately. */ -int spu_handle_mm_fault (struct mm_struct *mm,unsigned long ea, +int copro_handle_mm_fault (struct mm_struct *mm,unsigned long ea,unsigned long dsisr,unsigned *flt) {struct vm_area_struct *vma;
@@ -58,12 +56,12 @@ int spu_handle_mm_fault(struct mm_struct *mm, unsigned long ea, goto out_unlock; } - is_write = dsisr &MFC_DSISR_ACCESS_PUT ; + is_write = dsisr &DSISR_ISSTORE ;if (is_write) {if (!(vma->vm_flags &VM_WRITE )) goto out_unlock; }else { -if (dsisr &MFC_DSISR_ACCESS_DENIED ) +if (dsisr &DSISR_PROTFAULT ) goto out_unlock;if (!(vma->vm_flags & (VM_READ |VM_EXEC ))) goto out_unlock;
@@ -91,4 +89,4 @@ out_unlock:up_read (&mm->mmap_sem);return ret; } -EXPORT_SYMBOL_GPL (spu_handle_mm_fault); +EXPORT_SYMBOL_GPL (copro_handle_mm_fault);
arch/powerpc/platforms/cell/Kconfig +1 -0
@@ -86,6 +86,7 @@ config SPU_FS_64K_LS config SPU_BASE bool default n + select PPC_COPRO_BASE config CBE_RAS bool "RAS features for bare metal Cell BE"
arch/powerpc/platforms/cell/Makefile +1 -1
@@ -20,7 +20,7 @@ spu-manage-$(CONFIG_PPC_CELL_COMMON) += spu_manage.o obj-$(CONFIG_SPU_BASE) += spu_callbacks.o spu_base.o \ spu_notify.o \ - spu_syscalls.o spu_fault.o \ + spu_syscalls.o \ $(spu-priv1-y) \ $(spu-manage-y) \ spufs/
arch/powerpc/platforms/cell/spufs/fault.c +2 -2
@@ -138,7 +138,7 @@ int spufs_handle_class1(struct spu_context *ctx)if (ctx->state ==SPU_STATE_RUNNABLE ) ctx->spu->stats.hash_flt++; -/* we must not hold the lock when entering spu_handle_mm_fault */ +/* we must not hold the lock when entering copro_handle_mm_fault */ spu_release (ctx); access = (_PAGE_PRESENT | _PAGE_USER);
@@ -149,7 +149,7 @@ int spufs_handle_class1(struct spu_context *ctx)/* hashing failed, so try the actual fault handler */ if (ret) - ret =spu_handle_mm_fault (current->mm, ea, dsisr, &flt); + ret =copro_handle_mm_fault (current->mm, ea, dsisr, &flt);/* * This is nasty: we need the state_mutex for all the bookkeeping even
Signature · 1 line
1.9.1
Re: [PATCH v4 01/16] powerpc/cell: Move spu_handle_mm_fault() out of cell platform
Quoted 9 lines · Michael Neuling
From: Ian Munsie <[email protected]>
Currently
spu_handle_mm_fault()is in the cell platform.This code is generically useful for other non-cell co-processors on powerpc.
This patch moves this function out of the cell platform into
arch/powerpc/mmso that others may use it.
Quoted 193 lines
Signed-off-by Ian Munsie <[email protected]>Signed-off-by Michael Neuling <[email protected]>--- arch/powerpc/Kconfig | 4 ++++ arch/powerpc/include/asm/copro.h | 16 ++++++++++++++++ arch/powerpc/include/asm/spu.h | 5 ++--- arch/powerpc/mm/Makefile | 1 + .../{platforms/cell/spu_fault.c => mm/copro_fault.c} | 14 ++++++-------- arch/powerpc/platforms/cell/Kconfig | 1 + arch/powerpc/platforms/cell/Makefile | 2 +- arch/powerpc/platforms/cell/spufs/fault.c | 4 ++-- 8 files changed, 33 insertions(+), 14 deletions(-) create mode 100644 arch/powerpc/include/asm/copro.h rename arch/powerpc/{platforms/cell/spu_fault.c => mm/copro_fault.c} (89%)arch/powerpc/Kconfig +4
-0@@ -603,6 +603,10 @@ config PPC_SUBPAGE_PROT to set access permissions (read/write, readonly, or no access) on the 4k subpages of each 64k page. +config PPC_COPRO_BASE + bool + default n + config SCHED_SMT bool "SMT (Hyperthreading) scheduler support" depends on PPC64 && SMParch/powerpc/include/asm/copro.h new file +16
-0@@ -0,0 +1,16 @@ +/* +* Copyright 2014 IBM Corp. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version +* 2 of the License, or (at your option) any later version. +*/ + +#ifndef _ASM_POWERPC_COPRO_H +#define _ASM_POWERPC_COPRO_H + +int copro_handle_mm_fault (struct mm_struct *mm,unsigned long ea, +unsigned long dsisr,unsigned *flt); + +#endif /* _ASM_POWERPC_COPRO_H */ arch/powerpc/include/asm/spu.h +2
-3@@ -27,6 +27,8 @@#include <linux/workqueue.h> #include <linux/device.h> #include <linux/mutex.h> +#include <asm/reg.h> +#include <asm/copro.h> #define LS_SIZE (256 * 1024)#define LS_ADDR_MASK (LS_SIZE - 1)@@ -277,9 +279,6 @@ void spu_remove_dev_attr(struct device_attribute *attr);int spu_add_dev_attr_group (struct attribute_group *attrs);void spu_remove_dev_attr_group (struct attribute_group *attrs); -int spu_handle_mm_fault (struct mm_struct *mm,unsigned long ea, -unsigned long dsisr,unsigned *flt); -/* * Notifier blocks: * arch/powerpc/mm/Makefile +1
-0@@ -34,3 +34,4 @@ obj-$(CONFIG_TRANSPARENT_HUGEPAGE) += hugepage-hash64.o obj-$(CONFIG_PPC_SUBPAGE_PROT) += subpage-prot.o obj-$(CONFIG_NOT_COHERENT_CACHE) += dma-noncoherent.o obj-$(CONFIG_HIGHMEM) += highmem.o +obj-$(CONFIG_PPC_COPRO_BASE) += copro_fault.oarch/powerpc/mm/copro_fault.c renamed from arch/powerpc/platforms/cell/spu_fault.c +6
-8@@ -1,5 +1,5 @@/* -* SPU mm fault handler +* CoProcessor (SPU/AFU) mm fault handler * * (C) Copyright IBM Deutschland Entwicklung GmbH 2007 * @@ -23,16 +23,14 @@#include <linux/sched.h> #include <linux/mm.h> #include <linux/export.h> - -#include <asm/spu.h> -#include <asm/spu_csa.h> +#include <asm/reg.h> /* * This ought to be kept in sync with the powerpc specific do_page_fault * function. Currently, there are a few corner cases that we haven't had * to handle fortunately. */ -int spu_handle_mm_fault (struct mm_struct *mm,unsigned long ea, +int copro_handle_mm_fault (struct mm_struct *mm,unsigned long ea,unsigned long dsisr,unsigned *flt) {struct vm_area_struct *vma;@@ -58,12 +56,12 @@ int spu_handle_mm_fault(struct mm_struct *mm, unsigned long ea, goto out_unlock; } - is_write = dsisr &MFC_DSISR_ACCESS_PUT ; + is_write = dsisr &DSISR_ISSTORE ;if (is_write) {if (!(vma->vm_flags &VM_WRITE )) goto out_unlock; }else { -if (dsisr &MFC_DSISR_ACCESS_DENIED ) +if (dsisr &DSISR_PROTFAULT ) goto out_unlock;if (!(vma->vm_flags & (VM_READ |VM_EXEC ))) goto out_unlock;@@ -91,4 +89,4 @@ out_unlock:up_read (&mm->mmap_sem);return ret; } -EXPORT_SYMBOL_GPL (spu_handle_mm_fault); +EXPORT_SYMBOL_GPL (copro_handle_mm_fault);arch/powerpc/platforms/cell/Kconfig +1
-0@@ -86,6 +86,7 @@ config SPU_FS_64K_LS config SPU_BASE bool default n + select PPC_COPRO_BASE config CBE_RAS bool "RAS features for bare metal Cell BE"arch/powerpc/platforms/cell/Makefile +1
-1@@ -20,7 +20,7 @@ spu-manage-$(CONFIG_PPC_CELL_COMMON) += spu_manage.o obj-$(CONFIG_SPU_BASE) += spu_callbacks.o spu_base.o \ spu_notify.o \ - spu_syscalls.o spu_fault.o \ + spu_syscalls.o \ $(spu-priv1-y) \ $(spu-manage-y) \ spufs/arch/powerpc/platforms/cell/spufs/fault.c +2
-2@@ -138,7 +138,7 @@ int spufs_handle_class1(struct spu_context *ctx)if (ctx->state ==SPU_STATE_RUNNABLE ) ctx->spu->stats.hash_flt++; -/* we must not hold the lock when entering spu_handle_mm_fault */ +/* we must not hold the lock when entering copro_handle_mm_fault */ spu_release (ctx); access = (_PAGE_PRESENT | _PAGE_USER);@@ -149,7 +149,7 @@ int spufs_handle_class1(struct spu_context *ctx)/* hashing failed, so try the actual fault handler */ if (ret) - ret =spu_handle_mm_fault (current->mm, ea, dsisr, &flt); + ret =copro_handle_mm_fault (current->mm, ea, dsisr, &flt);/* * This is nasty: we need the state_mutex for all the bookkeeping even Signature · 7 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
PATCH v4 2/16 powerpc/cell: Move data segment faulting code out of cell platform
In reply to Michael NeulingFrom: Ian Munsie <[email protected]>
__spu_trap_data_seg() currently contains code to determine the VSID and ESID required for a particular EA and mm struct.
This code is generically useful for other co-processors. This moves the code of the cell platform so it can be used by other powerpc code. It also adds 1TB segment handling which Cell didn't support. The new function is called copro_calculate_slb().
This also moves the internal struct spu_slb to a generic struct copro_slb which is now used in the Cell and copro code. We use this new struct instead of passing around esid and vsid parameters.
--- arch/powerpc/include/asm/copro.h | 7 +++++ arch/powerpc/include/asm/mmu-hash64.h | 7 +++++ arch/powerpc/mm/copro_fault.c | 46 ++++++++++++++++++++++++++++ arch/powerpc/mm/slb.c | 3 -- arch/powerpc/platforms/cell/spu_base.c | 55 ++++++---------------------------- 5 files changed, 69 insertions(+), 49 deletions(-)
arch/powerpc/include/asm/copro.h +7 -0
@@ -10,7 +10,14 @@#ifndef _ASM_POWERPC_COPRO_H#define _ASM_POWERPC_COPRO_H +struct copro_slb +{ +u64 esid, vsid; +}; +int copro_handle_mm_fault (struct mm_struct *mm,unsigned long ea,unsigned long dsisr,unsigned *flt); +int copro_calculate_slb (struct mm_struct *mm,u64 ea,struct copro_slb *slb); +#endif /* _ASM_POWERPC_COPRO_H */
arch/powerpc/include/asm/mmu-hash64.h +7 -0
@@ -190,6 +190,13 @@ static inline unsigned int mmu_psize_to_shift(unsigned int mmu_psize)#ifndef __ASSEMBLY__ +static inline int slb_vsid_shift (int ssize) +{ +if (ssize ==MMU_SEGSIZE_256M ) +return SLB_VSID_SHIFT ; +return SLB_VSID_SHIFT_1T ; +} +static inline int segment_shift (int ssize) {if (ssize ==MMU_SEGSIZE_256M )
arch/powerpc/mm/copro_fault.c +46 -0
55 lines not on this page · raw message
arch/powerpc/mm/slb.c +0 -3
@@ -46,9 +46,6 @@ static inline unsigned long mk_esid_data(unsigned long ea, int ssize,return (ea &slb_esid_mask (ssize)) |SLB_ESID_V | slot; } -#define slb_vsid_shift (ssize) \ - ((ssize) == MMU_SEGSIZE_256M? SLB_VSID_SHIFT: SLB_VSID_SHIFT_1T) -static inline unsigned long mk_vsid_data (unsigned long ea,int ssize,unsigned long flags) {
arch/powerpc/platforms/cell/spu_base.c +9 -46
92 lines not on this page · raw message
Signature · 1 line
1.9.1
Re: [PATCH v4 02/16] powerpc/cell: Move data segment faulting code out of cell platform
Quoted 5 lines · Michael Neuling
From: Ian Munsie <[email protected]>
__spu_trap_data_seg()currently contains code to determine the VSID and ESID required for a particular EA and mm struct.
Quoted 9 lines
This code is generically useful for other co-processors. This moves the code of the cell platform so it can be used by other powerpc code. It also adds 1TB segment handling which Cell didn't support. The new function is called
copro_calculate_slb().This also moves the internal struct
spu_slbto a generic structcopro_slbwhich is now used in the Cell and copro code. We use this new struct instead of passing around esid and vsid parameters.
Quoted 93 lines
Signed-off-by Ian Munsie <[email protected]>Signed-off-by Michael Neuling <[email protected]>--- arch/powerpc/include/asm/copro.h | 7 +++++ arch/powerpc/include/asm/mmu-hash64.h | 7 +++++ arch/powerpc/mm/copro_fault.c | 46 ++++++++++++++++++++++++++++ arch/powerpc/mm/slb.c | 3 -- arch/powerpc/platforms/cell/spu_base.c | 55 ++++++---------------------------- 5 files changed, 69 insertions(+), 49 deletions(-)arch/powerpc/include/asm/copro.h +7
-0@@ -10,7 +10,14 @@#ifndef _ASM_POWERPC_COPRO_H#define _ASM_POWERPC_COPRO_H +struct copro_slb +{ +u64 esid, vsid; +}; +int copro_handle_mm_fault (struct mm_struct *mm,unsigned long ea,unsigned long dsisr,unsigned *flt); +int copro_calculate_slb (struct mm_struct *mm,u64 ea,struct copro_slb *slb); +#endif /* _ASM_POWERPC_COPRO_H */ arch/powerpc/include/asm/mmu-hash64.h +7
-0@@ -190,6 +190,13 @@ static inline unsigned int mmu_psize_to_shift(unsigned int mmu_psize)#ifndef __ASSEMBLY__ +static inline int slb_vsid_shift (int ssize) +{ +if (ssize ==MMU_SEGSIZE_256M ) +return SLB_VSID_SHIFT ; +return SLB_VSID_SHIFT_1T ; +} +static inline int segment_shift (int ssize) {if (ssize ==MMU_SEGSIZE_256M )arch/powerpc/mm/copro_fault.c +31
-0@@ -24,6 +24,7 @@#include <linux/mm.h> #include <linux/export.h> #include <asm/reg.h> +#include <asm/copro.h> /* * This ought to be kept in sync with the powerpc specific do_page_fault @@ -90,3 +91,48 @@ out_unlock:return ret; }EXPORT_SYMBOL_GPL (copro_handle_mm_fault); + +int copro_calculate_slb (struct mm_struct *mm,u64 ea,struct copro_slb *slb) +{ +u64 vsid; +int psize, ssize; + + slb->esid = (ea &ESID_MASK ) |SLB_ESID_V ; + +switch (REGION_ID (ea)) { +case USER_REGION_ID : +pr_devel ("%s: 0x%llx -- USER_REGION_ID\n" , __func__, ea); + psize =get_slice_psize (mm, ea); + ssize =user_segment_size (ea); + vsid =get_vsid (mm->context.id, ea, ssize); +break ; +case VMALLOC_REGION_ID : +pr_devel ("%s: 0x%llx -- VMALLOC_REGION_ID\n" , __func__, ea); +if (ea <VMALLOC_END ) + psize = mmu_vmalloc_psize; +else + psize = mmu_io_psize; + ssize = mmu_kernel_ssize; + vsid =get_kernel_vsid (ea, mmu_kernel_ssize); +break ; +case KERNEL_REGION_ID : +pr_devel ("%s: 0x%llx -- KERNEL_REGION_ID\n" , __func__, ea); + psize = mmu_linear_psize; + ssize = mmu_kernel_ssize; + vsid =get_kernel_vsid (ea, mmu_kernel_ssize); +break ;
arch/powerpc/mm/copro_fault.c out_unlock: · line 133
Quoted 10 lines
arch/powerpc/mm/copro_fault.c +10
-0+default : +pr_debug ("%s: invalid region access at %016llx\n" , __func__, ea); +return 1 ; + } + + vsid = (vsid <<slb_vsid_shift (ssize)) |SLB_VSID_USER ; + + vsid |= mmu_psize_defs[psize].sllp | + ((ssize ==MMU_SEGSIZE_1T ) ?SLB_VSID_B_1T :0 ); +
s/0/SLB_VSID_B_256M/
Quoted 129 lines
arch/powerpc/mm/copro_fault.c +5
-0+ slb->vsid = vsid; + +return 0 ; +} +EXPORT_SYMBOL_GPL (copro_calculate_slb);arch/powerpc/mm/slb.c +0
-3@@ -46,9 +46,6 @@ static inline unsigned long mk_esid_data(unsigned long ea, int ssize,return (ea &slb_esid_mask (ssize)) |SLB_ESID_V | slot; } -#define slb_vsid_shift (ssize) \ - ((ssize) == MMU_SEGSIZE_256M? SLB_VSID_SHIFT: SLB_VSID_SHIFT_1T) -static inline unsigned long mk_vsid_data (unsigned long ea,int ssize,unsigned long flags) {arch/powerpc/platforms/cell/spu_base.c +9
-46@@ -76,10 +76,6 @@ static LIST_HEAD(spu_full_list);static DEFINE_SPINLOCK (spu_full_list_lock);static DEFINE_MUTEX (spu_full_list_mutex); -struct spu_slb { -u64 esid, vsid; -}; -void spu_invalidate_slbs (struct spu *spu) {struct spu_priv2 __iomem *priv2 = spu->priv2;@@ -149,7 +145,7 @@ static void spu_restart_dma(struct spu *spu) } } -static inline void spu_load_slb (struct spu *spu,int slbe,struct spu_slb *slb) +static inline void spu_load_slb (struct spu *spu,int slbe,struct copro_slb *slb) {struct spu_priv2 __iomem *priv2 = spu->priv2;@@ -167,45 +163,12 @@ static inline void spu_load_slb(struct spu *spu, int slbe, struct spu_slb *slb)static int __spu_trap_data_seg (struct spu *spu,unsigned long ea) { -struct mm_struct *mm = spu->mm; -struct spu_slb slb; -int psize; - -pr_debug ("%s\n" , __func__); - - slb.esid = (ea &ESID_MASK ) |SLB_ESID_V ; +struct copro_slb slb; +int ret; -switch (REGION_ID (ea)) { -case USER_REGION_ID : -#ifdef CONFIG_PPC_MM_SLICES - psize =get_slice_psize (mm, ea); -#else - psize = mm->context.user_psize; -#endif - slb.vsid = (get_vsid (mm->context.id, ea,MMU_SEGSIZE_256M ) - <<SLB_VSID_SHIFT ) |SLB_VSID_USER ; -break ; -case VMALLOC_REGION_ID : -if (ea <VMALLOC_END ) - psize = mmu_vmalloc_psize; -else - psize = mmu_io_psize; - slb.vsid = (get_kernel_vsid (ea,MMU_SEGSIZE_256M ) - <<SLB_VSID_SHIFT ) |SLB_VSID_KERNEL ; -break ; -case KERNEL_REGION_ID : - psize = mmu_linear_psize; - slb.vsid = (get_kernel_vsid (ea,MMU_SEGSIZE_256M ) - <<SLB_VSID_SHIFT ) |SLB_VSID_KERNEL ; -break ; -default : -/* Future: support kernel segments so that drivers -* can use SPUs. -*/ -pr_debug ("invalid region access at %016lx\n" , ea); -return 1 ; - } - slb.vsid |= mmu_psize_defs[psize].sllp; + ret =copro_calculate_slb (spu->mm, ea, &slb); +if (ret) +return ret;spu_load_slb (spu, spu->slb_replace, &slb);@@ -253,7 +216,7 @@ static int __spu_trap_data_map(struct spu *spu, unsigned long ea, u64 dsisr)return 0 ; } -static void __spu_kernel_slb (void *addr,struct spu_slb *slb) +static void __spu_kernel_slb (void *addr,struct copro_slb *slb) {unsigned long ea = (unsigned long )addr;u64 llp;@@ -272,7 +235,7 @@ static void __spu_kernel_slb(void *addr, struct spu_slb *slb)* Given an array of @nr_slbs SLB entries, @slbs, return non-zero if the * address @new_addr is present. */ -static inline int __slb_present (struct spu_slb *slbs,int nr_slbs, +static inline int __slb_present (struct copro_slb *slbs,int nr_slbs,void *new_addr) {unsigned long ea = (unsigned long )new_addr;@@ -297,7 +260,7 @@ static inline int __slb_present(struct spu_slb *slbs, int nr_slbs,void spu_setup_kernel_slbs (struct spu *spu,struct spu_lscsa *lscsa,void *code,int code_size) { -struct spu_slb slbs[4 ]; +struct copro_slb slbs[4 ];int i, nr_slbs =0 ;/* start and end addresses of both mappings */ void *addrs[] = {Signature · 7 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
PATCH v4 3/16 powerpc/cell: Make spu_flush_all_slbs() generic
In reply to Michael NeulingFrom: Ian Munsie <[email protected]>
This moves spu_flush_all_slbs() into a generic call copro_flush_all_slbs().
This will be useful when we add cxl which also needs a similar SLB flush call.
--- arch/powerpc/include/asm/copro.h | 6 ++++++ arch/powerpc/mm/copro_fault.c | 9 +++++++++ arch/powerpc/mm/hash_utils_64.c | 10 +++------- arch/powerpc/mm/slice.c | 10 +++------- 4 files changed, 21 insertions(+), 14 deletions(-)
arch/powerpc/include/asm/copro.h +6 -0
@@ -20,4 +20,10 @@ int copro_handle_mm_fault(struct mm_struct *mm, unsigned long ea,int copro_calculate_slb (struct mm_struct *mm,u64 ea,struct copro_slb *slb); + +#ifdef CONFIG_PPC_COPRO_BASE +void copro_flush_all_slbs (struct mm_struct *mm); +#else +static inline void copro_flush_all_slbs (struct mm_struct *mm) {} +#endif #endif /* _ASM_POWERPC_COPRO_H */
arch/powerpc/mm/copro_fault.c +9 -0
@@ -25,6 +25,7 @@#include <linux/export.h> #include <asm/reg.h> #include <asm/copro.h> +#include <asm/spu.h> /* * This ought to be kept in sync with the powerpc specific do_page_fault
@@ -136,3 +137,11 @@ int copro_calculate_slb(struct mm_struct *mm, u64 ea, struct copro_slb *slb)return 0 ; }EXPORT_SYMBOL_GPL (copro_calculate_slb); + +void copro_flush_all_slbs (struct mm_struct *mm) +{ +#ifdef CONFIG_SPU_BASE +spu_flush_all_slbs (mm); +#endif +} +EXPORT_SYMBOL_GPL (copro_flush_all_slbs);
arch/powerpc/mm/hash_utils_64.c +3 -7
@@ -51,7 +51,7 @@#include <asm/cacheflush.h> #include <asm/cputable.h> #include <asm/sections.h> -#include <asm/spu.h> +#include <asm/copro.h> #include <asm/udbg.h> #include <asm/code-patching.h> #include <asm/fadump.h>
@@ -901,9 +901,7 @@ void demote_segment_4k(struct mm_struct *mm, unsigned long addr)if (get_slice_psize (mm, addr) ==MMU_PAGE_4K )return ;slice_set_range_psize (mm, addr,1 ,MMU_PAGE_4K ); -#ifdef CONFIG_SPU_BASE -spu_flush_all_slbs (mm); -#endif +copro_flush_all_slbs (mm);if (get_paca_psize (addr) !=MMU_PAGE_4K ) {get_paca ()->context = mm->context;slb_flush_and_rebolt ();
@@ -1141,9 +1139,7 @@ int hash_page(unsigned long ea, unsigned long access, unsigned long trap)"to 4kB pages because of " "non-cacheable mapping\n"); psize = mmu_vmalloc_psize =MMU_PAGE_4K ; -#ifdef CONFIG_SPU_BASE -spu_flush_all_slbs (mm); -#endif +copro_flush_all_slbs (mm); } }
arch/powerpc/mm/slice.c +3 -7
@@ -32,7 +32,7 @@#include <linux/export.h> #include <asm/mman.h> #include <asm/mmu.h> -#include <asm/spu.h> +#include <asm/copro.h> /* some sanity checks */ #if (PGTABLE_RANGE >>43 ) >SLICE_MASK_SIZE
@@ -232,9 +232,7 @@ static void slice_convert(struct mm_struct *mm, struct slice_mask mask, int psizspin_unlock_irqrestore (&slice_convert_lock, flags); -#ifdef CONFIG_SPU_BASE -spu_flush_all_slbs (mm); -#endif +copro_flush_all_slbs (mm); }/*
@@ -671,9 +669,7 @@ void slice_set_psize(struct mm_struct *mm, unsigned long address,spin_unlock_irqrestore (&slice_convert_lock, flags); -#ifdef CONFIG_SPU_BASE -spu_flush_all_slbs (mm); -#endif +copro_flush_all_slbs (mm); } void slice_set_range_psize(struct mm_struct *mm, unsigned long start,
Signature · 1 line
1.9.1
Re: [PATCH v4 03/16] powerpc/cell: Make spu_flush_all_slbs() generic
Quoted 6 lines · Michael Neuling
From: Ian Munsie <[email protected]>
This moves
spu_flush_all_slbs()into a generic callcopro_flush_all_slbs().This will be useful when we add cxl which also needs a similar SLB flush call.
Quoted 126 lines
Signed-off-by Ian Munsie <[email protected]>Signed-off-by Michael Neuling <[email protected]>--- arch/powerpc/include/asm/copro.h | 6 ++++++ arch/powerpc/mm/copro_fault.c | 9 +++++++++ arch/powerpc/mm/hash_utils_64.c | 10 +++------- arch/powerpc/mm/slice.c | 10 +++------- 4 files changed, 21 insertions(+), 14 deletions(-)arch/powerpc/include/asm/copro.h +6
-0@@ -20,4 +20,10 @@ int copro_handle_mm_fault(struct mm_struct *mm, unsigned long ea,int copro_calculate_slb (struct mm_struct *mm,u64 ea,struct copro_slb *slb); + +#ifdef CONFIG_PPC_COPRO_BASE +void copro_flush_all_slbs (struct mm_struct *mm); +#else +static inline void copro_flush_all_slbs (struct mm_struct *mm) {} +#endif #endif /* _ASM_POWERPC_COPRO_H */ arch/powerpc/mm/copro_fault.c +9
-0@@ -25,6 +25,7 @@#include <linux/export.h> #include <asm/reg.h> #include <asm/copro.h> +#include <asm/spu.h> /* * This ought to be kept in sync with the powerpc specific do_page_fault @@ -136,3 +137,11 @@ int copro_calculate_slb(struct mm_struct *mm, u64 ea, struct copro_slb *slb)return 0 ; }EXPORT_SYMBOL_GPL (copro_calculate_slb); + +void copro_flush_all_slbs (struct mm_struct *mm) +{ +#ifdef CONFIG_SPU_BASE +spu_flush_all_slbs (mm); +#endif +} +EXPORT_SYMBOL_GPL (copro_flush_all_slbs);arch/powerpc/mm/hash_utils_64.c +3
-7@@ -51,7 +51,7 @@#include <asm/cacheflush.h> #include <asm/cputable.h> #include <asm/sections.h> -#include <asm/spu.h> +#include <asm/copro.h> #include <asm/udbg.h> #include <asm/code-patching.h> #include <asm/fadump.h> @@ -901,9 +901,7 @@ void demote_segment_4k(struct mm_struct *mm, unsigned long addr)if (get_slice_psize (mm, addr) ==MMU_PAGE_4K )return ;slice_set_range_psize (mm, addr,1 ,MMU_PAGE_4K ); -#ifdef CONFIG_SPU_BASE -spu_flush_all_slbs (mm); -#endif +copro_flush_all_slbs (mm);if (get_paca_psize (addr) !=MMU_PAGE_4K ) {get_paca ()->context = mm->context;slb_flush_and_rebolt ();@@ -1141,9 +1139,7 @@ int hash_page(unsigned long ea, unsigned long access, unsigned long trap)"to 4kB pages because of " "non-cacheable mapping\n"); psize = mmu_vmalloc_psize =MMU_PAGE_4K ; -#ifdef CONFIG_SPU_BASE -spu_flush_all_slbs (mm); -#endif +copro_flush_all_slbs (mm); } }arch/powerpc/mm/slice.c +3
-7@@ -32,7 +32,7 @@#include <linux/export.h> #include <asm/mman.h> #include <asm/mmu.h> -#include <asm/spu.h> +#include <asm/copro.h> /* some sanity checks */ #if (PGTABLE_RANGE >>43 ) >SLICE_MASK_SIZE @@ -232,9 +232,7 @@ static void slice_convert(struct mm_struct *mm, struct slice_mask mask, int psizspin_unlock_irqrestore (&slice_convert_lock, flags); -#ifdef CONFIG_SPU_BASE -spu_flush_all_slbs (mm); -#endif +copro_flush_all_slbs (mm); }/* @@ -671,9 +669,7 @@ void slice_set_psize(struct mm_struct *mm, unsigned long address,spin_unlock_irqrestore (&slice_convert_lock, flags); -#ifdef CONFIG_SPU_BASE -spu_flush_all_slbs (mm); -#endif +copro_flush_all_slbs (mm); } void slice_set_range_psize(struct mm_struct *mm, unsigned long start,Signature · 7 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
PATCH v4 4/16 powerpc/msi: Improve IRQ bitmap allocator
In reply to Michael NeulingFrom: Ian Munsie <[email protected]>
Currently msi_bitmap_alloc_hwirqs() will round up any IRQ allocation requests to the nearest power of 2. eg. ask for 5 IRQs and you'll get 8. This wastes a lot of IRQs which can be a scarce resource.
For cxl we may require multiple IRQs for every context that is attached to the accelerator. There may be 1000s of contexts attached, hence we can easily run out of IRQs, especially if we are needlessly wasting them.
This changes the msi_bitmap_alloc_hwirqs() to allocate only the required number of IRQs, hence avoiding this wastage. It keeps the natural alignment requirement though.
--- arch/powerpc/sysdev/msi_bitmap.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-)
arch/powerpc/sysdev/msi_bitmap.c +25 -11
@@ -20,32 +20,37 @@ int msi_bitmap_alloc_hwirqs(struct msi_bitmap *bmp, int num)int offset, order =get_count_order (num);spin_lock_irqsave (&bmp->lock, flags); -/* -* This is fast, but stricter than we need. We might want to add -* a fallback routine which does a linear search with no alignment. -*/ - offset =bitmap_find_free_region (bmp->bitmap, bmp->irq_count, order); + + offset =bitmap_find_next_zero_area (bmp->bitmap, bmp->irq_count,0 , + num, (1 << order) -1 ); +if (offset > bmp->irq_count) + goto err; + +bitmap_set (bmp->bitmap, offset, num);spin_unlock_irqrestore (&bmp->lock, flags); -pr_debug ("msi_bitmap: allocated 0x%x (2^%d) at offset 0x%x\n" , - num, order, offset); +pr_debug ("msi_bitmap: allocated 0x%x at offset 0x%x\n" , num, offset);return offset; +err: +spin_unlock_irqrestore (&bmp->lock, flags); +return -ENOMEM ; } +EXPORT_SYMBOL (msi_bitmap_alloc_hwirqs);void msi_bitmap_free_hwirqs (struct msi_bitmap *bmp,unsigned int offset,unsigned int num) {unsigned long flags; -int order =get_count_order (num); -pr_debug ("msi_bitmap: freeing 0x%x (2^%d) at offset 0x%x\n" , - num, order, offset); +pr_debug ("msi_bitmap: freeing 0x%x at offset 0x%x\n" , + num, offset);spin_lock_irqsave (&bmp->lock, flags); -bitmap_release_region (bmp->bitmap, offset, order); +bitmap_clear (bmp->bitmap, offset, num);spin_unlock_irqrestore (&bmp->lock, flags); } +EXPORT_SYMBOL (msi_bitmap_free_hwirqs);void msi_bitmap_reserve_hwirq (struct msi_bitmap *bmp,unsigned int hwirq) {
@@ -180,6 +185,15 @@ void __init test_basics(void)msi_bitmap_free_hwirqs (&bmp, size /2 ,1 );check (msi_bitmap_alloc_hwirqs (&bmp,1 ) == size /2 ); +/* Check we get a naturally aligned offset */ +check (msi_bitmap_alloc_hwirqs (&bmp,2 ) %2 ==0 ); +check (msi_bitmap_alloc_hwirqs (&bmp,4 ) %4 ==0 ); +check (msi_bitmap_alloc_hwirqs (&bmp,8 ) %8 ==0 ); +check (msi_bitmap_alloc_hwirqs (&bmp,9 ) %16 ==0 ); +check (msi_bitmap_alloc_hwirqs (&bmp,3 ) %4 ==0 ); +check (msi_bitmap_alloc_hwirqs (&bmp,7 ) %8 ==0 ); +check (msi_bitmap_alloc_hwirqs (&bmp,121 ) %128 ==0 ); +msi_bitmap_free (&bmp);/* Clients may check bitmap == NULL for "not-allocated" */
Signature · 1 line
1.9.1
PATCH v4 5/16 powerpc/mm: Export mmu_kernel_ssize and mmu_linear_psize
In reply to Michael NeulingFrom: Ian Munsie <[email protected]>
Export mmu_kernel_ssize and mmu_linear_psize. These are needed by the cxl driver which has it's own MMU. To setup the MMU cxl needs access to these.
--- arch/powerpc/mm/hash_utils_64.c | 2 ++ 1 file changed, 2 insertions(+)
arch/powerpc/mm/hash_utils_64.c +2 -0
@@ -98,6 +98,7 @@ unsigned long htab_size_bytes;unsigned long htab_hash_mask;EXPORT_SYMBOL_GPL (htab_hash_mask);int mmu_linear_psize =MMU_PAGE_4K ; +EXPORT_SYMBOL_GPL (mmu_linear_psize);int mmu_virtual_psize =MMU_PAGE_4K ;int mmu_vmalloc_psize =MMU_PAGE_4K ;#ifdef CONFIG_SPARSEMEM_VMEMMAP
@@ -105,6 +106,7 @@ int mmu_vmemmap_psize = MMU_PAGE_4K;#endif int mmu_io_psize =MMU_PAGE_4K ;int mmu_kernel_ssize =MMU_SEGSIZE_256M ; +EXPORT_SYMBOL_GPL (mmu_kernel_ssize);int mmu_highuser_ssize =MMU_SEGSIZE_256M ;u16 mmu_slb_size =64 ;EXPORT_SYMBOL_GPL (mmu_slb_size);
Signature · 1 line
1.9.1
Re: [PATCH v4 05/16] powerpc/mm: Export mmu_kernel_ssize and mmu_linear_psize
Quoted 5 lines · Michael Neuling
From: Ian Munsie <[email protected]>
Export
mmu_kernel_ssizeandmmu_linear_psize. These are needed by the cxl driver which has it's own MMU. To setup the MMU cxl needs access to these.
Quoted 34 lines
Signed-off-by Ian Munsie <[email protected]>Signed-off-by Michael Neuling <[email protected]>--- arch/powerpc/mm/hash_utils_64.c | 2 ++ 1 file changed, 2 insertions(+)arch/powerpc/mm/hash_utils_64.c +2
-0@@ -98,6 +98,7 @@ unsigned long htab_size_bytes;unsigned long htab_hash_mask;EXPORT_SYMBOL_GPL (htab_hash_mask);int mmu_linear_psize =MMU_PAGE_4K ; +EXPORT_SYMBOL_GPL (mmu_linear_psize);int mmu_virtual_psize =MMU_PAGE_4K ;int mmu_vmalloc_psize =MMU_PAGE_4K ;#ifdef CONFIG_SPARSEMEM_VMEMMAP @@ -105,6 +106,7 @@ int mmu_vmemmap_psize = MMU_PAGE_4K;#endif int mmu_io_psize =MMU_PAGE_4K ;int mmu_kernel_ssize =MMU_SEGSIZE_256M ; +EXPORT_SYMBOL_GPL (mmu_kernel_ssize);int mmu_highuser_ssize =MMU_SEGSIZE_256M ;u16 mmu_slb_size =64 ;EXPORT_SYMBOL_GPL (mmu_slb_size);Signature · 7 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
PATCH v4 6/16 powerpc/powernv: Split out set MSI IRQ chip code
In reply to Michael NeulingFrom: Ian Munsie <[email protected]>
Some of the MSI IRQ code in pnv_pci_ioda_msi_setup() is generically useful so split it out.
This will be used by some of the cxl PCIe code later.
--- arch/powerpc/platforms/powernv/pci-ioda.c | 42 ++++++++++++++++++------------- 1 file changed, 24 insertions(+), 18 deletions(-)
arch/powerpc/platforms/powernv/pci-ioda.c +24 -18
@@ -1306,14 +1306,35 @@ static void pnv_ioda2_msi_eoi(struct irq_data *d)icp_native_eoi (d); } + +static void set_msi_irq_chip (struct pnv_phb *phb,unsigned int virq) +{ +struct irq_data *idata; +struct irq_chip *ichip; + +if (phb->type !=PNV_PHB_IODA2 ) +return ; + +if (!phb->ioda.irq_chip_init) { +/* +* First time we setup an MSI IRQ, we need to setup the +* corresponding IRQ chip to route correctly. +*/ + idata =irq_get_irq_data (virq); + ichip =irq_data_get_irq_chip (idata); + phb->ioda.irq_chip_init =1 ; + phb->ioda.irq_chip = *ichip; + phb->ioda.irq_chip.irq_eoi = pnv_ioda2_msi_eoi; + } +irq_set_chip (virq, &phb->ioda.irq_chip); +} +static int pnv_pci_ioda_msi_setup (struct pnv_phb *phb,struct pci_dev *dev,unsigned int hwirq,unsigned int virq,unsigned int is_64,struct msi_msg *msg) {struct pnv_ioda_pe *pe =pnv_ioda_get_pe (dev);struct pci_dn *pdn =pci_get_pdn (dev); -struct irq_data *idata; -struct irq_chip *ichip;unsigned int xive_num = hwirq - phb->msi_base;__be32 data;int rc;
@@ -1365,22 +1386,7 @@ static int pnv_pci_ioda_msi_setup(struct pnv_phb *phb, struct pci_dev *dev, } msg->data =be32_to_cpu (data); -/* -* Change the IRQ chip for the MSI interrupts on PHB3. -* The corresponding IRQ chip should be populated for -* the first time. -*/ -if (phb->type ==PNV_PHB_IODA2 ) { -if (!phb->ioda.irq_chip_init) { - idata =irq_get_irq_data (virq); - ichip =irq_data_get_irq_chip (idata); - phb->ioda.irq_chip_init =1 ; - phb->ioda.irq_chip = *ichip; - phb->ioda.irq_chip.irq_eoi = pnv_ioda2_msi_eoi; - } - -irq_set_chip (virq, &phb->ioda.irq_chip); - } +set_msi_irq_chip (phb, virq); pr_devel("%s: %s-bit MSI on hwirq %x (xive #%d)," " address=%x_%08x data=%x PE# %d\n",
Signature · 1 line
1.9.1
PATCH v4 7/16 cxl: Add new header for call backs and structs
In reply to Michael NeulingFrom: Ian Munsie <[email protected]>
This new header adds callbacks and structs needed by the rest of the kernel to hook into the cxl infrastructure.
This adds the cxl_ctx_in_use() function for use in the mm code to see if any cxl contexts are currently in use. This is used by the tlbie() to determine if it can do local TLB invalidations or not. This also adds get/put calls for the cxl driver module to refcount the active cxl contexts.
cxl_ctx_get/put/in_use are static inlined here as they are called in tlbie which we want to be fast (mpe's suggestion).
Empty functions are provided when CONFIG_CXL_BASE is not enabled.
--- include/misc/cxl.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 include/misc/cxl.h
include/misc/cxl.h new file +48 -0
@@ -0,0 +1,48 @@ +/* +* Copyright 2014 IBM Corp. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version +* 2 of the License, or (at your option) any later version. +*/ + +#ifndef _MISC_CXL_H +#define _MISC_CXL_H + +#ifdef CONFIG_CXL_BASE + +#define CXL_IRQ_RANGES 4 + +struct cxl_irq_ranges { +irq_hw_number_t offset[CXL_IRQ_RANGES ]; +irq_hw_number_t range[CXL_IRQ_RANGES ]; +}; + +extern atomic_t cxl_use_count; + +static inline bool cxl_ctx_in_use (void ) +{ +return (atomic_read (&cxl_use_count) !=0 ); +} + +static inline void cxl_ctx_get (void ) +{ +atomic_inc (&cxl_use_count); +} + +static inline void cxl_ctx_put (void ) +{ +atomic_dec (&cxl_use_count); +} + +void cxl_slbia (struct mm_struct *mm); + +#else /* CONFIG_CXL_BASE */ + +static inline bool cxl_ctx_in_use (void ) {return false; } +static inline void cxl_slbia (struct mm_struct *mm) {} + +#endif /* CONFIG_CXL_BASE */ + +#endif
Signature · 1 line
1.9.1
PATCH v4 8/16 powerpc/powerpc: Add new PCIe functions for allocating cxl interrupts
In reply to Michael NeulingFrom: Ian Munsie <[email protected]>
This adds a number of functions for allocating IRQs under powernv PCIe for cxl.
--- arch/powerpc/include/asm/pnv-pci.h | 31 ++++++ arch/powerpc/platforms/powernv/pci-ioda.c | 154 ++++++++++++++++++++++++++++++ 2 files changed, 185 insertions(+) create mode 100644 arch/powerpc/include/asm/pnv-pci.h
arch/powerpc/include/asm/pnv-pci.h new file +31 -0
@@ -0,0 +1,31 @@ +/* +* Copyright 2014 IBM Corp. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version +* 2 of the License, or (at your option) any later version. +*/ + +#ifndef _ASM_PNV_PCI_H +#define _ASM_PNV_PCI_H + +#include <linux/pci.h> +#include <misc/cxl.h> + +int pnv_phb_to_cxl (struct pci_dev *dev); +int pnv_cxl_ioda_msi_setup (struct pci_dev *dev,unsigned int hwirq, +unsigned int virq); +int pnv_cxl_alloc_hwirqs (struct pci_dev *dev,int num); +void pnv_cxl_release_hwirqs (struct pci_dev *dev,int hwirq,int num); +int pnv_cxl_get_irq_count (struct pci_dev *dev); +struct device_node *pnv_pci_to_phb_node (struct pci_dev *dev); + +#ifdef CONFIG_CXL_BASE +int pnv_cxl_alloc_hwirq_ranges (struct cxl_irq_ranges *irqs, +struct pci_dev *dev,int num); +void pnv_cxl_release_hwirq_ranges (struct cxl_irq_ranges *irqs, +struct pci_dev *dev); +#endif + +#endif
arch/powerpc/platforms/powernv/pci-ioda.c +154 -0
166 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v4 9/16 powerpc/mm: Add new hash_page_mm()
In reply to Michael NeulingFrom: Ian Munsie <[email protected]>
This adds a new function hash_page_mm() based on the existing hash_page(). This version allows any struct mm to be passed in, rather than assuming current. This is useful for servicing co-processor faults which are not in the context of the current running process.
We need to be careful here as the current hash_page() assumes current in a few places.
--- arch/powerpc/include/asm/mmu-hash64.h | 1 + arch/powerpc/mm/hash_utils_64.c | 24 +++++++++++++++++------- 2 files changed, 18 insertions(+), 7 deletions(-)
arch/powerpc/include/asm/mmu-hash64.h +1 -0
@@ -324,6 +324,7 @@ extern int __hash_page_64K(unsigned long ea, unsigned long access, unsigned int local, int ssize);struct mm_struct ;unsigned int hash_page_do_lazy_icache (unsigned int pp,pte_t pte,int trap); +extern int hash_page_mm (struct mm_struct *mm,unsigned long ea,unsigned long access,unsigned long trap);extern int hash_page (unsigned long ea,unsigned long access,unsigned long trap); int __hash_page_huge(unsigned long ea, unsigned long access, unsigned long vsid, pte_t *ptep, unsigned long trap, int local, int ssize,
arch/powerpc/mm/hash_utils_64.c +17 -7
@@ -904,7 +904,7 @@ void demote_segment_4k(struct mm_struct *mm, unsigned long addr)return ;slice_set_range_psize (mm, addr,1 ,MMU_PAGE_4K );copro_flush_all_slbs (mm); -if (get_paca_psize (addr) !=MMU_PAGE_4K ) { +if ((get_paca_psize (addr) !=MMU_PAGE_4K ) && (current->mm == mm)) {get_paca ()->context = mm->context;slb_flush_and_rebolt (); }
@@ -989,12 +989,11 @@ static void check_paca_psize(unsigned long ea, struct mm_struct *mm,* -1 - critical hash insertion error * -2 - access not permitted by subpage protection mechanism */ -int hash_page (unsigned long ea,unsigned long access,unsigned long trap) +int hash_page_mm (struct mm_struct *mm,unsigned long ea,unsigned long access,unsigned long trap) {enum ctx_state prev_state =exception_enter ();pgd_t *pgdir;unsigned long vsid; -struct mm_struct *mm;pte_t *ptep;unsigned hugeshift;const struct cpumask *tmp;
@@ -1008,7 +1007,6 @@ int hash_page(unsigned long ea, unsigned long access, unsigned long trap)switch (REGION_ID (ea)) {case USER_REGION_ID : user_region =1 ; - mm = current->mm;if (! mm) {DBG_LOW (" user region with no mm !\n" ); rc =1 ;
@@ -1019,7 +1017,6 @@ int hash_page(unsigned long ea, unsigned long access, unsigned long trap) vsid =get_vsid (mm->context.id, ea, ssize);break ;case VMALLOC_REGION_ID : - mm = &init_mm; vsid =get_kernel_vsid (ea, mmu_kernel_ssize);if (ea <VMALLOC_END ) psize = mmu_vmalloc_psize;
@@ -1104,7 +1101,8 @@ int hash_page(unsigned long ea, unsigned long access, unsigned long trap) WARN_ON(1); }#endif -check_paca_psize (ea, mm, psize, user_region); +if (current->mm == mm) +check_paca_psize (ea, mm, psize, user_region); goto bail; }
@@ -1145,7 +1143,8 @@ int hash_page(unsigned long ea, unsigned long access, unsigned long trap) } } -check_paca_psize (ea, mm, psize, user_region); +if (current->mm == mm) +check_paca_psize (ea, mm, psize, user_region);#endif /* CONFIG_PPC_64K_PAGES */ #ifdef CONFIG_PPC_HAS_HASH_64K
@@ -1180,6 +1179,17 @@ bail:exception_exit (prev_state);return rc; } +EXPORT_SYMBOL_GPL (hash_page_mm); + +int hash_page (unsigned long ea,unsigned long access,unsigned long trap) +{ +struct mm_struct *mm = current->mm; + +if (REGION_ID (ea) ==VMALLOC_REGION_ID ) + mm = &init_mm; + +return hash_page_mm (mm, ea, access, trap); +}EXPORT_SYMBOL_GPL (hash_page); void hash_preload(struct mm_struct *mm, unsigned long ea,
Signature · 1 line
1.9.1
Re: [PATCH v4 09/16] powerpc/mm: Add new hash_page_mm()
Quoted 9 lines · Michael Neuling
From: Ian Munsie <[email protected]>
This adds a new function
hash_page_mm()based on the existinghash_page(). This version allows any struct mm to be passed in, rather than assuming current. This is useful for servicing co-processor faults which are not in the context of the current running process.We need to be careful here as the current
hash_page()assumes current in a few places.
if you move cxl_slbia patch before this, then we could add additonal information here.
1) We use this to insert hpte entries on-behalf of co-processor.
2) we don't need to flush cpu slb entries when adding new hpte entries
3) We do flush the co-processor slb cache, if adding hpte entry result
in a segement demotion or have mmu_ci_restrictions enabled.
4) We do update the slice array to indicate the new base page size
5) w.r.t co-processor on segment miss we look at slice array and add new slb entry
using newly added copro_calculate_slb "powerpc/cell: Move data segment faulting code out of cell platform"
Quoted 109 lines
Signed-off-by Ian Munsie <[email protected]>Signed-off-by Michael Neuling <[email protected]>--- arch/powerpc/include/asm/mmu-hash64.h | 1 + arch/powerpc/mm/hash_utils_64.c | 24 +++++++++++++++++------- 2 files changed, 18 insertions(+), 7 deletions(-)arch/powerpc/include/asm/mmu-hash64.h +1
-0@@ -324,6 +324,7 @@ extern int __hash_page_64K(unsigned long ea, unsigned long access, unsigned int local, int ssize);struct mm_struct ;unsigned int hash_page_do_lazy_icache (unsigned int pp,pte_t pte,int trap); +extern int hash_page_mm (struct mm_struct *mm,unsigned long ea,unsigned long access,unsigned long trap);extern int hash_page (unsigned long ea,unsigned long access,unsigned long trap); int __hash_page_huge(unsigned long ea, unsigned long access, unsigned long vsid, pte_t *ptep, unsigned long trap, int local, int ssize,arch/powerpc/mm/hash_utils_64.c +17
-7@@ -904,7 +904,7 @@ void demote_segment_4k(struct mm_struct *mm, unsigned long addr)return ;slice_set_range_psize (mm, addr,1 ,MMU_PAGE_4K );copro_flush_all_slbs (mm); -if (get_paca_psize (addr) !=MMU_PAGE_4K ) { +if ((get_paca_psize (addr) !=MMU_PAGE_4K ) && (current->mm == mm)) {get_paca ()->context = mm->context;slb_flush_and_rebolt (); }@@ -989,12 +989,11 @@ static void check_paca_psize(unsigned long ea, struct mm_struct *mm,* -1 - critical hash insertion error * -2 - access not permitted by subpage protection mechanism */ -int hash_page (unsigned long ea,unsigned long access,unsigned long trap) +int hash_page_mm (struct mm_struct *mm,unsigned long ea,unsigned long access,unsigned long trap) {enum ctx_state prev_state =exception_enter ();pgd_t *pgdir;unsigned long vsid; -struct mm_struct *mm;pte_t *ptep;unsigned hugeshift;const struct cpumask *tmp;@@ -1008,7 +1007,6 @@ int hash_page(unsigned long ea, unsigned long access, unsigned long trap)switch (REGION_ID (ea)) {case USER_REGION_ID : user_region =1 ; - mm = current->mm;if (! mm) {DBG_LOW (" user region with no mm !\n" ); rc =1 ;@@ -1019,7 +1017,6 @@ int hash_page(unsigned long ea, unsigned long access, unsigned long trap) vsid =get_vsid (mm->context.id, ea, ssize);break ;case VMALLOC_REGION_ID : - mm = &init_mm; vsid =get_kernel_vsid (ea, mmu_kernel_ssize);if (ea <VMALLOC_END ) psize = mmu_vmalloc_psize;@@ -1104,7 +1101,8 @@ int hash_page(unsigned long ea, unsigned long access, unsigned long trap) WARN_ON(1); }#endif -check_paca_psize (ea, mm, psize, user_region); +if (current->mm == mm) +check_paca_psize (ea, mm, psize, user_region); goto bail; }@@ -1145,7 +1143,8 @@ int hash_page(unsigned long ea, unsigned long access, unsigned long trap) } } -check_paca_psize (ea, mm, psize, user_region); +if (current->mm == mm) +check_paca_psize (ea, mm, psize, user_region);#endif /* CONFIG_PPC_64K_PAGES */ #ifdef CONFIG_PPC_HAS_HASH_64K @@ -1180,6 +1179,17 @@ bail:exception_exit (prev_state);return rc; } +EXPORT_SYMBOL_GPL (hash_page_mm); + +int hash_page (unsigned long ea,unsigned long access,unsigned long trap) +{ +struct mm_struct *mm = current->mm; + +if (REGION_ID (ea) ==VMALLOC_REGION_ID ) + mm = &init_mm; + +return hash_page_mm (mm, ea, access, trap); +}EXPORT_SYMBOL_GPL (hash_page); void hash_preload(struct mm_struct *mm, unsigned long ea,Signature · 7 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
PATCH v4 10/16 powerpc/opal: Add PHB to cxl mode call
In reply to Michael NeulingFrom: Ian Munsie <[email protected]>
This adds the OPAL call to change a PHB into cxl mode.
--- arch/powerpc/include/asm/opal.h | 2 ++ arch/powerpc/platforms/powernv/opal-wrappers.S | 1 + 2 files changed, 3 insertions(+)
arch/powerpc/include/asm/opal.h +2 -0
@@ -146,6 +146,7 @@ struct opal_sg_list {#define OPAL_GET_PARAM 89#define OPAL_SET_PARAM 90#define OPAL_DUMP_RESEND 91 +#define OPAL_PCI_SET_PHB_CXL_MODE 93#define OPAL_DUMP_INFO2 94#define OPAL_PCI_EEH_FREEZE_SET 97#define OPAL_HANDLE_HMI 98
@@ -924,6 +925,7 @@ int64_t opal_sensor_read(uint32_t sensor_hndl, int token, __be32 *sensor_data);int64_t opal_handle_hmi (void );int64_t opal_register_dump_region (uint32_t id,uint64_t start,uint64_t end);int64_t opal_unregister_dump_region (uint32_t id); +int64_t opal_pci_set_phb_cxl_mode (uint64_t phb_id,uint64_t mode,uint64_t pe_number);/* Internal functions */ extern int early_init_dt_scan_opal(unsigned long node, const char *uname,
arch/powerpc/platforms/powernv/opal-wrappers.S +1 -0
@@ -247,3 +247,4 @@ OPAL_CALL(opal_set_param, OPAL_SET_PARAM); OPAL_CALL(opal_handle_hmi, OPAL_HANDLE_HMI); OPAL_CALL(opal_register_dump_region, OPAL_REGISTER_DUMP_REGION); OPAL_CALL(opal_unregister_dump_region, OPAL_UNREGISTER_DUMP_REGION); +OPAL_CALL(opal_pci_set_phb_cxl_mode, OPAL_PCI_SET_PHB_CXL_MODE);
Signature · 1 line
1.9.1
PATCH v4 11/16 powerpc/mm: Add hooks for cxl
In reply to Michael NeulingFrom: Ian Munsie <[email protected]>
This adds hooks into the core powerpc mm code for cxl.
The core powerpc code sometimes uses local tlbie. Unfortunately this won't work with the current cxl driver as it relies on snooping tlbie broadcasts.
The cxl hardware can have TLB entries invalidated via MMIO but this is not currently supported by the driver. In future we can make local tlbie smarter so that it invalidates cxl contexts via MMIO when it needs to but for now we have this workaround.
This workaround checks for any active cxl contexts and if so, disables local tlbie.
This also adds a hook for when SLBs are invalidated. This ensures any corresponding SLBs in cxl are also invalidated at the same time. This is required for segment demotion.
--- arch/powerpc/mm/copro_fault.c | 2 ++ arch/powerpc/mm/hash_native_64.c | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-)
arch/powerpc/mm/copro_fault.c +2 -0
@@ -26,6 +26,7 @@#include <asm/reg.h> #include <asm/copro.h> #include <asm/spu.h> +#include <misc/cxl.h> /* * This ought to be kept in sync with the powerpc specific do_page_fault
@@ -143,5 +144,6 @@ void copro_flush_all_slbs(struct mm_struct *mm)#ifdef CONFIG_SPU_BASE spu_flush_all_slbs (mm);#endif +cxl_slbia (mm); }EXPORT_SYMBOL_GPL (copro_flush_all_slbs);
arch/powerpc/mm/hash_native_64.c +5 -1
@@ -29,6 +29,8 @@#include <asm/kexec.h> #include <asm/ppc-opcode.h> +#include <misc/cxl.h> +#ifdef DEBUG_LOW #define DBG_LOW(fmt...) udbg_printf(fmt)#else
@@ -149,9 +151,11 @@ static inline void __tlbiel(unsigned long vpn, int psize, int apsize, int ssize)static inline void tlbie (unsigned long vpn,int psize,int apsize,int ssize,int local) { -unsigned int use_local = local &&mmu_has_feature (MMU_FTR_TLBIEL ); +unsigned int use_local;int lock_tlbie = !mmu_has_feature (MMU_FTR_LOCKLESS_TLBIE ); + use_local = local &&mmu_has_feature (MMU_FTR_TLBIEL ) && !cxl_ctx_in_use (); +if (use_local) use_local = mmu_psize_defs[psize].tlbiel;if (lock_tlbie && !use_local)
Signature · 1 line
1.9.1
Re: [PATCH v4 11/16] powerpc/mm: Add hooks for cxl
Quoted 39 lines · Michael Neuling
From: Ian Munsie <[email protected]>
This adds hooks into the core powerpc mm code for cxl.
The core powerpc code sometimes uses local tlbie. Unfortunately this won't work with the current cxl driver as it relies on snooping tlbie broadcasts.
The cxl hardware can have TLB entries invalidated via MMIO but this is not currently supported by the driver. In future we can make local tlbie smarter so that it invalidates cxl contexts via MMIO when it needs to but for now we have this workaround.
This workaround checks for any active cxl contexts and if so, disables local tlbie.
This also adds a hook for when SLBs are invalidated. This ensures any corresponding SLBs in cxl are also invalidated at the same time. This is required for segment demotion.
Signed-off-by Ian Munsie <[email protected]>Signed-off-by Michael Neuling <[email protected]>--- arch/powerpc/mm/copro_fault.c | 2 ++ arch/powerpc/mm/hash_native_64.c | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-)arch/powerpc/mm/copro_fault.c +1
-0@@ -26,6 +26,7 @@#include <asm/reg.h> #include <asm/copro.h> #include <asm/spu.h> +#include <misc/cxl.h> /* * This ought to be kept in sync with the powerpc specific do_page_fault
arch/powerpc/mm/copro_fault.c void copro_flush_all_slbs(struct mm_struct *mm) · line 148
Quoted 5 lines
arch/powerpc/mm/copro_fault.c +1
-0@@ -143,5 +144,6 @@ void copro_flush_all_slbs(struct mm_struct *mm)#ifdef CONFIG_SPU_BASE spu_flush_all_slbs (mm);#endif +cxl_slbia (mm); }
If you split this patch into two and move the above hunk in a patch before "[PATCH v4 09/16] powerpc/mm: Add new hash_page_mm()", it would make it much easier to follow. We could then update the commit of the 09th patch to carry additional information that talk about how the hash_page_mm really work as I replied to that patch.
Quoted 35 lines
arch/powerpc/mm/copro_fault.c +0
-0EXPORT_SYMBOL_GPL (copro_flush_all_slbs);arch/powerpc/mm/hash_native_64.c +5
-1@@ -29,6 +29,8 @@#include <asm/kexec.h> #include <asm/ppc-opcode.h> +#include <misc/cxl.h> +#ifdef DEBUG_LOW #define DBG_LOW(fmt...) udbg_printf(fmt)#else @@ -149,9 +151,11 @@ static inline void __tlbiel(unsigned long vpn, int psize, int apsize, int ssize)static inline void tlbie (unsigned long vpn,int psize,int apsize,int ssize,int local) { -unsigned int use_local = local &&mmu_has_feature (MMU_FTR_TLBIEL ); +unsigned int use_local;int lock_tlbie = !mmu_has_feature (MMU_FTR_LOCKLESS_TLBIE ); + use_local = local &&mmu_has_feature (MMU_FTR_TLBIEL ) && !cxl_ctx_in_use (); +if (use_local) use_local = mmu_psize_defs[psize].tlbiel;if (lock_tlbie && !use_local)Signature · 7 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
PATCH v4 12/16 cxl: Add base builtin support
In reply to Michael NeulingFrom: Ian Munsie <[email protected]>
This adds the base cxl support that cannot be built as a module. Specifically it adds the cxl callbacks that are called from the core powerpc mm code which must always exist irrespective of if the cxl module is loaded or not. This is similar to how cell works with CONFIG_SPU_BASE.
This adds a cxl_slbia() call (similar to spu_flush_all_slbs()) which checks if the cxl module is loaded and in use, returning immediately if it is not. If it is in use it calls into the cxl SLB invalidation code.
--- drivers/misc/Kconfig | 1 + drivers/misc/Makefile | 1 + drivers/misc/cxl/Kconfig | 8 +++++ drivers/misc/cxl/Makefile | 1 + drivers/misc/cxl/base.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 97 insertions(+) create mode 100644 drivers/misc/cxl/Kconfig create mode 100644 drivers/misc/cxl/Makefile create mode 100644 drivers/misc/cxl/base.c
drivers/misc/Kconfig +1 -0
@@ -527,4 +527,5 @@ source "drivers/misc/vmw_vmci/Kconfig" source "drivers/misc/mic/Kconfig" source "drivers/misc/genwqe/Kconfig" source "drivers/misc/echo/Kconfig" +source "drivers/misc/cxl/Kconfig" endmenu
drivers/misc/Makefile +1 -0
@@ -55,3 +55,4 @@ obj-y += mic/ obj-$(CONFIG_GENWQE) += genwqe/ obj-$(CONFIG_ECHO) += echo/ obj-$(CONFIG_VEXPRESS_SYSCFG) += vexpress-syscfg.o +obj-$(CONFIG_CXL_BASE) += cxl/
drivers/misc/cxl/Kconfig new file +8 -0
@@ -0,0 +1,8 @@ +# +# IBM Coherent Accelerator (CXL) compatible devices +# + +config CXL_BASE + bool + default n + select PPC_COPRO_BASE
drivers/misc/cxl/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-$(CONFIG_CXL_BASE) += base.o
drivers/misc/cxl/base.c new file +86 -0
86 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v4 13/16 cxl: Driver code for powernv PCIe based cards for userspace access
In reply to Michael NeulingFrom: Ian Munsie <[email protected]>
This is the core of the cxl driver.
It adds support for using cxl cards in the powernv environment only (ie POWER8 bare metal). It allows access to cxl accelerators by userspace using the /dev/cxl/afuM.N char devices.
The kernel driver has no knowledge of the function implemented by the accelerator. It provides services to userspace via the /dev/cxl/afuM.N devices. When a program opens this device and runs the start work IOCTL, the accelerator will have coherent access to that processes memory using the same virtual addresses. That process may mmap the device to access any MMIO space the accelerator provides. Also, reads on the device will allow interrupts to be received. These services are further documented in a later patch in Documentation/powerpc/cxl.txt.
Documentation of the cxl hardware architecture and userspace API is provided in subsequent patches.
--- drivers/misc/cxl/context.c | 193 +++++++++ drivers/misc/cxl/cxl.h | 629 ++++++++++++++++++++++++++++ drivers/misc/cxl/debugfs.c | 132 ++++++ drivers/misc/cxl/fault.c | 291 +++++++++++++ drivers/misc/cxl/file.c | 508 ++++++++++++++++++++++ drivers/misc/cxl/irq.c | 402 ++++++++++++++++++ drivers/misc/cxl/main.c | 230 ++++++++++ drivers/misc/cxl/native.c | 683 ++++++++++++++++++++++++++++++ drivers/misc/cxl/pci.c | 1000 ++++++++++++++++++++++++++++++++++++++++++++ drivers/misc/cxl/sysfs.c | 385 +++++++++++++++++ 10 files changed, 4453 insertions(+) create mode 100644 drivers/misc/cxl/context.c create mode 100644 drivers/misc/cxl/cxl.h create mode 100644 drivers/misc/cxl/debugfs.c create mode 100644 drivers/misc/cxl/fault.c create mode 100644 drivers/misc/cxl/file.c create mode 100644 drivers/misc/cxl/irq.c create mode 100644 drivers/misc/cxl/main.c create mode 100644 drivers/misc/cxl/native.c create mode 100644 drivers/misc/cxl/pci.c create mode 100644 drivers/misc/cxl/sysfs.c
drivers/misc/cxl/context.c new file +193 -0
@@ -0,0 +1,193 @@ +/* +* Copyright 2014 IBM Corp. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version +* 2 of the License, or (at your option) any later version. +*/ + +#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/bitmap.h> +#include <linux/sched.h> +#include <linux/pid.h> +#include <linux/fs.h> +#include <linux/mm.h> +#include <linux/debugfs.h> +#include <linux/slab.h> +#include <linux/idr.h> +#include <asm/cputable.h> +#include <asm/current.h> +#include <asm/copro.h> + +#include "cxl.h" + +/* +* Allocates space for a CXL context. +*/ +struct cxl_context *cxl_context_alloc (void ) +{ +return kzalloc (sizeof (struct cxl_context ),GFP_KERNEL ); +} + +/* +* Initialises a CXL context. +*/ +int cxl_context_init (struct cxl_context *ctx,struct cxl_afu *afu,bool master) +{ +int i; + +spin_lock_init (&ctx->sste_lock); + ctx->afu = afu; + ctx->master = master; + ctx->pid =NULL ;/* Set in start work ioctl */ + +/* +* Allocate the segment table before we put it in the IDR so that we +* can always access it when dereferenced from IDR. For the same +* reason, the segment table is only destroyed after the context is +* removed from the IDR. Access to this in the IOCTL is protected by +* Linux filesytem symantics (can't IOCTL until open is complete). +*/ + i =cxl_alloc_sst (ctx); +if (i) +return i; + +INIT_WORK (&ctx->fault_work, cxl_handle_fault); + +init_waitqueue_head (&ctx->wq); +spin_lock_init (&ctx->lock); + + ctx->irq_bitmap =NULL ; + ctx->pending_irq = false; + ctx->pending_fault = false; + ctx->pending_afu_err = false; + +/* +* When we have to destroy all contexts in cxl_context_detach_all() we +* end up with afu_release_irqs() called from inside a +* idr_for_each_entry(). Hence we need to make sure that anything +* dereferenced from this IDR is ok before we allocate the IDR here. +* This clears out the IRQ ranges to ensure this. +*/ +for (i =0 ; i <CXL_IRQ_RANGES ; i++) + ctx->irqs.range[i] =0 ; + +mutex_init (&ctx->status_mutex); + + ctx->status =OPENED ; + +/* +* Allocating IDR! We better make sure everything's setup that +* dereferences from it. +*/ +idr_preload (GFP_KERNEL ); +spin_lock (&afu->contexts_lock); + i =idr_alloc (&ctx->afu->contexts_idr, ctx,0 , + ctx->afu->num_procs,GFP_NOWAIT ); +spin_unlock (&afu->contexts_lock); +idr_preload_end (); +if (i <0 ) +return i; + + ctx->pe = i; + ctx->elem = &ctx->afu->spa[i]; + ctx->pe_inserted = false; +return 0 ; +} + +/* +* Map a per-context mmio space into the given vma. +*/ +int cxl_context_iomap (struct cxl_context *ctx,struct vm_area_struct *vma) +{ +u64 len = vma->vm_end - vma->vm_start; + len =min (len, ctx->psn_size); + +if (ctx->afu->current_mode ==CXL_MODE_DEDICATED ) { + vma->vm_page_prot =pgprot_noncached (vma->vm_page_prot); +return vm_iomap_memory (vma, ctx->afu->psn_phys, ctx->afu->adapter->ps_size); + } + +/* make sure there is a valid per process space for this AFU */ +if ((ctx->master && !ctx->afu->psa) || (!ctx->afu->pp_psa)) { +pr_devel ("AFU doesn't support mmio space\n" ); +return -EINVAL ; + } + +/* Can't mmap until the AFU is enabled */ +if (!ctx->afu->enabled) +return -EBUSY ; + +pr_devel ("%s: mmio physical: %llx pe: %i master:%i\n" , __func__, + ctx->psn_phys, ctx->pe , ctx->master); + + vma->vm_page_prot =pgprot_noncached (vma->vm_page_prot); +return vm_iomap_memory (vma, ctx->psn_phys, len); +} + +/* +* Detach a context from the hardware. This disables interrupts and doesn't +* return until all outstanding interrupts for this context have completed. The +* hardware should no longer access *ctx after this has returned. +*/ +static void __detach_context (struct cxl_context *ctx) +{ +enum cxl_context_status status; + +mutex_lock (&ctx->status_mutex); + status = ctx->status; + ctx->status =CLOSED ; +mutex_unlock (&ctx->status_mutex); +if (status !=STARTED ) +return ; + +WARN_ON (cxl_detach_process (ctx)); +afu_release_irqs (ctx); +flush_work (&ctx->fault_work);/* Only needed for dedicated process */ +wake_up_all (&ctx->wq); +} + +/* +* Detach the given context from the AFU. This doesn't actually +* free the context but it should stop the context running in hardware +* (ie. prevent this context from generating any further interrupts +* so that it can be freed). +*/ +void cxl_context_detach (struct cxl_context *ctx) +{ +__detach_context (ctx); +} + +/* +* Detach all contexts on the given AFU. +*/ +void cxl_context_detach_all (struct cxl_afu *afu) +{ +struct cxl_context *ctx; +int tmp; + +rcu_read_lock (); +idr_for_each_entry (&afu->contexts_idr, ctx, tmp) +/* +* Anything done in here needs to be setup before the IDR is +* created and torn down after the IDR removed +*/ +__detach_context (ctx); +rcu_read_unlock (); +} + +void cxl_context_free (struct cxl_context *ctx) +{ +spin_lock (&ctx->afu->contexts_lock); +idr_remove (&ctx->afu->contexts_idr, ctx->pe); +spin_unlock (&ctx->afu->contexts_lock); +synchronize_rcu (); + +free_page ((u64 )ctx->sstp); + ctx->sstp =NULL ; + +put_pid (ctx->pid); +kfree (ctx); +}
drivers/misc/cxl/cxl.h new file +629 -0
629 lines not on this page · raw message
drivers/misc/cxl/debugfs.c new file +132 -0
132 lines not on this page · raw message
drivers/misc/cxl/fault.c new file +291 -0
291 lines not on this page · raw message
drivers/misc/cxl/file.c new file +508 -0
508 lines not on this page · raw message
drivers/misc/cxl/irq.c new file +402 -0
402 lines not on this page · raw message
drivers/misc/cxl/main.c new file +230 -0
230 lines not on this page · raw message
drivers/misc/cxl/native.c new file +683 -0
615 lines not on this page · raw message
drivers/misc/cxl/pci.c new file +1000 -0
1,000 lines not on this page · raw message
drivers/misc/cxl/sysfs.c new file +385 -0
385 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.9.1
Part of the diff is not shown here. View the raw message.
Re: [PATCH v4 13/16] cxl: Driver code for powernv PCIe based cards for userspace access
Excerpts from Michael Neuling's message of 2014-10-08 19:55:02 +1100:
Quoted 2 lines
drivers/misc/cxl/file.c new file +2
-0+static ssize_t afu_read (struct file *file,char __user *buf,size_t count, +loff_t *off)
...
drivers/misc/cxl/file.c line 293
Quoted 11 lines
drivers/misc/cxl/file.c new file +11
-0+for (;;) { +prepare_to_wait (&ctx->wq, &wait,TASK_INTERRUPTIBLE ); +if (ctx_event_pending (ctx)) +break ; + +spin_unlock_irqrestore (&ctx->lock, flags); +if (file->f_flags &O_NONBLOCK ) +return -EAGAIN ; + +if (signal_pending (current)) +return -ERESTARTSYS ;
Looks like I mucked this up while refactoring - these two cases no longer call finish_wait() which can lead to a crash if something later wakes up the ctx->wq... I'll post a fix in a separate patch shortly.
-Ian
PATCH 1/1 CXL: Fix afu_read() not doing finish_wait() on signal or non-blocking
If afu_read() returned due to a signal or the AFU file descriptor being opened non-blocking it would not call finish_wait() before returning, which could lead to a crash later when something else wakes up the wait queue.
This patch restructures the wait logic to ensure that the cleanup is done correctly.
--- drivers/misc/cxl/file.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)
drivers/misc/cxl/file.c +15 -5
@@ -273,6 +273,7 @@ static ssize_t afu_read(struct file *file, char __user *buf, size_t count,struct cxl_context *ctx = file->private_data;struct cxl_event event;unsigned long flags; +int rc;DEFINE_WAIT (wait);if (count <CXL_READ_MIN_SIZE )
@@ -285,13 +286,17 @@ static ssize_t afu_read(struct file *file, char __user *buf, size_t count,if (ctx_event_pending (ctx))break ; -spin_unlock_irqrestore (&ctx->lock, flags); -if (file->f_flags &O_NONBLOCK ) -return -EAGAIN ; +if (file->f_flags &O_NONBLOCK ) { + rc = -EAGAIN ; + goto out; + } -if (signal_pending (current)) -return -ERESTARTSYS ; +if (signal_pending (current)) { + rc = -ERESTARTSYS ; + goto out; + } +spin_unlock_irqrestore (&ctx->lock, flags);pr_devel ("afu_read going to sleep...\n" );schedule ();pr_devel ("afu_read woken up\n" );
@@ -336,6 +341,11 @@ static ssize_t afu_read(struct file *file, char __user *buf, size_t count,if (copy_to_user (buf, &event, event.header.size))return -EFAULT ;return event.header.size; + +out: +finish_wait (&ctx->wq, &wait); +spin_unlock_irqrestore (&ctx->lock, flags); +return rc; }static const struct file_operations afu_fops = {
Signature · 1 line
2.1.0
PATCH 1/1 CXL: Fix afu_read() not doing finish_wait() on signal or non-blocking
From: Ian Munsie <[email protected]>
If afu_read() returned due to a signal or the AFU file descriptor being opened non-blocking it would not call finish_wait() before returning, which could lead to a crash later when something else wakes up the wait queue.
This patch restructures the wait logic to ensure that the cleanup is done correctly.
---
Resending with correct whitespace as my mailer decided to replace tabs with spaces on the last try.
drivers/misc/cxl/file.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)
drivers/misc/cxl/file.c +15 -5
@@ -273,6 +273,7 @@ static ssize_t afu_read(struct file *file, char __user *buf, size_t count,struct cxl_context *ctx = file->private_data;struct cxl_event event;unsigned long flags; +int rc;DEFINE_WAIT (wait);if (count <CXL_READ_MIN_SIZE )
@@ -285,13 +286,17 @@ static ssize_t afu_read(struct file *file, char __user *buf, size_t count,if (ctx_event_pending (ctx))break ; -spin_unlock_irqrestore (&ctx->lock, flags); -if (file->f_flags &O_NONBLOCK ) -return -EAGAIN ; +if (file->f_flags &O_NONBLOCK ) { + rc = -EAGAIN ; + goto out; + } -if (signal_pending (current)) -return -ERESTARTSYS ; +if (signal_pending (current)) { + rc = -ERESTARTSYS ; + goto out; + } +spin_unlock_irqrestore (&ctx->lock, flags);pr_devel ("afu_read going to sleep...\n" );schedule ();pr_devel ("afu_read woken up\n" );
@@ -336,6 +341,11 @@ static ssize_t afu_read(struct file *file, char __user *buf, size_t count,if (copy_to_user (buf, &event, event.header.size))return -EFAULT ;return event.header.size; + +out: +finish_wait (&ctx->wq, &wait); +spin_unlock_irqrestore (&ctx->lock, flags); +return rc; }static const struct file_operations afu_fops = {
Signature · 1 line
2.1.0
PATCH v4 14/16 cxl: Add userspace header file
In reply to Michael NeulingFrom: Ian Munsie <[email protected]>
This adds a header file for use by userspace programs wanting to interact with the kernel cxl driver. It defines structs and magic numbers required for userspace to interact with devices in /dev/cxl/afuM.N.
Further documentation on this interface is added in a subsequent patch in Documentation/powerpc/cxl.txt.
It also adds this new userspace header file to Kbuild so it's exported when doing "make headers_installs".
--- include/uapi/Kbuild | 1 + include/uapi/misc/Kbuild | 2 ++ include/uapi/misc/cxl.h | 87 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 include/uapi/misc/Kbuild create mode 100644 include/uapi/misc/cxl.h
include/uapi/Kbuild +1 -0
@@ -12,3 +12,4 @@ header-y += video/ header-y += drm/ header-y += xen/ header-y += scsi/ +header-y += misc/
include/uapi/misc/Kbuild new file +2 -0
@@ -0,0 +1,2 @@ +# misc Header export list +header-y += cxl.h
include/uapi/misc/cxl.h new file +87 -0
87 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v4 15/16 cxl: Add driver to Kbuild and Makefiles
In reply to Michael NeulingFrom: Ian Munsie <[email protected]>
--- drivers/misc/cxl/Kconfig | 17 +++++++++++++++++ drivers/misc/cxl/Makefile | 2 ++ 2 files changed, 19 insertions(+)
drivers/misc/cxl/Kconfig +17 -0
@@ -6,3 +6,20 @@ config CXL_BASE bool default n select PPC_COPRO_BASE + +config CXL + tristate "Support for IBM Coherent Accelerators (CXL)" + depends on PPC_POWERNV && PCI_MSI + select CXL_BASE + default m + help + Select this option to enable driver support for IBM Coherent + Accelerators (CXL). CXL is otherwise known as Coherent Accelerator + Processor Interface (CAPI). CAPI allows accelerators in FPGAs to be + coherently attached to a CPU via an MMU. This driver enables + userspace programs to access these accelerators via /dev/cxl/afuM.N + devices. + + CAPI adapters are found in POWER8 based systems. + + If unsure, say N.
drivers/misc/cxl/Makefile +2 -0
@@ -1 +1,3 @@ +cxl-y += main.o file.o irq.o fault.o native.o context.o sysfs.o debugfs.o pci.o +obj-$(CONFIG_CXL) += cxl.o obj-$(CONFIG_CXL_BASE) += base.o
Signature · 1 line
1.9.1
PATCH v4 16/16 cxl: Add documentation for userspace APIs
In reply to Michael NeulingFrom: Ian Munsie <[email protected]>
This documentation gives an overview of the hardware architecture, userspace APIs via /dev/cxl/afuM.N and the syfs files. It also adds a MAINTAINERS file entry for cxl.
--- Documentation/ABI/testing/sysfs-class-cxl | 130 ++++++++++ Documentation/ioctl/ioctl-number.txt | 1 + Documentation/powerpc/00-INDEX | 2 + Documentation/powerpc/cxl.txt | 379 ++++++++++++++++++++++++++++++ MAINTAINERS | 12 + include/uapi/misc/cxl.h | 7 +- 6 files changed, 528 insertions(+), 3 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-class-cxl create mode 100644 Documentation/powerpc/cxl.txt
Documentation/ABI/testing/sysfs-class-cxl new file +130 -0
@@ -0,0 +1,130 @@ +Slave contexts (eg. /sys/class/cxl/afu0.0s): + +What: /sys/class/cxl/<afu>/irqs_max +Date: September 2014 +Contact: [email protected] +Description: read/write + Decimal value of maximum number of interrupts that can be + requested by userspace. The default on probe is the maximum + that hardware can support (eg. 2037). Write values will limit + userspace applications to that many userspace interrupts. Must + be >= irqs_min. + +What: /sys/class/cxl/<afu>/irqs_min +Date: September 2014 +Contact: [email protected] +Description: read only + Decimal value of the minimum number of interrupts that + userspace must request on a CXL_START_WORK ioctl. Userspace may + omit the num_interrupts field in the START_WORK IOCTL to get + this minimum automatically. + +What: /sys/class/cxl/<afu>/mmio_size +Date: September 2014 +Contact: [email protected] +Description: read only + Decimal value of the size of the MMIO space that may be mmaped + by userspace. + +What: /sys/class/cxl/<afu>/modes_supported +Date: September 2014 +Contact: [email protected] +Description: read only + List of the modes this AFU supports. One per line. + Valid entries are: "dedicated_process" and "afu_directed" + +What: /sys/class/cxl/<afu>/mode +Date: September 2014 +Contact: [email protected] +Description: read/write + The current mode the AFU is using. Will be one of the modes + given in modes_supported. Writing will change the mode + provided that no user contexts are attached. + + +What: /sys/class/cxl/<afu>/prefault_mode +Date: September 2014 +Contact: [email protected] +Description: read/write + Set the mode for prefaulting in segments into the segment table + when performing the START_WORK ioctl. Possible values: + none: No prefaulting (default) + work_element_descriptor: Treat the work element + descriptor as an effective address and + prefault what it points to. + all: all segments process calling START_WORK maps. + +What: /sys/class/cxl/<afu>/reset +Date: September 2014 +Contact: [email protected] +Description: write only + Writing 1 here will reset the AFU provided there are not + contexts active on the AFU. + +What: /sys/class/cxl/<afu>/api_version +Date: September 2014 +Contact: [email protected] +Description: read only + Decimal value of the current version of the kernel/user API. + +What: /sys/class/cxl/<afu>/api_version_com +Date: September 2014 +Contact: [email protected] +Description: read only + Decimal value of the the lowest version of the userspace API + this this kernel supports. + + + +Master contexts (eg. /sys/class/cxl/afu0.0m) + +What: /sys/class/cxl/<afu>m/mmio_size +Date: September 2014 +Contact: [email protected] +Description: read only + Decimal value of the size of the MMIO space that may be mmaped + by userspace. This includes all slave contexts space also. + +What: /sys/class/cxl/<afu>m/pp_mmio_len +Date: September 2014 +Contact: [email protected] +Description: read only + Decimal value of the Per Process MMIO space length. + +What: /sys/class/cxl/<afu>m/pp_mmio_off +Date: September 2014 +Contact: [email protected] +Description: read only + Decimal value of the Per Process MMIO space offset. + + +Card info (eg. /sys/class/cxl/card0) + +What: /sys/class/cxl/<card>/caia_version +Date: September 2014 +Contact: [email protected] +Description: read only + Identifies the CAIA Version the card implements. + +What: /sys/class/cxl/<card>/psl_version +Date: September 2014 +Contact: [email protected] +Description: read only + Identifies the revision level of the PSL. + +What: /sys/class/cxl/<card>/base_image +Date: September 2014 +Contact: [email protected] +Description: read only + Identifies the revision level of the base image for devices + that support loadable PSLs. For FPGAs this field identifies + the image contained in the on-adapter flash which is loaded + during the initial program load. + +What: /sys/class/cxl/<card>/image_loaded +Date: September 2014 +Contact: [email protected] +Description: read only + Will return "user" or "factory" depending on the image loaded + onto the card. +
Documentation/ioctl/ioctl-number.txt +1 -0
@@ -313,6 +313,7 @@ Code Seq#(hex) Include File Comments 0xB1 00-1F PPPoX <mailto:[email protected]> 0xB3 00 linux/mmc/ioctl.h 0xC0 00-0F linux/usb/iowarrior.h +0xCA 00-0F uapi/misc/cxl.h 0xCB 00-1F CBM serial IEC bus in development: <mailto:[email protected]> 0xCD 01 linux/reiserfs_fs.h
Documentation/powerpc/00-INDEX +2 -0
@@ -11,6 +11,8 @@ bootwrapper.txt cpu_features.txt - info on how we support a variety of CPUs with minimal compile-time options. +cxl.txt + - Overview of the CXL driver. eeh-pci-error-recovery.txt - info on PCI Bus EEH Error Recovery firmware-assisted-dump.txt
Documentation/powerpc/cxl.txt new file +379 -0
379 lines not on this page · raw message
MAINTAINERS +12 -0
@@ -2711,6 +2711,18 @@ W: http://www.chelsio.com S: Supported F: drivers/net/ethernet/chelsio/cxgb4vf/ +CXL (IBM Coherent Accelerator Processor Interface CAPI) DRIVER +M: Ian Munsie <[email protected]> +M: Michael Neuling <[email protected]> +L: [email protected] +S: Supported +F: drivers/misc/cxl/ +F: include/misc/cxl.h +F: include/uapi/misc/cxl.h +F: Documentation/powerpc/cxl.txt +F: Documentation/powerpc/cxl.txt +F: Documentation/ABI/testing/sysfs-class-cxl + STMMAC ETHERNET DRIVER M: Giuseppe Cavallaro <[email protected]> L: [email protected]
include/uapi/misc/cxl.h +4 -3
@@ -13,7 +13,7 @@#include <linux/types.h> #include <linux/ioctl.h> -/* Structs for IOCTLS for userspace to talk to the kernel */ +struct cxl_ioctl_start_work {__u64 flags;__u64 work_element_descriptor;
@@ -26,19 +26,20 @@ struct cxl_ioctl_start_work {__u64 reserved5;__u64 reserved6; }; +#define CXL_START_WORK_AMR 0x0000000000000001ULL#define CXL_START_WORK_NUM_IRQS 0x0000000000000002ULL#define CXL_START_WORK_ALL (CXL_START_WORK_AMR |\ CXL_START_WORK_NUM_IRQS) -/* IOCTL numbers */ +/* ioctl numbers */ #define CXL_MAGIC 0xCA#define CXL_IOCTL_START_WORK _IOW(CXL_MAGIC, 0x00, struct cxl_ioctl_start_work)#define CXL_IOCTL_GET_PROCESS_ELEMENT _IOR(CXL_MAGIC, 0x01, __u32) -/* Events from read() */ #define CXL_READ_MIN_SIZE 0x1000/* 4K */ +/* Events from read() */ enum cxl_event_type {CXL_EVENT_RESERVED =0 ,CXL_EVENT_AFU_INTERRUPT =1 ,
Signature · 1 line
1.9.1