Blame opae-libs/plugins/xfpga/intel-fpga.h

Packit 534379
// Copyright(c) 2017-2020, Intel Corporation
Packit 534379
//
Packit 534379
// Redistribution  and  use  in source  and  binary  forms,  with  or  without
Packit 534379
// modification, are permitted provided that the following conditions are met:
Packit 534379
//
Packit 534379
// * Redistributions of  source code  must retain the  above copyright notice,
Packit 534379
//   this list of conditions and the following disclaimer.
Packit 534379
// * Redistributions in binary form must reproduce the above copyright notice,
Packit 534379
//   this list of conditions and the following disclaimer in the documentation
Packit 534379
//   and/or other materials provided with the distribution.
Packit 534379
// * Neither the name  of Intel Corporation  nor the names of its contributors
Packit 534379
//   may be used to  endorse or promote  products derived  from this  software
Packit 534379
//   without specific prior written permission.
Packit 534379
//
Packit 534379
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Packit 534379
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,  BUT NOT LIMITED TO,  THE
Packit 534379
// IMPLIED WARRANTIES OF  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Packit 534379
// ARE DISCLAIMED.  IN NO EVENT  SHALL THE COPYRIGHT OWNER  OR CONTRIBUTORS BE
Packit 534379
// LIABLE  FOR  ANY  DIRECT,  INDIRECT,  INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR
Packit 534379
// CONSEQUENTIAL  DAMAGES  (INCLUDING,  BUT  NOT LIMITED  TO,  PROCUREMENT  OF
Packit 534379
// SUBSTITUTE GOODS OR SERVICES;  LOSS OF USE,  DATA, OR PROFITS;  OR BUSINESS
Packit 534379
// INTERRUPTION)  HOWEVER CAUSED  AND ON ANY THEORY  OF LIABILITY,  WHETHER IN
Packit 534379
// CONTRACT,  STRICT LIABILITY,  OR TORT  (INCLUDING NEGLIGENCE  OR OTHERWISE)
Packit 534379
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,  EVEN IF ADVISED OF THE
Packit 534379
// POSSIBILITY OF SUCH DAMAGE.
Packit 534379
Packit 534379
Packit 534379
#ifndef _UAPI_INTEL_FPGA_H
Packit 534379
#define _UAPI_INTEL_FPGA_H
Packit 534379
Packit 534379
#include <linux/types.h>
Packit 534379
Packit 534379
#define FPGA_API_VERSION 0
Packit 534379
Packit 534379
/*
Packit 534379
 * The IOCTL interface for Intel FPGA is designed for extensibility by
Packit 534379
 * embedding the structure length (argsz) and flags into structures passed
Packit 534379
 * between kernel and userspace. This design referenced the VFIO IOCTL
Packit 534379
 * interface (include/uapi/linux/vfio.h).
Packit 534379
 */
Packit 534379
Packit 534379
#define FPGA_MAGIC 0xB5
Packit 534379
Packit 534379
#define FPGA_BASE 0
Packit 534379
#define PORT_BASE 0x40
Packit 534379
#define FME_BASE 0x80
Packit 534379
Packit 534379
/* Common IOCTLs for both FME and AFU file descriptor */
Packit 534379
Packit 534379
/**
Packit 534379
 * FPGA_GET_API_VERSION - _IO(FPGA_MAGIC, FPGA_BASE + 0)
Packit 534379
 *
Packit 534379
 * Report the version of the driver API.
Packit 534379
 * Return: Driver API Version.
Packit 534379
 */
Packit 534379
Packit 534379
#define FPGA_GET_API_VERSION	_IO(FPGA_MAGIC, FPGA_BASE + 0)
Packit 534379
Packit 534379
/**
Packit 534379
 * FPGA_CHECK_EXTENSION - _IO(FPGA_MAGIC, FPGA_BASE + 1)
Packit 534379
 *
Packit 534379
 * Check whether an extension is supported.
Packit 534379
 * Return: 0 if not supported, otherwise the extension is supported.
Packit 534379
 */
Packit 534379
Packit 534379
#define FPGA_CHECK_EXTENSION	_IO(FPGA_MAGIC, FPGA_BASE + 1)
Packit 534379
Packit 534379
/* IOCTLs for AFU file descriptor */
Packit 534379
Packit 534379
/**
Packit 534379
 * FPGA_PORT_RESET - _IO(FPGA_MAGIC, PORT_BASE + 0)
Packit 534379
 *
Packit 534379
 * Reset the FPGA AFU Port. No parameters are supported.
Packit 534379
 * Return: 0 on success, -errno of failure
Packit 534379
 */
Packit 534379
Packit 534379
#define FPGA_PORT_RESET		_IO(FPGA_MAGIC, PORT_BASE + 0)
Packit 534379
Packit 534379
/**
Packit 534379
 * FPGA_PORT_GET_INFO - _IOR(FPGA_MAGIC, PORT_BASE + 1, struct fpga_port_info)
Packit 534379
 *
Packit 534379
 * Retrieve information about the fpga port.
Packit 534379
 * Driver fills the info in provided struct fpga_port_info.
Packit 534379
 * Return: 0 on success, -errno on failure.
Packit 534379
 */
Packit 534379
struct fpga_port_info {
Packit 534379
	/* Input */
Packit 534379
	__u32 argsz;		/* Structure length */
Packit 534379
	/* Output */
Packit 534379
	__u32 flags;		/* Zero for now */
Packit 534379
	__u32 capability;	/* The capability of port device */
Packit 534379
#define FPGA_PORT_CAP_ERR_IRQ	(1 << 0) /* Support port error interrupt */
Packit 534379
#define FPGA_PORT_CAP_UAFU_IRQ	(1 << 1) /* Support uafu error interrupt */
Packit 534379
	__u32 num_regions;	/* The number of supported regions */
Packit 534379
	__u32 num_umsgs;	/* The number of allocated umsgs */
Packit 534379
	__u32 num_uafu_irqs;    /* The number of uafu interrupts */
Packit 534379
};
Packit 534379
Packit 534379
#define FPGA_PORT_GET_INFO	_IO(FPGA_MAGIC, PORT_BASE + 1)
Packit 534379
Packit 534379
/**
Packit 534379
 * FPGA_PORT_GET_REGION_INFO - _IOWR(FPGA_MAGIC, PORT_BASE + 2,
Packit 534379
 *						struct fpga_port_region_info)
Packit 534379
 *
Packit 534379
 * Retrieve information about a device region.
Packit 534379
 * Caller provides struct fpga_port_region_info with index value set.
Packit 534379
 * Driver returns the region info in other fields.
Packit 534379
 * Return: 0 on success, -errno on failure.
Packit 534379
 */
Packit 534379
struct fpga_port_region_info {
Packit 534379
	/* input */
Packit 534379
	__u32 argsz;		/* Structure length */
Packit 534379
	/* Output */
Packit 534379
	__u32 flags;		/* Access permission */
Packit 534379
#define FPGA_REGION_READ	(1 << 0)	/* Region is readable */
Packit 534379
#define FPGA_REGION_WRITE	(1 << 1)	/* Region is writable */
Packit 534379
#define FPGA_REGION_MMAP	(1 << 2)	/* Can be mmaped to userspace */
Packit 534379
	/* Input */
Packit 534379
	__u32 index;		/* Region index */
Packit 534379
#define FPGA_PORT_INDEX_UAFU	0		/* User AFU */
Packit 534379
#define FPGA_PORT_INDEX_STP	1		/* Signal Tap */
Packit 534379
	__u32 padding;
Packit 534379
	/* Output */
Packit 534379
	__u64 size;		/* Region size (bytes) */
Packit 534379
	__u64 offset;		/* Region offset from start of device fd */
Packit 534379
};
Packit 534379
Packit 534379
#define FPGA_PORT_GET_REGION_INFO	_IO(FPGA_MAGIC, PORT_BASE + 2)
Packit 534379
Packit 534379
/**
Packit 534379
 * FPGA_PORT_DMA_MAP - _IOWR(FPGA_MAGIC, PORT_BASE + 3,
Packit 534379
 *						struct fpga_port_dma_map)
Packit 534379
 *
Packit 534379
 * Map the dma memory per user_addr and length which are provided by caller.
Packit 534379
 * Driver fills the iova in provided struct afu_port_dma_map.
Packit 534379
 * This interface only accepts page-size aligned user memory for dma mapping.
Packit 534379
 *
Packit 534379
 * Setting only one of FPGA_DMA_TO_DEV or FPGA_DMA_FROM_DEV limits
Packit 534379
 * FPGA-initiated DMA requests to only reads or only writes. In order
Packit 534379
 * to support legacy drivers that lacked these flags, setting neither
Packit 534379
 * flag is equivalent to setting both flags: both read and write are
Packit 534379
 * requests permitted.
Packit 534379
 *
Packit 534379
 * Return: 0 on success, -errno on failure.
Packit 534379
 */
