get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/86503/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 86503,
    "url": "http://patches.dpdk.org/api/patches/86503/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/20210114061411.39166-6-chenbo.xia@intel.com/",
    "project": {
        "id": 1,
        "url": "http://patches.dpdk.org/api/projects/1/?format=api",
        "name": "DPDK",
        "link_name": "dpdk",
        "list_id": "dev.dpdk.org",
        "list_email": "dev@dpdk.org",
        "web_url": "http://core.dpdk.org",
        "scm_url": "git://dpdk.org/dpdk",
        "webscm_url": "http://git.dpdk.org/dpdk",
        "list_archive_url": "https://inbox.dpdk.org/dev",
        "list_archive_url_format": "https://inbox.dpdk.org/dev/{}",
        "commit_url_format": ""
    },
    "msgid": "<20210114061411.39166-6-chenbo.xia@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20210114061411.39166-6-chenbo.xia@intel.com",
    "date": "2021-01-14T06:14:07",
    "name": "[v2,5/9] vfio_user: implement interrupt related APIs",
    "commit_ref": null,
    "pull_url": null,
    "state": "changes-requested",
    "archived": true,
    "hash": "4c1a7e709658ded93fc190ba87628333a058116b",
    "submitter": {
        "id": 1276,
        "url": "http://patches.dpdk.org/api/people/1276/?format=api",
        "name": "Chenbo Xia",
        "email": "chenbo.xia@intel.com"
    },
    "delegate": {
        "id": 1,
        "url": "http://patches.dpdk.org/api/users/1/?format=api",
        "username": "tmonjalo",
        "first_name": "Thomas",
        "last_name": "Monjalon",
        "email": "thomas@monjalon.net"
    },
    "mbox": "http://patches.dpdk.org/project/dpdk/patch/20210114061411.39166-6-chenbo.xia@intel.com/mbox/",
    "series": [
        {
            "id": 14711,
            "url": "http://patches.dpdk.org/api/series/14711/?format=api",
            "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=14711",
            "date": "2021-01-14T06:14:02",
            "name": "Introduce vfio-user library",
            "version": 2,
            "mbox": "http://patches.dpdk.org/series/14711/mbox/"
        }
    ],
    "comments": "http://patches.dpdk.org/api/patches/86503/comments/",
    "check": "success",
    "checks": "http://patches.dpdk.org/api/patches/86503/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<dev-bounces@dpdk.org>",
        "X-Original-To": "patchwork@inbox.dpdk.org",
        "Delivered-To": "patchwork@inbox.dpdk.org",
        "Received": [
            "from mails.dpdk.org (mails.dpdk.org [217.70.189.124])\n\tby inbox.dpdk.org (Postfix) with ESMTP id 3CBDCA0A02;\n\tThu, 14 Jan 2021 07:20:19 +0100 (CET)",
            "from [217.70.189.124] (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id 47ED5140DCC;\n\tThu, 14 Jan 2021 07:19:49 +0100 (CET)",
            "from mga04.intel.com (mga04.intel.com [192.55.52.120])\n by mails.dpdk.org (Postfix) with ESMTP id 6ED50140DCB\n for <dev@dpdk.org>; Thu, 14 Jan 2021 07:19:47 +0100 (CET)",
            "from orsmga003.jf.intel.com ([10.7.209.27])\n by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;\n 13 Jan 2021 22:19:46 -0800",
            "from npg-dpdk-virtio-xiachenbo-nw.sh.intel.com ([10.67.119.123])\n by orsmga003.jf.intel.com with ESMTP; 13 Jan 2021 22:19:43 -0800"
        ],
        "IronPort-SDR": [
            "\n faJWJKFuXZul+OtVA5p41vHs40lHnhzpULsGhALUTCLdEqdYvpAPVyPHWcKVbv7FFAM8fS5/Je\n 6SOd1jp1g1Kw==",
            "\n C3+iIWYhI9JmwRWYEx5ra74z2bOc1B7O2jWXnloyXqjnvBjNiw5gADIEMm9JRegy0DEU4B6cEC\n 0D4cASCiGDQQ=="
        ],
        "X-IronPort-AV": [
            "E=McAfee;i=\"6000,8403,9863\"; a=\"175735649\"",
            "E=Sophos;i=\"5.79,346,1602572400\"; d=\"scan'208\";a=\"175735649\"",
            "E=Sophos;i=\"5.79,346,1602572400\"; d=\"scan'208\";a=\"349069001\""
        ],
        "X-ExtLoop1": "1",
        "From": "Chenbo Xia <chenbo.xia@intel.com>",
        "To": "dev@dpdk.org,\n\tthomas@monjalon.net,\n\tdavid.marchand@redhat.com",
        "Cc": "stephen@networkplumber.org, cunming.liang@intel.com, xiuchun.lu@intel.com,\n miao.li@intel.com, jingjing.wu@intel.com, beilei.xing@intel.com",
        "Date": "Thu, 14 Jan 2021 14:14:07 +0800",
        "Message-Id": "<20210114061411.39166-6-chenbo.xia@intel.com>",
        "X-Mailer": "git-send-email 2.17.1",
        "In-Reply-To": "<20210114061411.39166-1-chenbo.xia@intel.com>",
        "References": "<20201218073851.93609-1-chenbo.xia@intel.com>\n <20210114061411.39166-1-chenbo.xia@intel.com>",
        "Subject": "[dpdk-dev] [PATCH v2 5/9] vfio_user: implement interrupt related\n APIs",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.29",
        "Precedence": "list",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n <mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Archive": "<http://mails.dpdk.org/archives/dev/>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<https://mails.dpdk.org/listinfo/dev>,\n <mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>"
    },
    "content": "This patch implements two interrupt related APIs, which are\nrte_vfio_user_get_irq() and rte_vfio_user_set_irq_info().\nThe former is for devices to get interrupt configuration\n(e.g., irqfds). The latter is for setting interrupt information\nbefore vfio-user starts.\n\nSigned-off-by: Chenbo Xia <chenbo.xia@intel.com>\nSigned-off-by: Xiuchun Lu <xiuchun.lu@intel.com>\n---\n lib/librte_vfio_user/rte_vfio_user.h    |  46 ++++\n lib/librte_vfio_user/version.map        |   2 +\n lib/librte_vfio_user/vfio_user_base.h   |   8 +\n lib/librte_vfio_user/vfio_user_server.c | 300 +++++++++++++++++++++++-\n lib/librte_vfio_user/vfio_user_server.h |   6 +\n 5 files changed, 357 insertions(+), 5 deletions(-)",
    "diff": "diff --git a/lib/librte_vfio_user/rte_vfio_user.h b/lib/librte_vfio_user/rte_vfio_user.h\nindex f575017bdf..472ca15529 100644\n--- a/lib/librte_vfio_user/rte_vfio_user.h\n+++ b/lib/librte_vfio_user/rte_vfio_user.h\n@@ -69,6 +69,11 @@ struct rte_vfio_user_regions {\n \tstruct rte_vfio_user_reg_info reg_info[];\n };\n \n+struct rte_vfio_user_irq_info {\n+\tuint32_t irq_num;\n+\tstruct vfio_irq_info irq_info[];\n+};\n+\n /**\n  *  Below APIs are for vfio-user server (device provider) to use:\n  *\t*rte_vfio_user_register\n@@ -76,8 +81,10 @@ struct rte_vfio_user_regions {\n  *\t*rte_vfio_user_start\n  *\t*rte_vfio_get_sock_addr\n  *\t*rte_vfio_user_get_mem_table\n+ *\t*rte_vfio_user_get_irq\n  *\t*rte_vfio_user_set_dev_info\n  *\t*rte_vfio_user_set_reg_info\n+ *\t*rte_vfio_user_set_irq_info\n  */\n \n /**\n@@ -188,4 +195,43 @@ __rte_experimental\n int\n rte_vfio_get_sock_addr(int dev_id, char *buf, size_t len);\n \n+/**\n+ * Get the irqfds of a vfio-user device.\n+ *\n+ * @param dev_id\n+ *   Vfio-user device ID\n+ * @param index\n+ *   irq index\n+ * @param count\n+ *   irq count\n+ * @param[out] fds\n+ *   Pointer to the irqfds\n+ * @return\n+ *   0 on success, -1 on failure\n+ */\n+__rte_experimental\n+int\n+rte_vfio_user_get_irq(int dev_id, uint32_t index, uint32_t count,\n+\tint *fds);\n+\n+/**\n+ * Set the irq information for a vfio-user device.\n+ *\n+ * This information must be set before calling rte_vfio_user_start, and should\n+ * not be updated after start. Update after start can be done by unregistration\n+ * and re-registration, and then the device-level change can be detected by\n+ * vfio-user client.\n+ *\n+ * @param sock_addr\n+ *   Unix domain socket address\n+ * @param irq\n+ *   IRQ information for the vfio-user device\n+ * @return\n+ *   0 on success, -1 on failure\n+ */\n+__rte_experimental\n+int\n+rte_vfio_user_set_irq_info(const char *sock_addr,\n+\tstruct rte_vfio_user_irq_info *irq);\n+\n #endif\ndiff --git a/lib/librte_vfio_user/version.map b/lib/librte_vfio_user/version.map\nindex 3a50b5ef0e..621a51a9fc 100644\n--- a/lib/librte_vfio_user/version.map\n+++ b/lib/librte_vfio_user/version.map\n@@ -6,8 +6,10 @@ EXPERIMENTAL {\n \trte_vfio_user_start;\n \trte_vfio_get_sock_addr;\n \trte_vfio_user_get_mem_table;\n+\trte_vfio_user_get_irq;\n \trte_vfio_user_set_dev_info;\n \trte_vfio_user_set_reg_info;\n+\trte_vfio_user_set_irq_info;\n \n \tlocal: *;\n };\ndiff --git a/lib/librte_vfio_user/vfio_user_base.h b/lib/librte_vfio_user/vfio_user_base.h\nindex dd13170298..1780db4322 100644\n--- a/lib/librte_vfio_user/vfio_user_base.h\n+++ b/lib/librte_vfio_user/vfio_user_base.h\n@@ -61,6 +61,12 @@ struct vfio_user_reg {\n \tuint8_t rsvd[VFIO_USER_MAX_RSVD];\n };\n \n+struct vfio_user_irq_set {\n+\tstruct vfio_irq_set set;\n+\t/* Reserved for data of irq set */\n+\tuint8_t rsvd[VFIO_USER_MAX_RSVD];\n+};\n+\n struct vfio_user_reg_rw {\n \tuint64_t reg_offset;\n \tuint32_t reg_idx;\n@@ -83,6 +89,8 @@ struct vfio_user_msg {\n \t\tstruct rte_vfio_user_mem_reg memory[VFIO_USER_MSG_MAX_NREG];\n \t\tstruct vfio_device_info dev_info;\n \t\tstruct vfio_user_reg reg_info;\n+\t\tstruct vfio_irq_info irq_info;\n+\t\tstruct vfio_user_irq_set irq_set;\n \t\tstruct vfio_user_reg_rw reg_rw;\n \t} payload;\n \tint fds[VFIO_USER_MAX_FD];\ndiff --git a/lib/librte_vfio_user/vfio_user_server.c b/lib/librte_vfio_user/vfio_user_server.c\nindex 9e98b4ec81..104a0abb77 100644\n--- a/lib/librte_vfio_user/vfio_user_server.c\n+++ b/lib/librte_vfio_user/vfio_user_server.c\n@@ -9,6 +9,7 @@\n #include <sys/socket.h>\n #include <sys/mman.h>\n #include <sys/un.h>\n+#include <sys/eventfd.h>\n \n #include \"vfio_user_server.h\"\n \n@@ -310,6 +311,150 @@ vfio_user_device_get_reg_info(struct vfio_user_server *dev,\n \treturn 0;\n }\n \n+static int\n+vfio_user_device_get_irq_info(struct vfio_user_server *dev,\n+\tstruct vfio_user_msg *msg)\n+{\n+\tstruct vfio_irq_info *irq_info = &msg->payload.irq_info;\n+\tstruct rte_vfio_user_irq_info *info = dev->irqs.info;\n+\tuint32_t i;\n+\n+\tif (vfio_user_check_msg_fdnum(msg, 0) != 0)\n+\t\treturn -EINVAL;\n+\n+\tfor (i = 0; i < info->irq_num; i++) {\n+\t\tif (irq_info->index == info->irq_info[i].index) {\n+\t\t\tirq_info->count = info->irq_info[i].count;\n+\t\t\tirq_info->flags |= info->irq_info[i].flags;\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\tif (i == info->irq_num)\n+\t\treturn -EINVAL;\n+\n+\tVFIO_USER_LOG(DEBUG, \"IRQ info: argsz(0x%x), flags(0x%x), index(0x%x),\"\n+\t\t\" count(0x%x)\\n\", irq_info->argsz, irq_info->flags,\n+\t\tirq_info->index, irq_info->count);\n+\n+\treturn 0;\n+}\n+\n+static inline int\n+irq_set_trigger(struct vfio_user_irqs *irqs,\n+\tstruct vfio_irq_set *irq_set, struct vfio_user_msg *msg)\n+{\n+\tuint32_t i = irq_set->start;\n+\tint eventfd;\n+\n+\tswitch (irq_set->flags & VFIO_IRQ_SET_DATA_TYPE_MASK) {\n+\tcase VFIO_IRQ_SET_DATA_NONE:\n+\t\tif (vfio_user_check_msg_fdnum(msg, 0) != 0)\n+\t\t\treturn -EINVAL;\n+\n+\t\tfor (; i < irq_set->start + irq_set->count; i++) {\n+\t\t\teventfd = irqs->fds[irq_set->index][i];\n+\t\t\tif (eventfd >= 0) {\n+\t\t\t\tif (eventfd_write(eventfd, (eventfd_t)1))\n+\t\t\t\t\treturn -errno;\n+\t\t\t}\n+\t\t}\n+\t\tbreak;\n+\tcase VFIO_IRQ_SET_DATA_BOOL:\n+\t\tif (vfio_user_check_msg_fdnum(msg, 0) != 0)\n+\t\t\treturn -EINVAL;\n+\n+\t\tuint8_t *idx = irq_set->data;\n+\t\tfor (; i < irq_set->start + irq_set->count; i++, idx++) {\n+\t\t\teventfd = irqs->fds[irq_set->index][i];\n+\t\t\tif (eventfd >= 0 && *idx == 1) {\n+\t\t\t\tif (eventfd_write(eventfd, (eventfd_t)1))\n+\t\t\t\t\treturn -errno;\n+\t\t\t}\n+\t\t}\n+\t\tbreak;\n+\tcase VFIO_IRQ_SET_DATA_EVENTFD:\n+\t\tif (vfio_user_check_msg_fdnum(msg, irq_set->count) != 0)\n+\t\t\treturn -EINVAL;\n+\n+\t\tint32_t *fds = msg->fds;\n+\t\tfor (; i < irq_set->start + irq_set->count; i++, fds++) {\n+\t\t\teventfd = irqs->fds[irq_set->index][i];\n+\t\t\tif (eventfd >= 0)\n+\t\t\t\tclose(eventfd); /* Clear original irqfd*/\n+\t\t\tif (*fds >= 0)\n+\t\t\t\tirqs->fds[irq_set->index][i] = *fds;\n+\t\t}\n+\t\tbreak;\n+\tdefault:\n+\t\treturn -EINVAL;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static void\n+vfio_user_disable_irqs(struct vfio_user_irqs *irqs)\n+{\n+\tstruct rte_vfio_user_irq_info *info = irqs->info;\n+\tuint32_t i, j;\n+\n+\tfor (i = 0; i < info->irq_num; i++) {\n+\t\tfor (j = 0; j < info->irq_info[i].count; j++) {\n+\t\t\tif (irqs->fds[i][j] != -1) {\n+\t\t\t\tclose(irqs->fds[i][j]);\n+\t\t\t\tirqs->fds[i][j] = -1;\n+\t\t\t}\n+\t\t}\n+\t}\n+}\n+\n+static int\n+vfio_user_device_set_irqs(struct vfio_user_server *dev,\n+\tstruct vfio_user_msg *msg)\n+{\n+\tstruct vfio_user_irq_set *irq = &msg->payload.irq_set;\n+\tstruct vfio_irq_set *irq_set = &irq->set;\n+\tstruct rte_vfio_user_irq_info *info = dev->irqs.info;\n+\tint ret = 0;\n+\n+\tif (info->irq_num <= irq_set->index\n+\t\t|| info->irq_info[irq_set->index].count <\n+\t\tirq_set->start + irq_set->count) {\n+\t\tvfio_user_close_msg_fds(msg);\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tif (irq_set->count == 0) {\n+\t\tif (irq_set->flags & VFIO_IRQ_SET_DATA_NONE) {\n+\t\t\tvfio_user_disable_irqs(&dev->irqs);\n+\t\t\treturn 0;\n+\t\t}\n+\t\tvfio_user_close_msg_fds(msg);\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tswitch (irq_set->flags & VFIO_IRQ_SET_ACTION_TYPE_MASK) {\n+\t/* Mask/Unmask not supported for now */\n+\tcase VFIO_IRQ_SET_ACTION_MASK:\n+\t\t/* FALLTHROUGH */\n+\tcase VFIO_IRQ_SET_ACTION_UNMASK:\n+\t\treturn 0;\n+\tcase VFIO_IRQ_SET_ACTION_TRIGGER:\n+\t\tret = irq_set_trigger(&dev->irqs, irq_set, msg);\n+\t\tbreak;\n+\tdefault:\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tVFIO_USER_LOG(DEBUG, \"Set IRQ: argsz(0x%x), flags(0x%x), index(0x%x), \"\n+\t\t\"start(0x%x), count(0x%x)\\n\", irq_set->argsz, irq_set->flags,\n+\t\tirq_set->index, irq_set->start, irq_set->count);\n+\n+\t/* Do not reply fds back */\n+\tmsg->fd_num = 0;\n+\treturn ret;\n+}\n+\n static int\n vfio_user_region_read(struct vfio_user_server *dev,\n \tstruct vfio_user_msg *msg)\n@@ -421,6 +566,50 @@ vfio_user_destroy_mem(struct vfio_user_server *dev)\n \tdev->mem = NULL;\n }\n \n+static inline void\n+vfio_user_destroy_irq(struct vfio_user_server *dev)\n+{\n+\tstruct vfio_user_irqs *irq = &dev->irqs;\n+\tint *fd;\n+\tuint32_t i, j;\n+\n+\tif (!irq->info)\n+\t\treturn;\n+\n+\tfor (i = 0; i < irq->info->irq_num; i++) {\n+\t\tfd = irq->fds[i];\n+\n+\t\tfor (j = 0; j < irq->info->irq_info[i].count; j++) {\n+\t\t\tif (fd[j] != -1)\n+\t\t\t\tclose(fd[j]);\n+\t\t}\n+\n+\t\tfree(fd);\n+\t}\n+\n+\tfree(irq->fds);\n+}\n+\n+static inline void\n+vfio_user_clean_irqfd(struct vfio_user_server *dev)\n+{\n+\tstruct vfio_user_irqs *irq = &dev->irqs;\n+\tint *fd;\n+\tuint32_t i, j;\n+\n+\tif (!irq->info)\n+\t\treturn;\n+\n+\tfor (i = 0; i < irq->info->irq_num; i++) {\n+\t\tfd = irq->fds[i];\n+\n+\t\tfor (j = 0; j < irq->info->irq_info[i].count; j++) {\n+\t\t\tclose(fd[j]);\n+\t\t\tfd[j] = -1;\n+\t\t}\n+\t}\n+}\n+\n static int\n vfio_user_device_reset(struct vfio_user_server *dev,\n \tstruct vfio_user_msg *msg)\n@@ -436,6 +625,7 @@ vfio_user_device_reset(struct vfio_user_server *dev,\n \t\treturn -ENOTSUP;\n \n \tvfio_user_destroy_mem_entries(dev->mem);\n+\tvfio_user_clean_irqfd(dev);\n \tdev->is_ready = 0;\n \n \tif (dev->ops->reset_device)\n@@ -451,8 +641,8 @@ static vfio_user_msg_handler_t vfio_user_msg_handlers[VFIO_USER_MAX] = {\n \t[VFIO_USER_DMA_UNMAP] = vfio_user_dma_unmap,\n \t[VFIO_USER_DEVICE_GET_INFO] = vfio_user_device_get_info,\n \t[VFIO_USER_DEVICE_GET_REGION_INFO] = vfio_user_device_get_reg_info,\n-\t[VFIO_USER_DEVICE_GET_IRQ_INFO] = NULL,\n-\t[VFIO_USER_DEVICE_SET_IRQS] = NULL,\n+\t[VFIO_USER_DEVICE_GET_IRQ_INFO] = vfio_user_device_get_irq_info,\n+\t[VFIO_USER_DEVICE_SET_IRQS] = vfio_user_device_set_irqs,\n \t[VFIO_USER_REGION_READ] = vfio_user_region_read,\n \t[VFIO_USER_REGION_WRITE] = vfio_user_region_write,\n \t[VFIO_USER_DMA_READ] = NULL,\n@@ -856,6 +1046,7 @@ vfio_user_message_handler(int dev_id, int fd)\n \t * to avoid errors in data path handling\n \t */\n \tif ((cmd == VFIO_USER_DMA_MAP || cmd == VFIO_USER_DMA_UNMAP ||\n+\t\tcmd == VFIO_USER_DEVICE_SET_IRQS ||\n \t\tcmd == VFIO_USER_DEVICE_RESET)\n \t\t&& dev->ops->lock_dp) {\n \t\tdev->ops->lock_dp(dev_id, 1);\n@@ -898,7 +1089,8 @@ vfio_user_message_handler(int dev_id, int fd)\n \t\tif (vfio_user_is_ready(dev) && dev->ops->new_device)\n \t\t\tdev->ops->new_device(dev_id);\n \t} else {\n-\t\tif ((cmd == VFIO_USER_DMA_MAP || cmd == VFIO_USER_DMA_UNMAP)\n+\t\tif ((cmd == VFIO_USER_DMA_MAP || cmd == VFIO_USER_DMA_UNMAP\n+\t\t\t|| cmd == VFIO_USER_DEVICE_SET_IRQS)\n \t\t\t&& dev->ops->update_status)\n \t\t\tdev->ops->update_status(dev_id);\n \t}\n@@ -926,6 +1118,7 @@ vfio_user_sock_read(int fd, void *data)\n \t\tif (dev) {\n \t\t\tdev->ops->destroy_device(dev_id);\n \t\t\tvfio_user_destroy_mem_entries(dev->mem);\n+\t\t\tvfio_user_clean_irqfd(dev);\n \t\t\tdev->is_ready = 0;\n \t\t\tdev->msg_id = 0;\n \t\t}\n@@ -1023,9 +1216,9 @@ vfio_user_start_server(struct vfio_user_server_socket *sk)\n \t}\n \n \t/* All the info must be set before start */\n-\tif (!dev->dev_info || !dev->reg) {\n+\tif (!dev->dev_info || !dev->reg || !dev->irqs.info) {\n \t\tVFIO_USER_LOG(ERR, \"Failed to start, \"\n-\t\t\t\"dev/reg info must be set before start\\n\");\n+\t\t\t\"dev/reg/irq info must be set before start\\n\");\n \t\treturn -1;\n \t}\n \n@@ -1139,6 +1332,7 @@ rte_vfio_user_unregister(const char *sock_addr)\n \t\treturn -1;\n \t}\n \tvfio_user_destroy_mem(dev);\n+\tvfio_user_destroy_irq(dev);\n \tvfio_user_del_device(dev);\n \n \treturn 0;\n@@ -1301,3 +1495,99 @@ rte_vfio_user_get_mem_table(int dev_id)\n \n \treturn dev->mem;\n }\n+\n+int\n+rte_vfio_user_get_irq(int dev_id, uint32_t index, uint32_t count, int *fds)\n+{\n+\tstruct vfio_user_server *dev;\n+\tstruct vfio_user_irqs *irqs;\n+\tuint32_t irq_max;\n+\n+\tdev = vfio_user_get_device(dev_id);\n+\tif (!dev) {\n+\t\tVFIO_USER_LOG(ERR, \"Failed to get irq info:\"\n+\t\t\t\"device %d not found.\\n\", dev_id);\n+\t\treturn -1;\n+\t}\n+\n+\tif (!fds)\n+\t\treturn -1;\n+\n+\tirqs = &dev->irqs;\n+\tif (index >= irqs->info->irq_num)\n+\t\treturn -1;\n+\n+\tirq_max = irqs->info->irq_info[index].count;\n+\tif (count > irq_max)\n+\t\treturn -1;\n+\n+\tmemcpy(fds, dev->irqs.fds[index], count * sizeof(int));\n+\treturn 0;\n+}\n+\n+int\n+rte_vfio_user_set_irq_info(const char *sock_addr,\n+\tstruct rte_vfio_user_irq_info *irq)\n+{\n+\tstruct vfio_user_server *dev;\n+\tstruct vfio_user_server_socket *sk;\n+\tuint32_t i;\n+\tint dev_id, ret;\n+\n+\tif (!irq)\n+\t\treturn -1;\n+\n+\tpthread_mutex_lock(&vfio_ep_sock.mutex);\n+\tsk = vfio_user_find_socket(sock_addr);\n+\tpthread_mutex_unlock(&vfio_ep_sock.mutex);\n+\n+\tif (!sk) {\n+\t\tVFIO_USER_LOG(ERR, \"Failed to set irq info with sock_addr:\"\n+\t\t\t\"%s: addr not registered.\\n\", sock_addr);\n+\t\treturn -1;\n+\t}\n+\n+\tdev_id = sk->sock.dev_id;\n+\tdev = vfio_user_get_device(dev_id);\n+\tif (!dev) {\n+\t\tVFIO_USER_LOG(ERR, \"Failed to set irq info:\"\n+\t\t\t\"device %d not found.\\n\", dev_id);\n+\t\treturn -1;\n+\t}\n+\n+\tif (dev->started) {\n+\t\tVFIO_USER_LOG(ERR, \"Failed to set irq info for device %d\\n\"\n+\t\t\t \", device already started\\n\", dev_id);\n+\t\treturn -1;\n+\t}\n+\n+\tif (dev->irqs.info)\n+\t\tvfio_user_destroy_irq(dev);\n+\n+\tdev->irqs.info = irq;\n+\n+\tdev->irqs.fds = malloc(irq->irq_num * sizeof(int *));\n+\tif (!dev->irqs.fds)\n+\t\treturn -1;\n+\n+\tfor (i = 0; i < irq->irq_num; i++) {\n+\t\tuint32_t sz = irq->irq_info[i].count * sizeof(int);\n+\t\tdev->irqs.fds[i] = malloc(sz);\n+\t\tif (!dev->irqs.fds[i]) {\n+\t\t\tret = -1;\n+\t\t\tgoto exit;\n+\t\t}\n+\n+\t\tmemset(dev->irqs.fds[i], 0xFF, sz);\n+\t}\n+\n+\treturn 0;\n+exit:\n+\tfor (--i;; i--) {\n+\t\tfree(dev->irqs.fds[i]);\n+\t\tif (i == 0)\n+\t\t\tbreak;\n+\t}\n+\tfree(dev->irqs.fds);\n+\treturn ret;\n+}\ndiff --git a/lib/librte_vfio_user/vfio_user_server.h b/lib/librte_vfio_user/vfio_user_server.h\nindex 0b20ab4e3a..1b4ed4f47c 100644\n--- a/lib/librte_vfio_user/vfio_user_server.h\n+++ b/lib/librte_vfio_user/vfio_user_server.h\n@@ -9,6 +9,11 @@\n \n #include \"vfio_user_base.h\"\n \n+struct vfio_user_irqs {\n+\tstruct rte_vfio_user_irq_info *info;\n+\tint **fds;\n+};\n+\n struct vfio_user_server {\n \tint dev_id;\n \tint is_ready;\n@@ -21,6 +26,7 @@ struct vfio_user_server {\n \tstruct rte_vfio_user_mem *mem;\n \tstruct vfio_device_info *dev_info;\n \tstruct rte_vfio_user_regions *reg;\n+\tstruct vfio_user_irqs irqs;\n };\n \n typedef int (*event_handler)(int fd, void *data);\n",
    "prefixes": [
        "v2",
        "5/9"
    ]
}