drivers/firmware/cirrus/test/cs_dsp_mock_bin.c
Source file repositories/reference/linux-study-clean/drivers/firmware/cirrus/test/cs_dsp_mock_bin.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/firmware/cirrus/test/cs_dsp_mock_bin.c- Extension
.c- Size
- 8059 bytes
- Lines
- 234
- Domain
- Driver Families
- Bucket
- drivers/firmware
- 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
kunit/resource.hkunit/test.hlinux/firmware/cirrus/cs_dsp.hlinux/firmware/cirrus/cs_dsp_test_utils.hlinux/firmware/cirrus/wmfw.hlinux/firmware.hlinux/math.hlinux/overflow.hlinux/string.hlinux/vmalloc.h
Detected Declarations
struct cs_dsp_mock_bin_builderfunction cs_dsp_mock_bin_get_firmwarefunction cs_dsp_mock_bin_add_raw_blockfunction cs_dsp_mock_bin_add_name_or_infofunction cs_dsp_mock_bin_add_infofunction cs_dsp_mock_bin_add_namefunction cs_dsp_mock_bin_add_patchfunction cs_dsp_mock_bin_add_patch_off32function cs_dsp_mock_bin_init
Annotated Snippet
struct cs_dsp_mock_bin_builder {
struct cs_dsp_test *test_priv;
void *buf;
void *write_p;
size_t bytes_used;
};
/**
* cs_dsp_mock_bin_get_firmware() - Get struct firmware wrapper for data.
*
* @builder: Pointer to struct cs_dsp_mock_bin_builder.
*
* Return: Pointer to a struct firmware wrapper for the data.
*/
struct firmware *cs_dsp_mock_bin_get_firmware(struct cs_dsp_mock_bin_builder *builder)
{
struct firmware *fw;
fw = kunit_kzalloc(builder->test_priv->test, sizeof(*fw), GFP_KERNEL);
KUNIT_ASSERT_NOT_ERR_OR_NULL(builder->test_priv->test, fw);
fw->data = builder->buf;
fw->size = builder->bytes_used;
return fw;
}
EXPORT_SYMBOL_NS_GPL(cs_dsp_mock_bin_get_firmware, "FW_CS_DSP_KUNIT_TEST_UTILS");
/**
* cs_dsp_mock_bin_add_raw_block() - Add a data block to the bin file.
*
* @builder: Pointer to struct cs_dsp_mock_bin_builder.
* @alg_id: Algorithm ID.
* @alg_ver: Algorithm version.
* @type: Type of the block.
* @offset: 16-bit offset.
* @offset32: 32-bit offset (sample rate on V1 and V2 file formats).
* @payload_data: Pointer to buffer containing the payload data.
* @payload_len_bytes: Length of payload data in bytes.
*/
void cs_dsp_mock_bin_add_raw_block(struct cs_dsp_mock_bin_builder *builder,
unsigned int alg_id, unsigned int alg_ver,
int type, u16 offset, u32 offset32,
const void *payload_data, size_t payload_len_bytes)
{
struct wmfw_coeff_item *item;
size_t bytes_needed = struct_size_t(struct wmfw_coeff_item, data, payload_len_bytes);
KUNIT_ASSERT_TRUE(builder->test_priv->test,
(builder->write_p + bytes_needed) <
(builder->buf + CS_DSP_MOCK_BIN_BUF_SIZE));
item = builder->write_p;
item->offset = cpu_to_le16(offset);
item->offset32 = cpu_to_le32(offset32);
item->type = cpu_to_le16(type);
item->id = cpu_to_le32(alg_id);
item->ver = cpu_to_le32(alg_ver << 8);
item->len = cpu_to_le32(payload_len_bytes);
if (payload_len_bytes)
memcpy(item->data, payload_data, payload_len_bytes);
builder->write_p += bytes_needed;
builder->bytes_used += bytes_needed;
}
EXPORT_SYMBOL_NS_GPL(cs_dsp_mock_bin_add_raw_block, "FW_CS_DSP_KUNIT_TEST_UTILS");
static void cs_dsp_mock_bin_add_name_or_info(struct cs_dsp_mock_bin_builder *builder,
const char *info, int type)
{
size_t info_len = strlen(info);
char *tmp = NULL;
if (info_len % 4) {
/* Create a padded string with length a multiple of 4 */
size_t copy_len = info_len;
info_len = round_up(info_len, 4);
tmp = kunit_kzalloc(builder->test_priv->test, info_len, GFP_KERNEL);
KUNIT_ASSERT_NOT_ERR_OR_NULL(builder->test_priv->test, tmp);
memcpy(tmp, info, copy_len);
info = tmp;
}
cs_dsp_mock_bin_add_raw_block(builder, 0, 0, WMFW_INFO_TEXT, 0, 0, info, info_len);
kunit_kfree(builder->test_priv->test, tmp);
}
/**
Annotation
- Immediate include surface: `kunit/resource.h`, `kunit/test.h`, `linux/firmware/cirrus/cs_dsp.h`, `linux/firmware/cirrus/cs_dsp_test_utils.h`, `linux/firmware/cirrus/wmfw.h`, `linux/firmware.h`, `linux/math.h`, `linux/overflow.h`.
- Detected declarations: `struct cs_dsp_mock_bin_builder`, `function cs_dsp_mock_bin_get_firmware`, `function cs_dsp_mock_bin_add_raw_block`, `function cs_dsp_mock_bin_add_name_or_info`, `function cs_dsp_mock_bin_add_info`, `function cs_dsp_mock_bin_add_name`, `function cs_dsp_mock_bin_add_patch`, `function cs_dsp_mock_bin_add_patch_off32`, `function cs_dsp_mock_bin_init`.
- Atlas domain: Driver Families / drivers/firmware.
- 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.