From patchwork Thu Aug 3 17:59:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sunil V L X-Patchwork-Id: 13340434 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1D8DCC001DF for ; Thu, 3 Aug 2023 18:01:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=WjLaVgpU+s1JaiVbbqYgi+KF6rCACatWcvys0Gy2lG0=; b=hZXrByvI4juP67 gLXUL+xyWuCsOK8dmdJlfR+klVOfnkKS9f7gmhWegJ4QpzlAgCVk4fU8q86IUS834cdD/dH0UL+X8 QDnTK1q+hwWkMG9wFrlMFdjNKV1LBHK4q9yjSSDGMoQr0d0hIZ+kJkl+e4f8X/mz6gNPSv/nsgZL4 Q8VHmga0RlVfdwlEvRkVt+/itbTbgXlJis25El+x6FVPj2dLdHi3P5kx4l2xWhsMjc8B8rQ5DHnjJ bzw+8aJnfC8nCZdIPhyzA0zWgXvMM43T0DTYpd7ekfXq2IW2enZGulufGH0L+7Mt6uE6JQEZutFIB cZzD66Nypmtbh9ylnmmA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qRcd9-00AVGK-1m; Thu, 03 Aug 2023 18:00:59 +0000 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qRcd6-00AVDw-1t for linux-riscv@lists.infradead.org; Thu, 03 Aug 2023 18:00:58 +0000 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-686fc0d3c92so886529b3a.0 for ; Thu, 03 Aug 2023 11:00:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1691085656; x=1691690456; 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=DyY105ZWYDcmAte3LXmkGWmEUp/pfY0rBCzPBKLc5no=; b=F2No1P8dCodOCJka5dx2xLrl5WcKTOqh0CqE9s2TUtqnLixlF6cr/AUvszgzy2TZTu IpgJ+dCrZugmZepjC/tpy4R5LQ7Pz00gUcQA/TtEMUWoSfT5/uFb1jKxDzT1ZQsqsZTd n/YxBVubsZMRX+XTZS1a6+twWBxpWIcvQgGZi10KPo9NwU+hLzYpn1k3UmbuJPr0c0iN /xxd/mndMDktQMKzqNFO4efMHpBh/HZI7YvgUVyIjmX6wmoATvY7iqn4QFz7f0d+cSG4 WzANehXdmfb0puBdKFejEfzCVDWLv6Eq7vxbamEiMtycsiO96UVNPeRmqmAhUEv2O88s z+Bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691085656; x=1691690456; 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=DyY105ZWYDcmAte3LXmkGWmEUp/pfY0rBCzPBKLc5no=; b=OJRcaJr2y6LRFdW4uYApMz5jQVGF5IET3kNPjsPk8c19VTl+B20vvDRrNw8i1xHeUz yf9Z6wpgEBPQJdxbp/jeXIWfmbNji7FDy5MSLyq4jcUgmDIxSQYYs6P5CbGgruu5ZiPa scQ6OB7Rp0UwExVGqSoZ1AwYu7Gk1/9l4LZCL2MFDty6f2wwA3L7hVA9ztBM26EBM4ry jr4hSjko4/muGLDTQNLIKrIOI+wOJQl+oj7SCXLkqjE6RDhIKlF+3myQOz/q6Z1p+k3V QAr36D1e/ffswZ0RVOb++4B49/mKqQ3FrY5UIRWDIyKnKuEfXP1sqzvAlgECa022/C4i Oo/Q== X-Gm-Message-State: ABy/qLZaJ2Vau4Pmd1I8Seur5sfX8ryKx1S1S7+VzNOk8mBWLeiUhS5b dW7gcWCLhwPWtZjDMX3guHCXSw== X-Google-Smtp-Source: APBJJlF1KqR7PBmpd+0ur15adwkWpnUfiC6IMRYgAhf76Ujfi0pbNhhy0c6BhAYpNTIPaEB13Qkk0A== X-Received: by 2002:a05:6a00:1883:b0:666:b254:1c9c with SMTP id x3-20020a056a00188300b00666b2541c9cmr22057156pfh.27.1691085656078; Thu, 03 Aug 2023 11:00:56 -0700 (PDT) Received: from sunil-pc.Dlink ([106.51.190.143]) by smtp.gmail.com with ESMTPSA id s8-20020aa78d48000000b0065a1b05193asm134952pfe.185.2023.08.03.11.00.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 11:00:55 -0700 (PDT) From: Sunil V L 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 Subject: [RFC PATCH v1 11/21] swnode: Add support to create early during boot Date: Thu, 3 Aug 2023 23:29:06 +0530 Message-Id: <20230803175916.3174453-12-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230803175916.3174453-1-sunilvl@ventanamicro.com> References: <20230803175916.3174453-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230803_110056_646459_5FE37D06 X-CRM114-Status: GOOD ( 20.21 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Heikki Krogerus , "Rafael J . Wysocki" , Catalin Marinas , Atish Kumar Patra , Conor Dooley , Will Deacon , Haibo Xu , Jonathan Corbet , Marc Zyngier , Daniel Lezcano , Robert Moore , Andrew Jones , Albert Ou , Paul Walmsley , Bjorn Helgaas , Thomas Gleixner , Andy Shevchenko , Anup Patel , Greg Kroah-Hartman , Daniel Scally , Palmer Dabbelt , Sakari Ailus , Anup Patel , Len Brown Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org From: Anup Patel 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 Co-developed-by: Sunil V L Signed-off-by: Sunil V L --- 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 #include #include +#include #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);