1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  * Copyright(c) 2022 Intel Corporation. All rights reserved.
4  */
5 
6 #ifndef _MODULE_INITIAL_SETTINGS_CONCRETE_H
7 #define _MODULE_INITIAL_SETTINGS_CONCRETE_H
8 
9 #include "module_initial_settings.h"
10 #include <utilities/array.h>
11 #include <sof/compiler_attributes.h>
12 
13 #include <stddef.h>
14 
15 #pragma pack(push, 4)
16 struct BaseModuleCfgExt {
17 	/*!
18 	 * \brief Specifies number of items in input_pins array. Maximum size is 8.
19 	 */
20 	uint16_t nb_input_pins;
21 	/*!
22 	 * \brief Specifies number of items in output_pins array. Maximum size is 8.
23 	 */
24 	uint16_t nb_output_pins;
25 	/*!
26 	 * \brief Not used, set to 0.
27 	 */
28 	uint8_t  reserved[12];
29 	/*!
30 	 * \brief Specifies format of input pins.
31 	 * \remarks Pin format arrays may be non-continuous i.e. may contain pin #0
32 	 * format followed by pin #2 format
33 	 * in case pin #1 will not be in use. FW assigned format of the pin based
34 	 * on pin_index, not on a position of the item in the array.
35 	 * Applies to both input and output pins.
36 	 */
37 	InputPinFormat input_pins[1];
38 	/*!
39 	 * \brief Specifies format of output pins.
40 	 */
41 	OutputPinFormat output_pins[1];
42 };
43 #pragma pack(pop)
44 
45 namespace dsp_fw
46 {
47 /*! \brief concrete implementation of the intel_adsp::ModuleInitialSettingsInterface
48  *
49  * Allow to retrieve the settings items in the INIT_INSTANCE IPC message
50  */
51 struct ModuleInitialSettingsConcrete : public intel_adsp::ModuleInitialSettingsInterface
52 {
53 	/*! \brief Initializes a new ModuleInitialSettingsConcrete instance given
54 	 *  an INIT_INSTANCE IPC message blob
55 	 */
56 	explicit ModuleInitialSettingsConcrete(DwordArray const &cfg_ipc_msg);
57 
58 	/*! \brief Extrapolates some hard-coded BaseModuleCfgExt based on the legacy
59 	 * BaseModuleCfg and the given input count and output count.
60 	 *  \remarks If BaseModuleCfgExt was actually already part of
61 	 *  the INIT_INSTANCE IPC message, nothing is performed.
62 	 */
63 	void DeduceBaseModuleCfgExt(size_t in_pins_count, size_t out_pins_count);
64 
65 	/*! \brief Gets the untyped value array of the settings item for the given key
66 	 *  \note In this methods it is assumed that the given INIT_INSTANCE IPC message
67 	 *   has a valid content
68 	 *  \warning IsParsable() result shall have been checked before invoking this method.
69 	 */
70 	virtual void const *GetUntypedItem(intel_adsp::ModuleInitialSettingsKey key,
71 					   size_t &length);
72 
73 	/*! \brief Indicates if the given INIT_INSTANCE IPC message is parse-able */
IsParsableModuleInitialSettingsConcrete74 	bool IsParsable(void) const
75 	{
76 		return ((cfg_ != NULL) || (cfg_ext_ != NULL));
77 	}
78 
79 	/*! \brief Gets pointer on the BaseModuleCfg data retrieved from the IPC message */
GetBaseModuleCfgModuleInitialSettingsConcrete80 	BaseModuleCfg const *GetBaseModuleCfg(void) const
81 	{
82 		return cfg_;
83 	}
84 
85 	/*! \brief Gets pointer on the BaseModuleCfgExt data retrieved from the IPC message */
GetBaseModuleCfgExtModuleInitialSettingsConcrete86 	BaseModuleCfgExt const *GetBaseModuleCfgExt(void) const
87 	{
88 		return cfg_ext_;
89 	}
90 
91 private:
92 	BaseModuleCfg const *cfg_;
93 	BaseModuleCfgExt const *cfg_ext_;
94 	/* temporary extended module config for case where it is not part of
95 	 * the INIT_INSTANCE IPC message
96 	 */
97 	union {
98 		BaseModuleCfgExt tlv;
99 		/* struct below reserved the placeholder for the biggest possible BaseModuleCfgExt
100 		 * block.
101 		 */
102 		struct {
103 			uint16_t           do_not_use1;
104 			uint16_t           do_not_use2;
105 			uint8_t            do_not_use3[8];
106 			uint32_t           do_not_use4;
107 			InputPinFormat     do_not_use5[INPUT_PIN_COUNT];
108 			OutputPinFormat    do_not_use6[OUTPUT_PIN_COUNT];
109 		} placeholder;
110 	} tmp_cfg_ext_;
111 };
112 }
113 
114 #endif /*_MODULE_INITIAL_SETTINGS_CONCRETE_H */
115