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)))
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 struct comp_dev *dev;
117 struct k_queue *queue;
118 uint8_t id;
119 uint32_t drain_req;
121 void *r_ptr;
125enum buffer_state {
126 KPB_BUFFER_FREE = 0,
132 KPB_LP = 0,
137 enum buffer_state state;
139 void *end_addr;
140 void *w_ptr;
141 void *r_ptr;
146/* Draining task data */
147struct draining_data {
148 struct comp_buffer *sink;
170 size_t buffer_size;
171 size_t buffered;
172 size_t free;
176/* moved to ipc4/kpb.h */
177/* enum ipc4_kpb_module_config_params */
178
179/* Stores KPB mic selector config */
181 /* channel bit set to 1 implies channel selection */
182 uint32_t mask;
183};
185struct kpb_task_params {
186 /* If largeconfigset is set to KP_POS_IN_BUFFER then number of modules must
187 * correspond to number of modules between kpb and copier attached to hostdma.
188 * Once draining path is configured, cannot be reinitialized/changed.
189 */
190 uint32_t number_of_modules;
191 struct {
192 uint16_t module_id;
193 uint16_t instance_id;
197/* fmt namespace: */
198#define FAST_MODE_TASK_MAX_LIST_COUNT 5
199
203};
205/* The +1 is here because we also push the kbp device
206 * handle in addition to the max number of modules
207 */
208#define DEVICE_LIST_SIZE (FAST_MODE_TASK_MAX_MODULES_COUNT + 1)
209
210/* Devicelist type
211 * In Reference FW KPB used Bi-dir lists to store modules for FMT. It is possible that lists are
212 * not necessary, but in case it might be wrong, here we use an array
213 * with a list interface to switch it to a list easily.
214 */
215struct device_list {
217 /* number of items AND index of next empty box */
218 size_t count;
219};
221/*
222 *
223 *
224 * KPB FMT config set steps:
225 * 1. Get dev_ids of module instances from IPC
226 * 2. Alloc this kpb module instance on kpb_list_item, save address of where it was allocated
227 * 3. Push the address on dev_list.device_list
228 * 2. For each dev_id get device handler(module instance)
229 * 3. Alloc device handler in modules_list_item, save address of where it was allocated
230 * 4. Register this address in fmt.device_list
231 *
232 * Pointer structure:
233 *
234 * COMP_DEVS
235 * ^
236 * |
237 * dev_list.modules_list_item(comp_dev* )
238 * ^
239 * |
240 * dev_list.device_list(comp_dev**)
241 * ^
242 * |
243 * fmt.device_list(device_list*)
244 *
245 *
246 */
247
248/* KpbFastModeTaskModulesList Namespace */
249struct kpb_fmt_dev_list {
259void kpb_notifier_schedule(struct kpb_client *cli);
260#if defined(__ZEPHYR__) && defined(CONFIG_SOF_FULL_ZEPHYR_APPLICATION)
262__syscall void kpb_notifier_init(struct comp_dev *dev, struct kpb_client *cli);
263#include <zephyr/syscalls/kpb.h>
264#else
265#define kpb_notifier_init z_impl_kpb_notifier_init
266#endif
267#endif
268
269#ifdef UNIT_TEST
270void sys_comp_kpb_init(void);
271#endif
272
273#endif /* __SOF_AUDIO_KPB_H__ */
void sys_comp_kpb_init(void)
comp_copy_type
Type of next dma copy mode, changed on runtime.
Definition component.h:266
#define FAST_MODE_TASK_MAX_MODULES_COUNT
Definition kpb.h:73
buffer_state
Definition kpb.h:127
@ KPB_BUFFER_OFF
Definition kpb.h:130
@ KPB_BUFFER_FULL
Definition kpb.h:129
@ KPB_BUFFER_FREE
Definition kpb.h:128
#define DEVICE_LIST_SIZE
Definition kpb.h:210
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:133
@ KPB_LP
Definition kpb.h:134
@ KPB_HP
Definition kpb.h:135
#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:200
User-space ABI log levels and binary trace packet header definitions.
Audio component interconnect buffer connecting two pipeline components.
Definition buffer.h:150
Audio component base device "class" used by all other component types.
Definition component.h:587
Definition kpb.h:217
size_t count
Definition kpb.h:220
struct comp_dev ** devs[DEVICE_LIST_SIZE]
Definition kpb.h:218
Definition kpb.h:149
uint64_t prev_adjustment_time
Definition kpb.h:167
uint64_t period_copy_start
Definition kpb.h:159
size_t drain_req
Definition kpb.h:152
uint64_t draining_time_start
Definition kpb.h:157
size_t task_iteration
Definition kpb.h:166
size_t sample_width
Definition kpb.h:155
size_t drain_interval
Definition kpb.h:158
struct comp_buffer * sink
Definition kpb.h:150
enum comp_copy_type copy_type
Definition kpb.h:165
size_t prev_adjustment_drained
Definition kpb.h:168
struct history_buffer * hb
Definition kpb.h:151
size_t drained
Definition kpb.h:153
uint8_t is_draining_active
Definition kpb.h:154
bool sync_mode_on
Definition kpb.h:164
size_t pb_limit
Period bytes limit.
Definition kpb.h:160
size_t period_bytes
Definition kpb.h:161
size_t buffered_while_draining
Definition kpb.h:156
struct comp_dev * dev
Definition kpb.h:163
uint64_t next_copy_time
Definition kpb.h:162
Definition kpb.h:202
Definition kpb.h:138
struct history_buffer * next
next history buffer
Definition kpb.h:144
void * end_addr
buffer end address
Definition kpb.h:141
void * w_ptr
buffer write pointer
Definition kpb.h:142
enum buffer_state state
state of the buffer
Definition kpb.h:139
void * start_addr
buffer start address
Definition kpb.h:140
struct history_buffer * prev
next history buffer
Definition kpb.h:145
void * r_ptr
buffer read pointer
Definition kpb.h:143
Definition kpb.h:171
struct history_buffer * c_hb
spce we can use to write new data
Definition kpb.h:175
size_t free
Definition kpb.h:174
size_t buffered
amount of buffered data
Definition kpb.h:173
size_t buffer_size
size of internal history buffer
Definition kpb.h:172
Definition kpb.h:117
uint32_t drain_req
normalized value of buffered bytes
Definition kpb.h:121
enum kpb_client_state state
current state of a client
Definition kpb.h:122
struct comp_buffer * sink
client's sink
Definition kpb.h:124
void * r_ptr
current read position
Definition kpb.h:123
uint8_t id
id associated with output sink
Definition kpb.h:120
struct k_queue * queue
Definition kpb.h:119
struct comp_dev * dev
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:251
struct comp_dev * modules_list_item[FAST_MODE_TASK_MAX_MODULES_COUNT]
Definition kpb.h:256
struct comp_dev * kpb_list_item[KPB_MAX_SINK_CNT]
Definition kpb.h:255
struct comp_dev * kpb_mi_ptr
Definition kpb.h:257
Definition kpb.h:182
uint32_t mask
Definition kpb.h:184
Definition kpb.h:187
uint16_t instance_id
Definition kpb.h:195
uint32_t number_of_modules
Definition kpb.h:192
uint16_t module_id
Definition kpb.h:194
struct kpb_task_params::@130 dev_ids[1]