sound/soc/sof/ipc4-control.c
Source file repositories/reference/linux-study-clean/sound/soc/sof/ipc4-control.c
File Facts
- System
- Linux kernel
- Corpus path
sound/soc/sof/ipc4-control.c- Extension
.c- Size
- 29112 bytes
- Lines
- 1038
- 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.
- 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
sof-priv.hsof-audio.hipc4-priv.hipc4-topology.h
Detected Declarations
function sof_ipc4_set_get_kcontrol_datafunction sof_ipc4_set_volume_datafunction sof_ipc4_volume_putfunction sof_ipc4_volume_getfunction sof_ipc4_set_generic_control_datafunction sof_ipc4_refresh_generic_controlfunction sof_ipc4_set_bytes_control_datafunction sof_ipc4_refresh_bytes_controlfunction sof_ipc4_switch_putfunction sof_ipc4_switch_getfunction sof_ipc4_enum_putfunction sof_ipc4_enum_getfunction sof_ipc4_set_get_bytes_datafunction sof_ipc4_bytes_putfunction sof_ipc4_bytes_getfunction sof_ipc4_bytes_ext_putfunction _sof_ipc4_bytes_ext_getfunction sof_ipc4_bytes_ext_getfunction sof_ipc4_bytes_ext_volatile_getfunction sof_ipc4_volsw_setupfunction sof_ipc4_control_updatefunction sof_ipc4_widget_kcontrol_setupfunction list_for_each_entryfunction sof_ipc4_set_up_volume_table
Annotated Snippet
if (swidget->comp_id == scontrol->comp_id) {
widget_found = true;
break;
}
}
if (!widget_found) {
dev_err(scomp->dev, "Failed to find widget for kcontrol %s\n", scontrol->name);
return -ENOENT;
}
if (lock)
mutex_lock(&swidget->setup_mutex);
else
lockdep_assert_held(&swidget->setup_mutex);
/*
* Volatile controls should always be part of static pipelines and the
* widget use_count would always be > 0 in this case. For the others,
* just return the cached value if the widget is not set up.
*/
if (!swidget->use_count)
goto unlock;
msg->primary &= ~SOF_IPC4_MOD_INSTANCE_MASK;
msg->primary |= SOF_IPC4_MOD_INSTANCE(swidget->instance_id);
ret = iops->set_get_data(sdev, msg, msg->data_size, set);
if (!set)
goto unlock;
/* It is a set-data operation, and we have a valid backup that we can restore */
if (ret < 0) {
if (!scontrol->old_ipc_control_data)
goto unlock;
/*
* Current ipc_control_data is not valid, we use the last known good
* configuration
*/
memcpy(scontrol->ipc_control_data, scontrol->old_ipc_control_data,
scontrol->size);
kfree(scontrol->old_ipc_control_data);
scontrol->old_ipc_control_data = NULL;
/* Send the last known good configuration to firmware */
ret = iops->set_get_data(sdev, msg, msg->data_size, set);
if (ret < 0)
goto unlock;
}
unlock:
if (lock)
mutex_unlock(&swidget->setup_mutex);
return ret;
}
static int
sof_ipc4_set_volume_data(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget,
struct snd_sof_control *scontrol, bool lock)
{
struct sof_ipc4_control_data *cdata = scontrol->ipc_control_data;
struct sof_ipc4_gain *gain = swidget->private;
struct sof_ipc4_gain_params params;
bool all_channels_equal = true;
struct sof_ipc4_msg msg;
u32 value;
int ret, i;
/* check if all channel values are equal */
value = cdata->chanv[0].value;
for (i = 1; i < scontrol->num_channels; i++) {
if (cdata->chanv[i].value != value) {
all_channels_equal = false;
break;
}
}
/*
* notify DSP with a single IPC message if all channel values are equal. Otherwise send
* a separate IPC for each channel.
*/
memcpy(&msg, &cdata->msg, sizeof(msg));
for (i = 0; i < scontrol->num_channels; i++) {
if (all_channels_equal) {
params.channels = SOF_IPC4_GAIN_ALL_CHANNELS_MASK;
params.init_val = cdata->chanv[0].value;
} else {
params.channels = cdata->chanv[i].channel;
params.init_val = cdata->chanv[i].value;
}
Annotation
- Immediate include surface: `sof-priv.h`, `sof-audio.h`, `ipc4-priv.h`, `ipc4-topology.h`.
- Detected declarations: `function sof_ipc4_set_get_kcontrol_data`, `function sof_ipc4_set_volume_data`, `function sof_ipc4_volume_put`, `function sof_ipc4_volume_get`, `function sof_ipc4_set_generic_control_data`, `function sof_ipc4_refresh_generic_control`, `function sof_ipc4_set_bytes_control_data`, `function sof_ipc4_refresh_bytes_control`, `function sof_ipc4_switch_put`, `function sof_ipc4_switch_get`.
- Atlas domain: Driver Families / sound/soc.
- Implementation status: source 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.