drivers/base/swnode.c
Source file repositories/reference/linux-study-clean/drivers/base/swnode.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/base/swnode.c- Extension
.c- Size
- 27706 bytes
- Lines
- 1144
- Domain
- Driver Families
- Bucket
- drivers/base
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/container_of.hlinux/device.hlinux/err.hlinux/export.hlinux/idr.hlinux/init.hlinux/kobject.hlinux/kstrtox.hlinux/list.hlinux/property.hlinux/slab.hlinux/spinlock.hlinux/string.hlinux/sysfs.hlinux/types.hbase.h
Detected Declarations
struct swnodefunction is_software_nodefunction software_node_to_swnodefunction list_for_each_entryfunction property_entry_getfunction property_entry_count_elems_of_sizefunction property_entry_read_int_arrayfunction property_entry_read_string_arrayfunction property_entry_free_datafunction property_copy_string_arrayfunction property_entry_copy_datafunction property_entries_dupfunction property_entries_freefunction swnode_putfunction software_node_putfunction software_node_property_presentfunction software_node_read_int_arrayfunction software_node_read_string_arrayfunction software_node_get_namefunction software_node_get_name_prefixfunction software_node_get_parentfunction software_node_get_next_childfunction software_node_get_named_child_nodefunction list_for_each_entryfunction software_node_get_reference_argsfunction swnode_graph_find_next_portfunction software_node_graph_get_next_endpointfunction software_node_graph_get_remote_endpointfunction software_node_graph_get_port_parentfunction software_node_graph_parse_endpointfunction software_node_find_by_namefunction list_for_each_entryfunction software_node_freefunction software_node_releasefunction swnode_registerfunction software_node_register_node_groupfunction software_node_unregister_node_groupfunction software_node_registerfunction software_node_unregisterfunction fwnode_create_software_nodefunction fwnode_remove_software_nodefunction device_add_software_nodefunction device_remove_software_nodefunction device_create_managed_software_nodefunction software_node_notifyfunction software_node_notify_removefunction software_node_initexport is_software_node
Annotated Snippet
struct swnode {
struct kobject kobj;
struct fwnode_handle fwnode;
const struct software_node *node;
int id;
/* hierarchy */
struct ida child_ids;
struct list_head entry;
struct list_head children;
struct swnode *parent;
unsigned int allocated:1;
unsigned int managed:1;
};
static DEFINE_IDA(swnode_root_ids);
static struct kset *swnode_kset;
#define kobj_to_swnode(_kobj_) container_of(_kobj_, struct swnode, kobj)
static const struct fwnode_operations software_node_ops;
bool is_software_node(const struct fwnode_handle *fwnode)
{
return !IS_ERR_OR_NULL(fwnode) && fwnode->ops == &software_node_ops;
}
EXPORT_SYMBOL_GPL(is_software_node);
#define to_swnode(__fwnode) \
({ \
typeof(__fwnode) __to_swnode_fwnode = __fwnode; \
\
is_software_node(__to_swnode_fwnode) ? \
container_of(__to_swnode_fwnode, \
struct swnode, fwnode) : NULL; \
})
static inline struct swnode *dev_to_swnode(struct device *dev)
{
struct fwnode_handle *fwnode = dev_fwnode(dev);
if (!fwnode)
return NULL;
if (!is_software_node(fwnode))
fwnode = fwnode->secondary;
return to_swnode(fwnode);
}
static struct swnode *
software_node_to_swnode(const struct software_node *node)
{
struct swnode *swnode = NULL;
struct kobject *k;
if (!node)
return NULL;
spin_lock(&swnode_kset->list_lock);
list_for_each_entry(k, &swnode_kset->list, entry) {
swnode = kobj_to_swnode(k);
if (swnode->node == node)
break;
swnode = NULL;
}
spin_unlock(&swnode_kset->list_lock);
return swnode;
}
const struct software_node *to_software_node(const struct fwnode_handle *fwnode)
{
const struct swnode *swnode = to_swnode(fwnode);
return swnode ? swnode->node : NULL;
}
EXPORT_SYMBOL_GPL(to_software_node);
struct fwnode_handle *software_node_fwnode(const struct software_node *node)
{
struct swnode *swnode = software_node_to_swnode(node);
return swnode ? &swnode->fwnode : NULL;
}
EXPORT_SYMBOL_GPL(software_node_fwnode);
Annotation
- Immediate include surface: `linux/container_of.h`, `linux/device.h`, `linux/err.h`, `linux/export.h`, `linux/idr.h`, `linux/init.h`, `linux/kobject.h`, `linux/kstrtox.h`.
- Detected declarations: `struct swnode`, `function is_software_node`, `function software_node_to_swnode`, `function list_for_each_entry`, `function property_entry_get`, `function property_entry_count_elems_of_size`, `function property_entry_read_int_array`, `function property_entry_read_string_array`, `function property_entry_free_data`, `function property_copy_string_array`.
- Atlas domain: Driver Families / drivers/base.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.