VisionFive2 Linux kernel

StarFive Tech Linux Kernel for VisionFive (JH7110) boards (mirror)

More than 9999 Commits   32 Branches   54 Tags
2874c5fd28426 (Thomas Gleixner    2019-05-27 08:55:01 +0200   1) /* SPDX-License-Identifier: GPL-2.0-or-later */
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000   2) /*
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000   3)  * Copyright 2015 IBM Corp.
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000   4)  */
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000   5) 
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000   6) #ifndef _MISC_CXL_H
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000   7) #define _MISC_CXL_H
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000   8) 
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000   9) #include <linux/pci.h>
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  10) #include <linux/poll.h>
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  11) #include <linux/interrupt.h>
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  12) #include <uapi/misc/cxl.h>
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  13) 
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  14) /*
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  15)  * This documents the in kernel API for driver to use CXL. It allows kernel
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  16)  * drivers to bind to AFUs using an AFU configuration record exposed as a PCI
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  17)  * configuration record.
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  18)  *
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  19)  * This API enables control over AFU and contexts which can't be part of the
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  20)  * generic PCI API. This API is agnostic to the actual AFU.
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  21)  */
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  22) 
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  23) /* Get the AFU associated with a pci_dev */
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  24) struct cxl_afu *cxl_pci_to_afu(struct pci_dev *dev);
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  25) 
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  26) /* Get the AFU conf record number associated with a pci_dev */
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  27) unsigned int cxl_pci_to_cfg_record(struct pci_dev *dev);
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  28) 
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  29) 
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  30) /*
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  31)  * Context lifetime overview:
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  32)  *
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  33)  * An AFU context may be inited and then started and stoppped multiple times
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  34)  * before it's released. ie.
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  35)  *    - cxl_dev_context_init()
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  36)  *      - cxl_start_context()
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  37)  *      - cxl_stop_context()
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  38)  *      - cxl_start_context()
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  39)  *      - cxl_stop_context()
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  40)  *     ...repeat...
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  41)  *    - cxl_release_context()
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  42)  * Once released, a context can't be started again.
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  43)  *
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  44)  * One context is inited by the cxl driver for every pci_dev. This is to be
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  45)  * used as a default kernel context. cxl_get_context() will get this
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  46)  * context. This context will be released by PCI hot unplug, so doesn't need to
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  47)  * be released explicitly by drivers.
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  48)  *
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  49)  * Additional kernel contexts may be inited using cxl_dev_context_init().
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  50)  * These must be released using cxl_context_detach().
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  51)  *
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  52)  * Once a context has been inited, IRQs may be configured. Firstly these IRQs
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  53)  * must be allocated (cxl_allocate_afu_irqs()), then individually mapped to
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  54)  * specific handlers (cxl_map_afu_irq()).
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  55)  *
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  56)  * These IRQs can be unmapped (cxl_unmap_afu_irq()) and finally released
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  57)  * (cxl_free_afu_irqs()).
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  58)  *
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  59)  * The AFU can be reset (cxl_afu_reset()). This will cause the PSL/AFU
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  60)  * hardware to lose track of all contexts. It's upto the caller of
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  61)  * cxl_afu_reset() to restart these contexts.
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  62)  */
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  63) 
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  64) /*
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  65)  * On pci_enabled_device(), the cxl driver will init a single cxl context for
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  66)  * use by the driver. It doesn't start this context (as that will likely
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  67)  * generate DMA traffic for most AFUs).
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  68)  *
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  69)  * This gets the default context associated with this pci_dev.  This context
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  70)  * doesn't need to be released as this will be done by the PCI subsystem on hot
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  71)  * unplug.
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  72)  */
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  73) struct cxl_context *cxl_get_context(struct pci_dev *dev);
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  74) /*
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  75)  * Allocate and initalise a context associated with a AFU PCI device. This
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  76)  * doesn't start the context in the AFU.
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  77)  */
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  78) struct cxl_context *cxl_dev_context_init(struct pci_dev *dev);
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  79) /*
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  80)  * Release and free a context. Context should be stopped before calling.
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  81)  */
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  82) int cxl_release_context(struct cxl_context *ctx);
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  83) 
ad42de859ff14 (Michael Neuling    2016-06-24 08:47:07 +0200  84) /*
ad42de859ff14 (Michael Neuling    2016-06-24 08:47:07 +0200  85)  * Set and get private data associated with a context. Allows drivers to have a
ad42de859ff14 (Michael Neuling    2016-06-24 08:47:07 +0200  86)  * back pointer to some useful structure.
ad42de859ff14 (Michael Neuling    2016-06-24 08:47:07 +0200  87)  */
ad42de859ff14 (Michael Neuling    2016-06-24 08:47:07 +0200  88) int cxl_set_priv(struct cxl_context *ctx, void *priv);
ad42de859ff14 (Michael Neuling    2016-06-24 08:47:07 +0200  89) void *cxl_get_priv(struct cxl_context *ctx);
ad42de859ff14 (Michael Neuling    2016-06-24 08:47:07 +0200  90) 
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  91) /*
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  92)  * Allocate AFU interrupts for this context. num=0 will allocate the default
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  93)  * for this AFU as given in the AFU descriptor. This number doesn't include the
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  94)  * interrupt 0 (CAIA defines AFU IRQ 0 for page faults). Each interrupt to be
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  95)  * used must map a handler with cxl_map_afu_irq.
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  96)  */
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  97) int cxl_allocate_afu_irqs(struct cxl_context *cxl, int num);
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  98) /* Free allocated interrupts */
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000  99) void cxl_free_afu_irqs(struct cxl_context *cxl);
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 100) 
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 101) /*
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 102)  * Map a handler for an AFU interrupt associated with a particular context. AFU
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 103)  * IRQS numbers start from 1 (CAIA defines AFU IRQ 0 for page faults). cookie
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 104)  * is private data is that will be provided to the interrupt handler.
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 105)  */
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 106) int cxl_map_afu_irq(struct cxl_context *cxl, int num,
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 107) 		    irq_handler_t handler, void *cookie, char *name);
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 108) /* unmap mapped IRQ handlers */
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 109) void cxl_unmap_afu_irq(struct cxl_context *cxl, int num, void *cookie);
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 110) 
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 111) /*
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 112)  * Start work on the AFU. This starts an cxl context and associates it with a
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 113)  * task. task == NULL will make it a kernel context.
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 114)  */
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 115) int cxl_start_context(struct cxl_context *ctx, u64 wed,
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 116) 		      struct task_struct *task);
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 117) /*
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 118)  * Stop a context and remove it from the PSL
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 119)  */
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 120) int cxl_stop_context(struct cxl_context *ctx);
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 121) 
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 122) /* Reset the AFU */
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 123) int cxl_afu_reset(struct cxl_context *ctx);
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 124) 
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 125) /*
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 126)  * Set a context as a master context.
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 127)  * This sets the default problem space area mapped as the full space, rather
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 128)  * than just the per context area (for slaves).
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 129)  */
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 130) void cxl_set_master(struct cxl_context *ctx);
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 131) 
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 132) /*
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 133)  * Map and unmap the AFU Problem Space area. The amount and location mapped
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 134)  * depends on if this context is a master or slave.
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 135)  */
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 136) void __iomem *cxl_psa_map(struct cxl_context *ctx);
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 137) void cxl_psa_unmap(void __iomem *addr);
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 138) 
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 139) /*  Get the process element for this context */
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 140) int cxl_process_element(struct cxl_context *ctx);
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 141) 
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 142) /*
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 143)  * These calls allow drivers to create their own file descriptors and make them
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 144)  * identical to the cxl file descriptor user API. An example use case:
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 145)  *
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 146)  * struct file_operations cxl_my_fops = {};
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 147)  * ......
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 148)  *	// Init the context
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 149)  *	ctx = cxl_dev_context_init(dev);
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 150)  *	if (IS_ERR(ctx))
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 151)  *		return PTR_ERR(ctx);
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 152)  *	// Create and attach a new file descriptor to my file ops
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 153)  *	file = cxl_get_fd(ctx, &cxl_my_fops, &fd);
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 154)  *	// Start context
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 155)  *	rc = cxl_start_work(ctx, &work.work);
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 156)  *	if (rc) {
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 157)  *		fput(file);
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 158)  *		put_unused_fd(fd);
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 159)  *		return -ENODEV;
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 160)  *	}
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 161)  *	// No error paths after installing the fd
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 162)  *	fd_install(fd, file);
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 163)  *	return fd;
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 164)  *
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 165)  * This inits a context, and gets a file descriptor and associates some file
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 166)  * ops to that file descriptor. If the file ops are blank, the cxl driver will
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 167)  * fill them in with the default ones that mimic the standard user API.  Once
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 168)  * completed, the file descriptor can be installed. Once the file descriptor is
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 169)  * installed, it's visible to the user so no errors must occur past this point.
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 170)  *
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 171)  * If cxl_fd_release() file op call is installed, the context will be stopped
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 172)  * and released when the fd is released. Hence the driver won't need to manage
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 173)  * this itself.
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 174)  */
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 175) 
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 176) /*
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 177)  * Take a context and associate it with my file ops. Returns the associated
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 178)  * file and file descriptor. Any file ops which are blank are filled in by the
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 179)  * cxl driver with the default ops to mimic the standard API.
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 180)  */
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 181) struct file *cxl_get_fd(struct cxl_context *ctx, struct file_operations *fops,
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 182) 			int *fd);
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 183) /* Get the context associated with this file */
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 184) struct cxl_context *cxl_fops_get_context(struct file *file);
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 185) /*
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 186)  * Start a context associated a struct cxl_ioctl_start_work used by the
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 187)  * standard cxl user API.
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 188)  */
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 189) int cxl_start_work(struct cxl_context *ctx,
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 190) 		   struct cxl_ioctl_start_work *work);
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 191) /*
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 192)  * Export all the existing fops so drivers can use them
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 193)  */
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 194) int cxl_fd_open(struct inode *inode, struct file *file);
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 195) int cxl_fd_release(struct inode *inode, struct file *file);
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 196) long cxl_fd_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 197) int cxl_fd_mmap(struct file *file, struct vm_area_struct *vm);
afc9a42b7464f (Al Viro            2017-07-03 06:39:46 -0400 198) __poll_t cxl_fd_poll(struct file *file, struct poll_table_struct *poll);
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 199) ssize_t cxl_fd_read(struct file *file, char __user *buf, size_t count,
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 200) 			   loff_t *off);
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 201) 
13e68d8bd05c9 (Daniel Axtens      2015-08-14 17:41:25 +1000 202) /*
13e68d8bd05c9 (Daniel Axtens      2015-08-14 17:41:25 +1000 203)  * For EEH, a driver may want to assert a PERST will reload the same image
13e68d8bd05c9 (Daniel Axtens      2015-08-14 17:41:25 +1000 204)  * from flash into the FPGA.
13e68d8bd05c9 (Daniel Axtens      2015-08-14 17:41:25 +1000 205)  *
13e68d8bd05c9 (Daniel Axtens      2015-08-14 17:41:25 +1000 206)  * This is a property of the entire adapter, not a single AFU, so drivers
13e68d8bd05c9 (Daniel Axtens      2015-08-14 17:41:25 +1000 207)  * should set this property with care!
13e68d8bd05c9 (Daniel Axtens      2015-08-14 17:41:25 +1000 208)  */
13e68d8bd05c9 (Daniel Axtens      2015-08-14 17:41:25 +1000 209) void cxl_perst_reloads_same_image(struct cxl_afu *afu,
13e68d8bd05c9 (Daniel Axtens      2015-08-14 17:41:25 +1000 210) 				  bool perst_reloads_same_image);
13e68d8bd05c9 (Daniel Axtens      2015-08-14 17:41:25 +1000 211) 
d601ea918b878 (Frederic Barrat    2016-03-04 12:26:40 +0100 212) /*
d601ea918b878 (Frederic Barrat    2016-03-04 12:26:40 +0100 213)  * Read the VPD for the card where the AFU resides
d601ea918b878 (Frederic Barrat    2016-03-04 12:26:40 +0100 214)  */
d601ea918b878 (Frederic Barrat    2016-03-04 12:26:40 +0100 215) ssize_t cxl_read_adapter_vpd(struct pci_dev *dev, void *buf, size_t count);
d601ea918b878 (Frederic Barrat    2016-03-04 12:26:40 +0100 216) 
b810253bd9342 (Philippe Bergheaud 2016-06-23 15:03:53 +0200 217) /*
b810253bd9342 (Philippe Bergheaud 2016-06-23 15:03:53 +0200 218)  * AFU driver ops allow an AFU driver to create their own events to pass to
b810253bd9342 (Philippe Bergheaud 2016-06-23 15:03:53 +0200 219)  * userspace through the file descriptor as a simpler alternative to overriding
b810253bd9342 (Philippe Bergheaud 2016-06-23 15:03:53 +0200 220)  * the read() and poll() calls that works with the generic cxl events. These
b810253bd9342 (Philippe Bergheaud 2016-06-23 15:03:53 +0200 221)  * events are given priority over the generic cxl events, so they will be
b810253bd9342 (Philippe Bergheaud 2016-06-23 15:03:53 +0200 222)  * delivered first if multiple types of events are pending.
b810253bd9342 (Philippe Bergheaud 2016-06-23 15:03:53 +0200 223)  *
b810253bd9342 (Philippe Bergheaud 2016-06-23 15:03:53 +0200 224)  * The AFU driver must call cxl_context_events_pending() to notify the cxl
b810253bd9342 (Philippe Bergheaud 2016-06-23 15:03:53 +0200 225)  * driver that new events are ready to be delivered for a specific context.
b810253bd9342 (Philippe Bergheaud 2016-06-23 15:03:53 +0200 226)  * cxl_context_events_pending() will adjust the current count of AFU driver
b810253bd9342 (Philippe Bergheaud 2016-06-23 15:03:53 +0200 227)  * events for this context, and wake up anyone waiting on the context wait
b810253bd9342 (Philippe Bergheaud 2016-06-23 15:03:53 +0200 228)  * queue.
b810253bd9342 (Philippe Bergheaud 2016-06-23 15:03:53 +0200 229)  *
b810253bd9342 (Philippe Bergheaud 2016-06-23 15:03:53 +0200 230)  * The cxl driver will then call fetch_event() to get a structure defining
b810253bd9342 (Philippe Bergheaud 2016-06-23 15:03:53 +0200 231)  * the size and address of the driver specific event data. The cxl driver
b810253bd9342 (Philippe Bergheaud 2016-06-23 15:03:53 +0200 232)  * will build a cxl header with type and process_element fields filled in,
b810253bd9342 (Philippe Bergheaud 2016-06-23 15:03:53 +0200 233)  * and header.size set to sizeof(struct cxl_event_header) + data_size.
b810253bd9342 (Philippe Bergheaud 2016-06-23 15:03:53 +0200 234)  * The total size of the event is limited to CXL_READ_MIN_SIZE (4K).
b810253bd9342 (Philippe Bergheaud 2016-06-23 15:03:53 +0200 235)  *
b810253bd9342 (Philippe Bergheaud 2016-06-23 15:03:53 +0200 236)  * fetch_event() is called with a spin lock held, so it must not sleep.
b810253bd9342 (Philippe Bergheaud 2016-06-23 15:03:53 +0200 237)  *
b810253bd9342 (Philippe Bergheaud 2016-06-23 15:03:53 +0200 238)  * The cxl driver will then deliver the event to userspace, and finally
b810253bd9342 (Philippe Bergheaud 2016-06-23 15:03:53 +0200 239)  * call event_delivered() to return the status of the operation, identified
b810253bd9342 (Philippe Bergheaud 2016-06-23 15:03:53 +0200 240)  * by cxl context and AFU driver event data pointers.
b810253bd9342 (Philippe Bergheaud 2016-06-23 15:03:53 +0200 241)  *   0        Success
b810253bd9342 (Philippe Bergheaud 2016-06-23 15:03:53 +0200 242)  *   -EFAULT  copy_to_user() has failed
b810253bd9342 (Philippe Bergheaud 2016-06-23 15:03:53 +0200 243)  *   -EINVAL  Event data pointer is NULL, or event size is greater than
b810253bd9342 (Philippe Bergheaud 2016-06-23 15:03:53 +0200 244)  *            CXL_READ_MIN_SIZE.
b810253bd9342 (Philippe Bergheaud 2016-06-23 15:03:53 +0200 245)  */
b810253bd9342 (Philippe Bergheaud 2016-06-23 15:03:53 +0200 246) struct cxl_afu_driver_ops {
b810253bd9342 (Philippe Bergheaud 2016-06-23 15:03:53 +0200 247) 	struct cxl_event_afu_driver_reserved *(*fetch_event) (
b810253bd9342 (Philippe Bergheaud 2016-06-23 15:03:53 +0200 248) 						struct cxl_context *ctx);
b810253bd9342 (Philippe Bergheaud 2016-06-23 15:03:53 +0200 249) 	void (*event_delivered) (struct cxl_context *ctx,
b810253bd9342 (Philippe Bergheaud 2016-06-23 15:03:53 +0200 250) 				 struct cxl_event_afu_driver_reserved *event,
b810253bd9342 (Philippe Bergheaud 2016-06-23 15:03:53 +0200 251) 				 int rc);
b810253bd9342 (Philippe Bergheaud 2016-06-23 15:03:53 +0200 252) };
b810253bd9342 (Philippe Bergheaud 2016-06-23 15:03:53 +0200 253) 
b810253bd9342 (Philippe Bergheaud 2016-06-23 15:03:53 +0200 254) /*
b810253bd9342 (Philippe Bergheaud 2016-06-23 15:03:53 +0200 255)  * Associate the above driver ops with a specific context.
b810253bd9342 (Philippe Bergheaud 2016-06-23 15:03:53 +0200 256)  * Reset the current count of AFU driver events.
b810253bd9342 (Philippe Bergheaud 2016-06-23 15:03:53 +0200 257)  */
b810253bd9342 (Philippe Bergheaud 2016-06-23 15:03:53 +0200 258) void cxl_set_driver_ops(struct cxl_context *ctx,
b810253bd9342 (Philippe Bergheaud 2016-06-23 15:03:53 +0200 259) 			struct cxl_afu_driver_ops *ops);
b810253bd9342 (Philippe Bergheaud 2016-06-23 15:03:53 +0200 260) 
b810253bd9342 (Philippe Bergheaud 2016-06-23 15:03:53 +0200 261) /* Notify cxl driver that new events are ready to be delivered for context */
b810253bd9342 (Philippe Bergheaud 2016-06-23 15:03:53 +0200 262) void cxl_context_events_pending(struct cxl_context *ctx,
b810253bd9342 (Philippe Bergheaud 2016-06-23 15:03:53 +0200 263) 				unsigned int new_events);
b810253bd9342 (Philippe Bergheaud 2016-06-23 15:03:53 +0200 264) 
6f7f0b3df6d49 (Michael Neuling    2015-05-27 16:07:18 +1000 265) #endif /* _MISC_CXL_H */