mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-28 11:18:45 +07:00
5e2d059b52
Notable changes: - A fix for a bug in our page table fragment allocator, where a page table page could be freed and reallocated for something else while still in use, leading to memory corruption etc. The fix reuses pt_mm in struct page (x86 only) for a powerpc only refcount. - Fixes to our pkey support. Several are user-visible changes, but bring us in to line with x86 behaviour and/or fix outright bugs. Thanks to Florian Weimer for reporting many of these. - A series to improve the hvc driver & related OPAL console code, which have been seen to cause hardlockups at times. The hvc driver changes in particular have been in linux-next for ~month. - Increase our MAX_PHYSMEM_BITS to 128TB when SPARSEMEM_VMEMMAP=y. - Remove Power8 DD1 and Power9 DD1 support, neither chip should be in use anywhere other than as a paper weight. - An optimised memcmp implementation using Power7-or-later VMX instructions - Support for barrier_nospec on some NXP CPUs. - Support for flushing the count cache on context switch on some IBM CPUs (controlled by firmware), as a Spectre v2 mitigation. - A series to enhance the information we print on unhandled signals to bring it into line with other arches, including showing the offending VMA and dumping the instructions around the fault. Thanks to: Aaro Koskinen, Akshay Adiga, Alastair D'Silva, Alexey Kardashevskiy, Alexey Spirkov, Alistair Popple, Andrew Donnellan, Aneesh Kumar K.V, Anju T Sudhakar, Arnd Bergmann, Bartosz Golaszewski, Benjamin Herrenschmidt, Bharat Bhushan, Bjoern Noetel, Boqun Feng, Breno Leitao, Bryant G. Ly, Camelia Groza, Christophe Leroy, Christoph Hellwig, Cyril Bur, Dan Carpenter, Daniel Klamt, Darren Stevens, Dave Young, David Gibson, Diana Craciun, Finn Thain, Florian Weimer, Frederic Barrat, Gautham R. Shenoy, Geert Uytterhoeven, Geoff Levand, Guenter Roeck, Gustavo Romero, Haren Myneni, Hari Bathini, Joel Stanley, Jonathan Neuschäfer, Kees Cook, Madhavan Srinivasan, Mahesh Salgaonkar, Markus Elfring, Mathieu Malaterre, Mauro S. M. Rodrigues, Michael Hanselmann, Michael Neuling, Michael Schmitz, Mukesh Ojha, Murilo Opsfelder Araujo, Nicholas Piggin, Parth Y Shah, Paul Mackerras, Paul Menzel, Ram Pai, Randy Dunlap, Rashmica Gupta, Reza Arbab, Rodrigo R. Galvao, Russell Currey, Sam Bobroff, Scott Wood, Shilpasri G Bhat, Simon Guo, Souptick Joarder, Stan Johnson, Thiago Jung Bauermann, Tyrel Datwyler, Vaibhav Jain, Vasant Hegde, Venkat Rao B, zhong jiang. -----BEGIN PGP SIGNATURE----- iQJHBAABCgAxFiEEJFGtCPCthwEv2Y/bUevqPMjhpYAFAlt2O6cTHG1wZUBlbGxl cm1hbi5pZC5hdQAKCRBR6+o8yOGlgC7hD/4+cj796Df7GsVsIMxzQm7SS9dklIdO JuKj2Nr5HRzTH59jWlXukLG9mfTNCFgFJB4gEpK1ArDOTcHTCI9RRsLZTZ/kum66 7Pd+7T40dLYXB5uecuUs0vMXa2fI3syKh1VLzACSXv3Dh9BBIKQBwW/aD2eww4YI 1fS5LnXZ2PSxfr6KNAC6ogZnuaiD0sHXOYrtGHq+S/TFC7+Z6ySa6+AnPS+hPVoo /rHDE1Khr66aj7uk+PP2IgUrCFj6Sbj6hTVlS/iAuwbMjUl9ty6712PmvX9x6wMZ 13hJQI+g6Ci+lqLKqmqVUpXGSr6y4NJGPS/Hko4IivBTJApI+qV/tF2H9nxU+6X0 0RqzsMHPHy13n2torA1gC7ttzOuXPI4hTvm6JWMSsfmfjTxLANJng3Dq3ejh6Bqw 76EMowpDLexwpy7/glPpqNdsP4ySf2Qm8yq3mR7qpL4m3zJVRGs11x+s5DW8NKBL Fl5SqZvd01abH+sHwv6NLaLkEtayUyohxvyqu2RU3zu5M5vi7DhqstybTPjKPGu0 icSPh7b2y10WpOUpC6lxpdi8Me8qH47mVc/trZ+SpgBrsuEmtJhGKszEnzRCOqos o2IhYHQv3lQv86kpaAFQlg/RO+Lv+Lo5qbJ209V+hfU5nYzXpEulZs4dx1fbA+ze fK8GEh+u0L4uJg== =PzRz -----END PGP SIGNATURE----- Merge tag 'powerpc-4.19-1' of git://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux Pull powerpc updates from Michael Ellerman: "Notable changes: - A fix for a bug in our page table fragment allocator, where a page table page could be freed and reallocated for something else while still in use, leading to memory corruption etc. The fix reuses pt_mm in struct page (x86 only) for a powerpc only refcount. - Fixes to our pkey support. Several are user-visible changes, but bring us in to line with x86 behaviour and/or fix outright bugs. Thanks to Florian Weimer for reporting many of these. - A series to improve the hvc driver & related OPAL console code, which have been seen to cause hardlockups at times. The hvc driver changes in particular have been in linux-next for ~month. - Increase our MAX_PHYSMEM_BITS to 128TB when SPARSEMEM_VMEMMAP=y. - Remove Power8 DD1 and Power9 DD1 support, neither chip should be in use anywhere other than as a paper weight. - An optimised memcmp implementation using Power7-or-later VMX instructions - Support for barrier_nospec on some NXP CPUs. - Support for flushing the count cache on context switch on some IBM CPUs (controlled by firmware), as a Spectre v2 mitigation. - A series to enhance the information we print on unhandled signals to bring it into line with other arches, including showing the offending VMA and dumping the instructions around the fault. Thanks to: Aaro Koskinen, Akshay Adiga, Alastair D'Silva, Alexey Kardashevskiy, Alexey Spirkov, Alistair Popple, Andrew Donnellan, Aneesh Kumar K.V, Anju T Sudhakar, Arnd Bergmann, Bartosz Golaszewski, Benjamin Herrenschmidt, Bharat Bhushan, Bjoern Noetel, Boqun Feng, Breno Leitao, Bryant G. Ly, Camelia Groza, Christophe Leroy, Christoph Hellwig, Cyril Bur, Dan Carpenter, Daniel Klamt, Darren Stevens, Dave Young, David Gibson, Diana Craciun, Finn Thain, Florian Weimer, Frederic Barrat, Gautham R. Shenoy, Geert Uytterhoeven, Geoff Levand, Guenter Roeck, Gustavo Romero, Haren Myneni, Hari Bathini, Joel Stanley, Jonathan Neuschäfer, Kees Cook, Madhavan Srinivasan, Mahesh Salgaonkar, Markus Elfring, Mathieu Malaterre, Mauro S. M. Rodrigues, Michael Hanselmann, Michael Neuling, Michael Schmitz, Mukesh Ojha, Murilo Opsfelder Araujo, Nicholas Piggin, Parth Y Shah, Paul Mackerras, Paul Menzel, Ram Pai, Randy Dunlap, Rashmica Gupta, Reza Arbab, Rodrigo R. Galvao, Russell Currey, Sam Bobroff, Scott Wood, Shilpasri G Bhat, Simon Guo, Souptick Joarder, Stan Johnson, Thiago Jung Bauermann, Tyrel Datwyler, Vaibhav Jain, Vasant Hegde, Venkat Rao, zhong jiang" * tag 'powerpc-4.19-1' of git://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux: (234 commits) powerpc/mm/book3s/radix: Add mapping statistics powerpc/uaccess: Enable get_user(u64, *p) on 32-bit powerpc/mm/hash: Remove unnecessary do { } while(0) loop powerpc/64s: move machine check SLB flushing to mm/slb.c powerpc/powernv/idle: Fix build error powerpc/mm/tlbflush: update the mmu_gather page size while iterating address range powerpc/mm: remove warning about ‘type’ being set powerpc/32: Include setup.h header file to fix warnings powerpc: Move `path` variable inside DEBUG_PROM powerpc/powermac: Make some functions static powerpc/powermac: Remove variable x that's never read cxl: remove a dead branch powerpc/powermac: Add missing include of header pmac.h powerpc/kexec: Use common error handling code in setup_new_fdt() powerpc/xmon: Add address lookup for percpu symbols powerpc/mm: remove huge_pte_offset_and_shift() prototype powerpc/lib: Use patch_site to patch copy_32 functions once cache is enabled powerpc/pseries: Fix endianness while restoring of r3 in MCE handler. powerpc/fadump: merge adjacent memory ranges to reduce PT_LOAD segements powerpc/fadump: handle crash memory ranges array index overflow ...
541 lines
12 KiB
C
541 lines
12 KiB
C
/*
|
|
* 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/pci.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/file.h>
|
|
#include <misc/cxl.h>
|
|
#include <linux/module.h>
|
|
#include <linux/mount.h>
|
|
#include <linux/sched/mm.h>
|
|
#include <linux/mmu_context.h>
|
|
|
|
#include "cxl.h"
|
|
|
|
/*
|
|
* Since we want to track memory mappings to be able to force-unmap
|
|
* when the AFU is no longer reachable, we need an inode. For devices
|
|
* opened through the cxl user API, this is not a problem, but a
|
|
* userland process can also get a cxl fd through the cxl_get_fd()
|
|
* API, which is used by the cxlflash driver.
|
|
*
|
|
* Therefore we implement our own simple pseudo-filesystem and inode
|
|
* allocator. We don't use the anonymous inode, as we need the
|
|
* meta-data associated with it (address_space) and it is shared by
|
|
* other drivers/processes, so it could lead to cxl unmapping VMAs
|
|
* from random processes.
|
|
*/
|
|
|
|
#define CXL_PSEUDO_FS_MAGIC 0x1697697f
|
|
|
|
static int cxl_fs_cnt;
|
|
static struct vfsmount *cxl_vfs_mount;
|
|
|
|
static const struct dentry_operations cxl_fs_dops = {
|
|
.d_dname = simple_dname,
|
|
};
|
|
|
|
static struct dentry *cxl_fs_mount(struct file_system_type *fs_type, int flags,
|
|
const char *dev_name, void *data)
|
|
{
|
|
return mount_pseudo(fs_type, "cxl:", NULL, &cxl_fs_dops,
|
|
CXL_PSEUDO_FS_MAGIC);
|
|
}
|
|
|
|
static struct file_system_type cxl_fs_type = {
|
|
.name = "cxl",
|
|
.owner = THIS_MODULE,
|
|
.mount = cxl_fs_mount,
|
|
.kill_sb = kill_anon_super,
|
|
};
|
|
|
|
|
|
void cxl_release_mapping(struct cxl_context *ctx)
|
|
{
|
|
if (ctx->kernelapi && ctx->mapping)
|
|
simple_release_fs(&cxl_vfs_mount, &cxl_fs_cnt);
|
|
}
|
|
|
|
static struct file *cxl_getfile(const char *name,
|
|
const struct file_operations *fops,
|
|
void *priv, int flags)
|
|
{
|
|
struct file *file;
|
|
struct inode *inode;
|
|
int rc;
|
|
|
|
/* strongly inspired by anon_inode_getfile() */
|
|
|
|
if (fops->owner && !try_module_get(fops->owner))
|
|
return ERR_PTR(-ENOENT);
|
|
|
|
rc = simple_pin_fs(&cxl_fs_type, &cxl_vfs_mount, &cxl_fs_cnt);
|
|
if (rc < 0) {
|
|
pr_err("Cannot mount cxl pseudo filesystem: %d\n", rc);
|
|
file = ERR_PTR(rc);
|
|
goto err_module;
|
|
}
|
|
|
|
inode = alloc_anon_inode(cxl_vfs_mount->mnt_sb);
|
|
if (IS_ERR(inode)) {
|
|
file = ERR_CAST(inode);
|
|
goto err_fs;
|
|
}
|
|
|
|
file = alloc_file_pseudo(inode, cxl_vfs_mount, name,
|
|
flags & (O_ACCMODE | O_NONBLOCK), fops);
|
|
if (IS_ERR(file))
|
|
goto err_inode;
|
|
|
|
file->private_data = priv;
|
|
|
|
return file;
|
|
|
|
err_inode:
|
|
iput(inode);
|
|
err_fs:
|
|
simple_release_fs(&cxl_vfs_mount, &cxl_fs_cnt);
|
|
err_module:
|
|
module_put(fops->owner);
|
|
return file;
|
|
}
|
|
|
|
struct cxl_context *cxl_dev_context_init(struct pci_dev *dev)
|
|
{
|
|
struct cxl_afu *afu;
|
|
struct cxl_context *ctx;
|
|
int rc;
|
|
|
|
afu = cxl_pci_to_afu(dev);
|
|
if (IS_ERR(afu))
|
|
return ERR_CAST(afu);
|
|
|
|
ctx = cxl_context_alloc();
|
|
if (!ctx)
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
ctx->kernelapi = true;
|
|
|
|
/* Make it a slave context. We can promote it later? */
|
|
rc = cxl_context_init(ctx, afu, false);
|
|
if (rc)
|
|
goto err_ctx;
|
|
|
|
return ctx;
|
|
|
|
err_ctx:
|
|
kfree(ctx);
|
|
return ERR_PTR(rc);
|
|
}
|
|
EXPORT_SYMBOL_GPL(cxl_dev_context_init);
|
|
|
|
struct cxl_context *cxl_get_context(struct pci_dev *dev)
|
|
{
|
|
return dev->dev.archdata.cxl_ctx;
|
|
}
|
|
EXPORT_SYMBOL_GPL(cxl_get_context);
|
|
|
|
int cxl_release_context(struct cxl_context *ctx)
|
|
{
|
|
if (ctx->status >= STARTED)
|
|
return -EBUSY;
|
|
|
|
cxl_context_free(ctx);
|
|
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL_GPL(cxl_release_context);
|
|
|
|
static irq_hw_number_t cxl_find_afu_irq(struct cxl_context *ctx, int num)
|
|
{
|
|
__u16 range;
|
|
int r;
|
|
|
|
for (r = 0; r < CXL_IRQ_RANGES; r++) {
|
|
range = ctx->irqs.range[r];
|
|
if (num < range) {
|
|
return ctx->irqs.offset[r] + num;
|
|
}
|
|
num -= range;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
|
|
int cxl_set_priv(struct cxl_context *ctx, void *priv)
|
|
{
|
|
if (!ctx)
|
|
return -EINVAL;
|
|
|
|
ctx->priv = priv;
|
|
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL_GPL(cxl_set_priv);
|
|
|
|
void *cxl_get_priv(struct cxl_context *ctx)
|
|
{
|
|
if (!ctx)
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
return ctx->priv;
|
|
}
|
|
EXPORT_SYMBOL_GPL(cxl_get_priv);
|
|
|
|
int cxl_allocate_afu_irqs(struct cxl_context *ctx, int num)
|
|
{
|
|
int res;
|
|
irq_hw_number_t hwirq;
|
|
|
|
if (num == 0)
|
|
num = ctx->afu->pp_irqs;
|
|
res = afu_allocate_irqs(ctx, num);
|
|
if (res)
|
|
return res;
|
|
|
|
if (!cpu_has_feature(CPU_FTR_HVMODE)) {
|
|
/* In a guest, the PSL interrupt is not multiplexed. It was
|
|
* allocated above, and we need to set its handler
|
|
*/
|
|
hwirq = cxl_find_afu_irq(ctx, 0);
|
|
if (hwirq)
|
|
cxl_map_irq(ctx->afu->adapter, hwirq, cxl_ops->psl_interrupt, ctx, "psl");
|
|
}
|
|
|
|
if (ctx->status == STARTED) {
|
|
if (cxl_ops->update_ivtes)
|
|
cxl_ops->update_ivtes(ctx);
|
|
else WARN(1, "BUG: cxl_allocate_afu_irqs must be called prior to starting the context on this platform\n");
|
|
}
|
|
|
|
return res;
|
|
}
|
|
EXPORT_SYMBOL_GPL(cxl_allocate_afu_irqs);
|
|
|
|
void cxl_free_afu_irqs(struct cxl_context *ctx)
|
|
{
|
|
irq_hw_number_t hwirq;
|
|
unsigned int virq;
|
|
|
|
if (!cpu_has_feature(CPU_FTR_HVMODE)) {
|
|
hwirq = cxl_find_afu_irq(ctx, 0);
|
|
if (hwirq) {
|
|
virq = irq_find_mapping(NULL, hwirq);
|
|
if (virq)
|
|
cxl_unmap_irq(virq, ctx);
|
|
}
|
|
}
|
|
afu_irq_name_free(ctx);
|
|
cxl_ops->release_irq_ranges(&ctx->irqs, ctx->afu->adapter);
|
|
}
|
|
EXPORT_SYMBOL_GPL(cxl_free_afu_irqs);
|
|
|
|
int cxl_map_afu_irq(struct cxl_context *ctx, int num,
|
|
irq_handler_t handler, void *cookie, char *name)
|
|
{
|
|
irq_hw_number_t hwirq;
|
|
|
|
/*
|
|
* Find interrupt we are to register.
|
|
*/
|
|
hwirq = cxl_find_afu_irq(ctx, num);
|
|
if (!hwirq)
|
|
return -ENOENT;
|
|
|
|
return cxl_map_irq(ctx->afu->adapter, hwirq, handler, cookie, name);
|
|
}
|
|
EXPORT_SYMBOL_GPL(cxl_map_afu_irq);
|
|
|
|
void cxl_unmap_afu_irq(struct cxl_context *ctx, int num, void *cookie)
|
|
{
|
|
irq_hw_number_t hwirq;
|
|
unsigned int virq;
|
|
|
|
hwirq = cxl_find_afu_irq(ctx, num);
|
|
if (!hwirq)
|
|
return;
|
|
|
|
virq = irq_find_mapping(NULL, hwirq);
|
|
if (virq)
|
|
cxl_unmap_irq(virq, cookie);
|
|
}
|
|
EXPORT_SYMBOL_GPL(cxl_unmap_afu_irq);
|
|
|
|
/*
|
|
* Start a context
|
|
* Code here similar to afu_ioctl_start_work().
|
|
*/
|
|
int cxl_start_context(struct cxl_context *ctx, u64 wed,
|
|
struct task_struct *task)
|
|
{
|
|
int rc = 0;
|
|
bool kernel = true;
|
|
|
|
pr_devel("%s: pe: %i\n", __func__, ctx->pe);
|
|
|
|
mutex_lock(&ctx->status_mutex);
|
|
if (ctx->status == STARTED)
|
|
goto out; /* already started */
|
|
|
|
/*
|
|
* Increment the mapped context count for adapter. This also checks
|
|
* if adapter_context_lock is taken.
|
|
*/
|
|
rc = cxl_adapter_context_get(ctx->afu->adapter);
|
|
if (rc)
|
|
goto out;
|
|
|
|
if (task) {
|
|
ctx->pid = get_task_pid(task, PIDTYPE_PID);
|
|
kernel = false;
|
|
|
|
/* acquire a reference to the task's mm */
|
|
ctx->mm = get_task_mm(current);
|
|
|
|
/* ensure this mm_struct can't be freed */
|
|
cxl_context_mm_count_get(ctx);
|
|
|
|
if (ctx->mm) {
|
|
/* decrement the use count from above */
|
|
mmput(ctx->mm);
|
|
/* make TLBIs for this context global */
|
|
mm_context_add_copro(ctx->mm);
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Increment driver use count. Enables global TLBIs for hash
|
|
* and callbacks to handle the segment table
|
|
*/
|
|
cxl_ctx_get();
|
|
|
|
/* See the comment in afu_ioctl_start_work() */
|
|
smp_mb();
|
|
|
|
if ((rc = cxl_ops->attach_process(ctx, kernel, wed, 0))) {
|
|
put_pid(ctx->pid);
|
|
ctx->pid = NULL;
|
|
cxl_adapter_context_put(ctx->afu->adapter);
|
|
cxl_ctx_put();
|
|
if (task) {
|
|
cxl_context_mm_count_put(ctx);
|
|
if (ctx->mm)
|
|
mm_context_remove_copro(ctx->mm);
|
|
}
|
|
goto out;
|
|
}
|
|
|
|
ctx->status = STARTED;
|
|
out:
|
|
mutex_unlock(&ctx->status_mutex);
|
|
return rc;
|
|
}
|
|
EXPORT_SYMBOL_GPL(cxl_start_context);
|
|
|
|
int cxl_process_element(struct cxl_context *ctx)
|
|
{
|
|
return ctx->external_pe;
|
|
}
|
|
EXPORT_SYMBOL_GPL(cxl_process_element);
|
|
|
|
/* Stop a context. Returns 0 on success, otherwise -Errno */
|
|
int cxl_stop_context(struct cxl_context *ctx)
|
|
{
|
|
return __detach_context(ctx);
|
|
}
|
|
EXPORT_SYMBOL_GPL(cxl_stop_context);
|
|
|
|
void cxl_set_master(struct cxl_context *ctx)
|
|
{
|
|
ctx->master = true;
|
|
}
|
|
EXPORT_SYMBOL_GPL(cxl_set_master);
|
|
|
|
/* wrappers around afu_* file ops which are EXPORTED */
|
|
int cxl_fd_open(struct inode *inode, struct file *file)
|
|
{
|
|
return afu_open(inode, file);
|
|
}
|
|
EXPORT_SYMBOL_GPL(cxl_fd_open);
|
|
int cxl_fd_release(struct inode *inode, struct file *file)
|
|
{
|
|
return afu_release(inode, file);
|
|
}
|
|
EXPORT_SYMBOL_GPL(cxl_fd_release);
|
|
long cxl_fd_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
|
|
{
|
|
return afu_ioctl(file, cmd, arg);
|
|
}
|
|
EXPORT_SYMBOL_GPL(cxl_fd_ioctl);
|
|
int cxl_fd_mmap(struct file *file, struct vm_area_struct *vm)
|
|
{
|
|
return afu_mmap(file, vm);
|
|
}
|
|
EXPORT_SYMBOL_GPL(cxl_fd_mmap);
|
|
__poll_t cxl_fd_poll(struct file *file, struct poll_table_struct *poll)
|
|
{
|
|
return afu_poll(file, poll);
|
|
}
|
|
EXPORT_SYMBOL_GPL(cxl_fd_poll);
|
|
ssize_t cxl_fd_read(struct file *file, char __user *buf, size_t count,
|
|
loff_t *off)
|
|
{
|
|
return afu_read(file, buf, count, off);
|
|
}
|
|
EXPORT_SYMBOL_GPL(cxl_fd_read);
|
|
|
|
#define PATCH_FOPS(NAME) if (!fops->NAME) fops->NAME = afu_fops.NAME
|
|
|
|
/* Get a struct file and fd for a context and attach the ops */
|
|
struct file *cxl_get_fd(struct cxl_context *ctx, struct file_operations *fops,
|
|
int *fd)
|
|
{
|
|
struct file *file;
|
|
int rc, flags, fdtmp;
|
|
char *name = NULL;
|
|
|
|
/* only allow one per context */
|
|
if (ctx->mapping)
|
|
return ERR_PTR(-EEXIST);
|
|
|
|
flags = O_RDWR | O_CLOEXEC;
|
|
|
|
/* This code is similar to anon_inode_getfd() */
|
|
rc = get_unused_fd_flags(flags);
|
|
if (rc < 0)
|
|
return ERR_PTR(rc);
|
|
fdtmp = rc;
|
|
|
|
/*
|
|
* Patch the file ops. Needs to be careful that this is rentrant safe.
|
|
*/
|
|
if (fops) {
|
|
PATCH_FOPS(open);
|
|
PATCH_FOPS(poll);
|
|
PATCH_FOPS(read);
|
|
PATCH_FOPS(release);
|
|
PATCH_FOPS(unlocked_ioctl);
|
|
PATCH_FOPS(compat_ioctl);
|
|
PATCH_FOPS(mmap);
|
|
} else /* use default ops */
|
|
fops = (struct file_operations *)&afu_fops;
|
|
|
|
name = kasprintf(GFP_KERNEL, "cxl:%d", ctx->pe);
|
|
file = cxl_getfile(name, fops, ctx, flags);
|
|
kfree(name);
|
|
if (IS_ERR(file))
|
|
goto err_fd;
|
|
|
|
cxl_context_set_mapping(ctx, file->f_mapping);
|
|
*fd = fdtmp;
|
|
return file;
|
|
|
|
err_fd:
|
|
put_unused_fd(fdtmp);
|
|
return NULL;
|
|
}
|
|
EXPORT_SYMBOL_GPL(cxl_get_fd);
|
|
|
|
struct cxl_context *cxl_fops_get_context(struct file *file)
|
|
{
|
|
return file->private_data;
|
|
}
|
|
EXPORT_SYMBOL_GPL(cxl_fops_get_context);
|
|
|
|
void cxl_set_driver_ops(struct cxl_context *ctx,
|
|
struct cxl_afu_driver_ops *ops)
|
|
{
|
|
WARN_ON(!ops->fetch_event || !ops->event_delivered);
|
|
atomic_set(&ctx->afu_driver_events, 0);
|
|
ctx->afu_driver_ops = ops;
|
|
}
|
|
EXPORT_SYMBOL_GPL(cxl_set_driver_ops);
|
|
|
|
void cxl_context_events_pending(struct cxl_context *ctx,
|
|
unsigned int new_events)
|
|
{
|
|
atomic_add(new_events, &ctx->afu_driver_events);
|
|
wake_up_all(&ctx->wq);
|
|
}
|
|
EXPORT_SYMBOL_GPL(cxl_context_events_pending);
|
|
|
|
int cxl_start_work(struct cxl_context *ctx,
|
|
struct cxl_ioctl_start_work *work)
|
|
{
|
|
int rc;
|
|
|
|
/* code taken from afu_ioctl_start_work */
|
|
if (!(work->flags & CXL_START_WORK_NUM_IRQS))
|
|
work->num_interrupts = ctx->afu->pp_irqs;
|
|
else if ((work->num_interrupts < ctx->afu->pp_irqs) ||
|
|
(work->num_interrupts > ctx->afu->irqs_max)) {
|
|
return -EINVAL;
|
|
}
|
|
|
|
rc = afu_register_irqs(ctx, work->num_interrupts);
|
|
if (rc)
|
|
return rc;
|
|
|
|
rc = cxl_start_context(ctx, work->work_element_descriptor, current);
|
|
if (rc < 0) {
|
|
afu_release_irqs(ctx, ctx);
|
|
return rc;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL_GPL(cxl_start_work);
|
|
|
|
void __iomem *cxl_psa_map(struct cxl_context *ctx)
|
|
{
|
|
if (ctx->status != STARTED)
|
|
return NULL;
|
|
|
|
pr_devel("%s: psn_phys%llx size:%llx\n",
|
|
__func__, ctx->psn_phys, ctx->psn_size);
|
|
return ioremap(ctx->psn_phys, ctx->psn_size);
|
|
}
|
|
EXPORT_SYMBOL_GPL(cxl_psa_map);
|
|
|
|
void cxl_psa_unmap(void __iomem *addr)
|
|
{
|
|
iounmap(addr);
|
|
}
|
|
EXPORT_SYMBOL_GPL(cxl_psa_unmap);
|
|
|
|
int cxl_afu_reset(struct cxl_context *ctx)
|
|
{
|
|
struct cxl_afu *afu = ctx->afu;
|
|
int rc;
|
|
|
|
rc = cxl_ops->afu_reset(afu);
|
|
if (rc)
|
|
return rc;
|
|
|
|
return cxl_ops->afu_check_and_enable(afu);
|
|
}
|
|
EXPORT_SYMBOL_GPL(cxl_afu_reset);
|
|
|
|
void cxl_perst_reloads_same_image(struct cxl_afu *afu,
|
|
bool perst_reloads_same_image)
|
|
{
|
|
afu->adapter->perst_same_image = perst_reloads_same_image;
|
|
}
|
|
EXPORT_SYMBOL_GPL(cxl_perst_reloads_same_image);
|
|
|
|
ssize_t cxl_read_adapter_vpd(struct pci_dev *dev, void *buf, size_t count)
|
|
{
|
|
struct cxl_afu *afu = cxl_pci_to_afu(dev);
|
|
if (IS_ERR(afu))
|
|
return -ENODEV;
|
|
|
|
return cxl_ops->read_adapter_vpd(afu->adapter, buf, count);
|
|
}
|
|
EXPORT_SYMBOL_GPL(cxl_read_adapter_vpd);
|