public inbox for linux-omap@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] IRQ: simplify OMAP2 mask_irq/unmask_irq code
@ 2008-05-20 18:21 Paul Walmsley
  2008-05-20 23:18 ` Kyungmin Park
  0 siblings, 1 reply; 11+ messages in thread
From: Paul Walmsley @ 2008-05-20 18:21 UTC (permalink / raw)
  To: linux-omap; +Cc: lethal


Simplify the IRQ register/IRQ register bit calculations in
mach-omap2/irq.c.  

Test-booted on 3430SDP.

Signed-off-by: Paul Walmsley <paul@pwsan.com>

---

size:
   text    data     bss     dec     hex filename
3341347  170992  109008 3621347  3741e3 vmlinux.3430sdp
3341315  170992  109008 3621315  3741c3 vmlinux.3430sdp.patched

---

 arch/arm/mach-omap2/irq.c |   17 +++++++----------
 1 files changed, 7 insertions(+), 10 deletions(-)


diff --git a/arch/arm/mach-omap2/irq.c b/arch/arm/mach-omap2/irq.c
index ac062ee..f610825 100644
--- a/arch/arm/mach-omap2/irq.c
+++ b/arch/arm/mach-omap2/irq.c
@@ -27,6 +27,9 @@
 #define INTC_MIR_CLEAR0	0x0088
 #define INTC_MIR_SET0	0x008c
 
+/* Number of IRQ state bits in each MIR register */
+#define IRQ_BITS_PER_REG	32
+
 /*
  * OMAP2 has a number of different interrupt controllers, each interrupt
  * controller is identified as its own "bank". Register definitions are
@@ -67,24 +70,18 @@ static void omap_ack_irq(unsigned int irq)
 
 static void omap_mask_irq(unsigned int irq)
 {
-	int offset = (irq >> 5) << 5;
+	int offset = irq & (~(IRQ_BITS_PER_REG - 1));
 
-	if (irq >= 64)
-		irq %= 64;
-	else if (irq >= 32)
-		irq %= 32;
+	irq %= IRQ_BITS_PER_REG;
 
 	intc_bank_write_reg(1 << irq, &irq_banks[0], INTC_MIR_SET0 + offset);
 }
 
 static void omap_unmask_irq(unsigned int irq)
 {
-	int offset = (irq >> 5) << 5;
+	int offset = irq & (~(IRQ_BITS_PER_REG - 1));
 
-	if (irq >= 64)
-		irq %= 64;
-	else if (irq >= 32)
-		irq %= 32;
+	irq %= IRQ_BITS_PER_REG;
 
 	intc_bank_write_reg(1 << irq, &irq_banks[0], INTC_MIR_CLEAR0 + offset);
 }

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

* Re: [PATCH] IRQ: simplify OMAP2 mask_irq/unmask_irq code
  2008-05-20 18:21 [PATCH] IRQ: simplify OMAP2 mask_irq/unmask_irq code Paul Walmsley
@ 2008-05-20 23:18 ` Kyungmin Park
  2008-05-21  0:12   ` Paul Walmsley
  0 siblings, 1 reply; 11+ messages in thread
From: Kyungmin Park @ 2008-05-20 23:18 UTC (permalink / raw)
  To: Paul Walmsley; +Cc: linux-omap, lethal

On Wed, May 21, 2008 at 3:21 AM, Paul Walmsley <paul@pwsan.com> wrote:
>
> Simplify the IRQ register/IRQ register bit calculations in
> mach-omap2/irq.c.
>
> Test-booted on 3430SDP.
>
> Signed-off-by: Paul Walmsley <paul@pwsan.com>
>
> ---
>
> size:
>   text    data     bss     dec     hex filename
> 3341347  170992  109008 3621347  3741e3 vmlinux.3430sdp
> 3341315  170992  109008 3621315  3741c3 vmlinux.3430sdp.patched
>
> ---
>
>  arch/arm/mach-omap2/irq.c |   17 +++++++----------
>  1 files changed, 7 insertions(+), 10 deletions(-)
>
>
> diff --git a/arch/arm/mach-omap2/irq.c b/arch/arm/mach-omap2/irq.c
> index ac062ee..f610825 100644
> --- a/arch/arm/mach-omap2/irq.c
> +++ b/arch/arm/mach-omap2/irq.c
> @@ -27,6 +27,9 @@
>  #define INTC_MIR_CLEAR0        0x0088
>  #define INTC_MIR_SET0  0x008c
>
> +/* Number of IRQ state bits in each MIR register */
> +#define IRQ_BITS_PER_REG       32
> +
>  /*
>  * OMAP2 has a number of different interrupt controllers, each interrupt
>  * controller is identified as its own "bank". Register definitions are
> @@ -67,24 +70,18 @@ static void omap_ack_irq(unsigned int irq)
>
>  static void omap_mask_irq(unsigned int irq)
>  {
> -       int offset = (irq >> 5) << 5;
> +       int offset = irq & (~(IRQ_BITS_PER_REG - 1));
>
> -       if (irq >= 64)
> -               irq %= 64;
> -       else if (irq >= 32)
> -               irq %= 32;
> +       irq %= IRQ_BITS_PER_REG;

Is it the right conversion?
If the irq is greater then 32 and less then or equal to  64 it's
result is different.
E.g, If irq is 63 then original irq is 63, but new code is 31

And if this code is right, how about to use mask instead of modulo op?
irq &= (IRQ_BITS_PER_REG - 1);

Thank you,
Kyungmin Park

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

* Re: [PATCH] IRQ: simplify OMAP2 mask_irq/unmask_irq code
  2008-05-20 23:18 ` Kyungmin Park
