Skip to content

Commit 1df2865

Browse files
Alan Tullgregkh
authored andcommitted
fpga-mgr: add fpga image information struct
This patch adds a minor change in the FPGA Manager API to hold information that is specific to an FPGA image file. This change is expected to bring little, if any, pain. The socfpga and zynq drivers are fixed up in this patch. An FPGA image file will have particulars that affect how the image is programmed to the FPGA. One example is that current 'flags' currently has one bit which shows whether the FPGA image was built for full reconfiguration or partial reconfiguration. Another example is timeout values for enabling or disabling the bridges in the FPGA. As the complexity of the FPGA design increases, the bridges in the FPGA may take longer times to enable or disable. This patch adds a new 'struct fpga_image_info', moves the current 'u32 flags' to it. Two other image-specific u32's are added for the bridge enable/disable timeouts. The FPGA Manager API functions are changed, replacing the 'u32 flag' parameter with a pointer to struct fpga_image_info. Subsequent patches fix the existing low level FPGA manager drivers. Signed-off-by: Alan Tull <atull@opensource.altera.com> Acked-by: Moritz Fischer <moritz.fischer@ettus.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent a33ddf8 commit 1df2865

4 files changed

Lines changed: 38 additions & 19 deletions

File tree

‎drivers/fpga/fpga-mgr.c‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ static struct class *fpga_mgr_class;
3232
/**
3333
* fpga_mgr_buf_load - load fpga from image in buffer
3434
* @mgr: fpga manager
35-
* @flags: flags setting fpga confuration modes
35+
* @info: fpga image specific information
3636
* @buf: buffer contain fpga image
3737
* @count: byte count of buf
3838
*
@@ -44,8 +44,8 @@ static struct class *fpga_mgr_class;
4444
*
4545
* Return: 0 on success, negative error code otherwise.
4646
*/
47-
int fpga_mgr_buf_load(struct fpga_manager *mgr, u32 flags, const char *buf,
48-
size_t count)
47+
int fpga_mgr_buf_load(struct fpga_manager *mgr, struct fpga_image_info *info,
48+
const char *buf, size_t count)
4949
{
5050
struct device *dev = &mgr->dev;
5151
int ret;
@@ -56,7 +56,7 @@ int fpga_mgr_buf_load(struct fpga_manager *mgr, u32 flags, const char *buf,
5656
* ready to receive an FPGA image.
5757
*/
5858
mgr->state = FPGA_MGR_STATE_WRITE_INIT;
59-
ret = mgr->mops->write_init(mgr, flags, buf, count);
59+
ret = mgr->mops->write_init(mgr, info, buf, count);
6060
if (ret) {
6161
dev_err(dev, "Error preparing FPGA for writing\n");
6262
mgr->state = FPGA_MGR_STATE_WRITE_INIT_ERR;
@@ -79,7 +79,7 @@ int fpga_mgr_buf_load(struct fpga_manager *mgr, u32 flags, const char *buf,
7979
* steps to finish and set the FPGA into operating mode.
8080
*/
8181
mgr->state = FPGA_MGR_STATE_WRITE_COMPLETE;
82-
ret = mgr->mops->write_complete(mgr, flags);
82+
ret = mgr->mops->write_complete(mgr, info);
8383
if (ret) {
8484
dev_err(dev, "Error after writing image data to FPGA\n");
8585
mgr->state = FPGA_MGR_STATE_WRITE_COMPLETE_ERR;
@@ -94,7 +94,7 @@ EXPORT_SYMBOL_GPL(fpga_mgr_buf_load);
9494
/**
9595
* fpga_mgr_firmware_load - request firmware and load to fpga
9696
* @mgr: fpga manager
97-
* @flags: flags setting fpga confuration modes
97+
* @info: fpga image specific information
9898
* @image_name: name of image file on the firmware search path
9999
*
100100
* Request an FPGA image using the firmware class, then write out to the FPGA.
@@ -105,7 +105,8 @@ EXPORT_SYMBOL_GPL(fpga_mgr_buf_load);
105105
*
106106
* Return: 0 on success, negative error code otherwise.
107107
*/
108-
int fpga_mgr_firmware_load(struct fpga_manager *mgr, u32 flags,
108+
int fpga_mgr_firmware_load(struct fpga_manager *mgr,
109+
struct fpga_image_info *info,
109110
const char *image_name)
110111
{
111112
struct device *dev = &mgr->dev;
@@ -123,7 +124,7 @@ int fpga_mgr_firmware_load(struct fpga_manager *mgr, u32 flags,
123124
return ret;
124125
}
125126

126-
ret = fpga_mgr_buf_load(mgr, flags, fw->data, fw->size);
127+
ret = fpga_mgr_buf_load(mgr, info, fw->data, fw->size);
127128

128129
release_firmware(fw);
129130

‎drivers/fpga/socfpga.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,13 +407,14 @@ static int socfpga_fpga_reset(struct fpga_manager *mgr)
407407
/*
408408
* Prepare the FPGA to receive the configuration data.
409409
*/
410-
static int socfpga_fpga_ops_configure_init(struct fpga_manager *mgr, u32 flags,
410+
static int socfpga_fpga_ops_configure_init(struct fpga_manager *mgr,
411+
struct fpga_image_info *info,
411412
const char *buf, size_t count)
412413
{
413414
struct socfpga_fpga_priv *priv = mgr->priv;
414415
int ret;
415416

416-
if (flags & FPGA_MGR_PARTIAL_RECONFIG) {
417+
if (info->flags & FPGA_MGR_PARTIAL_RECONFIG) {
417418
dev_err(&mgr->dev, "Partial reconfiguration not supported.\n");
418419
return -EINVAL;
419420
}
@@ -478,7 +479,7 @@ static int socfpga_fpga_ops_configure_write(struct fpga_manager *mgr,
478479
}
479480

480481
static int socfpga_fpga_ops_configure_complete(struct fpga_manager *mgr,
481-
u32 flags)
482+
struct fpga_image_info *info)
482483
{
483484
struct socfpga_fpga_priv *priv = mgr->priv;
484485
u32 status;

‎drivers/fpga/zynq-fpga.c‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ static irqreturn_t zynq_fpga_isr(int irq, void *data)
175175
return IRQ_HANDLED;
176176
}
177177

178-
static int zynq_fpga_ops_write_init(struct fpga_manager *mgr, u32 flags,
178+
static int zynq_fpga_ops_write_init(struct fpga_manager *mgr,
179+
struct fpga_image_info *info,
179180
const char *buf, size_t count)
180181
{
181182
struct zynq_fpga_priv *priv;
@@ -189,7 +190,7 @@ static int zynq_fpga_ops_write_init(struct fpga_manager *mgr, u32 flags,
189190
return err;
190191

191192
/* don't globally reset PL if we're doing partial reconfig */
192-
if (!(flags & FPGA_MGR_PARTIAL_RECONFIG)) {
193+
if (!(info->flags & FPGA_MGR_PARTIAL_RECONFIG)) {
193194
/* assert AXI interface resets */
194195
regmap_write(priv->slcr, SLCR_FPGA_RST_CTRL_OFFSET,
195196
FPGA_RST_ALL_MASK);
@@ -343,7 +344,8 @@ static int zynq_fpga_ops_write(struct fpga_manager *mgr,
343344
return err;
344345
}
345346

346-
static int zynq_fpga_ops_write_complete(struct fpga_manager *mgr, u32 flags)
347+
static int zynq_fpga_ops_write_complete(struct fpga_manager *mgr,
348+
struct fpga_image_info *info)
347349
{
348350
struct zynq_fpga_priv *priv = mgr->priv;
349351
int err;
@@ -364,7 +366,7 @@ static int zynq_fpga_ops_write_complete(struct fpga_manager *mgr, u32 flags)
364366
return err;
365367

366368
/* for the partial reconfig case we didn't touch the level shifters */
367-
if (!(flags & FPGA_MGR_PARTIAL_RECONFIG)) {
369+
if (!(info->flags & FPGA_MGR_PARTIAL_RECONFIG)) {
368370
/* enable level shifters from PL to PS */
369371
regmap_write(priv->slcr, SLCR_LVL_SHFTR_EN_OFFSET,
370372
LVL_SHFTR_ENABLE_PL_TO_PS);

‎include/linux/fpga/fpga-mgr.h‎

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,18 @@ enum fpga_mgr_states {
6868
*/
6969
#define FPGA_MGR_PARTIAL_RECONFIG BIT(0)
7070

71+
/**
72+
* struct fpga_image_info - information specific to a FPGA image
73+
* @flags: boolean flags as defined above
74+
* @enable_timeout_us: maximum time to enable traffic through bridge (uSec)
75+
* @disable_timeout_us: maximum time to disable traffic through bridge (uSec)
76+
*/
77+
struct fpga_image_info {
78+
u32 flags;
79+
u32 enable_timeout_us;
80+
u32 disable_timeout_us;
81+
};
82+
7183
/**
7284
* struct fpga_manager_ops - ops for low level fpga manager drivers
7385
* @state: returns an enum value of the FPGA's state
@@ -82,10 +94,12 @@ enum fpga_mgr_states {
8294
*/
8395
struct fpga_manager_ops {
8496
enum fpga_mgr_states (*state)(struct fpga_manager *mgr);
85-
int (*write_init)(struct fpga_manager *mgr, u32 flags,
97+
int (*write_init)(struct fpga_manager *mgr,
98+
struct fpga_image_info *info,
8699
const char *buf, size_t count);
87100
int (*write)(struct fpga_manager *mgr, const char *buf, size_t count);
88-
int (*write_complete)(struct fpga_manager *mgr, u32 flags);
101+
int (*write_complete)(struct fpga_manager *mgr,
102+
struct fpga_image_info *info);
89103
void (*fpga_remove)(struct fpga_manager *mgr);
90104
};
91105

@@ -109,10 +123,11 @@ struct fpga_manager {
109123

110124
#define to_fpga_manager(d) container_of(d, struct fpga_manager, dev)
111125

112-
int fpga_mgr_buf_load(struct fpga_manager *mgr, u32 flags,
126+
int fpga_mgr_buf_load(struct fpga_manager *mgr, struct fpga_image_info *info,
113127
const char *buf, size_t count);
114128

115-
int fpga_mgr_firmware_load(struct fpga_manager *mgr, u32 flags,
129+
int fpga_mgr_firmware_load(struct fpga_manager *mgr,
130+
struct fpga_image_info *info,
116131
const char *image_name);
117132

118133
struct fpga_manager *of_fpga_mgr_get(struct device_node *node);

0 commit comments

Comments
 (0)