Skip to contentSkip to conversation

iommu/exynos: use convenient macro to handle gate clocks

PATCH NAK Cho KyongHo 3 participants 6 messages Mar 14, 2014 – Mar 18, 2014

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v11 15/27 iommu/exynos: use convenient macro to handle gate clocks

exynos-iommu driver must care about master H/W's gate clock as well as System MMU's gate clock. To enhance readability of the source code, macros to gate/ungate those clocks are defined.

---
 drivers/iommu/exynos-iommu.c |   34 ++++++++++++++++++++++------------
 1 file changed, 22 insertions(+), 12 deletions(-)
drivers/iommu/exynos-iommu.c +22 -12
index 71e77f1..cef62d0 100644
@@ -101,6 +101,16 @@
 #define REG_PB1_SADDR		0x054
 #define REG_PB1_EADDR		0x058
 
+#define __clk_gate_ctrl(data, clk, en)	do {		\
+		if (data->clk)				\
+			clk_##en##able(data->clk);	\
+	} while (0)
+
+#define __sysmmu_clk_enable(data)	__clk_gate_ctrl(data, clk, en)
+#define __sysmmu_clk_disable(data)	__clk_gate_ctrl(data, clk, dis)
+#define __master_clk_enable(data)	__clk_gate_ctrl(data, clk_master, en)
+#define __master_clk_disable(data)	__clk_gate_ctrl(data, clk_master, dis)
+
 static struct kmem_cache *lv2table_kmem_cache;
 
 static unsigned long *section_entry(unsigned long *pgtable, unsigned long iova)
@@ -302,7 +312,7 @@ static irqreturn_t exynos_sysmmu_irq(int irq, void *dev_id)
 
 	WARN_ON(!is_sysmmu_active(data));
 
-	clk_enable(data->clk_master);
+	__master_clk_enable(data);
 	itype = (enum exynos_sysmmu_inttype)
 		__ffs(__raw_readl(data->sfrbase + REG_INT_STATUS));
 	if (WARN_ON(!((itype >= 0) && (itype < SYSMMU_FAULT_UNKNOWN))))
@@ -329,7 +339,7 @@ static irqreturn_t exynos_sysmmu_irq(int irq, void *dev_id)
 	if (itype != SYSMMU_FAULT_UNKNOWN)
 		sysmmu_unblock(data->sfrbase);
 
-	clk_disable(data->clk_master);
+	__master_clk_disable(data);
 
 	read_unlock(&data->lock);
 
@@ -346,12 +356,12 @@ static bool __exynos_sysmmu_disable(struct sysmmu_drvdata *data)
 	if (!set_sysmmu_inactive(data))
 		goto finish;
 
-	clk_enable(data->clk_master);
+	__master_clk_enable(data);
 
 	__raw_writel(CTRL_DISABLE, data->sfrbase + REG_MMU_CTRL);
 
-	clk_disable(data->clk);
-	clk_disable(data->clk_master);
+	__sysmmu_clk_disable(data);
+	__master_clk_disable(data);
 
 	disabled = true;
 	data->pgtable = 0;
