All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yinghai Lu <yinghai@kernel.org>
To: "H. Peter Anvin" <hpa@zytor.com>, Tony Luck <tony.luck@intel.com>,
	Bjorn Helgaas <bhelgaas@google.com>,
	"Rafael J. Wysocki" <rjw@sisk.pl>, x86 <x86@kernel.org>
Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-acpi@vger.kernel.org, Yinghai Lu <yinghai@kernel.org>,
	Joerg Roedel <joro@8bytes.org>,
	Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Subject: [PATCH v2 08/10] IOMMU: Add intel_enable_irq_remapping_one()
Date: Thu,  2 Jan 2014 16:08:15 -0800	[thread overview]
Message-ID: <1388707697-16800-9-git-send-email-yinghai@kernel.org> (raw)
In-Reply-To: <1388707697-16800-1-git-send-email-yinghai@kernel.org>

Will need that for hot-added iommu interrupt remapping suppor.

Signed-off-by: Yinghai <yinghai@kernel.org>
Cc: Joerg Roedel <joro@8bytes.org>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
---
 drivers/iommu/intel_irq_remapping.c | 134 ++++++++++++++++++++++++++++++++++--
 1 file changed, 127 insertions(+), 7 deletions(-)

diff --git a/drivers/iommu/intel_irq_remapping.c b/drivers/iommu/intel_irq_remapping.c
index 8471f40..41d03d7 100644
--- a/drivers/iommu/intel_irq_remapping.c
+++ b/drivers/iommu/intel_irq_remapping.c
@@ -218,7 +218,7 @@ static struct intel_iommu *map_ioapic_to_ir(int apic)
 {
 	int i;
 
-	for (i = 0; i < MAX_IO_APICS; i++)
+	for (i = 0; i < ir_ioapic_num; i++)
 		if (ir_ioapic[i].id == apic)
 			return ir_ioapic[i].iommu;
 	return NULL;
@@ -324,7 +324,7 @@ static int set_ioapic_sid(struct irte *irte, int apic)
 	if (!irte)
 		return -1;
 
-	for (i = 0; i < MAX_IO_APICS; i++) {
+	for (i = 0; i < ir_ioapic_num; i++) {
 		if (ir_ioapic[i].id == apic) {
 			sid = (ir_ioapic[i].bus << 8) | ir_ioapic[i].devfn;
 			break;
@@ -704,6 +704,7 @@ static void ir_parse_one_ioapic_scope(struct acpi_dmar_device_scope *scope,
 	struct acpi_dmar_pci_path *path;
 	u8 bus;
 	int count;
+	int i;
 
 	bus = scope->bus;
 	path = (struct acpi_dmar_pci_path *)(scope + 1);
@@ -720,11 +721,16 @@ static void ir_parse_one_ioapic_scope(struct acpi_dmar_device_scope *scope,
 		path++;
 	}
 
-	ir_ioapic[ir_ioapic_num].bus   = bus;
-	ir_ioapic[ir_ioapic_num].devfn = PCI_DEVFN(path->device, path->function);
-	ir_ioapic[ir_ioapic_num].iommu = iommu;
-	ir_ioapic[ir_ioapic_num].id    = scope->enumeration_id;
-	ir_ioapic_num++;
+	for (i = 0; i < ir_ioapic_num; i++)
+		if (!ir_ioapic[i].iommu)
+			break;
+
+	ir_ioapic[i].bus   = bus;
+	ir_ioapic[i].devfn = PCI_DEVFN(path->device, path->function);
+	ir_ioapic[i].iommu = iommu;
+	ir_ioapic[i].id    = scope->enumeration_id;
+	if (i == ir_ioapic_num)
+		ir_ioapic_num++;
 }
 
 static int ir_parse_ioapic_hpet_scope(struct acpi_dmar_header *header,
@@ -1139,6 +1145,120 @@ static int intel_setup_hpet_msi(unsigned int irq, unsigned int id)
 	return 0;
 }
 
+void disable_irq_remapping_one(struct dmar_drhd_unit *drhd)
+{
+	struct intel_iommu *iommu = drhd->iommu;
+	int i;
+
+	/*
+	 * Disable Interrupt-remapping for the DRHD's now.
+	 */
+	if (!ecap_ir_support(iommu->ecap))
+		return;
+
+	iommu_disable_irq_remapping(iommu);
+
+	/* remove it from ir_ioapic */
+	for (i = 0; i < ir_ioapic_num; i++)
+		if (ir_ioapic[i].iommu == iommu) {
+			ir_ioapic[i].iommu = NULL;
+			ir_ioapic[i].id	= 0xff;
+		}
+}
+
+static int parse_ioapics_under_ir_one(struct dmar_drhd_unit *drhd)
+{
+	int ir_supported = 0;
+
+	struct intel_iommu *iommu = drhd->iommu;
+
+	if (ecap_ir_support(iommu->ecap)) {
+		if (ir_parse_ioapic_hpet_scope(drhd->hdr, iommu))
+			return -1;
+
+		ir_supported = 1;
+	}
+
+	return ir_supported;
+}
+
+int intel_enable_irq_remapping_one(struct dmar_drhd_unit *drhd)
+{
+	int setup = 0;
+	int eim = 1;
+	int ret;
+	struct intel_iommu *iommu = drhd->iommu;
+
+	if (parse_ioapics_under_ir_one(drhd) != 1) {
+		pr_info("Not enable interrupt remapping\n");
+		return -1;
+	}
+
+	/*
+	 * If the queued invalidation is already initialized,
+	 * shouldn't disable it.
+	 */
+	if (!iommu->qi) {
+		/*
+		 * Clear previous faults.
+		 */
+		dmar_fault(-1, iommu);
+
+		/*
+		 * Disable intr remapping and queued invalidation, if already
+		 * enabled prior to OS handover.
+		 */
+		iommu_disable_irq_remapping(iommu);
+
+		dmar_disable_qi(iommu);
+	}
+
+	/*
+	 * check for the Interrupt-remapping support
+	 */
+
+	if (ecap_ir_support(iommu->ecap))
+		if (eim && !ecap_eim_support(iommu->ecap)) {
+			pr_info("DRHD %Lx: EIM not supported by DRHD, ecap %Lx\n",
+				drhd->reg_base_addr, iommu->ecap);
+			return -1;
+		}
+
+	/*
+	 * Enable queued invalidation for the DRHD's.
+	 */
+	ret = dmar_enable_qi(iommu);
+
+	if (ret) {
+		pr_err("DRHD %Lx: failed to enable queued, invalidation, ecap %Lx, ret %d\n",
+		       drhd->reg_base_addr, iommu->ecap, ret);
+		return -1;
+	}
+
+	/*
+	 * Setup Interrupt-remapping for the DRHD's now.
+	 */
+	if (ecap_ir_support(iommu->ecap)) {
+		if (intel_setup_irq_remapping(iommu, eim))
+			goto error;
+
+		setup = 1;
+	}
+
+	if (!setup)
+		goto error;
+
+	pr_info("Enabled IRQ remapping in %s mode\n", eim ? "x2apic" : "xapic");
+
+	return eim ? IRQ_REMAP_X2APIC_MODE : IRQ_REMAP_XAPIC_MODE;
+
+error:
+	/*
+	 * handle error condition gracefully here!
+	 */
+	return -1;
+}
+
 struct irq_remap_ops intel_irq_remap_ops = {
 	.supported		= intel_irq_remapping_supported,
 	.prepare		= dmar_table_init,
-- 
1.8.4

  parent reply	other threads:[~2014-01-03  0:08 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-03  0:08 [PATCH v2 00/10] IOMMU: irq-remapping and dmar hotplug support Yinghai Lu
2014-01-03  0:08 ` [PATCH v2 01/10] IOMMU: Update dmar units devices list during hotplug Yinghai Lu
2014-01-03  0:08 ` [PATCH v2 02/10] IOMMU: Fix tboot force iommu logic Yinghai Lu
2014-01-03  0:08 ` [PATCH v2 03/10] IOMMU: Don't clean handler data before free_irq() Yinghai Lu
2014-01-03  0:08 ` [PATCH v2 04/10] IOMMU: iommu_unique_seq_id() Yinghai Lu
2014-01-03  0:08 ` [PATCH v2 05/10] ACPI: Add acpi_run_dsm() Yinghai Lu
2014-01-03  0:08 ` [PATCH v2 06/10] IOMMU: Separate free_dmar_iommu from free_iommu Yinghai Lu
2014-01-03  0:08 ` [PATCH v2 07/10] IOMMU: Add init_dmar_one() Yinghai Lu
2014-01-03  0:08 ` Yinghai Lu [this message]
2014-01-03  0:08 ` [PATCH v2 09/10] IOMMU: Add dmar_parse_one_drhd() Yinghai Lu
2014-01-03  0:08 ` [PATCH v2 10/10] IOMMU: Add intel iommu irq-remapping and dmar hotplug support Yinghai Lu
2014-01-06  2:23   ` Yijing Wang
2014-01-06  2:23     ` Yijing Wang
2014-01-06  3:12   ` Yijing Wang
2014-01-06  3:12     ` Yijing Wang

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=1388707697-16800-9-git-send-email-yinghai@kernel.org \
    --to=yinghai@kernel.org \
    --cc=bhelgaas@google.com \
    --cc=hpa@zytor.com \
    --cc=joro@8bytes.org \
    --cc=konrad.wilk@oracle.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=rjw@sisk.pl \
    --cc=tony.luck@intel.com \
    --cc=x86@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.