Release 4.7 drivers/misc/cxl/api.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/anon_inodes.h>
#include <linux/file.h>
#include <misc/cxl.h>
#include <linux/fs.h>
#include "cxl.h"
struct cxl_context *cxl_dev_context_init(struct pci_dev *dev)
{
	struct address_space *mapping;
	struct cxl_afu *afu;
	struct cxl_context  *ctx;
	int rc;
	afu = cxl_pci_to_afu(dev);
	ctx = cxl_context_alloc();
	if (IS_ERR(ctx)) {
		rc = PTR_ERR(ctx);
		goto err_dev;
	}
	ctx->kernelapi = true;
	/*
         * Make our own address space since we won't have one from the
         * filesystem like the user api has, and even if we do associate a file
         * with this context we don't want to use the global anonymous inode's
         * address space as that can invalidate unrelated users:
         */
	mapping = kmalloc(sizeof(struct address_space), GFP_KERNEL);
	if (!mapping) {
		rc = -ENOMEM;
		goto err_ctx;
	}
	address_space_init_once(mapping);
	/* Make it a slave context.  We can promote it later? */
	rc = cxl_context_init(ctx, afu, false, mapping);
	if (rc)
		goto err_mapping;
	return ctx;
err_mapping:
	kfree(mapping);
err_ctx:
	kfree(ctx);
err_dev:
	return ERR_PTR(rc);
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| ian munsie | ian munsie | 75 | 51.02% | 2 | 66.67% | 
| michael neuling | michael neuling | 72 | 48.98% | 1 | 33.33% | 
 | Total | 147 | 100.00% | 3 | 100.00% | 
EXPORT_SYMBOL_GPL(cxl_dev_context_init);
struct cxl_context *cxl_get_context(struct pci_dev *dev)
{
	return dev->dev.archdata.cxl_ctx;
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| michael neuling | michael neuling | 21 | 100.00% | 1 | 100.00% | 
 | Total | 21 | 100.00% | 1 | 100.00% | 
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;
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| michael neuling | michael neuling | 28 | 93.33% | 1 | 50.00% | 
| andrew donnellan | andrew donnellan | 2 | 6.67% | 1 | 50.00% | 
 | Total | 30 | 100.00% | 2 | 100.00% | 
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;
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| frederic barrat | frederic barrat | 73 | 100.00% | 1 | 100.00% | 
 | Total | 73 | 100.00% | 1 | 100.00% | 
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 && !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");
	}
	return res;
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| frederic barrat | frederic barrat | 57 | 62.64% | 1 | 50.00% | 
| michael neuling | michael neuling | 34 | 37.36% | 1 | 50.00% | 
 | Total | 91 | 100.00% | 2 | 100.00% | 
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);
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| frederic barrat | frederic barrat | 55 | 66.27% | 2 | 50.00% | 
| michael neuling | michael neuling | 23 | 27.71% | 1 | 25.00% | 
| andrew donnellan | andrew donnellan | 5 | 6.02% | 1 | 25.00% | 
 | Total | 83 | 100.00% | 4 | 100.00% | 
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);
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| michael neuling | michael neuling | 64 | 100.00% | 1 | 100.00% | 
 | Total | 64 | 100.00% | 1 | 100.00% | 
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);
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| michael neuling | michael neuling | 59 | 100.00% | 1 | 100.00% | 
 | Total | 59 | 100.00% | 1 | 100.00% | 
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 */
	if (task) {
		ctx->pid = get_task_pid(task, PIDTYPE_PID);
		ctx->glpid = get_task_pid(task->group_leader, PIDTYPE_PID);
		kernel = false;
		ctx->real_mode = false;
	}
	cxl_ctx_get();
	if ((rc = cxl_ops->attach_process(ctx, kernel, wed, 0))) {
		put_pid(ctx->pid);
		cxl_ctx_put();
		goto out;
	}
	ctx->status = STARTED;
out:
	mutex_unlock(&ctx->status_mutex);
	return rc;
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| michael neuling | michael neuling | 137 | 88.39% | 1 | 25.00% | 
| vaibhav jain | vaibhav jain | 9 | 5.81% | 1 | 25.00% | 
| ian munsie | ian munsie | 6 | 3.87% | 1 | 25.00% | 
| frederic barrat | frederic barrat | 3 | 1.94% | 1 | 25.00% | 
 | Total | 155 | 100.00% | 4 | 100.00% | 
EXPORT_SYMBOL_GPL(cxl_start_context);
int cxl_process_element(struct cxl_context *ctx)
{
	return ctx->external_pe;
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| michael neuling | michael neuling | 14 | 93.33% | 1 | 50.00% | 
| christophe lombard | christophe lombard | 1 | 6.67% | 1 | 50.00% | 
 | Total | 15 | 100.00% | 2 | 100.00% | 
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);
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| michael neuling | michael neuling | 16 | 100.00% | 2 | 100.00% | 
 | Total | 16 | 100.00% | 2 | 100.00% | 
