From patchwork Fri May 18 21:34:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jordan Crouse X-Patchwork-Id: 10412339 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 53931602C2 for ; Fri, 18 May 2018 21:51:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 431C128B0F for ; Fri, 18 May 2018 21:51:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 37BA228B06; Fri, 18 May 2018 21:51:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A4B2628B09 for ; Fri, 18 May 2018 21:51:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=e585fq/P8ZYpBovZa+siA6fB7XDBFSTe6eKn4qJXfsI=; b=dnj6frBxd+gQ3WCEyvhjHNHhqS +MiyNuwrEIOz5wbw6OWoTrl8WkwE6E+KMzOKssqTYyzLdtT0MaXGj8OFgn1es8wSuSdQL/slKPz6q 8dt8Dx0ww1540deHlUkwI9aq2IISvDtoDmpdv4Da87onYR1C5bSm1lHeAPJ1k5CbHlheFdtixikSk dvSukepW9f4H2Ig3pstdvbWlztdH8TCTNi/EJWL9zHXzdi4x5mPMCBBERTYgndHIBPSTFuklF7Znv cjiRCVuzWTMGnCS5XtKZU/osNJIzaR7U4pg595CAM1jnsFbo8WtHPaU9WWRZANBClFeIXPLChA+53 Unn+e/kw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fJnHa-00022N-BE; Fri, 18 May 2018 21:51:26 +0000 Received: from smtp.codeaurora.org ([198.145.29.96]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fJn2B-00006b-5H for linux-arm-kernel@lists.infradead.org; Fri, 18 May 2018 21:35:46 +0000 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 4A391610D9; Fri, 18 May 2018 21:35:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1526679316; bh=CeIQAxSbs1zIn6aTpJ4pLoZvV/6iHTEpZZAvJIakado=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RAxqAi0Hn6Jy58jqj2s5nBbnBUMz3kaWEp08rvbIPjLQQBQSAmChHD7EXc2EMdE0K K2IbRl3bcxYEzsX86wPmF1DKAHUYAAQjLPurmEj2niuqsd86uZGDcm2qYael2dQWLF 8lpHA0fkTTdB74UOfSPlutEp2pLZwxClXa8raKiE= Received: from jcrouse-lnx.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: jcrouse@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id D883960392; Fri, 18 May 2018 21:35:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1526679310; bh=CeIQAxSbs1zIn6aTpJ4pLoZvV/6iHTEpZZAvJIakado=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ny3lmB5xEAvpvXdD6X7VdP6R+dUGndCr5cjDRN84S8VUfNuvbkbr7T9t6lB2afqwV DKbpPwIjlTtjgIPt6HZtg37rm/tOLW8f/SfzB+2Ax4krLVTOKOdXQQM+M55cw66d6S J0wmebpkTE8QVt/XbjK39haBS2LVvjTQRUUdnqBY= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org D883960392 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=jcrouse@codeaurora.org From: Jordan Crouse To: freedreno@lists.freedesktop.org Subject: [PATCH 06/16] iommu: arm-smmu: Add side-band function for specific PASID callbacks Date: Fri, 18 May 2018 15:34:50 -0600 Message-Id: <20180518213500.31595-7-jcrouse@codeaurora.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180518213500.31595-1-jcrouse@codeaurora.org> References: <20180518213500.31595-1-jcrouse@codeaurora.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180518_143531_366737_69FEA73A X-CRM114-Status: GOOD ( 17.24 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jean-philippe.brucker@arm.com, linux-arm-msm@vger.kernel.org, dri-devel@lists.freedesktop.org, tfiga@chromium.org, iommu@lists.linux-foundation.org, vivek.gautam@codeaurora.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Just allowing a client driver to create and manage a a private PASID isn't interesting if the client driver doesn't have enough information about the pagetable to be able to use it. Add a side band function for arm-smmu that lets the client device register pasid operations to pass the relevant pagetable information to the client driver whenever a new PASID is created or destroyed Signed-off-by: Jordan Crouse --- drivers/iommu/arm-smmu.c | 40 ++++++++++++++++++++++++++++++++++++++++ include/linux/arm-smmu.h | 18 ++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 include/linux/arm-smmu.h diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c index 5c7c135bbb44..100797a07be0 100644 --- a/drivers/iommu/arm-smmu.c +++ b/drivers/iommu/arm-smmu.c @@ -50,6 +50,7 @@ #include #include #include +#include #include @@ -254,6 +255,8 @@ struct arm_smmu_domain { spinlock_t pasid_lock; struct list_head pasid_list; + const struct arm_smmu_pasid_ops *pasid_ops; + void *pasid_data; }; struct arm_smmu_option_prop { @@ -296,6 +299,10 @@ static void arm_smmu_mm_detach(struct iommu_domain *domain, struct device *dev, struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); struct arm_smmu_pasid *node, *obj = NULL; + if (smmu_domain->pasid_ops && smmu_domain->pasid_ops->remove_pasid) + smmu_domain->pasid_ops->remove_pasid(io_mm->pasid, + smmu_domain->pasid_data); + spin_lock(&smmu_domain->pasid_lock); list_for_each_entry(node, &smmu_domain->pasid_list, node) { if (node->pasid == io_mm->pasid) { @@ -392,6 +399,26 @@ static int arm_smmu_mm_attach(struct iommu_domain *domain, struct device *dev, obj->domain = domain; obj->pasid = io_mm->pasid; + if (smmu_domain->pasid_ops && smmu_domain->pasid_ops->install_pasid) { + int ret; + u64 ttbr; + + if (smmu_domain->cfg.fmt == ARM_SMMU_CTX_FMT_AARCH32_S) + ttbr = pgtbl_cfg.arm_v7s_cfg.ttbr; + else + ttbr = pgtbl_cfg.arm_lpae_s1_cfg.ttbr; + + ret = smmu_domain->pasid_ops->install_pasid(io_mm->pasid, ttbr, + smmu_domain->cfg.asid, smmu_domain->pasid_data); + + if (ret) { + free_io_pgtable_ops(obj->pgtbl_ops); + kfree(obj); + + return ret; + } + } + spin_lock(&smmu_domain->pasid_lock); list_add_tail(&obj->node, &smmu_domain->pasid_list); spin_unlock(&smmu_domain->pasid_lock); @@ -2156,6 +2183,19 @@ static int arm_smmu_device_cfg_probe(struct arm_smmu_device *smmu) return 0; } +void arm_smmu_add_pasid_ops(struct iommu_domain *domain, + const struct arm_smmu_pasid_ops *ops, void *data) +{ + struct arm_smmu_domain *smmu_domain; + + if (domain) { + smmu_domain = to_smmu_domain(domain); + smmu_domain->pasid_ops = ops; + smmu_domain->pasid_data = data; + } +} +EXPORT_SYMBOL_GPL(arm_smmu_add_pasid_ops); + struct arm_smmu_match_data { enum arm_smmu_arch_version version; enum arm_smmu_implementation model; diff --git a/include/linux/arm-smmu.h b/include/linux/arm-smmu.h new file mode 100644 index 000000000000..c14ca52231bf --- /dev/null +++ b/include/linux/arm-smmu.h @@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (c) 2018, The Linux Foundation. All rights reserved. */ + +#ifndef ARM_SMMU_H_ +#define ARM_SMMU_H_ + +struct iommu_domain; + +struct arm_smmu_pasid_ops { + int (*install_pasid)(int pasid, u64 ttbr, u32 asid, void *data); + void (*remove_pasid)(int pasid, void *data); +}; + + +void arm_smmu_add_pasid_ops(struct iommu_domain *domain, + const struct arm_smmu_pasid_ops *ops, void *data); + +#endif