From: Sunil V L <sunilvl@ventanamicro.com>
To: linux-doc@vger.kernel.org, linux-riscv@lists.infradead.org,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org,
linux-pci@vger.kernel.org
Cc: Jonathan Corbet <corbet@lwn.net>,
Paul Walmsley <paul.walmsley@sifive.com>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>,
"Rafael J . Wysocki" <rafael@kernel.org>,
Len Brown <lenb@kernel.org>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Daniel Scally <djrscally@gmail.com>,
Heikki Krogerus <heikki.krogerus@linux.intel.com>,
Sakari Ailus <sakari.ailus@linux.intel.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Daniel Lezcano <daniel.lezcano@linaro.org>,
Thomas Gleixner <tglx@linutronix.de>,
Anup Patel <anup@brainfault.org>, Marc Zyngier <maz@kernel.org>,
Bjorn Helgaas <bhelgaas@google.com>,
Robert Moore <robert.moore@intel.com>,
Haibo Xu <haibo1.xu@intel.com>,
Andrew Jones <ajones@ventanamicro.com>,
Conor Dooley <conor.dooley@microchip.com>,
Atish Kumar Patra <atishp@rivosinc.com>,
Anup Patel <apatel@ventanamicro.com>,
Sunil V L <sunilvl@ventanamicro.com>
Subject: [RFC PATCH v1 11/21] swnode: Add support to create early during boot
Date: Thu, 3 Aug 2023 23:29:06 +0530 [thread overview]
Message-ID: <20230803175916.3174453-12-sunilvl@ventanamicro.com> (raw)
In-Reply-To: <20230803175916.3174453-1-sunilvl@ventanamicro.com>
From: Anup Patel <apatel@ventanamicro.com>
swnode framework can be used to create fwnode for interrupt
controllers. This helps in keeping the drivers same for both
DT and ACPI. To enable this, enhance the swnode framework so
that it can be created early during boot without dependency
on sysfs.
Signed-off-by: Anup Patel <apatel@ventanamicro.com>
Co-developed-by: Sunil V L <sunilvl@ventanamicro.com>
Signed-off-by: Sunil V L <sunilvl@ventanamicro.com>
---
drivers/base/swnode.c | 117 +++++++++++++++++++++++++++++++++------
include/linux/property.h | 3 +
2 files changed, 103 insertions(+), 17 deletions(-)
diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c
index 1886995a0b3a..43f191a38980 100644
--- a/drivers/base/swnode.c
+++ b/drivers/base/swnode.c
@@ -10,6 +10,7 @@
#include <linux/kernel.h>
#include <linux/property.h>
#include <linux/slab.h>
+#include <linux/spinlock.h>
#include "base.h"
@@ -21,6 +22,7 @@ struct swnode {
/* hierarchy */
struct ida child_ids;
+ struct list_head early;
struct list_head entry;
struct list_head children;
struct swnode *parent;
@@ -32,6 +34,9 @@ struct swnode {
static DEFINE_IDA(swnode_root_ids);
static struct kset *swnode_kset;
+static DEFINE_SPINLOCK(swnode_early_lock);
+static LIST_HEAD(swnode_early_list);
+
#define kobj_to_swnode(_kobj_) container_of(_kobj_, struct swnode, kobj)
static const struct fwnode_operations software_node_ops;
@@ -73,6 +78,17 @@ software_node_to_swnode(const struct software_node *node)
if (!node)
return NULL;
+ spin_lock(&swnode_early_lock);
+
+ list_for_each_entry(swnode, &swnode_early_list, early) {
+ if (swnode->node == node) {
+ spin_unlock(&swnode_early_lock);
+ return swnode;
+ }
+ }
+
+ spin_unlock(&swnode_early_lock);
+
spin_lock(&swnode_kset->list_lock);
list_for_each_entry(k, &swnode_kset->list, entry) {
@@ -698,6 +714,19 @@ software_node_find_by_name(const struct software_node *parent, const char *name)
if (!name)
return NULL;
+ spin_lock(&swnode_early_lock);
+
+ list_for_each_entry(swnode, &swnode_early_list, early) {
+ if (parent == swnode->node->parent && swnode->node->name &&
+ !strcmp(name, swnode->node->name)) {
+ kobject_get(&swnode->kobj);
+ spin_unlock(&swnode_early_lock);
+ return swnode->node;
+ }
+ }
+
+ spin_unlock(&swnode_early_lock);
+
spin_lock(&swnode_kset->list_lock);
list_for_each_entry(k, &swnode_kset->list, entry) {
@@ -742,10 +771,16 @@ static void software_node_free(const struct software_node *node)
kfree(node);
}
-static void software_node_release(struct kobject *kobj)
+static void software_node_release_common(struct kobject *kobj, bool early)
{
struct swnode *swnode = kobj_to_swnode(kobj);
+ if (early) {
+ spin_lock(&swnode_early_lock);
+ list_del(&swnode->early);
+ spin_unlock(&swnode_early_lock);
+ }
+
if (swnode->parent) {
ida_simple_remove(&swnode->parent->child_ids, swnode->id);
list_del(&swnode->entry);
@@ -760,6 +795,20 @@ static void software_node_release(struct kobject *kobj)
kfree(swnode);
}
+static void software_node_release(struct kobject *kobj)
+{
+ software_node_release_common(kobj, false);
+}
+
+static void software_node_release_early(struct kobject *kobj)
+{
+ software_node_release_common(kobj, true);
+}
+
+static const struct kobj_type software_node_type_early = {
+ .release = software_node_release_early
+};
+
static const struct kobj_type software_node_type = {
.release = software_node_release,
.sysfs_ops = &kobj_sysfs_ops,
@@ -767,7 +816,7 @@ static const struct kobj_type software_node_type = {
static struct fwnode_handle *
swnode_register(const struct software_node *node, struct swnode *parent,
- unsigned int allocated)
+ unsigned int allocated, unsigned int early)
{
struct swnode *swnode;
int ret;
@@ -786,21 +835,39 @@ swnode_register(const struct software_node *node, struct swnode *parent,
swnode->id = ret;
swnode->node = node;
swnode->parent = parent;
- swnode->kobj.kset = swnode_kset;
+ swnode->kobj.kset = (!early) ? swnode_kset : NULL;
fwnode_init(&swnode->fwnode, &software_node_ops);
ida_init(&swnode->child_ids);
+ INIT_LIST_HEAD(&swnode->early);
INIT_LIST_HEAD(&swnode->entry);
INIT_LIST_HEAD(&swnode->children);
- if (node->name)
- ret = kobject_init_and_add(&swnode->kobj, &software_node_type,
- parent ? &parent->kobj : NULL,
- "%s", node->name);
- else
- ret = kobject_init_and_add(&swnode->kobj, &software_node_type,
- parent ? &parent->kobj : NULL,
- "node%d", swnode->id);
+ if (early) {
+ ret = 0;
+ kobject_init(&swnode->kobj, &software_node_type_early);
+ swnode->kobj.parent = parent ? &parent->kobj : NULL;
+ if (node->name)
+ ret = kobject_set_name(&swnode->kobj,
+ "%s", node->name);
+ else
+ ret = kobject_set_name(&swnode->kobj,
+ "node%d", swnode->id);
+ if (!ret) {
+ spin_lock(&swnode_early_lock);
+ list_add_tail(&swnode->early, &swnode_early_list);
+ spin_unlock(&swnode_early_lock);
+ }
+ } else {
+ if (node->name)
+ ret = kobject_init_and_add(&swnode->kobj, &software_node_type,
+ parent ? &parent->kobj : NULL,
+ "%s", node->name);
+ else
+ ret = kobject_init_and_add(&swnode->kobj, &software_node_type,
+ parent ? &parent->kobj : NULL,
+ "node%d", swnode->id);
+ }
if (ret) {
kobject_put(&swnode->kobj);
return ERR_PTR(ret);
@@ -815,7 +882,8 @@ swnode_register(const struct software_node *node, struct swnode *parent,
if (parent)
list_add_tail(&swnode->entry, &parent->children);
- kobject_uevent(&swnode->kobj, KOBJ_ADD);
+ if (!early)
+ kobject_uevent(&swnode->kobj, KOBJ_ADD);
return &swnode->fwnode;
}
@@ -892,7 +960,7 @@ int software_node_register(const struct software_node *node)
if (node->parent && !parent)
return -EINVAL;
- return PTR_ERR_OR_ZERO(swnode_register(node, parent, 0));
+ return PTR_ERR_OR_ZERO(swnode_register(node, parent, 0, 0));
}
EXPORT_SYMBOL_GPL(software_node_register);
@@ -910,9 +978,10 @@ void software_node_unregister(const struct software_node *node)
}
EXPORT_SYMBOL_GPL(software_node_unregister);
-struct fwnode_handle *
-fwnode_create_software_node(const struct property_entry *properties,
- const struct fwnode_handle *parent)
+static struct fwnode_handle *
+fwnode_create_software_node_common(const struct property_entry *properties,
+ const struct fwnode_handle *parent,
+ bool early)
{
struct fwnode_handle *fwnode;
struct software_node *node;
@@ -931,12 +1000,26 @@ fwnode_create_software_node(const struct property_entry *properties,
node->parent = p ? p->node : NULL;
- fwnode = swnode_register(node, p, 1);
+ fwnode = swnode_register(node, p, 1, early);
if (IS_ERR(fwnode))
software_node_free(node);
return fwnode;
}
+
+struct fwnode_handle *
+fwnode_create_software_node_early(const struct property_entry *properties,
+ const struct fwnode_handle *parent)
+{
+ return fwnode_create_software_node_common(properties, parent, true);
+}
+
+struct fwnode_handle *
+fwnode_create_software_node(const struct property_entry *properties,
+ const struct fwnode_handle *parent)
+{
+ return fwnode_create_software_node_common(properties, parent, false);
+}
EXPORT_SYMBOL_GPL(fwnode_create_software_node);
void fwnode_remove_software_node(struct fwnode_handle *fwnode)
diff --git a/include/linux/property.h b/include/linux/property.h
index 8c3c6685a2ae..7137338bfabb 100644
--- a/include/linux/property.h
+++ b/include/linux/property.h
@@ -503,6 +503,9 @@ void software_node_unregister_node_group(const struct software_node **node_group
int software_node_register(const struct software_node *node);
void software_node_unregister(const struct software_node *node);
+struct fwnode_handle *
+fwnode_create_software_node_early(const struct property_entry *properties,
+ const struct fwnode_handle *parent);
struct fwnode_handle *
fwnode_create_software_node(const struct property_entry *properties,
const struct fwnode_handle *parent);
--
2.39.2
next prev parent reply other threads:[~2023-08-03 18:02 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-03 17:58 [RFC PATCH v1 00/21] RISC-V: ACPI: Add external interrupt controller support Sunil V L
2023-08-03 17:58 ` [RFC PATCH v1 01/21] ACPICA: MADT: Add RISC-V external interrupt controllers Sunil V L
2023-08-03 17:58 ` [RFC PATCH v1 02/21] ACPICA: RHCT: Add flags, CMO and MMU nodes Sunil V L
2023-08-03 17:58 ` [RFC PATCH v1 03/21] RISC-V: ACPI: Fix acpi_os_ioremap to return iomem address Sunil V L
2023-08-07 8:20 ` Andrew Jones
2023-08-03 17:58 ` [RFC PATCH v1 04/21] RISC-V: ACPI: Enhance acpi_os_ioremap with MMIO remapping Sunil V L
2023-08-04 5:47 ` Andy Shevchenko
2023-08-04 8:19 ` Sunil V L
2023-08-07 8:41 ` Andrew Jones
2023-08-03 17:59 ` [RFC PATCH v1 05/21] arm64: PCI: Migrate ACPI related functions to pci-acpi.c Sunil V L
2023-08-04 5:53 ` Andy Shevchenko
2023-08-04 8:23 ` Sunil V L
2023-08-07 22:41 ` Bjorn Helgaas
2023-08-08 4:52 ` Sunil V L
2023-08-08 13:11 ` Andy Shevchenko
2023-08-08 13:11 ` Andy Shevchenko
2023-08-03 17:59 ` [RFC PATCH v1 06/21] RISC-V: ACPI: Implement PCI related functionality Sunil V L
2023-08-03 17:59 ` [RFC PATCH v1 07/21] RISC-V: Kconfig: Select ECAM and MCFG Sunil V L
2023-08-03 17:59 ` [RFC PATCH v1 08/21] RISC-V: ACPI: RHCT: Add function to get CBO block sizes Sunil V L
2023-08-04 6:00 ` Andy Shevchenko
2023-08-04 9:33 ` Sunil V L
2023-08-03 17:59 ` [RFC PATCH v1 09/21] RISC-V: cacheflush: Initialize CBO variables on ACPI systems Sunil V L
2023-08-04 5:56 ` Andy Shevchenko
2023-08-04 9:20 ` Sunil V L
2023-08-04 14:59 ` Andy Shevchenko
2023-08-04 15:19 ` Conor Dooley
2023-08-04 16:52 ` Andy Shevchenko
2023-08-04 16:56 ` Andy Shevchenko
2023-08-03 17:59 ` [RFC PATCH v1 10/21] clocksource/timer-riscv: ACPI: Add timer_cannot_wakeup_cpu Sunil V L
2023-08-03 17:59 ` Sunil V L [this message]
2023-08-04 6:09 ` [RFC PATCH v1 11/21] swnode: Add support to create early during boot Andy Shevchenko
2023-08-04 8:11 ` Sunil V L
2023-08-08 13:17 ` Marc Zyngier
2023-08-09 5:44 ` Sunil V L
2023-08-08 13:06 ` Marc Zyngier
2023-08-03 17:59 ` [RFC PATCH v1 12/21] irqchip/riscv-intc: Use swnode framework to create fwnode Sunil V L
2023-08-08 8:31 ` Conor Dooley
2023-08-09 5:49 ` Sunil V L
2023-08-03 17:59 ` [RFC PATCH v1 13/21] irqchip/riscv-imsic-early: Add ACPI support Sunil V L
2023-08-03 17:59 ` [RFC PATCH v1 14/21] ACPI: bus: Add acpi_riscv_init function Sunil V L
2023-08-03 17:59 ` [RFC PATCH v1 15/21] ACPI: RISC-V: Create IMSIC platform device Sunil V L
2023-08-03 17:59 ` [RFC PATCH v1 16/21] ACPI: Add APLIC IRQ model for RISC-V Sunil V L
2023-08-03 17:59 ` [RFC PATCH v1 17/21] ACPI: RISC-V: Create APLIC platform device Sunil V L
2023-08-03 17:59 ` [RFC PATCH v1 18/21] irqchip/irq-riscv-aplic-msi: Add ACPI support Sunil V L
2023-08-03 17:59 ` [RFC PATCH v1 19/21] ACPI: bus: Add PLIC IRQ model Sunil V L
2023-08-03 17:59 ` [RFC PATCH v1 20/21] RISC-V: ACPI: Create PLIC platform device Sunil V L
2023-08-08 8:41 ` Conor Dooley
2023-08-08 10:57 ` Anup Patel
2023-08-08 11:30 ` Conor Dooley
2023-08-09 5:47 ` Sunil V L
2023-08-03 17:59 ` [RFC PATCH v1 21/21] irqchip/sifive-plic: Add GSI conversion support Sunil V L
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230803175916.3174453-12-sunilvl@ventanamicro.com \
--to=sunilvl@ventanamicro.com \
--cc=ajones@ventanamicro.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=anup@brainfault.org \
--cc=aou@eecs.berkeley.edu \
--cc=apatel@ventanamicro.com \
--cc=atishp@rivosinc.com \
--cc=bhelgaas@google.com \
--cc=catalin.marinas@arm.com \
--cc=conor.dooley@microchip.com \
--cc=corbet@lwn.net \
--cc=daniel.lezcano@linaro.org \
--cc=djrscally@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=haibo1.xu@intel.com \
--cc=heikki.krogerus@linux.intel.com \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=maz@kernel.org \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=rafael@kernel.org \
--cc=robert.moore@intel.com \
--cc=sakari.ailus@linux.intel.com \
--cc=tglx@linutronix.de \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox