sound/soc/codecs/wm_adsp_fw_find_test.c

Source file repositories/reference/linux-study-clean/sound/soc/codecs/wm_adsp_fw_find_test.c

File Facts

System
Linux kernel
Corpus path
sound/soc/codecs/wm_adsp_fw_find_test.c
Extension
.c
Size
47166 bytes
Lines
1261
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.

Dependency Surface

Detected Declarations

Annotated Snippet

struct wm_adsp_fw_find_test {
	struct wm_adsp dsp;

	struct wm_adsp_fw_files found_fw;
	char searched_fw_files[768];
};

struct wm_adsp_fw_find_test_params {
	const char *part;
	const char *dsp_name;
	const char *fwf_name;
	const char *system_name;
	const char *alsa_name;
	bool wmfw_optional;
	bool bin_mandatory;

	/* If non-NULL this file should be returned as "found" */
	const char *expect_wmfw;

	/* If non-NULL this file should be returned as "found" */
	const char *expect_bin;

	/* Space-separated list of filenames in expected order of searching */
	const char *expected_searches;

	/* NULL-terminated array of pointers to filenames to simulate directory content */
	const char * const *dir_files;
};

/* Dummy struct firmware to return from wm_adsp_request_firmware_files */
static const struct firmware wm_adsp_find_test_dummy_firmware;

static void wm_adsp_fw_find_test_release_firmware_files_stub(struct wm_adsp_fw_files *fw)
{
	/*
	 * fw->wmfw.firmware and fw->coeff.firmware allocated by this KUnit
	 * test are dummies not allocated by the real request_firmware() call
	 * so they must not be passed to release_firmware().
	 * This function replaces wm_adsp_release_firmware_files().
	 */

	if (!fw)
		return;

	kfree(fw->wmfw.filename);
	kfree(fw->coeff.filename);

	fw->wmfw.firmware = NULL;
	fw->coeff.firmware = NULL;
	fw->wmfw.filename = NULL;
	fw->coeff.filename = NULL;
}

static void wm_adsp_free_found_fw(struct kunit *test)
{
	struct wm_adsp_fw_find_test *priv = test->priv;

	wm_adsp_fw_find_test_release_firmware_files_stub(&priv->found_fw);
}

/* Simple lookup of a filename in a list of names */
static int wm_adsp_fw_find_test_firmware_request_simple_stub(const struct firmware **firmware,
							     const char *filename,
							     struct device *dev)
{
	struct kunit *test = kunit_get_current_test();
	const struct wm_adsp_fw_find_test_params *params = test->param_value;
	int i;

	/* Non-parameterized test? */
	if (!params)
		return -ENOENT;

	if (!params->dir_files)
		return -ENOENT;

	for (i = 0; params->dir_files[i]; i++) {
		if (strcmp(params->dir_files[i], filename) == 0) {
			*firmware = &wm_adsp_find_test_dummy_firmware;
			return 0;
		}
	}

	return -ENOENT;
}

static void wm_adsp_fw_find_test_pick_file(struct kunit *test)
{
	struct wm_adsp_fw_find_test *priv = test->priv;
	const struct wm_adsp_fw_find_test_params *params = test->param_value;

Annotation

Implementation Notes