Re: [PATCH V4 XRT Alveo 05/20] fpga: xrt: group platform driver
Hi Tom, On 3/30/21 5:52 AM, Tom Rix wrote: On 3/23/21 10:29 PM, Lizhi Hou wrote: group driver that manages life cycle of a bunch of leaf driver instances and bridges them with root. Signed-off-by: Sonal Santan Signed-off-by: Max Zhen Signed-off-by: Lizhi Hou --- drivers/fpga/xrt/include/group.h | 25 +++ drivers/fpga/xrt/lib/group.c | 286 +++ 2 files changed, 311 insertions(+) create mode 100644 drivers/fpga/xrt/include/group.h create mode 100644 drivers/fpga/xrt/lib/group.c diff --git a/drivers/fpga/xrt/include/group.h b/drivers/fpga/xrt/include/group.h new file mode 100644 index ..09e9d03f53fe --- /dev/null +++ b/drivers/fpga/xrt/include/group.h @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2020-2021 Xilinx, Inc. + * ok, removed generic boilerplate + * Authors: + * Cheng Zhen + */ + +#ifndef _XRT_GROUP_H_ +#define _XRT_GROUP_H_ + +#include "xleaf.h" move header to another patch Yes, the header is moved to 04/20 patch. + +/* + * Group driver leaf calls. ok + */ +enum xrt_group_leaf_cmd { + XRT_GROUP_GET_LEAF = XRT_XLEAF_CUSTOM_BASE, /* See comments in xleaf.h */ ok + XRT_GROUP_PUT_LEAF, + XRT_GROUP_INIT_CHILDREN, + XRT_GROUP_FINI_CHILDREN, + XRT_GROUP_TRIGGER_EVENT, +}; + +#endif /* _XRT_GROUP_H_ */ diff --git a/drivers/fpga/xrt/lib/group.c b/drivers/fpga/xrt/lib/group.c new file mode 100644 index ..7b8716569641 --- /dev/null +++ b/drivers/fpga/xrt/lib/group.c @@ -0,0 +1,286 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Xilinx Alveo FPGA Group Driver + * + * Copyright (C) 2020-2021 Xilinx, Inc. + * + * Authors: + * Cheng Zhen + */ + +#include +#include +#include "xleaf.h" +#include "subdev_pool.h" +#include "group.h" +#include "metadata.h" +#include "lib-drv.h" + +#define XRT_GRP "xrt_group" + +struct xrt_group { + struct platform_device *pdev; + struct xrt_subdev_pool leaves; + bool leaves_created; + struct mutex lock; /* lock for group */ +}; + +static int xrt_grp_root_cb(struct device *dev, void *parg, +enum xrt_root_cmd cmd, void *arg) ok +{ + int rc; + struct platform_device *pdev = + container_of(dev, struct platform_device, dev); + struct xrt_group *xg = (struct xrt_group *)parg; + + switch (cmd) { + case XRT_ROOT_GET_LEAF_HOLDERS: { + struct xrt_root_get_holders *holders = + (struct xrt_root_get_holders *)arg; + rc = xrt_subdev_pool_get_holders(&xg->leaves, + holders->xpigh_pdev, + holders->xpigh_holder_buf, + holders->xpigh_holder_buf_len); + break; + } + default: + /* Forward parent call to root. */ + rc = xrt_subdev_root_request(pdev, cmd, arg); + break; + } + + return rc; +} + +/* + * Cut subdev's dtb from group's dtb based on passed-in endpoint descriptor. + * Return the subdev's dtb through dtbp, if found. + */ +static int xrt_grp_cut_subdev_dtb(struct xrt_group *xg, struct xrt_subdev_endpoints *eps, + char *grp_dtb, char **dtbp) +{ + int ret, i, ep_count = 0; + char *dtb = NULL; + + ret = xrt_md_create(DEV(xg->pdev), &dtb); + if (ret) + return ret; + + for (i = 0; eps->xse_names[i].ep_name || eps->xse_names[i].regmap_name; i++) { + const char *ep_name = eps->xse_names[i].ep_name; + const char *reg_name = eps->xse_names[i].regmap_name; + + if (!ep_name) + xrt_md_get_compatible_endpoint(DEV(xg->pdev), grp_dtb, reg_name, &ep_name); + if (!ep_name) + continue; + + ret = xrt_md_copy_endpoint(DEV(xg->pdev), dtb, grp_dtb, ep_name, reg_name, NULL); + if (ret) + continue; + xrt_md_del_endpoint(DEV(xg->pdev), grp_dtb, ep_name, reg_name); + ep_count++; + } + /* Found enough endpoints, return the subdev's dtb. */ + if (ep_count >= eps->xse_min_ep) { + *dtbp = dtb; + return 0; + } + + /* Cleanup - Restore all endpoints that has been deleted, if any. */ + if (ep_count > 0) { + xrt_md_copy_endpoint(DEV(xg->pdev), grp_dtb, dtb, + XRT_MD_NODE_ENDPOINTS, NULL, NULL); + } + vfree(dtb); + *dtbp = NULL; + return 0; +} + +static int xrt_grp_create_leaves(struct xrt_group *xg) +{ + struct xrt_subdev_platdata *pdata = DEV_PDATA(xg->pdev); + struct xrt_subdev_endpoints *eps = NULL; + int ret = 0, failed = 0; + enum xrt_subdev_id did; + char *grp_dtb = NULL; + unsigned long mlen; + + if (!pdata) + return -EINVAL; ok + + mlen = xrt_md_size(DEV(xg->pdev), pdata->xsp_dtb); + if (
Re: [PATCH V4 XRT Alveo 05/20] fpga: xrt: group platform driver
On 3/23/21 10:29 PM, Lizhi Hou wrote: > group driver that manages life cycle of a bunch of leaf driver instances > and bridges them with root. > > Signed-off-by: Sonal Santan > Signed-off-by: Max Zhen > Signed-off-by: Lizhi Hou > --- > drivers/fpga/xrt/include/group.h | 25 +++ > drivers/fpga/xrt/lib/group.c | 286 +++ > 2 files changed, 311 insertions(+) > create mode 100644 drivers/fpga/xrt/include/group.h > create mode 100644 drivers/fpga/xrt/lib/group.c > > diff --git a/drivers/fpga/xrt/include/group.h > b/drivers/fpga/xrt/include/group.h > new file mode 100644 > index ..09e9d03f53fe > --- /dev/null > +++ b/drivers/fpga/xrt/include/group.h > @@ -0,0 +1,25 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +/* > + * Copyright (C) 2020-2021 Xilinx, Inc. > + * ok, removed generic boilerplate > + * Authors: > + * Cheng Zhen > + */ > + > +#ifndef _XRT_GROUP_H_ > +#define _XRT_GROUP_H_ > + > +#include "xleaf.h" move header to another patch > + > +/* > + * Group driver leaf calls. ok > + */ > +enum xrt_group_leaf_cmd { > + XRT_GROUP_GET_LEAF = XRT_XLEAF_CUSTOM_BASE, /* See comments in xleaf.h > */ ok > + XRT_GROUP_PUT_LEAF, > + XRT_GROUP_INIT_CHILDREN, > + XRT_GROUP_FINI_CHILDREN, > + XRT_GROUP_TRIGGER_EVENT, > +}; > + > +#endif /* _XRT_GROUP_H_ */ > diff --git a/drivers/fpga/xrt/lib/group.c b/drivers/fpga/xrt/lib/group.c > new file mode 100644 > index ..7b8716569641 > --- /dev/null > +++ b/drivers/fpga/xrt/lib/group.c > @@ -0,0 +1,286 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * Xilinx Alveo FPGA Group Driver > + * > + * Copyright (C) 2020-2021 Xilinx, Inc. > + * > + * Authors: > + * Cheng Zhen > + */ > + > +#include > +#include > +#include "xleaf.h" > +#include "subdev_pool.h" > +#include "group.h" > +#include "metadata.h" > +#include "lib-drv.h" > + > +#define XRT_GRP "xrt_group" > + > +struct xrt_group { > + struct platform_device *pdev; > + struct xrt_subdev_pool leaves; > + bool leaves_created; > + struct mutex lock; /* lock for group */ > +}; > + > +static int xrt_grp_root_cb(struct device *dev, void *parg, > +enum xrt_root_cmd cmd, void *arg) ok > +{ > + int rc; > + struct platform_device *pdev = > + container_of(dev, struct platform_device, dev); > + struct xrt_group *xg = (struct xrt_group *)parg; > + > + switch (cmd) { > + case XRT_ROOT_GET_LEAF_HOLDERS: { > + struct xrt_root_get_holders *holders = > + (struct xrt_root_get_holders *)arg; > + rc = xrt_subdev_pool_get_holders(&xg->leaves, > + holders->xpigh_pdev, > + holders->xpigh_holder_buf, > + holders->xpigh_holder_buf_len); > + break; > + } > + default: > + /* Forward parent call to root. */ > + rc = xrt_subdev_root_request(pdev, cmd, arg); > + break; > + } > + > + return rc; > +} > + > +/* > + * Cut subdev's dtb from group's dtb based on passed-in endpoint descriptor. > + * Return the subdev's dtb through dtbp, if found. > + */ > +static int xrt_grp_cut_subdev_dtb(struct xrt_group *xg, struct > xrt_subdev_endpoints *eps, > + char *grp_dtb, char **dtbp) > +{ > + int ret, i, ep_count = 0; > + char *dtb = NULL; > + > + ret = xrt_md_create(DEV(xg->pdev), &dtb); > + if (ret) > + return ret; > + > + for (i = 0; eps->xse_names[i].ep_name || eps->xse_names[i].regmap_name; > i++) { > + const char *ep_name = eps->xse_names[i].ep_name; > + const char *reg_name = eps->xse_names[i].regmap_name; > + > + if (!ep_name) > + xrt_md_get_compatible_endpoint(DEV(xg->pdev), grp_dtb, > reg_name, &ep_name); > + if (!ep_name) > + continue; > + > + ret = xrt_md_copy_endpoint(DEV(xg->pdev), dtb, grp_dtb, > ep_name, reg_name, NULL); > + if (ret) > + continue; > + xrt_md_del_endpoint(DEV(xg->pdev), grp_dtb, ep_name, reg_name); > + ep_count++; > + } > + /* Found enough endpoints, return the subdev's dtb. */ > + if (ep_count >= eps->xse_min_ep) { > + *dtbp = dtb; > + return 0; > + } > + > + /* Cleanup - Restore all endpoints that has been deleted, if any. */ > + if (ep_count > 0) { > + xrt_md_copy_endpoint(DEV(xg->pdev), grp_dtb, dtb, > + XRT_MD_NODE_ENDPOINTS, NULL, NULL); > + } > + vfree(dtb); > + *dtbp = NULL; > + return 0; > +} > + > +static int xrt_grp_create_leaves(struct xrt_group *xg) > +{ > + struct xrt_subdev_platdata *pdata = DEV_PDATA(xg->pdev); > + struct xrt_subdev_endpoints *eps = NULL; > + int ret = 0, failed
[PATCH V4 XRT Alveo 05/20] fpga: xrt: group platform driver
group driver that manages life cycle of a bunch of leaf driver instances and bridges them with root. Signed-off-by: Sonal Santan Signed-off-by: Max Zhen Signed-off-by: Lizhi Hou --- drivers/fpga/xrt/include/group.h | 25 +++ drivers/fpga/xrt/lib/group.c | 286 +++ 2 files changed, 311 insertions(+) create mode 100644 drivers/fpga/xrt/include/group.h create mode 100644 drivers/fpga/xrt/lib/group.c diff --git a/drivers/fpga/xrt/include/group.h b/drivers/fpga/xrt/include/group.h new file mode 100644 index ..09e9d03f53fe --- /dev/null +++ b/drivers/fpga/xrt/include/group.h @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2020-2021 Xilinx, Inc. + * + * Authors: + * Cheng Zhen + */ + +#ifndef _XRT_GROUP_H_ +#define _XRT_GROUP_H_ + +#include "xleaf.h" + +/* + * Group driver leaf calls. + */ +enum xrt_group_leaf_cmd { + XRT_GROUP_GET_LEAF = XRT_XLEAF_CUSTOM_BASE, /* See comments in xleaf.h */ + XRT_GROUP_PUT_LEAF, + XRT_GROUP_INIT_CHILDREN, + XRT_GROUP_FINI_CHILDREN, + XRT_GROUP_TRIGGER_EVENT, +}; + +#endif /* _XRT_GROUP_H_ */ diff --git a/drivers/fpga/xrt/lib/group.c b/drivers/fpga/xrt/lib/group.c new file mode 100644 index ..7b8716569641 --- /dev/null +++ b/drivers/fpga/xrt/lib/group.c @@ -0,0 +1,286 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Xilinx Alveo FPGA Group Driver + * + * Copyright (C) 2020-2021 Xilinx, Inc. + * + * Authors: + * Cheng Zhen + */ + +#include +#include +#include "xleaf.h" +#include "subdev_pool.h" +#include "group.h" +#include "metadata.h" +#include "lib-drv.h" + +#define XRT_GRP "xrt_group" + +struct xrt_group { + struct platform_device *pdev; + struct xrt_subdev_pool leaves; + bool leaves_created; + struct mutex lock; /* lock for group */ +}; + +static int xrt_grp_root_cb(struct device *dev, void *parg, + enum xrt_root_cmd cmd, void *arg) +{ + int rc; + struct platform_device *pdev = + container_of(dev, struct platform_device, dev); + struct xrt_group *xg = (struct xrt_group *)parg; + + switch (cmd) { + case XRT_ROOT_GET_LEAF_HOLDERS: { + struct xrt_root_get_holders *holders = + (struct xrt_root_get_holders *)arg; + rc = xrt_subdev_pool_get_holders(&xg->leaves, +holders->xpigh_pdev, +holders->xpigh_holder_buf, +holders->xpigh_holder_buf_len); + break; + } + default: + /* Forward parent call to root. */ + rc = xrt_subdev_root_request(pdev, cmd, arg); + break; + } + + return rc; +} + +/* + * Cut subdev's dtb from group's dtb based on passed-in endpoint descriptor. + * Return the subdev's dtb through dtbp, if found. + */ +static int xrt_grp_cut_subdev_dtb(struct xrt_group *xg, struct xrt_subdev_endpoints *eps, + char *grp_dtb, char **dtbp) +{ + int ret, i, ep_count = 0; + char *dtb = NULL; + + ret = xrt_md_create(DEV(xg->pdev), &dtb); + if (ret) + return ret; + + for (i = 0; eps->xse_names[i].ep_name || eps->xse_names[i].regmap_name; i++) { + const char *ep_name = eps->xse_names[i].ep_name; + const char *reg_name = eps->xse_names[i].regmap_name; + + if (!ep_name) + xrt_md_get_compatible_endpoint(DEV(xg->pdev), grp_dtb, reg_name, &ep_name); + if (!ep_name) + continue; + + ret = xrt_md_copy_endpoint(DEV(xg->pdev), dtb, grp_dtb, ep_name, reg_name, NULL); + if (ret) + continue; + xrt_md_del_endpoint(DEV(xg->pdev), grp_dtb, ep_name, reg_name); + ep_count++; + } + /* Found enough endpoints, return the subdev's dtb. */ + if (ep_count >= eps->xse_min_ep) { + *dtbp = dtb; + return 0; + } + + /* Cleanup - Restore all endpoints that has been deleted, if any. */ + if (ep_count > 0) { + xrt_md_copy_endpoint(DEV(xg->pdev), grp_dtb, dtb, +XRT_MD_NODE_ENDPOINTS, NULL, NULL); + } + vfree(dtb); + *dtbp = NULL; + return 0; +} + +static int xrt_grp_create_leaves(struct xrt_group *xg) +{ + struct xrt_subdev_platdata *pdata = DEV_PDATA(xg->pdev); + struct xrt_subdev_endpoints *eps = NULL; + int ret = 0, failed = 0; + enum xrt_subdev_id did; + char *grp_dtb = NULL; + unsigned long mlen; + + if (!pdata) + return -EINVAL; + + mlen = xrt_md_size(DEV(xg->pdev), pdata->xsp_dtb); + if (mlen == XRT_MD_INVALID_LENGTH) { + xrt_err(xg->pdev, "invalid dtb