From patchwork Tue Feb 11 13:12:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 11375449 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 243CD1820 for ; Tue, 11 Feb 2020 13:13:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 045EF20848 for ; Tue, 11 Feb 2020 13:13:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="JShKl6tZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729054AbgBKNNE (ORCPT ); Tue, 11 Feb 2020 08:13:04 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:32926 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729032AbgBKNND (ORCPT ); Tue, 11 Feb 2020 08:13:03 -0500 Received: by mail-wm1-f65.google.com with SMTP id m10so2250347wmc.0 for ; Tue, 11 Feb 2020 05:13:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GheSz6neeN101nnz+FLOMJnrgCH2+MfnhxBOEsDMmXs=; b=JShKl6tZS7GpJERb5eCGZI7MTawLLYCPtJqP12ehsJ1w/S50qovoib1cqPZmaDSwg0 jjXkPqf63XQRrI6dkcBUNHwhVk9h2r0jG4dXBeIqpCcBT3Vp2CDkhhof/pZkGnlZlYjA HX7okiZrFbZkWMoHuCiyZfcMCAyrTjP0QCsDpxUHeXhTVmvYAhwrnRcNs/OYyIgqKloa QCkvHDHppbjbbApFdEhR2iytUgCVJn53uI7cgovLsrs6rkN8L+rqlpCWT+hm6l2sibim yz9kTe32mQ6GA/gud4Ly3szhwO8p42fGavNl3x8XJ5NV/yrJ9Mu2uPXxEb1y96OU+oa1 Lizg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GheSz6neeN101nnz+FLOMJnrgCH2+MfnhxBOEsDMmXs=; b=Olq+EVvQ5QOCqEHuRmnwVDnR9rVV655uHlc8vwaPbPQIL8oz3WRWtBQycdYF8DsUs4 mQBxMF+maY8fCniNjI/lBgJUCK0l9MNuHD/tbbnAEcQy5LfkYMsMadLX8GwPDSqdswfT L/dpI3by1qdq5k0fCCpN3uHpWKMcEynQvIeim8vmxqo/TOYBoH/SvKc4SHwdXbvC4s96 JXqROrJ8EWQj5cXP8X6VLVHrhT9Mxp1glqIAIc3b7lIy96hFGHgbOlY7F/9DoTlCEW3O +SuUxXCPeOKKpSChP9GpaGNjXCvHz3yWLXWfSu5cTNq9lKy/2rZ3Gn6utDJwrAhB3WO3 I6mw== X-Gm-Message-State: APjAAAX8klV21MmL54jVcR5mF7N2ApoR4Y/522jEj30ojppw4m8eUuer q89bt4+w1skauAaYIxk3nlj4BA== X-Google-Smtp-Source: APXvYqxd6Cg0lSNsAMRLVwVUdpIg0bBIYoGlnhsECR2LrSlHcPK1OPYbBWi4nu2ydo/l10SOHjhJIg== X-Received: by 2002:a1c:7c18:: with SMTP id x24mr5979102wmc.185.1581426780114; Tue, 11 Feb 2020 05:13:00 -0800 (PST) Received: from localhost.localdomain (lfbn-nic-1-65-232.w2-15.abo.wanadoo.fr. [2.15.156.232]) by smtp.gmail.com with ESMTPSA id b21sm3873013wmd.37.2020.02.11.05.12.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Feb 2020 05:12:59 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Thomas Gleixner , Jason Cooper , Marc Zyngier Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 1/6] irq: make irq_domain_reset_irq_data() available even for non-V2 users Date: Tue, 11 Feb 2020 14:12:35 +0100 Message-Id: <20200211131240.15853-2-brgl@bgdev.pl> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200211131240.15853-1-brgl@bgdev.pl> References: <20200211131240.15853-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Bartosz Golaszewski irq_domain_reset_irq_data() doesn't modify the parent data, so it can be made available even if irq domain hierarchy is not being built. Signed-off-by: Bartosz Golaszewski --- include/linux/irqdomain.h | 4 ++-- kernel/irq/irqdomain.c | 24 ++++++++++++------------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/include/linux/irqdomain.h b/include/linux/irqdomain.h index b2d47571ab67..20d38621e2f8 100644 --- a/include/linux/irqdomain.h +++ b/include/linux/irqdomain.h @@ -450,6 +450,7 @@ extern void irq_domain_set_info(struct irq_domain *domain, unsigned int virq, irq_hw_number_t hwirq, struct irq_chip *chip, void *chip_data, irq_flow_handler_t handler, void *handler_data, const char *handler_name); +extern void irq_domain_reset_irq_data(struct irq_data *irq_data); #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY extern struct irq_domain *irq_domain_create_hierarchy(struct irq_domain *parent, unsigned int flags, unsigned int size, @@ -475,7 +476,6 @@ extern int __irq_domain_alloc_irqs(struct irq_domain *domain, int irq_base, extern void irq_domain_free_irqs(unsigned int virq, unsigned int nr_irqs); extern int irq_domain_activate_irq(struct irq_data *irq_data, bool early); extern void irq_domain_deactivate_irq(struct irq_data *irq_data); - static inline int irq_domain_alloc_irqs(struct irq_domain *domain, unsigned int nr_irqs, int node, void *arg) { @@ -491,7 +491,7 @@ extern int irq_domain_set_hwirq_and_chip(struct irq_domain *domain, irq_hw_number_t hwirq, struct irq_chip *chip, void *chip_data); -extern void irq_domain_reset_irq_data(struct irq_data *irq_data); + extern void irq_domain_free_irqs_common(struct irq_domain *domain, unsigned int virq, unsigned int nr_irqs); diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c index 7527e5ef6fe5..039427c98af8 100644 --- a/kernel/irq/irqdomain.c +++ b/kernel/irq/irqdomain.c @@ -1047,6 +1047,18 @@ int irq_domain_alloc_descs(int virq, unsigned int cnt, irq_hw_number_t hwirq, return virq; } +/** + * irq_domain_reset_irq_data - Clear hwirq, chip and chip_data in @irq_data + * @irq_data: The pointer to irq_data + */ +void irq_domain_reset_irq_data(struct irq_data *irq_data) +{ + irq_data->hwirq = 0; + irq_data->chip = &no_irq_chip; + irq_data->chip_data = NULL; +} +EXPORT_SYMBOL_GPL(irq_domain_reset_irq_data); + #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY /** * irq_domain_create_hierarchy - Add a irqdomain into the hierarchy @@ -1247,18 +1259,6 @@ void irq_domain_set_info(struct irq_domain *domain, unsigned int virq, } EXPORT_SYMBOL(irq_domain_set_info); -/** - * irq_domain_reset_irq_data - Clear hwirq, chip and chip_data in @irq_data - * @irq_data: The pointer to irq_data - */ -void irq_domain_reset_irq_data(struct irq_data *irq_data) -{ - irq_data->hwirq = 0; - irq_data->chip = &no_irq_chip; - irq_data->chip_data = NULL; -} -EXPORT_SYMBOL_GPL(irq_domain_reset_irq_data); - /** * irq_domain_free_irqs_common - Clear irq_data and free the parent * @domain: Interrupt domain to match From patchwork Tue Feb 11 13:12:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 11375447 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EE4CA13A4 for ; Tue, 11 Feb 2020 13:13:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B12A920848 for ; Tue, 11 Feb 2020 13:13:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="FNi6voqe" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729058AbgBKNNY (ORCPT ); Tue, 11 Feb 2020 08:13:24 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:52368 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729039AbgBKNNF (ORCPT ); Tue, 11 Feb 2020 08:13:05 -0500 Received: by mail-wm1-f68.google.com with SMTP id p9so3478472wmc.2 for ; Tue, 11 Feb 2020 05:13:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4/ClLMH9K8gj4a+Aqm8LmKwTwzGtDeG5yCyNx1PNxt4=; b=FNi6voqeityGInSH+wzZct/pOqfAlTliEISbwzIJfFpPaD8Bjnh1BMfaYQLdXTNuPQ Xktq/CS3AUD/SCYS2VKHVwmWm9F1xY4uzn6BII0ZPl0CuxHoebLTy4r+DppNnHgYCpBf wAQi/fsSwQYQd6yO1NIkVcvNFBM0oGz1mm5WhlXN9WAGq4QHnES/e3kRHdfm0S4SLU8d Ncylq5Gq9YgI1lNcKejw8epLL2RiOxwJxyKDCL+0XVdaZDHmdBjuW8HMCsTpnqxqm5q+ s7RtuD0viKkEBSalFaoKebmn3eYIynlfnnFBVTQvyzSC/x8003Llpftundeod7dpvfmw BGuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4/ClLMH9K8gj4a+Aqm8LmKwTwzGtDeG5yCyNx1PNxt4=; b=KGCgxCBULWtKClMRbJwz6X9r+VmXYxCOzAw3WuQ+xm2HfUKVRrM31DGRZkkV6WFZcP c//s+fo6W6j2z4R+mvSahqBmUyTEvMznnOF+LCX99qtIKsHXMLhoMjpuspv0Acag4xFC NbCCzpI4A+c7Ns+6n4qdLZ7WBQOEAb95taVqwxHty1DIpp7zRMkIymrvVFvayKY1OWIH WzrxnGoYezLiFFg1FcsENu4zRohTKfKzireAMh923EIp/Qi3ClxATCL3LNi4tF9qA8dJ k0pb4Wryo9qV1Ql+Ypc3MOWvFvwDOjL4mR50iaKHCUj0JvNKjfxDlTLfznJCwv9H0Zdm QoxQ== X-Gm-Message-State: APjAAAVR3t6KKnJlZaJ6B2Zxt2TjlsM8HhW9R877PbjvT4Hk8TEp1GIb fmMGPxfoMR9KFvbvfcMMJc0rTQ== X-Google-Smtp-Source: APXvYqwZ4k2qVszsqu+njre4MwxPq/Bw+VWHU07m3kjE8M9nbQCgx00TQADN6PRrUiKTbdtLSBZcrQ== X-Received: by 2002:a7b:c1da:: with SMTP id a26mr5930833wmj.155.1581426781316; Tue, 11 Feb 2020 05:13:01 -0800 (PST) Received: from localhost.localdomain (lfbn-nic-1-65-232.w2-15.abo.wanadoo.fr. [2.15.156.232]) by smtp.gmail.com with ESMTPSA id b21sm3873013wmd.37.2020.02.11.05.13.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Feb 2020 05:13:00 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Thomas Gleixner , Jason Cooper , Marc Zyngier Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 2/6] irq/irq_sim: simplify the API Date: Tue, 11 Feb 2020 14:12:36 +0100 Message-Id: <20200211131240.15853-3-brgl@bgdev.pl> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200211131240.15853-1-brgl@bgdev.pl> References: <20200211131240.15853-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Bartosz Golaszewski The interrupt simulator API exposes a lot of custom data structures and functions and doesn't reuse the interfaces already exposed by the irq subsystem. This patch tries to address it. We hide all the simulator-related data structures from users and instead rely on the well-known irq domain. When creating the interrupt simulator the user receives a pointer to a newly created irq_domain and can use it to create mappings for simulated interrupts. It is also possible to pass a handle to fwnode when creating the simulator domain and retrieve it using irq_find_matching_fwnode(). The irq_sim_fire() function now only takes the virtual interrupt number as argument - there's no need anymore to pass it any data structure linked to the simulator. We modify the two modules that use the simulator at the same time as adding these changes in order to reduce the intermediate bloat that would result when trying to migrate the drivers in separate patches. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-mockup.c | 47 ++++-- drivers/iio/dummy/iio_dummy_evgen.c | 32 ++-- include/linux/irq_sim.h | 34 ++--- kernel/irq/Kconfig | 1 + kernel/irq/irq_sim.c | 225 +++++++++++++++++----------- 5 files changed, 202 insertions(+), 137 deletions(-) diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index 7d343bea784a..711aa9912271 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -48,7 +49,7 @@ struct gpio_mockup_line_status { struct gpio_mockup_chip { struct gpio_chip gc; struct gpio_mockup_line_status *lines; - struct irq_sim irqsim; + struct irq_domain *irq_sim_domain; struct dentry *dbg_dir; struct mutex lock; }; @@ -144,14 +145,12 @@ static void gpio_mockup_set_multiple(struct gpio_chip *gc, static int gpio_mockup_apply_pull(struct gpio_mockup_chip *chip, unsigned int offset, int value) { + int curr, irq, irq_type, ret = 0; struct gpio_desc *desc; struct gpio_chip *gc; - struct irq_sim *sim; - int curr, irq, irq_type; gc = &chip->gc; desc = &gc->gpiodev->descs[offset]; - sim = &chip->irqsim; mutex_lock(&chip->lock); @@ -161,14 +160,24 @@ static int gpio_mockup_apply_pull(struct gpio_mockup_chip *chip, if (curr == value) goto out; - irq = irq_sim_irqnum(sim, offset); + irq = irq_find_mapping(chip->irq_sim_domain, offset); + if (!irq) + /* + * This is fine - it just means, nobody is listening + * for interrupts on this line, otherwise + * irq_create_mapping() would have been called from + * the to_irq() callback. + */ + goto set_value; + irq_type = irq_get_trigger_type(irq); if ((value == 1 && (irq_type & IRQ_TYPE_EDGE_RISING)) || (value == 0 && (irq_type & IRQ_TYPE_EDGE_FALLING))) - irq_sim_fire(sim, offset); + irq_sim_fire(irq); } +set_value: /* Change the value unless we're actively driving the line. */ if (!test_bit(FLAG_REQUESTED, &desc->flags) || !test_bit(FLAG_IS_OUT, &desc->flags)) @@ -177,7 +186,7 @@ static int gpio_mockup_apply_pull(struct gpio_mockup_chip *chip, out: chip->lines[offset].pull = value; mutex_unlock(&chip->lock); - return 0; + return ret; } static int gpio_mockup_set_config(struct gpio_chip *gc, @@ -236,7 +245,7 @@ static int gpio_mockup_to_irq(struct gpio_chip *gc, unsigned int offset) { struct gpio_mockup_chip *chip = gpiochip_get_data(gc); - return irq_sim_irqnum(&chip->irqsim, offset); + return irq_create_mapping(chip->irq_sim_domain, offset); } static void gpio_mockup_free(struct gpio_chip *gc, unsigned int offset) @@ -389,6 +398,19 @@ static int gpio_mockup_name_lines(struct device *dev, return 0; } +static void gpio_mockup_dispose_mappings(void *data) +{ + struct gpio_mockup_chip *chip = data; + struct gpio_chip *gc = &chip->gc; + int i, irq; + + for (i = 0; i < gc->ngpio; i++) { + irq = irq_find_mapping(chip->irq_sim_domain, i); + if (irq) + irq_dispose_mapping(irq); + } +} + static int gpio_mockup_probe(struct platform_device *pdev) { struct gpio_mockup_chip *chip; @@ -456,8 +478,13 @@ static int gpio_mockup_probe(struct platform_device *pdev) return rv; } - rv = devm_irq_sim_init(dev, &chip->irqsim, gc->ngpio); - if (rv < 0) + chip->irq_sim_domain = devm_irq_domain_create_sim(dev, NULL, + gc->ngpio); + if (IS_ERR(chip->irq_sim_domain)) + return PTR_ERR(chip->irq_sim_domain); + + rv = devm_add_action_or_reset(dev, gpio_mockup_dispose_mappings, chip); + if (rv) return rv; rv = devm_gpiochip_add_data(dev, &chip->gc, chip); diff --git a/drivers/iio/dummy/iio_dummy_evgen.c b/drivers/iio/dummy/iio_dummy_evgen.c index a6edf30567aa..31c9e012abeb 100644 --- a/drivers/iio/dummy/iio_dummy_evgen.c +++ b/drivers/iio/dummy/iio_dummy_evgen.c @@ -37,8 +37,7 @@ struct iio_dummy_eventgen { struct iio_dummy_regs regs[IIO_EVENTGEN_NO]; struct mutex lock; bool inuse[IIO_EVENTGEN_NO]; - struct irq_sim irq_sim; - int base; + struct irq_domain *irq_sim_domain; }; /* We can only ever have one instance of this 'device' */ @@ -46,19 +45,17 @@ static struct iio_dummy_eventgen *iio_evgen; static int iio_dummy_evgen_create(void) { - int ret; - iio_evgen = kzalloc(sizeof(*iio_evgen), GFP_KERNEL); if (!iio_evgen) return -ENOMEM; - ret = irq_sim_init(&iio_evgen->irq_sim, IIO_EVENTGEN_NO); - if (ret < 0) { + iio_evgen->irq_sim_domain = irq_domain_create_sim(NULL, + IIO_EVENTGEN_NO); + if (IS_ERR(iio_evgen->irq_sim_domain)) { kfree(iio_evgen); - return ret; + return PTR_ERR(iio_evgen->irq_sim_domain); } - iio_evgen->base = irq_sim_irqnum(&iio_evgen->irq_sim, 0); mutex_init(&iio_evgen->lock); return 0; @@ -80,7 +77,7 @@ int iio_dummy_evgen_get_irq(void) mutex_lock(&iio_evgen->lock); for (i = 0; i < IIO_EVENTGEN_NO; i++) { if (!iio_evgen->inuse[i]) { - ret = irq_sim_irqnum(&iio_evgen->irq_sim, i); + ret = irq_create_mapping(iio_evgen->irq_sim_domain, i); iio_evgen->inuse[i] = true; break; } @@ -101,21 +98,27 @@ EXPORT_SYMBOL_GPL(iio_dummy_evgen_get_irq); */ void iio_dummy_evgen_release_irq(int irq) { + struct irq_data *irqd = irq_get_irq_data(irq); + mutex_lock(&iio_evgen->lock); - iio_evgen->inuse[irq - iio_evgen->base] = false; + iio_evgen->inuse[irqd_to_hwirq(irqd)] = false; + irq_dispose_mapping(irq); mutex_unlock(&iio_evgen->lock); } EXPORT_SYMBOL_GPL(iio_dummy_evgen_release_irq); struct iio_dummy_regs *iio_dummy_evgen_get_regs(int irq) { - return &iio_evgen->regs[irq - iio_evgen->base]; + struct irq_data *irqd = irq_get_irq_data(irq); + + return &iio_evgen->regs[irqd_to_hwirq(irqd)]; + } EXPORT_SYMBOL_GPL(iio_dummy_evgen_get_regs); static void iio_dummy_evgen_free(void) { - irq_sim_fini(&iio_evgen->irq_sim); + irq_domain_remove_sim(iio_evgen->irq_sim_domain); kfree(iio_evgen); } @@ -131,7 +134,7 @@ static ssize_t iio_evgen_poke(struct device *dev, { struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); unsigned long event; - int ret; + int ret, irq; ret = kstrtoul(buf, 10, &event); if (ret) @@ -140,7 +143,8 @@ static ssize_t iio_evgen_poke(struct device *dev, iio_evgen->regs[this_attr->address].reg_id = this_attr->address; iio_evgen->regs[this_attr->address].reg_data = event; - irq_sim_fire(&iio_evgen->irq_sim, this_attr->address); + irq = irq_find_mapping(iio_evgen->irq_sim_domain, this_attr->address); + irq_sim_fire(irq); return len; } diff --git a/include/linux/irq_sim.h b/include/linux/irq_sim.h index 4500d453a63e..26bf6164dcc7 100644 --- a/include/linux/irq_sim.h +++ b/include/linux/irq_sim.h @@ -1,41 +1,27 @@ /* SPDX-License-Identifier: GPL-2.0+ */ /* * Copyright (C) 2017-2018 Bartosz Golaszewski + * Copyright (C) 2020 Bartosz Golaszewski */ #ifndef _LINUX_IRQ_SIM_H #define _LINUX_IRQ_SIM_H -#include #include +#include +#include /* * Provides a framework for allocating simulated interrupts which can be * requested like normal irqs and enqueued from process context. */ -struct irq_sim_work_ctx { - struct irq_work work; - unsigned long *pending; -}; - -struct irq_sim_irq_ctx { - int irqnum; - bool enabled; -}; - -struct irq_sim { - struct irq_sim_work_ctx work_ctx; - int irq_base; - unsigned int irq_count; - struct irq_sim_irq_ctx *irqs; -}; - -int irq_sim_init(struct irq_sim *sim, unsigned int num_irqs); -int devm_irq_sim_init(struct device *dev, struct irq_sim *sim, - unsigned int num_irqs); -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); +struct irq_domain *irq_domain_create_sim(struct fwnode_handle *fwnode, + unsigned int num_irqs); +struct irq_domain *devm_irq_domain_create_sim(struct device *dev, + struct fwnode_handle *fwnode, + unsigned int num_irqs); +void irq_domain_remove_sim(struct irq_domain *domain); +void irq_sim_fire(int virq); #endif /* _LINUX_IRQ_SIM_H */ diff --git a/kernel/irq/Kconfig b/kernel/irq/Kconfig index f92d9a687372..d0890f7729d4 100644 --- a/kernel/irq/Kconfig +++ b/kernel/irq/Kconfig @@ -68,6 +68,7 @@ config IRQ_DOMAIN config IRQ_SIM bool select IRQ_WORK + select IRQ_DOMAIN # Support for hierarchical irq domains config IRQ_DOMAIN_HIERARCHY diff --git a/kernel/irq/irq_sim.c b/kernel/irq/irq_sim.c index b992f88c5613..575c1e3d32a9 100644 --- a/kernel/irq/irq_sim.c +++ b/kernel/irq/irq_sim.c @@ -1,14 +1,30 @@ // SPDX-License-Identifier: GPL-2.0+ /* * Copyright (C) 2017-2018 Bartosz Golaszewski + * Copyright (C) 2020 Bartosz Golaszewski */ -#include -#include #include +#include +#include +#include + +struct irq_sim_work_ctx { + struct irq_work work; + int irq_base; + unsigned int irq_count; + unsigned long *pending; + struct irq_domain *domain; +}; + +struct irq_sim_irq_ctx { + int irqnum; + bool enabled; + struct irq_sim_work_ctx *work_ctx; +}; struct irq_sim_devres { - struct irq_sim *sim; + struct irq_domain *domain; }; static void irq_sim_irqmask(struct irq_data *data) @@ -47,148 +63,179 @@ static void irq_sim_handle_irq(struct irq_work *work) { struct irq_sim_work_ctx *work_ctx; unsigned int offset = 0; - struct irq_sim *sim; int irqnum; work_ctx = container_of(work, struct irq_sim_work_ctx, work); - sim = container_of(work_ctx, struct irq_sim, work_ctx); - while (!bitmap_empty(work_ctx->pending, sim->irq_count)) { + while (!bitmap_empty(work_ctx->pending, work_ctx->irq_count)) { offset = find_next_bit(work_ctx->pending, - sim->irq_count, offset); + work_ctx->irq_count, offset); clear_bit(offset, work_ctx->pending); - irqnum = irq_sim_irqnum(sim, offset); + irqnum = irq_find_mapping(work_ctx->domain, offset); handle_simple_irq(irq_to_desc(irqnum)); } } +static int irq_sim_domain_map(struct irq_domain *domain, + unsigned int virq, irq_hw_number_t hw) +{ + struct irq_sim_work_ctx *work_ctx = domain->host_data; + struct irq_sim_irq_ctx *irq_ctx; + + irq_ctx = kzalloc(sizeof(*irq_ctx), GFP_KERNEL); + if (!irq_ctx) + return -ENOMEM; + + irq_set_chip(virq, &irq_sim_irqchip); + irq_set_chip_data(virq, irq_ctx); + irq_set_handler(virq, handle_simple_irq); + irq_modify_status(virq, IRQ_NOREQUEST | IRQ_NOAUTOEN, IRQ_NOPROBE); + irq_ctx->work_ctx = work_ctx; + + return 0; +} + +static void irq_sim_domain_unmap(struct irq_domain *domain, unsigned int virq) +{ + struct irq_sim_irq_ctx *irq_ctx; + struct irq_data *irqd; + + irqd = irq_domain_get_irq_data(domain, virq); + irq_ctx = irq_data_get_irq_chip_data(irqd); + + irq_set_handler(virq, NULL); + irq_domain_reset_irq_data(irqd); + kfree(irq_ctx); +} + +static const struct irq_domain_ops irq_sim_domain_ops = { + .map = irq_sim_domain_map, + .unmap = irq_sim_domain_unmap, +}; + /** - * irq_sim_init - Initialize the interrupt simulator: allocate a range of - * dummy interrupts. + * irq_domain_create_sim - Create a new interrupt simulator irq_domain and + * allocate a range of dummy interrupts. * - * @sim: The interrupt simulator object to initialize. - * @num_irqs: Number of interrupts to allocate + * @fnode: struct fwnode_handle to be associated with this domain. + * @num_irqs: Number of interrupts to allocate. * - * On success: return the base of the allocated interrupt range. - * On failure: a negative errno. + * On success: return a new irq_domain object. + * On failure: a negative errno wrapped with ERR_PTR(). */ -int irq_sim_init(struct irq_sim *sim, unsigned int num_irqs) +struct irq_domain *irq_domain_create_sim(struct fwnode_handle *fwnode, + unsigned int num_irqs) { - int i; + struct irq_sim_work_ctx *work_ctx; - sim->irqs = kmalloc_array(num_irqs, sizeof(*sim->irqs), GFP_KERNEL); - if (!sim->irqs) - return -ENOMEM; + work_ctx = kmalloc(sizeof(*work_ctx), GFP_KERNEL); + if (!work_ctx) + goto err_out; - sim->irq_base = irq_alloc_descs(-1, 0, num_irqs, 0); - if (sim->irq_base < 0) { - kfree(sim->irqs); - return sim->irq_base; - } + work_ctx->pending = bitmap_zalloc(num_irqs, GFP_KERNEL); + if (!work_ctx->pending) + goto err_free_work_ctx; - 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); - return -ENOMEM; - } + work_ctx->domain = irq_domain_create_linear(fwnode, num_irqs, + &irq_sim_domain_ops, + work_ctx); + if (!work_ctx->domain) + goto err_free_bitmap; - 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, &irq_sim_irqchip); - 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); - } + work_ctx->irq_count = num_irqs; + init_irq_work(&work_ctx->work, irq_sim_handle_irq); - init_irq_work(&sim->work_ctx.work, irq_sim_handle_irq); - sim->irq_count = num_irqs; + return work_ctx->domain; - return sim->irq_base; +err_free_bitmap: + bitmap_free(work_ctx->pending); +err_free_work_ctx: + kfree(work_ctx); +err_out: + return ERR_PTR(-ENOMEM); } -EXPORT_SYMBOL_GPL(irq_sim_init); +EXPORT_SYMBOL_GPL(irq_domain_create_sim); /** - * irq_sim_fini - Deinitialize the interrupt simulator: free the interrupt - * descriptors and allocated memory. + * irq_domain_remove_sim - Deinitialize the interrupt simulator domain: free + * the interrupt descriptors and allocated memory. * - * @sim: The interrupt simulator to tear down. + * @domain: The interrupt simulator domain to tear down. */ -void irq_sim_fini(struct irq_sim *sim) +void irq_domain_remove_sim(struct irq_domain *domain) { - 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); + struct irq_sim_work_ctx *work_ctx = domain->host_data; + + irq_work_sync(&work_ctx->work); + bitmap_free(work_ctx->pending); + kfree(work_ctx); + + irq_domain_remove(domain); } -EXPORT_SYMBOL_GPL(irq_sim_fini); +EXPORT_SYMBOL_GPL(irq_domain_remove_sim); -static void devm_irq_sim_release(struct device *dev, void *res) +static void devm_irq_domain_release_sim(struct device *dev, void *res) { struct irq_sim_devres *this = res; - irq_sim_fini(this->sim); + irq_domain_remove_sim(this->domain); } /** - * irq_sim_init - Initialize the interrupt simulator for a managed device. + * devm_irq_domain_create_sim - Create a new interrupt simulator for + * a managed device. * * @dev: Device to initialize the simulator object for. - * @sim: The interrupt simulator object to initialize. + * @fnode: struct fwnode_handle to be associated with this domain. * @num_irqs: Number of interrupts to allocate * - * On success: return the base of the allocated interrupt range. - * On failure: a negative errno. + * On success: return a new irq_domain object. + * On failure: a negative errno wrapped with ERR_PTR(). */ -int devm_irq_sim_init(struct device *dev, struct irq_sim *sim, - unsigned int num_irqs) +struct irq_domain *devm_irq_domain_create_sim(struct device *dev, + struct fwnode_handle *fwnode, + unsigned int num_irqs) { struct irq_sim_devres *dr; - int rv; - dr = devres_alloc(devm_irq_sim_release, sizeof(*dr), GFP_KERNEL); + dr = devres_alloc(devm_irq_domain_release_sim, + sizeof(*dr), GFP_KERNEL); if (!dr) - return -ENOMEM; + return ERR_PTR(-ENOMEM); - rv = irq_sim_init(sim, num_irqs); - if (rv < 0) { + dr->domain = irq_domain_create_sim(fwnode, num_irqs); + if (IS_ERR(dr->domain)) { devres_free(dr); - return rv; + return dr->domain; } - dr->sim = sim; devres_add(dev, dr); - - return rv; + return dr->domain; } -EXPORT_SYMBOL_GPL(devm_irq_sim_init); +EXPORT_SYMBOL_GPL(devm_irq_domain_create_sim); /** * irq_sim_fire - Enqueue an interrupt. * - * @sim: The interrupt simulator object. - * @offset: Offset of the simulated interrupt which should be fired. + * @virq: Virtual interrupt number to fire. It must be associated with + * an existing interrupt simulator. */ -void irq_sim_fire(struct irq_sim *sim, unsigned int offset) +void irq_sim_fire(int virq) { - if (sim->irqs[offset].enabled) { - set_bit(offset, sim->work_ctx.pending); - irq_work_queue(&sim->work_ctx.work); + struct irq_sim_irq_ctx *irq_ctx; + struct irq_data *irqd; + + irqd = irq_get_irq_data(virq); + if (!irqd) { + pr_warn_ratelimited("%s: invalid irq number\n", __func__); + return; } -} -EXPORT_SYMBOL_GPL(irq_sim_fire); -/** - * irq_sim_irqnum - Get the allocated number of a dummy interrupt. - * - * @sim: The interrupt simulator object. - * @offset: Offset of the simulated interrupt for which to retrieve - * the number. - */ -int irq_sim_irqnum(struct irq_sim *sim, unsigned int offset) -{ - return sim->irqs[offset].irqnum; + irq_ctx = irq_data_get_irq_chip_data(irqd); + + if (irq_ctx->enabled) { + set_bit(irqd_to_hwirq(irqd), irq_ctx->work_ctx->pending); + irq_work_queue(&irq_ctx->work_ctx->work); + } } -EXPORT_SYMBOL_GPL(irq_sim_irqnum); +EXPORT_SYMBOL_GPL(irq_sim_fire); From patchwork Tue Feb 11 13:12:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 11375445 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 16E20921 for ; Tue, 11 Feb 2020 13:13:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EA93920870 for ; Tue, 11 Feb 2020 13:13:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="vCbyLf9V" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729064AbgBKNNF (ORCPT ); Tue, 11 Feb 2020 08:13:05 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:35188 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728353AbgBKNNE (ORCPT ); Tue, 11 Feb 2020 08:13:04 -0500 Received: by mail-wm1-f67.google.com with SMTP id b17so3537635wmb.0 for ; Tue, 11 Feb 2020 05:13:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uc8xQCON5zDwR8DUMLyo3MIMMq2WPuIE9JxQ1gURZh8=; b=vCbyLf9VWyEXfKLjEe55OgreiTorLdlet6cpkzjqgxySZKumn1sFYmLj9u46YTXTM5 C10ATKL3noqzpXBqonK2a+V9tZW/B9DutE0bifDGmfEuCjj1if8zk8Kb3FYLWn8i2+8S axXX7eVfj6It1jztvxpRbJcPSiQxzO8IYhd2jgp043VGQ70nNKiKsPRtxU/AzHsHMBv4 0kGjGCHa5+3Sf1gp8X7kgGs+c+ZX4bQK6eZF2Sd+iDxOGvGRvYgqjUYMavUPd8JVgGvj eqf6oEJG9Ue3SUD47SWPTe5gtdpHt5ks/m0E8+GGajVB4UtLuPPxbHFGAvp6H9xtHr/Q PWeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uc8xQCON5zDwR8DUMLyo3MIMMq2WPuIE9JxQ1gURZh8=; b=ir+wUk6LtldqEGa0k5CPwizmlyQheeO/YKOpGYZK64ZgB1a5z/duS1R40u0m1pmvHc 0x5To0pawcjzWM/QFr72fBn5ts3/86At1PLzplcF/QS8fHnk3uRReFozRGyWSxtBxRVY 79U1a9sYwMWF3pe2YVpzRNAA6+i7kXAtqWZWw++72+xWT9+NbIAE8DxDY8anu52FvECo Zy5d60yAP02TKBKes4EuWliTBB26jhwSK+7mr/opajKtg21fCVrRA94l5qPU8IC7YN/a 0KzizOdJSeuuWSwZ9XaLV71JcA/rjfYYYe4XhcLp3WDf3bKNtMAAZnDUsQrAJBXCwOrc yNlw== X-Gm-Message-State: APjAAAXEXKYpSMZeRqzifRZui1t2Zde9psJ8kw3F3+BSEx1UHTJ9ClmP Td1ccpDzWgRfv1AUxpyzxLSs5w== X-Google-Smtp-Source: APXvYqxzfbcatJyy+RYI1cefcr1daJmFQcMYqV3T4tUbL6cK8/4aHjxYt4gy3CW5BTPxHR6EPF93Og== X-Received: by 2002:a7b:c147:: with SMTP id z7mr5567366wmi.168.1581426782790; Tue, 11 Feb 2020 05:13:02 -0800 (PST) Received: from localhost.localdomain (lfbn-nic-1-65-232.w2-15.abo.wanadoo.fr. [2.15.156.232]) by smtp.gmail.com with ESMTPSA id b21sm3873013wmd.37.2020.02.11.05.13.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Feb 2020 05:13:01 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Thomas Gleixner , Jason Cooper , Marc Zyngier Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 3/6] irq/domain: add a new callback to domain ops Date: Tue, 11 Feb 2020 14:12:37 +0100 Message-Id: <20200211131240.15853-4-brgl@bgdev.pl> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200211131240.15853-1-brgl@bgdev.pl> References: <20200211131240.15853-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Bartosz Golaszewski Add the remove() callback to irq_domain_ops which can be used to automatically dispose of any host data associated with the domain when irq_domain_remove() is called. Signed-off-by: Bartosz Golaszewski --- include/linux/irqdomain.h | 3 +++ kernel/irq/irqdomain.c | 3 +++ 2 files changed, 6 insertions(+) diff --git a/include/linux/irqdomain.h b/include/linux/irqdomain.h index 20d38621e2f8..fbc25f464f62 100644 --- a/include/linux/irqdomain.h +++ b/include/linux/irqdomain.h @@ -95,6 +95,8 @@ enum irq_domain_bus_token { * @unmap: Dispose of such a mapping * @xlate: Given a device tree node and interrupt specifier, decode * the hardware irq number and linux irq type value. + * @remove: Free any custom resources associated with this domain. This is + * called from irq_domain_remove() before any other code. * * Functions below are provided by the driver and called whenever a new mapping * is created or an old mapping is disposed. The driver can then proceed to @@ -126,6 +128,7 @@ struct irq_domain_ops { void (*debug_show)(struct seq_file *m, struct irq_domain *d, struct irq_data *irqd, int ind); #endif + void (*remove)(struct irq_domain *d); }; extern struct irq_domain_ops irq_generic_chip_ops; diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c index 039427c98af8..b391d2e65bdd 100644 --- a/kernel/irq/irqdomain.c +++ b/kernel/irq/irqdomain.c @@ -242,6 +242,9 @@ EXPORT_SYMBOL_GPL(__irq_domain_add); */ void irq_domain_remove(struct irq_domain *domain) { + if (domain->ops->remove) + domain->ops->remove(domain); + mutex_lock(&irq_domain_mutex); debugfs_remove_domain_dir(domain); From patchwork Tue Feb 11 13:12:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 11375443 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2D6FF921 for ; Tue, 11 Feb 2020 13:13:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0BC6220848 for ; Tue, 11 Feb 2020 13:13:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="1jvVusFz" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729073AbgBKNNG (ORCPT ); Tue, 11 Feb 2020 08:13:06 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:51300 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729032AbgBKNNF (ORCPT ); Tue, 11 Feb 2020 08:13:05 -0500 Received: by mail-wm1-f68.google.com with SMTP id t23so3488246wmi.1 for ; Tue, 11 Feb 2020 05:13:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=f+82O1OuBB3itFL0o65sBPeQjxKbsseoBh5Dt/Kun5Y=; b=1jvVusFzmlhzxZfNTJYcIcWAhYOXsvC8wyNQkaeYZ5qJyntOxfoWQgnmgOXW6jchYp Iu02eDVYR6McIUfUL/VvFFm0qrea5OtXU2TrWDUC627cE+5bkdrK64ofCM/jOnYhQRWb c44LrAvxURzTDxJYWAe1B4TztYkJxXOgxPMA0Z5+tRseJu0hF6zckMivlEPCqIIUWedp ztA1RAOwZ86g50jC5ePdx1lesa/MPL2wdo4qGVDBfFpbUu1sCFqt8+OFsYMlkLoTMV/t R1czk5ccNrwYP0oixc766Su6GZMmsCdZ3Cir8rx47YZ/LzVmn5wRrLqEze0l3sfRm2lF ymWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=f+82O1OuBB3itFL0o65sBPeQjxKbsseoBh5Dt/Kun5Y=; b=ZEusGAPqNcu1Dv5GtdvTSSJdh5gcNZsNheIRQBfmHP3vLGpLcsyXv1i5gPP59QV9pL WX1rjEYgpJ1aRvANY5Lc2xj1pUIxjo4RpqXIHzudSgpZ7s60CP5xGueLMJQCWMZfbP7w 9IX8jpiQ6c80AXc0Ci5qJJ5n+moNEsYHEY5e0NE9SnUJzvYAiqwCUJ6cAdrUcY65JwZi P6Cd+pby0IC9YV8AfwWA3nXZMMsQut40t3FDIG+zI1LUXkG3c4byn1k8KhAfkwUQLKo/ xFv0cZ12bdYXVfNH8qs82tk+qXli33M3qY/Mob8HsChyxxQlveyPw/ZiHmzTdsNegb7Z xAmQ== X-Gm-Message-State: APjAAAW86f7noS2GgCjrWlfuXtBapvMYBlbpGZfVP29LT8oDScaX/rti h/OU0hF0aKI31XLwHPyGMqXu8A== X-Google-Smtp-Source: APXvYqzljNsEnWt6VAXASHyN5ZUk1Glg/tkFgMB+ilT6DVfsMIc5l3auu39ziddsgEQzSNQdJY1mqw== X-Received: by 2002:a7b:c4c5:: with SMTP id g5mr5768157wmk.85.1581426783999; Tue, 11 Feb 2020 05:13:03 -0800 (PST) Received: from localhost.localdomain (lfbn-nic-1-65-232.w2-15.abo.wanadoo.fr. [2.15.156.232]) by smtp.gmail.com with ESMTPSA id b21sm3873013wmd.37.2020.02.11.05.13.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Feb 2020 05:13:03 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Thomas Gleixner , Jason Cooper , Marc Zyngier Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 4/6] irq/irq_sim: remove irq_domain_remove_sim() Date: Tue, 11 Feb 2020 14:12:38 +0100 Message-Id: <20200211131240.15853-5-brgl@bgdev.pl> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200211131240.15853-1-brgl@bgdev.pl> References: <20200211131240.15853-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Bartosz Golaszewski Use the new remove() callback in irq_domain_ops to dispose of any private data associated with the sim domain. This allows us to drop the dedicated irq_domain_remove_sim() function and instead just use the regular irq_domain_remove(). Signed-off-by: Bartosz Golaszewski --- drivers/iio/dummy/iio_dummy_evgen.c | 2 +- include/linux/irq_sim.h | 1 - kernel/irq/irq_sim.c | 32 ++++++++++++----------------- 3 files changed, 14 insertions(+), 21 deletions(-) diff --git a/drivers/iio/dummy/iio_dummy_evgen.c b/drivers/iio/dummy/iio_dummy_evgen.c index 31c9e012abeb..47620bdae845 100644 --- a/drivers/iio/dummy/iio_dummy_evgen.c +++ b/drivers/iio/dummy/iio_dummy_evgen.c @@ -118,7 +118,7 @@ EXPORT_SYMBOL_GPL(iio_dummy_evgen_get_regs); static void iio_dummy_evgen_free(void) { - irq_domain_remove_sim(iio_evgen->irq_sim_domain); + irq_domain_remove(iio_evgen->irq_sim_domain); kfree(iio_evgen); } diff --git a/include/linux/irq_sim.h b/include/linux/irq_sim.h index 26bf6164dcc7..90e910fa2f91 100644 --- a/include/linux/irq_sim.h +++ b/include/linux/irq_sim.h @@ -21,7 +21,6 @@ struct irq_domain *irq_domain_create_sim(struct fwnode_handle *fwnode, struct irq_domain *devm_irq_domain_create_sim(struct device *dev, struct fwnode_handle *fwnode, unsigned int num_irqs); -void irq_domain_remove_sim(struct irq_domain *domain); void irq_sim_fire(int virq); #endif /* _LINUX_IRQ_SIM_H */ diff --git a/kernel/irq/irq_sim.c b/kernel/irq/irq_sim.c index 575c1e3d32a9..a4400aed5fb2 100644 --- a/kernel/irq/irq_sim.c +++ b/kernel/irq/irq_sim.c @@ -108,9 +108,19 @@ static void irq_sim_domain_unmap(struct irq_domain *domain, unsigned int virq) kfree(irq_ctx); } +static void irq_sim_domain_remove(struct irq_domain *domain) +{ + struct irq_sim_work_ctx *work_ctx = domain->host_data; + + irq_work_sync(&work_ctx->work); + bitmap_free(work_ctx->pending); + kfree(work_ctx); +} + static const struct irq_domain_ops irq_sim_domain_ops = { .map = irq_sim_domain_map, .unmap = irq_sim_domain_unmap, + .remove = irq_sim_domain_remove, }; /** @@ -122,6 +132,8 @@ static const struct irq_domain_ops irq_sim_domain_ops = { * * On success: return a new irq_domain object. * On failure: a negative errno wrapped with ERR_PTR(). + * + * The returned domain can be freed using irq_domain_remove(). */ struct irq_domain *irq_domain_create_sim(struct fwnode_handle *fwnode, unsigned int num_irqs) @@ -156,29 +168,11 @@ struct irq_domain *irq_domain_create_sim(struct fwnode_handle *fwnode, } EXPORT_SYMBOL_GPL(irq_domain_create_sim); -/** - * irq_domain_remove_sim - Deinitialize the interrupt simulator domain: free - * the interrupt descriptors and allocated memory. - * - * @domain: The interrupt simulator domain to tear down. - */ -void irq_domain_remove_sim(struct irq_domain *domain) -{ - struct irq_sim_work_ctx *work_ctx = domain->host_data; - - irq_work_sync(&work_ctx->work); - bitmap_free(work_ctx->pending); - kfree(work_ctx); - - irq_domain_remove(domain); -} -EXPORT_SYMBOL_GPL(irq_domain_remove_sim); - static void devm_irq_domain_release_sim(struct device *dev, void *res) { struct irq_sim_devres *this = res; - irq_domain_remove_sim(this->domain); + irq_domain_remove(this->domain); } /** From patchwork Tue Feb 11 13:12:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 11375439 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A475C921 for ; Tue, 11 Feb 2020 13:13:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 820CF20848 for ; Tue, 11 Feb 2020 13:13:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="LcrMHtCU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729072AbgBKNNJ (ORCPT ); Tue, 11 Feb 2020 08:13:09 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:35292 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729065AbgBKNNG (ORCPT ); Tue, 11 Feb 2020 08:13:06 -0500 Received: by mail-wr1-f68.google.com with SMTP id w12so12344426wrt.2 for ; Tue, 11 Feb 2020 05:13:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=anPiy+Oai5eVC9epbsqPoMEWmUp50/yoIqvuC47WE5o=; b=LcrMHtCUppxeolsKFGx6QsBeDzCgd+5f8d/Oq/d8bQLTe2OeansixpI49rk7VTtwHO TAadngLfrWrhX/Za4qdIf48h7osfj+UtUjkYt8J+GCrXmU3esu+ojHKWvQPt39Cw0EmU 8iwhyTdDSKEuJwjPVx2LSG1K+4AZ2eHca+Pt/hpgb3HSE0TJRzk7+/6vxp+A9MQcK2g5 WxLqITqfiEcblyk3kcL8wB0WDcrtnF8YEuApH4lNvz2SbbUmBdKrW2BpMVkOXQPlDMzc mPmY3MEo4I7MsTQ6a5JLe7mIygDcVOKtUqN9hKS/JM0sKW02t0qiGKxQ/L81g4zm1bkC blQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=anPiy+Oai5eVC9epbsqPoMEWmUp50/yoIqvuC47WE5o=; b=uQG1Xjsi111OCX7pGoTorbZm2AuW/GTGfkmTNWEiZI8RJL4kX50fg4A0PbNLFKT+yz xbO3YiTWnPyNUAPse15ks/+qJMdym8nJHKTP9fBWYDLeMwMdGAT9CRmZwPkJIvdI7ObO /oj6pd2E/eHk1pn+7QSY5XqtHEw8VWJpcaUbDLK1ID43bYfbE2JnZcH5a1r6tYr+lfK4 mCBc/NYFWWngMgbiE6Y/x1KlI1u6VN26UDiKtqR/P49z6QTPnb+WGcfhYdNmnj8Xd37Y uwMnVom7W1Y+Ul9J9VKitxHAupNgw66v4UFDTNxnZfmjORuIGVcIoGZ03Zi0VTzBo/Wx fVyQ== X-Gm-Message-State: APjAAAWvRBotRhWRZwxJCHF1TJO+IOzYM/oFR7L/EX3V5PxVv3vYBJma 3pWm0pVOF/Iq+iPAaBi5FwhSUL3fsBE= X-Google-Smtp-Source: APXvYqzzhUz5QJgJfU2ox7SdgabZbIVUaJl7QIQdgt8cnPmLLHB161BbLwhKlnx0AUyBK9UVc6nz1A== X-Received: by 2002:a5d:51c9:: with SMTP id n9mr8771950wrv.334.1581426785134; Tue, 11 Feb 2020 05:13:05 -0800 (PST) Received: from localhost.localdomain (lfbn-nic-1-65-232.w2-15.abo.wanadoo.fr. [2.15.156.232]) by smtp.gmail.com with ESMTPSA id b21sm3873013wmd.37.2020.02.11.05.13.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Feb 2020 05:13:04 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Thomas Gleixner , Jason Cooper , Marc Zyngier Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 5/6] irq/domain: provide irq_domain_dispose_mappings() helper Date: Tue, 11 Feb 2020 14:12:39 +0100 Message-Id: <20200211131240.15853-6-brgl@bgdev.pl> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200211131240.15853-1-brgl@bgdev.pl> References: <20200211131240.15853-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Bartosz Golaszewski Unmapping all interrupts before removing an irq_domain is a common use-case. Provide an appropriate helper that can also be used with the remove() callback in irq_domain ops. Signed-off-by: Bartosz Golaszewski --- include/linux/irqdomain.h | 2 ++ kernel/irq/irqdomain.c | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/include/linux/irqdomain.h b/include/linux/irqdomain.h index fbc25f464f62..8fd27614dafd 100644 --- a/include/linux/irqdomain.h +++ b/include/linux/irqdomain.h @@ -390,6 +390,7 @@ extern unsigned int irq_create_mapping(struct irq_domain *host, irq_hw_number_t hwirq); extern unsigned int irq_create_fwspec_mapping(struct irq_fwspec *fwspec); extern void irq_dispose_mapping(unsigned int virq); +extern void irq_domain_dispose_mappings(struct irq_domain *domain); /** * irq_linear_revmap() - Find a linux irq from a hw irq number. @@ -594,6 +595,7 @@ irq_domain_hierarchical_is_msi_remap(struct irq_domain *domain) #else /* CONFIG_IRQ_DOMAIN */ static inline void irq_dispose_mapping(unsigned int virq) { } +static inline void irq_domain_dispose_mappings(struct irq_domain *domain) { } static inline struct irq_domain *irq_find_matching_fwnode( struct fwnode_handle *fwnode, enum irq_domain_bus_token bus_token) { diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c index b391d2e65bdd..d09de9f2411a 100644 --- a/kernel/irq/irqdomain.c +++ b/kernel/irq/irqdomain.c @@ -888,6 +888,23 @@ void irq_dispose_mapping(unsigned int virq) } EXPORT_SYMBOL_GPL(irq_dispose_mapping); +/** + * irq_domain_dispose_mappings() - Unmap all interrupts + * @domain: domain for which to unmap all interrupts + */ +void irq_domain_dispose_mappings(struct irq_domain *domain) +{ + unsigned int virq; + int i; + + for (i = 0; i < domain->hwirq_max; i++) { + virq = irq_find_mapping(domain, i); + if (virq) + irq_dispose_mapping(virq); + } +} +EXPORT_SYMBOL_GPL(irq_domain_dispose_mappings); + /** * irq_find_mapping() - Find a linux irq from a hw irq number. * @domain: domain owning this hardware interrupt From patchwork Tue Feb 11 13:12:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 11375441 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 42DC61820 for ; Tue, 11 Feb 2020 13:13:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2285D20848 for ; Tue, 11 Feb 2020 13:13:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="YMVL4Uut" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729083AbgBKNNT (ORCPT ); Tue, 11 Feb 2020 08:13:19 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:44713 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729087AbgBKNNJ (ORCPT ); Tue, 11 Feb 2020 08:13:09 -0500 Received: by mail-wr1-f66.google.com with SMTP id m16so12281771wrx.11 for ; Tue, 11 Feb 2020 05:13:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1vPmpeWQjbELhAAh7qUDhl/FE61ojZhZ+nedC+mmNBA=; b=YMVL4UutOUUUBwxTLjas1GuxZpiRAyZ1QAJDqZuCsiixVQ0HwJ8iqYUKqX4By5wK1O xh5q5/mIudN6g8VmBHS+ZVag+52200shz8xC+qEl5LTCcxOS9snJLRjuDHpc6Uq/8VMD /6BZpEia3GazsYMJfmihNFHq7HA0BMFugaXVwo6qJag3ClvXZPuzjUW8pACj2AN6HJCY EDpVS9GLXJtxdNC9SmGGn9C7fNvv2wno61s8xPnkugdealVsXLRUmJxHRks0PlH6hyGb s73Uvf0fZhev9/ZOwoT21KBAA23sMroSApT3hyDQqvHJKDqVrtogp75kjFOM4er1dKUX /l8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1vPmpeWQjbELhAAh7qUDhl/FE61ojZhZ+nedC+mmNBA=; b=YVVcGawyrdLD3Q3OG9+t/NDM12UjtPWxAWuK+/+Rc51GsY9hEQAb/EjunKN2QiJ9YN b9VlPBj9NrAanXiqQhe6GPlyBlArIU4BoVKthjTS5+uxl2ppu0FVGzo8Kv4RA7F5ADvQ S9fw6sRZEkXq4wDV/dCDRJHAbUCT1kO8L1dzJmf1XZyuOupzz36Xewic5v9KFdbkzypu A6SgEMzjasAT07UMtrs4v8g0Qco5GtIH5NHEJRd4Zky4DwlJ9LAitydhWWbhFliL5cWI oNcVv/nIdBXEiKhL+ECkLf1GCIDexUTlijGyYP7MzG7mKS397U3K4uUWtQyXrb/h6HeT dODg== X-Gm-Message-State: APjAAAX5Ket3DUFHS1VRl81YmNtYWHxA0csn5Fykvcf78KLZL3juFPHb 2PD75rqByuN7aXWBkPTMoIyP9g== X-Google-Smtp-Source: APXvYqwsqGPsgxct0EcwFH2nXNkyOmhcAIVbam2T5OBf09TafGb/SaZA0NIR5OfaTljHguvsgfn4aA== X-Received: by 2002:a5d:4d12:: with SMTP id z18mr8658792wrt.139.1581426786597; Tue, 11 Feb 2020 05:13:06 -0800 (PST) Received: from localhost.localdomain (lfbn-nic-1-65-232.w2-15.abo.wanadoo.fr. [2.15.156.232]) by smtp.gmail.com with ESMTPSA id b21sm3873013wmd.37.2020.02.11.05.13.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Feb 2020 05:13:06 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Thomas Gleixner , Jason Cooper , Marc Zyngier Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 6/6] irqchip: keystone: use irq_domain_dispose_mappings() Date: Tue, 11 Feb 2020 14:12:40 +0100 Message-Id: <20200211131240.15853-7-brgl@bgdev.pl> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200211131240.15853-1-brgl@bgdev.pl> References: <20200211131240.15853-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org From: Bartosz Golaszewski Shrink the code a bit by using the new irq_domain_dispose_mappings() helper. Signed-off-by: Bartosz Golaszewski --- drivers/irqchip/irq-keystone.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/irqchip/irq-keystone.c b/drivers/irqchip/irq-keystone.c index 8118ebe80b09..57819d1c3c32 100644 --- a/drivers/irqchip/irq-keystone.c +++ b/drivers/irqchip/irq-keystone.c @@ -135,6 +135,7 @@ static int keystone_irq_map(struct irq_domain *h, unsigned int virq, static const struct irq_domain_ops keystone_irq_ops = { .map = keystone_irq_map, .xlate = irq_domain_xlate_onecell, + .remove = irq_domain_dispose_mappings, }; static int keystone_irq_probe(struct platform_device *pdev) @@ -203,13 +204,9 @@ static int keystone_irq_probe(struct platform_device *pdev) static int keystone_irq_remove(struct platform_device *pdev) { struct keystone_irq_device *kirq = platform_get_drvdata(pdev); - int hwirq; free_irq(kirq->irq, kirq); - for (hwirq = 0; hwirq < KEYSTONE_N_IRQ; hwirq++) - irq_dispose_mapping(irq_find_mapping(kirq->irqd, hwirq)); - irq_domain_remove(kirq->irqd); return 0; }