sound/soc/sof/sof-client-ipc-flood-test.c

Source file repositories/reference/linux-study-clean/sound/soc/sof/sof-client-ipc-flood-test.c

File Facts

System
Linux kernel
Corpus path
sound/soc/sof/sof-client-ipc-flood-test.c
Extension
.c
Size
10536 bytes
Lines
385
Domain
Driver Families
Bucket
sound/soc
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.

Dependency Surface

Detected Declarations

Annotated Snippet

static const struct file_operations sof_ipc_flood_fops = {
	.open = sof_ipc_flood_dfs_open,
	.read = sof_ipc_flood_dfs_read,
	.llseek = default_llseek,
	.write = sof_ipc_flood_dfs_write,
	.release = sof_ipc_flood_dfs_release,

	.owner = THIS_MODULE,
};

/*
 * The IPC test client creates a couple of debugfs entries that will be used
 * flood tests. Users can write to these entries to execute the IPC flood test
 * by specifying either the number of IPCs to flood the DSP with or the duration
 * (in ms) for which the DSP should be flooded with test IPCs. At the
 * end of each test, the average, min and max response times are reported back.
 * The results of the last flood test can be accessed by reading the debugfs
 * entries.
 */
static int sof_ipc_flood_probe(struct auxiliary_device *auxdev,
			       const struct auxiliary_device_id *id)
{
	struct sof_client_dev *cdev = auxiliary_dev_to_sof_client_dev(auxdev);
	struct dentry *debugfs_root = sof_client_get_debugfs_root(cdev);
	struct device *dev = &auxdev->dev;
	struct sof_ipc_flood_priv *priv;

	/* allocate memory for client data */
	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
	if (!priv)
		return -ENOMEM;

	priv->buf = devm_kmalloc(dev, IPC_FLOOD_TEST_RESULT_LEN, GFP_KERNEL);
	if (!priv->buf)
		return -ENOMEM;

	cdev->data = priv;

	/* create debugfs root folder with device name under parent SOF dir */
	priv->dfs_root = debugfs_create_dir(dev_name(dev), debugfs_root);
	if (!IS_ERR_OR_NULL(priv->dfs_root)) {
		/* create read-write ipc_flood_count debugfs entry */
		debugfs_create_file_aux_num(DEBUGFS_IPC_FLOOD_COUNT, 0644,
				    priv->dfs_root, cdev, 0, &sof_ipc_flood_fops);

		/* create read-write ipc_flood_duration_ms debugfs entry */
		debugfs_create_file_aux_num(DEBUGFS_IPC_FLOOD_DURATION, 0644,
				    priv->dfs_root, cdev, 1, &sof_ipc_flood_fops);

		if (auxdev->id == 0) {
			/*
			 * Create symlinks for backwards compatibility to the
			 * first IPC flood test instance
			 */
			char target[100];

			snprintf(target, 100, "%s/" DEBUGFS_IPC_FLOOD_COUNT,
				 dev_name(dev));
			priv->dfs_link[0] =
				debugfs_create_symlink(DEBUGFS_IPC_FLOOD_COUNT,
						       debugfs_root, target);

			snprintf(target, 100, "%s/" DEBUGFS_IPC_FLOOD_DURATION,
				 dev_name(dev));
			priv->dfs_link[1] =
				debugfs_create_symlink(DEBUGFS_IPC_FLOOD_DURATION,
						       debugfs_root, target);
		}
	}

	/* enable runtime PM */
	pm_runtime_set_autosuspend_delay(dev, SOF_IPC_CLIENT_SUSPEND_DELAY_MS);
	pm_runtime_use_autosuspend(dev);
	pm_runtime_enable(dev);
	pm_runtime_mark_last_busy(dev);
	pm_runtime_idle(dev);

	return 0;
}

static void sof_ipc_flood_remove(struct auxiliary_device *auxdev)
{
	struct sof_client_dev *cdev = auxiliary_dev_to_sof_client_dev(auxdev);
	struct sof_ipc_flood_priv *priv = cdev->data;

	pm_runtime_disable(&auxdev->dev);

	if (auxdev->id == 0) {
		debugfs_remove(priv->dfs_link[0]);
		debugfs_remove(priv->dfs_link[1]);

Annotation

Implementation Notes