From nobody Sat May 4 19:39:42 2024 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; dmarc=fail(p=quarantine dis=quarantine) header.from=opensource.wdc.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1650434190364712.325217652546; Tue, 19 Apr 2022 22:56:30 -0700 (PDT) Received: from localhost ([::1]:37374 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nh3KE-0001AQ-7r for importer@patchew.org; Wed, 20 Apr 2022 01:56:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33742) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nh3H2-0007qS-Sq for qemu-devel@nongnu.org; Wed, 20 Apr 2022 01:53:08 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:41244) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nh3H0-0004Qd-PQ for qemu-devel@nongnu.org; Wed, 20 Apr 2022 01:53:08 -0400 Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 20 Apr 2022 13:53:03 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 19 Apr 2022 22:23:22 -0700 Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 19 Apr 2022 22:53:04 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4Kjqb33Y6dz1SHwl for ; Tue, 19 Apr 2022 22:53:03 -0700 (PDT) Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id gVJB4e9TpJwY for ; Tue, 19 Apr 2022 22:53:01 -0700 (PDT) Received: from toolbox.wdc.com (unknown [10.225.165.119]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4KjqZx4s6Bz1Rwrw; Tue, 19 Apr 2022 22:52:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1650433986; x=1681969986; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/LhyZf2nYA3CHhEVP9i1qF21zpSIkG1ugCVQa7PPYo4=; b=LQw69JaW6+4DVPwY5s3gbX4GveKFWDikGjYreRnK4OXNjvyeU1zlou1T xHuTwdn/6FQb4sxf1BgLF/odJeOxHewRiVDGAo/Fw5Lr9J/lhiam+nAVW d4zbNu6pH7RLjdcu8WljjI0FPuCTs34wFJyM/XQcdZLyTxX2MLzCoRr43 f2ffQiK7NGXmlDqJ7725ttZYu2PtU45+5EBUUk4414/RqudppCdKgtjBD Q3CgxkB6Xk1EP1q8miYoN1P02MI7TFzhJpOhmHQ6tuEj5QI8GpClGECmF kjyYPY015U5biKEawT7NBFQIb6UMPvomNxLVmmkiliGnQQs9dT/7tzBdc w==; X-IronPort-AV: E=Sophos;i="5.90,274,1643644800"; d="scan'208";a="310304320" IronPort-SDR: KYgFJ1CPrCh826cvCGlHjLmuZDkLfcj338CE6BwepWB89lphldWPzidjn1ANXvfl5/4pPHFAI3 Pk0SiG/ASMSog1ziv6RoQdA+ZRclqsPB+a6G+MW0pRRFve3LbtRoM4WzRCSYy4oxJOwQrc212r qh/QGJpJLOzVmkRIJ6MsO2QBg6CUHDdWwjYTml5HUxeoYmluDxmShvae8ig01momTcxn0RYxCv Na9MIb3PW5BC/o2866gPolxsiSQ9RnTTZa5a1pyv1+sAMNrOOEvPSI6lHAPdScCioSoe2GgjJG r6xyof4R+2LVYHnrX4fDEKEA IronPort-SDR: B/tjdgMEmyOGCHTiWzvtH61wA+3z2YjHHNIasDdqu6NXn9W9NTB0tV6VhMP24+09lW9MYqVRFR xIeQUdHk/bVluJ4b3KmsFIwFngJ6qSEkIEoO+tzeebz5Rw49ynNFR9hlrqWk6fRCYOq3FrWG4v 5ZXNHxziC1OdqWwc68nsuprn3OqOmIDeL96RzM1SHa/AcFm8IIhtymphgY3Ck3G09W5vqWgnu1 ey4km92G5X6UyuZkdfzLLA1RAE53bmaB1zsnT4XGASeBzHo8Emwkjj3GXQbLnNQ+gqS+v9oNv4 zCE= WDCIronportException: Internal Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1650433981; x=1653025982; bh=/LhyZf2nYA3CHhEVP9 i1qF21zpSIkG1ugCVQa7PPYo4=; b=S3xIxg+NMn+DfAHKJcOR54lLg/YZtdXaUl 6bQUMVieED7govHUBtKHa6riYvvxGn/SGsLT87671jgMOXQY72HB0nbfhkfX8ad+ fQbahIKTnFQgDXGugusRUGyc4rp5KqX2rVnuKpMEXuXR4xGgd++w5QoAq05N9mLJ gl9IZldffFCwWxCgKsqorT+zyFFD6mKj2ja3rx2AojG3D9LQajStZ5+ePbgyPu1s w5iwy9GhZjSVMa9m3PNcPVz0FIsk1PnSxysnGxS/fFATWZHdZDI6yTKmGquT/B5C KRR+aIR1Xlj+p76HgD/snV47EwsCDXa4MkSZ9UJsKILxOlLaa9gA== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com From: Alistair Francis To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: Palmer Dabbelt , Alistair Francis , alistair23@gmail.com, Bin Meng , Alistair Francis , qemu-arm@nongnu.org, Peter Maydell , bmeng.cn@gmail.com, "Edgar E. Iglesias" Subject: [PATCH v4 1/6] hw/riscv: virt: Add a machine done notifier Date: Wed, 20 Apr 2022 15:52:43 +1000 Message-Id: <20220420055248.960491-2-alistair.francis@opensource.wdc.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220420055248.960491-1-alistair.francis@opensource.wdc.com> References: <20220420055248.960491-1-alistair.francis@opensource.wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=lists.gnu.org; Received-SPF: pass client-ip=68.232.141.245; envelope-from=prvs=1021dae20=alistair.francis@opensource.wdc.com; helo=esa1.hgst.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1650434192288100001 Content-Type: text/plain; charset="utf-8" From: Alistair Francis Move the binary and device tree loading code to the machine done notifier. This allows us to prepare for editing the device tree as part of the notifier. This is based on similar code in the ARM virt machine. Signed-off-by: Alistair Francis Reviewed-by: Edgar E. Iglesias Reviewed-by: Bin Meng --- include/hw/riscv/virt.h | 1 + hw/riscv/virt.c | 180 +++++++++++++++++++++------------------- 2 files changed, 97 insertions(+), 84 deletions(-) diff --git a/include/hw/riscv/virt.h b/include/hw/riscv/virt.h index 78b058ec86..8b8db3fb7c 100644 --- a/include/hw/riscv/virt.h +++ b/include/hw/riscv/virt.h @@ -45,6 +45,7 @@ struct RISCVVirtState { MachineState parent; =20 /*< public >*/ + Notifier machine_done; RISCVHartArrayState soc[VIRT_SOCKETS_MAX]; DeviceState *irqchip[VIRT_SOCKETS_MAX]; PFlashCFI01 *flash[2]; diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index da50cbed43..3d48469367 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -1156,6 +1156,95 @@ static DeviceState *virt_create_aia(RISCVVirtAIAType= aia_type, int aia_guests, return aplic_m; } =20 +static +void virt_machine_done(Notifier *notifier, void *data) +{ + RISCVVirtState *s =3D container_of(notifier, RISCVVirtState, + machine_done); + const MemMapEntry *memmap =3D virt_memmap; + MachineState *machine =3D MACHINE(s); + target_ulong start_addr =3D memmap[VIRT_DRAM].base; + target_ulong firmware_end_addr, kernel_start_addr; + uint32_t fdt_load_addr; + uint64_t kernel_entry; + + /* + * Only direct boot kernel is currently supported for KVM VM, + * so the "-bios" parameter is ignored and treated like "-bios none" + * when KVM is enabled. + */ + if (kvm_enabled()) { + g_free(machine->firmware); + machine->firmware =3D g_strdup("none"); + } + + if (riscv_is_32bit(&s->soc[0])) { + firmware_end_addr =3D riscv_find_and_load_firmware(machine, + RISCV32_BIOS_BIN, start_addr, NULL); + } else { + firmware_end_addr =3D riscv_find_and_load_firmware(machine, + RISCV64_BIOS_BIN, start_addr, NULL); + } + + if (machine->kernel_filename) { + kernel_start_addr =3D riscv_calc_kernel_start_addr(&s->soc[0], + firmware_end_addr= ); + + kernel_entry =3D riscv_load_kernel(machine->kernel_filename, + kernel_start_addr, NULL); + + if (machine->initrd_filename) { + hwaddr start; + hwaddr end =3D riscv_load_initrd(machine->initrd_filename, + machine->ram_size, kernel_entry, + &start); + qemu_fdt_setprop_cell(machine->fdt, "/chosen", + "linux,initrd-start", start); + qemu_fdt_setprop_cell(machine->fdt, "/chosen", "linux,initrd-e= nd", + end); + } + } else { + /* + * If dynamic firmware is used, it doesn't know where is the next m= ode + * if kernel argument is not set. + */ + kernel_entry =3D 0; + } + + if (drive_get(IF_PFLASH, 0, 0)) { + /* + * Pflash was supplied, let's overwrite the address we jump to aft= er + * reset to the base of the flash. + */ + start_addr =3D virt_memmap[VIRT_FLASH].base; + } + + /* + * Init fw_cfg. Must be done before riscv_load_fdt, otherwise the dev= ice + * tree cannot be altered and we get FDT_ERR_NOSPACE. + */ + s->fw_cfg =3D create_fw_cfg(machine); + rom_set_fw(s->fw_cfg); + + /* Compute the fdt load address in dram */ + fdt_load_addr =3D riscv_load_fdt(memmap[VIRT_DRAM].base, + machine->ram_size, machine->fdt); + /* load the reset vector */ + riscv_setup_rom_reset_vec(machine, &s->soc[0], start_addr, + virt_memmap[VIRT_MROM].base, + virt_memmap[VIRT_MROM].size, kernel_entry, + fdt_load_addr, machine->fdt); + + /* + * Only direct boot kernel is currently supported for KVM VM, + * So here setup kernel start address and fdt address. + * TODO:Support firmware loading and integrate to TCG start + */ + if (kvm_enabled()) { + riscv_setup_direct_kernel(kernel_entry, fdt_load_addr); + } +} + static void virt_machine_init(MachineState *machine) { const MemMapEntry *memmap =3D virt_memmap; @@ -1163,10 +1252,6 @@ static void virt_machine_init(MachineState *machine) MemoryRegion *system_memory =3D get_system_memory(); MemoryRegion *mask_rom =3D g_new(MemoryRegion, 1); char *soc_name; - target_ulong start_addr =3D memmap[VIRT_DRAM].base; - target_ulong firmware_end_addr, kernel_start_addr; - uint32_t fdt_load_addr; - uint64_t kernel_entry; DeviceState *mmio_irqchip, *virtio_irqchip, *pcie_irqchip; int i, base_hartid, hart_count; =20 @@ -1296,92 +1381,12 @@ static void virt_machine_init(MachineState *machine) memory_region_add_subregion(system_memory, memmap[VIRT_DRAM].base, machine->ram); =20 - /* create device tree */ - create_fdt(s, memmap, machine->ram_size, machine->kernel_cmdline, - riscv_is_32bit(&s->soc[0])); - /* boot rom */ memory_region_init_rom(mask_rom, NULL, "riscv_virt_board.mrom", memmap[VIRT_MROM].size, &error_fatal); memory_region_add_subregion(system_memory, memmap[VIRT_MROM].base, mask_rom); =20 - /* - * Only direct boot kernel is currently supported for KVM VM, - * so the "-bios" parameter is ignored and treated like "-bios none" - * when KVM is enabled. - */ - if (kvm_enabled()) { - g_free(machine->firmware); - machine->firmware =3D g_strdup("none"); - } - - if (riscv_is_32bit(&s->soc[0])) { - firmware_end_addr =3D riscv_find_and_load_firmware(machine, - RISCV32_BIOS_BIN, start_addr, NULL); - } else { - firmware_end_addr =3D riscv_find_and_load_firmware(machine, - RISCV64_BIOS_BIN, start_addr, NULL); - } - - if (machine->kernel_filename) { - kernel_start_addr =3D riscv_calc_kernel_start_addr(&s->soc[0], - firmware_end_addr= ); - - kernel_entry =3D riscv_load_kernel(machine->kernel_filename, - kernel_start_addr, NULL); - - if (machine->initrd_filename) { - hwaddr start; - hwaddr end =3D riscv_load_initrd(machine->initrd_filename, - machine->ram_size, kernel_entry, - &start); - qemu_fdt_setprop_cell(machine->fdt, "/chosen", - "linux,initrd-start", start); - qemu_fdt_setprop_cell(machine->fdt, "/chosen", "linux,initrd-e= nd", - end); - } - } else { - /* - * If dynamic firmware is used, it doesn't know where is the next m= ode - * if kernel argument is not set. - */ - kernel_entry =3D 0; - } - - if (drive_get(IF_PFLASH, 0, 0)) { - /* - * Pflash was supplied, let's overwrite the address we jump to aft= er - * reset to the base of the flash. - */ - start_addr =3D virt_memmap[VIRT_FLASH].base; - } - - /* - * Init fw_cfg. Must be done before riscv_load_fdt, otherwise the dev= ice - * tree cannot be altered and we get FDT_ERR_NOSPACE. - */ - s->fw_cfg =3D create_fw_cfg(machine); - rom_set_fw(s->fw_cfg); - - /* Compute the fdt load address in dram */ - fdt_load_addr =3D riscv_load_fdt(memmap[VIRT_DRAM].base, - machine->ram_size, machine->fdt); - /* load the reset vector */ - riscv_setup_rom_reset_vec(machine, &s->soc[0], start_addr, - virt_memmap[VIRT_MROM].base, - virt_memmap[VIRT_MROM].size, kernel_entry, - fdt_load_addr, machine->fdt); - - /* - * Only direct boot kernel is currently supported for KVM VM, - * So here setup kernel start address and fdt address. - * TODO:Support firmware loading and integrate to TCG start - */ - if (kvm_enabled()) { - riscv_setup_direct_kernel(kernel_entry, fdt_load_addr); - } - /* SiFive Test MMIO device */ sifive_test_create(memmap[VIRT_TEST].base); =20 @@ -1417,6 +1422,13 @@ static void virt_machine_init(MachineState *machine) drive_get(IF_PFLASH, 0, i)); } virt_flash_map(s, system_memory); + + /* create device tree */ + create_fdt(s, memmap, machine->ram_size, machine->kernel_cmdline, + riscv_is_32bit(&s->soc[0])); + + s->machine_done.notify =3D virt_machine_done; + qemu_add_machine_init_done_notifier(&s->machine_done); } =20 static void virt_machine_instance_init(Object *obj) --=20 2.35.1 From nobody Sat May 4 19:39:42 2024 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; dmarc=fail(p=quarantine dis=quarantine) header.from=opensource.wdc.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1650435545195140.12789552343713; Tue, 19 Apr 2022 23:19:05 -0700 (PDT) Received: from localhost ([::1]:42866 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nh3g7-0002L3-Uw for importer@patchew.org; Wed, 20 Apr 2022 02:19:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33800) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nh3H5-0007uj-Ly for qemu-devel@nongnu.org; Wed, 20 Apr 2022 01:53:11 -0400 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:55182) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nh3H3-0004SH-Ub for qemu-devel@nongnu.org; Wed, 20 Apr 2022 01:53:11 -0400 Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 20 Apr 2022 13:53:08 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 19 Apr 2022 22:23:27 -0700 Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 19 Apr 2022 22:53:09 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4Kjqb82TWwz1SVp4 for ; Tue, 19 Apr 2022 22:53:08 -0700 (PDT) Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id pCiqcHI_BZST for ; Tue, 19 Apr 2022 22:53:07 -0700 (PDT) Received: from toolbox.wdc.com (unknown [10.225.165.119]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4Kjqb26s2cz1Rvlx; Tue, 19 Apr 2022 22:53:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1650433989; x=1681969989; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MDWFWDRchKuYdI+t20XFRd6iszdOc+o4yz5MgNB95Fg=; b=cZwit/lC8uJT7m2s5QUsKggJ0rRstfZy/Vfixy+FttvY2JtlVj93Lbz+ AhLyuC5zwLss3abR2U1OuXbpJOnYpsigZS16bhFrL0cOjv8KIJpobyUSV ylunwSXNFiy3ddvw50zNwFKpno6nlu5Crenhrh8mfe/RHIqZgbfRSYWCT MfHS+V5KbzRCFpRaNksCfGzAxAT2d6hi+4x784vWHPPGSkUbnzNoffYuI rREzfxcM8aLWf/MFEaRsHT4RO1SWvL5ts6qp7caj59DfXf4OI0oTYdGZB Q9g71WJaP8xd0lGnCdRqJYITu3/TVE8dYQGairTeGd1ll9qKzCm9nNXSM A==; X-IronPort-AV: E=Sophos;i="5.90,274,1643644800"; d="scan'208";a="302527750" IronPort-SDR: 0ZIxWiReQn+SUwTEs7gCwNDR2PcbCHMuV3EP6644FlIfsMGzY0Jmumy00e+iC2zrL75Y2umS7f z6SfQqmFRlIydcRrPU4701uVgiTYFGmJ/YySTh0jA242EOSOoFbLGSjBbPWjN6QfpOlkfgAi1V o4GdTP/uM3SsqkNK5JcOpDIbpbVHcbQO+0QmqhB9YBP6YM/e0nmC0wYPgLiBycoRyr0Zm0q3dN q67bGibKGIK1ydzQnZocAwhaoZjEooevgdx7dcA9iKi4XHKKX38Xi0reLtH/gnExiU5Wro1zqG 7lSitzffg3Yi8mWKGGwFw8PF IronPort-SDR: XpPoqSYEN/emjPq1VtHU9EVK6yIpC8r87L+q5BfH9/+7ASwf9JLiAAzDoOfnHpNA3HTwbAtI9j ONCTeW4xqd831Kx1fUaHUW70cHKnsCGCpA/GC8G2jwTjYGg4wQjH+9viaTrqFlGtP7OCdu9gQM ex3uTV17Shx33fmB2854saVjaiwT4E9W+rhrCfvDneDq+xeGuLYow12r0G1Xm7R4ZcR9LxgGQC wuGfW62OY68Ij2/C8Vtj63FwBcXsRowMqRUPVoaNVtbgPXxF+fYb+OBlDwZJAZFlhmx9BEBqyn sSU= WDCIronportException: Internal Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1650433987; x=1653025988; bh=MDWFWDRchKuYdI+t20 XFRd6iszdOc+o4yz5MgNB95Fg=; b=QDWX1ErG+3VH3ItPU+6izieqKcQ7qdOfb4 PKTgsNpYjReLUVeZBL0pNQPEOXngG3x1oc+0yY29m5lrmg49Bq7zljQsWFIYkZd4 LxHQjjFYsE2cUrtFwCgx9A25IkDM8vZYewAXfhHvG3BTk6zWfdt9c1SlBgrFQ9Gs IzNLkjJZqFooG9AcSAHXY/rUj73HPze0ggwnOY8L+j7MJCBvYuDNg6h2qIeO+neQ fYbNC55Ssd02VsoYCM7+G7vjrgsVvqEujS4wgUSqOvUWuIWEpS3moITX/SYA2ngD zXF3ctX3d7dQ27Gmlba6mD/RbkllYZtXGE8bVLTK4PrckDyeLRcw== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com From: Alistair Francis To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: Palmer Dabbelt , Alistair Francis , alistair23@gmail.com, Bin Meng , Alistair Francis , qemu-arm@nongnu.org, Peter Maydell , bmeng.cn@gmail.com, "Edgar E. Iglesias" Subject: [PATCH v4 2/6] hw/core: Move the ARM sysbus-fdt to core Date: Wed, 20 Apr 2022 15:52:44 +1000 Message-Id: <20220420055248.960491-3-alistair.francis@opensource.wdc.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220420055248.960491-1-alistair.francis@opensource.wdc.com> References: <20220420055248.960491-1-alistair.francis@opensource.wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=lists.gnu.org; Received-SPF: pass client-ip=68.232.143.124; envelope-from=prvs=1021dae20=alistair.francis@opensource.wdc.com; helo=esa2.hgst.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1650435545899100001 Content-Type: text/plain; charset="utf-8" From: Alistair Francis The ARM virt machine currently uses sysbus-fdt to create device tree entries for dynamically created MMIO devices. The RISC-V virt machine can also benefit from this, so move the code to the core directory. Signed-off-by: Alistair Francis Reviewed-by: Edgar E. Iglesias Reviewed-by: Bin Meng --- include/hw/{arm =3D> core}/sysbus-fdt.h | 0 hw/arm/virt.c | 2 +- hw/arm/xlnx-versal-virt.c | 1 - hw/{arm =3D> core}/sysbus-fdt.c | 2 +- hw/arm/meson.build | 1 - hw/core/meson.build | 1 + 6 files changed, 3 insertions(+), 4 deletions(-) rename include/hw/{arm =3D> core}/sysbus-fdt.h (100%) rename hw/{arm =3D> core}/sysbus-fdt.c (99%) diff --git a/include/hw/arm/sysbus-fdt.h b/include/hw/core/sysbus-fdt.h similarity index 100% rename from include/hw/arm/sysbus-fdt.h rename to include/hw/core/sysbus-fdt.h diff --git a/hw/arm/virt.c b/hw/arm/virt.c index d2e5ecd234..cfababa292 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -56,7 +56,7 @@ #include "qemu/module.h" #include "hw/pci-host/gpex.h" #include "hw/virtio/virtio-pci.h" -#include "hw/arm/sysbus-fdt.h" +#include "hw/core/sysbus-fdt.h" #include "hw/platform-bus.h" #include "hw/qdev-properties.h" #include "hw/arm/fdt.h" diff --git a/hw/arm/xlnx-versal-virt.c b/hw/arm/xlnx-versal-virt.c index 7c7baff8b7..bc20af4ba8 100644 --- a/hw/arm/xlnx-versal-virt.c +++ b/hw/arm/xlnx-versal-virt.c @@ -15,7 +15,6 @@ #include "sysemu/device_tree.h" #include "hw/boards.h" #include "hw/sysbus.h" -#include "hw/arm/sysbus-fdt.h" #include "hw/arm/fdt.h" #include "cpu.h" #include "hw/qdev-properties.h" diff --git a/hw/arm/sysbus-fdt.c b/hw/core/sysbus-fdt.c similarity index 99% rename from hw/arm/sysbus-fdt.c rename to hw/core/sysbus-fdt.c index 48c5fe9bf1..19d22cbe73 100644 --- a/hw/arm/sysbus-fdt.c +++ b/hw/core/sysbus-fdt.c @@ -27,7 +27,7 @@ #ifdef CONFIG_LINUX #include #endif -#include "hw/arm/sysbus-fdt.h" +#include "hw/core/sysbus-fdt.h" #include "qemu/error-report.h" #include "sysemu/device_tree.h" #include "sysemu/tpm.h" diff --git a/hw/arm/meson.build b/hw/arm/meson.build index 721a8eb8be..122e5dd992 100644 --- a/hw/arm/meson.build +++ b/hw/arm/meson.build @@ -1,6 +1,5 @@ arm_ss =3D ss.source_set() arm_ss.add(files('boot.c'), fdt) -arm_ss.add(when: 'CONFIG_PLATFORM_BUS', if_true: files('sysbus-fdt.c')) arm_ss.add(when: 'CONFIG_ARM_VIRT', if_true: files('virt.c')) arm_ss.add(when: 'CONFIG_ACPI', if_true: files('virt-acpi-build.c')) arm_ss.add(when: 'CONFIG_DIGIC', if_true: files('digic_boards.c')) diff --git a/hw/core/meson.build b/hw/core/meson.build index 0f884d6fd4..7a4d02b6c0 100644 --- a/hw/core/meson.build +++ b/hw/core/meson.build @@ -33,6 +33,7 @@ softmmu_ss.add(when: 'CONFIG_PTIMER', if_true: files('pti= mer.c')) softmmu_ss.add(when: 'CONFIG_REGISTER', if_true: files('register.c')) softmmu_ss.add(when: 'CONFIG_SPLIT_IRQ', if_true: files('split-irq.c')) softmmu_ss.add(when: 'CONFIG_XILINX_AXI', if_true: files('stream.c')) +softmmu_ss.add(when: 'CONFIG_PLATFORM_BUS', if_true: files('sysbus-fdt.c')) =20 softmmu_ss.add(files( 'cpu-sysemu.c', --=20 2.35.1 From nobody Sat May 4 19:39:42 2024 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; dmarc=fail(p=quarantine dis=quarantine) header.from=opensource.wdc.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1650435140167187.00127406349156; Tue, 19 Apr 2022 23:12:20 -0700 (PDT) Received: from localhost ([::1]:59420 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nh3Zb-0003m6-1M for importer@patchew.org; Wed, 20 Apr 2022 02:12:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33962) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nh3HJ-0008EC-3M for qemu-devel@nongnu.org; Wed, 20 Apr 2022 01:53:25 -0400 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:13184) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nh3HH-0004UQ-5b for qemu-devel@nongnu.org; Wed, 20 Apr 2022 01:53:24 -0400 Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 20 Apr 2022 13:53:18 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 19 Apr 2022 22:24:17 -0700 Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 19 Apr 2022 22:53:14 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4KjqbF13NHz1SVp1 for ; Tue, 19 Apr 2022 22:53:13 -0700 (PDT) Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id BpluIYJRISV8 for ; Tue, 19 Apr 2022 22:53:12 -0700 (PDT) Received: from toolbox.wdc.com (unknown [10.225.165.119]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4Kjqb80LZ2z1Rwrw; Tue, 19 Apr 2022 22:53:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1650434003; x=1681970003; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=e2Z1mPMjuALcbIIiDbdx4iqIL8NEKphMfAicrXHlSr0=; b=Z3+pd43cRcw6FiTpzdcbkCY3GcM/DmN4SytkHS9BEOIR8PbuB+PfDW8J sy/qekpKAS0+eiu4BbbmWQiJHSGwl7kIR9jEjjejruG7VvCzorF62coq+ 4pbuItwdZNTgiYf8/9jJvfFRKqk4YtgPfKNFP+iQT2X8T0r2xk/Uo0xIg PCC2PM9tvSnR4nWi+8CaVbiXEYm8kEnsEc4qkdzcyxeIvJq+gmX399Vip AdUTls8+4uT4SPkVD14vVd0zQy1tIo1SZFPozzZXC2uk28ZYVQesELMaS xilqLNKg1GU9YDqv14iavCGNvn7Lf+/2nG6VZKxy9E/iy3Q4SYZcJtoC/ w==; X-IronPort-AV: E=Sophos;i="5.90,274,1643644800"; d="scan'208";a="199228719" IronPort-SDR: 0VHhUOUJ6N/1XWesE0fv14cvg7f6i9K6C/HKyVaGSALCFTLyzWtB9y3RwPxveFlOvzPP+C1bMR gySAbD1RWZjFOssPwgJvjc2i1xbdwP0niyN8IFnVX5VTJcxe3J6k/vQ6k+00yfOFmhsWDKEMuC zfY5/k+q1qQgsRec7WtXPwNIIJc56cnvc1J+De530gh9m7I8kudazUxmbDFHNbvu9Wcf2xitLm RfegHHNEeCCjogBC8Yokn6CZ8XBR+0YXjKatqt1eNmxDIEIk2k0D1ndlRz55pfFrPM/kMRJk17 oqE= IronPort-SDR: xq1H8eRX1E0XrqGSULumCS/msUKtMbv55utdEs6EcDfo4+oB7XQPOiRYYxeMaJirA6pgXBee81 kc09k7cJ0ifOBtzQY/r0ViquR5z+upyyiCZo09impsfjc/V9D6US53XxHlCIbpnI/tI5fEPuU5 FjwkQ3lm5CImKD3IIdBMnXKBEXvECZqeu3BAdp+YyoUo3lzvjltphPyfMjmfCbJnIw9fO2W/HE Y5QoUGJm/rLWnDDU/TEaupICEV6ggqBM20rLAO09fKr3rGFOESZeup/0HKVMU+Yv4iFDP9yfWF YpU= WDCIronportException: Internal Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1650433992; x=1653025993; bh=e2Z1mPMjuALcbIIiDb dx4iqIL8NEKphMfAicrXHlSr0=; b=DNbE90FZ7/spCVivuHuH8eyRnV7FCfHsGX kNA+5fpJYpSUn5q55drG7u1i03nUu/Dl6L5T0F+m9i0axizd6T62a+0OIwLDxw6Q VUO25umyGSwe/fTxIIiRP+jVDsW5obI+kgo19aS+HclA8ZwKmZ2K0nLV1CPC9/FM Vf6HJHzumcIK1ykMM89lZxaSKYYTjxiWMLwTgW5uVWq8vtVms464pwSHOtKzLtP1 TNnaQPyKOyR3VQZYvu4gbgsZqsRgv6VJKSg+Z+bSeaN9NhPnlWPkUxkpb4SveMtp V/UqqfcgKDfR4OsbkVQ7LfcA7LUS93ZyFUUepFYuEnF22jK31+0g== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com From: Alistair Francis To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: Palmer Dabbelt , Alistair Francis , alistair23@gmail.com, Bin Meng , Alistair Francis , qemu-arm@nongnu.org, Peter Maydell , bmeng.cn@gmail.com, "Edgar E. Iglesias" Subject: [PATCH v4 3/6] hw/riscv: virt: Create a platform bus Date: Wed, 20 Apr 2022 15:52:45 +1000 Message-Id: <20220420055248.960491-4-alistair.francis@opensource.wdc.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220420055248.960491-1-alistair.francis@opensource.wdc.com> References: <20220420055248.960491-1-alistair.francis@opensource.wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=lists.gnu.org; Received-SPF: pass client-ip=216.71.154.45; envelope-from=prvs=1021dae20=alistair.francis@opensource.wdc.com; helo=esa6.hgst.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1650435141913100001 Content-Type: text/plain; charset="utf-8" From: Alistair Francis Create a platform bus to allow dynamic devices to be connected. This is based on the ARM implementation. Signed-off-by: Alistair Francis Reviewed-by: Edgar E. Iglesias Reviewed-by: Bin Meng --- include/hw/riscv/virt.h | 7 ++++- hw/riscv/virt.c | 68 +++++++++++++++++++++++++++++------------ hw/riscv/Kconfig | 1 + 3 files changed, 56 insertions(+), 20 deletions(-) diff --git a/include/hw/riscv/virt.h b/include/hw/riscv/virt.h index 8b8db3fb7c..984e55c77f 100644 --- a/include/hw/riscv/virt.h +++ b/include/hw/riscv/virt.h @@ -46,6 +46,7 @@ struct RISCVVirtState { =20 /*< public >*/ Notifier machine_done; + DeviceState *platform_bus_dev; RISCVHartArrayState soc[VIRT_SOCKETS_MAX]; DeviceState *irqchip[VIRT_SOCKETS_MAX]; PFlashCFI01 *flash[2]; @@ -76,6 +77,7 @@ enum { VIRT_DRAM, VIRT_PCIE_MMIO, VIRT_PCIE_PIO, + VIRT_PLATFORM_BUS, VIRT_PCIE_ECAM }; =20 @@ -85,9 +87,12 @@ enum { VIRTIO_IRQ =3D 1, /* 1 to 8 */ VIRTIO_COUNT =3D 8, PCIE_IRQ =3D 0x20, /* 32 to 35 */ - VIRTIO_NDEV =3D 0x35 /* Arbitrary maximum number of interrupts */ + VIRT_PLATFORM_BUS_IRQ =3D 64, /* 64 to 96 */ + VIRTIO_NDEV =3D 96 /* Arbitrary maximum number of interrupts */ }; =20 +#define VIRT_PLATFORM_BUS_NUM_IRQS 32 + #define VIRT_IRQCHIP_IPI_MSI 1 #define VIRT_IRQCHIP_NUM_MSIS 255 #define VIRT_IRQCHIP_NUM_SOURCES VIRTIO_NDEV diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index 3d48469367..169da70350 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -37,6 +37,7 @@ #include "hw/intc/riscv_imsic.h" #include "hw/intc/sifive_plic.h" #include "hw/misc/sifive_test.h" +#include "hw/platform-bus.h" #include "chardev/char.h" #include "sysemu/device_tree.h" #include "sysemu/sysemu.h" @@ -68,25 +69,26 @@ #endif =20 static const MemMapEntry virt_memmap[] =3D { - [VIRT_DEBUG] =3D { 0x0, 0x100 }, - [VIRT_MROM] =3D { 0x1000, 0xf000 }, - [VIRT_TEST] =3D { 0x100000, 0x1000 }, - [VIRT_RTC] =3D { 0x101000, 0x1000 }, - [VIRT_CLINT] =3D { 0x2000000, 0x10000 }, - [VIRT_ACLINT_SSWI] =3D { 0x2F00000, 0x4000 }, - [VIRT_PCIE_PIO] =3D { 0x3000000, 0x10000 }, - [VIRT_PLIC] =3D { 0xc000000, VIRT_PLIC_SIZE(VIRT_CPUS_MAX * 2)= }, - [VIRT_APLIC_M] =3D { 0xc000000, APLIC_SIZE(VIRT_CPUS_MAX) }, - [VIRT_APLIC_S] =3D { 0xd000000, APLIC_SIZE(VIRT_CPUS_MAX) }, - [VIRT_UART0] =3D { 0x10000000, 0x100 }, - [VIRT_VIRTIO] =3D { 0x10001000, 0x1000 }, - [VIRT_FW_CFG] =3D { 0x10100000, 0x18 }, - [VIRT_FLASH] =3D { 0x20000000, 0x4000000 }, - [VIRT_IMSIC_M] =3D { 0x24000000, VIRT_IMSIC_MAX_SIZE }, - [VIRT_IMSIC_S] =3D { 0x28000000, VIRT_IMSIC_MAX_SIZE }, - [VIRT_PCIE_ECAM] =3D { 0x30000000, 0x10000000 }, - [VIRT_PCIE_MMIO] =3D { 0x40000000, 0x40000000 }, - [VIRT_DRAM] =3D { 0x80000000, 0x0 }, + [VIRT_DEBUG] =3D { 0x0, 0x100 }, + [VIRT_MROM] =3D { 0x1000, 0xf000 }, + [VIRT_TEST] =3D { 0x100000, 0x1000 }, + [VIRT_RTC] =3D { 0x101000, 0x1000 }, + [VIRT_CLINT] =3D { 0x2000000, 0x10000 }, + [VIRT_ACLINT_SSWI] =3D { 0x2F00000, 0x4000 }, + [VIRT_PCIE_PIO] =3D { 0x3000000, 0x10000 }, + [VIRT_PLATFORM_BUS] =3D { 0x4000000, 0x2000000 }, + [VIRT_PLIC] =3D { 0xc000000, VIRT_PLIC_SIZE(VIRT_CPUS_MAX * 2= ) }, + [VIRT_APLIC_M] =3D { 0xc000000, APLIC_SIZE(VIRT_CPUS_MAX) }, + [VIRT_APLIC_S] =3D { 0xd000000, APLIC_SIZE(VIRT_CPUS_MAX) }, + [VIRT_UART0] =3D { 0x10000000, 0x100 }, + [VIRT_VIRTIO] =3D { 0x10001000, 0x1000 }, + [VIRT_FW_CFG] =3D { 0x10100000, 0x18 }, + [VIRT_FLASH] =3D { 0x20000000, 0x4000000 }, + [VIRT_IMSIC_M] =3D { 0x24000000, VIRT_IMSIC_MAX_SIZE }, + [VIRT_IMSIC_S] =3D { 0x28000000, VIRT_IMSIC_MAX_SIZE }, + [VIRT_PCIE_ECAM] =3D { 0x30000000, 0x10000000 }, + [VIRT_PCIE_MMIO] =3D { 0x40000000, 0x40000000 }, + [VIRT_DRAM] =3D { 0x80000000, 0x0 }, }; =20 /* PCIe high mmio is fixed for RV32 */ @@ -1156,6 +1158,32 @@ static DeviceState *virt_create_aia(RISCVVirtAIAType= aia_type, int aia_guests, return aplic_m; } =20 +static void create_platform_bus(RISCVVirtState *s, DeviceState *irqchip) +{ + DeviceState *dev; + SysBusDevice *sysbus; + const MemMapEntry *memmap =3D virt_memmap; + int i; + MemoryRegion *sysmem =3D get_system_memory(); + + dev =3D qdev_new(TYPE_PLATFORM_BUS_DEVICE); + dev->id =3D g_strdup(TYPE_PLATFORM_BUS_DEVICE); + qdev_prop_set_uint32(dev, "num_irqs", VIRT_PLATFORM_BUS_NUM_IRQS); + qdev_prop_set_uint32(dev, "mmio_size", memmap[VIRT_PLATFORM_BUS].size); + sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); + s->platform_bus_dev =3D dev; + + sysbus =3D SYS_BUS_DEVICE(dev); + for (i =3D 0; i < VIRT_PLATFORM_BUS_NUM_IRQS; i++) { + int irq =3D VIRT_PLATFORM_BUS_IRQ + i; + sysbus_connect_irq(sysbus, i, qdev_get_gpio_in(irqchip, irq)); + } + + memory_region_add_subregion(sysmem, + memmap[VIRT_PLATFORM_BUS].base, + sysbus_mmio_get_region(sysbus, 0)); +} + static void virt_machine_done(Notifier *notifier, void *data) { @@ -1407,6 +1435,8 @@ static void virt_machine_init(MachineState *machine) memmap[VIRT_PCIE_PIO].base, DEVICE(pcie_irqchip)); =20 + create_platform_bus(s, DEVICE(mmio_irqchip)); + serial_mm_init(system_memory, memmap[VIRT_UART0].base, 0, qdev_get_gpio_in(DEVICE(mmio_irqchip), UART0_IRQ), 399193, serial_hd(0), DEVICE_LITTLE_ENDIAN); diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig index 91bb9d21c4..da790f5936 100644 --- a/hw/riscv/Kconfig +++ b/hw/riscv/Kconfig @@ -48,6 +48,7 @@ config RISCV_VIRT select SIFIVE_TEST select VIRTIO_MMIO select FW_CFG_DMA + select PLATFORM_BUS =20 config SIFIVE_E bool --=20 2.35.1 From nobody Sat May 4 19:39:42 2024 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; dmarc=fail(p=quarantine dis=quarantine) header.from=opensource.wdc.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1650434466275120.4069416030336; Tue, 19 Apr 2022 23:01:06 -0700 (PDT) Received: from localhost ([::1]:42830 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nh3Oi-0003ia-C8 for importer@patchew.org; Wed, 20 Apr 2022 02:01:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33908) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nh3HF-00087s-3f for qemu-devel@nongnu.org; Wed, 20 Apr 2022 01:53:21 -0400 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:55197) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nh3HD-0004UM-Bs for qemu-devel@nongnu.org; Wed, 20 Apr 2022 01:53:20 -0400 Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 20 Apr 2022 13:53:18 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 19 Apr 2022 22:23:36 -0700 Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 19 Apr 2022 22:53:19 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4KjqbK6BjGz1SVp5 for ; Tue, 19 Apr 2022 22:53:17 -0700 (PDT) Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id XJrQ0zUr9wfX for ; Tue, 19 Apr 2022 22:53:16 -0700 (PDT) Received: from toolbox.wdc.com (unknown [10.225.165.119]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4KjqbD5z5Hz1Rvlx; Tue, 19 Apr 2022 22:53:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1650433999; x=1681969999; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=H2nNCdBlGkbhKY2PzS9ttJJUrgi/BvPdzYzwwCBJy3c=; b=SYOwvqg30ba2gz6ogsHnvTsIYlkwW4bT7Rv4eE9iLlnCpZi3gNtreh3G p/gZ4O9cLX9l5WSF+dq/GQkPcSveeeB35mORaOl+nVMpFA59hVSWxTKfx OCyqGKOcXJNRDtqbxFplB9FSgxt1yqvPOtWTBFM/PMxwcdzef69m7psSP 8K0AtZgBarvH0Ro0/W7p6MjbJ5kPO9rbbA61z4w7oehrZgXHTZmp4cBi3 Q8E2gzMLZlEBMQitHROkGf6taNtPNDwP6UdWip/jruzBdMVkvXaYlXdum pG7q5vGS6nrB68l+1Q7sxo2DcsjWYGEqBUst51hzz+wcGpTRMAI7JqwSJ w==; X-IronPort-AV: E=Sophos;i="5.90,274,1643644800"; d="scan'208";a="302527765" IronPort-SDR: QjiDCXgB8sxdx5zPtlOPCaArvGEqp/RjoYzSZH8djRhKJrD+mO2HDfGkbpgVzdufFVjPJBebOR PtEG5ngwd362uC4PHMmu9pFOJVWAVuw+A+fKN2e6WU/ccM1RNpugYPaY3SLL0sSDHMJHDPoxVM rP8WUBSGc8/9MAsSPasuaZsERWqtViaKqF94Zy8MIS3fc1BwNbZa9wnPadVl50uQYlLDKTtvJB /LszuQp2iFJeDoKCuz2V8fR0Sx50uLpItxQvjTQqxqsjz5chLmm9zTWE1dn5dYMuWz2iYPvpwn GzEL0Zh98KqxWtsDP5GoIMY/ IronPort-SDR: k5/fXTs3Z5OtP/8LVc/4WyAkOOtMZNOAkn6BaTWgd6jT9qwZcByMadhT+9nRm+cfdGcpNpQipS f4PaEgpbuVEKNJmmCU3xNkVpuzYHjrkU9YTrlavFxtebVsbOULgchfN0TKy+Tk88Bp/fygLnef +VLGwRLdgpKGg0Y0+Yw0qxflB/4Fg9QulIxhxFLsVbh1PkEGS0+l2A+zLoH5g3UDsdw6wlFS/q q1f7UsPChwIS8Ad0lxenkAtTwddhK2/SyxWvE3Vi+gTjiWvCe0zzvBrODcMeLDxLBr56DEbNBc z6A= WDCIronportException: Internal Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1650433996; x=1653025997; bh=H2nNCdBlGkbhKY2PzS 9ttJJUrgi/BvPdzYzwwCBJy3c=; b=X+AG6YvsPIzNR5ltI+/gUovOJi/GZypjTN TxSa/XjB5takiG0o/DHZ4H5u+nFj/rQYMvhaTbdkm41/6dMtR6fIMP4ZaiTEzsnb LQuf9jg7uR7H/MmG7wXN5bCvcSWkVa0F1nZHg/Bt7/L+eSfYsh4+YytJHyAVR5tc kj3v97TziTYZOFtRaySyzP/QS0CgZHrRLj343QPvPI7WxUM/WOwI1TyShopty8DJ U19sgl2q9QVlRq8LbxxrAKkWrgPmD6tRfj0vJc53Z06OehbYAjt8gUIKQ+Ma+gPZ pkOM/T2VBTHtdJoM0YYO9YDPcAXP1ZP5jFjvMEVpdFYOYnaTUDgQ== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com From: Alistair Francis To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: Palmer Dabbelt , Alistair Francis , alistair23@gmail.com, Bin Meng , Alistair Francis , qemu-arm@nongnu.org, Peter Maydell , bmeng.cn@gmail.com, "Edgar E. Iglesias" Subject: [PATCH v4 4/6] hw/riscv: virt: Add support for generating platform FDT entries Date: Wed, 20 Apr 2022 15:52:46 +1000 Message-Id: <20220420055248.960491-5-alistair.francis@opensource.wdc.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220420055248.960491-1-alistair.francis@opensource.wdc.com> References: <20220420055248.960491-1-alistair.francis@opensource.wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=lists.gnu.org; Received-SPF: pass client-ip=68.232.143.124; envelope-from=prvs=1021dae20=alistair.francis@opensource.wdc.com; helo=esa2.hgst.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1650434467926100001 Content-Type: text/plain; charset="utf-8" From: Alistair Francis Similar to the ARM virt machine add support for adding device tree entries for dynamically created devices. Signed-off-by: Alistair Francis Reviewed-by: Edgar E. Iglesias --- hw/riscv/virt.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index 169da70350..e4a5c6c28b 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -28,6 +28,7 @@ #include "hw/qdev-properties.h" #include "hw/char/serial.h" #include "target/riscv/cpu.h" +#include "hw/core/sysbus-fdt.h" #include "hw/riscv/riscv_hart.h" #include "hw/riscv/virt.h" #include "hw/riscv/boot.h" @@ -411,6 +412,12 @@ static void create_fdt_socket_aclint(RISCVVirtState *s, qemu_fdt_setprop(mc->fdt, name, "interrupt-controller", NULL, 0); qemu_fdt_setprop_cell(mc->fdt, name, "#interrupt-cells", 0); riscv_socket_fdt_write_id(mc, mc->fdt, name, socket); + + platform_bus_add_all_fdt_nodes(mc->fdt, name, + memmap[VIRT_PLATFORM_BUS].base, + memmap[VIRT_PLATFORM_BUS].size, + VIRT_PLATFORM_BUS_IRQ); + g_free(name); } =20 @@ -469,6 +476,12 @@ static void create_fdt_socket_plic(RISCVVirtState *s, riscv_socket_fdt_write_id(mc, mc->fdt, plic_name, socket); qemu_fdt_setprop_cell(mc->fdt, plic_name, "phandle", plic_phandles[socket]); + + platform_bus_add_all_fdt_nodes(mc->fdt, plic_name, + memmap[VIRT_PLATFORM_BUS].base, + memmap[VIRT_PLATFORM_BUS].size, + VIRT_PLATFORM_BUS_IRQ); + g_free(plic_name); =20 g_free(plic_cells); @@ -546,6 +559,12 @@ static void create_fdt_imsic(RISCVVirtState *s, const = MemMapEntry *memmap, IMSIC_MMIO_GROUP_MIN_SHIFT); } qemu_fdt_setprop_cell(mc->fdt, imsic_name, "phandle", *msi_m_phandle); + + platform_bus_add_all_fdt_nodes(mc->fdt, imsic_name, + memmap[VIRT_PLATFORM_BUS].base, + memmap[VIRT_PLATFORM_BUS].size, + VIRT_PLATFORM_BUS_IRQ); + g_free(imsic_name); =20 /* S-level IMSIC node */ @@ -683,6 +702,12 @@ static void create_fdt_socket_aplic(RISCVVirtState *s, VIRT_IRQCHIP_NUM_SOURCES); riscv_socket_fdt_write_id(mc, mc->fdt, aplic_name, socket); qemu_fdt_setprop_cell(mc->fdt, aplic_name, "phandle", aplic_s_phandle); + + platform_bus_add_all_fdt_nodes(mc->fdt, aplic_name, + memmap[VIRT_PLATFORM_BUS].base, + memmap[VIRT_PLATFORM_BUS].size, + VIRT_PLATFORM_BUS_IRQ); + g_free(aplic_name); =20 g_free(aplic_cells); --=20 2.35.1 From nobody Sat May 4 19:39:42 2024 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; dmarc=fail(p=quarantine dis=quarantine) header.from=opensource.wdc.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1650435378125906.4831493659965; Tue, 19 Apr 2022 23:16:18 -0700 (PDT) Received: from localhost ([::1]:38794 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nh3dR-0008Jl-5B for importer@patchew.org; Wed, 20 Apr 2022 02:16:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34020) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nh3HM-0008K4-7K for qemu-devel@nongnu.org; Wed, 20 Apr 2022 01:53:28 -0400 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:13190) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nh3HK-0004VK-6G for qemu-devel@nongnu.org; Wed, 20 Apr 2022 01:53:27 -0400 Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 20 Apr 2022 13:53:23 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 19 Apr 2022 22:24:27 -0700 Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 19 Apr 2022 22:53:23 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4KjqbQ5bnMz1SVpC for ; Tue, 19 Apr 2022 22:53:22 -0700 (PDT) Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id P5-d5qPVS4fs for ; Tue, 19 Apr 2022 22:53:21 -0700 (PDT) Received: from toolbox.wdc.com (unknown [10.225.165.119]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4KjqbK4Kntz1Rwrw; Tue, 19 Apr 2022 22:53:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1650434006; x=1681970006; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8cubxdE+5rkaf0Cjh3SiUez+sCYKeMPtlbdA9NTcPVM=; b=ms0euG66Nn24jlQvHjegf8EIWsNgJTH9h0TUv2SJDSGTKHCo7bQFdHCN sEdNzz2TmHn52ZQHanFm4XGibcSmi5dkewsRhnQ4+X9cCwb9E046rULCY GcEYQGFwuqHYkR3SRVboiZUTCwsMBtehyWcBa9BjLQhQ/o+Bukq3DuQII vpk0OkEzdeuHXkIHIIvYXkTSuGHNirO83GuXI8eAGbxnwy90jv4jTFL/R 4azVvfOwkzwoMMmDCNS48UM6cmNKTKGdu4sLKPHtrQsb/I8pp1B47gzj6 pxfJjtN2/DlTgEFMsHCWJdMfHORFoLYzQbakaLzbHBeQvgfJnz6oPmnIO w==; X-IronPort-AV: E=Sophos;i="5.90,274,1643644800"; d="scan'208";a="199228723" IronPort-SDR: 64vecbpmTx6Kx4tj38nEmWvBJeIZCp6dpn5YDHspaiNY+q6d3Ap3zX3ITqtZEJnD4SZ9+dQQ0a XWAjAQiLpwvjZBIWK0DHCQMleDMAF+c37uaU2B8eTp2xbFJPI8eK50yKhqzIUe5JABMbfUtkLh 16x4UjvSfh3Ov1vPicP1s0HaBQfN2nGf0FtJbDClXMl+IYRpiOTCyFvdHZLxbd1jb/rZg/hZGQ buRk5XXdLKho01sMmlfkQM5PUvQV28pLRUE5ord3MPZy4as84UKFeIXYGN8UQRG+MWbyeXWXUh I4blKBxzjzJ2ZmvZITT4tTRK IronPort-SDR: S5mA9CwoafHBqUXhDHL+lhMIpdo+C+pdTwK26S4pUJ3Tao80Wh0VEzB6aD09PjSVdVA0ZU4MwS Q1C+iGZtTY5dXOgZSDKjomXNVDjY4yNIAEVlWoyyTs69HVi8g6UOmjB4j/LAScPraXQUTDanTt SsRcnmrFobFtaEq0g5OPhuxHXSW5b6YxWWa/0ZX8y6LkdkgkOW5U4PpGONQ8fszLorKXOUi8ib oBOgDefVuPsFvPQFPFuZLH3hgUwwPomM+q78y02IBChjUBlGbRxFwrydBhtFVhOAJ+tCZ0YFgV mss= WDCIronportException: Internal Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1650434001; x=1653026002; bh=8cubxdE+5rkaf0Cjh3 SiUez+sCYKeMPtlbdA9NTcPVM=; b=kUi/OCtqePGP+chTWFNFpktuiG6/mjZ0hi 51onv+2fpgz5O4wgSCHDnK7DA3SHAnmpOhRSBVjoTlNUb7XNPzEby2rw9zrvAH6K i85210kfrWjGD6QCnTeUycoB8xyntQ78Msa9aoAOAQEUi5pTrEkscmGaPpd1jFbw c9JidQkGx/02KV6RNOsjmzU3Tb91LIdcCRHQmEkkHvS7t7IMcx0EZE05KZ9Kuw9H N2ybcen1dPHzPnofQI1nYhPlXgQFV6iusS89gEP394EJsXAHuhznTjzhux2CNnoX FC5VhHA2SHPbjs1qu5OJBkq/iQU0N0uxdcMHxSWtmmPkbg+nXusQ== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com From: Alistair Francis To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: Palmer Dabbelt , Alistair Francis , alistair23@gmail.com, Bin Meng , Alistair Francis , qemu-arm@nongnu.org, Peter Maydell , bmeng.cn@gmail.com, "Edgar E. Iglesias" Subject: [PATCH v4 5/6] hw/riscv: virt: Add device plug support Date: Wed, 20 Apr 2022 15:52:47 +1000 Message-Id: <20220420055248.960491-6-alistair.francis@opensource.wdc.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220420055248.960491-1-alistair.francis@opensource.wdc.com> References: <20220420055248.960491-1-alistair.francis@opensource.wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=lists.gnu.org; Received-SPF: pass client-ip=216.71.154.45; envelope-from=prvs=1021dae20=alistair.francis@opensource.wdc.com; helo=esa6.hgst.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1650435379036100001 Content-Type: text/plain; charset="utf-8" From: Alistair Francis Add support for plugging in devices, this was tested with the TPM device. Signed-off-by: Alistair Francis Reviewed-by: Edgar E. Iglesias Reviewed-by: Bin Meng --- hw/riscv/virt.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index e4a5c6c28b..6eed1f4d70 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -1564,10 +1564,37 @@ static void virt_set_aclint(Object *obj, bool value= , Error **errp) s->have_aclint =3D value; } =20 +static HotplugHandler *virt_machine_get_hotplug_handler(MachineState *mach= ine, + DeviceState *dev) +{ + MachineClass *mc =3D MACHINE_GET_CLASS(machine); + + if (device_is_dynamic_sysbus(mc, dev)) { + return HOTPLUG_HANDLER(machine); + } + return NULL; +} + +static void virt_machine_device_plug_cb(HotplugHandler *hotplug_dev, + DeviceState *dev, Error **errp) +{ + RISCVVirtState *s =3D RISCV_VIRT_MACHINE(hotplug_dev); + + if (s->platform_bus_dev) { + MachineClass *mc =3D MACHINE_GET_CLASS(s); + + if (device_is_dynamic_sysbus(mc, dev)) { + platform_bus_link_device(PLATFORM_BUS_DEVICE(s->platform_bus_d= ev), + SYS_BUS_DEVICE(dev)); + } + } +} + static void virt_machine_class_init(ObjectClass *oc, void *data) { char str[128]; MachineClass *mc =3D MACHINE_CLASS(oc); + HotplugHandlerClass *hc =3D HOTPLUG_HANDLER_CLASS(oc); =20 mc->desc =3D "RISC-V VirtIO board"; mc->init =3D virt_machine_init; @@ -1579,6 +1606,10 @@ static void virt_machine_class_init(ObjectClass *oc,= void *data) mc->get_default_cpu_node_id =3D riscv_numa_get_default_cpu_node_id; mc->numa_mem_supported =3D true; mc->default_ram_id =3D "riscv_virt_board.ram"; + assert(!mc->get_hotplug_handler); + mc->get_hotplug_handler =3D virt_machine_get_hotplug_handler; + + hc->plug =3D virt_machine_device_plug_cb; =20 machine_class_allow_dynamic_sysbus_dev(mc, TYPE_RAMFB_DEVICE); =20 @@ -1609,6 +1640,10 @@ static const TypeInfo virt_machine_typeinfo =3D { .class_init =3D virt_machine_class_init, .instance_init =3D virt_machine_instance_init, .instance_size =3D sizeof(RISCVVirtState), + .interfaces =3D (InterfaceInfo[]) { + { TYPE_HOTPLUG_HANDLER }, + { } + }, }; =20 static void virt_machine_init_register_types(void) --=20 2.35.1 From nobody Sat May 4 19:39:42 2024 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; dmarc=fail(p=quarantine dis=quarantine) header.from=opensource.wdc.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1650435992658373.00167235132244; Tue, 19 Apr 2022 23:26:32 -0700 (PDT) Received: from localhost ([::1]:53538 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nh3nL-0000kZ-CB for importer@patchew.org; Wed, 20 Apr 2022 02:26:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34062) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nh3HO-0008OZ-9v for qemu-devel@nongnu.org; Wed, 20 Apr 2022 01:53:30 -0400 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:13184) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nh3HM-0004UQ-AN for qemu-devel@nongnu.org; Wed, 20 Apr 2022 01:53:30 -0400 Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 20 Apr 2022 13:53:28 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 19 Apr 2022 22:24:31 -0700 Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 19 Apr 2022 22:53:28 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4KjqbW2FzMz1SVp0 for ; Tue, 19 Apr 2022 22:53:27 -0700 (PDT) Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 8sx0BcT9Db0K for ; Tue, 19 Apr 2022 22:53:26 -0700 (PDT) Received: from toolbox.wdc.com (unknown [10.225.165.119]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4KjqbQ3JCnz1SVnx; Tue, 19 Apr 2022 22:53:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1650434008; x=1681970008; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=54LNDcv7kZB26uhwQDpQcWJg6cxn2r4zaQ0u9RhnAYA=; b=gKXuwgio0l3tMGsKYqU3my80jDQc5eHJgqjJ/NT5LptS68mU9fOFm18B irGkljBtzD5XYe9nrBT1GLFXTMIYAYnJiR3M2dRBVNCcKRP+DM0gq+apg xb/uPXc+ym/xqKTI3Xxw2Ta53N0i0rrv6pUsgh/TZKcnfe+Pl9VkOU6rm /UgsQe4VnsefuGB5jspgHwDUkxzgaYnMgB/mp9T7gBKNWSgsG/F/W7beP czRwzK0CDk9hImZX+m6ejhcLsLpFAcd15u52wlI4ikWorp4xrAtMz8Xs8 YDij1sxQIynwc1n6scivEeorPal/U+hyAhfRjrWFhcnEBf7qXY9RE3bVJ g==; X-IronPort-AV: E=Sophos;i="5.90,274,1643644800"; d="scan'208";a="199228727" IronPort-SDR: enG8ZeUcGlRbjnqKpElHOseJHHfY87P4C56uD4c3svvz8/dynZqd5gtbPFszCYM6Qy9wBER1IK PncIAJ3t3jckMRNEvJCUhLXu4MPw+/XrWtjxL7Ek9JrfYgG79yFPx284Qq0Hcuc1+5q2dKC4a4 zoKs7pobJY3VuSrXBkKW6GOZPi6pbS2G7BCr8vxC4pOx4gvx5tUV0MjLn/OHKIwOtKE+BVpl/w 8CbsYJXXubWEoft8Q1jEciKc6uzS5skQfK/OgKMYt0mBgbkhzJ/p4KPYimx3Copzeff3yaHLfi w6FteeXNAZ/5/Gp/3LbPvXmC IronPort-SDR: fm2Oq/s4pMajUSwvRJwvwkg9uOW4ZMSv7sNIjGdQyXyISnnzHjV0z+MesBvTKhNF8DLF25Oz9w EgkJekE4eRZWBXz3HUr1o0AJjbRcpRYZPPwGEKIENM8aVXi0dENt/0IAsFC0VkhRaNOD6+V4hY 5vbDVO3poJMxgbuWivkEdhyeg+I2G8iX+1aLH1NaW5ZGrG+OzCTcXmzmr3g4JOin7kYQ545fXe +Hz9ktBN2XH2Yp7i6RlJf5vKFDFlZ8dwGdFjoKkA4UHBPr84KWAoqhD9tueJpjM1JD6SLZtl+p kBE= WDCIronportException: Internal Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1650434006; x=1653026007; bh=54LNDcv7kZB26uhwQD pQcWJg6cxn2r4zaQ0u9RhnAYA=; b=BJ+huSzGbvFPyjR13/QkG6bmQiyzlY1olg P9fOn+QxTFuOVMowjaX9Oe56wqqoCN6JFsjfNgNLYqix2QA+blNULHukkgWK2MOj JPkV+Zh8otLWRPHgYenTOZpw49VoOwLn5HdyPJg7nA7rGP6YXBbYTU4C74UPVIWG T0WY7WT7RV/kmzRPqiUqIw/ycY1oJ99aqS0O7yOYYX9GG4oHEpu4j3pVafTc2vZl Mq+Lr4IrmwiPGy3M6i8wJcYM8V33qVFIxNT9Bt7rRVcjHy8dWAkseFEOGy9exCSx TzVc6NWEUR7zrfAnNTOY3HSK7+aAULqyO1iyLAnjHBRI3JrDhpVA== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com From: Alistair Francis To: qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: Palmer Dabbelt , Alistair Francis , alistair23@gmail.com, Bin Meng , Alistair Francis , qemu-arm@nongnu.org, Peter Maydell , bmeng.cn@gmail.com, "Edgar E. Iglesias" Subject: [PATCH v4 6/6] hw/riscv: Enable TPM backends Date: Wed, 20 Apr 2022 15:52:48 +1000 Message-Id: <20220420055248.960491-7-alistair.francis@opensource.wdc.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220420055248.960491-1-alistair.francis@opensource.wdc.com> References: <20220420055248.960491-1-alistair.francis@opensource.wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=lists.gnu.org; Received-SPF: pass client-ip=216.71.154.45; envelope-from=prvs=1021dae20=alistair.francis@opensource.wdc.com; helo=esa6.hgst.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1650435994891100001 Content-Type: text/plain; charset="utf-8" From: Alistair Francis Imply the TPM sysbus devices. This allows users to add TPM devices to the RISC-V virt board. This was tested by first creating an emulated TPM device: swtpm socket --tpm2 -t -d --tpmstate dir=3D/tmp/tpm \ --ctrl type=3Dunixio,path=3Dswtpm-sock Then launching QEMU with: -chardev socket,id=3Dchrtpm,path=3Dswtpm-sock \ -tpmdev emulator,id=3Dtpm0,chardev=3Dchrtpm \ -device tpm-tis-device,tpmdev=3Dtpm0 The TPM device can be seen in the memory tree and the generated device tree. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/942 Signed-off-by: Alistair Francis Reviewed-by: Edgar E. Iglesias Reviewed-by: Bin Meng --- hw/riscv/virt.c | 4 ++++ hw/riscv/Kconfig | 1 + 2 files changed, 5 insertions(+) diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index 6eed1f4d70..b62fd66a49 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -43,6 +43,7 @@ #include "sysemu/device_tree.h" #include "sysemu/sysemu.h" #include "sysemu/kvm.h" +#include "sysemu/tpm.h" #include "hw/pci/pci.h" #include "hw/pci-host/gpex.h" #include "hw/display/ramfb.h" @@ -1612,6 +1613,9 @@ static void virt_machine_class_init(ObjectClass *oc, = void *data) hc->plug =3D virt_machine_device_plug_cb; =20 machine_class_allow_dynamic_sysbus_dev(mc, TYPE_RAMFB_DEVICE); +#ifdef CONFIG_TPM + machine_class_allow_dynamic_sysbus_dev(mc, TYPE_TPM_TIS_SYSBUS); +#endif =20 object_class_property_add_bool(oc, "aclint", virt_get_aclint, virt_set_aclint); diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig index da790f5936..79ff61c464 100644 --- a/hw/riscv/Kconfig +++ b/hw/riscv/Kconfig @@ -34,6 +34,7 @@ config RISCV_VIRT imply PCI_DEVICES imply VIRTIO_VGA imply TEST_DEVICES + imply TPM_TIS_SYSBUS select RISCV_NUMA select GOLDFISH_RTC select MSI_NONBROKEN --=20 2.35.1