From nobody Sat Feb 7 09:42:43 2026 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 19E4038945C; Wed, 14 Jan 2026 09:40:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768383647; cv=none; b=kBqBMnlB7vP1MflgLKTpHy6lArT1b5tuWOzhAXhmYvnKJGbJ7qsA/9hFF3v7feMqAH+8ZteEfpcYLr6b1XmnboGqSLXHRo9DsPxUcIZObGeX0dCQAGW3XYrP0OsoyrPcsVtzyPcgVn7leAqAWbZaXz+j20Q2DootQjAE4Lgp38M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768383647; c=relaxed/simple; bh=vVZgxFYLzHLo6Je5qo4VsC2G21fb8AVTz3FULpwqbI8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Y3tntR9pYORDrN4Zj4uhtJtqgXQADQiK7ib4+z2L260Lur/bJ9IGDhZaLVGh/WfILWtPab3ZJQug7W3EQxZYZBAo6Gd5kDCSrCLc6k1gRaBInmCGlJzu4Be7IjXMkQxODt9tDZ0YGx250JDPcf+kIW3saBsaG//jic/SHfL/dNQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=vwm5pAWg; arc=none smtp.client-ip=185.246.84.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="vwm5pAWg" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id B780F1A2865; Wed, 14 Jan 2026 09:40:41 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 8DC476074A; Wed, 14 Jan 2026 09:40:41 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 841D5103C8177; Wed, 14 Jan 2026 10:40:38 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1768383640; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=jozCCQDErEkxTe2vzEruUqB8SMT6ApftoG0i4EMWZJY=; b=vwm5pAWg4cC+o6nC+XiWcJOFPvMVN7c61IkMm0lF77s3SX13JA+KuTmKZWhP7yAqcSlA7m kT/hxanYnqYiC/r86Dd2DGNlf3p5WpQRJNwAySKAxLOkjJJFIjS0KWUYGWLRai/iZ0Wch3 OrQpEJimslAbcX6EaFI8xgYIzNIlE5lGmlNYTPLokryyOAY5grfY6gsdAw3GxTwfKVITPE 0NHHTLU2cxv0X++qYG6xahjRF7N+NdkKT309kH50IhpT++SRXCyavCytSKHmcljjPAmCSB rUmJVb6jsWzjStu3Je56Wj7hELxXTPIQmZqnu8xeuR7J1MMpbYLHsnBSHWIfZA== From: "Herve Codina (Schneider Electric)" To: Thomas Gleixner , Wolfram Sang , Linus Walleij , Bartosz Golaszewski , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Geert Uytterhoeven , Magnus Damm , Saravana Kannan , Herve Codina Cc: linux-gpio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Pascal Eberhard , Miquel Raynal , Thomas Petazzoni Subject: [PATCH v8 1/8] of/irq: Introduce for_each_of_imap_item Date: Wed, 14 Jan 2026 10:39:30 +0100 Message-ID: <20260114093938.1089936-2-herve.codina@bootlin.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260114093938.1089936-1-herve.codina@bootlin.com> References: <20260114093938.1089936-1-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" for_each_of_imap_item is an iterator designed to help a driver to parse an interrupt-map property. Indeed some drivers need to know details about the interrupt mapping described in the device-tree in order to set internal registers accordingly. Signed-off-by: Herve Codina (Schneider Electric) Tested-by: Wolfram Sang Reviewed-by: Rob Herring (Arm) Reviewed-by: Linus Walleij --- drivers/of/irq.c | 70 ++++++++++++++++++++++++++++++++++++++++++ include/linux/of_irq.h | 41 ++++++++++++++++++++++++- 2 files changed, 110 insertions(+), 1 deletion(-) diff --git a/drivers/of/irq.c b/drivers/of/irq.c index e3816819dbfe..f374d8b212b8 100644 --- a/drivers/of/irq.c +++ b/drivers/of/irq.c @@ -157,6 +157,76 @@ const __be32 *of_irq_parse_imap_parent(const __be32 *i= map, int len, struct of_ph return imap; } =20 +int of_imap_parser_init(struct of_imap_parser *parser, struct device_node = *node, + struct of_imap_item *item) +{ + int imaplen; + u32 tmp; + int ret; + + /* + * parent_offset is the offset where the parent part is starting. + * In other words, the offset where the parent interrupt controller + * phandle is present. + * + * Compute this offset (child #interrupt-cells + child #address-cells) + */ + parser->parent_offset =3D of_bus_n_addr_cells(node); + + ret =3D of_property_read_u32(node, "#interrupt-cells", &tmp); + if (ret) + return ret; + + parser->parent_offset +=3D tmp; + + if (WARN(parser->parent_offset > ARRAY_SIZE(item->child_imap), + "child part size =3D %u, cannot fit in array of %zu items", + parser->parent_offset, ARRAY_SIZE(item->child_imap))) + return -EINVAL; + + parser->imap =3D of_get_property(node, "interrupt-map", &imaplen); + if (!parser->imap) + return -ENOENT; + + imaplen /=3D sizeof(*parser->imap); + parser->imap_end =3D parser->imap + imaplen; + + memset(item, 0, sizeof(*item)); + item->child_imap_count =3D parser->parent_offset; + + return 0; +} +EXPORT_SYMBOL_GPL(of_imap_parser_init); + +struct of_imap_item *of_imap_parser_one(struct of_imap_parser *parser, + struct of_imap_item *item) +{ + const __be32 *imap_parent, *imap_next; + int i; + + /* Release previously get parent node */ + of_node_put(item->parent_args.np); + + if (parser->imap + parser->parent_offset + 1 >=3D parser->imap_end) + return NULL; + + imap_parent =3D parser->imap + parser->parent_offset; + + imap_next =3D of_irq_parse_imap_parent(imap_parent, + parser->imap_end - imap_parent, + &item->parent_args); + if (!imap_next) + return NULL; + + for (i =3D 0; i < parser->parent_offset; i++) + item->child_imap[i] =3D be32_to_cpu(*(parser->imap + i)); + + parser->imap =3D imap_next; + + return item; +} +EXPORT_SYMBOL_GPL(of_imap_parser_one); + /** * of_irq_parse_raw - Low level interrupt tree parsing * @addr: address specifier (start of "reg" property of the device) in be3= 2 format diff --git a/include/linux/of_irq.h b/include/linux/of_irq.h index 1c2bc0281807..2a64d8cecaae 100644 --- a/include/linux/of_irq.h +++ b/include/linux/of_irq.h @@ -11,6 +11,30 @@ =20 typedef int (*of_irq_init_cb_t)(struct device_node *, struct device_node *= ); =20 +struct of_imap_parser { + struct device_node *node; + const __be32 *imap; + const __be32 *imap_end; + u32 parent_offset; +}; + +struct of_imap_item { + struct of_phandle_args parent_args; + u32 child_imap_count; + u32 child_imap[16]; /* Arbitrary size. + * Should be #address-cells + #interrupt-cells but + * avoid using allocation and so, expect that 16 + * should be enough + */ +}; + +/* + * If the iterator is exited prematurely (break, goto, return) of_node_put= () has + * to be called on item.parent_args.np + */ +#define for_each_of_imap_item(parser, item) \ + for (; of_imap_parser_one(parser, item);) + /* * Workarounds only applied to 32bit powermac machines */ @@ -49,6 +73,11 @@ extern int of_irq_get_byname(struct device_node *dev, co= nst char *name); extern int of_irq_to_resource_table(struct device_node *dev, struct resource *res, int nr_irqs); extern struct device_node *of_irq_find_parent(struct device_node *child); +extern int of_imap_parser_init(struct of_imap_parser *parser, + struct device_node *node, + struct of_imap_item *item); +extern struct of_imap_item *of_imap_parser_one(struct of_imap_parser *pars= er, + struct of_imap_item *item); extern struct irq_domain *of_msi_get_domain(struct device *dev, const struct device_node *np, enum irq_domain_bus_token token); @@ -92,7 +121,17 @@ static inline void *of_irq_find_parent(struct device_no= de *child) { return NULL; } - +static inline int of_imap_parser_init(struct of_imap_parser *parser, + struct device_node *node, + struct of_imap_item *item) +{ + return -ENOSYS; +} +static inline struct of_imap_item *of_imap_parser_one(struct of_imap_parse= r *parser, + struct of_imap_item *item) +{ + return NULL; +} static inline struct irq_domain *of_msi_get_domain(struct device *dev, struct device_node *np, enum irq_domain_bus_token token) --=20 2.52.0