sound/soc/intel/avs/utils.c
Source file repositories/reference/linux-study-clean/sound/soc/intel/avs/utils.c
File Facts
- System
- Linux kernel
- Corpus path
sound/soc/intel/avs/utils.c- Extension
.c- Size
- 6741 bytes
- Lines
- 303
- Domain
- Driver Families
- Bucket
- sound/soc
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- 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/firmware.hlinux/kfifo.hlinux/slab.havs.hmessages.h
Detected Declarations
function avs_module_entry_indexfunction avs_module_id_entry_indexfunction avs_get_module_entryfunction avs_get_module_id_entryfunction avs_get_module_idfunction avs_is_module_ida_emptyfunction avs_module_ida_destroyfunction avs_module_ida_allocfunction avs_module_info_initfunction avs_module_info_freefunction avs_module_id_allocfunction avs_module_id_freefunction avs_request_firmwarefunction avs_request_firmwarefunction avs_release_firmwaresfunction list_for_each_entry_safe
Annotated Snippet
if (!ida_ptrs[i]) {
while (i--)
kfree(ida_ptrs[i]);
kfree(ida_ptrs);
return -ENOMEM;
}
ida_init(ida_ptrs[i]);
}
/* If old elements have been reused, don't wipe them. */
if (tocopy_count)
kfree(adev->mod_idas);
else
avs_module_ida_destroy(adev);
adev->mod_idas = ida_ptrs;
return 0;
}
int avs_module_info_init(struct avs_dev *adev, bool purge)
{
struct avs_mods_info *info;
int ret;
ret = avs_ipc_get_modules_info(adev, &info);
if (ret)
return AVS_IPC_RET(ret);
mutex_lock(&adev->modres_mutex);
ret = avs_module_ida_alloc(adev, info, purge);
if (ret < 0) {
dev_err(adev->dev, "initialize module idas failed: %d\n", ret);
goto exit;
}
/* Refresh current information with newly received table. */
kfree(adev->mods_info);
adev->mods_info = info;
exit:
mutex_unlock(&adev->modres_mutex);
return ret;
}
void avs_module_info_free(struct avs_dev *adev)
{
mutex_lock(&adev->modres_mutex);
avs_module_ida_destroy(adev);
kfree(adev->mods_info);
adev->mods_info = NULL;
mutex_unlock(&adev->modres_mutex);
}
int avs_module_id_alloc(struct avs_dev *adev, u16 module_id)
{
int ret, idx, max_id;
mutex_lock(&adev->modres_mutex);
idx = avs_module_id_entry_index(adev, module_id);
if (idx == -ENOENT) {
dev_err(adev->dev, "invalid module id: %d", module_id);
ret = -EINVAL;
goto exit;
}
max_id = adev->mods_info->entries[idx].instance_max_count - 1;
ret = ida_alloc_max(adev->mod_idas[idx], max_id, GFP_KERNEL);
exit:
mutex_unlock(&adev->modres_mutex);
return ret;
}
void avs_module_id_free(struct avs_dev *adev, u16 module_id, u8 instance_id)
{
int idx;
mutex_lock(&adev->modres_mutex);
idx = avs_module_id_entry_index(adev, module_id);
if (idx == -ENOENT) {
dev_err(adev->dev, "invalid module id: %d", module_id);
goto exit;
}
ida_free(adev->mod_idas[idx], instance_id);
Annotation
- Immediate include surface: `linux/firmware.h`, `linux/kfifo.h`, `linux/slab.h`, `avs.h`, `messages.h`.
- Detected declarations: `function avs_module_entry_index`, `function avs_module_id_entry_index`, `function avs_get_module_entry`, `function avs_get_module_id_entry`, `function avs_get_module_id`, `function avs_is_module_ida_empty`, `function avs_module_ida_destroy`, `function avs_module_ida_alloc`, `function avs_module_info_init`, `function avs_module_info_free`.
- Atlas domain: Driver Families / sound/soc.
- Implementation status: source 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.