Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp3583249imj; Tue, 12 Feb 2019 00:54:52 -0800 (PST) X-Google-Smtp-Source: AHgI3IY7S1ezxqqueQyTcyhaqSbeq8NbNjsjXBd7tP5DG6pVj1lYNrHhQtp/yPy29Uf9mcExoKzR X-Received: by 2002:a62:5f47:: with SMTP id t68mr2964415pfb.89.1549961692041; Tue, 12 Feb 2019 00:54:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549961692; cv=none; d=google.com; s=arc-20160816; b=txg2TZfzQngjC/zYAIiqBVMY8ijWsRMUzsHUron3RkPHbqM/G0qXHHCD9ehyJLoZjZ 6hfrgZNbJ9gYr7GQaLf4187/3WbYhPuMNw0pDSiz+kb/1V/nbSNhYGayJi7+JRVGR1BH ejpaNXIcPQ6qTuITEISb6O9btOfRFYpRK0hTJlovJqOynbjCKSK1ZatdvoSJXYr5Jn+g mCJFnjQ/oPv6Ywfdg93UiXewORrVujnXMsAWDbebtedZssKMJh6pG4GyDdRWhriY/TOM RHPTEgp4PTPvuZtho4KOQFSVrcK7NomqYe17fEck+P+CG2THuH3N+xFxKod76WsQHcb7 ahJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :organization:user-agent:references:in-reply-to:subject:cc:to:from :message-id:date; bh=BhaazCte2HGz0U3Lu3PjMhDWpb6GqXFNgccDpxpkrFs=; b=zMMc42csHFDCfQwERQNj02nCFg1ZgWtl4zgSou7J9rhLmp/BAqRuIIhuy5WYzaVd2m SYXwNMyVXvgmoVeQ7VRstlkP6jQEFkGIx3afth6BCNT/1HEBQq0jDJlGuXuGMYgixSne 5ru/Q431jK2Pn52rEJSG6m4H+4e4JtIny24lRnefyxUsOAaWGGjr2cGn0fEgv+c7mAvu reYDRXBRC0Z554emCRYcape26qMGsCte8qp/wQwnamjnuBtfwHvgN5kEHASEjobnUKJm orYD8cjHP0jZqtWS3OlmH6xmKkfomFUqZ61VRFCSHBz0LsPdrMFgyD6hBuBRSKN3XuRg 7D6g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h16si11621394pgj.203.2019.02.12.00.54.35; Tue, 12 Feb 2019 00:54:52 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728633AbfBLIxO convert rfc822-to-8bit (ORCPT + 99 others); Tue, 12 Feb 2019 03:53:14 -0500 Received: from foss.arm.com ([217.140.101.70]:33604 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728501AbfBLIxM (ORCPT ); Tue, 12 Feb 2019 03:53:12 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 38C42EBD; Tue, 12 Feb 2019 00:53:12 -0800 (PST) Received: from big-swifty.misterjones.org (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8E6773F557; Tue, 12 Feb 2019 00:53:09 -0800 (PST) Date: Tue, 12 Feb 2019 08:53:00 +0000 Message-ID: <867ee5tmkz.wl-marc.zyngier@arm.com> From: Marc Zyngier To: Bartosz Golaszewski Cc: Bartosz Golaszewski , Linus Walleij , Thomas Gleixner , Uwe =?UTF-8?B?S2xlaW5lLUvDtm5pZw==?= , linux-gpio , LKML Subject: Re: [PATCH v2 2/9] irq/irq_sim: use irq domain In-Reply-To: References: <20190129084411.30495-1-brgl@bgdev.pl> <20190129084411.30495-3-brgl@bgdev.pl> <20190211222610.42e9189b@why.wild-wind.fr.eu.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 EasyPG/1.0.0 Emacs/25.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) Organization: ARM Ltd MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Bartosz, On Tue, 12 Feb 2019 08:30:32 +0000, Bartosz Golaszewski wrote: > > pon., 11 lut 2019 o 23:26 Marc Zyngier napisaƂ(a): > > > > On Tue, 29 Jan 2019 09:44:04 +0100 > > Bartosz Golaszewski wrote: > > > > > From: Bartosz Golaszewski > > > > > > 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 > > > --- > > > 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 > > > #include > > > +#include > > > #include > > > > > > /* > > > @@ -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. 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. Thanks, M. -- Jazz is not dead, it just smell funny.