@ 2008-05-21  0:12   ` Paul Walmsley
  2008-05-21  0:39     ` Philip Balister
  2008-05-21  0:55     ` Paul Mundt
  0 siblings, 2 replies; 11+ messages in thread
From: Paul Walmsley @ 2008-05-21  0:12 UTC (permalink / raw)
  To: Kyungmin Park; +Cc: linux-omap, lethal

Hello Kyungmin,

On Wed, 21 May 2008, Kyungmin Park wrote:

> On Wed, May 21, 2008 at 3:21 AM, Paul Walmsley <paul@pwsan.com> wrote:
> >
> >  static void omap_mask_irq(unsigned int irq)
> >  {
> > -       int offset = (irq >> 5) << 5;
> > +       int offset = irq & (~(IRQ_BITS_PER_REG - 1));
> >
> > -       if (irq >= 64)
> > -               irq %= 64;
> > -       else if (irq >= 32)
> > -               irq %= 32;
> > +       irq %= IRQ_BITS_PER_REG;
> 
> Is it the right conversion?
> If the irq is greater then 32 and less then or equal to  64 it's
> result is different.
> E.g, If irq is 63 then original irq is 63, but new code is 31

Hmm, in that condition, the result looks the same to me: irq % 32, either 
way?

More practically, if you look at what it does with that irq variable 
afterwards, it seems to be a bug if irq is ever greater than 31:

        intc_bank_write_reg(1 << irq, &irq_banks[0], INTC_MIR_CLEAR0 + 
                            offset);

I think the only case where the new code would work differently than the 
previous code is if irq > 95.  But that would be a bug, since the shift 
value would then be > 32, for a 32-bit register.

> And if this code is right, how about to use mask instead of modulo op?
> irq &= (IRQ_BITS_PER_REG - 1);

Hehe, very good point, that would probably save even more cycles!  If you 
agree with the above, perhaps I can convert the code to use that also, 
and add your Signed-off-by also?


- Paul

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

* Re: [PATCH] IRQ: simplify OMAP2 mask_irq/unmask_irq code
  2008-05-21  0:12   ` Paul Walmsley
@ 2008-05-21  0:39     ` Philip Balister
  2008-05-21  0:52       ` Kyungmin Park
  2008-05-21  0:55     ` Paul Mundt
  1 sibling, 1 reply; 11+ messages in thread
From: Philip Balister @ 2008-05-21  0:39 UTC (permalink / raw)
  To: Paul Walmsley; +Cc: Kyungmin Park, linux-omap, lethal

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

Paul Walmsley wrote:
> Hello Kyungmin,
> 
> On Wed, 21 May 2008, Kyungmin Park wrote:
> 
>> On Wed, May 21, 2008 at 3:21 AM, Paul Walmsley <paul@pwsan.com> wrote:
>>>  static void omap_mask_irq(unsigned int irq)
>>>  {
>>> -       int offset = (irq >> 5) << 5;
>>> +       int offset = irq & (~(IRQ_BITS_PER_REG - 1));
>>>
>>> -       if (irq >= 64)
>>> -               irq %= 64;
>>> -       else if (irq >= 32)
>>> -               irq %= 32;
>>> +       irq %= IRQ_BITS_PER_REG;
>> Is it the right conversion?
>> If the irq is greater then 32 and less then or equal to  64 it's
>> result is different.
>> E.g, If irq is 63 then original irq is 63, but new code is 31
> 
> Hmm, in that condition, the result looks the same to me: irq % 32, either 
> way?
> 
> More practically, if you look at what it does with that irq variable 
> afterwards, it seems to be a bug if irq is ever greater than 31:
> 
>         intc_bank_write_reg(1 << irq, &irq_banks[0], INTC_MIR_CLEAR0 + 
>                             offset);
> 
> I think the only case where the new code would work differently than the 
> previous code is if irq > 95.  But that would be a bug, since the shift 
> value would then be > 32, for a 32-bit register.
> 
>> And if this code is right, how about to use mask instead of modulo op?
>> irq &= (IRQ_BITS_PER_REG - 1);
> 
> Hehe, very good point, that would probably save even more cycles!  If you 
> agree with the above, perhaps I can convert the code to use that also, 
> and add your Signed-off-by also?

On some code where I used % to detect a counter passing multiples of a 
certain number, oprofile revealed that the % operator burned a lot of 
CPU cycles. I suspect this had to do with the counter increasing to very 
large numbers, but ever since, I've tried to avoid the % operator in 
critical paths.

Philip

[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/x-pkcs7-signature, Size: 3303 bytes --]

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

* Re: [PATCH] IRQ: simplify OMAP2 mask_irq/unmask_irq code
  2008-05-21  0:39     ` Philip Balister
@ 2008-05-21  0:52       ` Kyungmin Park
  0 siblings, 0 replies; 11+ messages in thread
From: Kyungmin Park @ 2008-05-21  0:52 UTC (permalink / raw)
  To: Philip Balister; +Cc: Paul Walmsley, linux-omap, lethal

On Wed, May 21, 2008 at 9:39 AM, Philip Balister <philip@balister.org> wrote:
> Paul Walmsley wrote:
>>
>> Hello Kyungmin,
>>
>> On Wed, 21 May 2008, Kyungmin Park wrote:
>>
>>> On Wed, May 21, 2008 at 3:21 AM, Paul Walmsley <paul@pwsan.com> wrote:
>>>>
>>>>  static void omap_mask_irq(unsigned int irq)
>>>>  {
>>>> -       int offset = (irq >> 5) << 5;
>>>> +       int offset = irq & (~(IRQ_BITS_PER_REG - 1));
>>>>
>>>> -       if (irq >= 64)
>>>> -               irq %= 64;
>>>> -       else if (irq >= 32)
>>>> -               irq %= 32;
>>>> +       irq %= IRQ_BITS_PER_REG;
>>>
>>> Is it the right conversion?
>>> If the irq is greater then 32 and less then or equal to  64 it's
>>> result is different.
>>> E.g, If irq is 63 then original irq is 63, but new code is 31
>>
>> Hmm, in that condition, the result looks the same to me: irq % 32, either
>> way?
>>
>> More practically, if you look at what it does with that irq variable
>> afterwards, it seems to be a bug if irq is ever greater than 31:
>>
>>        intc_bank_write_reg(1 << irq, &irq_banks[0], INTC_MIR_CLEAR0 +
>>                        offset);
>>
>> I think the only case where the new code would work differently than the
>> previous code is if irq > 95.  But that would be a bug, since the shift
>> value would then be > 32, for a 32-bit register.
>>
>>> And if this code is right, how about to use mask instead of modulo op?
>>> irq &= (IRQ_BITS_PER_REG - 1);
>>
>> Hehe, very good point, that would probably save even more cycles!  If you
>> agree with the above, perhaps I can convert the code to use that also, and
>> add your Signed-off-by also?
>
> On some code where I used % to detect a counter passing multiples of a
> certain number, oprofile revealed that the % operator burned a lot of CPU
> cycles. I suspect this had to do with the counter increasing to very large
> numbers, but ever since, I've tried to avoid the % operator in critical
> paths.
>
Yes, In embedded environment, we should avoid the multiple, divide,
and modulo op as much as possible.
It's best to use the bit operations.

Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>

BR,
Kyungmin Park

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

* Re: [PATCH] IRQ: simplify OMAP2 mask_irq/unmask_irq code
  2008-05-21  0:12   ` Paul Walmsley
  2008-05-21  0:39     ` Philip Balister
@ 2008-05-21  0:55     ` Paul Mundt
  2008-05-21  1:19       ` Paul Walmsley
  1 sibling, 1 reply; 11+ messages in thread
From: Paul Mundt @ 2008-05-21  0:55 UTC (permalink / raw)
  To: Paul Walmsley; +Cc: Kyungmin Park, linux-omap

On Tue, May 20, 2008 at 06:12:04PM -0600, Paul Walmsley wrote:
> On Wed, 21 May 2008, Kyungmin Park wrote:
> > On Wed, May 21, 2008 at 3:21 AM, Paul Walmsley <paul@pwsan.com> wrote:
> > >
> > >  static void omap_mask_irq(unsigned int irq)
> > >  {
> > > -       int offset = (irq >> 5) << 5;
> > > +       int offset = irq & (~(IRQ_BITS_PER_REG - 1));
> > >
> > > -       if (irq >= 64)
> > > -               irq %= 64;
> > > -       else if (irq >= 32)
> > > -               irq %= 32;
> > > +       irq %= IRQ_BITS_PER_REG;
> > 
> > Is it the right conversion?
> > If the irq is greater then 32 and less then or equal to  64 it's
> > result is different.
> > E.g, If irq is 63 then original irq is 63, but new code is 31
> 
> Hmm, in that condition, the result looks the same to me: irq % 32, either 
> way?
> 
> More practically, if you look at what it does with that irq variable 
> afterwards, it seems to be a bug if irq is ever greater than 31:
> 
>         intc_bank_write_reg(1 << irq, &irq_banks[0], INTC_MIR_CLEAR0 + 
>                             offset);
> 
> I think the only case where the new code would work differently than the 
> previous code is if irq > 95.  But that would be a bug, since the shift 
> value would then be > 32, for a 32-bit register.
> 
> > And if this code is right, how about to use mask instead of modulo op?
> > irq &= (IRQ_BITS_PER_REG - 1);
> 
> Hehe, very good point, that would probably save even more cycles!  If you 
> agree with the above, perhaps I can convert the code to use that also, 
> and add your Signed-off-by also?
> 
Kyungmin's idea looks good to me. If you roll the two together, feel free
to add my Acked-by also.

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

* Re: [PATCH] IRQ: simplify OMAP2 mask_irq/unmask_irq code
  2008-05-21  0:55     ` Paul Mundt
@ 2008-05-21  1:19       ` Paul Walmsley
  0 siblings, 0 replies; 11+ messages in thread
From: Paul Walmsley @ 2008-05-21  1:19 UTC (permalink / raw)
  To: Paul Mundt; +Cc: Kyungmin Park, linux-omap


Great - thanks everyone for the review,


- Paul

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

* [PATCH] IRQ: simplify OMAP2 mask_irq/unmask_irq code
@ 2008-05-21  1:19 Paul Walmsley
  2008-05-21 15:05 ` Tony Lindgren
  0 siblings, 1 reply; 11+ messages in thread
