Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp321182pxb; Fri, 15 Jan 2021 04:16:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJx1ZhfsAhx0uwCZ6mnGvSyOm8qJJ+o9fRvcyHffv2nR/NEFH/fLG2MdOkOx8vDia9rcV5LU X-Received: by 2002:a05:6402:1701:: with SMTP id y1mr961035edu.251.1610713004449; Fri, 15 Jan 2021 04:16:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610713004; cv=none; d=google.com; s=arc-20160816; b=dC2U9h3HydVb+RdKl7SZCerykY1m+4FedFY+rEqAYinpuUjPQvzNsq4Fll0cXOwxeI tOBwn1Ud4mAL2Wv6kbWtwDPS0hPC9AEYz3cix812ZhjOng8sszq4s+i7EmNl2eZXFXHk UeWz4I1m46NYlWvRPtUnuHKs7l4TzEDfHXWU/BoeNog+CIzUwoSyOkk3qtbgZ3/D2X5s QZAl2TMxDswtQVKLxAk21wIDhgl2wRTsKX2xH1cZaSYtkrTedQR0T0iFvCbEq3d8IV3P gyzNExlus+mIldmBYIGkQ+ZjQei4T/cYy4ImBqN/YF85swLynCwPc4LjYVTms4t8CyOq tgAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=ZVXfUo7uxIYjMvJNWCQVtGrfu1cTs6GKSBVW6sjOebA=; b=j8cnwS3fceXm9kPKJcDQW14Zsqf7MLokg4HhHayyaJZiq1c2eKFt+DCNlAuxhSXloj iof6mtwgnDg4xUKejW3ywmthnX/SsUUMDXF7pteHKTGCG+2kEySp2XXq3z6FVPLAyVHw wA5NVLe7J30d7IRn+8Odne3R64zKx04E5Vqh5gVevyQHR4TNSV7ZK7UQZ8KLqIC7RoCT EcrzH+7wwEToiXJ/vnTnfERyR4Y9394SWzvbXpLeMEitudp1r3p0WchBNp8JUvAv57vm zhLAsadjhzks6RL8rRIgfNGVpw0EhcdNn6wTX2R1TJuiBSuVpHMwi/XoXS1+k/FW1rnj 2uWg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z5si4183458ejj.549.2021.01.15.04.16.20; Fri, 15 Jan 2021 04:16:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728652AbhAOMOt (ORCPT + 99 others); Fri, 15 Jan 2021 07:14:49 -0500 Received: from foss.arm.com ([217.140.110.172]:37478 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728637AbhAOMOs (ORCPT ); Fri, 15 Jan 2021 07:14:48 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 78F4211FB; Fri, 15 Jan 2021 04:14:02 -0800 (PST) Received: from usa.arm.com (a074945.blr.arm.com [10.162.16.71]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 01F233F70D; Fri, 15 Jan 2021 04:13:57 -0800 (PST) From: Vivek Gautam To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, iommu@lists.linux-foundation.org, virtualization@lists.linux-foundation.org Cc: joro@8bytes.org, will.deacon@arm.com, mst@redhat.com, robin.murphy@arm.com, jean-philippe@linaro.org, eric.auger@redhat.com, alex.williamson@redhat.com, kevin.tian@intel.com, jacob.jun.pan@linux.intel.com, yi.l.liu@intel.com, lorenzo.pieralisi@arm.com, shameerali.kolothum.thodi@huawei.com, vivek.gautam@arm.com Subject: [PATCH RFC v1 02/15] iommu: Add a simple PASID table library Date: Fri, 15 Jan 2021 17:43:29 +0530 Message-Id: <20210115121342.15093-3-vivek.gautam@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210115121342.15093-1-vivek.gautam@arm.com> References: <20210115121342.15093-1-vivek.gautam@arm.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a small API in iommu subsystem to handle PASID table allocation requests from different consumer drivers, such as a paravirtualized iommu driver. The API provides ops for allocating and freeing PASID table, writing to it and managing the table caches. This library also provides for registering a vendor API that attaches to these ops. The vendor APIs would eventually perform arch level implementations for these PASID tables. Signed-off-by: Vivek Gautam Cc: Joerg Roedel Cc: Will Deacon Cc: Robin Murphy Cc: Jean-Philippe Brucker Cc: Eric Auger Cc: Alex Williamson Cc: Kevin Tian Cc: Jacob Pan Cc: Liu Yi L Cc: Lorenzo Pieralisi Cc: Shameerali Kolothum Thodi --- drivers/iommu/iommu-pasid-table.h | 134 ++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 drivers/iommu/iommu-pasid-table.h diff --git a/drivers/iommu/iommu-pasid-table.h b/drivers/iommu/iommu-pasid-table.h new file mode 100644 index 000000000000..bd4f57656f67 --- /dev/null +++ b/drivers/iommu/iommu-pasid-table.h @@ -0,0 +1,134 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * PASID table management for the IOMMU + * + * Copyright (C) 2021 Arm Ltd. + */ +#ifndef __IOMMU_PASID_TABLE_H +#define __IOMMU_PASID_TABLE_H + +#include + +#include "arm/arm-smmu-v3/arm-smmu-v3.h" + +enum pasid_table_fmt { + PASID_TABLE_ARM_SMMU_V3, + PASID_TABLE_NUM_FMTS, +}; + +/** + * struct arm_smmu_cfg_info - arm-smmu-v3 specific configuration data + * + * @s1_cfg: arm-smmu-v3 stage1 config data + * @feat_flag: features supported by arm-smmu-v3 implementation + */ +struct arm_smmu_cfg_info { + struct arm_smmu_s1_cfg *s1_cfg; + u32 feat_flag; +}; + +/** + * struct iommu_vendor_psdtable_cfg - Configuration data for PASID tables + * + * @iommu_dev: device performing the DMA table walks + * @fmt: The PASID table format + * @base: DMA address of the allocated table, set by the vendor driver + * @cfg: arm-smmu-v3 specific config data + */ +struct iommu_vendor_psdtable_cfg { + struct device *iommu_dev; + enum pasid_table_fmt fmt; + dma_addr_t base; + union { + struct arm_smmu_cfg_info cfg; + } vendor; +}; + +struct iommu_vendor_psdtable_ops; + +/** + * struct iommu_pasid_table - describes a set of PASID tables + * + * @cookie: An opaque token provided by the IOMMU driver and passed back to any + * callback routine. + * @cfg: A copy of the PASID table configuration + * @ops: The PASID table operations in use for this set of page tables + */ +struct iommu_pasid_table { + void *cookie; + struct iommu_vendor_psdtable_cfg cfg; + struct iommu_vendor_psdtable_ops *ops; +}; + +#define pasid_table_cfg_to_table(pst_cfg) \ + container_of((pst_cfg), struct iommu_pasid_table, cfg) + +struct iommu_vendor_psdtable_ops { + int (*alloc)(struct iommu_vendor_psdtable_cfg *cfg); + void (*free)(struct iommu_vendor_psdtable_cfg *cfg); + void (*prepare)(struct iommu_vendor_psdtable_cfg *cfg, + struct io_pgtable_cfg *pgtbl_cfg, u32 asid); + int (*write)(struct iommu_vendor_psdtable_cfg *cfg, int ssid, + void *cookie); + void (*sync)(void *cookie, int ssid, bool leaf); +}; + +static inline int iommu_psdtable_alloc(struct iommu_pasid_table *tbl, + struct iommu_vendor_psdtable_cfg *cfg) +{ + if (!tbl->ops->alloc) + return -ENOSYS; + + return tbl->ops->alloc(cfg); +} + +static inline void iommu_psdtable_free(struct iommu_pasid_table *tbl, + struct iommu_vendor_psdtable_cfg *cfg) +{ + if (!tbl->ops->free) + return; + + tbl->ops->free(cfg); +} + +static inline int iommu_psdtable_prepare(struct iommu_pasid_table *tbl, + struct iommu_vendor_psdtable_cfg *cfg, + struct io_pgtable_cfg *pgtbl_cfg, + u32 asid) +{ + if (!tbl->ops->prepare) + return -ENOSYS; + + tbl->ops->prepare(cfg, pgtbl_cfg, asid); + return 0; +} + +static inline int iommu_psdtable_write(struct iommu_pasid_table *tbl, + struct iommu_vendor_psdtable_cfg *cfg, + int ssid, void *cookie) +{ + if (!tbl->ops->write) + return -ENOSYS; + + return tbl->ops->write(cfg, ssid, cookie); +} + +static inline int iommu_psdtable_sync(struct iommu_pasid_table *tbl, + void *cookie, int ssid, bool leaf) +{ + if (!tbl->ops->sync) + return -ENOSYS; + + tbl->ops->sync(cookie, ssid, leaf); + return 0; +} + +/* A placeholder to register vendor specific pasid layer */ +static inline struct iommu_pasid_table * +iommu_register_pasid_table(enum pasid_table_fmt fmt, + struct device *dev, void *cookie) +{ + return NULL; +} + +#endif /* __IOMMU_PASID_TABLE_H */ -- 2.17.1