mirror of
https://github.com/edk2-porting/linux-next.git
synced 2024-12-24 21:24:00 +08:00
5cf0c7f650
fpga-mgr has three methods for programming FPGAs, depending on whether the image is in a scatter gather list, a contiguous buffer, or a firmware file. This makes it difficult to write upper layers as the caller has to assume whether the FPGA image is in a sg table, as a single buffer, or a firmware file. This commit moves these parameters to struct fpga_image_info and adds a single function for programming fpgas. New functions: * fpga_mgr_load - given fpga manager and struct fpga_image_info, program the fpga. * fpga_image_info_alloc - alloc a struct fpga_image_info. * fpga_image_info_free - free a struct fpga_image_info. These three functions are unexported: * fpga_mgr_buf_load_sg * fpga_mgr_buf_load * fpga_mgr_firmware_load Also use devm_kstrdup to copy firmware_name so we aren't making assumptions about where it comes from when allocing/freeing the struct fpga_image_info. API documentation has been updated and a new document for FPGA region has been added. Signed-off-by: Alan Tull <atull@kernel.org> Acked-by: Moritz Fischer <mdf@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
170 lines
5.8 KiB
C
170 lines
5.8 KiB
C
/*
|
|
* FPGA Framework
|
|
*
|
|
* Copyright (C) 2013-2016 Altera Corporation
|
|
* Copyright (C) 2017 Intel Corporation
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
* under the terms and conditions of the GNU General Public License,
|
|
* version 2, as published by the Free Software Foundation.
|
|
*
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
* more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along with
|
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
#ifndef _LINUX_FPGA_MGR_H
|
|
#define _LINUX_FPGA_MGR_H
|
|
|
|
#include <linux/mutex.h>
|
|
#include <linux/platform_device.h>
|
|
|
|
struct fpga_manager;
|
|
struct sg_table;
|
|
|
|
/**
|
|
* 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
|
|
* FPGA_MGR_EXTERNAL_CONFIG: FPGA has been configured prior to Linux booting
|
|
* FPGA_MGR_BITSTREAM_LSB_FIRST: SPI bitstream bit order is LSB first
|
|
* FPGA_MGR_COMPRESSED_BITSTREAM: FPGA bitstream is compressed
|
|
*/
|
|
#define FPGA_MGR_PARTIAL_RECONFIG BIT(0)
|
|
#define FPGA_MGR_EXTERNAL_CONFIG BIT(1)
|
|
#define FPGA_MGR_ENCRYPTED_BITSTREAM BIT(2)
|
|
#define FPGA_MGR_BITSTREAM_LSB_FIRST BIT(3)
|
|
#define FPGA_MGR_COMPRESSED_BITSTREAM BIT(4)
|
|
|
|
/**
|
|
* 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)
|
|
* @config_complete_timeout_us: maximum time for FPGA to switch to operating
|
|
* status in the write_complete op.
|
|
* @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
|
|
* @dev: device that owns this
|
|
*/
|
|
struct fpga_image_info {
|
|
u32 flags;
|
|
u32 enable_timeout_us;
|
|
u32 disable_timeout_us;
|
|
u32 config_complete_timeout_us;
|
|
char *firmware_name;
|
|
struct sg_table *sgt;
|
|
const char *buf;
|
|
size_t count;
|
|
struct device *dev;
|
|
};
|
|
|
|
/**
|
|
* struct fpga_manager_ops - ops for low level fpga manager drivers
|
|
* @initial_header_size: Maximum number of bytes that should be passed into write_init
|
|
* @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
|
|
* @write_sg: write the scatter list of configuration data to the FPGA
|
|
* @write_complete: set FPGA to operating state after writing is done
|
|
* @fpga_remove: optional: Set FPGA into a specific state during driver remove
|
|
*
|
|
* 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 {
|
|
size_t initial_header_size;
|
|
enum fpga_mgr_states (*state)(struct fpga_manager *mgr);
|
|
int (*write_init)(struct fpga_manager *mgr,
|
|
struct fpga_image_info *info,
|
|
const char *buf, size_t count);
|
|
int (*write)(struct fpga_manager *mgr, const char *buf, size_t count);
|
|
int (*write_sg)(struct fpga_manager *mgr, struct sg_table *sgt);
|
|
int (*write_complete)(struct fpga_manager *mgr,
|
|
struct fpga_image_info *info);
|
|
void (*fpga_remove)(struct fpga_manager *mgr);
|
|
};
|
|
|
|
/**
|
|
* 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)
|
|
|
|
struct fpga_image_info *fpga_image_info_alloc(struct device *dev);
|
|
|
|
void fpga_image_info_free(struct fpga_image_info *info);
|
|
|
|
int fpga_mgr_load(struct fpga_manager *mgr, struct fpga_image_info *info);
|
|
|
|
struct fpga_manager *of_fpga_mgr_get(struct device_node *node);
|
|
|
|
struct fpga_manager *fpga_mgr_get(struct device *dev);
|
|
|
|
void fpga_mgr_put(struct fpga_manager *mgr);
|
|
|
|
int fpga_mgr_register(struct device *dev, const char *name,
|
|
const struct fpga_manager_ops *mops, void *priv);
|
|
|
|
void fpga_mgr_unregister(struct device *dev);
|
|
|
|
#endif /*_LINUX_FPGA_MGR_H */
|