Received: by 2002:ab2:6c55:0:b0:1fd:c486:4f03 with SMTP id v21csp498595lqp; Wed, 12 Jun 2024 07:53:32 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXzJQt9fbTy54ZZv7O62Bl97q3Dx9rBc2yKnQc0AI8WTuMPyv5yknvFvPGY8BMmkYMLi9xsTP/CdTEc/SveH7M1kyp+IupyV15gqFtlTg== X-Google-Smtp-Source: AGHT+IGwG3o6G+0kC6bpNbB9HHmLCUk0gJrwbbsry8EjnYkE4t/nq77jwbMNX1jF7wK5NTWz53Rt X-Received: by 2002:a05:6a20:1581:b0:1b8:a08c:73e3 with SMTP id adf61e73a8af0-1b8a9c54be8mr2482460637.48.1718204012155; Wed, 12 Jun 2024 07:53:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718204012; cv=pass; d=google.com; s=arc-20160816; b=OnXCpW5cZP/Jqv2fmfeTPQQYLKQU5t8u1x/jB6wumxNqZkaF5YQvM6zSNPimbj/b7x 6DsTUB8Vtb/NFCQ9o2dOl8b/DEWsBw5dnC4lOxRB2N9aR5e9rj8kLKjsSPqS9G9/nQxK eoaDWl0U8W7I5PUuhT63NA6pktbqn1FevWM5SaRMs9OidZkG8K5s3nKCG90z6roz6dq8 u196CmtmcL47MgvcViqEBJp8bozgqA7KlSvWf7EdBteW1SIGdOAtK5sLarahY/mE4Mcu OjjBmenA+TV+Yj2KQo8kICC3kJU1JkLSYazxn0+CtMG2nS/dYOQxYZdr9mHvk1KjtO5T GSHw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=RMaVrXTNSn8/RlgcBidtA4XNwAtbmdRI1NY6kSKH78g=; fh=yCT3piSDX9gdRkisB7FgSrZBwFIC6W+rpkc+RCqKzEU=; b=Ju9wjbiXXMQUbwkBdNDMmMjV9ufL4GjguKtpuCWdfUixcAE2MnxsQFv9RtA9TxED32 9i19B0PtGDLzXT2ESzwNkffHAXSgLK2bp8cQgAdSMU6ZzqyCQq4TGK8XObOcKJTRvJ1j dtO4BAUKAPYgDCu3jDSX+BkWHu/gLCwVW04y12CfchYTLfj9Lb4qQvGG4j8GCI0W/22R kftmotbnooBkF4dw7bZxFA2yoJSlCYICCO5ea3iAaB8x4dRhUldrI3pGYjNEHSTNjH9c ulShcj1OIDJOee1F6o+/SaderFwXw1rUThKUPbAikPpaKn8bWvjfavqrKHm0zK02plXx e5xQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=vlnvGd4I; arc=pass (i=1 dkim=pass dkdomain=bgdev-pl.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-211441-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-211441-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 41be03b00d2f7-6f73c479369si3229972a12.504.2024.06.12.07.53.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 07:53:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-211441-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=vlnvGd4I; arc=pass (i=1 dkim=pass dkdomain=bgdev-pl.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-211441-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-211441-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id A9341281F9D for ; Wed, 12 Jun 2024 11:53:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E66FF16F29E; Wed, 12 Jun 2024 11:53:06 +0000 (UTC) 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: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) (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 42A5216E881 for ; Wed, 12 Jun 2024 11:53:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718193185; cv=none; b=Ebox9MnUfF+UZRFgEECMj8jRPKXwTicbFBG//jL0Guifs4qB2UQBQWzTV4zIo4MlEz5W6e9L+H9rplzdZSDDqPGj8ev4S3oliTOl+1SA14plCUIWz/4l17Rpt/7wTyTEC7AYP6G1Nhnpw3wGTRe0mIiLAPai0MNvrPFAowTf0Ts= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718193185; c=relaxed/simple; bh=gIxc5R2yJd9VUifO8gyW7fV3jyzLCecrCt5fl7cMhQM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UirkIvS9xJABmX/Qs8Ch3cQ38Y7TA9mluQNW4fOp4W/WhsbvYAH5cCh6vCwAH9CraFIHIf8wt7yr3RHPIUNqS+UOvc7VY6S/49AEKVqoazSXf2bv4M5vjTYEfwl/vAxUwxka+DHTo4jhMcISSWZmgK5NVBTVDhkXGcGsn8CU1h8= 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.54 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 Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-52bc121fb1eso5789702e87.1 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=sRHAYRc7rnQbRdYXIsGA3Zld97MPaw9rYCd1tX/E1aod0Cgtsuu7XG8pRrV9vz/Wdd r/caio3BUN7dcV3R5L/dEIi7QjCtUxEY99C9Jh6URUg2/r2d7QOhKw61ZDdeSkAOI5ka i4/RdZBtEDrWZD3LSt9JGo2HHoOXHGmP5KnzIPvymFjUfOF3CCCSUzt7LG8VNU06seFR 4tpOqHawJkVYgOyT5tY48T5X3OWG46fiv9QkWxI2yj0nr5HcdvQZKcnficeU2ZwKeqt+ X3/jJbKlpVRr2Eui2ww0hpiRP9AkOhve23mE9iUlpgmSZ2bSMrsaiopSgaYsRu/sCjKx EyLA== X-Forwarded-Encrypted: i=1; AJvYcCV6ptAapWvXD+bkxRE4ZWOFnJw1D2/+vPTpJxyRe5HyX0THF4O8i2ONiJ26MiByxIy7MVkJJncAoovE1CizPtOcRqkmql5xhaiExiB7 X-Gm-Message-State: AOJu0Yzdsdbl+rdx8b/e7hoGgtVdVbnJovaqxLhrHn3ZDI/cZQy89pBz DVJP1h9JZ2WuaPuT1Evac1sZ83c0Opsokmtb7vO/Rpawo5WYlc1ZCe8Zh+WKQLs= 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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); -- 2.40.1