drivers/hwtracing/stm/core.c
Source file repositories/reference/linux-study-clean/drivers/hwtracing/stm/core.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwtracing/stm/core.c- Extension
.c- Size
- 31239 bytes
- Lines
- 1375
- Domain
- Driver Families
- Bucket
- drivers/hwtracing
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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/pm_runtime.hlinux/uaccess.hlinux/kernel.hlinux/module.hlinux/device.hlinux/compat.hlinux/kdev_t.hlinux/srcu.hlinux/slab.hlinux/stm.hlinux/fs.hlinux/mm.hlinux/vmalloc.hstm.huapi/linux/stm.h
Detected Declarations
struct stm_pdrv_entryfunction masters_showfunction channels_showfunction hw_override_showfunction stm_find_devicefunction stm_put_devicefunction stm_masterfunction stp_master_allocfunction stp_master_freefunction stm_output_claimfunction stm_output_disclaimfunction bitmap_find_free_regionfunction stm_find_master_chanfunction stm_output_assignfunction stm_output_freefunction stm_output_initfunction major_matchfunction __stm_lookup_protocolfunction list_for_each_entryfunction stm_register_protocolfunction stm_unregister_protocolfunction list_for_each_entry_safefunction stm_get_protocolfunction stm_put_protocolfunction stm_lookup_protocolfunction stm_char_openfunction stm_char_releasefunction stm_assign_first_policyfunction stm_data_writefunction stm_writefunction stm_char_writefunction stm_mmap_mappedfunction stm_mmap_openfunction stm_mmap_closefunction stm_char_mmap_preparefunction stm_char_policy_set_ioctlfunction stm_char_policy_get_ioctlfunction stm_char_ioctlfunction stm_device_releasefunction stm_register_devicefunction stm_unregister_devicefunction stm_source_link_addfunction __stm_source_link_dropfunction linkfunction stm_source_link_showfunction stm_source_link_storefunction stm_source_device_releasefunction stm_source_register_device
Annotated Snippet
static const struct file_operations stm_fops = {
.open = stm_char_open,
.release = stm_char_release,
.write = stm_char_write,
.mmap_prepare = stm_char_mmap_prepare,
.unlocked_ioctl = stm_char_ioctl,
.compat_ioctl = compat_ptr_ioctl,
};
static void stm_device_release(struct device *dev)
{
struct stm_device *stm = to_stm_device(dev);
vfree(stm);
}
int stm_register_device(struct device *parent, struct stm_data *stm_data,
struct module *owner)
{
struct stm_device *stm;
unsigned int nmasters;
int err = -ENOMEM;
if (!stm_core_up)
return -EPROBE_DEFER;
if (!stm_data->packet || !stm_data->sw_nchannels)
return -EINVAL;
nmasters = stm_data->sw_end - stm_data->sw_start + 1;
stm = vzalloc(sizeof(*stm) + nmasters * sizeof(void *));
if (!stm)
return -ENOMEM;
stm->major = register_chrdev(0, stm_data->name, &stm_fops);
if (stm->major < 0) {
err = stm->major;
vfree(stm);
return err;
}
device_initialize(&stm->dev);
stm->dev.devt = MKDEV(stm->major, 0);
stm->dev.class = &stm_class;
stm->dev.parent = parent;
stm->dev.release = stm_device_release;
mutex_init(&stm->link_mutex);
spin_lock_init(&stm->link_lock);
INIT_LIST_HEAD(&stm->link_list);
/* initialize the object before it is accessible via sysfs */
spin_lock_init(&stm->mc_lock);
mutex_init(&stm->policy_mutex);
stm->sw_nmasters = nmasters;
stm->owner = owner;
stm->data = stm_data;
stm_data->stm = stm;
err = kobject_set_name(&stm->dev.kobj, "%s", stm_data->name);
if (err)
goto err_device;
err = device_add(&stm->dev);
if (err)
goto err_device;
/*
* Use delayed autosuspend to avoid bouncing back and forth
* on recurring character device writes, with the initial
* delay time of 2 seconds.
*/
pm_runtime_no_callbacks(&stm->dev);
pm_runtime_use_autosuspend(&stm->dev);
pm_runtime_set_autosuspend_delay(&stm->dev, 2000);
pm_runtime_set_suspended(&stm->dev);
pm_runtime_enable(&stm->dev);
return 0;
err_device:
unregister_chrdev(stm->major, stm_data->name);
/* calls stm_device_release() */
put_device(&stm->dev);
return err;
}
EXPORT_SYMBOL_GPL(stm_register_device);
Annotation
- Immediate include surface: `linux/pm_runtime.h`, `linux/uaccess.h`, `linux/kernel.h`, `linux/module.h`, `linux/device.h`, `linux/compat.h`, `linux/kdev_t.h`, `linux/srcu.h`.
- Detected declarations: `struct stm_pdrv_entry`, `function masters_show`, `function channels_show`, `function hw_override_show`, `function stm_find_device`, `function stm_put_device`, `function stm_master`, `function stp_master_alloc`, `function stp_master_free`, `function stm_output_claim`.
- Atlas domain: Driver Families / drivers/hwtracing.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.