2018-05-17 07:49:58 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
2015-10-07 23:36:28 +08:00
|
|
|
/*
|
|
|
|
* FPGA Framework
|
|
|
|
*
|
2017-11-16 04:20:12 +08:00
|
|
|
* Copyright (C) 2013-2016 Altera Corporation
|
|
|
|
* Copyright (C) 2017 Intel Corporation
|
2015-10-07 23:36:28 +08:00
|
|
|
*/
|
|
|
|
#ifndef _LINUX_FPGA_MGR_H
|
|
|
|
#define _LINUX_FPGA_MGR_H
|
|
|
|
|
2017-11-16 04:20:12 +08:00
|
|
|
#include <linux/mutex.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
|
2015-10-07 23:36:28 +08:00
|
|
|
struct fpga_manager;
|
2017-02-02 03:48:44 +08:00
|
|
|
struct sg_table;
|
2015-10-07 23:36:28 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* enum fpga_mgr_states - fpga framework states
|
|
|
|
* @FPGA_MGR_STATE_UNKNOWN: can't determine state
|
|
|
|
* @FPGA_MGR_STATE_POWER_OFF: FPGA power is off
|
|
|
|
* @FPGA_MGR_STATE_POWER_UP: FPGA reports power is up
|
|
|
|
* @FPGA_MGR_STATE_RESET: FPGA in reset state
|
|
|
|
* @FPGA_MGR_STATE_FIRMWARE_REQ: firmware request in progress
|
|
|
|
* @FPGA_MGR_STATE_FIRMWARE_REQ_ERR: firmware request failed
|
|
|
|
* @FPGA_MGR_STATE_WRITE_INIT: preparing FPGA for programming
|
|
|
|
* @FPGA_MGR_STATE_WRITE_INIT_ERR: Error during WRITE_INIT stage
|
|
|
|
* @FPGA_MGR_STATE_WRITE: writing image to FPGA
|
|
|
|
* @FPGA_MGR_STATE_WRITE_ERR: Error while writing FPGA
|
|
|
|
* @FPGA_MGR_STATE_WRITE_COMPLETE: Doing post programming steps
|
|
|
|
* @FPGA_MGR_STATE_WRITE_COMPLETE_ERR: Error during WRITE_COMPLETE
|
|
|
|
* @FPGA_MGR_STATE_OPERATING: FPGA is programmed and operating
|
|
|
|
*/
|
|
|
|
enum fpga_mgr_states {
|
|
|
|
/* default FPGA states */
|
|
|
|
FPGA_MGR_STATE_UNKNOWN,
|
|
|
|
FPGA_MGR_STATE_POWER_OFF,
|
|
|
|
FPGA_MGR_STATE_POWER_UP,
|
|
|
|
FPGA_MGR_STATE_RESET,
|
|
|
|
|
|
|
|
/* getting an image for loading */
|
|
|
|
FPGA_MGR_STATE_FIRMWARE_REQ,
|
|
|
|
FPGA_MGR_STATE_FIRMWARE_REQ_ERR,
|
|
|
|
|
|
|
|
/* write sequence: init, write, complete */
|
|
|
|
FPGA_MGR_STATE_WRITE_INIT,
|
|
|
|
FPGA_MGR_STATE_WRITE_INIT_ERR,
|
|
|
|
FPGA_MGR_STATE_WRITE,
|
|
|
|
FPGA_MGR_STATE_WRITE_ERR,
|
|
|
|
FPGA_MGR_STATE_WRITE_COMPLETE,
|
|
|
|
FPGA_MGR_STATE_WRITE_COMPLETE_ERR,
|
|
|
|
|
|
|
|
/* fpga is programmed and operating */
|
|
|
|
FPGA_MGR_STATE_OPERATING,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FPGA Manager flags
|
|
|
|
* FPGA_MGR_PARTIAL_RECONFIG: do partial reconfiguration if supported
|
2016-11-02 03:14:29 +08:00
|
|
|
* FPGA_MGR_EXTERNAL_CONFIG: FPGA has been configured prior to Linux booting
|
2017-06-14 23:36:27 +08:00
|
|
|
* FPGA_MGR_BITSTREAM_LSB_FIRST: SPI bitstream bit order is LSB first
|
2017-06-14 23:36:34 +08:00
|
|
|
* FPGA_MGR_COMPRESSED_BITSTREAM: FPGA bitstream is compressed
|
2015-10-07 23:36:28 +08:00
|
|
|
*/
|
|
|
|
#define FPGA_MGR_PARTIAL_RECONFIG BIT(0)
|
2016-11-02 03:14:29 +08:00
|
|
|
#define FPGA_MGR_EXTERNAL_CONFIG BIT(1)
|
2017-02-27 23:19:00 +08:00
|
|
|
#define FPGA_MGR_ENCRYPTED_BITSTREAM BIT(2)
|
2017-06-14 23:36:27 +08:00
|
|
|
#define FPGA_MGR_BITSTREAM_LSB_FIRST BIT(3)
|
2017-06-14 23:36:34 +08:00
|
|
|
#define FPGA_MGR_COMPRESSED_BITSTREAM BIT(4)
|
2015-10-07 23:36:28 +08:00
|
|
|
|
2016-11-02 03:14:26 +08:00
|
|
|
/**
|
|
|
|
* struct fpga_image_info - information specific to a FPGA image
|
|
|
|
* @flags: boolean flags as defined above
|
|
|
|
* @enable_timeout_us: maximum time to enable traffic through bridge (uSec)
|
|
|
|
* @disable_timeout_us: maximum time to disable traffic through bridge (uSec)
|
2017-03-24 08:34:27 +08:00
|
|
|
* @config_complete_timeout_us: maximum time for FPGA to switch to operating
|
|
|
|
* status in the write_complete op.
|
2017-11-16 04:20:12 +08:00
|
|
|
* @firmware_name: name of FPGA image firmware file
|
|
|
|
* @sgt: scatter/gather table containing FPGA image
|
|
|
|
* @buf: contiguous buffer containing FPGA image
|
|
|
|
* @count: size of buf
|
2018-06-30 08:53:09 +08:00
|
|
|
* @region_id: id of target region
|
2017-11-16 04:20:12 +08:00
|
|
|
* @dev: device that owns this
|
2017-11-16 04:20:19 +08:00
|
|
|
* @overlay: Device Tree overlay
|
2016-11-02 03:14:26 +08:00
|
|
|
*/
|
|
|
|
struct fpga_image_info {
|
|
|
|
u32 flags;
|
|
|
|
u32 enable_timeout_us;
|
|
|
|
u32 disable_timeout_us;
|
2017-03-24 08:34:27 +08:00
|
|
|
u32 config_complete_timeout_us;
|
2017-11-16 04:20:12 +08:00
|
|
|
char *firmware_name;
|
|
|
|
struct sg_table *sgt;
|
|
|
|
const char *buf;
|
|
|
|
size_t count;
|
2018-06-30 08:53:09 +08:00
|
|
|
int region_id;
|
2017-11-16 04:20:12 +08:00
|
|
|
struct device *dev;
|
2017-11-16 04:20:19 +08:00
|
|
|
#ifdef CONFIG_OF
|
|
|
|
struct device_node *overlay;
|
|
|
|
#endif
|
2016-11-02 03:14:26 +08:00
|
|
|
};
|
|
|
|
|
2015-10-07 23:36:28 +08:00
|
|
|
/**
|
|
|
|
* struct fpga_manager_ops - ops for low level fpga manager drivers
|
2016-11-23 02:22:09 +08:00
|
|
|
* @initial_header_size: Maximum number of bytes that should be passed into write_init
|
2015-10-07 23:36:28 +08:00
|
|
|
* @state: returns an enum value of the FPGA's state
|
|
|
|
* @write_init: prepare the FPGA to receive confuration data
|
|
|
|
* @write: write count bytes of configuration data to the FPGA
|
2017-02-02 03:48:44 +08:00
|
|
|
* @write_sg: write the scatter list of configuration data to the FPGA
|
2015-10-07 23:36:28 +08:00
|
|
|
* @write_complete: set FPGA to operating state after writing is done
|
|
|
|
* @fpga_remove: optional: Set FPGA into a specific state during driver remove
|
2017-11-16 04:20:28 +08:00
|
|
|
* @groups: optional attribute groups.
|
2015-10-07 23:36:28 +08:00
|
|
|
*
|
|
|
|
* fpga_manager_ops are the low level functions implemented by a specific
|
|
|
|
* fpga manager driver. The optional ones are tested for NULL before being
|
|
|
|
* called, so leaving them out is fine.
|
|
|
|
*/
|
|
|
|
struct fpga_manager_ops {
|
2016-11-23 02:22:09 +08:00
|
|
|
size_t initial_header_size;
|
2015-10-07 23:36:28 +08:00
|
|
|
enum fpga_mgr_states (*state)(struct fpga_manager *mgr);
|
2016-11-02 03:14:26 +08:00
|
|
|
int (*write_init)(struct fpga_manager *mgr,
|
|
|
|
struct fpga_image_info *info,
|
2015-10-07 23:36:28 +08:00
|
|
|
const char *buf, size_t count);
|
|
|
|
int (*write)(struct fpga_manager *mgr, const char *buf, size_t count);
|
2017-02-02 03:48:44 +08:00
|
|
|
int (*write_sg)(struct fpga_manager *mgr, struct sg_table *sgt);
|
2016-11-02 03:14:26 +08:00
|
|
|
int (*write_complete)(struct fpga_manager *mgr,
|
|
|
|
struct fpga_image_info *info);
|
2015-10-07 23:36:28 +08:00
|
|
|
void (*fpga_remove)(struct fpga_manager *mgr);
|
2017-11-16 04:20:28 +08:00
|
|
|
const struct attribute_group **groups;
|
2015-10-07 23:36:28 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct fpga_manager - fpga manager structure
|
|
|
|
* @name: name of low level fpga manager
|
|
|
|
* @dev: fpga manager device
|
|
|
|
* @ref_mutex: only allows one reference to fpga manager
|
|
|
|
* @state: state of fpga manager
|
|
|
|
* @mops: pointer to struct of fpga manager ops
|
|
|
|
* @priv: low level driver private date
|
|
|
|
*/
|
|
|
|
struct fpga_manager {
|
|
|
|
const char *name;
|
|
|
|
struct device dev;
|
|
|
|
struct mutex ref_mutex;
|
|
|
|
enum fpga_mgr_states state;
|
|
|
|
const struct fpga_manager_ops *mops;
|
|
|
|
void *priv;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define to_fpga_manager(d) container_of(d, struct fpga_manager, dev)
|
|
|
|
|
2017-11-16 04:20:12 +08:00
|
|
|
struct fpga_image_info *fpga_image_info_alloc(struct device *dev);
|
|
|
|
|
|
|
|
void fpga_image_info_free(struct fpga_image_info *info);
|
2015-10-07 23:36:28 +08:00
|
|
|
|
2017-11-16 04:20:12 +08:00
|
|
|
int fpga_mgr_load(struct fpga_manager *mgr, struct fpga_image_info *info);
|
2015-10-07 23:36:28 +08:00
|
|
|
|
2017-11-16 04:20:13 +08:00
|
|
|
int fpga_mgr_lock(struct fpga_manager *mgr);
|
|
|
|
void fpga_mgr_unlock(struct fpga_manager *mgr);
|
|
|
|
|
2015-10-07 23:36:28 +08:00
|
|
|
struct fpga_manager *of_fpga_mgr_get(struct device_node *node);
|
|
|
|
|
2016-11-02 03:14:23 +08:00
|
|
|
struct fpga_manager *fpga_mgr_get(struct device *dev);
|
|
|
|
|
2015-10-07 23:36:28 +08:00
|
|
|
void fpga_mgr_put(struct fpga_manager *mgr);
|
|
|
|
|
2018-05-17 07:49:55 +08:00
|
|
|
struct fpga_manager *fpga_mgr_create(struct device *dev, const char *name,
|
|
|
|
const struct fpga_manager_ops *mops,
|
|
|
|
void *priv);
|
|
|
|
void fpga_mgr_free(struct fpga_manager *mgr);
|
|
|
|
int fpga_mgr_register(struct fpga_manager *mgr);
|
|
|
|
void fpga_mgr_unregister(struct fpga_manager *mgr);
|
2015-10-07 23:36:28 +08:00
|
|
|
|
|
|
|
#endif /*_LINUX_FPGA_MGR_H */
|