@@ -396,14 +406,14 @@ static int __exynos_sysmmu_enable(struct sysmmu_drvdata *data,
 
 	data->pgtable = pgtable;
 
-	clk_enable(data->clk_master);
-	clk_enable(data->clk);
+	__master_clk_enable(data);
+	__sysmmu_clk_enable(data);
 
 	__sysmmu_set_ptbase(data->sfrbase, pgtable);
 
 	__raw_writel(CTRL_ENABLE, data->sfrbase + REG_MMU_CTRL);
 
-	clk_disable(data->clk_master);
+	__master_clk_disable(data);
 
 	data->domain = domain;
 
@@ -462,7 +472,7 @@ static void sysmmu_tlb_invalidate_entry(struct device *dev, unsigned long iova,
 		unsigned int maj;
 		unsigned int num_inv = 1;
 
-		clk_enable(data->clk_master);
+		__master_clk_enable(data);
 
 		maj = __raw_readl(data->sfrbase + REG_MMU_VERSION);
 		/*
@@ -483,7 +493,7 @@ static void sysmmu_tlb_invalidate_entry(struct device *dev, unsigned long iova,
 							num_inv);
 			sysmmu_unblock(data->sfrbase);
 		}
-		clk_disable(data->clk_master);
+		__master_clk_disable(data);
 	} else {
 		dev_dbg(data->sysmmu, "Disabled. Skipping invalidating TLB.\n");
 	}
@@ -499,12 +509,12 @@ void exynos_sysmmu_tlb_invalidate(struct device *dev)
 	read_lock_irqsave(&data->lock, flags);
 
 	if (is_sysmmu_active(data)) {
-		clk_enable(data->clk_master);
+		__master_clk_enable(data);
 		if (sysmmu_block(data->sfrbase)) {
 			__sysmmu_tlb_invalidate(data->sfrbase);
 			sysmmu_unblock(data->sfrbase);
 		}
-		clk_disable(data->clk_master);
+		__master_clk_disable(data);
 	} else {
 		dev_dbg(data->sysmmu, "Disabled. Skipping invalidating TLB.\n");
 	}
Signature · 1 line
1.7.9.5
#1 lore raw

Hi KyongHo,

Quoted 17 lines · Cho KyongHo

exynos-iommu driver must care about master H/W's gate clock as well as System MMU's gate clock. To enhance readability of the source code, macros to gate/ungate those clocks are defined.

---
  drivers/iommu/exynos-iommu.c |   34 ++++++++++++++++++++++------------
  1 file changed, 22 insertions(+), 12 deletions(-)
drivers/iommu/exynos-iommu.c +0 -0
index 71e77f1..cef62d0 100644
@@ -101,6 +101,16 @@
  #define REG_PB1_SADDR		0x054
  #define REG_PB1_EADDR		0x058
 

drivers/iommu/exynos-iommu.c line 113

Quoted 10 lines
drivers/iommu/exynos-iommu.c +10 -0
+#define __clk_gate_ctrl(data, clk, en)	do {		\
+		if (data->clk)				\
+			clk_##en##able(data->clk);	\
+	} while (0)
+
+#define __sysmmu_clk_enable(data)	__clk_gate_ctrl(data, clk, en)
+#define __sysmmu_clk_disable(data)	__clk_gate_ctrl(data, clk, dis)
+#define __master_clk_enable(data)	__clk_gate_ctrl(data, clk_master, en)
+#define __master_clk_disable(data)	__clk_gate_ctrl(data, clk_master, dis)
+

I'd say that such macros only obfuscate code, without any gains, as you can see in diffstat - this patch adds more lines than it removes.

Please drop this change.

Best regards,
Tomasz

#2 lore raw

Hi KyongHo,

Quoted 39 lines · Tomasz Figa

Hi KyongHo,

Quoted 20 lines · Cho KyongHo

exynos-iommu driver must care about master H/W's gate clock as well as System MMU's gate clock. To enhance readability of the source code, macros to gate/ungate those clocks are defined.

---
  drivers/iommu/exynos-iommu.c |   34 ++++++++++++++++++++++------------
  1 file changed, 22 insertions(+), 12 deletions(-)
drivers/iommu/exynos-iommu.c +2 -0
index 71e77f1..cef62d0 100644
@@ -101,6 +101,16 @@
  #define REG_PB1_SADDR         0x054
  #define REG_PB1_EADDR         0x058
 
+#define __clk_gate_ctrl(data, clk, en) do {            \
+               if (data->clk)                          \

drivers/iommu/exynos-iommu.c line 115

Quoted 10 lines
drivers/iommu/exynos-iommu.c +8 -0
+                       clk_##en##able(data->clk);      \
+       } while (0)
+
+#define __sysmmu_clk_enable(data)      __clk_gate_ctrl(data, clk, en)
+#define __sysmmu_clk_disable(data)     __clk_gate_ctrl(data, clk, dis)
+#define __master_clk_enable(data)      __clk_gate_ctrl(data, clk_master,
 en)
+#define __master_clk_disable(data)     __clk_gate_ctrl(data, clk_master,
 dis)
+

I'd say that such macros only obfuscate code, without any gains, as you can see in diffstat - this patch adds more lines than it removes.

Quoted 1 line

Please drop this change.

I agree with Tomasz here.

Signature · 2 lines
With warm regards,
Sachin
#3 lore raw
Quoted 42 lines · Sachin Kamat

Hi KyongHo,

Quoted 39 lines · Tomasz Figa

Hi KyongHo,

Quoted 20 lines · Cho KyongHo

exynos-iommu driver must care about master H/W's gate clock as well as System MMU's gate clock. To enhance readability of the source code, macros to gate/ungate those clocks are defined.

---
  drivers/iommu/exynos-iommu.c |   34 ++++++++++++++++++++++------------
  1 file changed, 22 insertions(+), 12 deletions(-)
drivers/iommu/exynos-iommu.c +2 -0
index 71e77f1..cef62d0 100644
@@ -101,6 +101,16 @@
  #define REG_PB1_SADDR         0x054
  #define REG_PB1_EADDR         0x058
 
+#define __clk_gate_ctrl(data, clk, en) do {            \
+               if (data->clk)                          \

drivers/iommu/exynos-iommu.c line 115

Quoted 10 lines
drivers/iommu/exynos-iommu.c +8 -0
+                       clk_##en##able(data->clk);      \
+       } while (0)
+
+#define __sysmmu_clk_enable(data)      __clk_gate_ctrl(data, clk, en)
+#define __sysmmu_clk_disable(data)     __clk_gate_ctrl(data, clk, dis)
+#define __master_clk_enable(data)      __clk_gate_ctrl(data, clk_master,
 en)
+#define __master_clk_disable(data)     __clk_gate_ctrl(data, clk_master,
 dis)
+

I'd say that such macros only obfuscate code, without any gains, as you can see in diffstat - this patch adds more lines than it removes.

Quoted 4 lines
Quoted 1 line

Please drop this change.

I agree with Tomasz here.

Are you concerning about using macros or more insertions than deletions?

The deletions in this patch are only clk_enable() and clk_disable() but they must be
"if (!IS_ERR(clk)) clk_enable(clk)" and "if (!IS_ERR(clk)) clk_disable(clk)".

I think use of macro is fancier in that case.

Thank you.

KyongHo.

#4 lore raw
Quoted 43 lines · Cho KyongHo
Quoted 42 lines · Sachin Kamat

Hi KyongHo,

Quoted 39 lines · Tomasz Figa

Hi KyongHo,

Quoted 20 lines · Cho KyongHo

exynos-iommu driver must care about master H/W's gate clock as well as System MMU's gate clock. To enhance readability of the source code, macros to gate/ungate those clocks are defined.

---
  drivers/iommu/exynos-iommu.c |   34 ++++++++++++++++++++++------------
  1 file changed, 22 insertions(+), 12 deletions(-)
drivers/iommu/exynos-iommu.c +2 -0
index 71e77f1..cef62d0 100644
@@ -101,6 +101,16 @@
  #define REG_PB1_SADDR         0x054
  #define REG_PB1_EADDR         0x058
 
+#define __clk_gate_ctrl(data, clk, en) do {            \
+               if (data->clk)                          \

drivers/iommu/exynos-iommu.c line 115

Quoted 10 lines
drivers/iommu/exynos-iommu.c +8 -0
+                       clk_##en##able(data->clk);      \
+       } while (0)
+
+#define __sysmmu_clk_enable(data)      __clk_gate_ctrl(data, clk, en)
+#define __sysmmu_clk_disable(data)     __clk_gate_ctrl(data, clk, dis)
+#define __master_clk_enable(data)      __clk_gate_ctrl(data, clk_master,
 en)
+#define __master_clk_disable(data)     __clk_gate_ctrl(data, clk_master,
 dis)
+

I'd say that such macros only obfuscate code, without any gains, as you can see in diffstat - this patch adds more lines than it removes.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Please drop this change.

I agree with Tomasz here.

Are you concerning about using macros or more insertions than deletions?

It is just making the code more difficult to read and understand.

Signature · 2 lines
With warm regards,
Sachin
#5 lore raw
Quoted 44 lines · Sachin Kamat
Quoted 43 lines · Cho KyongHo
Quoted 42 lines · Sachin Kamat

Hi KyongHo,

Quoted 39 lines · Tomasz Figa

Hi KyongHo,

Quoted 20 lines · Cho KyongHo

exynos-iommu driver must care about master H/W's gate clock as well as System MMU's gate clock. To enhance readability of the source code, macros to gate/ungate those clocks are defined.

---
   drivers/iommu/exynos-iommu.c |   34 ++++++++++++++++++++++------------
   1 file changed, 22 insertions(+), 12 deletions(-)
drivers/iommu/exynos-iommu.c +2 -0
index 71e77f1..cef62d0 100644
@@ -101,6 +101,16 @@
   #define REG_PB1_SADDR         0x054
   #define REG_PB1_EADDR         0x058
 
+#define __clk_gate_ctrl(data, clk, en) do {            \
+               if (data->clk)                          \

drivers/iommu/exynos-iommu.c line 115

Quoted 10 lines
drivers/iommu/exynos-iommu.c +8 -0
+                       clk_##en##able(data->clk);      \
+       } while (0)
+
+#define __sysmmu_clk_enable(data)      __clk_gate_ctrl(data, clk, en)
+#define __sysmmu_clk_disable(data)     __clk_gate_ctrl(data, clk, dis)
+#define __master_clk_enable(data)      __clk_gate_ctrl(data, clk_master,
 en)
+#define __master_clk_disable(data)     __clk_gate_ctrl(data, clk_master,
 dis)
+

I'd say that such macros only obfuscate code, without any gains, as you can see in diffstat - this patch adds more lines than it removes.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Please drop this change.

I agree with Tomasz here.

Are you concerning about using macros or more insertions than deletions?

It is just making the code more difficult to read and understand.

Especially when hiding accesses to struct fields inside and doing fancy stuff like concatenations.

Best regards,
Tomasz