Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp931470rwb; Fri, 13 Jan 2023 06:03:39 -0800 (PST) X-Google-Smtp-Source: AMrXdXsd4GiAACE9JBCGyN3B9AcTdMBw2drHFE59qvkDe7d8zBFy/cfwQ/w5iy+htSvmtr5hemXO X-Received: by 2002:a05:6402:1119:b0:472:46bf:fb3c with SMTP id u25-20020a056402111900b0047246bffb3cmr66508477edv.35.1673618619629; Fri, 13 Jan 2023 06:03:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673618619; cv=none; d=google.com; s=arc-20160816; b=TgXqB606M2cfFUNaJGN5puxMXoiTK6lRBXEP+CFd9JdlzD2ib9021tVtO6UoVbM2xJ V/Ib9TCTGqSg+jY7b0kp6d8e7okycUXAhqqnqP7gYSybFvSzv3dKfDkslxniVoiGPtu2 wH8l0DDO+CPROL4tKc98uGupSdkJ6I8QfqEgKuyH4KZTSzij8bZTdeh6BOPeVKO8aXF3 nDtMr06FJaHIGSQ9FQVuSncl9p0S6pg0qxT3tqaZRkLGHe/QCCv8pFKWTar9yZwg2CDc fNAoWd2bTe2zXrF5C+rxRCEnpFM2b7Cp8WXT3PDX/tqVbV0Gq407YG+LFm0PFmuMC+cB //Ng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:to:content-language:subject:cc:user-agent:mime-version :date:message-id:dkim-signature; bh=x96tmSEkPKr3U6Lyvplq33h6Gsm93tdEhuR5UvmVKvk=; b=CJHR4u5w3ATUXC+96Oaiu8fo5W5q54069dUi58M+q2QzaXwsLM0mbY5P0WRyG8UZlC gAg+d/qH85n/DrsaHTdSsQ4oJNblLS1sQiPUnir5cbr8XEELUkQaEyMB1xmZJZ61+in5 FPRY3+bvkd6XuezOZN3PmIOfk2NKtlcK7zC4KXdmRq7FiBpCz3A/xvZ0r8ai2lrISAO8 c6Ysef26AQvASXXAr1Ry0goJFKin9xhtJEKSNvl7Tsd4AjfBEaJN7WeoQ/nOpAV31X19 NcY4kyOzeL78Zss7zxk83Ct/KTnxX/xYvH6aiDVPa2+pdfGnFLHfKXM/71r0JA1wgwU4 N2JQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ZL4sg65w; 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 f15-20020a0564021e8f00b0048d6ace589esi26874687edf.128.2023.01.13.06.03.24; Fri, 13 Jan 2023 06:03:39 -0800 (PST) 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=ZL4sg65w; 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 S241024AbjAMN7q (ORCPT + 51 others); Fri, 13 Jan 2023 08:59:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241389AbjAMN7W (ORCPT ); Fri, 13 Jan 2023 08:59:22 -0500 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 159AE81D4A for ; Fri, 13 Jan 2023 05:56:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673618163; x=1705154163; h=message-id:date:mime-version:cc:subject:to:references: from:in-reply-to:content-transfer-encoding; bh=VZwFXYFnGMfG3iKDlkJ1lb1QPSC6NG8ZjIgCRDtG7lk=; b=ZL4sg65wpZareORVTZI9jkuZBqMViKNzi/1eWeeyPA+upzqZyBrwevim 9AemeFEkJmB3rjPcJirV+CekPr2rJcg8qyBCAV2dv3iY6kDTT+89EaTiE 7ljd1WV32aUmO5rFnZPK84wd/6tI3wqC6IPG/Vko2FMhsxtvs/LYGYxYT f+wcZgZ503mlkw86acBcoc/APFKNMyPIvKUuj9PG6oBRVyGofGADENv59 OUezEu/f2ifEde0XbjVlmmEqPz8aqPdBvm3x7ylz35yZf7IuE8CyS+3LJ JXNOzz6M1yPUyow1YE9MCeTtqsqoBVHcM3hkMp5BSEo4h7Z1o+RCzz0bJ g==; X-IronPort-AV: E=McAfee;i="6500,9779,10589"; a="307539820" X-IronPort-AV: E=Sophos;i="5.97,214,1669104000"; d="scan'208";a="307539820" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jan 2023 05:56:01 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10589"; a="608178088" X-IronPort-AV: E=Sophos;i="5.97,214,1669104000"; d="scan'208";a="608178088" Received: from blu2-mobl.ccr.corp.intel.com (HELO [10.252.190.181]) ([10.252.190.181]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jan 2023 05:55:58 -0800 Message-ID: <6783f737-2701-77e3-ce83-8d287be51cf6@linux.intel.com> Date: Fri, 13 Jan 2023 21:55:55 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Cc: baolu.lu@linux.intel.com Subject: Re: [PATCH 3/7] iommu/vt-d: Support Enhanced Command Interface Content-Language: en-US To: kan.liang@linux.intel.com, joro@8bytes.org, will@kernel.org, dwmw2@infradead.org, robin.murphy@arm.com, robert.moore@intel.com, rafael.j.wysocki@intel.com, lenb@kernel.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org References: <20230111202504.378258-1-kan.liang@linux.intel.com> <20230111202504.378258-4-kan.liang@linux.intel.com> From: Baolu Lu In-Reply-To: <20230111202504.378258-4-kan.liang@linux.intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,NICE_REPLY_A,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 On 2023/1/12 4:25, kan.liang@linux.intel.com wrote: > From: Kan Liang > > The Enhanced Command Register is to submit command and operand of > enhanced commands to DMA Remapping hardware. It can supports upto 256 > enhanced commands. > > There is a HW register to indicate the availability of all 256 enhanced > commands. Each bit stands for each command. But there isn't an existing > interface to read/write all 256 bits. Introduce the u64 ecmdcap[4] to > store the existence of each enhanced command. Read 4 times to get > all of them in map_iommu(). > > Add a helper to facilitate an enhanced command launch. Make sure hardware > complete the command. > > Add a helper to facilitate the check of PMU essentials. > > The helpers will be used later. > > Signed-off-by: Kan Liang > --- > drivers/iommu/intel/dmar.c | 63 +++++++++++++++++++++++++++++++++++++ > drivers/iommu/intel/iommu.h | 46 +++++++++++++++++++++++++++ > 2 files changed, 109 insertions(+) > > diff --git a/drivers/iommu/intel/dmar.c b/drivers/iommu/intel/dmar.c > index 91bb48267df2..dcafa32875c1 100644 > --- a/drivers/iommu/intel/dmar.c > +++ b/drivers/iommu/intel/dmar.c > @@ -1025,6 +1025,16 @@ static int map_iommu(struct intel_iommu *iommu, struct dmar_drhd_unit *drhd) > goto release; > } > } > + > + if (cap_ecmds(iommu->cap)) { > + int i; > + > + for (i = 0; i < DMA_MAX_NUM_ECMDCAP; i++) { > + iommu->ecmdcap[i] = dmar_readq(iommu->reg + DMAR_ECCAP_REG + > + i * DMA_ECMD_REG_STEP); > + } > + } > + > err = 0; > goto out; > > @@ -2434,3 +2444,56 @@ bool dmar_platform_optin(void) > return ret; > } > EXPORT_SYMBOL_GPL(dmar_platform_optin); > + > +#ifdef CONFIG_INTEL_IOMMU Why do you need above #ifdef? > +#define ecmd_get_status_code(res) ((res & 0xff) >> 1) > + > +/* > + * Function to submit a command to the enhanced command interface. The > + * valid enhanced command descriptions are defined in Table 47 of the > + * VT-d spec. The VT-d hardware implementation may support some but not > + * all commands, which can be determined by checking the Enhanced > + * Command Capability Register. > + * > + * Return values: > + * - 0: Command successful without any error; > + * - Negative: software error value; > + * - Nonzero positive: failure status code defined in Table 48. > + */ > +int ecmd_submit_sync(struct intel_iommu *iommu, u8 ecmd, > + u64 oa, bool has_ob, u64 ob) > +{ > + unsigned long flags; > + u64 res; > + int ret; > + > + if (!cap_ecmds(iommu->cap)) > + return -ENODEV; > + > + raw_spin_lock_irqsave(&iommu->register_lock, flags); > + > + res = dmar_readq(iommu->reg + DMAR_ECRSP_REG); > + if (res & DMA_ECMD_ECRSP_IP) { > + ret = -EBUSY; > + goto err; > + } > + > + if (has_ob) > + dmar_writeq(iommu->reg + DMAR_ECEO_REG, ob); The ecmds that require a Operand B are statically defined in the spec, right? What will it look like if we define a static ignore_ob(ecmd)? > + dmar_writeq(iommu->reg + DMAR_ECMD_REG, ecmd | (oa << DMA_ECMD_OA_SHIFT)); > + > + IOMMU_WAIT_OP(iommu, DMAR_ECRSP_REG, dmar_readq, > + !(res & DMA_ECMD_ECRSP_IP), res); > + > + if (res & DMA_ECMD_ECRSP_IP) { > + ret = -ETIMEDOUT; > + goto err; > + } > + > + ret = ecmd_get_status_code(res); > +err: > + raw_spin_unlock_irqrestore(&iommu->register_lock, flags); > + > + return ret; > +} > +#endif /* CONFIG_INTEL_IOMMU */ > diff --git a/drivers/iommu/intel/iommu.h b/drivers/iommu/intel/iommu.h > index 5bcefbea55c9..f227107434ac 100644 > --- a/drivers/iommu/intel/iommu.h > +++ b/drivers/iommu/intel/iommu.h > @@ -130,6 +130,10 @@ > #define DMAR_PERFOVFOFF_REG 0x318 > #define DMAR_PERFCNTROFF_REG 0x31c > #define DMAR_PERFEVNTCAP_REG 0x380 > +#define DMAR_ECMD_REG 0x400 > +#define DMAR_ECEO_REG 0x408 > +#define DMAR_ECRSP_REG 0x410 > +#define DMAR_ECCAP_REG 0x430 > #define DMAR_VCCAP_REG 0xe30 /* Virtual command capability register */ > #define DMAR_VCMD_REG 0xe00 /* Virtual command register */ > #define DMAR_VCRSP_REG 0xe10 /* Virtual command response register */ > @@ -304,6 +308,26 @@ > #define DMA_CCMD_SID(s) (((u64)((s) & 0xffff)) << 16) > #define DMA_CCMD_DID(d) ((u64)((d) & 0xffff)) > > +/* ECMD_REG */ > +#define DMA_MAX_NUM_ECMD 256 > +#define DMA_MAX_NUM_ECMDCAP (DMA_MAX_NUM_ECMD / 64) > +#define DMA_ECMD_REG_STEP 8 > +#define DMA_ECMD_ENABLE 0xf0 > +#define DMA_ECMD_DISABLE 0xf1 > +#define DMA_ECMD_FREEZE 0xf4 > +#define DMA_ECMD_UNFREEZE 0xf5 > +#define DMA_ECMD_OA_SHIFT 16 > +#define DMA_ECMD_ECRSP_IP 0x1 > +#define DMA_ECMD_ECCAP3 3 > +#define DMA_ECMD_ECCAP3_ECNTS (1ULL << 48) > +#define DMA_ECMD_ECCAP3_DCNTS (1ULL << 49) > +#define DMA_ECMD_ECCAP3_FCNTS (1ULL << 52) > +#define DMA_ECMD_ECCAP3_UFCNTS (1ULL << 53) > +#define DMA_ECMD_ECCAP3_ESSENTIAL (DMA_ECMD_ECCAP3_ECNTS | \ > + DMA_ECMD_ECCAP3_DCNTS | \ > + DMA_ECMD_ECCAP3_FCNTS | \ > + DMA_ECMD_ECCAP3_UFCNTS) > + > /* FECTL_REG */ > #define DMA_FECTL_IM (((u32)1) << 31) > > @@ -600,6 +624,7 @@ struct intel_iommu { > u64 cap; > u64 ecap; > u64 vccap; > + u64 ecmdcap[DMA_MAX_NUM_ECMDCAP]; > u32 gcmd; /* Holds TE, EAFL. Don't need SRTP, SFL, WBF */ > raw_spinlock_t register_lock; /* protect register handling */ > int seq_id; /* sequence id of the iommu */ > @@ -841,6 +866,15 @@ extern const struct iommu_ops intel_iommu_ops; > extern int intel_iommu_sm; > extern int iommu_calculate_agaw(struct intel_iommu *iommu); > extern int iommu_calculate_max_sagaw(struct intel_iommu *iommu); > +extern int ecmd_submit_sync(struct intel_iommu *iommu, u8 ecmd, > + u64 oa, bool has_ob, u64 ob); > + > +static inline bool ecmd_has_pmu_essential(struct intel_iommu *iommu) > +{ > + return (iommu->ecmdcap[DMA_ECMD_ECCAP3] & DMA_ECMD_ECCAP3_ESSENTIAL) == > + DMA_ECMD_ECCAP3_ESSENTIAL; > +} > + > extern int dmar_disabled; > extern int intel_iommu_enabled; > #else > @@ -852,6 +886,18 @@ static inline int iommu_calculate_max_sagaw(struct intel_iommu *iommu) > { > return 0; > } > + > +static inline int ecmd_submit_sync(struct intel_iommu *iommu, u8 ecmd, > + u64 oa, bool has_ob, u64 ob) > +{ > + return -EOPNOTSUPP; > +} > + > +static inline bool ecmd_has_pmu_essential(struct intel_iommu *iommu) > +{ > + return false; > +} Is there any need to call these helpers when INTEL_IOMMU is not configured? > + > #define dmar_disabled (1) > #define intel_iommu_enabled (0) > #define intel_iommu_sm (0) -- Best regards, baolu