mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Wei Yang <richard.weiyang@gmail.com>
To: joro@8bytes.org, jiang.liu@linux.intel.com, tglx@linutronix.de
Cc: iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org,
	Wei Yang <richard.weiyang@gmail.com>
Subject: [PATCH V4 4/4] iommu/vt-d: refine dmar_acpi_dev_scope_init() with dmar_walk_dmar_table()
Date: Thu, 14 Apr 2016 14:55:10 +0000	[thread overview]
Message-ID: <1460645710-22656-5-git-send-email-richard.weiyang@gmail.com> (raw)
In-Reply-To: <1460645710-22656-1-git-send-email-richard.weiyang@gmail.com>

dmar_acpi_dev_scope_init() iterates on the remapping structure and just do
proper job for ANDD structure. This is the what dmar_walk_dmar_table()
does.

This patch improves the code with dmar_walk_dmar_table().

Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
---
 drivers/iommu/dmar.c |   56 ++++++++++++++++++++++++++++----------------------
 1 file changed, 32 insertions(+), 24 deletions(-)

diff --git a/drivers/iommu/dmar.c b/drivers/iommu/dmar.c
index 35fc8fb..6281b45 100644
--- a/drivers/iommu/dmar.c
+++ b/drivers/iommu/dmar.c
@@ -733,36 +733,44 @@ static void __init dmar_acpi_insert_dev_scope(u8 device_number,
 		device_number, dev_name(&adev->dev));
 }
 
-static int __init dmar_acpi_dev_scope_init(void)
+static int __dmar_acpi_dev_scope_init(struct acpi_dmar_header *header,
+				      void *arg)
 {
 	struct acpi_dmar_andd *andd;
+	acpi_handle h;
+	struct acpi_device *adev;
+
+	andd = (struct acpi_dmar_andd *)header;
+	if (!ACPI_SUCCESS(acpi_get_handle(ACPI_ROOT_OBJECT,
+					  andd->device_name,
+					  &h))) {
+		pr_err("Failed to find handle for ACPI object %s\n",
+		       andd->device_name);
+		return 0;
+	}
+	if (acpi_bus_get_device(h, &adev)) {
+		pr_err("Failed to get device for ACPI object %s\n",
+		       andd->device_name);
+		return 0;
+	}
+	dmar_acpi_insert_dev_scope(andd->device_number, adev);
+	return 0;
+}
+
+static int __init dmar_acpi_dev_scope_init(void)
+{
+	struct acpi_table_dmar *dmar;
+	struct dmar_res_callback cb = {
+		.print_entry = false,
+		.ignore_unhandled = true,
+		.cb[ACPI_DMAR_TYPE_NAMESPACE] = &__dmar_acpi_dev_scope_init,
+	};
 
 	if (dmar_tbl == NULL)
 		return -ENODEV;
 
-	for (andd = (void *)dmar_tbl + sizeof(struct acpi_table_dmar);
-	     ((unsigned long)andd) < ((unsigned long)dmar_tbl) + dmar_tbl->length;
-	     andd = ((void *)andd) + andd->header.length) {
-		if (andd->header.type == ACPI_DMAR_TYPE_NAMESPACE) {
-			acpi_handle h;
-			struct acpi_device *adev;
-
-			if (!ACPI_SUCCESS(acpi_get_handle(ACPI_ROOT_OBJECT,
-							  andd->device_name,
-							  &h))) {
-				pr_err("Failed to find handle for ACPI object %s\n",
-				       andd->device_name);
-				continue;
-			}
-			if (acpi_bus_get_device(h, &adev)) {
-				pr_err("Failed to get device for ACPI object %s\n",
-				       andd->device_name);
-				continue;
-			}
-			dmar_acpi_insert_dev_scope(andd->device_number, adev);
-		}
-	}
-	return 0;
+	dmar = (struct acpi_table_dmar *)dmar_tbl;
+	return dmar_walk_dmar_table(dmar, &cb);
 }
 
 int __init dmar_dev_scope_init(void)
-- 
1.7.9.5

  parent reply	other threads:[~2016-04-14 14:55 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-14 14:55 [PATCH V4 0/4] Code refine for Intel IOMMU Wei Yang
2016-04-14 14:55 ` [PATCH V4 1/4] iommu/vt-d: replace *hdr with {drhd/atsr}[0] in struct dmar_{drhd/atsr}_unit Wei Yang
2016-04-14 14:55 ` [PATCH V4 2/4] iommu/vt-d: use zero-sized array in DMAR related ACPI structures Wei Yang
2016-04-14 14:55 ` [PATCH V4 3/4] iommu/vt-d: check Register Base Address at the beginning of dmar_parse_one_drhd() Wei Yang
2016-04-14 14:55 ` Wei Yang [this message]
2016-05-08 13:22 ` [PATCH V4 0/4] Code refine for Intel IOMMU Wei Yang
2016-05-09 11:24   ` Joerg Roedel
2016-05-09 22:20     ` Wei Yang

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=1460645710-22656-5-git-send-email-richard.weiyang@gmail.com \
    --to=richard.weiyang@gmail.com \
    --cc=iommu@lists.linux-foundation.org \
    --cc=jiang.liu@linux.intel.com \
    --cc=joro@8bytes.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tglx@linutronix.de \
    /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

all inboxes | Powered by JetHome®