mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Marc Zyngier <marc.zyngier@arm.com>
To: Bartosz Golaszewski <brgl@bgdev.pl>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Jonathan Cameron <Jonathan.Cameron@huawei.com>,
	Lars-Peter Clausen <lars@metafoo.de>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/3] irq/irq_sim: implement irq_sim_irq2offset()
Date: Wed, 18 Oct 2017 11:13:35 +0100	[thread overview]
Message-ID: <e5d643d2-94d7-acdf-ef87-0b490f6fb8c5@arm.com> (raw)
In-Reply-To: <CAMRc=McsPhPgxY_-ZD6SYJy4bed4uQXmYyvedRbCaMgFV6gbZw@mail.gmail.com>

On 18/10/17 10:51, Bartosz Golaszewski wrote:
> 2017-10-18 10:58 GMT+02:00 Marc Zyngier <marc.zyngier@arm.com>:
>> On 05/10/17 13:44, Bartosz Golaszewski wrote:
>>> Add a routine allowing to retrieve the offset corresponding with an
>>> allocated interrupt number from an irq_sim object.
>>>
>>> Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
>>> ---
>>>  include/linux/irq_sim.h |  1 +
>>>  kernel/irq/irq_sim.c    | 15 +++++++++++++++
>>>  2 files changed, 16 insertions(+)
>>>
>>> diff --git a/include/linux/irq_sim.h b/include/linux/irq_sim.h
>>> index 246f593face8..e9768ca81e3e 100644
>>> --- a/include/linux/irq_sim.h
>>> +++ b/include/linux/irq_sim.h
>>> @@ -41,5 +41,6 @@ void irq_sim_fini(struct irq_sim *sim);
>>>  void irq_sim_fire(struct irq_sim *sim, unsigned int offset);
>>>  int irq_sim_irqnum(struct irq_sim *sim, unsigned int offset);
>>>  int irq_sim_baseirq(struct irq_sim *sim);
>>> +unsigned int irq_sim_irq2offset(struct irq_sim *sim, int irq);
>>>
>>>  #endif /* _LINUX_IRQ_SIM_H */
>>> diff --git a/kernel/irq/irq_sim.c b/kernel/irq/irq_sim.c
>>> index 1be10d0e295f..9a9a1bc8853c 100644
>>> --- a/kernel/irq/irq_sim.c
>>> +++ b/kernel/irq/irq_sim.c
>>> @@ -174,3 +174,18 @@ int irq_sim_baseirq(struct irq_sim *sim)
>>>       return irq_sim_irqnum(sim, 0);
>>>  }
>>>  EXPORT_SYMBOL_GPL(irq_sim_baseirq);
>>> +
>>> +/**
>>> + * irq_sim_irq2offset - Get the offset of an allocated interrupt.
>>> + *
>>> + * @sim:        The interrupt simulator object.
>>> + * irq:         Allocated interrupt number.
>>> + *
>>> + * Perform a reverse lookup for the interrupt number and return its offset in
>>> + * the array allocated by sim_irq.
>>> + */
>>> +unsigned int irq_sim_irq2offset(struct irq_sim *sim, int irq)
>>> +{
>>> +     return irq - sim->irq_base;
>>> +}
>>> +EXPORT_SYMBOL_GPL(irq_sim_irq2offset);
>>>
>>
>> How is that useful in a random driver? The irq base and the offset are
>> things that should be internal to an irqchip. Maybe you could explain
>> the context you want to use this in.
>>
> 
> The interrupts are allocated within the interrupt simulator code, but
> it's up to users to actually request these irqs. That's why we already
> have sim_irq_irqnum().
> 
> The IIO dummy driver (one of the users of irq_sim) uses these irq
> numbers retrieved from the simulator to also access private data
> stored in the iio_dummy_evgen module. Currently we store the base
> interrupt number in a separate variable in the dummy_evgen context
> struct and calculate the offset in the interrupt array manually. We
> could simplify that code by moving this logic into the interrupt
> simulator.

It looks to me that this is all because the irq_sim creation is a bit awkward.
You end-up with all kind of exotic interfaces because you don't know the base
of the irq range at creation time.

How about something like this:

diff --git a/kernel/irq/irq_sim.c b/kernel/irq/irq_sim.c
index 24caabf1a0f7..484c3544c0d1 100644
--- a/kernel/irq/irq_sim.c
+++ b/kernel/irq/irq_sim.c
@@ -49,7 +49,8 @@ static void irq_sim_handle_irq(struct irq_work *work)
  * @sim:        The interrupt simulator object to initialize.
  * @num_irqs:   Number of interrupts to allocate
  *
- * Returns 0 on success and a negative error number on failure.
+ * Returns the interrupt base on success and a negative error number
+ * on failure.
  */
 int irq_sim_init(struct irq_sim *sim, unsigned int num_irqs)
 {
@@ -78,7 +79,7 @@ int irq_sim_init(struct irq_sim *sim, unsigned int num_irqs)
 	init_irq_work(&sim->work_ctx.work, irq_sim_handle_irq);
 	sim->irq_count = num_irqs;
 
-	return 0;
+	return sim->irq_base;
 }
 EXPORT_SYMBOL_GPL(irq_sim_init);
 
You can then deal with the offset directly in your driver, as you're
guaranteed a 1:1 mapping.

Thoughts?

	M.
-- 
Jazz is not dead. It just smells funny...

  reply	other threads:[~2017-10-18 10:13 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-05 12:44 [PATCH 0/3] irq-sim updates for 4.15 Bartosz Golaszewski
2017-10-05 12:44 ` [PATCH 1/3] irq/irq_sim: explicitly pull in slab.h Bartosz Golaszewski
2017-10-05 12:44 ` [PATCH 2/3] irq/irq_sim: implement irq_sim_baseirq() Bartosz Golaszewski
2017-10-05 12:44 ` [PATCH 3/3] irq/irq_sim: implement irq_sim_irq2offset() Bartosz Golaszewski
2017-10-18  8:58   ` Marc Zyngier
2017-10-18  9:51     ` Bartosz Golaszewski
2017-10-18 10:13       ` Marc Zyngier [this message]
2017-10-18 12:49         ` Bartosz Golaszewski
2017-10-18 15:47           ` Marc Zyngier
2017-10-18  8:34 ` [PATCH 0/3] irq-sim updates for 4.15 Bartosz Golaszewski

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=e5d643d2-94d7-acdf-ef87-0b490f6fb8c5@arm.com \
    --to=marc.zyngier@arm.com \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=brgl@bgdev.pl \
    --cc=lars@metafoo.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tglx@linutronix.de \
    /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

all inboxes | Powered by JetHome®