From nobody Sat Sep 21 05:18:58 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1569496937; cv=none; d=zoho.com; s=zohoarc; b=RpcUfZG8ePOgnLUHochnLAGKLVDgqbr315UVkEAqxqErndJq6Xgx2STD4F8RzTDCByCP+najBkCbz6bkKn0lGEux0b4WKaaXhJ8whiNdf0b/p9wPrDATBr3PhIwk7yxEksdERVOwZ5GHk3yeHTmXJ/f/K3KJwBWsbMaoTKKe4bI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569496937; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=48yj93rFbFU4HEDmt4PmiSTXNpNtGmqu2x0kpsxLXik=; b=RHBIxInrq1rzZF4hOwDENrk1EhcbNkjd8wO3+RwskCPZlI6LQeyr0vuQScNX5tHrD5ho/xkpRCzIshkKmgf34T/bYS+0n/GZ7QRYgPHapwVBSvr/Q8W7XbbcxGgAPoTEV3UIhsnG6wGPxeKzIiQNCMTzMT++mEyuB5cQcj4eZUI= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1569496937971687.047278439507; Thu, 26 Sep 2019 04:22:17 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iDRpa-0008G4-Du; Thu, 26 Sep 2019 11:21:06 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iDRpY-0008EV-V3 for xen-devel@lists.xenproject.org; Thu, 26 Sep 2019 11:21:04 +0000 Received: from mail-lj1-x243.google.com (unknown [2a00:1450:4864:20::243]) by localhost (Halon) with ESMTPS id b4867c0a-e04f-11e9-bf31-bc764e2007e4; Thu, 26 Sep 2019 11:20:55 +0000 (UTC) Received: by mail-lj1-x243.google.com with SMTP id y23so1732285lje.9 for ; Thu, 26 Sep 2019 04:20:55 -0700 (PDT) Received: from otyshchenko.kyiv.epam.com (ll-22.209.223.85.sovam.net.ua. [85.223.209.22]) by smtp.gmail.com with ESMTPSA id n4sm526810lfi.63.2019.09.26.04.20.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 26 Sep 2019 04:20:53 -0700 (PDT) X-Inumbo-ID: b4867c0a-e04f-11e9-bf31-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=5RJbm4O9fM8Vs4OMPQDCKEtjVDNEeQDTOSO16j0l31c=; b=DR6mZJ5ytSviX3gEVgZS6AhSupIgJGKiGA/0Jd+ha7fdOGhyWMR1AJM/SD8VvMrkUV pCh2Sz9dQmhjscBnEMmZOW0/viWesvDcjhJu0Q8Sj8G9RWNZfwR6r3huDpTvX3OJpCOA ooBrFU6rY5/kSk2DHLCyo6sscJkz0CC77XVKHUmCqS4JBNtR1s9eX//RzvgN6XyRHJ9J TAh74DFyw+vJiEbZ8q3+XJu4kwW1z2/j4OeY+7TgEWJl2K7KgcWq2zVV72hdNPJAn0TV vINi+oCqN/lPZiF+YHPVB7jBMdC8zaZjz+HeobiBcRhyO1aGP+ZX9+sT/BZ2iGXtOgdV AN7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=5RJbm4O9fM8Vs4OMPQDCKEtjVDNEeQDTOSO16j0l31c=; b=cgOt3QtGTsHzk2D8QvHHRgR2kGAQ6DZx+H3Z58JKWOZTD4tR2pAyganE05NyPKCFaN alkD1OXRKflwFAMCnMMTcWZFGjD0elT/GM2UwAUKE7FUjin7bWOQHyXoQsoZEqmNnoIe 61BJB5fQ+5Es1ZI3r9S7PdpHzWgtOndY3wbjqWfcSt3MacH2IUz0RlLn+A5klhIrFLoY 98yQ/Wor5lDKMIVNMAnMH1PDUMqhSM5kXA3XIOqQ84KndAowwGXfYI0lHuJMpJH2HX/y FO7BjaZ7vj0ifeYRJVrwxoaCVAdQN8znGPYFJT7yX2D6tsnZuNNxx51F8+GBMstQ9HNY BWpg== X-Gm-Message-State: APjAAAUuMZQ51fDsFyPTJWa4iP9NeYJ4fdIb8Lt/EfX89H38CSxuo7XK fSVO809fwGsLMM9al+6jVPa/gPDVREM= X-Google-Smtp-Source: APXvYqxckwfAtYcUCwzu2gSEYbEz9dx47UkU0TBc4dP5Hx5QI9g1KnMkSKAC0i6qKHhL4O+9PPnl2A== X-Received: by 2002:a2e:2bdb:: with SMTP id r88mr2220008ljr.82.1569496853959; Thu, 26 Sep 2019 04:20:53 -0700 (PDT) From: Oleksandr Tyshchenko To: xen-devel@lists.xenproject.org Date: Thu, 26 Sep 2019 14:20:27 +0300 Message-Id: <1569496834-7796-2-git-send-email-olekstysh@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1569496834-7796-1-git-send-email-olekstysh@gmail.com> References: <1569496834-7796-1-git-send-email-olekstysh@gmail.com> Subject: [Xen-devel] [PATCH V6 1/8] iommu/arm: Add iommu_helpers.c file to keep common for IOMMUs stuff X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Oleksandr Tyshchenko , julien.grall@arm.com, sstabellini@kernel.org, volodymyr_babchuk@epam.com MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Oleksandr Tyshchenko Introduce a separate file to keep various helpers which could be used by more than one IOMMU driver in order not to duplicate code. The first candidates to be moved to the new file are SMMU driver's "map_page/unmap_page" callbacks. These callbacks neither contain any SMMU specific info nor perform any SMMU specific actions and are going to be the same across all IOMMU drivers which H/W IP shares P2M with the CPU like SMMU does. So, move callbacks to iommu_helpers.c for the upcoming IPMMU driver to be able to re-use them. Signed-off-by: Oleksandr Tyshchenko Acked-by: Julien Grall --- Changes V3 -> V4: - added Julien's A-b - fixed Grammatical error - clarified comment in a header Changes V2 -> V3: - put headers in alphabetical order - retained Copyright from the SMMU code --- xen/drivers/passthrough/arm/Makefile | 2 +- xen/drivers/passthrough/arm/iommu_helpers.c | 84 +++++++++++++++++++++++++= ++++ xen/drivers/passthrough/arm/smmu.c | 48 +---------------- xen/include/asm-arm/iommu.h | 10 ++++ 4 files changed, 97 insertions(+), 47 deletions(-) create mode 100644 xen/drivers/passthrough/arm/iommu_helpers.c diff --git a/xen/drivers/passthrough/arm/Makefile b/xen/drivers/passthrough= /arm/Makefile index b3efcfd..4abb87a 100644 --- a/xen/drivers/passthrough/arm/Makefile +++ b/xen/drivers/passthrough/arm/Makefile @@ -1,2 +1,2 @@ -obj-y +=3D iommu.o +obj-y +=3D iommu.o iommu_helpers.o obj-$(CONFIG_ARM_SMMU) +=3D smmu.o diff --git a/xen/drivers/passthrough/arm/iommu_helpers.c b/xen/drivers/pass= through/arm/iommu_helpers.c new file mode 100644 index 0000000..a36e2b8 --- /dev/null +++ b/xen/drivers/passthrough/arm/iommu_helpers.c @@ -0,0 +1,84 @@ +/* + * xen/drivers/passthrough/arm/iommu_helpers.c + * + * Contains various helpers to be used by IOMMU drivers. + * + * Based on Xen's SMMU driver: + * xen/drivers/passthrough/arm/smmu.c + * + * Copyright (C) 2014 Linaro Limited. + * + * Copyright (C) 2019 EPAM Systems Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms and conditions of the GNU General Public + * License, version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; If not, see . + */ + +#include +#include +#include + +#include + +/* Should only be used if P2M Table is shared between the CPU and the IOMM= U. */ +int __must_check arm_iommu_map_page(struct domain *d, dfn_t dfn, mfn_t mfn, + unsigned int flags, + unsigned int *flush_flags) +{ + p2m_type_t t; + + /* + * Grant mappings can be used for DMA requests. The dev_bus_addr + * returned by the hypercall is the MFN (not the IPA). For device + * protected by an IOMMU, Xen needs to add a 1:1 mapping in the domain + * p2m to allow DMA request to work. + * This is only valid when the domain is directed mapped. Hence this + * function should only be used by gnttab code with gfn =3D=3D mfn =3D= =3D dfn. + */ + BUG_ON(!is_domain_direct_mapped(d)); + BUG_ON(mfn_x(mfn) !=3D dfn_x(dfn)); + + /* We only support readable and writable flags */ + if ( !(flags & (IOMMUF_readable | IOMMUF_writable)) ) + return -EINVAL; + + t =3D (flags & IOMMUF_writable) ? p2m_iommu_map_rw : p2m_iommu_map_ro; + + /* + * The function guest_physmap_add_entry replaces the current mapping + * if there is already one... + */ + return guest_physmap_add_entry(d, _gfn(dfn_x(dfn)), _mfn(dfn_x(dfn)), = 0, t); +} + +/* Should only be used if P2M Table is shared between the CPU and the IOMM= U. */ +int __must_check arm_iommu_unmap_page(struct domain *d, dfn_t dfn, + unsigned int *flush_flags) +{ + /* + * This function should only be used by gnttab code when the domain + * is direct mapped (i.e. gfn =3D=3D mfn =3D=3D dfn). + */ + if ( !is_domain_direct_mapped(d) ) + return -EINVAL; + + return guest_physmap_remove_page(d, _gfn(dfn_x(dfn)), _mfn(dfn_x(dfn))= , 0); +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/drivers/passthrough/arm/smmu.c b/xen/drivers/passthrough/a= rm/smmu.c index f151b9f..8ae986a 100644 --- a/xen/drivers/passthrough/arm/smmu.c +++ b/xen/drivers/passthrough/arm/smmu.c @@ -2734,50 +2734,6 @@ static void arm_smmu_iommu_domain_teardown(struct do= main *d) xfree(xen_domain); } =20 -static int __must_check arm_smmu_map_page(struct domain *d, dfn_t dfn, - mfn_t mfn, unsigned int flags, - unsigned int *flush_flags) -{ - p2m_type_t t; - - /* - * Grant mappings can be used for DMA requests. The dev_bus_addr - * returned by the hypercall is the MFN (not the IPA). For device - * protected by an IOMMU, Xen needs to add a 1:1 mapping in the domain - * p2m to allow DMA request to work. - * This is only valid when the domain is directed mapped. Hence this - * function should only be used by gnttab code with gfn =3D=3D mfn =3D=3D= dfn. - */ - BUG_ON(!is_domain_direct_mapped(d)); - BUG_ON(mfn_x(mfn) !=3D dfn_x(dfn)); - - /* We only support readable and writable flags */ - if (!(flags & (IOMMUF_readable | IOMMUF_writable))) - return -EINVAL; - - t =3D (flags & IOMMUF_writable) ? p2m_iommu_map_rw : p2m_iommu_map_ro; - - /* - * The function guest_physmap_add_entry replaces the current mapping - * if there is already one... - */ - return guest_physmap_add_entry(d, _gfn(dfn_x(dfn)), _mfn(dfn_x(dfn)), - 0, t); -} - -static int __must_check arm_smmu_unmap_page(struct domain *d, dfn_t dfn, - unsigned int *flush_flags) -{ - /* - * This function should only be used by gnttab code when the domain - * is direct mapped (i.e. gfn =3D=3D mfn =3D=3D dfn). - */ - if ( !is_domain_direct_mapped(d) ) - return -EINVAL; - - return guest_physmap_remove_page(d, _gfn(dfn_x(dfn)), _mfn(dfn_x(dfn)), 0= ); -} - static const struct iommu_ops arm_smmu_iommu_ops =3D { .init =3D arm_smmu_iommu_domain_init, .hwdom_init =3D arm_smmu_iommu_hwdom_init, @@ -2786,8 +2742,8 @@ static const struct iommu_ops arm_smmu_iommu_ops =3D { .iotlb_flush_all =3D arm_smmu_iotlb_flush_all, .assign_device =3D arm_smmu_assign_dev, .reassign_device =3D arm_smmu_reassign_dev, - .map_page =3D arm_smmu_map_page, - .unmap_page =3D arm_smmu_unmap_page, + .map_page =3D arm_iommu_map_page, + .unmap_page =3D arm_iommu_unmap_page, }; =20 static __init const struct arm_smmu_device *find_smmu(const struct device = *dev) diff --git a/xen/include/asm-arm/iommu.h b/xen/include/asm-arm/iommu.h index 77a94b2..937edc8 100644 --- a/xen/include/asm-arm/iommu.h +++ b/xen/include/asm-arm/iommu.h @@ -23,6 +23,16 @@ struct arch_iommu const struct iommu_ops *iommu_get_ops(void); void iommu_set_ops(const struct iommu_ops *ops); =20 +/* + * The mapping helpers below should only be used if P2M Table is shared + * between the CPU and the IOMMU. + */ +int __must_check arm_iommu_map_page(struct domain *d, dfn_t dfn, mfn_t mfn, + unsigned int flags, + unsigned int *flush_flags); +int __must_check arm_iommu_unmap_page(struct domain *d, dfn_t dfn, + unsigned int *flush_flags); + #endif /* __ARCH_ARM_IOMMU_H__ */ =20 /* --=20 2.7.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel