From nobody Tue Nov 4 11:01:34 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1505807594494613.1448621400729; Tue, 19 Sep 2017 00:53:14 -0700 (PDT) Received: from localhost ([::1]:40613 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1duDLF-0003cv-P8 for importer@patchew.org; Tue, 19 Sep 2017 03:53:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47528) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1duDGX-0008QF-Uw for qemu-devel@nongnu.org; Tue, 19 Sep 2017 03:48:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1duDGX-0000xr-12 for qemu-devel@nongnu.org; Tue, 19 Sep 2017 03:48:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52470) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1duDGU-0000uT-Go; Tue, 19 Sep 2017 03:48:18 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 80D491F56A; Tue, 19 Sep 2017 07:48:17 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-197.ams2.redhat.com [10.36.116.197]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6F7DA61346; Tue, 19 Sep 2017 07:48:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 80D491F56A Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eric.auger@redhat.com From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, peter.maydell@linaro.org, alex.williamson@redhat.com, mst@redhat.com, qemu-arm@nongnu.org, qemu-devel@nongnu.org, jean-philippe.brucker@arm.com Date: Tue, 19 Sep 2017 09:46:39 +0200 Message-Id: <1505807208-9063-8-git-send-email-eric.auger@redhat.com> In-Reply-To: <1505807208-9063-1-git-send-email-eric.auger@redhat.com> References: <1505807208-9063-1-git-send-email-eric.auger@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 19 Sep 2017 07:48:17 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC v4 07/16] virtio-iommu: Implement attach/detach command X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: wei@redhat.com, kevin.tian@intel.com, marc.zyngier@arm.com, tn@semihalf.com, will.deacon@arm.com, drjones@redhat.com, peterx@redhat.com, linuc.decode@gmail.com, bharat.bhushan@nxp.com, christoffer.dall@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This patch implements the device attach/detach to an address space. Signed-off-by: Eric Auger --- hw/virtio/virtio-iommu.c | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index 41a4bbc..bd859fb 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -110,8 +110,7 @@ static void virtio_iommu_put_dev(gpointer data) g_free(dev); } =20 -viommu_as *virtio_iommu_get_as(VirtIOIOMMU *s, uint32_t asid); -viommu_as *virtio_iommu_get_as(VirtIOIOMMU *s, uint32_t asid) +static viommu_as *virtio_iommu_get_as(VirtIOIOMMU *s, uint32_t asid) { viommu_as *as; =20 @@ -205,6 +204,8 @@ static int virtio_iommu_attach(VirtIOIOMMU *s, uint32_t asid =3D le32_to_cpu(req->address_space); uint32_t devid =3D le32_to_cpu(req->device); uint32_t reserved =3D le32_to_cpu(req->reserved); + viommu_as *as; + viommu_dev *dev; =20 trace_virtio_iommu_attach(asid, devid); =20 @@ -212,7 +213,22 @@ static int virtio_iommu_attach(VirtIOIOMMU *s, return VIRTIO_IOMMU_S_INVAL; } =20 - return VIRTIO_IOMMU_S_UNSUPP; + dev =3D virtio_iommu_get_dev(s, devid); + if (dev->as) { + /* + * the device is already attached to an address space, + * detach it first + */ + virtio_iommu_detach_dev_from_as(dev); + } + + as =3D virtio_iommu_get_as(s, asid); + QLIST_INSERT_HEAD(&as->device_list, dev, next); + + dev->as =3D as; + g_tree_ref(as->mappings); + + return VIRTIO_IOMMU_S_OK; } =20 static int virtio_iommu_detach(VirtIOIOMMU *s, @@ -220,14 +236,24 @@ static int virtio_iommu_detach(VirtIOIOMMU *s, { uint32_t devid =3D le32_to_cpu(req->device); uint32_t reserved =3D le32_to_cpu(req->reserved); - - trace_virtio_iommu_detach(devid); + viommu_dev *dev; =20 if (reserved) { return VIRTIO_IOMMU_S_INVAL; } =20 - return VIRTIO_IOMMU_S_UNSUPP; + dev =3D g_tree_lookup(s->devices, GUINT_TO_POINTER(devid)); + if (!dev) { + return VIRTIO_IOMMU_S_NOENT; + } + + if (!dev->as) { + return VIRTIO_IOMMU_S_INVAL; + } + + virtio_iommu_detach_dev_from_as(dev); + trace_virtio_iommu_detach(devid); + return VIRTIO_IOMMU_S_OK; } =20 static int virtio_iommu_map(VirtIOIOMMU *s, --=20 2.5.5