[Patch Part1 V2 11/20] iommu/vt-d, trivial: simplify code with existing macros

2013-12-05 Thread Jiang Liu
Simplify vt-d related code with existing macros and introduce a new
macro for_each_active_drhd_unit() to enumerate all active DRHD unit.

Signed-off-by: Jiang Liu 
---
 drivers/iommu/dmar.c|7 ++---
 drivers/iommu/intel-iommu.c |   55 ---
 drivers/iommu/intel_irq_remapping.c |   31 +++-
 include/linux/dmar.h|4 +++
 4 files changed, 29 insertions(+), 68 deletions(-)

diff --git a/drivers/iommu/dmar.c b/drivers/iommu/dmar.c
index 4bbd972..99fb0c2 100644
--- a/drivers/iommu/dmar.c
+++ b/drivers/iommu/dmar.c
@@ -1313,15 +1313,14 @@ int dmar_set_interrupt(struct intel_iommu *iommu)
 int __init enable_drhd_fault_handling(void)
 {
struct dmar_drhd_unit *drhd;
+   struct intel_iommu *iommu;
 
/*
 * Enable fault control interrupt.
 */
-   for_each_drhd_unit(drhd) {
-   int ret;
-   struct intel_iommu *iommu = drhd->iommu;
+   for_each_iommu(iommu, drhd) {
u32 fault_status;
-   ret = dmar_set_interrupt(iommu);
+   int ret = dmar_set_interrupt(iommu);
 
if (ret) {
pr_err("DRHD %Lx: failed to enable fault, interrupt, 
ret %d\n",
diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index b5f13e4..0ec49da 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -628,9 +628,7 @@ static struct intel_iommu *device_to_iommu(int segment, u8 
bus, u8 devfn)
struct dmar_drhd_unit *drhd = NULL;
int i;
 
-   for_each_drhd_unit(drhd) {
-   if (drhd->ignored)
-   continue;
+   for_each_active_drhd_unit(drhd) {
if (segment != drhd->segment)
continue;
 
@@ -2467,11 +2465,7 @@ static int __init init_dmars(void)
goto error;
}
 
-   for_each_drhd_unit(drhd) {
-   if (drhd->ignored)
-   continue;
-
-   iommu = drhd->iommu;
+   for_each_active_iommu(iommu, drhd) {
g_iommus[iommu->seq_id] = iommu;
 
ret = iommu_init_domains(iommu);
@@ -2495,12 +2489,7 @@ static int __init init_dmars(void)
/*
 * Start from the sane iommu hardware state.
 */
-   for_each_drhd_unit(drhd) {
-   if (drhd->ignored)
-   continue;
-
-   iommu = drhd->iommu;
-
+   for_each_active_iommu(iommu, drhd) {
/*
 * If the queued invalidation is already initialized by us
 * (for example, while enabling interrupt-remapping) then
@@ -2520,12 +2509,7 @@ static int __init init_dmars(void)
dmar_disable_qi(iommu);
}
 
-   for_each_drhd_unit(drhd) {
-   if (drhd->ignored)
-   continue;
-
-   iommu = drhd->iommu;
-
+   for_each_active_iommu(iommu, drhd) {
if (dmar_enable_qi(iommu)) {
/*
 * Queued Invalidate not enabled, use Register Based
@@ -2608,17 +2592,16 @@ static int __init init_dmars(void)
 *   global invalidate iotlb
 *   enable translation
 */
-   for_each_drhd_unit(drhd) {
+   for_each_iommu(iommu, drhd) {
if (drhd->ignored) {
/*
 * we always have to disable PMRs or DMA may fail on
 * this device
 */
if (force_on)
-   iommu_disable_protect_mem_regions(drhd->iommu);
+   iommu_disable_protect_mem_regions(iommu);
continue;
}
-   iommu = drhd->iommu;
 
iommu_flush_write_buffer(iommu);
 
@@ -2640,12 +2623,8 @@ static int __init init_dmars(void)
 
return 0;
 error:
-   for_each_drhd_unit(drhd) {
-   if (drhd->ignored)
-   continue;
-   iommu = drhd->iommu;
+   for_each_active_iommu(iommu, drhd)
free_iommu(iommu);
-   }
kfree(g_iommus);
return ret;
 }
@@ -3293,9 +3272,9 @@ static void __init init_no_remapping_devices(void)
}
}
 
-   for_each_drhd_unit(drhd) {
+   for_each_active_drhd_unit(drhd) {
int i;
-   if (drhd->ignored || drhd->include_all)
+   if (drhd->include_all)
continue;
 
for (i = 0; i < drhd->devices_cnt; i++)
@@ -3644,6 +3623,7 @@ int __init intel_iommu_init(void)
 {
int ret = 0;
struct dmar_drhd_unit *drhd;
+   struct intel_iommu *iommu;
 
/* VT-d is required for a TXT/tboot launch, so enforce that */
force_on = tboot_force_iommu();
@@ -3657,16 +3637,9 @@ int __init intel_iommu_init(void)
/*
  

[Patch Part1 V2 11/20] iommu/vt-d, trivial: simplify code with existing macros

2013-12-05 Thread Jiang Liu
Simplify vt-d related code with existing macros and introduce a new
macro for_each_active_drhd_unit() to enumerate all active DRHD unit.

Signed-off-by: Jiang Liu jiang@linux.intel.com
---
 drivers/iommu/dmar.c|7 ++---
 drivers/iommu/intel-iommu.c |   55 ---
 drivers/iommu/intel_irq_remapping.c |   31 +++-
 include/linux/dmar.h|4 +++
 4 files changed, 29 insertions(+), 68 deletions(-)

diff --git a/drivers/iommu/dmar.c b/drivers/iommu/dmar.c
index 4bbd972..99fb0c2 100644
--- a/drivers/iommu/dmar.c
+++ b/drivers/iommu/dmar.c
@@ -1313,15 +1313,14 @@ int dmar_set_interrupt(struct intel_iommu *iommu)
 int __init enable_drhd_fault_handling(void)
 {
struct dmar_drhd_unit *drhd;
+   struct intel_iommu *iommu;
 
/*
 * Enable fault control interrupt.
 */
-   for_each_drhd_unit(drhd) {
-   int ret;
-   struct intel_iommu *iommu = drhd-iommu;
+   for_each_iommu(iommu, drhd) {
u32 fault_status;
-   ret = dmar_set_interrupt(iommu);
+   int ret = dmar_set_interrupt(iommu);
 
if (ret) {
pr_err(DRHD %Lx: failed to enable fault, interrupt, 
ret %d\n,
diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index b5f13e4..0ec49da 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -628,9 +628,7 @@ static struct intel_iommu *device_to_iommu(int segment, u8 
bus, u8 devfn)
struct dmar_drhd_unit *drhd = NULL;
int i;
 
-   for_each_drhd_unit(drhd) {
-   if (drhd-ignored)
-   continue;
+   for_each_active_drhd_unit(drhd) {
if (segment != drhd-segment)
continue;
 
@@ -2467,11 +2465,7 @@ static int __init init_dmars(void)
goto error;
}
 
-   for_each_drhd_unit(drhd) {
-   if (drhd-ignored)
-   continue;
-
-   iommu = drhd-iommu;
+   for_each_active_iommu(iommu, drhd) {
g_iommus[iommu-seq_id] = iommu;
 
ret = iommu_init_domains(iommu);
@@ -2495,12 +2489,7 @@ static int __init init_dmars(void)
/*
 * Start from the sane iommu hardware state.
 */
-   for_each_drhd_unit(drhd) {
-   if (drhd-ignored)
-   continue;
-
-   iommu = drhd-iommu;
-
+   for_each_active_iommu(iommu, drhd) {
/*
 * If the queued invalidation is already initialized by us
 * (for example, while enabling interrupt-remapping) then
@@ -2520,12 +2509,7 @@ static int __init init_dmars(void)
dmar_disable_qi(iommu);
}
 
-   for_each_drhd_unit(drhd) {
-   if (drhd-ignored)
-   continue;
-
-   iommu = drhd-iommu;
-
+   for_each_active_iommu(iommu, drhd) {
if (dmar_enable_qi(iommu)) {
/*
 * Queued Invalidate not enabled, use Register Based
@@ -2608,17 +2592,16 @@ static int __init init_dmars(void)
 *   global invalidate iotlb
 *   enable translation
 */
-   for_each_drhd_unit(drhd) {
+   for_each_iommu(iommu, drhd) {
if (drhd-ignored) {
/*
 * we always have to disable PMRs or DMA may fail on
 * this device
 */
if (force_on)
-   iommu_disable_protect_mem_regions(drhd-iommu);
+   iommu_disable_protect_mem_regions(iommu);
continue;
}
-   iommu = drhd-iommu;
 
iommu_flush_write_buffer(iommu);
 
@@ -2640,12 +2623,8 @@ static int __init init_dmars(void)
 
return 0;
 error:
-   for_each_drhd_unit(drhd) {
-   if (drhd-ignored)
-   continue;
-   iommu = drhd-iommu;
+   for_each_active_iommu(iommu, drhd)
free_iommu(iommu);
-   }
kfree(g_iommus);
return ret;
 }
@@ -3293,9 +3272,9 @@ static void __init init_no_remapping_devices(void)
}
}
 
-   for_each_drhd_unit(drhd) {
+   for_each_active_drhd_unit(drhd) {
int i;
-   if (drhd-ignored || drhd-include_all)
+   if (drhd-include_all)
continue;
 
for (i = 0; i  drhd-devices_cnt; i++)
@@ -3644,6 +3623,7 @@ int __init intel_iommu_init(void)
 {
int ret = 0;
struct dmar_drhd_unit *drhd;
+   struct intel_iommu *iommu;
 
/* VT-d is required for a TXT/tboot launch, so enforce that */
force_on = tboot_force_iommu();
@@ -3657,16 +3637,9 @@ int __init intel_iommu_init(void)