Packit 534379
struct fpga_port_dma_map {
Packit 534379
	/* Input */
Packit 534379
	__u32 argsz;		/* Structure length */
Packit 534379
	__u32 flags;		/* Zero for now */
Packit 534379
#define FPGA_DMA_TO_DEV		(1 << 0)	/* Region is readable by FPGA */
Packit 534379
#define FPGA_DMA_FROM_DEV	(1 << 1)	/* Region is writable by FPGA */
Packit 534379
	__u64 user_addr;        /* Process virtual address */
Packit 534379
	__u64 length;           /* Length of mapping (bytes)*/
Packit 534379
	/* Output */
Packit 534379
	__u64 iova;             /* IO virtual address */
Packit 534379
};
Packit 534379
Packit 534379
#define FPGA_PORT_DMA_MAP	_IO(FPGA_MAGIC, PORT_BASE + 3)
Packit 534379
Packit 534379
/**
Packit 534379
 * FPGA_PORT_DMA_UNMAP - _IOW(FPGA_MAGIC, PORT_BASE + 4,
Packit 534379
 *						struct fpga_port_dma_unmap)
Packit 534379
 *
Packit 534379
 * Unmap the dma memory per iova provided by caller.
Packit 534379
 * Return: 0 on success, -errno on failure.
Packit 534379
 */
Packit 534379
struct fpga_port_dma_unmap {
Packit 534379
	/* Input */
Packit 534379
	__u32 argsz;		/* Structure length */
Packit 534379
	__u32 flags;		/* Zero for now */
Packit 534379
	__u64 iova;		/* IO virtual address */
Packit 534379
};
Packit 534379
Packit 534379
#define FPGA_PORT_DMA_UNMAP	_IO(FPGA_MAGIC, PORT_BASE + 4)
Packit 534379
Packit 534379
/**
Packit 534379
 * FPGA_PORT_UMSG_ENABLE - _IO(FPGA_MAGIC, PORT_BASE + 5)
Packit 534379
 * FPGA_PORT_UMSG_DISABLE - _IO(FPGA_MAGIC, PORT_BASE + 6)
Packit 534379
 *
Packit 534379
 * Interfaces to control UMSG function. No parameters are supported.
Packit 534379
 * Return: 0 on success, -errno on failure.
Packit 534379
 */
Packit 534379
Packit 534379
#define FPGA_PORT_UMSG_ENABLE	_IO(FPGA_MAGIC, PORT_BASE + 5)
Packit 534379
#define FPGA_PORT_UMSG_DISABLE	_IO(FPGA_MAGIC, PORT_BASE + 6)
Packit 534379
Packit 534379
/**
Packit 534379
 * FPGA_PORT_UMSG_SET_MODE - _IOW(FPGA_MAGIC, PORT_BASE + 7,
Packit 534379
 *						struct fpga_port_umsg_cfg)
Packit 534379
 *
Packit 534379
 * Set Hint Mode per bitmap provided by caller. One bit for each page
Packit 534379
 * in hint_bitmap. 0 - Disable and 1 - Enable Hint Mode.
Packit 534379
 * Return: 0 on success, -errno on failure.
Packit 534379
 */
Packit 534379
struct fpga_port_umsg_cfg {
Packit 534379
	/* Input */
Packit 534379
	__u32 argsz;		/* Structure length */
Packit 534379
	__u32 flags;		/* Zero for now */
Packit 534379
	__u32 hint_bitmap;	/* UMSG Hint Mode Bitmap */
Packit 534379
};
Packit 534379
Packit 534379
#define FPGA_PORT_UMSG_SET_MODE		_IO(FPGA_MAGIC, PORT_BASE + 7)
Packit 534379
Packit 534379
/**
Packit 534379
 * FPGA_PORT_UMSG_SET_BASE_ADDR - _IOW(FPGA_MAGIC, PORT_BASE + 8,
Packit 534379
 *						struct afu_port_umsg_base_addr)
Packit 534379
 *
Packit 534379
 * Set UMSG base address per iova provided by caller. Driver configures the
Packit 534379
 * UMSG base address with the iova, but only accept iova which get from the
Packit 534379
 * DMA_MAP IOCTL interface and the DMA region is big enough for all UMSGs
Packit 534379
 * (num_umsg * PAGE_SIZE)
Packit 534379
 * Return: 0 on success, -errno on failure.
Packit 534379
 */
Packit 534379
struct fpga_port_umsg_base_addr {
Packit 534379
	/* Input */
Packit 534379
	__u32 argsz;		/* Structure length */
Packit 534379
	__u32 flags;		/* Zero for now */
Packit 534379
	__u64 iova;		/* IO virtual address */
Packit 534379
};
Packit 534379
Packit 534379
#define FPGA_PORT_UMSG_SET_BASE_ADDR	_IO(FPGA_MAGIC, PORT_BASE + 8)
Packit 534379
Packit 534379
/**
Packit 534379
 * FPGA_PORT_ERR_SET_IRQ - _IOW(FPGA_MAGIC, PORT_BASE + 9,
Packit 534379
 *                                             struct fpga_port_err_irq_set)
Packit 534379
 *
Packit 534379
 * Set fpga port global error interrupt eventfd
Packit 534379
 * Return: 0 on success, -errno on failure.
Packit 534379
 */
Packit 534379
struct fpga_port_err_irq_set {
Packit 534379
	/* Input */
Packit 534379
	__u32 argsz;		/* Structure length */
Packit 534379
	__u32 flags;		/* Zero for now */
Packit 534379
	__s32 evtfd;		/* Eventfd handler */
Packit 534379
};
Packit 534379
Packit 534379
#define FPGA_PORT_ERR_SET_IRQ		_IO(FPGA_MAGIC, PORT_BASE + 9)
Packit 534379
Packit 534379
/**
Packit 534379
 * FPGA_PORT_UAFU_SET_IRQ - _IOW(FPGA_MAGIC, PORT_BASE + 10,
Packit 534379
 *                                             struct fpga_port_uafu_irq_set)
Packit 534379
 *
Packit 534379
 * Set fpga UAFU interrupt eventfd
Packit 534379
 * Return: 0 on success, -errno on failure.
Packit 534379
 */
Packit 534379
struct fpga_port_uafu_irq_set {
Packit 534379
	/* Input */
Packit 534379
	__u32 argsz;		/* Structure length */
Packit 534379
	__u32 flags;		/* Zero for now */
Packit 534379
	__u32 start;		/* First irq number */
Packit 534379
	__u32 count;		/* The number of eventfd handler */
Packit 534379
	__s32 evtfd[];		/* Eventfd handler */
Packit 534379
};
Packit 534379
Packit 534379
#define FPGA_PORT_UAFU_SET_IRQ		_IO(FPGA_MAGIC, PORT_BASE + 10)
Packit 534379
Packit 534379
/* IOCTLs for FME file descriptor */
Packit 534379
Packit 534379
/**
Packit 534379
 * FPGA_FME_PORT_PR - _IOWR(FPGA_MAGIC, FME_BASE + 0, struct fpga_fme_port_pr)
Packit 534379
 *
Packit 534379
 * Driver does Partial Reconfiguration based on Port ID and Buffer (Image)
Packit 534379
 * provided by caller.
Packit 534379
 * Return: 0 on success, -errno on failure.
Packit 534379
 * If FPGA_FME_PORT_PR returns -EIO, that indicates the HW has detected
Packit 534379
 * some errors during PR, under this case, the user can fetch HW error code
Packit 534379
 * from fpga_fme_port_pr.status. Each bit on the error code is used as the
Packit 534379
 * index for the array created by DEFINE_FPGA_PR_ERR_MSG().
Packit 534379
 * Otherwise, it is always zero.
Packit 534379
 */
Packit 534379
Packit 534379
#define DEFINE_FPGA_PR_ERR_MSG(_name_)			\
Packit 534379
static const char * const _name_[] = {			\
Packit 534379
	"PR operation error detected",			\
Packit 534379
	"PR CRC error detected",			\
Packit 534379
	"PR incompatiable bitstream error detected",	\
Packit 534379
	"PR IP protocol error detected",		\
Packit 534379
	"PR FIFO overflow error detected",		\
Packit 534379
	"PR timeout error detected",			\
Packit 534379
	"PR secure load error detected",		\
Packit 534379
}
Packit 534379
Packit 534379
#define PR_MAX_ERR_NUM	7
Packit 534379
Packit 534379
struct fpga_fme_port_pr {
Packit 534379
	/* Input */
Packit 534379
	__u32 argsz;		/* Structure length */
Packit 534379
	__u32 flags;		/* Zero for now */
Packit 534379
	__u32 port_id;
Packit 534379
	__u32 buffer_size;
Packit 534379
	__u64 buffer_address;	/* Userspace address to the buffer for PR */
Packit 534379
	/* Output */
Packit 534379
	__u64 status;		/* HW error code if ioctl returns -EIO */
Packit 534379
};
Packit 534379
Packit 534379
#define FPGA_FME_PORT_PR	_IO(FPGA_MAGIC, FME_BASE + 0)
Packit 534379
Packit 534379
/**
Packit 534379
 * FPGA_FME_PORT_RELEASE - _IOW(FPGA_MAGIC, FME_BASE + 1,
Packit 534379
 *						struct fpga_fme_port_release)
Packit 534379
 *
Packit 534379
 * Driver releases the port per Port ID provided by caller.
Packit 534379
 * Return: 0 on success, -errno on failure.
Packit 534379
 */
Packit 534379
struct fpga_fme_port_release {
Packit 534379
	/* Input */
Packit 534379
	__u32 argsz;		/* Structure length */
Packit 534379
	__u32 flags;		/* Zero for now */
Packit 534379
	__u32 port_id;
Packit 534379
};
Packit 534379
Packit 534379
#define FPGA_FME_PORT_RELEASE	_IO(FPGA_MAGIC, FME_BASE + 1)
Packit 534379
Packit 534379
/**
Packit 534379
 * FPGA_FME_PORT_ASSIGN - _IOW(FPGA_MAGIC, FME_BASE + 2,
Packit 534379
 *						struct fpga_fme_port_assign)
Packit 534379
 *
Packit 534379
 * Driver assigns the port per Port ID provided by caller.
Packit 534379
 * Return: 0 on success, -errno on failure.
Packit 534379
 */
Packit 534379
struct fpga_fme_port_assign {
Packit 534379
	/* Input */
Packit 534379
	__u32 argsz;		/* Structure length */
Packit 534379
	__u32 flags;		/* Zero for now */
Packit 534379
	__u32 port_id;
Packit 534379
};
Packit 534379
Packit 534379
#define FPGA_FME_PORT_ASSIGN	_IO(FPGA_MAGIC, FME_BASE + 2)
Packit 534379
Packit 534379
/**
Packit 534379
 * FPGA_FME_GET_INFO - _IOR(FPGA_MAGIC, FME_BASE + 3, struct fpga_fme_info)
Packit 534379
 *
Packit 534379
 * Retrieve information about the fpga fme.
Packit 534379
 * Driver fills the info in provided struct fpga_fme_info.
Packit 534379
 * Return: 0 on success, -errno on failure.
Packit 534379
 */
Packit 534379
struct fpga_fme_info {
Packit 534379
	/* Input */
Packit 534379
	__u32 argsz;		/* Structure length */
Packit 534379
	/* Output */
Packit 534379
	__u32 flags;		/* Zero for now */
Packit 534379
	__u32 capability;	/* The capability of FME device */
Packit 534379
#define FPGA_FME_CAP_ERR_IRQ	(1 << 0) /* Support fme error interrupt */
Packit 534379
};
Packit 534379
Packit 534379
#define FPGA_FME_GET_INFO      _IO(FPGA_MAGIC, FME_BASE + 3)
Packit 534379
Packit 534379
/**
Packit 534379
 * FPGA_FME_ERR_SET_IRQ - _IOW(FPGA_MAGIC, FME_BASE + 4,
Packit 534379
 *                                             struct fpga_fme_err_irq_set)
Packit 534379
 *
Packit 534379
 * Set fpga fme global error interrupt eventfd
Packit 534379
 * Return: 0 on success, -errno on failure.
Packit 534379
 */
Packit 534379
struct fpga_fme_err_irq_set {
Packit 534379
	/* Input */
Packit 534379
	__u32 argsz;		/* Structure length */
Packit 534379
	__u32 flags;		/* Zero for now */
Packit 534379
	__s32 evtfd;		/* Eventfd handler */
Packit 534379
};
Packit 534379
Packit 534379
#define FPGA_FME_ERR_SET_IRQ	_IO(FPGA_MAGIC, FME_BASE + 4)
Packit 534379
Packit 534379
#endif /* _UAPI_INTEL_FPGA_H */