Received: by 2002:a05:6358:795:b0:dc:4c66:fc3e with SMTP id n21csp2489529rwj; Sun, 30 Oct 2022 18:54:10 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4iV22at35V2uVvFPGPa220ZwJ3qTCWIhUlMxhI7waWOK13hhDhyldJjpCDEzB6FP3T4Ujf X-Received: by 2002:a63:5811:0:b0:46f:a710:1b77 with SMTP id m17-20020a635811000000b0046fa7101b77mr5383011pgb.392.1667181250586; Sun, 30 Oct 2022 18:54:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667181250; cv=none; d=google.com; s=arc-20160816; b=Az4I6WJ7uvPvQkFDxNTU/psVVPEzeGlH37wZDDAsuMqkcW9JeZmWpm4zIk6uvK5MM0 9BTGCw2qQcyHrhi/f7nvrmn4IGW7BfaxfV0jedgkTv9fVLuGwvCX6ATZKhAFes678cLW NzzeJ9VjNq39+DIa1qa0HLiTccmOa4WDu+mMPrLlemMMTChDAzSHIr2g5WiBYn9N0VBf uOKkrLzMLxY9oxDJKFJtbG06uMDyy86P0MhbiOnyZEcgzZb13aLVSiFyHhvAALhgfjbw tbkvPKd3e5i2b/CY++x/+6Sq8fkT3ZSnOLOCGLot/vUe5UmsErcDB83wj5F7nGrwtZlx qz7A== 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=P6zJH2jBOl2k/sKYZsz1ddUUAouqqa6Q5b89oPlyQiw=; b=OjEOYSsoR4uCDrG8hHE3KXeq2Z681HJhP3yKH2Hw2cJTvDeH+s5ShScLdmgd0lb7Pf 88EclTYQXj67u+Nb7xctu9u3ZoI/yZHht+lveHuPKnIto+TE/pnYp6nKvAhzyYtuQSLN GUHtBgTHsmiT2/X4m0K7zUGIFGuYlT1VHvPeFX0Yjt/PRLxSdbVM4ilZwEKsmGLj2zB7 aXVgdKTgSlLb1cqWnPmypoTPIcm2FNibzCry5gCKKEtgVQHdvNuncPC57ZS8ttCfAV5W hoofkOnLg+BD7uAxQVVeFtrOJ9gmJ48ay+keHwVAd4Tr3I62Apb6451fdlc19dX3nvNT kUAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="PjN/ZZek"; 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 cd20-20020a056a00421400b0056c45eb2147si6965369pfb.51.2022.10.30.18.53.58; Sun, 30 Oct 2022 18:54:10 -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="PjN/ZZek"; 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 S229707AbiJaBGI (ORCPT + 99 others); Sun, 30 Oct 2022 21:06:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229637AbiJaBGF (ORCPT ); Sun, 30 Oct 2022 21:06:05 -0400 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41DED9FF2 for ; Sun, 30 Oct 2022 18:06:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1667178364; x=1698714364; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uEGja7y75UUPzrjK6H3IN4daa8pbnGT3JK5PG289ku4=; b=PjN/ZZek0Eiw7ZTPC7V1wgLIElfvP44tkfDNJ2Ha+CYitT2KwqaSp/1D gIOY8218JtufLNIOeTVVH9wp/Yn4rPTS0dMZkTQ4XTj3rIOyOWQzWO3RS yAnEGgzWXwvsaCwc2fRmnV1afKnSjk95O6HWhSuVC1J4nJeFvxFgZObCj tIilq0vKWHglGnU06wKvbOiUV/Q3whNH80nmKn/s9/fQSMnQvWkSYLRRT VCjgNfUT6U6EeFrKA40oB9ZNIMk0vHJ2NJzvGH4lKorkySPBaBFQ9SONB eiWEEiQaEnZtzvTJwP21ZwHj3PDCjJNEToT5BMDgTx2zYzTis9WBJLZSs Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10516"; a="373001659" X-IronPort-AV: E=Sophos;i="5.95,227,1661842800"; d="scan'208";a="373001659" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Oct 2022 18:06:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10516"; a="584496136" X-IronPort-AV: E=Sophos;i="5.95,227,1661842800"; d="scan'208";a="584496136" Received: from allen-box.sh.intel.com ([10.239.159.48]) by orsmga003.jf.intel.com with ESMTP; 30 Oct 2022 18:06:01 -0700 From: Lu Baolu To: Joerg Roedel Cc: Jason Gunthorpe , Kevin Tian , Will Deacon , Robin Murphy , Jean-Philippe Brucker , iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [RESEND PATCH v14 02/13] iommu: Add max_pasids field in struct dev_iommu Date: Mon, 31 Oct 2022 08:59:06 +0800 Message-Id: <20221031005917.45690-3-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221031005917.45690-1-baolu.lu@linux.intel.com> References: <20221031005917.45690-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-5.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE 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 e3af4f46e6e0..ac3f6c6dcc6d 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 65a3b3d886dc..297ac79bc21c 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -278,6 +279,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; @@ -303,6 +322,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.34.1