public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 03/13] set iommu agaw
@ 2008-12-02 14:22 Han, Weidong
  2008-12-04 17:12 ` Mark McLoughlin
  0 siblings, 1 reply; 3+ messages in thread
From: Han, Weidong @ 2008-12-02 14:22 UTC (permalink / raw)
  To: 'Avi Kivity', Woodhouse, David, 'Jesse Barnes'
  Cc: 'Joerg Roedel', Kay, Allen M, Yu, Fenghua,
	'kvm@vger.kernel.org',
	'iommu@lists.linux-foundation.org'

[-- Attachment #1: Type: text/plain, Size: 2227 bytes --]

agaw may be different across iommus.

Signed-off-by: Weidong Han <weidong.han@intel.com>
---
 drivers/pci/dmar.c            |   14 ++++++++++++++
 include/linux/dma_remapping.h |    2 ++
 include/linux/intel-iommu.h   |    1 +
 3 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/drivers/pci/dmar.c b/drivers/pci/dmar.c
index 691b3ad..ebcc7c2 100644
--- a/drivers/pci/dmar.c
+++ b/drivers/pci/dmar.c
@@ -491,6 +491,8 @@ int alloc_iommu(struct dmar_drhd_unit *drhd)
 	int map_size;
 	u32 ver;
 	static int iommu_allocated = 0;
+	unsigned long sagaw;
+	int agaw;
 
 	iommu = kzalloc(sizeof(*iommu), GFP_KERNEL);
 	if (!iommu)
@@ -506,6 +508,18 @@ int alloc_iommu(struct dmar_drhd_unit *drhd)
 	iommu->cap = dmar_readq(iommu->reg + DMAR_CAP_REG);
 	iommu->ecap = dmar_readq(iommu->reg + DMAR_ECAP_REG);
 
+	/* set agaw, "SAGAW" may be different across iommus */
+	sagaw = cap_sagaw(iommu->cap);
+	for (agaw = width_to_agaw(DEFAULT_DOMAIN_ADDRESS_WIDTH);
+	     agaw >= 0; agaw--)
+		if (test_bit(agaw, &sagaw))
+			break;
+	if (agaw < 0) {
+		printk(KERN_ERR "IOMMU: unsupported sagaw %lx\n", sagaw);
+		goto error;
+	}
+	iommu->agaw = agaw;
+
 	/* the registers might be more than one page */
 	map_size = max_t(int, ecap_max_iotlb_offset(iommu->ecap),
 		cap_max_fault_reg_offset(iommu->cap));
diff --git a/include/linux/dma_remapping.h b/include/linux/dma_remapping.h
index eeb8243..c9d99c9 100644
--- a/include/linux/dma_remapping.h
+++ b/include/linux/dma_remapping.h
@@ -1,6 +1,8 @@
 #ifndef _DMA_REMAPPING_H
 #define _DMA_REMAPPING_H
 
+#define DEFAULT_DOMAIN_ADDRESS_WIDTH 48
+
 /*
  * VT-d hardware uses 4KiB page size regardless of host page size.
  */
diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
index 3d017cf..24a2945 100644
--- a/include/linux/intel-iommu.h
+++ b/include/linux/intel-iommu.h
@@ -299,6 +299,7 @@ struct intel_iommu {
 	struct dmar_domain **domains; /* ptr to domains */
 	spinlock_t	lock; /* protect context, domain ids */
 	struct root_entry *root_entry; /* virtual address */
+	int		agaw; /* agaw of this iommu */
 
 	unsigned int irq;
 	unsigned char name[7];    /* Device Name */
-- 
1.5.1

[-- Attachment #2: 0003-set-iommu-agaw.patch --]
[-- Type: application/octet-stream, Size: 2349 bytes --]

From 4ce44532dd932bfd830c23ac635293238aed3e3c Mon Sep 17 00:00:00 2001
From: Weidong Han <weidong.han@intel.com>
Date: Tue, 2 Dec 2008 14:07:20 +0800
Subject: [PATCH] set iommu agaw

iommu agaw may be different across iommus.

Signed-off-by: Weidong Han <weidong.han@intel.com>
---
 drivers/pci/dmar.c            |   14 ++++++++++++++
 include/linux/dma_remapping.h |    2 ++
 include/linux/intel-iommu.h   |    1 +
 3 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/drivers/pci/dmar.c b/drivers/pci/dmar.c
index 691b3ad..ebcc7c2 100644
--- a/drivers/pci/dmar.c
+++ b/drivers/pci/dmar.c
@@ -491,6 +491,8 @@ int alloc_iommu(struct dmar_drhd_unit *drhd)
 	int map_size;
 	u32 ver;
 	static int iommu_allocated = 0;
+	unsigned long sagaw;
+	int agaw;
 
 	iommu = kzalloc(sizeof(*iommu), GFP_KERNEL);
 	if (!iommu)
@@ -506,6 +508,18 @@ int alloc_iommu(struct dmar_drhd_unit *drhd)
 	iommu->cap = dmar_readq(iommu->reg + DMAR_CAP_REG);
 	iommu->ecap = dmar_readq(iommu->reg + DMAR_ECAP_REG);
 
+	/* set agaw, "SAGAW" may be different across iommus */
+	sagaw = cap_sagaw(iommu->cap);
+	for (agaw = width_to_agaw(DEFAULT_DOMAIN_ADDRESS_WIDTH);
+	     agaw >= 0; agaw--)
+		if (test_bit(agaw, &sagaw))
+			break;
+	if (agaw < 0) {
+		printk(KERN_ERR "IOMMU: unsupported sagaw %lx\n", sagaw);
+		goto error;
+	}
+	iommu->agaw = agaw;
+
 	/* the registers might be more than one page */
 	map_size = max_t(int, ecap_max_iotlb_offset(iommu->ecap),
 		cap_max_fault_reg_offset(iommu->cap));
diff --git a/include/linux/dma_remapping.h b/include/linux/dma_remapping.h
index eeb8243..c9d99c9 100644
--- a/include/linux/dma_remapping.h
+++ b/include/linux/dma_remapping.h
@@ -1,6 +1,8 @@
 #ifndef _DMA_REMAPPING_H
 #define _DMA_REMAPPING_H
 
+#define DEFAULT_DOMAIN_ADDRESS_WIDTH 48
+
 /*
  * VT-d hardware uses 4KiB page size regardless of host page size.
  */
diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
index 3d017cf..24a2945 100644
--- a/include/linux/intel-iommu.h
+++ b/include/linux/intel-iommu.h
@@ -299,6 +299,7 @@ struct intel_iommu {
 	struct dmar_domain **domains; /* ptr to domains */
 	spinlock_t	lock; /* protect context, domain ids */
 	struct root_entry *root_entry; /* virtual address */
+	int		agaw; /* agaw of this iommu */
 
 	unsigned int irq;
 	unsigned char name[7];    /* Device Name */
-- 
1.5.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-12-05  0:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-12-02 14:22 [PATCH 03/13] set iommu agaw Han, Weidong
2008-12-04 17:12 ` Mark McLoughlin
2008-12-05  0:56   ` Han, Weidong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox