sound/soc/sof/ipc.c
Source file repositories/reference/linux-study-clean/sound/soc/sof/ipc.c
File Facts
- System
- Linux kernel
- Corpus path
sound/soc/sof/ipc.c- Extension
.c- Size
- 5985 bytes
- Lines
- 233
- Domain
- Driver Families
- Bucket
- sound/soc
- 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.
- 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/mutex.hlinux/types.hsof-priv.hsof-audio.hops.h
Detected Declarations
function sof_ipc_send_msgfunction sof_ipc_tx_messagefunction sof_ipc_set_get_datafunction sof_ipc_tx_message_no_pmfunction snd_sof_ipc_get_replyfunction snd_sof_ipc_replyfunction snd_sof_ipc_freeexport sof_ipc_tx_messageexport sof_ipc_set_get_dataexport sof_ipc_tx_message_no_pmexport snd_sof_ipc_get_replyexport snd_sof_ipc_replyexport snd_sof_ipc_initexport snd_sof_ipc_free
Annotated Snippet
// SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
//
// This file is provided under a dual BSD/GPLv2 license. When using or
// redistributing this file, you may do so under either license.
//
// Copyright(c) 2018 Intel Corporation
//
// Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
//
// Generic IPC layer that can work over MMIO and SPI/I2C. PHY layer provided
// by platform driver code.
//
#include <linux/mutex.h>
#include <linux/types.h>
#include "sof-priv.h"
#include "sof-audio.h"
#include "ops.h"
/**
* sof_ipc_send_msg - generic function to prepare and send one IPC message
* @sdev: pointer to SOF core device struct
* @msg_data: pointer to a message to send
* @msg_bytes: number of bytes in the message
* @reply_bytes: number of bytes available for the reply.
* The buffer for the reply data is not passed to this
* function, the available size is an information for the
* reply handling functions.
*
* On success the function returns 0, otherwise negative error number.
*
* Note: higher level sdev->ipc->tx_mutex must be held to make sure that
* transfers are synchronized.
*/
int sof_ipc_send_msg(struct snd_sof_dev *sdev, void *msg_data, size_t msg_bytes,
size_t reply_bytes)
{
struct snd_sof_ipc *ipc = sdev->ipc;
struct snd_sof_ipc_msg *msg;
int ret;
if (ipc->disable_ipc_tx || sdev->fw_state != SOF_FW_BOOT_COMPLETE)
return -ENODEV;
/*
* The spin-lock is needed to protect message objects against other
* atomic contexts.
*/
guard(spinlock_irq)(&sdev->ipc_lock);
/* initialise the message */
msg = &ipc->msg;
/* attach message data */
msg->msg_data = msg_data;
msg->msg_size = msg_bytes;
msg->reply_size = reply_bytes;
msg->reply_error = 0;
sdev->msg = msg;
ret = snd_sof_dsp_send_msg(sdev, msg);
/* Next reply that we receive will be related to this message */
if (!ret)
msg->ipc_complete = false;
return ret;
}
/* send IPC message from host to DSP */
int sof_ipc_tx_message(struct snd_sof_ipc *ipc, void *msg_data, size_t msg_bytes,
void *reply_data, size_t reply_bytes)
{
if (msg_bytes > ipc->max_payload_size ||
reply_bytes > ipc->max_payload_size)
return -ENOBUFS;
return ipc->ops->tx_msg(ipc->sdev, msg_data, msg_bytes, reply_data,
reply_bytes, false);
}
EXPORT_SYMBOL(sof_ipc_tx_message);
/* IPC set or get data from host to DSP */
int sof_ipc_set_get_data(struct snd_sof_ipc *ipc, void *msg_data,
size_t msg_bytes, bool set)
{
return ipc->ops->set_get_data(ipc->sdev, msg_data, msg_bytes, set);
}
Annotation
- Immediate include surface: `linux/mutex.h`, `linux/types.h`, `sof-priv.h`, `sof-audio.h`, `ops.h`.
- Detected declarations: `function sof_ipc_send_msg`, `function sof_ipc_tx_message`, `function sof_ipc_set_get_data`, `function sof_ipc_tx_message_no_pm`, `function snd_sof_ipc_get_reply`, `function snd_sof_ipc_reply`, `function snd_sof_ipc_free`, `export sof_ipc_tx_message`, `export sof_ipc_set_get_data`, `export sof_ipc_tx_message_no_pm`.
- Atlas domain: Driver Families / sound/soc.
- Implementation status: integration implementation candidate.
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.