Sound Open Firmware
Loading...
Searching...
No Matches
kpb.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-3-Clause
2 *
3 * Copyright(c) 2019 Intel Corporation. All rights reserved.
4 *
5 * Author: Marcin Rajwa <marcin.rajwa@linux.intel.com>
6 */
7
8#ifndef __SOF_AUDIO_KPB_H__
9#define __SOF_AUDIO_KPB_H__
10
11#include <sof/trace/trace.h>
12#include <user/trace.h>
13#include <stdint.h>
14
15#if defined(__XCC__)
16
17#include <xtensa/config/core-isa.h>
18#if XCHAL_HAVE_HIFI3 || XCHAL_HAVE_HIFI4
19#define KPB_HIFI3
20#endif
21
22#endif
23struct comp_buffer;
24
25/* KPB internal defines */
26
27#if CONFIG_TIGERLAKE
28#define KPB_MAX_BUFF_TIME 3000
29#define HOST_WAKEUP_TIME 1000 /* aprox. time of host DMA wakup from suspend [ms] */
30#else
32#define KPB_MAX_BUFF_TIME 2100
33#define HOST_WAKEUP_TIME 0 /* aprox. time of host DMA wakup from suspend [ms] */
34#endif
35
36#define KPB_MAX_DRAINING_REQ (KPB_MAX_BUFF_TIME - HOST_WAKEUP_TIME)
37#define KPB_MAX_SUPPORTED_CHANNELS 6
39#define KPB_SAMPLES_PER_MS (KPB_SAMPLNG_FREQUENCY / 1000)
40#define KPB_SAMPLNG_FREQUENCY 16000
41#define KPB_SAMPLE_CONTAINER_SIZE(sw) ((sw == 16) ? 16 : 32)
42#define KPB_MAX_BUFFER_SIZE(sw, channels_number) ((KPB_SAMPLNG_FREQUENCY / 1000) * \
43 (KPB_SAMPLE_CONTAINER_SIZE(sw) / 8) * KPB_MAX_BUFF_TIME * \
44 (channels_number))
45#define KPB_MAX_NO_OF_CLIENTS 4
46#define KPB_MAX_SINK_CNT (1 + KPB_MAX_NO_OF_CLIENTS)
47#define KPB_NO_OF_HISTORY_BUFFERS 2
48#define KPB_ALLOCATION_STEP 0x100
49#define KPB_NO_OF_MEM_POOLS 5
50#define KPB_BYTES_TO_FRAMES(bytes, sample_width, channels_number) \
51 ((bytes) / ((KPB_SAMPLE_CONTAINER_SIZE(sample_width) / 8) * \
52 (channels_number)))
53
54#define KPB_DRAIN_NUM_OF_PPL_PERIODS_AT_ONCE 2
56#define HOST_BUFFER_MIN_SIZE(hb, channels_number) ((hb) * (channels_number))
57
59#define KPB_BYTES_TO_S16_SAMPLES(s) ((s) >> 1)
60#define KPB_BYTES_TO_S32_SAMPLES(s) ((s) >> 2)
62/* Macro that returns mask with selected bits set */
63#define KPB_COUNT_TO_BITMASK(cnt) (((0x1 << (cnt)) - 1))
64#define KPB_IS_BIT_SET(value, idx) ((value) & (1 << (idx)))
65#define KPB_REFERENCE_SUPPORT_CHANNELS 2
66/* Maximum number of channels in the micsel mask is 4,
67 * i.e. number of max supported channels - reference channels)
68 */
69#define KPB_MAX_MICSEL_CHANNELS 4
70/* Used in FMT */
71#define FAST_MODE_TASK_MAX_MODULES_COUNT 16
72#define REALTIME_PIN_ID 0
82enum kpb_state {
104 enum kpb_event event_id;
116 uint8_t id;
124 KPB_BUFFER_FREE = 0,
130 KPB_LP = 0,
135 enum buffer_state state;
137 void *end_addr;
138 void *w_ptr;
139 void *r_ptr;
144/* Draining task data */
145struct draining_data {
146 struct comp_buffer *sink;
168 size_t buffer_size;
169 size_t buffered;
170 size_t free;
174/* moved to ipc4/kpb.h */
175/* enum ipc4_kpb_module_config_params */
176
177/* Stores KPB mic selector config */
179 /* channel bit set to 1 implies channel selection */
180 uint32_t mask;
181};
183struct kpb_task_params {
184 /* If largeconfigset is set to KP_POS_IN_BUFFER then number of modules must
185 * correspond to number of modules between kpb and copier attached to hostdma.
186 * Once draining path is configured, cannot be reinitialized/changed.
187 */
188 uint32_t number_of_modules;
189 struct {
190 uint16_t module_id;
191 uint16_t instance_id;
195/* fmt namespace: */
196#define FAST_MODE_TASK_MAX_LIST_COUNT 5
197
201};
203/* The +1 is here because we also push the kbp device
204 * handle in addition to the max number of modules
205 */
206#define DEVICE_LIST_SIZE (FAST_MODE_TASK_MAX_MODULES_COUNT + 1)
207
208/* Devicelist type
209 * In Reference FW KPB used Bi-dir lists to store modules for FMT. It is possible that lists are
210 * not necessary, but in case it might be wrong, here we use an array
211 * with a list interface to switch it to a list easily.
212 */
213struct device_list {
215 /* number of items AND index of next empty box */
216 size_t count;
217};
219/*
220 *
221 *
222 * KPB FMT config set steps:
223 * 1. Get dev_ids of module instances from IPC
224 * 2. Alloc this kpb module instance on kpb_list_item, save address of where it was allocated
225 * 3. Push the address on dev_list.device_list
226 * 2. For each dev_id get device handler(module instance)
227 * 3. Alloc device handler in modules_list_item, save address of where it was allocated
228 * 4. Register this address in fmt.device_list
229 *
230 * Pointer structure:
231 *
232 * COMP_DEVS
233 * ^
234 * |
235 * dev_list.modules_list_item(comp_dev* )
236 * ^
237 * |
238 * dev_list.device_list(comp_dev**)
239 * ^
240 * |
241 * fmt.device_list(device_list*)
242 *
243 *
244 */
245
246/* KpbFastModeTaskModulesList Namespace */
247struct kpb_fmt_dev_list {
257void sys_comp_kpb_init(void);
258#endif
259
260#endif /* __SOF_AUDIO_KPB_H__ */
comp_copy_type
Type of next dma copy mode, changed on runtime.
Definition component.h:267
#define FAST_MODE_TASK_MAX_MODULES_COUNT
Definition kpb.h:73
buffer_state
Definition kpb.h:125
@ KPB_BUFFER_OFF
Definition kpb.h:128
@ KPB_BUFFER_FULL
Definition kpb.h:127
@ KPB_BUFFER_FREE
Definition kpb.h:126
#define DEVICE_LIST_SIZE
Definition kpb.h:208
kpb_state
All states below as well as relations between them are documented in the sof-dosc in kpbm-state-diagr...
Definition kpb.h:84
@ KPB_STATE_INIT_DRAINING
Definition kpb.h:91
@ KPB_STATE_HOST_COPY
Definition kpb.h:93
@ KPB_STATE_RESET_FINISHING
Definition kpb.h:86
@ KPB_STATE_RUN
Definition kpb.h:89
@ KPB_STATE_DISABLED
Definition kpb.h:85
@ KPB_STATE_DRAINING
Definition kpb.h:92
@ KPB_STATE_BUFFERING
Definition kpb.h:90
@ KPB_STATE_PREPARING
Definition kpb.h:88
@ KPB_STATE_RESETTING
Definition kpb.h:94
@ KPB_STATE_CREATED
Definition kpb.h:87
kpb_client_state
Definition kpb.h:110
@ KPB_CLIENT_BUFFERING
Definition kpb.h:112
@ KPB_CLIENT_DRAINNING_OD
draining on demand
Definition kpb.h:114
@ KPB_CLIENT_UNREGISTERED
Definition kpb.h:111
@ KPB_CLIENT_DRAINNING
Definition kpb.h:113
kpb_id
Definition kpb.h:131
@ KPB_LP
Definition kpb.h:132
@ KPB_HP
Definition kpb.h:133
#define KPB_MAX_SINK_CNT
Definition kpb.h:46
kpb_event
Definition kpb.h:97
@ KPB_EVENT_REGISTER_CLIENT
Definition kpb.h:98
@ KPB_EVENT_BEGIN_DRAINING
Definition kpb.h:100
@ KPB_EVENT_UNREGISTER_CLIENT
Definition kpb.h:102
@ KPB_EVENT_STOP_DRAINING
Definition kpb.h:101
@ KPB_EVENT_UPDATE_PARAMS
Definition kpb.h:99
#define FAST_MODE_TASK_MAX_LIST_COUNT
Definition kpb.h:198
Definition buffer.h:130
Audio component base device "class".
Definition component.h:645
Definition kpb.h:215
size_t count
Definition kpb.h:218
struct comp_dev ** devs[DEVICE_LIST_SIZE]
Definition kpb.h:216
Definition kpb.h:147
uint64_t prev_adjustment_time
Definition kpb.h:165
uint64_t period_copy_start
Definition kpb.h:157
size_t drain_req
Definition kpb.h:150
uint64_t draining_time_start
Definition kpb.h:155
size_t task_iteration
Definition kpb.h:164
size_t sample_width
Definition kpb.h:153
size_t drain_interval
Definition kpb.h:156
struct comp_buffer * sink
Definition kpb.h:148
enum comp_copy_type copy_type
Definition kpb.h:163
size_t prev_adjustment_drained
Definition kpb.h:166
struct history_buffer * hb
Definition kpb.h:149
size_t drained
Definition kpb.h:151
uint8_t is_draining_active
Definition kpb.h:152
bool sync_mode_on
Definition kpb.h:162
size_t pb_limit
Period bytes limit.
Definition kpb.h:158
size_t period_bytes
Definition kpb.h:159
size_t buffered_while_draining
Definition kpb.h:154
struct comp_dev * dev
Definition kpb.h:161
uint64_t next_copy_time
Definition kpb.h:160
Definition kpb.h:200
struct device_list * device_list[FAST_MODE_TASK_MAX_LIST_COUNT]
Definition kpb.h:202
Definition kpb.h:136
struct history_buffer * next
next history buffer
Definition kpb.h:142
void * end_addr
buffer end address
Definition kpb.h:139
void * w_ptr
buffer write pointer
Definition kpb.h:140
enum buffer_state state
state of the buffer
Definition kpb.h:137
void * start_addr
buffer start address
Definition kpb.h:138
struct history_buffer * prev
next history buffer
Definition kpb.h:143
void * r_ptr
buffer read pointer
Definition kpb.h:141
Definition kpb.h:169
struct history_buffer * c_hb
spce we can use to write new data
Definition kpb.h:173
size_t free
Definition kpb.h:172
size_t buffered
amount of buffered data
Definition kpb.h:171
size_t buffer_size
size of internal history buffer
Definition kpb.h:170
Definition kpb.h:117
uint32_t drain_req
normalized value of buffered bytes
Definition kpb.h:119
enum kpb_client_state state
current state of a client
Definition kpb.h:120
struct comp_buffer * sink
client's sink
Definition kpb.h:122
void * r_ptr
current read position
Definition kpb.h:121
uint8_t id
id associated with output sink
Definition kpb.h:118
Definition kpb.h:105
struct kpb_client * client_data
Definition kpb.h:107
enum kpb_event event_id
Definition kpb.h:106
Definition kpb.h:249
struct comp_dev * modules_list_item[FAST_MODE_TASK_MAX_MODULES_COUNT]
Definition kpb.h:254
struct comp_dev * kpb_list_item[KPB_MAX_SINK_CNT]
Definition kpb.h:253
struct comp_dev * kpb_mi_ptr
Definition kpb.h:255
struct device_list device_list[FAST_MODE_TASK_MAX_LIST_COUNT]
Definition kpb.h:251
Definition kpb.h:180
uint32_t mask
Definition kpb.h:182
Definition kpb.h:185
struct kpb_task_params::@312104334146060155313127306214256176337101160140 dev_ids[1]
uint16_t instance_id
Definition kpb.h:193
uint32_t number_of_modules
Definition kpb.h:190
uint16_t module_id
Definition kpb.h:192