public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Baolu Lu <baolu.lu@linux.intel.com>
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
Cc: baolu.lu@linux.intel.com
Subject: Re: [PATCH V2 3/7] iommu/vt-d: Support Enhanced Command Interface
Date: Thu, 19 Jan 2023 16:55:45 +0800	[thread overview]
Message-ID: <379823f4-d1c3-8943-4afe-e33f4d21785c@linux.intel.com> (raw)
In-Reply-To: <20230118205006.3182907-4-kan.liang@linux.intel.com>

On 2023/1/19 4:50, kan.liang@linux.intel.com wrote:
> +#ifdef CONFIG_INTEL_IOMMU
> +#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, 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;
> +	}
> +
> +	/*
> +	 * Unconditionally write the operand B, because
> +	 * - There is no side effect if an ecmd doesn't require an
> +	 *   operand B, but we set the register to some value.
> +	 * - It's not invoked in any critical path. The extra MMIO
> +	 *   write doesn't bring any performance concerns.
> +	 */
> +	dmar_writeq(iommu->reg + DMAR_ECEO_REG, ob);
> +	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 */

Can we remove the "#ifdef CONFIG_INTEL_IOMMU"? Or if this is currently
only intel-iommu specific, how about moving it to drivers/iommu/intel
/iommu.c?

--
Best regards,
baolu

  reply	other threads:[~2023-01-20  4:34 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-18 20:49 [PATCH V2 0/7] iommu/vt-d: Support performance monitoring for IOMMU kan.liang
2023-01-18 20:50 ` [PATCH V2 1/7] iommu/vt-d: Support size of the register set in DRHD kan.liang
2023-01-18 20:50 ` [PATCH V2 2/7] iommu/vt-d: Retrieve IOMMU perfmon capability information kan.liang
2023-01-18 20:50 ` [PATCH V2 3/7] iommu/vt-d: Support Enhanced Command Interface kan.liang
2023-01-19  8:55   ` Baolu Lu [this message]
2023-01-19 13:24     ` Liang, Kan
2023-01-18 20:50 ` [PATCH V2 4/7] iommu/vt-d: Add IOMMU perfmon support kan.liang
2023-01-18 20:50 ` [PATCH V2 5/7] iommu/vt-d: Support cpumask for IOMMU perfmon kan.liang
2023-01-18 20:50 ` [PATCH V2 6/7] iommu/vt-d: Add IOMMU perfmon overflow handler support kan.liang
2023-01-18 20:50 ` [PATCH V2 7/7] iommu/vt-d: Enable IOMMU perfmon support kan.liang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=379823f4-d1c3-8943-4afe-e33f4d21785c@linux.intel.com \
    --to=baolu.lu@linux.intel.com \
    --cc=dwmw2@infradead.org \
    --cc=iommu@lists.linux.dev \
    --cc=joro@8bytes.org \
    --cc=kan.liang@linux.intel.com \
    --cc=lenb@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rafael.j.wysocki@intel.com \
    --cc=robert.moore@intel.com \
    --cc=robin.murphy@arm.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox