From patchwork Wed Jun 12 11:52:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 804333 Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3DE07381D4 for ; Wed, 12 Jun 2024 11:53:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718193187; cv=none; b=sBvY6drgHkQ2rcjWzHnayABV7WJCOMTrBV7ZoPIgEmjxtL0fIo0wke8HevyJ2aAwXDfgwxJUssUk8UFqu5qN//BoMCYOMAqc9J0R30/qkj+3GtaFJ1MkpGFYMBZJ90K53Cnp3mTt8es5xfKw6vrMD5j0ydojOf5++Xqreu1PMGE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718193187; c=relaxed/simple; bh=gIxc5R2yJd9VUifO8gyW7fV3jyzLCecrCt5fl7cMhQM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JRXj5N0naOHjOy84MAZgB+8UUxARsjou++Skn/EQBj1RC71pXCjYJOX0J9/OB973GQL+p1Uk8ntciz1Bkar9R3XaNNsKtI91L3xMgLDoCg89kE5DkEGIUp91SHUjk4KWa1nLtS4QDXxlxM2twWehgZMETI3dnMYFXUJbnItyeE8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=vlnvGd4I; arc=none smtp.client-ip=209.85.167.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="vlnvGd4I" Received: by mail-lf1-f41.google.com with SMTP id 2adb3069b0e04-52bc3130ae6so5236145e87.3 for ; Wed, 12 Jun 2024 04:53:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1718193182; x=1718797982; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RMaVrXTNSn8/RlgcBidtA4XNwAtbmdRI1NY6kSKH78g=; b=vlnvGd4I9XwvwxIOYIOYmsD7QKkJ5KN8WsIpjHtV3WKatrYDHnkawEZtPh8p6ZNjWe wmM2YaX57fsXHk3qTqKjwQnLm5TwdRAPBrnCtAjmhLMoDq+nk3yewV4uSbLPCcpLfu3o l4P77jJG/tJqUFPS+OWjYpOCw8klnROq0c2XH67fTyQtWQiXwEXSysfnDUrEgfFxEiDo v1C1G+qixJuIj5kCamYwPUbM7xifgqSttaqwjxKxTQQOa/8ocSL+7e/8aRez7VaA/Xyt BD4869csava4myns3G8A/31wn81jfjKlqcuu5E8TuO/D36AbhNCgD8yy7Sqx/7OuNZye 7qiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718193182; x=1718797982; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RMaVrXTNSn8/RlgcBidtA4XNwAtbmdRI1NY6kSKH78g=; b=MRk536V0/J/OuvUiEo9YAHI/g+XYpD0yEsCo+XgYyaV33AnNBJCNkX5YOpHxcUHmEB hu0t5piFPgvQFMdV//W7wQzyx6txCcUJxlNYMA2rPC4JrRVgLt+FOAm/gJuoZ+E+Clgc XAyzVE0Tv7wtOZxdkklFskdrCWfkAI7oBZ68aorMUy589yxw3Qz88ZcFtUnmsHBBpcII 8PGe5JaCtBhjB69jd/iN8A9B/eYMO2qsM3X5SvgzfJ7J5ANI0bnoOEPdw+HKbpeL3oyT ZOht1kn5H790Uf0P5cr3BZoKpOUV/vEN7Ah/JkChkC8YkVpLg+0yayCq/RhwPAiTvtlz s3Rg== X-Gm-Message-State: AOJu0YxhzoDYZppNZHCYDwibZxrjo0TzBovAFVs7BaH6xms25MP261SN mlx4fDAcRq9+AU/qpozaGHb7pXnQZVHpxrwAnv8fv6N7psVh9HJDcFF1hv+VvwQw/NphWmQWuUb s X-Google-Smtp-Source: AGHT+IHYYStDCJ+efOYUfRfVc0U8uY+8W/Gy+dCA6wjCUkJXARiUSADe+wTLCY9FVnjiFVraHnRknw== X-Received: by 2002:ac2:46f6:0:b0:52c:84a2:6e0f with SMTP id 2adb3069b0e04-52c9a3c768fmr857602e87.15.1718193182228; Wed, 12 Jun 2024 04:53:02 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:8d3:3800:a172:4e8b:453e:2f03]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-35f1c958f9fsm10457352f8f.38.2024.06.12.04.53.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 04:53:01 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Thomas Gleixner Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 1/2] genirq/irq_sim: add a notifier for irqchip events Date: Wed, 12 Jun 2024 13:52:25 +0200 Message-ID: <20240612115231.26703-2-brgl@bgdev.pl> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240612115231.26703-1-brgl@bgdev.pl> References: <20240612115231.26703-1-brgl@bgdev.pl> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Bartosz Golaszewski Currently users of the interrupt simulator don't have any way of being notified about interrupts from the simulated domain being requested or released. This causes a problem for one of the users - the GPIO simulator - which is unable to lock the pins as interrupts. Add a blocking notifier and provide interfaces to register with it, then use it to notify users of the domain about interrupts being requested and released while also leaving space for future extensions. Signed-off-by: Bartosz Golaszewski --- include/linux/irq_sim.h | 11 +++++++ kernel/irq/irq_sim.c | 64 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/include/linux/irq_sim.h b/include/linux/irq_sim.h index ab831e5ae748..462d1913bb27 100644 --- a/include/linux/irq_sim.h +++ b/include/linux/irq_sim.h @@ -10,6 +10,7 @@ #include #include #include +#include /* * Provides a framework for allocating simulated interrupts which can be @@ -23,4 +24,14 @@ struct irq_domain *devm_irq_domain_create_sim(struct device *dev, unsigned int num_irqs); void irq_domain_remove_sim(struct irq_domain *domain); +enum { + IRQ_SIM_DOMAIN_IRQ_REQUESTED = 1, + IRQ_SIM_DOMAIN_IRQ_RELEASED, +}; + +int irq_sim_domain_register_notifier(struct irq_domain *domain, + struct notifier_block *nb); +int irq_sim_domain_unregister_notifier(struct irq_domain *domain, + struct notifier_block *nb); + #endif /* _LINUX_IRQ_SIM_H */ diff --git a/kernel/irq/irq_sim.c b/kernel/irq/irq_sim.c index 38d6ae651ac7..653b6ca869cb 100644 --- a/kernel/irq/irq_sim.c +++ b/kernel/irq/irq_sim.c @@ -17,6 +17,7 @@ struct irq_sim_work_ctx { unsigned int irq_count; unsigned long *pending; struct irq_domain *domain; + struct blocking_notifier_head notifier; }; struct irq_sim_irq_ctx { @@ -88,6 +89,28 @@ static int irq_sim_set_irqchip_state(struct irq_data *data, return 0; } +static int irq_sim_request_resources(struct irq_data *data) +{ + struct irq_sim_irq_ctx *irq_ctx = irq_data_get_irq_chip_data(data); + struct irq_sim_work_ctx *work_ctx = irq_ctx->work_ctx; + irq_hw_number_t hwirq = irqd_to_hwirq(data); + + blocking_notifier_call_chain(&work_ctx->notifier, + IRQ_SIM_DOMAIN_IRQ_REQUESTED, &hwirq); + + return 0; +} + +static void irq_sim_release_resources(struct irq_data *data) +{ + struct irq_sim_irq_ctx *irq_ctx = irq_data_get_irq_chip_data(data); + struct irq_sim_work_ctx *work_ctx = irq_ctx->work_ctx; + irq_hw_number_t hwirq = irqd_to_hwirq(data); + + blocking_notifier_call_chain(&work_ctx->notifier, + IRQ_SIM_DOMAIN_IRQ_RELEASED, &hwirq); +} + static struct irq_chip irq_sim_irqchip = { .name = "irq_sim", .irq_mask = irq_sim_irqmask, @@ -95,6 +118,8 @@ static struct irq_chip irq_sim_irqchip = { .irq_set_type = irq_sim_set_type, .irq_get_irqchip_state = irq_sim_get_irqchip_state, .irq_set_irqchip_state = irq_sim_set_irqchip_state, + .irq_request_resources = irq_sim_request_resources, + .irq_release_resources = irq_sim_release_resources, }; static void irq_sim_handle_irq(struct irq_work *work) @@ -183,6 +208,7 @@ struct irq_domain *irq_domain_create_sim(struct fwnode_handle *fwnode, work_ctx->irq_count = num_irqs; work_ctx->work = IRQ_WORK_INIT_HARD(irq_sim_handle_irq); work_ctx->pending = no_free_ptr(pending); + BLOCKING_INIT_NOTIFIER_HEAD(&work_ctx->notifier); return no_free_ptr(work_ctx)->domain; } @@ -242,3 +268,41 @@ struct irq_domain *devm_irq_domain_create_sim(struct device *dev, return domain; } EXPORT_SYMBOL_GPL(devm_irq_domain_create_sim); + +/** + * irq_sim_domain_register_notifier - Start listening for events on this + * interrupt simulator. + * + * @domain: The interrupt simulator domain to register with. + * @nb: Notifier block called on domain events. + * + * On success: return 0. + * On failure: return negative error code. + */ +int irq_sim_domain_register_notifier(struct irq_domain *domain, + struct notifier_block *nb) +{ + struct irq_sim_work_ctx *work_ctx = domain->host_data; + + return blocking_notifier_chain_register(&work_ctx->notifier, nb); +} +EXPORT_SYMBOL_GPL(irq_sim_domain_register_notifier); + +/** + * irq_sim_domain_unregister_notifier - Stop listening for events on this + * interrupt simulator. + * + * @domain: The interrupt simulator domain to register with. + * @nb: Notifier block called on domain events. + * + * On success: return 0. + * On failure: return negative error code. + */ +int irq_sim_domain_unregister_notifier(struct irq_domain *domain, + struct notifier_block *nb) +{ + struct irq_sim_work_ctx *work_ctx = domain->host_data; + + return blocking_notifier_chain_unregister(&work_ctx->notifier, nb); +} +EXPORT_SYMBOL_GPL(irq_sim_domain_unregister_notifier); From patchwork Wed Jun 12 11:52:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 803676 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AAD7B16F0EA for ; Wed, 12 Jun 2024 11:53:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718193186; cv=none; b=IDxRM6T48oPGw4wxntI+JuuL9BDNS/yPjNowyY5RPnhkqsNVhu3w52NmLRq1rTfmxzvq2uyT9AAb+yRPAKeLX1esV7KxxbBkQ1hbLdb8mO8mcsLKKJhs0cJPieKqXOL/kc34lr0MaTic7GCakcKBHtvQ79fJpGmkSq3/MAABUTY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718193186; c=relaxed/simple; bh=JDQkMWjIUvqE84ikntSBnxeL6cRw7OvNB40R51BdsFM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=irr3pNbdt9A5AfAfGZbv4pWy2R7QGFUbQ3w+JA3fowXIXcq06UZdVsShcBaP9lokIxD4EQ5CWii/v0FKnQBEjyNHRQFQsCqM1g0X6dJic9L9GoQSSTvJtscfp8byu7eeyOJsU1v/poTyjfGqil2vfWgg1PveCpvcjDLXWOx/BVs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=o5ZwoQR0; arc=none smtp.client-ip=209.85.221.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="o5ZwoQR0" Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-35f1dc4ab9aso17717f8f.3 for ; Wed, 12 Jun 2024 04:53:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1718193183; x=1718797983; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ufjGpymO2l4pPxuTK47gK3FSS4v9zOl7SdWpW7/pLTw=; b=o5ZwoQR0rAO4TGVJnnplKBsHMPK351oUwBYkRYyvRftaiqSh3r6JtdKgZsjQf8/OZa aB/yAtFAM5KdBd6XONd605p7gUOTnLtXYtDNc/jYjJzOktoF3d5UWolndePo4Yckl/Xr pKsj3+8x7ZMhnkvBeMmAHS0uAfFZHVPoqTpIWj3+p/pIbU73PlJ3ezMRGeXPLfAxHX/H QLuAnggjYIzAPaEIgbxUwoQlMSB1g0ZhR3fyKuncsXSv565QSirkBKPvLndWJyBAo8b+ WeJIGMAk8Ys8JTDaaPeayEaOOitrkXaH017iKkWqT20kTBn1ZB2JDNT+CF7QrUFQFwfX skUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718193183; x=1718797983; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ufjGpymO2l4pPxuTK47gK3FSS4v9zOl7SdWpW7/pLTw=; b=N9RVp/Uugk96IPYOGUDzaUt9wA56CJuhM49Sc++SsW8VgR+IJUDJVBk2I0vZiPYYjk kIfWS+I9z2pn5X4YnNtumflEmFKexLm++/cExD6BPMqrL9dmWIVraUUHdsvtL6vsUYLc 3ptc/Y5sEb+NHuhxOwl65ftBbM4o+kHSsoNBFM5SFxspuPRKTekdTGoGEaOpqh+uTM8T oGns47berw31RxPywfhw9rdp5gCUhm9N0NoONVVIhHh3Fy9QJztiIxfY7XEDLE/Knzb3 +77Zkm26+OqlEhNaxxGkUPkcPCRVBdCDAnaxHUKsX+ec8AEHCFssBlCc5dzPNhP7WjUb XRHQ== X-Gm-Message-State: AOJu0YxTV7IHwMwTu+H46SOmTwkbGQ86sKtANbilhqDfw8kuoSvxkbWu alsOx6VwWyf4MRwFeBkZLWHc99nPSAVMutoddN6kd3WRtScbCnLzLxM3tR/8KQA= X-Google-Smtp-Source: AGHT+IFjWInjWc9PWimjyszlJor2DHMYg9MFG+aIxIDc+zyXvpGduUgSZ7AIcsH+SI3wjocwmcF9dQ== X-Received: by 2002:a05:6000:bd0:b0:35f:1522:10b1 with SMTP id ffacd0b85a97d-35fe8910281mr1125602f8f.52.1718193183229; Wed, 12 Jun 2024 04:53:03 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:8d3:3800:a172:4e8b:453e:2f03]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-35f1c958f9fsm10457352f8f.38.2024.06.12.04.53.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 04:53:02 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Thomas Gleixner Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 2/2] gpio: sim: lock GPIOs as interrupts when they are requested Date: Wed, 12 Jun 2024 13:52:26 +0200 Message-ID: <20240612115231.26703-3-brgl@bgdev.pl> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240612115231.26703-1-brgl@bgdev.pl> References: <20240612115231.26703-1-brgl@bgdev.pl> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Bartosz Golaszewski Use the notifier exposed by the interrupt simulator to be notified about interrupts associated with simulated GPIO pins being requested or released and lock/unlock them as interrupts accordingly. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-sim.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/drivers/gpio/gpio-sim.c b/drivers/gpio/gpio-sim.c index 2ed5cbe7c8a8..b5526f09b22b 100644 --- a/drivers/gpio/gpio-sim.c +++ b/drivers/gpio/gpio-sim.c @@ -53,6 +53,7 @@ struct gpio_sim_chip { struct irq_domain *irq_sim; struct mutex lock; const struct attribute_group **attr_groups; + struct notifier_block nb; }; struct gpio_sim_attribute { @@ -227,6 +228,24 @@ static void gpio_sim_free(struct gpio_chip *gc, unsigned int offset) } } +static int gpio_sim_irq_domain_notify(struct notifier_block *nb, + unsigned long action, void *data) +{ + struct gpio_sim_chip *chip = container_of(nb, struct gpio_sim_chip, nb); + irq_hw_number_t *offset = data; + + switch (action) { + case IRQ_SIM_DOMAIN_IRQ_REQUESTED: + gpiochip_lock_as_irq(&chip->gc, *offset); + return NOTIFY_OK; + case IRQ_SIM_DOMAIN_IRQ_RELEASED: + gpiochip_unlock_as_irq(&chip->gc, *offset); + return NOTIFY_OK; + } + + return NOTIFY_DONE; +} + static void gpio_sim_dbg_show(struct seq_file *seq, struct gpio_chip *gc) { struct gpio_sim_chip *chip = gpiochip_get_data(gc); @@ -322,13 +341,15 @@ static void gpio_sim_put_device(void *data) put_device(dev); } -static void gpio_sim_dispose_mappings(void *data) +static void gpio_sim_teardown_irq_sim(void *data) { struct gpio_sim_chip *chip = data; unsigned int i; for (i = 0; i < chip->gc.ngpio; i++) irq_dispose_mapping(irq_find_mapping(chip->irq_sim, i)); + + irq_sim_domain_unregister_notifier(chip->irq_sim, &chip->nb); } static void gpio_sim_sysfs_remove(void *data) @@ -454,7 +475,12 @@ static int gpio_sim_add_bank(struct fwnode_handle *swnode, struct device *dev) if (IS_ERR(chip->irq_sim)) return PTR_ERR(chip->irq_sim); - ret = devm_add_action_or_reset(dev, gpio_sim_dispose_mappings, chip); + chip->nb.notifier_call = gpio_sim_irq_domain_notify; + ret = irq_sim_domain_register_notifier(chip->irq_sim, &chip->nb); + if (ret) + return ret; + + ret = devm_add_action_or_reset(dev, gpio_sim_teardown_irq_sim, chip); if (ret) return ret;