EXPORT_SYMBOL_GPL(cxl_stop_context);
void cxl_set_master(struct cxl_context *ctx)
{
	ctx->master = true;
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| michael neuling | michael neuling | 16 | 100.00% | 1 | 100.00% | 
 | Total | 16 | 100.00% | 1 | 100.00% | 
EXPORT_SYMBOL_GPL(cxl_set_master);
int cxl_set_translation_mode(struct cxl_context *ctx, bool real_mode)
{
	if (ctx->status == STARTED) {
		/*
                 * We could potentially update the PE and issue an update LLCMD
                 * to support this, but it doesn't seem to have a good use case
                 * since it's trivial to just create a second kernel context
                 * with different translation modes, so until someone convinces
                 * me otherwise:
                 */
		return -EBUSY;
	}
	ctx->real_mode = real_mode;
	return 0;
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| ian munsie | ian munsie | 37 | 100.00% | 1 | 100.00% | 
 | Total | 37 | 100.00% | 1 | 100.00% | 
EXPORT_SYMBOL_GPL(cxl_set_translation_mode);
/* wrappers around afu_* file ops which are EXPORTED */
int cxl_fd_open(struct inode *inode, struct file *file)
{
	return afu_open(inode, file);
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| michael neuling | michael neuling | 23 | 100.00% | 1 | 100.00% | 
 | Total | 23 | 100.00% | 1 | 100.00% | 
EXPORT_SYMBOL_GPL(cxl_fd_open);
int cxl_fd_release(struct inode *inode, struct file *file)
{
	return afu_release(inode, file);
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| michael neuling | michael neuling | 23 | 100.00% | 1 | 100.00% | 
 | Total | 23 | 100.00% | 1 | 100.00% | 
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);
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| michael neuling | michael neuling | 28 | 100.00% | 1 | 100.00% | 
 | Total | 28 | 100.00% | 1 | 100.00% | 
EXPORT_SYMBOL_GPL(cxl_fd_ioctl);
int cxl_fd_mmap(struct file *file, struct vm_area_struct *vm)
{
	return afu_mmap(file, vm);
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| michael neuling | michael neuling | 23 | 100.00% | 1 | 100.00% | 
 | Total | 23 | 100.00% | 1 | 100.00% | 
EXPORT_SYMBOL_GPL(cxl_fd_mmap);
unsigned int cxl_fd_poll(struct file *file, struct poll_table_struct *poll)
{
	return afu_poll(file, poll);
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| michael neuling | michael neuling | 24 | 100.00% | 1 | 100.00% | 
 | Total | 24 | 100.00% | 1 | 100.00% | 
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);
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| michael neuling | michael neuling | 34 | 100.00% | 1 | 100.00% | 
 | Total | 34 | 100.00% | 1 | 100.00% | 
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;
	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;
	file = anon_inode_getfile("cxl", fops, ctx, flags);
	if (IS_ERR(file))
		goto err_fd;
	file->f_mapping = ctx->mapping;
	*fd = fdtmp;
	return file;
err_fd:
	put_unused_fd(fdtmp);
	return NULL;
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| michael neuling | michael neuling | 146 | 87.95% | 1 | 50.00% | 
| ian munsie | ian munsie | 20 | 12.05% | 1 | 50.00% | 
 | Total | 166 | 100.00% | 2 | 100.00% | 
EXPORT_SYMBOL_GPL(cxl_get_fd);
struct cxl_context *cxl_fops_get_context(struct file *file)
{
	return file->private_data;
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| michael neuling | michael neuling | 17 | 100.00% | 1 | 100.00% | 
 | Total | 17 | 100.00% | 1 | 100.00% | 
EXPORT_SYMBOL_GPL(cxl_fops_get_context);
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;
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| michael neuling | michael neuling | 125 | 100.00% | 1 | 100.00% | 
 | Total | 125 | 100.00% | 1 | 100.00% | 
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);
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| michael neuling | michael neuling | 42 | 84.00% | 1 | 50.00% | 
| frederic barrat | frederic barrat | 8 | 16.00% | 1 | 50.00% | 
 | Total | 50 | 100.00% | 2 | 100.00% | 
EXPORT_SYMBOL_GPL(cxl_psa_map);
void cxl_psa_unmap(void __iomem *addr)
{
	iounmap(addr);
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| michael neuling | michael neuling | 15 | 100.00% | 1 | 100.00% | 
 | Total | 15 | 100.00% | 1 | 100.00% | 
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);
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| michael neuling | michael neuling | 40 | 86.96% | 1 | 50.00% | 
| frederic barrat | frederic barrat | 6 | 13.04% | 1 | 50.00% | 
 | Total | 46 | 100.00% | 2 | 100.00% | 
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;
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| daniel axtens | daniel axtens | 21 | 100.00% | 1 | 100.00% | 
 | Total | 21 | 100.00% | 1 | 100.00% | 
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);
	return cxl_ops->read_adapter_vpd(afu->adapter, buf, count);
}
Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| frederic barrat | frederic barrat | 41 | 100.00% | 1 | 100.00% | 
 | Total | 41 | 100.00% | 1 | 100.00% | 
EXPORT_SYMBOL_GPL(cxl_read_adapter_vpd);
Overall Contributors
 | Person | Tokens | Prop | Commits | CommitProp | 
| michael neuling | michael neuling | 1169 | 72.79% | 2 | 15.38% | 
| frederic barrat | frederic barrat | 248 | 15.44% | 3 | 23.08% | 
| ian munsie | ian munsie | 146 | 9.09% | 3 | 23.08% | 
| daniel axtens | daniel axtens | 26 | 1.62% | 1 | 7.69% | 
| vaibhav jain | vaibhav jain | 9 | 0.56% | 1 | 7.69% | 
| andrew donnellan | andrew donnellan | 7 | 0.44% | 2 | 15.38% | 
| christophe lombard | christophe lombard | 1 | 0.06% | 1 | 7.69% | 
 | Total | 1606 | 100.00% | 13 | 100.00% | 
  
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.