2018-05-16 23:49:58 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2015-10-07 15:36:28 +00:00
|
|
|
/*
|
|
|
|
* FPGA Manager Core
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013-2015 Altera Corporation
|
2017-11-15 20:20:12 +00:00
|
|
|
* Copyright (C) 2017 Intel Corporation
|
2015-10-07 15:36:28 +00:00
|
|
|
*
|
|
|
|
* With code from the mailing list:
|
|
|
|
* Copyright (C) 2013 Xilinx, Inc.
|
|
|
|
*/
|
|
|
|
#include <linux/firmware.h>
|
|
|
|
#include <linux/fpga/fpga-mgr.h>
|
|
|
|
#include <linux/idr.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/mutex.h>
|
|
|
|
#include <linux/slab.h>
|
2017-02-01 19:48:44 +00:00
|
|
|
#include <linux/scatterlist.h>
|
|
|
|
#include <linux/highmem.h>
|
2015-10-07 15:36:28 +00:00
|
|
|
|
|
|
|
static DEFINE_IDA(fpga_mgr_ida);
|
2023-08-11 07:30:42 +00:00
|
|
|
static const struct class fpga_mgr_class;
|
2015-10-07 15:36:28 +00:00
|
|
|
|
2020-11-15 19:51:18 +00:00
|
|
|
struct fpga_mgr_devres {
|
|
|
|
struct fpga_manager *mgr;
|
|
|
|
};
|
|
|
|
|
2021-06-25 19:51:47 +00:00
|
|
|
static inline void fpga_mgr_fpga_remove(struct fpga_manager *mgr)
|
|
|
|
{
|
|
|
|
if (mgr->mops->fpga_remove)
|
|
|
|
mgr->mops->fpga_remove(mgr);
|
|
|
|
}
|
|
|
|
|
2021-06-25 19:51:46 +00:00
|
|
|
static inline enum fpga_mgr_states fpga_mgr_state(struct fpga_manager *mgr)
|
|
|
|
{
|
|
|
|
if (mgr->mops->state)
|
|
|
|
return mgr->mops->state(mgr);
|
|
|
|
return FPGA_MGR_STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
2021-06-25 19:51:45 +00:00
|
|
|
static inline u64 fpga_mgr_status(struct fpga_manager *mgr)
|
|
|
|
{
|
|
|
|
if (mgr->mops->status)
|
|
|
|
return mgr->mops->status(mgr);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-06-25 19:51:44 +00:00
|
|
|
static inline int fpga_mgr_write(struct fpga_manager *mgr, const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
if (mgr->mops->write)
|
|
|
|
return mgr->mops->write(mgr, buf, count);
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
2021-06-25 19:51:43 +00:00
|
|
|
/*
|
|
|
|
* After all the FPGA image has been written, do the device specific steps to
|
|
|
|
* finish and set the FPGA into operating mode.
|
|
|
|
*/
|
|
|
|
static inline int fpga_mgr_write_complete(struct fpga_manager *mgr,
|
|
|
|
struct fpga_image_info *info)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
mgr->state = FPGA_MGR_STATE_WRITE_COMPLETE;
|
|
|
|
if (mgr->mops->write_complete)
|
|
|
|
ret = mgr->mops->write_complete(mgr, info);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(&mgr->dev, "Error after writing image data to FPGA\n");
|
|
|
|
mgr->state = FPGA_MGR_STATE_WRITE_COMPLETE_ERR;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
mgr->state = FPGA_MGR_STATE_OPERATING;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
fpga: fpga-mgr: support bitstream offset in image buffer
At the moment FPGA manager core loads to the device entire image
provided to fpga_mgr_load(). But it is not always whole FPGA image
buffer meant to be written to the device. In particular, .dat formatted
image for Microchip MPF contains meta info in the header that is not
meant to be written to the device. This is issue for those low level
drivers that loads data to the device with write() fpga_manager_ops
callback, since write() can be called in iterator over scatter-gather
table, not only linear image buffer. On the other hand, write_sg()
callback is provided with whole image in scatter-gather form and can
decide itself which part should be sent to the device.
Add header_size and data_size to the fpga_image_info struct, add
skip_header to the fpga_manager_ops struct and adjust fpga_mgr_write()
callers with respect to them.
* info->header_size indicates part at the beginning of image buffer
that contains some meta info. It is optional and can be 0,
initialized with mops->initial_header_size.
* mops->skip_header tells fpga-mgr core whether write should start
from the beginning of image buffer or at the offset of header_size.
* info->data_size is the size of bitstream data that is meant to be
written to the device. It is also optional and can be 0, which
means bitstream data is up to the end of image buffer.
Also add parse_header() callback to fpga_manager_ops, which purpose is
to set info->header_size and info->data_size. At least
initial_header_size bytes of image buffer will be passed into
parse_header() first time. If it is not enough, parse_header() should
set desired size into info->header_size and return -EAGAIN, then it will
be called again with greater part of image buffer on the input.
Suggested-by: Xu Yilun <yilun.xu@intel.com>
Signed-off-by: Ivan Bornyakov <i.bornyakov@metrotek.ru>
Acked-by: Xu Yilun <yilun.xu@intel.com>
Link: https://lore.kernel.org/r/20220623163248.3672-2-i.bornyakov@metrotek.ru
Signed-off-by: Xu Yilun <yilun.xu@intel.com>
2022-06-23 16:32:44 +00:00
|
|
|
static inline int fpga_mgr_parse_header(struct fpga_manager *mgr,
|
|
|
|
struct fpga_image_info *info,
|
|
|
|
const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
if (mgr->mops->parse_header)
|
|
|
|
return mgr->mops->parse_header(mgr, info, buf, count);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-06-25 19:51:42 +00:00
|
|
|
static inline int fpga_mgr_write_init(struct fpga_manager *mgr,
|
|
|
|
struct fpga_image_info *info,
|
|
|
|
const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
if (mgr->mops->write_init)
|
|
|
|
return mgr->mops->write_init(mgr, info, buf, count);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-06-25 19:51:48 +00:00
|
|
|
static inline int fpga_mgr_write_sg(struct fpga_manager *mgr,
|
|
|
|
struct sg_table *sgt)
|
|
|
|
{
|
|
|
|
if (mgr->mops->write_sg)
|
|
|
|
return mgr->mops->write_sg(mgr, sgt);
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
2018-05-16 23:49:59 +00:00
|
|
|
/**
|
2021-06-08 21:23:46 +00:00
|
|
|
* fpga_image_info_alloc - Allocate an FPGA image info struct
|
2018-05-16 23:49:59 +00:00
|
|
|
* @dev: owning device
|
|
|
|
*
|
|
|
|
* Return: struct fpga_image_info or NULL
|
|
|
|
*/
|
2017-11-15 20:20:12 +00:00
|
|
|
struct fpga_image_info *fpga_image_info_alloc(struct device *dev)
|
|
|
|
{
|
|
|
|
struct fpga_image_info *info;
|
|
|
|
|
|
|
|
get_device(dev);
|
|
|
|
|
|
|
|
info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL);
|
|
|
|
if (!info) {
|
|
|
|
put_device(dev);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
info->dev = dev;
|
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(fpga_image_info_alloc);
|
|
|
|
|
2018-05-16 23:49:59 +00:00
|
|
|
/**
|
2021-06-08 21:23:46 +00:00
|
|
|
* fpga_image_info_free - Free an FPGA image info struct
|
2018-05-16 23:49:59 +00:00
|
|
|
* @info: FPGA image info struct to free
|
|
|
|
*/
|
2017-11-15 20:20:12 +00:00
|
|
|
void fpga_image_info_free(struct fpga_image_info *info)
|
|
|
|
{
|
|
|
|
struct device *dev;
|
|
|
|
|
|
|
|
if (!info)
|
|
|
|
return;
|
|
|
|
|
|
|
|
dev = info->dev;
|
|
|
|
if (info->firmware_name)
|
|
|
|
devm_kfree(dev, info->firmware_name);
|
|
|
|
|
|
|
|
devm_kfree(dev, info);
|
|
|
|
put_device(dev);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(fpga_image_info_free);
|
|
|
|
|
2017-02-01 19:48:44 +00:00
|
|
|
/*
|
fpga: fpga-mgr: support bitstream offset in image buffer
At the moment FPGA manager core loads to the device entire image
provided to fpga_mgr_load(). But it is not always whole FPGA image
buffer meant to be written to the device. In particular, .dat formatted
image for Microchip MPF contains meta info in the header that is not
meant to be written to the device. This is issue for those low level
drivers that loads data to the device with write() fpga_manager_ops
callback, since write() can be called in iterator over scatter-gather
table, not only linear image buffer. On the other hand, write_sg()
callback is provided with whole image in scatter-gather form and can
decide itself which part should be sent to the device.
Add header_size and data_size to the fpga_image_info struct, add
skip_header to the fpga_manager_ops struct and adjust fpga_mgr_write()
callers with respect to them.
* info->header_size indicates part at the beginning of image buffer
that contains some meta info. It is optional and can be 0,
initialized with mops->initial_header_size.
* mops->skip_header tells fpga-mgr core whether write should start
from the beginning of image buffer or at the offset of header_size.
* info->data_size is the size of bitstream data that is meant to be
written to the device. It is also optional and can be 0, which
means bitstream data is up to the end of image buffer.
Also add parse_header() callback to fpga_manager_ops, which purpose is
to set info->header_size and info->data_size. At least
initial_header_size bytes of image buffer will be passed into
parse_header() first time. If it is not enough, parse_header() should
set desired size into info->header_size and return -EAGAIN, then it will
be called again with greater part of image buffer on the input.
Suggested-by: Xu Yilun <yilun.xu@intel.com>
Signed-off-by: Ivan Bornyakov <i.bornyakov@metrotek.ru>
Acked-by: Xu Yilun <yilun.xu@intel.com>
Link: https://lore.kernel.org/r/20220623163248.3672-2-i.bornyakov@metrotek.ru
Signed-off-by: Xu Yilun <yilun.xu@intel.com>
2022-06-23 16:32:44 +00:00
|
|
|
* Call the low level driver's parse_header function with entire FPGA image
|
|
|
|
* buffer on the input. This will set info->header_size and info->data_size.
|
|
|
|
*/
|
|
|
|
static int fpga_mgr_parse_header_mapped(struct fpga_manager *mgr,
|
|
|
|
struct fpga_image_info *info,
|
|
|
|
const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
mgr->state = FPGA_MGR_STATE_PARSE_HEADER;
|
|
|
|
ret = fpga_mgr_parse_header(mgr, info, buf, count);
|
|
|
|
|
|
|
|
if (info->header_size + info->data_size > count) {
|
2022-06-24 08:14:09 +00:00
|
|
|
dev_err(&mgr->dev, "Bitstream data outruns FPGA image\n");
|
fpga: fpga-mgr: support bitstream offset in image buffer
At the moment FPGA manager core loads to the device entire image
provided to fpga_mgr_load(). But it is not always whole FPGA image
buffer meant to be written to the device. In particular, .dat formatted
image for Microchip MPF contains meta info in the header that is not
meant to be written to the device. This is issue for those low level
drivers that loads data to the device with write() fpga_manager_ops
callback, since write() can be called in iterator over scatter-gather
table, not only linear image buffer. On the other hand, write_sg()
callback is provided with whole image in scatter-gather form and can
decide itself which part should be sent to the device.
Add header_size and data_size to the fpga_image_info struct, add
skip_header to the fpga_manager_ops struct and adjust fpga_mgr_write()
callers with respect to them.
* info->header_size indicates part at the beginning of image buffer
that contains some meta info. It is optional and can be 0,
initialized with mops->initial_header_size.
* mops->skip_header tells fpga-mgr core whether write should start
from the beginning of image buffer or at the offset of header_size.
* info->data_size is the size of bitstream data that is meant to be
written to the device. It is also optional and can be 0, which
means bitstream data is up to the end of image buffer.
Also add parse_header() callback to fpga_manager_ops, which purpose is
to set info->header_size and info->data_size. At least
initial_header_size bytes of image buffer will be passed into
parse_header() first time. If it is not enough, parse_header() should
set desired size into info->header_size and return -EAGAIN, then it will
be called again with greater part of image buffer on the input.
Suggested-by: Xu Yilun <yilun.xu@intel.com>
Signed-off-by: Ivan Bornyakov <i.bornyakov@metrotek.ru>
Acked-by: Xu Yilun <yilun.xu@intel.com>
Link: https://lore.kernel.org/r/20220623163248.3672-2-i.bornyakov@metrotek.ru
Signed-off-by: Xu Yilun <yilun.xu@intel.com>
2022-06-23 16:32:44 +00:00
|
|
|
ret = -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret) {
|
|
|
|
dev_err(&mgr->dev, "Error while parsing FPGA image header\n");
|
|
|
|
mgr->state = FPGA_MGR_STATE_PARSE_HEADER_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Call the low level driver's parse_header function with first fragment of
|
|
|
|
* scattered FPGA image on the input. If header fits first fragment,
|
|
|
|
* parse_header will set info->header_size and info->data_size. If it is not,
|
|
|
|
* parse_header will set desired size to info->header_size and -EAGAIN will be
|
|
|
|
* returned.
|
|
|
|
*/
|
|
|
|
static int fpga_mgr_parse_header_sg_first(struct fpga_manager *mgr,
|
|
|
|
struct fpga_image_info *info,
|
|
|
|
struct sg_table *sgt)
|
|
|
|
{
|
|
|
|
struct sg_mapping_iter miter;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
mgr->state = FPGA_MGR_STATE_PARSE_HEADER;
|
|
|
|
|
|
|
|
sg_miter_start(&miter, sgt->sgl, sgt->nents, SG_MITER_FROM_SG);
|
|
|
|
if (sg_miter_next(&miter) &&
|
|
|
|
miter.length >= info->header_size)
|
|
|
|
ret = fpga_mgr_parse_header(mgr, info, miter.addr, miter.length);
|
|
|
|
else
|
|
|
|
ret = -EAGAIN;
|
|
|
|
sg_miter_stop(&miter);
|
|
|
|
|
|
|
|
if (ret && ret != -EAGAIN) {
|
|
|
|
dev_err(&mgr->dev, "Error while parsing FPGA image header\n");
|
|
|
|
mgr->state = FPGA_MGR_STATE_PARSE_HEADER_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy scattered FPGA image fragments to temporary buffer and call the
|
|
|
|
* low level driver's parse_header function. This should be called after
|
|
|
|
* fpga_mgr_parse_header_sg_first() returned -EAGAIN. In case of success,
|
|
|
|
* pointer to the newly allocated image header copy will be returned and
|
|
|
|
* its size will be set into *ret_size. Returned buffer needs to be freed.
|
|
|
|
*/
|
|
|
|
static void *fpga_mgr_parse_header_sg(struct fpga_manager *mgr,
|
|
|
|
struct fpga_image_info *info,
|
|
|
|
struct sg_table *sgt, size_t *ret_size)
|
|
|
|
{
|
|
|
|
size_t len, new_header_size, header_size = 0;
|
|
|
|
char *new_buf, *buf = NULL;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
do {
|
|
|
|
new_header_size = info->header_size;
|
|
|
|
if (new_header_size <= header_size) {
|
|
|
|
dev_err(&mgr->dev, "Requested invalid header size\n");
|
|
|
|
ret = -EFAULT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
new_buf = krealloc(buf, new_header_size, GFP_KERNEL);
|
|
|
|
if (!new_buf) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
buf = new_buf;
|
|
|
|
|
|
|
|
len = sg_pcopy_to_buffer(sgt->sgl, sgt->nents,
|
|
|
|
buf + header_size,
|
|
|
|
new_header_size - header_size,
|
|
|
|
header_size);
|
|
|
|
if (len != new_header_size - header_size) {
|
|
|
|
ret = -EFAULT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
header_size = new_header_size;
|
|
|
|
ret = fpga_mgr_parse_header(mgr, info, buf, header_size);
|
|
|
|
} while (ret == -EAGAIN);
|
|
|
|
|
|
|
|
if (ret) {
|
|
|
|
dev_err(&mgr->dev, "Error while parsing FPGA image header\n");
|
|
|
|
mgr->state = FPGA_MGR_STATE_PARSE_HEADER_ERR;
|
|
|
|
kfree(buf);
|
|
|
|
buf = ERR_PTR(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
*ret_size = header_size;
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Call the low level driver's write_init function. This will do the
|
2017-02-01 19:48:44 +00:00
|
|
|
* device-specific things to get the FPGA into the state where it is ready to
|
fpga: fpga-mgr: support bitstream offset in image buffer
At the moment FPGA manager core loads to the device entire image
provided to fpga_mgr_load(). But it is not always whole FPGA image
buffer meant to be written to the device. In particular, .dat formatted
image for Microchip MPF contains meta info in the header that is not
meant to be written to the device. This is issue for those low level
drivers that loads data to the device with write() fpga_manager_ops
callback, since write() can be called in iterator over scatter-gather
table, not only linear image buffer. On the other hand, write_sg()
callback is provided with whole image in scatter-gather form and can
decide itself which part should be sent to the device.
Add header_size and data_size to the fpga_image_info struct, add
skip_header to the fpga_manager_ops struct and adjust fpga_mgr_write()
callers with respect to them.
* info->header_size indicates part at the beginning of image buffer
that contains some meta info. It is optional and can be 0,
initialized with mops->initial_header_size.
* mops->skip_header tells fpga-mgr core whether write should start
from the beginning of image buffer or at the offset of header_size.
* info->data_size is the size of bitstream data that is meant to be
written to the device. It is also optional and can be 0, which
means bitstream data is up to the end of image buffer.
Also add parse_header() callback to fpga_manager_ops, which purpose is
to set info->header_size and info->data_size. At least
initial_header_size bytes of image buffer will be passed into
parse_header() first time. If it is not enough, parse_header() should
set desired size into info->header_size and return -EAGAIN, then it will
be called again with greater part of image buffer on the input.
Suggested-by: Xu Yilun <yilun.xu@intel.com>
Signed-off-by: Ivan Bornyakov <i.bornyakov@metrotek.ru>
Acked-by: Xu Yilun <yilun.xu@intel.com>
Link: https://lore.kernel.org/r/20220623163248.3672-2-i.bornyakov@metrotek.ru
Signed-off-by: Xu Yilun <yilun.xu@intel.com>
2022-06-23 16:32:44 +00:00
|
|
|
* receive an FPGA image. The low level driver gets to see at least first
|
|
|
|
* info->header_size bytes in the buffer. If info->header_size is 0,
|
|
|
|
* write_init will not get any bytes of image buffer.
|
2017-02-01 19:48:44 +00:00
|
|
|
*/
|
|
|
|
static int fpga_mgr_write_init_buf(struct fpga_manager *mgr,
|
|
|
|
struct fpga_image_info *info,
|
|
|
|
const char *buf, size_t count)
|
|
|
|
{
|
fpga: fpga-mgr: support bitstream offset in image buffer
At the moment FPGA manager core loads to the device entire image
provided to fpga_mgr_load(). But it is not always whole FPGA image
buffer meant to be written to the device. In particular, .dat formatted
image for Microchip MPF contains meta info in the header that is not
meant to be written to the device. This is issue for those low level
drivers that loads data to the device with write() fpga_manager_ops
callback, since write() can be called in iterator over scatter-gather
table, not only linear image buffer. On the other hand, write_sg()
callback is provided with whole image in scatter-gather form and can
decide itself which part should be sent to the device.
Add header_size and data_size to the fpga_image_info struct, add
skip_header to the fpga_manager_ops struct and adjust fpga_mgr_write()
callers with respect to them.
* info->header_size indicates part at the beginning of image buffer
that contains some meta info. It is optional and can be 0,
initialized with mops->initial_header_size.
* mops->skip_header tells fpga-mgr core whether write should start
from the beginning of image buffer or at the offset of header_size.
* info->data_size is the size of bitstream data that is meant to be
written to the device. It is also optional and can be 0, which
means bitstream data is up to the end of image buffer.
Also add parse_header() callback to fpga_manager_ops, which purpose is
to set info->header_size and info->data_size. At least
initial_header_size bytes of image buffer will be passed into
parse_header() first time. If it is not enough, parse_header() should
set desired size into info->header_size and return -EAGAIN, then it will
be called again with greater part of image buffer on the input.
Suggested-by: Xu Yilun <yilun.xu@intel.com>
Signed-off-by: Ivan Bornyakov <i.bornyakov@metrotek.ru>
Acked-by: Xu Yilun <yilun.xu@intel.com>
Link: https://lore.kernel.org/r/20220623163248.3672-2-i.bornyakov@metrotek.ru
Signed-off-by: Xu Yilun <yilun.xu@intel.com>
2022-06-23 16:32:44 +00:00
|
|
|
size_t header_size = info->header_size;
|
2017-02-01 19:48:44 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
mgr->state = FPGA_MGR_STATE_WRITE_INIT;
|
fpga: fpga-mgr: support bitstream offset in image buffer
At the moment FPGA manager core loads to the device entire image
provided to fpga_mgr_load(). But it is not always whole FPGA image
buffer meant to be written to the device. In particular, .dat formatted
image for Microchip MPF contains meta info in the header that is not
meant to be written to the device. This is issue for those low level
drivers that loads data to the device with write() fpga_manager_ops
callback, since write() can be called in iterator over scatter-gather
table, not only linear image buffer. On the other hand, write_sg()
callback is provided with whole image in scatter-gather form and can
decide itself which part should be sent to the device.
Add header_size and data_size to the fpga_image_info struct, add
skip_header to the fpga_manager_ops struct and adjust fpga_mgr_write()
callers with respect to them.
* info->header_size indicates part at the beginning of image buffer
that contains some meta info. It is optional and can be 0,
initialized with mops->initial_header_size.
* mops->skip_header tells fpga-mgr core whether write should start
from the beginning of image buffer or at the offset of header_size.
* info->data_size is the size of bitstream data that is meant to be
written to the device. It is also optional and can be 0, which
means bitstream data is up to the end of image buffer.
Also add parse_header() callback to fpga_manager_ops, which purpose is
to set info->header_size and info->data_size. At least
initial_header_size bytes of image buffer will be passed into
parse_header() first time. If it is not enough, parse_header() should
set desired size into info->header_size and return -EAGAIN, then it will
be called again with greater part of image buffer on the input.
Suggested-by: Xu Yilun <yilun.xu@intel.com>
Signed-off-by: Ivan Bornyakov <i.bornyakov@metrotek.ru>
Acked-by: Xu Yilun <yilun.xu@intel.com>
Link: https://lore.kernel.org/r/20220623163248.3672-2-i.bornyakov@metrotek.ru
Signed-off-by: Xu Yilun <yilun.xu@intel.com>
2022-06-23 16:32:44 +00:00
|
|
|
|
|
|
|
if (header_size > count)
|
|
|
|
ret = -EINVAL;
|
|
|
|
else if (!header_size)
|
2021-06-25 19:51:42 +00:00
|
|
|
ret = fpga_mgr_write_init(mgr, info, NULL, 0);
|
fpga: fpga-mgr: support bitstream offset in image buffer
At the moment FPGA manager core loads to the device entire image
provided to fpga_mgr_load(). But it is not always whole FPGA image
buffer meant to be written to the device. In particular, .dat formatted
image for Microchip MPF contains meta info in the header that is not
meant to be written to the device. This is issue for those low level
drivers that loads data to the device with write() fpga_manager_ops
callback, since write() can be called in iterator over scatter-gather
table, not only linear image buffer. On the other hand, write_sg()
callback is provided with whole image in scatter-gather form and can
decide itself which part should be sent to the device.
Add header_size and data_size to the fpga_image_info struct, add
skip_header to the fpga_manager_ops struct and adjust fpga_mgr_write()
callers with respect to them.
* info->header_size indicates part at the beginning of image buffer
that contains some meta info. It is optional and can be 0,
initialized with mops->initial_header_size.
* mops->skip_header tells fpga-mgr core whether write should start
from the beginning of image buffer or at the offset of header_size.
* info->data_size is the size of bitstream data that is meant to be
written to the device. It is also optional and can be 0, which
means bitstream data is up to the end of image buffer.
Also add parse_header() callback to fpga_manager_ops, which purpose is
to set info->header_size and info->data_size. At least
initial_header_size bytes of image buffer will be passed into
parse_header() first time. If it is not enough, parse_header() should
set desired size into info->header_size and return -EAGAIN, then it will
be called again with greater part of image buffer on the input.
Suggested-by: Xu Yilun <yilun.xu@intel.com>
Signed-off-by: Ivan Bornyakov <i.bornyakov@metrotek.ru>
Acked-by: Xu Yilun <yilun.xu@intel.com>
Link: https://lore.kernel.org/r/20220623163248.3672-2-i.bornyakov@metrotek.ru
Signed-off-by: Xu Yilun <yilun.xu@intel.com>
2022-06-23 16:32:44 +00:00
|
|
|
else
|
2022-04-23 17:02:32 +00:00
|
|
|
ret = fpga_mgr_write_init(mgr, info, buf, count);
|
2017-02-01 19:48:44 +00:00
|
|
|
|
|
|
|
if (ret) {
|
|
|
|
dev_err(&mgr->dev, "Error preparing FPGA for writing\n");
|
|
|
|
mgr->state = FPGA_MGR_STATE_WRITE_INIT_ERR;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
fpga: fpga-mgr: support bitstream offset in image buffer
At the moment FPGA manager core loads to the device entire image
provided to fpga_mgr_load(). But it is not always whole FPGA image
buffer meant to be written to the device. In particular, .dat formatted
image for Microchip MPF contains meta info in the header that is not
meant to be written to the device. This is issue for those low level
drivers that loads data to the device with write() fpga_manager_ops
callback, since write() can be called in iterator over scatter-gather
table, not only linear image buffer. On the other hand, write_sg()
callback is provided with whole image in scatter-gather form and can
decide itself which part should be sent to the device.
Add header_size and data_size to the fpga_image_info struct, add
skip_header to the fpga_manager_ops struct and adjust fpga_mgr_write()
callers with respect to them.
* info->header_size indicates part at the beginning of image buffer
that contains some meta info. It is optional and can be 0,
initialized with mops->initial_header_size.
* mops->skip_header tells fpga-mgr core whether write should start
from the beginning of image buffer or at the offset of header_size.
* info->data_size is the size of bitstream data that is meant to be
written to the device. It is also optional and can be 0, which
means bitstream data is up to the end of image buffer.
Also add parse_header() callback to fpga_manager_ops, which purpose is
to set info->header_size and info->data_size. At least
initial_header_size bytes of image buffer will be passed into
parse_header() first time. If it is not enough, parse_header() should
set desired size into info->header_size and return -EAGAIN, then it will
be called again with greater part of image buffer on the input.
Suggested-by: Xu Yilun <yilun.xu@intel.com>
Signed-off-by: Ivan Bornyakov <i.bornyakov@metrotek.ru>
Acked-by: Xu Yilun <yilun.xu@intel.com>
Link: https://lore.kernel.org/r/20220623163248.3672-2-i.bornyakov@metrotek.ru
Signed-off-by: Xu Yilun <yilun.xu@intel.com>
2022-06-23 16:32:44 +00:00
|
|
|
static int fpga_mgr_prepare_sg(struct fpga_manager *mgr,
|
|
|
|
struct fpga_image_info *info,
|
|
|
|
struct sg_table *sgt)
|
2017-02-01 19:48:44 +00:00
|
|
|
{
|
|
|
|
struct sg_mapping_iter miter;
|
|
|
|
size_t len;
|
|
|
|
char *buf;
|
|
|
|
int ret;
|
|
|
|
|
fpga: fpga-mgr: support bitstream offset in image buffer
At the moment FPGA manager core loads to the device entire image
provided to fpga_mgr_load(). But it is not always whole FPGA image
buffer meant to be written to the device. In particular, .dat formatted
image for Microchip MPF contains meta info in the header that is not
meant to be written to the device. This is issue for those low level
drivers that loads data to the device with write() fpga_manager_ops
callback, since write() can be called in iterator over scatter-gather
table, not only linear image buffer. On the other hand, write_sg()
callback is provided with whole image in scatter-gather form and can
decide itself which part should be sent to the device.
Add header_size and data_size to the fpga_image_info struct, add
skip_header to the fpga_manager_ops struct and adjust fpga_mgr_write()
callers with respect to them.
* info->header_size indicates part at the beginning of image buffer
that contains some meta info. It is optional and can be 0,
initialized with mops->initial_header_size.
* mops->skip_header tells fpga-mgr core whether write should start
from the beginning of image buffer or at the offset of header_size.
* info->data_size is the size of bitstream data that is meant to be
written to the device. It is also optional and can be 0, which
means bitstream data is up to the end of image buffer.
Also add parse_header() callback to fpga_manager_ops, which purpose is
to set info->header_size and info->data_size. At least
initial_header_size bytes of image buffer will be passed into
parse_header() first time. If it is not enough, parse_header() should
set desired size into info->header_size and return -EAGAIN, then it will
be called again with greater part of image buffer on the input.
Suggested-by: Xu Yilun <yilun.xu@intel.com>
Signed-off-by: Ivan Bornyakov <i.bornyakov@metrotek.ru>
Acked-by: Xu Yilun <yilun.xu@intel.com>
Link: https://lore.kernel.org/r/20220623163248.3672-2-i.bornyakov@metrotek.ru
Signed-off-by: Xu Yilun <yilun.xu@intel.com>
2022-06-23 16:32:44 +00:00
|
|
|
/* Short path. Low level driver don't care about image header. */
|
|
|
|
if (!mgr->mops->initial_header_size && !mgr->mops->parse_header)
|
2017-02-01 19:48:44 +00:00
|
|
|
return fpga_mgr_write_init_buf(mgr, info, NULL, 0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* First try to use miter to map the first fragment to access the
|
|
|
|
* header, this is the typical path.
|
|
|
|
*/
|
fpga: fpga-mgr: support bitstream offset in image buffer
At the moment FPGA manager core loads to the device entire image
provided to fpga_mgr_load(). But it is not always whole FPGA image
buffer meant to be written to the device. In particular, .dat formatted
image for Microchip MPF contains meta info in the header that is not
meant to be written to the device. This is issue for those low level
drivers that loads data to the device with write() fpga_manager_ops
callback, since write() can be called in iterator over scatter-gather
table, not only linear image buffer. On the other hand, write_sg()
callback is provided with whole image in scatter-gather form and can
decide itself which part should be sent to the device.
Add header_size and data_size to the fpga_image_info struct, add
skip_header to the fpga_manager_ops struct and adjust fpga_mgr_write()
callers with respect to them.
* info->header_size indicates part at the beginning of image buffer
that contains some meta info. It is optional and can be 0,
initialized with mops->initial_header_size.
* mops->skip_header tells fpga-mgr core whether write should start
from the beginning of image buffer or at the offset of header_size.
* info->data_size is the size of bitstream data that is meant to be
written to the device. It is also optional and can be 0, which
means bitstream data is up to the end of image buffer.
Also add parse_header() callback to fpga_manager_ops, which purpose is
to set info->header_size and info->data_size. At least
initial_header_size bytes of image buffer will be passed into
parse_header() first time. If it is not enough, parse_header() should
set desired size into info->header_size and return -EAGAIN, then it will
be called again with greater part of image buffer on the input.
Suggested-by: Xu Yilun <yilun.xu@intel.com>
Signed-off-by: Ivan Bornyakov <i.bornyakov@metrotek.ru>
Acked-by: Xu Yilun <yilun.xu@intel.com>
Link: https://lore.kernel.org/r/20220623163248.3672-2-i.bornyakov@metrotek.ru
Signed-off-by: Xu Yilun <yilun.xu@intel.com>
2022-06-23 16:32:44 +00:00
|
|
|
ret = fpga_mgr_parse_header_sg_first(mgr, info, sgt);
|
|
|
|
/* If 0, header fits first fragment, call write_init on it */
|
|
|
|
if (!ret) {
|
|
|
|
sg_miter_start(&miter, sgt->sgl, sgt->nents, SG_MITER_FROM_SG);
|
|
|
|
if (sg_miter_next(&miter)) {
|
|
|
|
ret = fpga_mgr_write_init_buf(mgr, info, miter.addr,
|
|
|
|
miter.length);
|
|
|
|
sg_miter_stop(&miter);
|
|
|
|
return ret;
|
|
|
|
}
|
2017-02-01 19:48:44 +00:00
|
|
|
sg_miter_stop(&miter);
|
fpga: fpga-mgr: support bitstream offset in image buffer
At the moment FPGA manager core loads to the device entire image
provided to fpga_mgr_load(). But it is not always whole FPGA image
buffer meant to be written to the device. In particular, .dat formatted
image for Microchip MPF contains meta info in the header that is not
meant to be written to the device. This is issue for those low level
drivers that loads data to the device with write() fpga_manager_ops
callback, since write() can be called in iterator over scatter-gather
table, not only linear image buffer. On the other hand, write_sg()
callback is provided with whole image in scatter-gather form and can
decide itself which part should be sent to the device.
Add header_size and data_size to the fpga_image_info struct, add
skip_header to the fpga_manager_ops struct and adjust fpga_mgr_write()
callers with respect to them.
* info->header_size indicates part at the beginning of image buffer
that contains some meta info. It is optional and can be 0,
initialized with mops->initial_header_size.
* mops->skip_header tells fpga-mgr core whether write should start
from the beginning of image buffer or at the offset of header_size.
* info->data_size is the size of bitstream data that is meant to be
written to the device. It is also optional and can be 0, which
means bitstream data is up to the end of image buffer.
Also add parse_header() callback to fpga_manager_ops, which purpose is
to set info->header_size and info->data_size. At least
initial_header_size bytes of image buffer will be passed into
parse_header() first time. If it is not enough, parse_header() should
set desired size into info->header_size and return -EAGAIN, then it will
be called again with greater part of image buffer on the input.
Suggested-by: Xu Yilun <yilun.xu@intel.com>
Signed-off-by: Ivan Bornyakov <i.bornyakov@metrotek.ru>
Acked-by: Xu Yilun <yilun.xu@intel.com>
Link: https://lore.kernel.org/r/20220623163248.3672-2-i.bornyakov@metrotek.ru
Signed-off-by: Xu Yilun <yilun.xu@intel.com>
2022-06-23 16:32:44 +00:00
|
|
|
/*
|
|
|
|
* If -EAGAIN, more sg buffer is needed,
|
|
|
|
* otherwise an error has occurred.
|
|
|
|
*/
|
|
|
|
} else if (ret != -EAGAIN) {
|
2017-02-01 19:48:44 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
fpga: fpga-mgr: support bitstream offset in image buffer
At the moment FPGA manager core loads to the device entire image
provided to fpga_mgr_load(). But it is not always whole FPGA image
buffer meant to be written to the device. In particular, .dat formatted
image for Microchip MPF contains meta info in the header that is not
meant to be written to the device. This is issue for those low level
drivers that loads data to the device with write() fpga_manager_ops
callback, since write() can be called in iterator over scatter-gather
table, not only linear image buffer. On the other hand, write_sg()
callback is provided with whole image in scatter-gather form and can
decide itself which part should be sent to the device.
Add header_size and data_size to the fpga_image_info struct, add
skip_header to the fpga_manager_ops struct and adjust fpga_mgr_write()
callers with respect to them.
* info->header_size indicates part at the beginning of image buffer
that contains some meta info. It is optional and can be 0,
initialized with mops->initial_header_size.
* mops->skip_header tells fpga-mgr core whether write should start
from the beginning of image buffer or at the offset of header_size.
* info->data_size is the size of bitstream data that is meant to be
written to the device. It is also optional and can be 0, which
means bitstream data is up to the end of image buffer.
Also add parse_header() callback to fpga_manager_ops, which purpose is
to set info->header_size and info->data_size. At least
initial_header_size bytes of image buffer will be passed into
parse_header() first time. If it is not enough, parse_header() should
set desired size into info->header_size and return -EAGAIN, then it will
be called again with greater part of image buffer on the input.
Suggested-by: Xu Yilun <yilun.xu@intel.com>
Signed-off-by: Ivan Bornyakov <i.bornyakov@metrotek.ru>
Acked-by: Xu Yilun <yilun.xu@intel.com>
Link: https://lore.kernel.org/r/20220623163248.3672-2-i.bornyakov@metrotek.ru
Signed-off-by: Xu Yilun <yilun.xu@intel.com>
2022-06-23 16:32:44 +00:00
|
|
|
/*
|
|
|
|
* Copy the fragments into temporary memory.
|
|
|
|
* Copying is done inside fpga_mgr_parse_header_sg().
|
|
|
|
*/
|
|
|
|
buf = fpga_mgr_parse_header_sg(mgr, info, sgt, &len);
|
|
|
|
if (IS_ERR(buf))
|
|
|
|
return PTR_ERR(buf);
|
2017-02-01 19:48:44 +00:00
|
|
|
|
|
|
|
ret = fpga_mgr_write_init_buf(mgr, info, buf, len);
|
|
|
|
|
|
|
|
kfree(buf);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-10-07 15:36:28 +00:00
|
|
|
/**
|
2017-02-01 19:48:44 +00:00
|
|
|
* fpga_mgr_buf_load_sg - load fpga from image in buffer from a scatter list
|
2015-10-07 15:36:28 +00:00
|
|
|
* @mgr: fpga manager
|
2016-11-01 19:14:26 +00:00
|
|
|
* @info: fpga image specific information
|
2017-02-01 19:48:44 +00:00
|
|
|
* @sgt: scatterlist table
|
2015-10-07 15:36:28 +00:00
|
|
|
*
|
|
|
|
* Step the low level fpga manager through the device-specific steps of getting
|
|
|
|
* an FPGA ready to be configured, writing the image to it, then doing whatever
|
2015-10-22 17:38:38 +00:00
|
|
|
* post-configuration steps necessary. This code assumes the caller got the
|
2016-11-01 19:14:23 +00:00
|
|
|
* mgr pointer from of_fpga_mgr_get() or fpga_mgr_get() and checked that it is
|
|
|
|
* not an error code.
|
2015-10-07 15:36:28 +00:00
|
|
|
*
|
2017-02-01 19:48:44 +00:00
|
|
|
* This is the preferred entry point for FPGA programming, it does not require
|
|
|
|
* any contiguous kernel memory.
|
|
|
|
*
|
2015-10-07 15:36:28 +00:00
|
|
|
* Return: 0 on success, negative error code otherwise.
|
|
|
|
*/
|
2017-11-15 20:20:12 +00:00
|
|
|
static int fpga_mgr_buf_load_sg(struct fpga_manager *mgr,
|
|
|
|
struct fpga_image_info *info,
|
|
|
|
struct sg_table *sgt)
|
2015-10-07 15:36:28 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
fpga: fpga-mgr: support bitstream offset in image buffer
At the moment FPGA manager core loads to the device entire image
provided to fpga_mgr_load(). But it is not always whole FPGA image
buffer meant to be written to the device. In particular, .dat formatted
image for Microchip MPF contains meta info in the header that is not
meant to be written to the device. This is issue for those low level
drivers that loads data to the device with write() fpga_manager_ops
callback, since write() can be called in iterator over scatter-gather
table, not only linear image buffer. On the other hand, write_sg()
callback is provided with whole image in scatter-gather form and can
decide itself which part should be sent to the device.
Add header_size and data_size to the fpga_image_info struct, add
skip_header to the fpga_manager_ops struct and adjust fpga_mgr_write()
callers with respect to them.
* info->header_size indicates part at the beginning of image buffer
that contains some meta info. It is optional and can be 0,
initialized with mops->initial_header_size.
* mops->skip_header tells fpga-mgr core whether write should start
from the beginning of image buffer or at the offset of header_size.
* info->data_size is the size of bitstream data that is meant to be
written to the device. It is also optional and can be 0, which
means bitstream data is up to the end of image buffer.
Also add parse_header() callback to fpga_manager_ops, which purpose is
to set info->header_size and info->data_size. At least
initial_header_size bytes of image buffer will be passed into
parse_header() first time. If it is not enough, parse_header() should
set desired size into info->header_size and return -EAGAIN, then it will
be called again with greater part of image buffer on the input.
Suggested-by: Xu Yilun <yilun.xu@intel.com>
Signed-off-by: Ivan Bornyakov <i.bornyakov@metrotek.ru>
Acked-by: Xu Yilun <yilun.xu@intel.com>
Link: https://lore.kernel.org/r/20220623163248.3672-2-i.bornyakov@metrotek.ru
Signed-off-by: Xu Yilun <yilun.xu@intel.com>
2022-06-23 16:32:44 +00:00
|
|
|
ret = fpga_mgr_prepare_sg(mgr, info, sgt);
|
2017-02-01 19:48:44 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* Write the FPGA image to the FPGA. */
|
|
|
|
mgr->state = FPGA_MGR_STATE_WRITE;
|
|
|
|
if (mgr->mops->write_sg) {
|
2021-06-25 19:51:48 +00:00
|
|
|
ret = fpga_mgr_write_sg(mgr, sgt);
|
2017-02-01 19:48:44 +00:00
|
|
|
} else {
|
fpga: fpga-mgr: support bitstream offset in image buffer
At the moment FPGA manager core loads to the device entire image
provided to fpga_mgr_load(). But it is not always whole FPGA image
buffer meant to be written to the device. In particular, .dat formatted
image for Microchip MPF contains meta info in the header that is not
meant to be written to the device. This is issue for those low level
drivers that loads data to the device with write() fpga_manager_ops
callback, since write() can be called in iterator over scatter-gather
table, not only linear image buffer. On the other hand, write_sg()
callback is provided with whole image in scatter-gather form and can
decide itself which part should be sent to the device.
Add header_size and data_size to the fpga_image_info struct, add
skip_header to the fpga_manager_ops struct and adjust fpga_mgr_write()
callers with respect to them.
* info->header_size indicates part at the beginning of image buffer
that contains some meta info. It is optional and can be 0,
initialized with mops->initial_header_size.
* mops->skip_header tells fpga-mgr core whether write should start
from the beginning of image buffer or at the offset of header_size.
* info->data_size is the size of bitstream data that is meant to be
written to the device. It is also optional and can be 0, which
means bitstream data is up to the end of image buffer.
Also add parse_header() callback to fpga_manager_ops, which purpose is
to set info->header_size and info->data_size. At least
initial_header_size bytes of image buffer will be passed into
parse_header() first time. If it is not enough, parse_header() should
set desired size into info->header_size and return -EAGAIN, then it will
be called again with greater part of image buffer on the input.
Suggested-by: Xu Yilun <yilun.xu@intel.com>
Signed-off-by: Ivan Bornyakov <i.bornyakov@metrotek.ru>
Acked-by: Xu Yilun <yilun.xu@intel.com>
Link: https://lore.kernel.org/r/20220623163248.3672-2-i.bornyakov@metrotek.ru
Signed-off-by: Xu Yilun <yilun.xu@intel.com>
2022-06-23 16:32:44 +00:00
|
|
|
size_t length, count = 0, data_size = info->data_size;
|
2017-02-01 19:48:44 +00:00
|
|
|
struct sg_mapping_iter miter;
|
|
|
|
|
|
|
|
sg_miter_start(&miter, sgt->sgl, sgt->nents, SG_MITER_FROM_SG);
|
fpga: fpga-mgr: support bitstream offset in image buffer
At the moment FPGA manager core loads to the device entire image
provided to fpga_mgr_load(). But it is not always whole FPGA image
buffer meant to be written to the device. In particular, .dat formatted
image for Microchip MPF contains meta info in the header that is not
meant to be written to the device. This is issue for those low level
drivers that loads data to the device with write() fpga_manager_ops
callback, since write() can be called in iterator over scatter-gather
table, not only linear image buffer. On the other hand, write_sg()
callback is provided with whole image in scatter-gather form and can
decide itself which part should be sent to the device.
Add header_size and data_size to the fpga_image_info struct, add
skip_header to the fpga_manager_ops struct and adjust fpga_mgr_write()
callers with respect to them.
* info->header_size indicates part at the beginning of image buffer
that contains some meta info. It is optional and can be 0,
initialized with mops->initial_header_size.
* mops->skip_header tells fpga-mgr core whether write should start
from the beginning of image buffer or at the offset of header_size.
* info->data_size is the size of bitstream data that is meant to be
written to the device. It is also optional and can be 0, which
means bitstream data is up to the end of image buffer.
Also add parse_header() callback to fpga_manager_ops, which purpose is
to set info->header_size and info->data_size. At least
initial_header_size bytes of image buffer will be passed into
parse_header() first time. If it is not enough, parse_header() should
set desired size into info->header_size and return -EAGAIN, then it will
be called again with greater part of image buffer on the input.
Suggested-by: Xu Yilun <yilun.xu@intel.com>
Signed-off-by: Ivan Bornyakov <i.bornyakov@metrotek.ru>
Acked-by: Xu Yilun <yilun.xu@intel.com>
Link: https://lore.kernel.org/r/20220623163248.3672-2-i.bornyakov@metrotek.ru
Signed-off-by: Xu Yilun <yilun.xu@intel.com>
2022-06-23 16:32:44 +00:00
|
|
|
|
|
|
|
if (mgr->mops->skip_header &&
|
|
|
|
!sg_miter_skip(&miter, info->header_size)) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2017-02-01 19:48:44 +00:00
|
|
|
while (sg_miter_next(&miter)) {
|
fpga: fpga-mgr: support bitstream offset in image buffer
At the moment FPGA manager core loads to the device entire image
provided to fpga_mgr_load(). But it is not always whole FPGA image
buffer meant to be written to the device. In particular, .dat formatted
image for Microchip MPF contains meta info in the header that is not
meant to be written to the device. This is issue for those low level
drivers that loads data to the device with write() fpga_manager_ops
callback, since write() can be called in iterator over scatter-gather
table, not only linear image buffer. On the other hand, write_sg()
callback is provided with whole image in scatter-gather form and can
decide itself which part should be sent to the device.
Add header_size and data_size to the fpga_image_info struct, add
skip_header to the fpga_manager_ops struct and adjust fpga_mgr_write()
callers with respect to them.
* info->header_size indicates part at the beginning of image buffer
that contains some meta info. It is optional and can be 0,
initialized with mops->initial_header_size.
* mops->skip_header tells fpga-mgr core whether write should start
from the beginning of image buffer or at the offset of header_size.
* info->data_size is the size of bitstream data that is meant to be
written to the device. It is also optional and can be 0, which
means bitstream data is up to the end of image buffer.
Also add parse_header() callback to fpga_manager_ops, which purpose is
to set info->header_size and info->data_size. At least
initial_header_size bytes of image buffer will be passed into
parse_header() first time. If it is not enough, parse_header() should
set desired size into info->header_size and return -EAGAIN, then it will
be called again with greater part of image buffer on the input.
Suggested-by: Xu Yilun <yilun.xu@intel.com>
Signed-off-by: Ivan Bornyakov <i.bornyakov@metrotek.ru>
Acked-by: Xu Yilun <yilun.xu@intel.com>
Link: https://lore.kernel.org/r/20220623163248.3672-2-i.bornyakov@metrotek.ru
Signed-off-by: Xu Yilun <yilun.xu@intel.com>
2022-06-23 16:32:44 +00:00
|
|
|
if (data_size)
|
|
|
|
length = min(miter.length, data_size - count);
|
|
|
|
else
|
|
|
|
length = miter.length;
|
|
|
|
|
|
|
|
ret = fpga_mgr_write(mgr, miter.addr, length);
|
2017-02-01 19:48:44 +00:00
|
|
|
if (ret)
|
|
|
|
break;
|
fpga: fpga-mgr: support bitstream offset in image buffer
At the moment FPGA manager core loads to the device entire image
provided to fpga_mgr_load(). But it is not always whole FPGA image
buffer meant to be written to the device. In particular, .dat formatted
image for Microchip MPF contains meta info in the header that is not
meant to be written to the device. This is issue for those low level
drivers that loads data to the device with write() fpga_manager_ops
callback, since write() can be called in iterator over scatter-gather
table, not only linear image buffer. On the other hand, write_sg()
callback is provided with whole image in scatter-gather form and can
decide itself which part should be sent to the device.
Add header_size and data_size to the fpga_image_info struct, add
skip_header to the fpga_manager_ops struct and adjust fpga_mgr_write()
callers with respect to them.
* info->header_size indicates part at the beginning of image buffer
that contains some meta info. It is optional and can be 0,
initialized with mops->initial_header_size.
* mops->skip_header tells fpga-mgr core whether write should start
from the beginning of image buffer or at the offset of header_size.
* info->data_size is the size of bitstream data that is meant to be
written to the device. It is also optional and can be 0, which
means bitstream data is up to the end of image buffer.
Also add parse_header() callback to fpga_manager_ops, which purpose is
to set info->header_size and info->data_size. At least
initial_header_size bytes of image buffer will be passed into
parse_header() first time. If it is not enough, parse_header() should
set desired size into info->header_size and return -EAGAIN, then it will
be called again with greater part of image buffer on the input.
Suggested-by: Xu Yilun <yilun.xu@intel.com>
Signed-off-by: Ivan Bornyakov <i.bornyakov@metrotek.ru>
Acked-by: Xu Yilun <yilun.xu@intel.com>
Link: https://lore.kernel.org/r/20220623163248.3672-2-i.bornyakov@metrotek.ru
Signed-off-by: Xu Yilun <yilun.xu@intel.com>
2022-06-23 16:32:44 +00:00
|
|
|
|
|
|
|
count += length;
|
|
|
|
if (data_size && count >= data_size)
|
|
|
|
break;
|
2017-02-01 19:48:44 +00:00
|
|
|
}
|
|
|
|
sg_miter_stop(&miter);
|
|
|
|
}
|
|
|
|
|
fpga: fpga-mgr: support bitstream offset in image buffer
At the moment FPGA manager core loads to the device entire image
provided to fpga_mgr_load(). But it is not always whole FPGA image
buffer meant to be written to the device. In particular, .dat formatted
image for Microchip MPF contains meta info in the header that is not
meant to be written to the device. This is issue for those low level
drivers that loads data to the device with write() fpga_manager_ops
callback, since write() can be called in iterator over scatter-gather
table, not only linear image buffer. On the other hand, write_sg()
callback is provided with whole image in scatter-gather form and can
decide itself which part should be sent to the device.
Add header_size and data_size to the fpga_image_info struct, add
skip_header to the fpga_manager_ops struct and adjust fpga_mgr_write()
callers with respect to them.
* info->header_size indicates part at the beginning of image buffer
that contains some meta info. It is optional and can be 0,
initialized with mops->initial_header_size.
* mops->skip_header tells fpga-mgr core whether write should start
from the beginning of image buffer or at the offset of header_size.
* info->data_size is the size of bitstream data that is meant to be
written to the device. It is also optional and can be 0, which
means bitstream data is up to the end of image buffer.
Also add parse_header() callback to fpga_manager_ops, which purpose is
to set info->header_size and info->data_size. At least
initial_header_size bytes of image buffer will be passed into
parse_header() first time. If it is not enough, parse_header() should
set desired size into info->header_size and return -EAGAIN, then it will
be called again with greater part of image buffer on the input.
Suggested-by: Xu Yilun <yilun.xu@intel.com>
Signed-off-by: Ivan Bornyakov <i.bornyakov@metrotek.ru>
Acked-by: Xu Yilun <yilun.xu@intel.com>
Link: https://lore.kernel.org/r/20220623163248.3672-2-i.bornyakov@metrotek.ru
Signed-off-by: Xu Yilun <yilun.xu@intel.com>
2022-06-23 16:32:44 +00:00
|
|
|
out:
|
2015-10-07 15:36:28 +00:00
|
|
|
if (ret) {
|
2017-02-01 19:48:44 +00:00
|
|
|
dev_err(&mgr->dev, "Error while writing image data to FPGA\n");
|
|
|
|
mgr->state = FPGA_MGR_STATE_WRITE_ERR;
|
2015-10-07 15:36:28 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-02-01 19:48:44 +00:00
|
|
|
return fpga_mgr_write_complete(mgr, info);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int fpga_mgr_buf_load_mapped(struct fpga_manager *mgr,
|
|
|
|
struct fpga_image_info *info,
|
|
|
|
const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
fpga: fpga-mgr: support bitstream offset in image buffer
At the moment FPGA manager core loads to the device entire image
provided to fpga_mgr_load(). But it is not always whole FPGA image
buffer meant to be written to the device. In particular, .dat formatted
image for Microchip MPF contains meta info in the header that is not
meant to be written to the device. This is issue for those low level
drivers that loads data to the device with write() fpga_manager_ops
callback, since write() can be called in iterator over scatter-gather
table, not only linear image buffer. On the other hand, write_sg()
callback is provided with whole image in scatter-gather form and can
decide itself which part should be sent to the device.
Add header_size and data_size to the fpga_image_info struct, add
skip_header to the fpga_manager_ops struct and adjust fpga_mgr_write()
callers with respect to them.
* info->header_size indicates part at the beginning of image buffer
that contains some meta info. It is optional and can be 0,
initialized with mops->initial_header_size.
* mops->skip_header tells fpga-mgr core whether write should start
from the beginning of image buffer or at the offset of header_size.
* info->data_size is the size of bitstream data that is meant to be
written to the device. It is also optional and can be 0, which
means bitstream data is up to the end of image buffer.
Also add parse_header() callback to fpga_manager_ops, which purpose is
to set info->header_size and info->data_size. At least
initial_header_size bytes of image buffer will be passed into
parse_header() first time. If it is not enough, parse_header() should
set desired size into info->header_size and return -EAGAIN, then it will
be called again with greater part of image buffer on the input.
Suggested-by: Xu Yilun <yilun.xu@intel.com>
Signed-off-by: Ivan Bornyakov <i.bornyakov@metrotek.ru>
Acked-by: Xu Yilun <yilun.xu@intel.com>
Link: https://lore.kernel.org/r/20220623163248.3672-2-i.bornyakov@metrotek.ru
Signed-off-by: Xu Yilun <yilun.xu@intel.com>
2022-06-23 16:32:44 +00:00
|
|
|
ret = fpga_mgr_parse_header_mapped(mgr, info, buf, count);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2017-02-01 19:48:44 +00:00
|
|
|
ret = fpga_mgr_write_init_buf(mgr, info, buf, count);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
fpga: fpga-mgr: support bitstream offset in image buffer
At the moment FPGA manager core loads to the device entire image
provided to fpga_mgr_load(). But it is not always whole FPGA image
buffer meant to be written to the device. In particular, .dat formatted
image for Microchip MPF contains meta info in the header that is not
meant to be written to the device. This is issue for those low level
drivers that loads data to the device with write() fpga_manager_ops
callback, since write() can be called in iterator over scatter-gather
table, not only linear image buffer. On the other hand, write_sg()
callback is provided with whole image in scatter-gather form and can
decide itself which part should be sent to the device.
Add header_size and data_size to the fpga_image_info struct, add
skip_header to the fpga_manager_ops struct and adjust fpga_mgr_write()
callers with respect to them.
* info->header_size indicates part at the beginning of image buffer
that contains some meta info. It is optional and can be 0,
initialized with mops->initial_header_size.
* mops->skip_header tells fpga-mgr core whether write should start
from the beginning of image buffer or at the offset of header_size.
* info->data_size is the size of bitstream data that is meant to be
written to the device. It is also optional and can be 0, which
means bitstream data is up to the end of image buffer.
Also add parse_header() callback to fpga_manager_ops, which purpose is
to set info->header_size and info->data_size. At least
initial_header_size bytes of image buffer will be passed into
parse_header() first time. If it is not enough, parse_header() should
set desired size into info->header_size and return -EAGAIN, then it will
be called again with greater part of image buffer on the input.
Suggested-by: Xu Yilun <yilun.xu@intel.com>
Signed-off-by: Ivan Bornyakov <i.bornyakov@metrotek.ru>
Acked-by: Xu Yilun <yilun.xu@intel.com>
Link: https://lore.kernel.org/r/20220623163248.3672-2-i.bornyakov@metrotek.ru
Signed-off-by: Xu Yilun <yilun.xu@intel.com>
2022-06-23 16:32:44 +00:00
|
|
|
if (mgr->mops->skip_header) {
|
|
|
|
buf += info->header_size;
|
|
|
|
count -= info->header_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info->data_size)
|
|
|
|
count = info->data_size;
|
|
|
|
|
2015-10-07 15:36:28 +00:00
|
|
|
/*
|
|
|
|
* Write the FPGA image to the FPGA.
|
|
|
|
*/
|
|
|
|
mgr->state = FPGA_MGR_STATE_WRITE;
|
2021-06-25 19:51:44 +00:00
|
|
|
ret = fpga_mgr_write(mgr, buf, count);
|
2015-10-07 15:36:28 +00:00
|
|
|
if (ret) {
|
2017-02-01 19:48:44 +00:00
|
|
|
dev_err(&mgr->dev, "Error while writing image data to FPGA\n");
|
2015-10-07 15:36:28 +00:00
|
|
|
mgr->state = FPGA_MGR_STATE_WRITE_ERR;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-02-01 19:48:44 +00:00
|
|
|
return fpga_mgr_write_complete(mgr, info);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* fpga_mgr_buf_load - load fpga from image in buffer
|
|
|
|
* @mgr: fpga manager
|
2018-05-16 23:49:59 +00:00
|
|
|
* @info: fpga image info
|
2017-02-01 19:48:44 +00:00
|
|
|
* @buf: buffer contain fpga image
|
|
|
|
* @count: byte count of buf
|
|
|
|
*
|
|
|
|
* Step the low level fpga manager through the device-specific steps of getting
|
|
|
|
* an FPGA ready to be configured, writing the image to it, then doing whatever
|
|
|
|
* post-configuration steps necessary. This code assumes the caller got the
|
|
|
|
* mgr pointer from of_fpga_mgr_get() and checked that it is not an error code.
|
|
|
|
*
|
|
|
|
* Return: 0 on success, negative error code otherwise.
|
|
|
|
*/
|
2017-11-15 20:20:12 +00:00
|
|
|
static int fpga_mgr_buf_load(struct fpga_manager *mgr,
|
|
|
|
struct fpga_image_info *info,
|
|
|
|
const char *buf, size_t count)
|
2017-02-01 19:48:44 +00:00
|
|
|
{
|
|
|
|
struct page **pages;
|
|
|
|
struct sg_table sgt;
|
|
|
|
const void *p;
|
|
|
|
int nr_pages;
|
|
|
|
int index;
|
|
|
|
int rc;
|
|
|
|
|
2015-10-07 15:36:28 +00:00
|
|
|
/*
|
2017-02-01 19:48:44 +00:00
|
|
|
* This is just a fast path if the caller has already created a
|
|
|
|
* contiguous kernel buffer and the driver doesn't require SG, non-SG
|
|
|
|
* drivers will still work on the slow path.
|
2015-10-07 15:36:28 +00:00
|
|
|
*/
|
2017-02-01 19:48:44 +00:00
|
|
|
if (mgr->mops->write)
|
|
|
|
return fpga_mgr_buf_load_mapped(mgr, info, buf, count);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert the linear kernel pointer into a sg_table of pages for use
|
|
|
|
* by the driver.
|
|
|
|
*/
|
|
|
|
nr_pages = DIV_ROUND_UP((unsigned long)buf + count, PAGE_SIZE) -
|
|
|
|
(unsigned long)buf / PAGE_SIZE;
|
|
|
|
pages = kmalloc_array(nr_pages, sizeof(struct page *), GFP_KERNEL);
|
|
|
|
if (!pages)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
p = buf - offset_in_page(buf);
|
|
|
|
for (index = 0; index < nr_pages; index++) {
|
|
|
|
if (is_vmalloc_addr(p))
|
|
|
|
pages[index] = vmalloc_to_page(p);
|
|
|
|
else
|
|
|
|
pages[index] = kmap_to_page((void *)p);
|
|
|
|
if (!pages[index]) {
|
|
|
|
kfree(pages);
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
p += PAGE_SIZE;
|
2015-10-07 15:36:28 +00:00
|
|
|
}
|
|
|
|
|
2017-02-01 19:48:44 +00:00
|
|
|
/*
|
|
|
|
* The temporary pages list is used to code share the merging algorithm
|
|
|
|
* in sg_alloc_table_from_pages
|
|
|
|
*/
|
|
|
|
rc = sg_alloc_table_from_pages(&sgt, pages, index, offset_in_page(buf),
|
|
|
|
count, GFP_KERNEL);
|
|
|
|
kfree(pages);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
rc = fpga_mgr_buf_load_sg(mgr, info, &sgt);
|
|
|
|
sg_free_table(&sgt);
|
|
|
|
|
|
|
|
return rc;
|
2015-10-07 15:36:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* fpga_mgr_firmware_load - request firmware and load to fpga
|
|
|
|
* @mgr: fpga manager
|
2016-11-01 19:14:26 +00:00
|
|
|
* @info: fpga image specific information
|
2015-10-07 15:36:28 +00:00
|
|
|
* @image_name: name of image file on the firmware search path
|
|
|
|
*
|
|
|
|
* Request an FPGA image using the firmware class, then write out to the FPGA.
|
|
|
|
* Update the state before each step to provide info on what step failed if
|
2015-10-22 17:38:38 +00:00
|
|
|
* there is a failure. This code assumes the caller got the mgr pointer
|
2016-11-01 19:14:23 +00:00
|
|
|
* from of_fpga_mgr_get() or fpga_mgr_get() and checked that it is not an error
|
|
|
|
* code.
|
2015-10-07 15:36:28 +00:00
|
|
|
*
|
|
|
|
* Return: 0 on success, negative error code otherwise.
|
|
|
|
*/
|
2017-11-15 20:20:12 +00:00
|
|
|
static int fpga_mgr_firmware_load(struct fpga_manager *mgr,
|
|
|
|
struct fpga_image_info *info,
|
|
|
|
const char *image_name)
|
2015-10-07 15:36:28 +00:00
|
|
|
{
|
|
|
|
struct device *dev = &mgr->dev;
|
|
|
|
const struct firmware *fw;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
dev_info(dev, "writing %s to %s\n", image_name, mgr->name);
|
|
|
|
|
|
|
|
mgr->state = FPGA_MGR_STATE_FIRMWARE_REQ;
|
|
|
|
|
|
|
|
ret = request_firmware(&fw, image_name, dev);
|
|
|
|
if (ret) {
|
|
|
|
mgr->state = FPGA_MGR_STATE_FIRMWARE_REQ_ERR;
|
|
|
|
dev_err(dev, "Error requesting firmware %s\n", image_name);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-11-01 19:14:26 +00:00
|
|
|
ret = fpga_mgr_buf_load(mgr, info, fw->data, fw->size);
|
2015-10-07 15:36:28 +00:00
|
|
|
|
|
|
|
release_firmware(fw);
|
|
|
|
|
2015-11-18 09:48:16 +00:00
|
|
|
return ret;
|
2015-10-07 15:36:28 +00:00
|
|
|
}
|
2017-11-15 20:20:12 +00:00
|
|
|
|
2018-05-16 23:49:59 +00:00
|
|
|
/**
|
|
|
|
* fpga_mgr_load - load FPGA from scatter/gather table, buffer, or firmware
|
|
|
|
* @mgr: fpga manager
|
|
|
|
* @info: fpga image information.
|
|
|
|
*
|
|
|
|
* Load the FPGA from an image which is indicated in @info. If successful, the
|
|
|
|
* FPGA ends up in operating mode.
|
|
|
|
*
|
|
|
|
* Return: 0 on success, negative error code otherwise.
|
|
|
|
*/
|
2017-11-15 20:20:12 +00:00
|
|
|
int fpga_mgr_load(struct fpga_manager *mgr, struct fpga_image_info *info)
|
|
|
|
{
|
fpga: fpga-mgr: support bitstream offset in image buffer
At the moment FPGA manager core loads to the device entire image
provided to fpga_mgr_load(). But it is not always whole FPGA image
buffer meant to be written to the device. In particular, .dat formatted
image for Microchip MPF contains meta info in the header that is not
meant to be written to the device. This is issue for those low level
drivers that loads data to the device with write() fpga_manager_ops
callback, since write() can be called in iterator over scatter-gather
table, not only linear image buffer. On the other hand, write_sg()
callback is provided with whole image in scatter-gather form and can
decide itself which part should be sent to the device.
Add header_size and data_size to the fpga_image_info struct, add
skip_header to the fpga_manager_ops struct and adjust fpga_mgr_write()
callers with respect to them.
* info->header_size indicates part at the beginning of image buffer
that contains some meta info. It is optional and can be 0,
initialized with mops->initial_header_size.
* mops->skip_header tells fpga-mgr core whether write should start
from the beginning of image buffer or at the offset of header_size.
* info->data_size is the size of bitstream data that is meant to be
written to the device. It is also optional and can be 0, which
means bitstream data is up to the end of image buffer.
Also add parse_header() callback to fpga_manager_ops, which purpose is
to set info->header_size and info->data_size. At least
initial_header_size bytes of image buffer will be passed into
parse_header() first time. If it is not enough, parse_header() should
set desired size into info->header_size and return -EAGAIN, then it will
be called again with greater part of image buffer on the input.
Suggested-by: Xu Yilun <yilun.xu@intel.com>
Signed-off-by: Ivan Bornyakov <i.bornyakov@metrotek.ru>
Acked-by: Xu Yilun <yilun.xu@intel.com>
Link: https://lore.kernel.org/r/20220623163248.3672-2-i.bornyakov@metrotek.ru
Signed-off-by: Xu Yilun <yilun.xu@intel.com>
2022-06-23 16:32:44 +00:00
|
|
|
info->header_size = mgr->mops->initial_header_size;
|
|
|
|
|
2017-11-15 20:20:12 +00:00
|
|
|
if (info->sgt)
|
|
|
|
return fpga_mgr_buf_load_sg(mgr, info, info->sgt);
|
|
|
|
if (info->buf && info->count)
|
|
|
|
return fpga_mgr_buf_load(mgr, info, info->buf, info->count);
|
|
|
|
if (info->firmware_name)
|
|
|
|
return fpga_mgr_firmware_load(mgr, info, info->firmware_name);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(fpga_mgr_load);
|
2015-10-07 15:36:28 +00:00
|
|
|
|
|
|
|
static const char * const state_str[] = {
|
|
|
|
[FPGA_MGR_STATE_UNKNOWN] = "unknown",
|
|
|
|
[FPGA_MGR_STATE_POWER_OFF] = "power off",
|
|
|
|
[FPGA_MGR_STATE_POWER_UP] = "power up",
|
|
|
|
[FPGA_MGR_STATE_RESET] = "reset",
|
|
|
|
|
|
|
|
/* requesting FPGA image from firmware */
|
|
|
|
[FPGA_MGR_STATE_FIRMWARE_REQ] = "firmware request",
|
|
|
|
[FPGA_MGR_STATE_FIRMWARE_REQ_ERR] = "firmware request error",
|
|
|
|
|
fpga: fpga-mgr: support bitstream offset in image buffer
At the moment FPGA manager core loads to the device entire image
provided to fpga_mgr_load(). But it is not always whole FPGA image
buffer meant to be written to the device. In particular, .dat formatted
image for Microchip MPF contains meta info in the header that is not
meant to be written to the device. This is issue for those low level
drivers that loads data to the device with write() fpga_manager_ops
callback, since write() can be called in iterator over scatter-gather
table, not only linear image buffer. On the other hand, write_sg()
callback is provided with whole image in scatter-gather form and can
decide itself which part should be sent to the device.
Add header_size and data_size to the fpga_image_info struct, add
skip_header to the fpga_manager_ops struct and adjust fpga_mgr_write()
callers with respect to them.
* info->header_size indicates part at the beginning of image buffer
that contains some meta info. It is optional and can be 0,
initialized with mops->initial_header_size.
* mops->skip_header tells fpga-mgr core whether write should start
from the beginning of image buffer or at the offset of header_size.
* info->data_size is the size of bitstream data that is meant to be
written to the device. It is also optional and can be 0, which
means bitstream data is up to the end of image buffer.
Also add parse_header() callback to fpga_manager_ops, which purpose is
to set info->header_size and info->data_size. At least
initial_header_size bytes of image buffer will be passed into
parse_header() first time. If it is not enough, parse_header() should
set desired size into info->header_size and return -EAGAIN, then it will
be called again with greater part of image buffer on the input.
Suggested-by: Xu Yilun <yilun.xu@intel.com>
Signed-off-by: Ivan Bornyakov <i.bornyakov@metrotek.ru>
Acked-by: Xu Yilun <yilun.xu@intel.com>
Link: https://lore.kernel.org/r/20220623163248.3672-2-i.bornyakov@metrotek.ru
Signed-off-by: Xu Yilun <yilun.xu@intel.com>
2022-06-23 16:32:44 +00:00
|
|
|
/* Parse FPGA image header */
|
|
|
|
[FPGA_MGR_STATE_PARSE_HEADER] = "parse header",
|
|
|
|
[FPGA_MGR_STATE_PARSE_HEADER_ERR] = "parse header error",
|
|
|
|
|
2015-10-07 15:36:28 +00:00
|
|
|
/* Preparing FPGA to receive image */
|
|
|
|
[FPGA_MGR_STATE_WRITE_INIT] = "write init",
|
|
|
|
[FPGA_MGR_STATE_WRITE_INIT_ERR] = "write init error",
|
|
|
|
|
|
|
|
/* Writing image to FPGA */
|
|
|
|
[FPGA_MGR_STATE_WRITE] = "write",
|
|
|
|
[FPGA_MGR_STATE_WRITE_ERR] = "write error",
|
|
|
|
|
|
|
|
/* Finishing configuration after image has been written */
|
|
|
|
[FPGA_MGR_STATE_WRITE_COMPLETE] = "write complete",
|
|
|
|
[FPGA_MGR_STATE_WRITE_COMPLETE_ERR] = "write complete error",
|
|
|
|
|
|
|
|
/* FPGA reports to be in normal operating mode */
|
|
|
|
[FPGA_MGR_STATE_OPERATING] = "operating",
|
|
|
|
};
|
|
|
|
|
|
|
|
static ssize_t name_show(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
struct fpga_manager *mgr = to_fpga_manager(dev);
|
|
|
|
|
|
|
|
return sprintf(buf, "%s\n", mgr->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t state_show(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
struct fpga_manager *mgr = to_fpga_manager(dev);
|
|
|
|
|
|
|
|
return sprintf(buf, "%s\n", state_str[mgr->state]);
|
|
|
|
}
|
|
|
|
|
2018-06-30 00:53:10 +00:00
|
|
|
static ssize_t status_show(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
struct fpga_manager *mgr = to_fpga_manager(dev);
|
|
|
|
u64 status;
|
|
|
|
int len = 0;
|
|
|
|
|
2021-06-25 19:51:45 +00:00
|
|
|
status = fpga_mgr_status(mgr);
|
2018-06-30 00:53:10 +00:00
|
|
|
|
|
|
|
if (status & FPGA_MGR_STATUS_OPERATION_ERR)
|
|
|
|
len += sprintf(buf + len, "reconfig operation error\n");
|
|
|
|
if (status & FPGA_MGR_STATUS_CRC_ERR)
|
|
|
|
len += sprintf(buf + len, "reconfig CRC error\n");
|
|
|
|
if (status & FPGA_MGR_STATUS_INCOMPATIBLE_IMAGE_ERR)
|
|
|
|
len += sprintf(buf + len, "reconfig incompatible image\n");
|
|
|
|
if (status & FPGA_MGR_STATUS_IP_PROTOCOL_ERR)
|
|
|
|
len += sprintf(buf + len, "reconfig IP protocol error\n");
|
|
|
|
if (status & FPGA_MGR_STATUS_FIFO_OVERFLOW_ERR)
|
|
|
|
len += sprintf(buf + len, "reconfig fifo overflow error\n");
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2015-10-07 15:36:28 +00:00
|
|
|
static DEVICE_ATTR_RO(name);
|
|
|
|
static DEVICE_ATTR_RO(state);
|
2018-06-30 00:53:10 +00:00
|
|
|
static DEVICE_ATTR_RO(status);
|
2015-10-07 15:36:28 +00:00
|
|
|
|
|
|
|
static struct attribute *fpga_mgr_attrs[] = {
|
|
|
|
&dev_attr_name.attr,
|
|
|
|
&dev_attr_state.attr,
|
2018-06-30 00:53:10 +00:00
|
|
|
&dev_attr_status.attr,
|
2015-10-07 15:36:28 +00:00
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
ATTRIBUTE_GROUPS(fpga_mgr);
|
|
|
|
|
2024-03-05 19:29:26 +00:00
|
|
|
static struct fpga_manager *__fpga_mgr_get(struct device *mgr_dev)
|
2015-10-07 15:36:28 +00:00
|
|
|
{
|
|
|
|
struct fpga_manager *mgr;
|
|
|
|
|
2024-03-05 19:29:26 +00:00
|
|
|
mgr = to_fpga_manager(mgr_dev);
|
2015-10-07 15:36:28 +00:00
|
|
|
|
2024-03-05 19:29:26 +00:00
|
|
|
if (!try_module_get(mgr->mops_owner))
|
|
|
|
mgr = ERR_PTR(-ENODEV);
|
2015-10-22 17:38:37 +00:00
|
|
|
|
2015-10-07 15:36:28 +00:00
|
|
|
return mgr;
|
|
|
|
}
|
2016-11-01 19:14:23 +00:00
|
|
|
|
|
|
|
static int fpga_mgr_dev_match(struct device *dev, const void *data)
|
|
|
|
{
|
|
|
|
return dev->parent == data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-06-08 21:23:46 +00:00
|
|
|
* fpga_mgr_get - Given a device, get a reference to an fpga mgr.
|
2016-11-01 19:14:23 +00:00
|
|
|
* @dev: parent device that fpga mgr was registered with
|
|
|
|
*
|
|
|
|
* Return: fpga manager struct or IS_ERR() condition containing error code.
|
|
|
|
*/
|
|
|
|
struct fpga_manager *fpga_mgr_get(struct device *dev)
|
|
|
|
{
|
2024-03-05 19:29:26 +00:00
|
|
|
struct fpga_manager *mgr;
|
|
|
|
struct device *mgr_dev;
|
|
|
|
|
|
|
|
mgr_dev = class_find_device(&fpga_mgr_class, NULL, dev, fpga_mgr_dev_match);
|
2016-11-01 19:14:23 +00:00
|
|
|
if (!mgr_dev)
|
|
|
|
return ERR_PTR(-ENODEV);
|
|
|
|
|
2024-03-05 19:29:26 +00:00
|
|
|
mgr = __fpga_mgr_get(mgr_dev);
|
|
|
|
if (IS_ERR(mgr))
|
|
|
|
put_device(mgr_dev);
|
|
|
|
|
|
|
|
return mgr;
|
2016-11-01 19:14:23 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(fpga_mgr_get);
|
|
|
|
|
|
|
|
/**
|
2021-06-08 21:23:46 +00:00
|
|
|
* of_fpga_mgr_get - Given a device node, get a reference to an fpga mgr.
|
2016-11-01 19:14:23 +00:00
|
|
|
*
|
2018-05-16 23:49:59 +00:00
|
|
|
* @node: device node
|
2016-11-01 19:14:23 +00:00
|
|
|
*
|
|
|
|
* Return: fpga manager struct or IS_ERR() condition containing error code.
|
|
|
|
*/
|
|
|
|
struct fpga_manager *of_fpga_mgr_get(struct device_node *node)
|
|
|
|
{
|
2024-03-05 19:29:26 +00:00
|
|
|
struct fpga_manager *mgr;
|
|
|
|
struct device *mgr_dev;
|
2016-11-01 19:14:23 +00:00
|
|
|
|
2024-03-05 19:29:26 +00:00
|
|
|
mgr_dev = class_find_device_by_of_node(&fpga_mgr_class, node);
|
|
|
|
if (!mgr_dev)
|
2016-11-01 19:14:23 +00:00
|
|
|
return ERR_PTR(-ENODEV);
|
|
|
|
|
2024-03-05 19:29:26 +00:00
|
|
|
mgr = __fpga_mgr_get(mgr_dev);
|
|
|
|
if (IS_ERR(mgr))
|
|
|
|
put_device(mgr_dev);
|
|
|
|
|
|
|
|
return mgr;
|
2016-11-01 19:14:23 +00:00
|
|
|
}
|
2015-10-07 15:36:28 +00:00
|
|
|
EXPORT_SYMBOL_GPL(of_fpga_mgr_get);
|
|
|
|
|
|
|
|
/**
|
2021-06-08 21:23:46 +00:00
|
|
|
* fpga_mgr_put - release a reference to an fpga manager
|
2015-10-07 15:36:28 +00:00
|
|
|
* @mgr: fpga manager structure
|
|
|
|
*/
|
|
|
|
void fpga_mgr_put(struct fpga_manager *mgr)
|
|
|
|
{
|
2024-03-05 19:29:26 +00:00
|
|
|
module_put(mgr->mops_owner);
|
2015-10-22 17:38:37 +00:00
|
|
|
put_device(&mgr->dev);
|
2015-10-07 15:36:28 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(fpga_mgr_put);
|
|
|
|
|
2017-11-15 20:20:13 +00:00
|
|
|
/**
|
|
|
|
* fpga_mgr_lock - Lock FPGA manager for exclusive use
|
|
|
|
* @mgr: fpga manager
|
|
|
|
*
|
|
|
|
* Given a pointer to FPGA Manager (from fpga_mgr_get() or
|
2018-05-16 23:49:59 +00:00
|
|
|
* of_fpga_mgr_put()) attempt to get the mutex. The user should call
|
|
|
|
* fpga_mgr_lock() and verify that it returns 0 before attempting to
|
|
|
|
* program the FPGA. Likewise, the user should call fpga_mgr_unlock
|
|
|
|
* when done programming the FPGA.
|
2017-11-15 20:20:13 +00:00
|
|
|
*
|
|
|
|
* Return: 0 for success or -EBUSY
|
|
|
|
*/
|
|
|
|
int fpga_mgr_lock(struct fpga_manager *mgr)
|
|
|
|
{
|
|
|
|
if (!mutex_trylock(&mgr->ref_mutex)) {
|
|
|
|
dev_err(&mgr->dev, "FPGA manager is in use.\n");
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(fpga_mgr_lock);
|
|
|
|
|
|
|
|
/**
|
2018-05-16 23:49:59 +00:00
|
|
|
* fpga_mgr_unlock - Unlock FPGA manager after done programming
|
2017-11-15 20:20:13 +00:00
|
|
|
* @mgr: fpga manager
|
|
|
|
*/
|
|
|
|
void fpga_mgr_unlock(struct fpga_manager *mgr)
|
|
|
|
{
|
|
|
|
mutex_unlock(&mgr->ref_mutex);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(fpga_mgr_unlock);
|
|
|
|
|
2015-10-07 15:36:28 +00:00
|
|
|
/**
|
2024-03-05 19:29:26 +00:00
|
|
|
* __fpga_mgr_register_full - create and register an FPGA Manager device
|
2021-06-14 17:09:04 +00:00
|
|
|
* @parent: fpga manager device from pdev
|
2021-11-19 01:55:51 +00:00
|
|
|
* @info: parameters for fpga manager
|
2024-03-05 19:29:26 +00:00
|
|
|
* @owner: owner module containing the ops
|
2015-10-07 15:36:28 +00:00
|
|
|
*
|
2021-11-19 01:55:51 +00:00
|
|
|
* The caller of this function is responsible for calling fpga_mgr_unregister().
|
|
|
|
* Using devm_fpga_mgr_register_full() instead is recommended.
|
2018-10-15 22:20:01 +00:00
|
|
|
*
|
2021-11-19 01:55:51 +00:00
|
|
|
* Return: pointer to struct fpga_manager pointer or ERR_PTR()
|
2015-10-07 15:36:28 +00:00
|
|
|
*/
|
2021-11-19 01:55:51 +00:00
|
|
|
struct fpga_manager *
|
2024-03-05 19:29:26 +00:00
|
|
|
__fpga_mgr_register_full(struct device *parent, const struct fpga_manager_info *info,
|
|
|
|
struct module *owner)
|
2015-10-07 15:36:28 +00:00
|
|
|
{
|
2021-11-19 01:55:51 +00:00
|
|
|
const struct fpga_manager_ops *mops = info->mops;
|
2015-10-07 15:36:28 +00:00
|
|
|
struct fpga_manager *mgr;
|
|
|
|
int id, ret;
|
|
|
|
|
2021-06-25 19:51:46 +00:00
|
|
|
if (!mops) {
|
2021-06-14 17:09:04 +00:00
|
|
|
dev_err(parent, "Attempt to register without fpga_manager_ops\n");
|
2021-11-19 01:55:51 +00:00
|
|
|
return ERR_PTR(-EINVAL);
|
2015-10-07 15:36:28 +00:00
|
|
|
}
|
|
|
|
|
2021-11-19 01:55:51 +00:00
|
|
|
if (!info->name || !strlen(info->name)) {
|
2021-06-14 17:09:04 +00:00
|
|
|
dev_err(parent, "Attempt to register with no name!\n");
|
2021-11-19 01:55:51 +00:00
|
|
|
return ERR_PTR(-EINVAL);
|
2015-10-07 15:36:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mgr = kzalloc(sizeof(*mgr), GFP_KERNEL);
|
|
|
|
if (!mgr)
|
2021-11-19 01:55:51 +00:00
|
|
|
return ERR_PTR(-ENOMEM);
|
2015-10-07 15:36:28 +00:00
|
|
|
|
2022-05-27 08:59:15 +00:00
|
|
|
id = ida_alloc(&fpga_mgr_ida, GFP_KERNEL);
|
2021-11-19 01:55:51 +00:00
|
|
|
if (id < 0) {
|
|
|
|
ret = id;
|
2015-10-07 15:36:28 +00:00
|
|
|
goto error_kfree;
|
2021-11-19 01:55:51 +00:00
|
|
|
}
|
2015-10-07 15:36:28 +00:00
|
|
|
|
|
|
|
mutex_init(&mgr->ref_mutex);
|
|
|
|
|
2024-03-05 19:29:26 +00:00
|
|
|
mgr->mops_owner = owner;
|
|
|
|
|
2021-11-19 01:55:51 +00:00
|
|
|
mgr->name = info->name;
|
|
|
|
mgr->mops = info->mops;
|
|
|
|
mgr->priv = info->priv;
|
|
|
|
mgr->compat_id = info->compat_id;
|
2015-10-07 15:36:28 +00:00
|
|
|
|
2023-08-11 07:30:42 +00:00
|
|
|
mgr->dev.class = &fpga_mgr_class;
|
2017-11-15 20:20:28 +00:00
|
|
|
mgr->dev.groups = mops->groups;
|
2021-06-14 17:09:04 +00:00
|
|
|
mgr->dev.parent = parent;
|
|
|
|
mgr->dev.of_node = parent->of_node;
|
2015-10-07 15:36:28 +00:00
|
|
|
mgr->dev.id = id;
|
|
|
|
|
2015-10-29 19:39:56 +00:00
|
|
|
ret = dev_set_name(&mgr->dev, "fpga%d", id);
|
|
|
|
if (ret)
|
|
|
|
goto error_device;
|
2015-10-07 15:36:28 +00:00
|
|
|
|
2021-11-19 01:55:51 +00:00
|
|
|
/*
|
|
|
|
* Initialize framework state by requesting low level driver read state
|
|
|
|
* from device. FPGA may be in reset mode or may have been programmed
|
|
|
|
* by bootloader or EEPROM.
|
|
|
|
*/
|
|
|
|
mgr->state = fpga_mgr_state(mgr);
|
|
|
|
|
|
|
|
ret = device_register(&mgr->dev);
|
|
|
|
if (ret) {
|
|
|
|
put_device(&mgr->dev);
|
|
|
|
return ERR_PTR(ret);
|
|
|
|
}
|
|
|
|
|
2018-05-16 23:49:55 +00:00
|
|
|
return mgr;
|
|
|
|
|
|
|
|
error_device:
|
2022-05-27 08:59:15 +00:00
|
|
|
ida_free(&fpga_mgr_ida, id);
|
2018-05-16 23:49:55 +00:00
|
|
|
error_kfree:
|
|
|
|
kfree(mgr);
|
|
|
|
|
2021-11-19 01:55:51 +00:00
|
|
|
return ERR_PTR(ret);
|
2018-05-16 23:49:55 +00:00
|
|
|
}
|
2024-03-05 19:29:26 +00:00
|
|
|
EXPORT_SYMBOL_GPL(__fpga_mgr_register_full);
|
2018-05-16 23:49:55 +00:00
|
|
|
|
|
|
|
/**
|
2024-03-05 19:29:26 +00:00
|
|
|
* __fpga_mgr_register - create and register an FPGA Manager device
|
2021-06-14 17:09:04 +00:00
|
|
|
* @parent: fpga manager device from pdev
|
2018-10-15 22:20:01 +00:00
|
|
|
* @name: fpga manager name
|
|
|
|
* @mops: pointer to structure of fpga manager ops
|
|
|
|
* @priv: fpga manager private data
|
2024-03-05 19:29:26 +00:00
|
|
|
* @owner: owner module containing the ops
|
2018-10-15 22:20:01 +00:00
|
|
|
*
|
2021-11-19 01:55:51 +00:00
|
|
|
* The caller of this function is responsible for calling fpga_mgr_unregister().
|
|
|
|
* Using devm_fpga_mgr_register() instead is recommended. This simple
|
|
|
|
* version of the register function should be sufficient for most users. The
|
|
|
|
* fpga_mgr_register_full() function is available for users that need to pass
|
|
|
|
* additional, optional parameters.
|
2018-10-15 22:20:01 +00:00
|
|
|
*
|
2021-11-19 01:55:51 +00:00
|
|
|
* Return: pointer to struct fpga_manager pointer or ERR_PTR()
|
2018-10-15 22:20:01 +00:00
|
|
|
*/
|
2021-11-19 01:55:51 +00:00
|
|
|
struct fpga_manager *
|
2024-03-05 19:29:26 +00:00
|
|
|
__fpga_mgr_register(struct device *parent, const char *name,
|
|
|
|
const struct fpga_manager_ops *mops, void *priv, struct module *owner)
|
2018-10-15 22:20:01 +00:00
|
|
|
{
|
2021-11-19 01:55:51 +00:00
|
|
|
struct fpga_manager_info info = { 0 };
|
2018-10-15 22:20:01 +00:00
|
|
|
|
2021-11-19 01:55:51 +00:00
|
|
|
info.name = name;
|
|
|
|
info.mops = mops;
|
|
|
|
info.priv = priv;
|
2018-10-15 22:20:01 +00:00
|
|
|
|
2024-03-05 19:29:26 +00:00
|
|
|
return __fpga_mgr_register_full(parent, &info, owner);
|
2015-10-07 15:36:28 +00:00
|
|
|
}
|
2024-03-05 19:29:26 +00:00
|
|
|
EXPORT_SYMBOL_GPL(__fpga_mgr_register);
|
2015-10-07 15:36:28 +00:00
|
|
|
|
|
|
|
/**
|
2021-06-08 21:23:46 +00:00
|
|
|
* fpga_mgr_unregister - unregister an FPGA manager
|
2018-10-15 22:20:01 +00:00
|
|
|
* @mgr: fpga manager struct
|
|
|
|
*
|
2021-06-08 21:23:46 +00:00
|
|
|
* This function is intended for use in an FPGA manager driver's remove function.
|
2015-10-07 15:36:28 +00:00
|
|
|
*/
|
2018-05-16 23:49:55 +00:00
|
|
|
void fpga_mgr_unregister(struct fpga_manager *mgr)
|
2015-10-07 15:36:28 +00:00
|
|
|
{
|
|
|
|
dev_info(&mgr->dev, "%s %s\n", __func__, mgr->name);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the low level driver provides a method for putting fpga into
|
|
|
|
* a desired state upon unregister, do it.
|
|
|
|
*/
|
2021-06-25 19:51:47 +00:00
|
|
|
fpga_mgr_fpga_remove(mgr);
|
2015-10-07 15:36:28 +00:00
|
|
|
|
|
|
|
device_unregister(&mgr->dev);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(fpga_mgr_unregister);
|
|
|
|
|
2020-11-15 19:51:18 +00:00
|
|
|
static void devm_fpga_mgr_unregister(struct device *dev, void *res)
|
|
|
|
{
|
|
|
|
struct fpga_mgr_devres *dr = res;
|
|
|
|
|
|
|
|
fpga_mgr_unregister(dr->mgr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-03-05 19:29:26 +00:00
|
|
|
* __devm_fpga_mgr_register_full - resource managed variant of fpga_mgr_register()
|
2021-11-19 01:55:51 +00:00
|
|
|
* @parent: fpga manager device from pdev
|
|
|
|
* @info: parameters for fpga manager
|
2024-03-05 19:29:26 +00:00
|
|
|
* @owner: owner module containing the ops
|
2020-11-15 19:51:18 +00:00
|
|
|
*
|
2022-04-23 17:02:33 +00:00
|
|
|
* Return: fpga manager pointer on success, negative error code otherwise.
|
|
|
|
*
|
2021-11-19 01:55:51 +00:00
|
|
|
* This is the devres variant of fpga_mgr_register_full() for which the unregister
|
2020-11-15 19:51:18 +00:00
|
|
|
* function will be called automatically when the managing device is detached.
|
|
|
|
*/
|
2021-11-19 01:55:51 +00:00
|
|
|
struct fpga_manager *
|
2024-03-05 19:29:26 +00:00
|
|
|
__devm_fpga_mgr_register_full(struct device *parent, const struct fpga_manager_info *info,
|
|
|
|
struct module *owner)
|
2020-11-15 19:51:18 +00:00
|
|
|
{
|
|
|
|
struct fpga_mgr_devres *dr;
|
2021-11-19 01:55:51 +00:00
|
|
|
struct fpga_manager *mgr;
|
2020-11-15 19:51:18 +00:00
|
|
|
|
|
|
|
dr = devres_alloc(devm_fpga_mgr_unregister, sizeof(*dr), GFP_KERNEL);
|
|
|
|
if (!dr)
|
2021-11-19 01:55:51 +00:00
|
|
|
return ERR_PTR(-ENOMEM);
|
2020-11-15 19:51:18 +00:00
|
|
|
|
2024-03-05 19:29:26 +00:00
|
|
|
mgr = __fpga_mgr_register_full(parent, info, owner);
|
2021-11-19 01:55:51 +00:00
|
|
|
if (IS_ERR(mgr)) {
|
2020-11-15 19:51:18 +00:00
|
|
|
devres_free(dr);
|
2021-11-19 01:55:51 +00:00
|
|
|
return mgr;
|
2020-11-15 19:51:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dr->mgr = mgr;
|
2021-11-19 01:55:51 +00:00
|
|
|
devres_add(parent, dr);
|
2020-11-15 19:51:18 +00:00
|
|
|
|
2021-11-19 01:55:51 +00:00
|
|
|
return mgr;
|
|
|
|
}
|
2024-03-05 19:29:26 +00:00
|
|
|
EXPORT_SYMBOL_GPL(__devm_fpga_mgr_register_full);
|
2021-11-19 01:55:51 +00:00
|
|
|
|
|
|
|
/**
|
2024-03-05 19:29:26 +00:00
|
|
|
* __devm_fpga_mgr_register - resource managed variant of fpga_mgr_register()
|
2021-11-19 01:55:51 +00:00
|
|
|
* @parent: fpga manager device from pdev
|
|
|
|
* @name: fpga manager name
|
|
|
|
* @mops: pointer to structure of fpga manager ops
|
|
|
|
* @priv: fpga manager private data
|
2024-03-05 19:29:26 +00:00
|
|
|
* @owner: owner module containing the ops
|
2021-11-19 01:55:51 +00:00
|
|
|
*
|
2022-04-23 17:02:33 +00:00
|
|
|
* Return: fpga manager pointer on success, negative error code otherwise.
|
|
|
|
*
|
2021-11-19 01:55:51 +00:00
|
|
|
* This is the devres variant of fpga_mgr_register() for which the
|
|
|
|
* unregister function will be called automatically when the managing
|
|
|
|
* device is detached.
|
|
|
|
*/
|
|
|
|
struct fpga_manager *
|
2024-03-05 19:29:26 +00:00
|
|
|
__devm_fpga_mgr_register(struct device *parent, const char *name,
|
|
|
|
const struct fpga_manager_ops *mops, void *priv,
|
|
|
|
struct module *owner)
|
2021-11-19 01:55:51 +00:00
|
|
|
{
|
|
|
|
struct fpga_manager_info info = { 0 };
|
|
|
|
|
|
|
|
info.name = name;
|
|
|
|
info.mops = mops;
|
|
|
|
info.priv = priv;
|
|
|
|
|
2024-03-05 19:29:26 +00:00
|
|
|
return __devm_fpga_mgr_register_full(parent, &info, owner);
|
2020-11-15 19:51:18 +00:00
|
|
|
}
|
2024-03-05 19:29:26 +00:00
|
|
|
EXPORT_SYMBOL_GPL(__devm_fpga_mgr_register);
|
2020-11-15 19:51:18 +00:00
|
|
|
|
2015-10-07 15:36:28 +00:00
|
|
|
static void fpga_mgr_dev_release(struct device *dev)
|
|
|
|
{
|
2021-11-19 01:55:51 +00:00
|
|
|
struct fpga_manager *mgr = to_fpga_manager(dev);
|
|
|
|
|
2022-05-27 08:59:15 +00:00
|
|
|
ida_free(&fpga_mgr_ida, mgr->dev.id);
|
2021-11-19 01:55:51 +00:00
|
|
|
kfree(mgr);
|
2015-10-07 15:36:28 +00:00
|
|
|
}
|
|
|
|
|
2023-08-11 07:30:42 +00:00
|
|
|
static const struct class fpga_mgr_class = {
|
|
|
|
.name = "fpga_manager",
|
|
|
|
.dev_groups = fpga_mgr_groups,
|
|
|
|
.dev_release = fpga_mgr_dev_release,
|
|
|
|
};
|
|
|
|
|
2015-10-07 15:36:28 +00:00
|
|
|
static int __init fpga_mgr_class_init(void)
|
|
|
|
{
|
|
|
|
pr_info("FPGA manager framework\n");
|
|
|
|
|
2023-08-11 07:30:42 +00:00
|
|
|
return class_register(&fpga_mgr_class);
|
2015-10-07 15:36:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit fpga_mgr_class_exit(void)
|
|
|
|
{
|
2023-08-11 07:30:42 +00:00
|
|
|
class_unregister(&fpga_mgr_class);
|
2015-10-07 15:36:28 +00:00
|
|
|
ida_destroy(&fpga_mgr_ida);
|
|
|
|
}
|
|
|
|
|
2017-11-15 20:20:12 +00:00
|
|
|
MODULE_AUTHOR("Alan Tull <atull@kernel.org>");
|
2015-10-07 15:36:28 +00:00
|
|
|
MODULE_DESCRIPTION("FPGA manager framework");
|
|
|
|
MODULE_LICENSE("GPL v2");
|
|
|
|
|
|
|
|
subsys_initcall(fpga_mgr_class_init);
|
|
|
|
module_exit(fpga_mgr_class_exit);
|