linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bartosz Golaszewski <brgl@bgdev.pl>
To: Marc Zyngier <marc.zyngier@arm.com>
Cc: "Bartosz Golaszewski" <bgolaszewski@baylibre.com>,
	"Linus Walleij" <linus.walleij@linaro.org>,
	"Thomas Gleixner" <tglx@linutronix.de>,
	"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
	linux-gpio <linux-gpio@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2 2/9] irq/irq_sim: use irq domain
Date: Tue, 12 Feb 2019 09:56:46 +0100	[thread overview]
Message-ID: <CAMRc=Md8SvX8a-NBE7PrdZ+enZkn+LR1+XOmOZ6oyJUPp1T0cw@mail.gmail.com> (raw)
In-Reply-To: <867ee5tmkz.wl-marc.zyngier@arm.com>

wt., 12 lut 2019 o 09:53 Marc Zyngier <marc.zyngier@arm.com> napisał(a):
>
> Bartosz,
>
> On Tue, 12 Feb 2019 08:30:32 +0000,
> Bartosz Golaszewski <bgolaszewski@baylibre.com> wrote:
> >
> > pon., 11 lut 2019 o 23:26 Marc Zyngier <marc.zyngier@arm.com> napisał(a):
> > >
> > > On Tue, 29 Jan 2019 09:44:04 +0100
> > > Bartosz Golaszewski <brgl@bgdev.pl> wrote:
> > >
> > > > From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> > > >
> > > > Delegate the offset to virq number mapping to the provided framework
> > > > instead of handling it locally. Use the legacy domain as we want to
> > > > preallocate the irq descriptors.
> > >
> > > Why?
> > >
> > > >
> > > > Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> > > > ---
> > > >  include/linux/irq_sim.h |  6 +--
> > > >  kernel/irq/irq_sim.c    | 94 +++++++++++++++++++++++++++++------------
> > > >  2 files changed, 71 insertions(+), 29 deletions(-)
> > > >
> > > > diff --git a/include/linux/irq_sim.h b/include/linux/irq_sim.h
> > > > index eda132c22b57..b96c2f752320 100644
> > > > --- a/include/linux/irq_sim.h
> > > > +++ b/include/linux/irq_sim.h
> > > > @@ -8,6 +8,7 @@
> > > >
> > > >  #include <linux/irq.h>
> > > >  #include <linux/irq_work.h>
> > > > +#include <linux/irqdomain.h>
> > > >  #include <linux/device.h>
> > > >
> > > >  /*
> > > > @@ -21,16 +22,15 @@ struct irq_sim_work_ctx {
> > > >  };
> > > >
> > > >  struct irq_sim_irq_ctx {
> > > > -     int                     irqnum;
> > > >       bool                    enabled;
> > > >  };
> > > >
> > > >  struct irq_sim {
> > > >       struct irq_chip         chip;
> > > > +     struct irq_domain       *domain;
> > > >       struct irq_sim_work_ctx work_ctx;
> > > > -     int                     irq_base;
> > > > +     int                     virq_base;
> > > >       unsigned int            irq_count;
> > > > -     struct irq_sim_irq_ctx  *irqs;
> > > >  };
> > > >
> > > >  int irq_sim_init(struct irq_sim *sim, unsigned int num_irqs);
> > > > diff --git a/kernel/irq/irq_sim.c b/kernel/irq/irq_sim.c
> > > > index b732e4e2e45b..2bcdbab1bc5a 100644
> > > > --- a/kernel/irq/irq_sim.c
> > > > +++ b/kernel/irq/irq_sim.c
> > > > @@ -44,6 +44,43 @@ static void irq_sim_handle_irq(struct irq_work *work)
> > > >       }
> > > >  }
> > > >
> > > > +static int irq_sim_domain_map(struct irq_domain *domain,
> > > > +                           unsigned int virq, irq_hw_number_t hw)
> > > > +{
> > > > +     struct irq_sim *sim = domain->host_data;
> > > > +     struct irq_sim_irq_ctx *ctx;
> > > > +
> > > > +     ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
> > > > +     if (!ctx)
> > > > +             return -ENOMEM;
> > > > +
> > > > +     irq_set_chip(virq, &sim->chip);
> > > > +     irq_set_chip_data(virq, ctx);
> > > > +     irq_set_handler(virq, handle_simple_irq);
> > >
> > > Consider using modern APIs such as irq_domain_set_info().
> > >
> > > > +     irq_modify_status(virq, IRQ_NOREQUEST | IRQ_NOAUTOEN, IRQ_NOPROBE);
> > >
> > > Where is this requirement coming from?
> > >
> > > > +
> > > > +     return 0;
> > > > +}
> > > > +
> > > > +static void irq_sim_domain_free(struct irq_domain *domain,
> > > > +                             unsigned int virq, unsigned int num_irqs)
> > > > +{
> > > > +     struct irq_sim_irq_ctx *ctx;
> > > > +     struct irq_data *irq;
> > > > +     int i;
> > > > +
> > > > +     for (i = 0; i < num_irqs; i++) {
> > > > +             irq = irq_domain_get_irq_data(domain, virq + i);
> > > > +             ctx = irq_data_get_irq_chip_data(irq);
> > > > +             kfree(ctx);
> > > > +     }
> > > > +}
> > > > +
> > > > +static const struct irq_domain_ops irq_sim_domain_ops = {
> > > > +     .map = irq_sim_domain_map,
> > > > +     .free = irq_sim_domain_free,
> > >
> > > The intended use of the v2 API is to have alloc and free as a pair, and
> > > no map. So please choose which version of the API you're using here.
> > > The safest bet would be to move what you do on map into alloc.
> > >
> > > > +};
> > > > +
> > > >  /**
> > > >   * irq_sim_init - Initialize the interrupt simulator: allocate a range of
> > > >   *                dummy interrupts.
> > > > @@ -56,16 +93,15 @@ static void irq_sim_handle_irq(struct irq_work *work)
> > > >   */
> > > >  int irq_sim_init(struct irq_sim *sim, unsigned int num_irqs)
> > > >  {
> > > > -     int i;
> > > > -
> > > > -     sim->irqs = kmalloc_array(num_irqs, sizeof(*sim->irqs), GFP_KERNEL);
> > > > -     if (!sim->irqs)
> > > > +     sim->virq_base = irq_alloc_descs(-1, 0, num_irqs, 0);
> > > > +     if (sim->virq_base < 0)
> > > > +             return sim->virq_base;
> > > > +
> > > > +     sim->domain = irq_domain_add_legacy(NULL, num_irqs, sim->virq_base,
> > > > +                                         0, &irq_sim_domain_ops, sim);
> > >
> > > Why do you need a legacy domain? As far as I can tell, this is new
> > > code, hence it has no legacy.
> > >
> > > > +     if (!sim->domain) {
> > > > +             irq_free_descs(sim->virq_base, num_irqs);
> > > >               return -ENOMEM;
> > > > -
> > > > -     sim->irq_base = irq_alloc_descs(-1, 0, num_irqs, 0);
> > > > -     if (sim->irq_base < 0) {
> > > > -             kfree(sim->irqs);
> > > > -             return sim->irq_base;
> > > >       }
> > > >
> > > >       sim->chip.name = "irq_sim";
> > > > @@ -74,25 +110,15 @@ int irq_sim_init(struct irq_sim *sim, unsigned int num_irqs)
> > > >
> > > >       sim->work_ctx.pending = bitmap_zalloc(num_irqs, GFP_KERNEL);
> > > >       if (!sim->work_ctx.pending) {
> > > > -             kfree(sim->irqs);
> > > > -             irq_free_descs(sim->irq_base, num_irqs);
> > > > +             irq_domain_remove(sim->domain);
> > > > +             irq_free_descs(sim->virq_base, num_irqs);
> > > >               return -ENOMEM;
> > > >       }
> > > >
> > > > -     for (i = 0; i < num_irqs; i++) {
> > > > -             sim->irqs[i].irqnum = sim->irq_base + i;
> > > > -             sim->irqs[i].enabled = false;
> > > > -             irq_set_chip(sim->irq_base + i, &sim->chip);
> > > > -             irq_set_chip_data(sim->irq_base + i, &sim->irqs[i]);
> > > > -             irq_set_handler(sim->irq_base + i, &handle_simple_irq);
> > > > -             irq_modify_status(sim->irq_base + i,
> > > > -                               IRQ_NOREQUEST | IRQ_NOAUTOEN, IRQ_NOPROBE);
> > > > -     }
> > > > -
> > > >       init_irq_work(&sim->work_ctx.work, irq_sim_handle_irq);
> > > >       sim->irq_count = num_irqs;
> > > >
> > > > -     return sim->irq_base;
> > > > +     return sim->virq_base;
> > > >  }
> > > >  EXPORT_SYMBOL_GPL(irq_sim_init);
> > > >
> > > > @@ -106,8 +132,8 @@ void irq_sim_fini(struct irq_sim *sim)
> > > >  {
> > > >       irq_work_sync(&sim->work_ctx.work);
> > > >       bitmap_free(sim->work_ctx.pending);
> > > > -     irq_free_descs(sim->irq_base, sim->irq_count);
> > > > -     kfree(sim->irqs);
> > > > +     irq_domain_free_irqs(sim->virq_base, sim->irq_count);
> > > > +     irq_domain_remove(sim->domain);
> > > >  }
> > > >  EXPORT_SYMBOL_GPL(irq_sim_fini);
> > > >
> > > > @@ -151,6 +177,20 @@ int devm_irq_sim_init(struct device *dev, struct irq_sim *sim,
> > > >  }
> > > >  EXPORT_SYMBOL_GPL(devm_irq_sim_init);
> > > >
> > > > +static struct irq_sim_irq_ctx *
> > > > +irq_sim_get_ctx(struct irq_sim *sim, unsigned int offset)
> > > > +{
> > > > +     struct irq_sim_irq_ctx *ctx;
> > > > +     struct irq_data *irq;
> > > > +     int virq;
> > > > +
> > > > +     virq = irq_find_mapping(sim->domain, offset);
> > > > +     irq = irq_domain_get_irq_data(sim->domain, virq);
> > > > +     ctx = irq_data_get_irq_chip_data(irq);
> > > > +
> > > > +     return ctx;
> > > > +}
> > > > +
> > > >  /**
> > > >   * irq_sim_fire - Enqueue an interrupt.
> > > >   *
> > > > @@ -159,7 +199,9 @@ EXPORT_SYMBOL_GPL(devm_irq_sim_init);
> > > >   */
> > > >  void irq_sim_fire(struct irq_sim *sim, unsigned int offset)
> > > >  {
> > > > -     if (sim->irqs[offset].enabled) {
> > > > +     struct irq_sim_irq_ctx *ctx = irq_sim_get_ctx(sim, offset);
> > > > +
> > > > +     if (ctx->enabled) {
> > > >               set_bit(offset, sim->work_ctx.pending);
> > > >               irq_work_queue(&sim->work_ctx.work);
> > > >       }
> > > > @@ -175,6 +217,6 @@ EXPORT_SYMBOL_GPL(irq_sim_fire);
> > > >   */
> > > >  int irq_sim_irqnum(struct irq_sim *sim, unsigned int offset)
> > > >  {
> > > > -     return sim->irqs[offset].irqnum;
> > > > +     return irq_find_mapping(sim->domain, offset);
> > > >  }
> > > >  EXPORT_SYMBOL_GPL(irq_sim_irqnum);
> > >
> > >
> > > Thanks,
> > >
> > >         M.
> > > --
> > > Without deviation from the norm, progress is not possible.
> >
> > Hi Marc,
> >
> > since we're so late in the release cycle and I really only need patch
> > 3/9 from this series - I'll drop this patch and 1/9 as well in v3. We
> > can come back to this in the next cycle.
>
> Then this series doesn't even compile once you remove these two
> patches (just removing patch #1 breaks everything). Please repost a
> fixed series that can be reviewed in the light of your new, reduced
> requirements.
>

Yes, this is what I meant by "I'll drop this patch and 1/9 as well in
v3" - I meant I'll repost a new version without the first two and with
patch 3/9 fixed.

> I'd also appreciate if you could answer the questions I have above, as
> it appears that you intend to bring this patch back in the future.
>

Sure, will do.

Bart

  reply	other threads:[~2019-02-12  8:57 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-29  8:44 [PATCH v2 0/9] gpio: mockup: improve the user-space testing interface Bartosz Golaszewski
2019-01-29  8:44 ` [PATCH v2 1/9] irq/irq_sim: don't share the irq_chip structure between simulators Bartosz Golaszewski
2019-02-11 22:28   ` Marc Zyngier
2019-02-12  8:29     ` Bartosz Golaszewski
2019-01-29  8:44 ` [PATCH v2 2/9] irq/irq_sim: use irq domain Bartosz Golaszewski
2019-02-11 22:26   ` Marc Zyngier
2019-02-12  8:30     ` Bartosz Golaszewski
2019-02-12  8:53       ` Marc Zyngier
2019-02-12  8:56         ` Bartosz Golaszewski [this message]
2019-01-29  8:44 ` [PATCH v2 3/9] irq/irq_sim: provide irq_sim_fire_type() Bartosz Golaszewski
2019-01-29  9:07   ` Uwe Kleine-König
2019-01-29 11:01     ` Bartosz Golaszewski
2019-01-29 12:55       ` Uwe Kleine-König
2019-02-01 11:02         ` Bartosz Golaszewski
2019-02-12  9:10   ` Marc Zyngier
2019-02-12  9:19     ` Bartosz Golaszewski
2019-02-12 10:06       ` Uwe Kleine-König
2019-02-12 10:15         ` Bartosz Golaszewski
2019-02-12 10:27       ` Marc Zyngier
2019-02-12 10:37         ` Bartosz Golaszewski
2019-02-12 10:52           ` Marc Zyngier
2019-02-12 11:05         ` Uwe Kleine-König
2019-02-12 11:09           ` Bartosz Golaszewski
2019-02-12 11:35           ` Marc Zyngier
2019-01-29  8:44 ` [PATCH v2 4/9] gpio: mockup: add locking Bartosz Golaszewski
2019-01-29  8:44 ` [PATCH v2 5/9] gpio: mockup: implement get_multiple() Bartosz Golaszewski
2019-01-29  8:44 ` [PATCH v2 6/9] gpio: mockup: don't create the debugfs link named after the label Bartosz Golaszewski
2019-01-29  8:44 ` [PATCH v2 7/9] gpio: mockup: change the type of 'offset' to unsigned int Bartosz Golaszewski
2019-01-29  8:44 ` [PATCH v2 8/9] gpio: mockup: change the signature of unlocked get/set helpers Bartosz Golaszewski
2019-01-29  8:44 ` [PATCH v2 9/9] gpio: mockup: rework debugfs interface Bartosz Golaszewski
2019-02-06 10:23 ` [PATCH v2 0/9] gpio: mockup: improve the user-space testing interface Bartosz Golaszewski
2019-02-11 22:33   ` Marc Zyngier

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='CAMRc=Md8SvX8a-NBE7PrdZ+enZkn+LR1+XOmOZ6oyJUPp1T0cw@mail.gmail.com' \
    --to=brgl@bgdev.pl \
    --cc=bgolaszewski@baylibre.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marc.zyngier@arm.com \
    --cc=tglx@linutronix.de \
    --cc=u.kleine-koenig@pengutronix.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;
as well as URLs for NNTP newsgroup(s).