From nobody Mon Nov 23 04:30:09 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1795056251056815.9793059949493; Wed, 18 Nov 2026 18:44:11 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xTs7S-0000r1-87; Wed, 18 Nov 2026 21:43:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xTs7O-0000pX-Fk; Wed, 18 Nov 2026 21:43:22 -0500 Received: from smtp21.cstnet.cn ([159.226.251.21] helo=cstnet.cn) by eggs.gnu.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1xTs7K-0005bs-PU; Wed, 18 Nov 2026 21:43:22 -0500 Received: from k3-03 (unknown [159.226.43.8]) by APP-01 (Coremail) with SMTP id qwCowAD3Hfg8Yv5qZFtAAQ--.232S3; Thu, 19 Nov 2026 10:43:11 +0800 (CST) From: Tan Chi To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, palmer@dabbelt.com, alistair.francis@wdc.com, liwei1518@gmail.com, daniel.barboza@oss.qualcomm.com, zhiwei_liu@linux.alibaba.com, chao.liu.zevorn@gmail.com, Tan Chi Subject: [PATCH 1/3] hw/riscv: iommu: Add migration support for common state Date: Thu, 19 Nov 2026 10:42:48 +0800 Message-ID: <20261119024251.280765-2-tanchi25@mails.ucas.ac.cn> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261119024251.280765-1-tanchi25@mails.ucas.ac.cn> References: <20261119024251.280765-1-tanch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xvE14v2 6r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj4 0_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8 JrUvcSsGvfC2KfnxnUUI43ZEXa7VUjMqcUUUUUU== X-Originating-IP: [159.226.43.8] X-CM-SenderInfo: pwdquxrlsvqzpdlo2hpxfd2hldfou0/ Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=159.226.251.21; envelope-from=tanchi25@mails.ucas.ac.cn; helo=cstnet.cn X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1795056260270158500 Content-Type: text/plain; charset="utf-8" Add VMState support for the common RISC-V IOMMU device to preserve its register state, device directory configuration, and command, fault, and page-request queue state across migration. Save the HPM cycle counter state and overflow timer in a separate subsection when HPM is enabled. Rebuild the HPM event-to-counter mapping from the restored event selector registers on the destination. Signed-off-by: Tan Chi --- hw/riscv/riscv-iommu-hpm.c | 27 +++++++++++++++++++ hw/riscv/riscv-iommu-hpm.h | 2 ++ hw/riscv/riscv-iommu.c | 54 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+) diff --git a/hw/riscv/riscv-iommu-hpm.c b/hw/riscv/riscv-iommu-hpm.c index 9bfef6db45..9656fdc839 100644 --- a/hw/riscv/riscv-iommu-hpm.c +++ b/hw/riscv/riscv-iommu-hpm.c @@ -381,3 +381,30 @@ void riscv_iommu_process_hpmevt_write(RISCVIOMMUState = *s, uint32_t evt_reg) =20 update_event_map(s, val, ctr_idx); } + +int riscv_iommu_hpm_post_load(void *opaque, int version_id) +{ + RISCVIOMMUState *s =3D opaque; + uint64_t evt_val; + unsigned int i; + + if (!(s->cap & RISCV_IOMMU_CAP_HPM)) { + return 0; + } + + g_hash_table_remove_all(s->hpm_event_ctr_map); + + for (i =3D 0; i < s->hpm_cntrs; i++) { + evt_val =3D riscv_iommu_reg_get64( + s, RISCV_IOMMU_REG_IOHPMEVT_BASE + (i << 3)); + + if (!check_valid_event_id( + get_field(evt_val, RISCV_IOMMU_IOHPMEVT_EVENT_ID))) { + continue; + } + + update_event_map(s, evt_val, i); + } + + return 0; +} diff --git a/hw/riscv/riscv-iommu-hpm.h b/hw/riscv/riscv-iommu-hpm.h index 5fc4ef2e8b..516974ec87 100644 --- a/hw/riscv/riscv-iommu-hpm.h +++ b/hw/riscv/riscv-iommu-hpm.h @@ -30,4 +30,6 @@ void riscv_iommu_process_iocntinh_cy(RISCVIOMMUState *s, = bool prev_cy_inh); void riscv_iommu_process_hpmcycle_write(RISCVIOMMUState *s); void riscv_iommu_process_hpmevt_write(RISCVIOMMUState *s, uint32_t evt_reg= ); =20 +int riscv_iommu_hpm_post_load(void *opaque, int version_id); + #endif diff --git a/hw/riscv/riscv-iommu.c b/hw/riscv/riscv-iommu.c index 5b1a388364..7c23e32693 100644 --- a/hw/riscv/riscv-iommu.c +++ b/hw/riscv/riscv-iommu.c @@ -3067,6 +3067,59 @@ void riscv_iommu_reset(RISCVIOMMUState *s) qemu_mutex_unlock(&s->iot_lock); } =20 +static bool riscv_iommu_hpm_state_needed(void *opaque) +{ + RISCVIOMMUState *s =3D opaque; + + return !!(s->cap & RISCV_IOMMU_CAP_HPM); +} + +static const VMStateDescription vmstate_riscv_iommu_hpm =3D { + .name =3D "riscv-iommu/hpm", + .version_id =3D 1, + .minimum_version_id =3D 1, + .needed =3D riscv_iommu_hpm_state_needed, + .post_load =3D riscv_iommu_hpm_post_load, + .fields =3D (const VMStateField[]) { + VMSTATE_UINT64(hpmcycle_val, RISCVIOMMUState), + VMSTATE_UINT64(hpmcycle_prev, RISCVIOMMUState), + VMSTATE_UINT64(irq_overflow_left, RISCVIOMMUState), + VMSTATE_TIMER_PTR(hpm_timer, RISCVIOMMUState), + VMSTATE_END_OF_LIST() + } +}; + +static const VMStateDescription vmstate_riscv_iommu =3D { + .name =3D "riscv-iommu", + .version_id =3D 1, + .minimum_version_id =3D 1, + .priority =3D MIG_PRI_IOMMU, + .fields =3D (const VMStateField[]) { + VMSTATE_BUFFER_POINTER_UNSAFE(regs, RISCVIOMMUState, + 0, RISCV_IOMMU_REG_MSI_CONFIG), + + VMSTATE_UINT64(ddtp, RISCVIOMMUState), + VMSTATE_UINT64(fctl, RISCVIOMMUState), + + VMSTATE_UINT64(cq_addr, RISCVIOMMUState), + VMSTATE_UINT64(fq_addr, RISCVIOMMUState), + VMSTATE_UINT64(pq_addr, RISCVIOMMUState), + + VMSTATE_UINT32(cq_mask, RISCVIOMMUState), + VMSTATE_UINT32(fq_mask, RISCVIOMMUState), + VMSTATE_UINT32(pq_mask, RISCVIOMMUState), + + VMSTATE_BUFFER_POINTER_UNSAFE(regs_ro, RISCVIOMMUState, + 0, RISCV_IOMMU_REG_MSI_CONFIG), + + VMSTATE_END_OF_LIST(), + }, + .subsections =3D (const VMStateDescription * const []) { + &vmstate_riscv_iommu_hpm, + NULL + } +}; + static const Property riscv_iommu_properties[] =3D { DEFINE_PROP_UINT32("version", RISCVIOMMUState, version, RISCV_IOMMU_SPEC_DOT_VER), @@ -3094,6 +3147,7 @@ static void riscv_iommu_class_init(ObjectClass *klass= , const void *data) dc->user_creatable =3D false; dc->realize =3D riscv_iommu_realize; dc->unrealize =3D riscv_iommu_unrealize; + dc->vmsd =3D &vmstate_riscv_iommu; device_class_set_props(dc, riscv_iommu_properties); } =20 --=20 2.53.0 From nobody Mon Nov 23 04:30:09 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1795056257387953.3388557049359; Wed, 18 Nov 2026 18:44:17 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xTs7P-0000pb-Ra; Wed, 18 Nov 2026 21:43:23 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xTs7N-0000pL-IO; Wed, 18 Nov 2026 21:43:21 -0500 Received: from smtp21.cstnet.cn ([159.226.251.21] helo=cstnet.cn) by eggs.gnu.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1xTs7K-0005aN-Ov; Wed, 18 Nov 2026 21:43:21 -0500 Received: from k3-03 (unknown [159.226.43.8]) by APP-01 (Coremail) with SMTP id qwCowAD3Hfg8Yv5qZFtAAQ--.232S4; Thu, 19 Nov 2026 10:43:12 +0800 (CST) From: Tan Chi To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, palmer@dabbelt.com, alistair.francis@wdc.com, liwei1518@gmail.com, daniel.barboza@oss.qualcomm.com, zhiwei_liu@linux.alibaba.com, chao.liu.zevorn@gmail.com, Tan Chi Subject: [PATCH 2/3] hw/riscv: iommu-pci: Add migration support Date: Thu, 19 Nov 2026 10:42:49 +0800 Message-ID: <20261119024251.280765-3-tanchi25@mails.ucas.ac.cn> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261119024251.280765-1-tanchi25@mails.ucas.ac.cn> References: <20261119024251.280765-1-tanchi25@mails.ucas.ac.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: qwCowAD3Hfg8Yv5qZFtAAQ--.232S4 X-Coremail-Antispam: 1UD129KBjvJXoW7uFW3ZF1DKryDGryrXFW8Zwb_yoW8Cw4DpF s5ur4Sy3W5JFs2qa13Jw4UGF4YqanYg3WYvr47Ca1kJa1UKrWYqFsxA347Ar4DJFW5Xw12 vw4fCFWDCF4jywUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUmG14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_Jryl82xGYIkIc2 x26xkF7I0E14v26r4j6ryUM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Cr0_Gr1UM2 8EF7xvwVC2z280aVAFwI0_Cr1j6rxdM28EF7xvwVC2z280aVCY1x0267AKxVWxJr0_GcWl nxkEFVAIw20F6cxK64vIFxWle2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4 CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4UMcvj eVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I 1lc7CjxVAaw2AFwI0_Jw0_GFylc2xSY4AK67AK6r4UMxAIw28IcxkI7VAKI48JMxC20s02 6xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_Jr I_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v2 6r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj4 0_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8 JrUvcSsGvfC2KfnxnUUI43ZEXa7VUUiFxUUUUUU== X-Originating-IP: [159.226.43.8] X-CM-SenderInfo: pwdquxrlsvqzpdlo2hpxfd2hldfou0/ Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=159.226.251.21; envelope-from=tanchi25@mails.ucas.ac.cn; helo=cstnet.cn X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1795056262065158500 Content-Type: text/plain; charset="utf-8" Replace the unmigratable VMState description with one that saves the PCI configuration space and MSI-X state. Use the existing PCI migration helpers to preserve the MSI-X table and pending bit array when MSI-X is present. The common IOMMU state is migrated separately by the embedded RISC-V IOMMU device. Signed-off-by: Tan Chi --- hw/riscv/riscv-iommu-pci.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/hw/riscv/riscv-iommu-pci.c b/hw/riscv/riscv-iommu-pci.c index 14dd5f3857..d149032cd1 100644 --- a/hw/riscv/riscv-iommu-pci.c +++ b/hw/riscv/riscv-iommu-pci.c @@ -143,9 +143,23 @@ static void riscv_iommu_pci_exit(PCIDevice *pci_dev) pci_setup_iommu(pci_device_root_bus(pci_dev), NULL, NULL); } =20 -static const VMStateDescription riscv_iommu_vmstate =3D { - .name =3D "riscv-iommu", - .unmigratable =3D 1 +static bool riscv_iommu_pci_msix_present(void *opaque, int version_id) +{ + RISCVIOMMUStatePci *s =3D opaque; + + return msix_present(&s->pci); +} + +static const VMStateDescription vmstate_riscv_iommu_pci =3D { + .name =3D "riscv-iommu-pci", + .version_id =3D 1, + .minimum_version_id =3D 1, + .fields =3D (const VMStateField[]) { + VMSTATE_PCI_DEVICE(pci, RISCVIOMMUStatePci), + VMSTATE_MSIX_TEST(pci, RISCVIOMMUStatePci, + riscv_iommu_pci_msix_present), + VMSTATE_END_OF_LIST() + } }; =20 static void riscv_iommu_pci_init(Object *obj) @@ -193,7 +207,7 @@ static void riscv_iommu_pci_class_init(ObjectClass *kla= ss, const void *data) k->exit =3D riscv_iommu_pci_exit; k->class_id =3D RISCV_PCI_CLASS_SYSTEM_IOMMU; dc->desc =3D "RISCV-IOMMU DMA Remapping device"; - dc->vmsd =3D &riscv_iommu_vmstate; + dc->vmsd =3D &vmstate_riscv_iommu_pci; dc->hotpluggable =3D false; dc->user_creatable =3D true; set_bit(DEVICE_CATEGORY_MISC, dc->categories); --=20 2.53.0 From nobody Mon Nov 23 04:30:09 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1795056256992310.0442223347875; Wed, 18 Nov 2026 18:44:16 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xTs7S-0000r3-5o; Wed, 18 Nov 2026 21:43:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xTs7O-0000pZ-IE; Wed, 18 Nov 2026 21:43:22 -0500 Received: from smtp21.cstnet.cn ([159.226.251.21] helo=cstnet.cn) by eggs.gnu.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1xTs7K-0005eZ-QJ; Wed, 18 Nov 2026 21:43:22 -0500 Received: from k3-03 (unknown [159.226.43.8]) by APP-01 (Coremail) with SMTP id qwCowAD3Hfg8Yv5qZFtAAQ--.232S5; Thu, 19 Nov 2026 10:43:12 +0800 (CST) From: Tan Chi To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, palmer@dabbelt.com, alistair.francis@wdc.com, liwei1518@gmail.com, daniel.barboza@oss.qualcomm.com, zhiwei_liu@linux.alibaba.com, chao.liu.zevorn@gmail.com, Tan Chi Subject: [PATCH 3/3] hw/riscv: iommu-sys: Add migration support Date: Thu, 19 Nov 2026 10:42:50 +0800 Message-ID: <20261119024251.280765-4-tanchi25@mails.ucas.ac.cn> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261119024251.280765-1-tanchi25@mails.ucas.ac.cn> References: <20261119024251.280765-1-tanchi25@mails.ucas.ac.cn> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: qwCowAD3Hfg8Yv5qZFtAAQ--.232S5 X-Coremail-Antispam: 1UD129KBjvJXoW7WFW5Wry8Gw1fXw4fArW8JFb_yoW8tFWrpF s5urWayr1DGr1xAFnIvw1UCF48J3Z7Ww15Z393ua97uF4UtrWDJFs5Kay5ArWkGFZ7Ca4r Cr1rGr98Ar4Yvr7anT9S1TB71UU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-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=159.226.251.21; envelope-from=tanchi25@mails.ucas.ac.cn; helo=cstnet.cn X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1795056260413158500 Content-Type: text/plain; charset="utf-8" Add VMState support for the system-bus RISC-V IOMMU device. Preserve the MSI-X configuration table and pending bit array, which are maintained in separate buffers by the system-bus wrapper. The common IOMMU registers and internal state are migrated independently by the embedded IOMMU device. Signed-off-by: Tan Chi --- hw/riscv/riscv-iommu-sys.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/hw/riscv/riscv-iommu-sys.c b/hw/riscv/riscv-iommu-sys.c index 258c171efd..6e4cea00a5 100644 --- a/hw/riscv/riscv-iommu-sys.c +++ b/hw/riscv/riscv-iommu-sys.c @@ -21,6 +21,7 @@ #include "hw/pci/pci_bus.h" #include "hw/core/qdev-properties.h" #include "hw/core/sysbus.h" +#include "migration/vmstate.h" #include "qapi/error.h" #include "qemu/error-report.h" #include "qemu/host-utils.h" @@ -242,6 +243,25 @@ DeviceState *riscv_create_iommu_sys(DeviceState *mmio_= irqchip, return iommu_sys; } =20 +#define RISCV_IOMMU_SYSDEV_MSIX_TABLE_SIZE \ + (RISCV_IOMMU_PCI_MSIX_VECTORS * PCI_MSIX_ENTRY_SIZE) + +#define RISCV_IOMMU_SYSDEV_MSIX_PBA_SIZE \ + (QEMU_ALIGN_UP(RISCV_IOMMU_PCI_MSIX_VECTORS, 64) / 8) + +static const VMStateDescription vmstate_riscv_iommu_sys =3D { + .name =3D "riscv-iommu-sys", + .version_id =3D 1, + .minimum_version_id =3D 1, + .fields =3D (const VMStateField[]) { + VMSTATE_BUFFER_POINTER_UNSAFE(msix_table, RISCVIOMMUStateSys, 0, + RISCV_IOMMU_SYSDEV_MSIX_TABLE_SIZE), + VMSTATE_BUFFER_POINTER_UNSAFE(msix_pba, RISCVIOMMUStateSys, 0, + RISCV_IOMMU_SYSDEV_MSIX_PBA_SIZE), + VMSTATE_END_OF_LIST() + } +}; + static const Property riscv_iommu_sys_properties[] =3D { DEFINE_PROP_UINT64("addr", RISCVIOMMUStateSys, addr, 0), DEFINE_PROP_UINT32("base-irq", RISCVIOMMUStateSys, base_irq, 0), @@ -267,6 +287,7 @@ static void riscv_iommu_sys_class_init(ObjectClass *kla= ss, const void *data) rc->phases.hold =3D riscv_iommu_sys_reset_hold; =20 dc->realize =3D riscv_iommu_sys_realize; + dc->vmsd =3D &vmstate_riscv_iommu_sys; set_bit(DEVICE_CATEGORY_MISC, dc->categories); device_class_set_props(dc, riscv_iommu_sys_properties); } --=20 2.53.0