From nobody Sat Nov 23 20:25:18 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1730347165; cv=none; d=zohomail.com; s=zohoarc; b=FVcpOdm67XxC0EJczGxJQAILQBrVQFUa8KvJWoJkhfWWvweYQuZMhwPIwfemfd4ddGsTEzKw1L0Mc7oxQaN5m7mvWn8sQyQWS1+b2h/BL/ZNAyPBb5HxE05NbfO0oTMwBWDebvOUjeNAWDGPp1eHCt6UdUbmV6nwPv6NDSCMLzs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730347165; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=WrsngeKBBs/+ALCLr8B5ACb/gzSGOmV5QlCUVuSGwdU=; b=SMxyVt4pKfPO4Hz6lobks6XuXTlz0J9kBFJ6hoqmlWJrOlTLqFlJLLmKlyfGg+VyYyLG6h4aOdUfR8+7evM/9R+pRA996yDmfPsIxPwA27ojmPPyRDHBnPaOmBrn9l9M4iRC4vZoqNSrI65k0jhMi7IMp6CKbbTfS6EorQClric= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730347165189562.4956570478232; Wed, 30 Oct 2024 20:59:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t6MHv-0004e7-TL; Wed, 30 Oct 2024 23:56:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t6MHd-0003l9-3D for qemu-devel@nongnu.org; Wed, 30 Oct 2024 23:55:41 -0400 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t6MHb-0004Fl-Ds for qemu-devel@nongnu.org; Wed, 30 Oct 2024 23:55:40 -0400 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-20c7edf2872so12561945ad.1 for ; Wed, 30 Oct 2024 20:55:39 -0700 (PDT) Received: from toolbox.alistair23.me (2403-580b-97e8-0-82ce-f179-8a79-69f4.ip6.aussiebb.net. [2403:580b:97e8:0:82ce:f179:8a79:69f4]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21105707064sm3022795ad.70.2024.10.30.20.55.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Oct 2024 20:55:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730346938; x=1730951738; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=WrsngeKBBs/+ALCLr8B5ACb/gzSGOmV5QlCUVuSGwdU=; b=XSvhGP8nN5WMzjK30XuuDy0FD6p+neWbVFQ8Y5ErbXaxvWmIc7kQceL0TGJgTTIW9F Yd/+HbAw3K1DCcDl0A7jta0LtxHyFo3gI8lfwT+5XxpVpMqEHLLqhCnrkVyiv+FKiGe7 uI9D8GPhQbdYzhjy6UAefZwa1vXAJ+4ZeAsrSJB81rJazJ5ancKto6vlEd36WSL7Eei8 QSCEuLf5fOBZEoTlVrPCLF/hMO0TZRXTw/St602XpnXIklC0CGqWFWoV1M9R5v7KgxG5 yNwz7OfYkK3t1FdSbfmD2vPEZBlC1B+pQcw435o+DLHK1OLJ3GSpG3tY+Ncn9WC7QlVb up4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730346938; x=1730951738; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WrsngeKBBs/+ALCLr8B5ACb/gzSGOmV5QlCUVuSGwdU=; b=EQEuZ7nxjT50FDeMxhn6+z+Tjm/bxW6WBaAK3bwLOF0VnoMUT8q2z12j6lxlq1oQFN 5Qqb2cgXIn08eLk6ejnuJk6iksheTcTOT90Lk4e7lw6cllhmq7GrT6AVSDQTx4I/L7zX zYXnmHqVpwtUmbPZ9Hu1jt0DDztzfLMr2ztdAMjMX1SqxkZvTREhrNZwXcP1s4fc9Q56 byXreHYvmWEAFeGKP0ZD9cVNEHEcL1QowUsQxREXglJWaFq9gJHN1A4xQ6Z69k8zUwBu qUEl7m+ZsQWAhpQexb+Ens5lUOGnm8ZksLDLY85KtVNA2BG8TY/oH7lHktjXSSDMrZ9U pNLw== X-Gm-Message-State: AOJu0YxgQfGbj/vD90XrdHgTWcUFxEqgVVm8sjN6+uOChC79tQnM5D1N RCD9roRMhVdQt06FDw5Pfv0RCwx7VmQZttEMRuBMQChgbLA85y6XAqz74eT6 X-Google-Smtp-Source: AGHT+IFMUWuEZdc+Axmu38actBVBcGn8mR+pp8hGK/YveksosAuyvUrTOuPEKsmFVmQHGsPOY2+gqw== X-Received: by 2002:a17:903:2312:b0:20c:c9ac:bd0d with SMTP id d9443c01a7336-2110574c2eemr15525845ad.19.1730346937800; Wed, 30 Oct 2024 20:55:37 -0700 (PDT) From: Alistair Francis X-Google-Original-From: Alistair Francis To: qemu-devel@nongnu.org Cc: alistair23@gmail.com, Tomasz Jeznach , Daniel Henrique Barboza , Frank Chang , Alistair Francis Subject: [PULL 41/50] hw/riscv/virt.c: support for RISC-V IOMMU PCIDevice hotplug Date: Thu, 31 Oct 2024 13:53:09 +1000 Message-ID: <20241031035319.731906-42-alistair.francis@wdc.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241031035319.731906-1-alistair.francis@wdc.com> References: <20241031035319.731906-1-alistair.francis@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=2607:f8b0:4864:20::62d; envelope-from=alistair23@gmail.com; helo=mail-pl1-x62d.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 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, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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: 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-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1730347167246116600 Content-Type: text/plain; charset="utf-8" From: Tomasz Jeznach Generate device tree entry for riscv-iommu PCI device, along with mapping all PCI device identifiers to the single IOMMU device instance. Signed-off-by: Tomasz Jeznach Signed-off-by: Daniel Henrique Barboza Reviewed-by: Frank Chang Reviewed-by: Alistair Francis Message-ID: <20241016204038.649340-7-dbarboza@ventanamicro.com> Signed-off-by: Alistair Francis --- hw/riscv/virt.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index ee3129f3b3..45a8c4f819 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -32,6 +32,7 @@ #include "hw/core/sysbus-fdt.h" #include "target/riscv/pmu.h" #include "hw/riscv/riscv_hart.h" +#include "hw/riscv/iommu.h" #include "hw/riscv/virt.h" #include "hw/riscv/boot.h" #include "hw/riscv/numa.h" @@ -1032,6 +1033,30 @@ static void create_fdt_virtio_iommu(RISCVVirtState *= s, uint16_t bdf) bdf + 1, iommu_phandle, bdf + 1, 0xffff - bdf); } =20 +static void create_fdt_iommu(RISCVVirtState *s, uint16_t bdf) +{ + const char comp[] =3D "riscv,pci-iommu"; + void *fdt =3D MACHINE(s)->fdt; + uint32_t iommu_phandle; + g_autofree char *iommu_node =3D NULL; + g_autofree char *pci_node =3D NULL; + + pci_node =3D g_strdup_printf("/soc/pci@%lx", + (long) virt_memmap[VIRT_PCIE_ECAM].base); + iommu_node =3D g_strdup_printf("%s/iommu@%x", pci_node, bdf); + iommu_phandle =3D qemu_fdt_alloc_phandle(fdt); + qemu_fdt_add_subnode(fdt, iommu_node); + + qemu_fdt_setprop(fdt, iommu_node, "compatible", comp, sizeof(comp)); + qemu_fdt_setprop_cell(fdt, iommu_node, "#iommu-cells", 1); + qemu_fdt_setprop_cell(fdt, iommu_node, "phandle", iommu_phandle); + qemu_fdt_setprop_cells(fdt, iommu_node, "reg", + bdf << 8, 0, 0, 0, 0); + qemu_fdt_setprop_cells(fdt, pci_node, "iommu-map", + 0, iommu_phandle, 0, bdf, + bdf + 1, iommu_phandle, bdf + 1, 0xffff - bdf); +} + static void finalize_fdt(RISCVVirtState *s) { uint32_t phandle =3D 1, irq_mmio_phandle =3D 1, msi_pcie_phandle =3D 1; @@ -1738,9 +1763,11 @@ static HotplugHandler *virt_machine_get_hotplug_hand= ler(MachineState *machine, MachineClass *mc =3D MACHINE_GET_CLASS(machine); =20 if (device_is_dynamic_sysbus(mc, dev) || - object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_IOMMU_PCI)) { + object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_IOMMU_PCI) || + object_dynamic_cast(OBJECT(dev), TYPE_RISCV_IOMMU_PCI)) { return HOTPLUG_HANDLER(machine); } + return NULL; } =20 @@ -1761,6 +1788,10 @@ static void virt_machine_device_plug_cb(HotplugHandl= er *hotplug_dev, if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_IOMMU_PCI)) { create_fdt_virtio_iommu(s, pci_get_bdf(PCI_DEVICE(dev))); } + + if (object_dynamic_cast(OBJECT(dev), TYPE_RISCV_IOMMU_PCI)) { + create_fdt_iommu(s, pci_get_bdf(PCI_DEVICE(dev))); + } } =20 static void virt_machine_class_init(ObjectClass *oc, void *data) --=20 2.47.0