1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * Support utilities for cs_dsp testing. 4 * 5 * Copyright (C) 2024 Cirrus Logic, Inc. and 6 * Cirrus Logic International Semiconductor Ltd. 7 */ 8 9 #include <linux/regmap.h> 10 #include <linux/firmware/cirrus/wmfw.h> 11 12 struct kunit; 13 struct cs_dsp_test; 14 struct cs_dsp_test_local; 15 16 /** 17 * struct cs_dsp_test - base class for test utilities 18 * 19 * @test: Pointer to struct kunit instance. 20 * @dsp: Pointer to struct cs_dsp instance. 21 * @local: Private data for each test suite. 22 */ 23 struct cs_dsp_test { 24 struct kunit *test; 25 struct cs_dsp *dsp; 26 27 struct cs_dsp_test_local *local; 28 29 /* Following members are private */ 30 bool saw_bus_write; 31 }; 32 33 /** 34 * struct cs_dsp_mock_alg_def - Info for creating a mock algorithm entry. 35 * 36 * @id Algorithm ID. 37 * @ver; Algorithm version. 38 * @xm_base_words XM base address in DSP words. 39 * @xm_size_words XM size in DSP words. 40 * @ym_base_words YM base address in DSP words. 41 * @ym_size_words YM size in DSP words. 42 * @zm_base_words ZM base address in DSP words. 43 * @zm_size_words ZM size in DSP words. 44 */ 45 struct cs_dsp_mock_alg_def { 46 unsigned int id; 47 unsigned int ver; 48 unsigned int xm_base_words; 49 unsigned int xm_size_words; 50 unsigned int ym_base_words; 51 unsigned int ym_size_words; 52 unsigned int zm_base_words; 53 unsigned int zm_size_words; 54 }; 55 56 struct cs_dsp_mock_coeff_def { 57 const char *shortname; 58 const char *fullname; 59 const char *description; 60 u16 type; 61 u16 flags; 62 u16 mem_type; 63 unsigned int offset_dsp_words; 64 unsigned int length_bytes; 65 }; 66 67 /** 68 * struct cs_dsp_mock_xm_header - XM header builder 69 * 70 * @test_priv: Pointer to the struct cs_dsp_test. 71 * @blob_data: Pointer to the created blob data. 72 * @blob_size_bytes: Size of the data at blob_data. 73 */ 74 struct cs_dsp_mock_xm_header { 75 struct cs_dsp_test *test_priv; 76 void *blob_data; 77 size_t blob_size_bytes; 78 }; 79 80 struct cs_dsp_mock_wmfw_builder; 81 struct cs_dsp_mock_bin_builder; 82 83 extern const unsigned int cs_dsp_mock_adsp2_32bit_sysbase; 84 extern const unsigned int cs_dsp_mock_adsp2_16bit_sysbase; 85 extern const unsigned int cs_dsp_mock_halo_core_base; 86 extern const unsigned int cs_dsp_mock_halo_sysinfo_base; 87 88 extern const struct cs_dsp_region cs_dsp_mock_halo_dsp1_regions[]; 89 extern const unsigned int cs_dsp_mock_halo_dsp1_region_sizes[]; 90 extern const struct cs_dsp_region cs_dsp_mock_adsp2_32bit_dsp1_regions[]; 91 extern const unsigned int cs_dsp_mock_adsp2_32bit_dsp1_region_sizes[]; 92 extern const struct cs_dsp_region cs_dsp_mock_adsp2_16bit_dsp1_regions[]; 93 extern const unsigned int cs_dsp_mock_adsp2_16bit_dsp1_region_sizes[]; 94 int cs_dsp_mock_count_regions(const unsigned int *region_sizes); 95 unsigned int cs_dsp_mock_size_of_region(const struct cs_dsp *dsp, int mem_type); 96 unsigned int cs_dsp_mock_base_addr_for_mem(struct cs_dsp_test *priv, int mem_type); 97 unsigned int cs_dsp_mock_reg_addr_inc_per_unpacked_word(struct cs_dsp_test *priv); 98 unsigned int cs_dsp_mock_reg_block_length_bytes(struct cs_dsp_test *priv, int mem_type); 99 unsigned int cs_dsp_mock_reg_block_length_registers(struct cs_dsp_test *priv, int mem_type); 100 unsigned int cs_dsp_mock_reg_block_length_dsp_words(struct cs_dsp_test *priv, int mem_type); 101 bool cs_dsp_mock_has_zm(struct cs_dsp_test *priv); 102 int cs_dsp_mock_packed_to_unpacked_mem_type(int packed_mem_type); 103 unsigned int cs_dsp_mock_num_dsp_words_to_num_packed_regs(unsigned int num_dsp_words); 104 unsigned int cs_dsp_mock_xm_header_get_alg_base_in_words(struct cs_dsp_test *priv, 105 unsigned int alg_id, 106 int mem_type); 107 unsigned int cs_dsp_mock_xm_header_get_fw_version_from_regmap(struct cs_dsp_test *priv); 108 unsigned int cs_dsp_mock_xm_header_get_fw_version(struct cs_dsp_mock_xm_header *header); 109 void cs_dsp_mock_xm_header_drop_from_regmap_cache(struct cs_dsp_test *priv); 110 int cs_dsp_mock_xm_header_write_to_regmap(struct cs_dsp_mock_xm_header *header); 111 struct cs_dsp_mock_xm_header *cs_dsp_create_mock_xm_header(struct cs_dsp_test *priv, 112 const struct cs_dsp_mock_alg_def *algs, 113 size_t num_algs); 114 115 int cs_dsp_mock_regmap_init(struct cs_dsp_test *priv); 116 void cs_dsp_mock_regmap_drop_range(struct cs_dsp_test *priv, 117 unsigned int first_reg, unsigned int last_reg); 118 void cs_dsp_mock_regmap_drop_regs(struct cs_dsp_test *priv, 119 unsigned int first_reg, size_t num_regs); 120 void cs_dsp_mock_regmap_drop_bytes(struct cs_dsp_test *priv, 121 unsigned int first_reg, size_t num_bytes); 122 void cs_dsp_mock_regmap_drop_system_regs(struct cs_dsp_test *priv); 123 bool cs_dsp_mock_regmap_is_dirty(struct cs_dsp_test *priv, bool drop_system_regs); 124 125 struct cs_dsp_mock_bin_builder *cs_dsp_mock_bin_init(struct cs_dsp_test *priv, 126 int format_version, 127 unsigned int fw_version); 128 void cs_dsp_mock_bin_add_raw_block(struct cs_dsp_mock_bin_builder *builder, 129 unsigned int alg_id, unsigned int alg_ver, 130 int type, unsigned int offset, 131 const void *payload_data, size_t payload_len_bytes); 132 void cs_dsp_mock_bin_add_info(struct cs_dsp_mock_bin_builder *builder, 133 const char *info); 134 void cs_dsp_mock_bin_add_name(struct cs_dsp_mock_bin_builder *builder, 135 const char *name); 136 void cs_dsp_mock_bin_add_patch(struct cs_dsp_mock_bin_builder *builder, 137 unsigned int alg_id, unsigned int alg_ver, 138 int mem_region, unsigned int reg_addr_offset, 139 const void *payload_data, size_t payload_len_bytes); 140 struct firmware *cs_dsp_mock_bin_get_firmware(struct cs_dsp_mock_bin_builder *builder); 141 142 struct cs_dsp_mock_wmfw_builder *cs_dsp_mock_wmfw_init(struct cs_dsp_test *priv, 143 int format_version); 144 void cs_dsp_mock_wmfw_add_raw_block(struct cs_dsp_mock_wmfw_builder *builder, 145 int mem_region, unsigned int mem_offset_dsp_words, 146 const void *payload_data, size_t payload_len_bytes); 147 void cs_dsp_mock_wmfw_add_info(struct cs_dsp_mock_wmfw_builder *builder, 148 const char *info); 149 void cs_dsp_mock_wmfw_add_data_block(struct cs_dsp_mock_wmfw_builder *builder, 150 int mem_region, unsigned int mem_offset_dsp_words, 151 const void *payload_data, size_t payload_len_bytes); 152 void cs_dsp_mock_wmfw_start_alg_info_block(struct cs_dsp_mock_wmfw_builder *builder, 153 unsigned int alg_id, 154 const char *name, 155 const char *description); 156 void cs_dsp_mock_wmfw_add_coeff_desc(struct cs_dsp_mock_wmfw_builder *builder, 157 const struct cs_dsp_mock_coeff_def *def); 158 void cs_dsp_mock_wmfw_end_alg_info_block(struct cs_dsp_mock_wmfw_builder *builder); 159 struct firmware *cs_dsp_mock_wmfw_get_firmware(struct cs_dsp_mock_wmfw_builder *builder); 160 int cs_dsp_mock_wmfw_format_version(struct cs_dsp_mock_wmfw_builder *builder); 161