Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp296531rwe; Fri, 26 Aug 2022 05:20:19 -0700 (PDT) X-Google-Smtp-Source: AA6agR4zNzkc7p62QY9BJj7E1MQJBWbJ8XT2WiGoxYUCvPJF1NaPLN1t/KIFAs1HnupI9evC3tg9 X-Received: by 2002:a05:6402:1912:b0:447:25aa:b255 with SMTP id e18-20020a056402191200b0044725aab255mr6759265edz.51.1661516419350; Fri, 26 Aug 2022 05:20:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661516419; cv=none; d=google.com; s=arc-20160816; b=yFgVBN8+TszqnVDqpbW7rvfAwndSbfkKdks3VLpbGd02Ev7Q+3fIIKTWTbxn+PLFUZ cwsEwrPrA2hpERq8an9+WPP5Npim08Ef6cad8RopsSHUzfSIZk6umP/Oq2k/lHLV7kBA afDNCy56ZHnaJQdVbgCD2U5g3Z+hyEstpVONntlHlkfUhHYcvOPn5pv40LaLjjuT+ZzC 60PQCtlEFpSnZDhQkS7YpHdD+pZsGNBkZ5XqzzHk9OoXvmUr6sqcVBFmLPk6GY0v9i5X S1k0j8n/bbQGz3IqeVlDAJ6HkisXQDAbBfwixyfmiln2cpjOlKLP0f32X6U0ZhFIMPxd N3aQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=esOb/OZVJUtZb/23LKO8uC4tbZCVlHncIRtnMfciGJI=; b=u/ofqHJv8Ld7aVIIWA2NjrFEhUxc6sWobFgXivti36OMKM/6XP/zM4h9XwkVq+M57i SjDRDwvouPbHekPGnJZdbnvdjPHl5aJm9QtEuUAUKsLGUU5vgV9tVZftcialm0KTKUMr BFdr4OVP91ehzbUfSnr8C75LCfDUTL7AeVAkv2dVF2byaR+SP5fijvrrN9Zx/rV8PNQx rztowOVS/JDFeWeox1X+QUAWC1j7WE/IjZHVwqRcWT07BkN8AHlje1IVJyp1kXpwCmmS QRicx9rwv0rvhp2F2JU0LYSqWjLPQ8ALWC7RmEWpPq6X6YoGN9N2UFOdLVqJGOaaqYHL x+fg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="dzH/q6Yr"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jg36-20020a170907972400b0073d045866b3si1459262ejc.225.2022.08.26.05.19.52; Fri, 26 Aug 2022 05:20:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="dzH/q6Yr"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343642AbiHZMRg (ORCPT + 99 others); Fri, 26 Aug 2022 08:17:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343673AbiHZMRb (ORCPT ); Fri, 26 Aug 2022 08:17:31 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0F8ED9E96; Fri, 26 Aug 2022 05:17:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661516250; x=1693052250; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Pkkvw5TrdL+mKzrXgkga3FZhkLTWvt5jlQ/qUj6gIfw=; b=dzH/q6Yrz2aIlcM8m2GhbfkuqWtRhEkAbYiHDu+lMRUmg3jvvAC106Hk lVfg6pEsxgiR7noi63yXBwnXJEKoc2wPyMiWc9BxiHYx9kh9wJpCrSEy9 hF7FzjT6AYbNK2HLmo+QyEJ2AwjaSb1fVH4jLr8T2i3Es2ybnYZ2d0ahK 2uw3zqPv0uSNiIfjFlp88I6hFnteZDWj7JzhfEi8eiuDsuKhi1Ej5hvej ognZqlYSyk0lDu5nUhT2sOxak4WuOewbj5wK1FQaAmyQNzw+n7kkH04AM Lw4eJ++n5rlSGSrIp9OO3BpA/77rpV3Rx6l/6By2z+RIH3xqnjfYVdf+f Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10450"; a="281463023" X-IronPort-AV: E=Sophos;i="5.93,265,1654585200"; d="scan'208";a="281463023" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Aug 2022 05:17:28 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,265,1654585200"; d="scan'208";a="606747480" Received: from allen-box.sh.intel.com ([10.239.159.48]) by orsmga007.jf.intel.com with ESMTP; 26 Aug 2022 05:17:23 -0700 From: Lu Baolu To: Joerg Roedel , Jason Gunthorpe , Christoph Hellwig , Bjorn Helgaas , Kevin Tian , Ashok Raj , Will Deacon , Robin Murphy , Jean-Philippe Brucker , Dave Jiang , Fenghua Yu , Vinod Koul Cc: Eric Auger , Liu Yi L , Jacob jun Pan , Zhangfei Gao , Zhu Tony , iommu@lists.linux.dev, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v12 02/17] iommu: Add max_pasids field in struct dev_iommu Date: Fri, 26 Aug 2022 20:11:26 +0800 Message-Id: <20220826121141.50743-3-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220826121141.50743-1-baolu.lu@linux.intel.com> References: <20220826121141.50743-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use this field to save the number of PASIDs that a device is able to consume. It is a generic attribute of a device and lifting it into the per-device dev_iommu struct could help to avoid the boilerplate code in various IOMMU drivers. Signed-off-by: Lu Baolu Reviewed-by: Kevin Tian Reviewed-by: Jason Gunthorpe Reviewed-by: Yi Liu Tested-by: Zhangfei Gao Tested-by: Tony Zhu --- include/linux/iommu.h | 2 ++ drivers/iommu/iommu.c | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/include/linux/iommu.h b/include/linux/iommu.h index ed172cbdabf2..0d9ce209a501 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -368,6 +368,7 @@ struct iommu_fault_param { * @fwspec: IOMMU fwspec data * @iommu_dev: IOMMU device this device is linked to * @priv: IOMMU Driver private data + * @max_pasids: number of PASIDs this device can consume * * TODO: migrate other per device data pointers under iommu_dev_data, e.g. * struct iommu_group *iommu_group; @@ -379,6 +380,7 @@ struct dev_iommu { struct iommu_fwspec *fwspec; struct iommu_device *iommu_dev; void *priv; + u32 max_pasids; }; int iommu_device_register(struct iommu_device *iommu, diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 780fb7071577..e9f6a8d33b58 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -218,6 +219,24 @@ static void dev_iommu_free(struct device *dev) kfree(param); } +static u32 dev_iommu_get_max_pasids(struct device *dev) +{ + u32 max_pasids = 0, bits = 0; + int ret; + + if (dev_is_pci(dev)) { + ret = pci_max_pasids(to_pci_dev(dev)); + if (ret > 0) + max_pasids = ret; + } else { + ret = device_property_read_u32(dev, "pasid-num-bits", &bits); + if (!ret) + max_pasids = 1UL << bits; + } + + return min_t(u32, max_pasids, dev->iommu->iommu_dev->max_pasids); +} + static int __iommu_probe_device(struct device *dev, struct list_head *group_list) { const struct iommu_ops *ops = dev->bus->iommu_ops; @@ -243,6 +262,7 @@ static int __iommu_probe_device(struct device *dev, struct list_head *group_list } dev->iommu->iommu_dev = iommu_dev; + dev->iommu->max_pasids = dev_iommu_get_max_pasids(dev); group = iommu_group_get_for_dev(dev); if (IS_ERR(group)) { -- 2.25.1