public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Joerg Roedel <joerg.roedel@amd.com>
To: Ingo Molnar <mingo@elte.hu>
Cc: iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org,
	Joerg Roedel <joerg.roedel@amd.com>
Subject: [PATCH 09/34] x86/amd-iommu: Implement protection domain list
Date: Fri, 27 Nov 2009 14:55:20 +0100	[thread overview]
Message-ID: <1259330145-14865-10-git-send-email-joerg.roedel@amd.com> (raw)
In-Reply-To: <1259330145-14865-1-git-send-email-joerg.roedel@amd.com>

This patch adds code to keep a global list of all protection
domains. This allows to simplify the resume code.

Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
---
 arch/x86/include/asm/amd_iommu_types.h |    7 ++++++
 arch/x86/kernel/amd_iommu.c            |   33 ++++++++++++++++++++++++++++++++
 arch/x86/kernel/amd_iommu_init.c       |    8 +++++++
 3 files changed, 48 insertions(+), 0 deletions(-)

diff --git a/arch/x86/include/asm/amd_iommu_types.h b/arch/x86/include/asm/amd_iommu_types.h
index e68b148..b332b7f 100644
--- a/arch/x86/include/asm/amd_iommu_types.h
+++ b/arch/x86/include/asm/amd_iommu_types.h
@@ -231,6 +231,7 @@ extern bool amd_iommu_dump;
  * independent of their use.
  */
 struct protection_domain {
+	struct list_head list;  /* for list of all protection domains */
 	spinlock_t lock;	/* mostly used to lock the page table*/
 	u16 id;			/* the domain id written to the device table */
 	int mode;		/* paging mode (0-6 levels) */
@@ -376,6 +377,12 @@ extern struct amd_iommu *amd_iommus[MAX_IOMMUS];
 extern int amd_iommus_present;
 
 /*
+ * Declarations for the global list of all protection domains
+ */
+extern spinlock_t amd_iommu_pd_lock;
+extern struct list_head amd_iommu_pd_list;
+
+/*
  * Structure defining one entry in the device table
  */
 struct dev_table_entry {
diff --git a/arch/x86/kernel/amd_iommu.c b/arch/x86/kernel/amd_iommu.c
index b2c19f4..0c4319b 100644
--- a/arch/x86/kernel/amd_iommu.c
+++ b/arch/x86/kernel/amd_iommu.c
@@ -985,6 +985,31 @@ static void dma_ops_free_addresses(struct dma_ops_domain *dom,
  *
  ****************************************************************************/
 
+/*
+ * This function adds a protection domain to the global protection domain list
+ */
+static void add_domain_to_list(struct protection_domain *domain)
+{
+	unsigned long flags;
+
+	spin_lock_irqsave(&amd_iommu_pd_lock, flags);
+	list_add(&domain->list, &amd_iommu_pd_list);
+	spin_unlock_irqrestore(&amd_iommu_pd_lock, flags);
+}
+
+/*
+ * This function removes a protection domain to the global
+ * protection domain list
+ */
+static void del_domain_from_list(struct protection_domain *domain)
+{
+	unsigned long flags;
+
+	spin_lock_irqsave(&amd_iommu_pd_lock, flags);
+	list_del(&domain->list);
+	spin_unlock_irqrestore(&amd_iommu_pd_lock, flags);
+}
+
 static u16 domain_id_alloc(void)
 {
 	unsigned long flags;
@@ -1073,6 +1098,8 @@ static void dma_ops_domain_free(struct dma_ops_domain *dom)
 	if (!dom)
 		return;
 
+	del_domain_from_list(&dom->domain);
+
 	free_pagetable(&dom->domain);
 
 	for (i = 0; i < APERTURE_MAX_RANGES; ++i) {
@@ -1113,6 +1140,8 @@ static struct dma_ops_domain *dma_ops_domain_alloc(struct amd_iommu *iommu)
 	dma_dom->need_flush = false;
 	dma_dom->target_dev = 0xffff;
 
+	add_domain_to_list(&dma_dom->domain);
+
 	if (alloc_new_range(iommu, dma_dom, true, GFP_KERNEL))
 		goto free_dma_dom;
 
@@ -2188,6 +2217,8 @@ static void protection_domain_free(struct protection_domain *domain)
 	if (!domain)
 		return;
 
+	del_domain_from_list(domain);
+
 	if (domain->id)
 		domain_id_free(domain->id);
 
@@ -2207,6 +2238,8 @@ static struct protection_domain *protection_domain_alloc(void)
 	if (!domain->id)
 		goto out_err;
 
+	add_domain_to_list(domain);
+
 	return domain;
 
 out_err:
diff --git a/arch/x86/kernel/amd_iommu_init.c b/arch/x86/kernel/amd_iommu_init.c
index 8567d16..73d5173 100644
--- a/arch/x86/kernel/amd_iommu_init.c
+++ b/arch/x86/kernel/amd_iommu_init.c
@@ -142,6 +142,12 @@ struct amd_iommu *amd_iommus[MAX_IOMMUS];
 int amd_iommus_present;
 
 /*
+ * List of protection domains - used during resume
+ */
+LIST_HEAD(amd_iommu_pd_list);
+spinlock_t amd_iommu_pd_lock;
+
+/*
  * Pointer to the device table which is shared by all AMD IOMMUs
  * it is indexed by the PCI device id or the HT unit id and contains
  * information about the domain the device belongs to as well as the
@@ -1263,6 +1269,8 @@ static int __init amd_iommu_init(void)
 	 */
 	amd_iommu_pd_alloc_bitmap[0] = 1;
 
+	spin_lock_init(&amd_iommu_pd_lock);
+
 	/*
 	 * now the data structures are allocated and basically initialized
 	 * start the real acpi table scan
-- 
1.6.5.3



  parent reply	other threads:[~2009-11-27 13:56 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-27 13:55 [git pull] IOMMU updates for 2.6.33 Joerg Roedel
2009-11-27 13:55 ` [PATCH 01/34] x86/amd-iommu: Separate internal interface definitions Joerg Roedel
2009-11-27 13:55 ` [PATCH 02/34] x86/amd-iommu: Update copyright headers Joerg Roedel
2009-11-27 13:55 ` [PATCH 03/34] x86/amd-iommu: Add an index field to struct amd_iommu Joerg Roedel
2009-11-27 13:55 ` [PATCH 04/34] x86/amd-iommu: Add per IOMMU reference counting Joerg Roedel
2009-11-27 13:55 ` [PATCH 05/34] x86/amd-iommu: Add function to complete a tlb flush Joerg Roedel
2009-11-27 13:55 ` [PATCH 06/34] x86/amd-iommu: Make iommu_flush_pages aware of multiple IOMMUs Joerg Roedel
2009-11-27 13:55 ` [PATCH 07/34] x86/amd-iommu: Use __iommu_flush_pages for tlb flushes Joerg Roedel
2009-11-27 13:55 ` [PATCH 08/34] x86/amd-iommu: Remove iommu_flush_domain function Joerg Roedel
2009-11-27 13:55 ` Joerg Roedel [this message]
2009-11-27 13:55 ` [PATCH 10/34] x86/amd-iommu: Reimplement amd_iommu_flush_all_domains() Joerg Roedel
2009-11-27 13:55 ` [PATCH 11/34] x86/amd-iommu: Reimplement flush_all_domains_on_iommu() Joerg Roedel
2009-11-27 13:55 ` [PATCH 12/34] x86/amd-iommu: Make np-cache a global flag Joerg Roedel
2009-11-27 13:55 ` [PATCH 13/34] x86/amd-iommu: Use check_device for amd_iommu_dma_supported Joerg Roedel
2009-11-27 13:55 ` [PATCH 14/34] x86/amd-iommu: Use check_device in get_device_resources Joerg Roedel
2009-11-27 13:55 ` [PATCH 15/34] x86/amd-iommu: Remove iommu parameter from dma_ops_domain_(un)map Joerg Roedel
2009-11-27 13:55 ` [PATCH 16/34] x86/amd-iommu: Make alloc_new_range aware of multiple IOMMUs Joerg Roedel
2009-11-27 13:55 ` [PATCH 17/34] x86/amd-iommu: Remove iommu parameter from __(un)map_single Joerg Roedel
2009-11-27 13:55 ` [PATCH 18/34] x86/amd-iommu: Remove iommu specific handling from dma_ops path Joerg Roedel
2009-11-27 13:55 ` [PATCH 19/34] x86/amd-iommu: Let domain_for_device handle aliases Joerg Roedel
2009-11-27 13:55 ` [PATCH 20/34] x86/amd-iommu: Simplify get_device_resources() Joerg Roedel
2009-11-27 13:55 ` [PATCH 21/34] x86/amd-iommu: Move find_protection_domain to helper functions Joerg Roedel
2009-11-27 13:55 ` [PATCH 22/34] x86/amd-iommu: Use get_device_id and check_device where appropriate Joerg Roedel
2009-11-27 13:55 ` [PATCH 23/34] x86/amd-iommu: Remove iommu parameter from dma_ops_domain_alloc Joerg Roedel
2009-11-27 13:55 ` [PATCH 24/34] x86/amd-iommu: Move some pte allocation functions in the right section Joerg Roedel
2009-11-27 13:55 ` [PATCH 25/34] x86/amd-iommu: Rearrange dma_ops related functions Joerg Roedel
2009-11-27 13:55 ` [PATCH 26/34] x86/amd-iommu: Remove support for domain sharing Joerg Roedel
2009-11-27 13:55 ` [PATCH 27/34] x86/amd-iommu: Use dev->arch->iommu to store iommu related information Joerg Roedel
2009-11-27 13:55 ` [PATCH 28/34] x86/amd-iommu: Add device bind reference counting Joerg Roedel
2009-11-27 13:55 ` [PATCH 29/34] x86/amd-iommu: Keep devices per domain in a list Joerg Roedel
2009-11-27 13:55 ` [PATCH 30/34] x86/amd-iommu: Cleanup attach/detach_device code Joerg Roedel
2009-11-27 13:55 ` [PATCH 31/34] x86/amd-iommu: Introduce iommu_flush_device() function Joerg Roedel
2009-11-27 13:55 ` [PATCH 32/34] x86/amd-iommu: Cleanup DTE flushing code Joerg Roedel
2009-11-27 13:55 ` [PATCH 33/34] x86/amd-iommu: Move reset_iommu_command_buffer out of locked code Joerg Roedel
2009-11-27 13:55 ` [PATCH 34/34] x86/amd-iommu: Remove amd_iommu_pd_table Joerg Roedel
2009-11-27 19:27 ` [git pull] IOMMU updates for 2.6.33 Ingo Molnar

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=1259330145-14865-10-git-send-email-joerg.roedel@amd.com \
    --to=joerg.roedel@amd.com \
    --cc=iommu@lists.linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    /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