From: Paul Walmsley @ 2008-05-21  1:19 UTC (permalink / raw)
  To: linux-omap; +Cc: Paul Mundt, Kyungmin Park


Modify mach-omap2/irq.c to simplify the IRQ number-to-IRQ register and IRQ 
number-to-register bit calculations.

Signed-off-by: Kyungmin Park <kmpark@infradead.org>
Signed-off-by: Paul Walmsley <paul@pwsan.com>
Acked-by: Paul Mundt <lethal@linux-sh.org>

size:
   text    data     bss     dec     hex filename
3341347  170992  109008 3621347  3741e3 vmlinux.3430sdp
3341315  170992  109008 3621315  3741c3 vmlinux.3430sdp.patched
---

 arch/arm/mach-omap2/irq.c |   17 +++++++----------
 1 files changed, 7 insertions(+), 10 deletions(-)


diff --git a/arch/arm/mach-omap2/irq.c b/arch/arm/mach-omap2/irq.c
index ac062ee..9300712 100644
--- a/arch/arm/mach-omap2/irq.c
+++ b/arch/arm/mach-omap2/irq.c
@@ -27,6 +27,9 @@
 #define INTC_MIR_CLEAR0	0x0088
 #define INTC_MIR_SET0	0x008c
 
+/* Number of IRQ state bits in each MIR register */
+#define IRQ_BITS_PER_REG	32
+
 /*
  * OMAP2 has a number of different interrupt controllers, each interrupt
  * controller is identified as its own "bank". Register definitions are
@@ -67,24 +70,18 @@ static void omap_ack_irq(unsigned int irq)
 
 static void omap_mask_irq(unsigned int irq)
 {
-	int offset = (irq >> 5) << 5;
+	int offset = irq & (~(IRQ_BITS_PER_REG - 1));
 
-	if (irq >= 64)
-		irq %= 64;
-	else if (irq >= 32)
-		irq %= 32;
+	irq &= (IRQ_BITS_PER_REG - 1);
 
 	intc_bank_write_reg(1 << irq, &irq_banks[0], INTC_MIR_SET0 + offset);
 }
 
 static void omap_unmask_irq(unsigned int irq)
 {
-	int offset = (irq >> 5) << 5;
+	int offset = irq & (~(IRQ_BITS_PER_REG - 1));
 
-	if (irq >= 64)
-		irq %= 64;
-	else if (irq >= 32)
-		irq %= 32;
+	irq &= (IRQ_BITS_PER_REG - 1);
 
 	intc_bank_write_reg(1 << irq, &irq_banks[0], INTC_MIR_CLEAR0 + offset);
 }

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

* Re: [PATCH] IRQ: simplify OMAP2 mask_irq/unmask_irq code
  2008-05-21  1:19 Paul Walmsley
@ 2008-05-21 15:05 ` Tony Lindgren
  2008-05-21 19:15   ` Paul Walmsley
  0 siblings, 1 reply; 11+ messages in thread
From: Tony Lindgren @ 2008-05-21 15:05 UTC (permalink / raw)
  To: Paul Walmsley; +Cc: linux-omap, Paul Mundt, Kyungmin Park

Hi,

* Paul Walmsley <paul@pwsan.com> [080520 18:20]:
> 
> Modify mach-omap2/irq.c to simplify the IRQ number-to-IRQ register and IRQ 
> number-to-register bit calculations.

How about patching Jouni's new omap_irq_pending() for this too?

Tony

> Signed-off-by: Kyungmin Park <kmpark@infradead.org>
> Signed-off-by: Paul Walmsley <paul@pwsan.com>
> Acked-by: Paul Mundt <lethal@linux-sh.org>
> 
> size:
>    text    data     bss     dec     hex filename
> 3341347  170992  109008 3621347  3741e3 vmlinux.3430sdp
> 3341315  170992  109008 3621315  3741c3 vmlinux.3430sdp.patched
> ---
> 
>  arch/arm/mach-omap2/irq.c |   17 +++++++----------
>  1 files changed, 7 insertions(+), 10 deletions(-)
> 
> 
> diff --git a/arch/arm/mach-omap2/irq.c b/arch/arm/mach-omap2/irq.c
> index ac062ee..9300712 100644
> --- a/arch/arm/mach-omap2/irq.c
> +++ b/arch/arm/mach-omap2/irq.c
> @@ -27,6 +27,9 @@
>  #define INTC_MIR_CLEAR0	0x0088
>  #define INTC_MIR_SET0	0x008c
>  
> +/* Number of IRQ state bits in each MIR register */
> +#define IRQ_BITS_PER_REG	32
> +
>  /*
>   * OMAP2 has a number of different interrupt controllers, each interrupt
>   * controller is identified as its own "bank". Register definitions are
> @@ -67,24 +70,18 @@ static void omap_ack_irq(unsigned int irq)
>  
>  static void omap_mask_irq(unsigned int irq)
>  {
> -	int offset = (irq >> 5) << 5;
> +	int offset = irq & (~(IRQ_BITS_PER_REG - 1));
>  
> -	if (irq >= 64)
> -		irq %= 64;
> -	else if (irq >= 32)
> -		irq %= 32;
> +	irq &= (IRQ_BITS_PER_REG - 1);
>  
>  	intc_bank_write_reg(1 << irq, &irq_banks[0], INTC_MIR_SET0 + offset);
>  }
>  
>  static void omap_unmask_irq(unsigned int irq)
>  {
> -	int offset = (irq >> 5) << 5;
> +	int offset = irq & (~(IRQ_BITS_PER_REG - 1));
>  
> -	if (irq >= 64)
> -		irq %= 64;
> -	else if (irq >= 32)
> -		irq %= 32;
> +	irq &= (IRQ_BITS_PER_REG - 1);
>  
>  	intc_bank_write_reg(1 << irq, &irq_banks[0], INTC_MIR_CLEAR0 + offset);
>  }
> --
> To unsubscribe from this list: send the line "unsubscribe linux-omap" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH] IRQ: simplify OMAP2 mask_irq/unmask_irq code
  2008-05-21 15:05 ` Tony Lindgren
@ 2008-05-21 19:15   ` Paul Walmsley
  2008-05-22 19:50     ` Tony Lindgren
  0 siblings, 1 reply; 11+ messages in thread
From: Paul Walmsley @ 2008-05-21 19:15 UTC (permalink / raw)
  To: Tony Lindgren; +Cc: linux-omap, Paul Mundt, Kyungmin Park

Hi Tony,

On Wed, 21 May 2008, Tony Lindgren wrote:

> * Paul Walmsley <paul@pwsan.com> [080520 18:20]:
> > 
> > Modify mach-omap2/irq.c to simplify the IRQ number-to-IRQ register and IRQ 
> > number-to-register bit calculations.
> 
> How about patching Jouni's new omap_irq_pending() for this too?

done - updated patch below.

- Paul


[PATCH] IRQ: simplify OMAP2 mask_irq/unmask_irq code

Modify mach-omap2/irq.c to simplify the IRQ number-to-IRQ register and
IRQ number-to-register bit calculations.

Signed-off-by: Paul Walmsley <paul@pwsan.com>
Signed-off-by: Kyungmin Park <kmpark@infradead.org>
Acked-by: Paul Mundt <lethal@linux-sh.org>

size:
   text    data     bss     dec     hex filename
3272871  155128   98792 3526791  35d087 vmlinux.3430sdp
3272839  155128   98792 3526759  35d067 vmlinux.3430sdp.patched
---

 arch/arm/mach-omap2/irq.c |   27 ++++++++++++++-------------
 1 files changed, 14 insertions(+), 13 deletions(-)


diff --git a/arch/arm/mach-omap2/irq.c b/arch/arm/mach-omap2/irq.c
index f1e1e2e..94d2f93 100644
--- a/arch/arm/mach-omap2/irq.c
+++ b/arch/arm/mach-omap2/irq.c
@@ -28,6 +28,9 @@
 #define INTC_MIR_SET0		0x008c
 #define INTC_PENDING_IRQ0	0x0098
 
+/* Number of IRQ state bits in each MIR register */
+#define IRQ_BITS_PER_REG	32
+
 /*
  * OMAP2 has a number of different interrupt controllers, each interrupt
  * controller is identified as its own "bank". Register definitions are
@@ -68,24 +71,18 @@ static void omap_ack_irq(unsigned int irq)
 
 static void omap_mask_irq(unsigned int irq)
 {
-	int offset = (irq >> 5) << 5;
+	int offset = irq & (~(IRQ_BITS_PER_REG - 1));
 
-	if (irq >= 64)
-		irq %= 64;
-	else if (irq >= 32)
-		irq %= 32;
+	irq &= (IRQ_BITS_PER_REG - 1);
 
 	intc_bank_write_reg(1 << irq, &irq_banks[0], INTC_MIR_SET0 + offset);
 }
 
 static void omap_unmask_irq(unsigned int irq)
 {
-	int offset = (irq >> 5) << 5;
+	int offset = irq & (~(IRQ_BITS_PER_REG - 1));
 
-	if (irq >= 64)
-		irq %= 64;
-	else if (irq >= 32)
-		irq %= 32;
+	irq &= (IRQ_BITS_PER_REG - 1);
 
 	intc_bank_write_reg(1 << irq, &irq_banks[0], INTC_MIR_CLEAR0 + offset);
 }
@@ -131,11 +128,15 @@ int omap_irq_pending(void)
 		struct omap_irq_bank *bank = irq_banks + i;
 		int irq;
 
-		for (irq = 0; irq < bank->nr_irqs; irq += 32)
-			if (intc_bank_read_reg(bank, INTC_PENDING_IRQ0 +
-					       ((irq >> 5) << 5)))
+		for (irq = 0; irq < bank->nr_irqs; irq += IRQ_BITS_PER_REG) {
+			int offset = irq & (~(IRQ_BITS_PER_REG - 1));
+
+			if (intc_bank_read_reg(bank, (INTC_PENDING_IRQ0 +
+						      offset)))
 				return 1;
+		}
 	}
+
 	return 0;
 }
 

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

* Re: [PATCH] IRQ: simplify OMAP2 mask_irq/unmask_irq code
  2008-05-21 19:15   ` Paul Walmsley
@ 2008-05-22 19:50     ` Tony Lindgren
  0 siblings, 0 replies; 11+ messages in thread
From: Tony Lindgren @ 2008-05-22 19:50 UTC (permalink / raw)
  To: Paul Walmsley; +Cc: linux-omap, Paul Mundt, Kyungmin Park

* Paul Walmsley <paul@pwsan.com> [080521 12:15]:
> Hi Tony,
> 
> On Wed, 21 May 2008, Tony Lindgren wrote:
> 
> > * Paul Walmsley <paul@pwsan.com> [080520 18:20]:
> > > 
> > > Modify mach-omap2/irq.c to simplify the IRQ number-to-IRQ register and IRQ 
> > > number-to-register bit calculations.
> > 
> > How about patching Jouni's new omap_irq_pending() for this too?
> 
> done - updated patch below.

Thanks, pushing today.

Tony

> 
> - Paul
> 
> 
> [PATCH] IRQ: simplify OMAP2 mask_irq/unmask_irq code
> 
> Modify mach-omap2/irq.c to simplify the IRQ number-to-IRQ register and
> IRQ number-to-register bit calculations.
> 
> Signed-off-by: Paul Walmsley <paul@pwsan.com>
> Signed-off-by: Kyungmin Park <kmpark@infradead.org>
> Acked-by: Paul Mundt <lethal@linux-sh.org>
> 
> size:
>    text    data     bss     dec     hex filename
> 3272871  155128   98792 3526791  35d087 vmlinux.3430sdp
> 3272839  155128   98792 3526759  35d067 vmlinux.3430sdp.patched
> ---
> 
>  arch/arm/mach-omap2/irq.c |   27 ++++++++++++++-------------
>  1 files changed, 14 insertions(+), 13 deletions(-)
> 
> 
> diff --git a/arch/arm/mach-omap2/irq.c b/arch/arm/mach-omap2/irq.c
> index f1e1e2e..94d2f93 100644
> --- a/arch/arm/mach-omap2/irq.c
> +++ b/arch/arm/mach-omap2/irq.c
> @@ -28,6 +28,9 @@
>  #define INTC_MIR_SET0		0x008c
>  #define INTC_PENDING_IRQ0	0x0098
>  
> +/* Number of IRQ state bits in each MIR register */
> +#define IRQ_BITS_PER_REG	32
> +
>  /*
>   * OMAP2 has a number of different interrupt controllers, each interrupt
>   * controller is identified as its own "bank". Register definitions are
> @@ -68,24 +71,18 @@ static void omap_ack_irq(unsigned int irq)
>  
>  static void omap_mask_irq(unsigned int irq)
>  {
> -	int offset = (irq >> 5) << 5;
> +	int offset = irq & (~(IRQ_BITS_PER_REG - 1));
>  
> -	if (irq >= 64)
> -		irq %= 64;
> -	else if (irq >= 32)
> -		irq %= 32;
> +	irq &= (IRQ_BITS_PER_REG - 1);
>  
>  	intc_bank_write_reg(1 << irq, &irq_banks[0], INTC_MIR_SET0 + offset);
>  }
>  
>  static void omap_unmask_irq(unsigned int irq)
>  {
> -	int offset = (irq >> 5) << 5;
> +	int offset = irq & (~(IRQ_BITS_PER_REG - 1));
>  
> -	if (irq >= 64)
> -		irq %= 64;
> -	else if (irq >= 32)
> -		irq %= 32;
> +	irq &= (IRQ_BITS_PER_REG - 1);
>  
>  	intc_bank_write_reg(1 << irq, &irq_banks[0], INTC_MIR_CLEAR0 + offset);
>  }
> @@ -131,11 +128,15 @@ int omap_irq_pending(void)
>  		struct omap_irq_bank *bank = irq_banks + i;
>  		int irq;
>  
> -		for (irq = 0; irq < bank->nr_irqs; irq += 32)
> -			if (intc_bank_read_reg(bank, INTC_PENDING_IRQ0 +
> -					       ((irq >> 5) << 5)))
> +		for (irq = 0; irq < bank->nr_irqs; irq += IRQ_BITS_PER_REG) {
> +			int offset = irq & (~(IRQ_BITS_PER_REG - 1));
> +
> +			if (intc_bank_read_reg(bank, (INTC_PENDING_IRQ0 +
> +						      offset)))
>  				return 1;
> +		}
>  	}
> +
>  	return 0;
>  }
>  

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

end of thread, other threads:[~2008-05-22 19:50 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-05-20 18:21 [PATCH] IRQ: simplify OMAP2 mask_irq/unmask_irq code Paul Walmsley
2008-05-20 23:18 ` Kyungmin Park
2008-05-21  0:12   ` Paul Walmsley
2008-05-21  0:39     ` Philip Balister
2008-05-21  0:52       ` Kyungmin Park
2008-05-21  0:55     ` Paul Mundt
2008-05-21  1:19       ` Paul Walmsley
  -- strict thread matches above, loose matches on Subject: below --
2008-05-21  1:19 Paul Walmsley
2008-05-21 15:05 ` Tony Lindgren
2008-05-21 19:15   ` Paul Walmsley
2008-05-22 19:50     ` Tony Lindgren

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