diff --git a/src/audio/copier/copier.c b/src/audio/copier/copier.c index e8976ec9add6..06900abce766 100644 --- a/src/audio/copier/copier.c +++ b/src/audio/copier/copier.c @@ -57,30 +57,33 @@ LOG_MODULE_REGISTER(copier, CONFIG_SOF_LOG_LEVEL); SOF_DEFINE_REG_UUID(copier); #if CONFIG_INTEL_ADSP_MIC_PRIVACY -static void mic_privacy_event(void *arg, enum notify_id type, void *data) +/* Take the mic privacy state posted since the last copy, see mic_privacy_propagate_settings() */ +static void mic_privacy_take_state(struct mic_privacy_data *mic_priv_data) { - struct mic_privacy_data *mic_priv_data = arg; - struct mic_privacy_settings *mic_privacy_settings = data; + uint32_t word = atomic_get(&mic_privacy_state_word); - if (type == NOTIFIER_ID_MIC_PRIVACY_STATE_CHANGE) { - LOG_INF("state1 = %d, state2 = %d ", - mic_privacy_settings->mic_privacy_state, mic_priv_data->mic_privacy_state); + if (MIC_PRIV_STATE_SEQ(word) == mic_priv_data->state_seq) + return; - if (mic_privacy_settings->mic_privacy_state == MIC_PRIV_UNMUTED) { - if (mic_priv_data->mic_privacy_state == MIC_PRIV_MUTED) { - mic_priv_data->mic_privacy_state = MIC_PRIV_FADE_IN; - LOG_INF("switch to FADE_IN"); - } - } else { - /* In case when mute would be triggered before copier instantiation. */ - if (mic_priv_data->mic_privacy_state != MIC_PRIV_MUTED) { - mic_priv_data->mic_privacy_state = MIC_PRIV_FADE_OUT; - LOG_INF("switch to FADE_OUT"); - } + mic_priv_data->state_seq = MIC_PRIV_STATE_SEQ(word); + + LOG_INF("state1 = %u, state2 = %d ", + MIC_PRIV_STATE_MUTE(word), mic_priv_data->mic_privacy_state); + + if (!MIC_PRIV_STATE_MUTE(word)) { + if (mic_priv_data->mic_privacy_state == MIC_PRIV_MUTED) { + mic_priv_data->mic_privacy_state = MIC_PRIV_FADE_IN; + LOG_INF("switch to FADE_IN"); + } + } else { + /* In case when mute would be triggered before copier instantiation. */ + if (mic_priv_data->mic_privacy_state != MIC_PRIV_MUTED) { + mic_priv_data->mic_privacy_state = MIC_PRIV_FADE_OUT; + LOG_INF("switch to FADE_OUT"); } - mic_priv_data->max_ramp_time_in_ms = (mic_privacy_settings->max_ramp_time * 1000) / - ADSP_RTC_FREQUENCY; } + mic_priv_data->max_ramp_time_in_ms = (MIC_PRIV_STATE_RAMP(word) * 1000) / + ADSP_RTC_FREQUENCY; } __cold static int mic_privacy_configure(struct processing_module *mod, struct copier_data *cd) @@ -111,13 +114,10 @@ __cold static int mic_privacy_configure(struct processing_module *mod, struct co cd->mic_priv = mic_priv_data; - ret = notifier_register(cd->mic_priv, NULL, NOTIFIER_ID_MIC_PRIVACY_STATE_CHANGE, - mic_privacy_event); + /* only take the mic privacy states posted from now on */ + mic_priv_data->state_seq = MIC_PRIV_STATE_SEQ(atomic_get(&mic_privacy_state_word)); - if (ret != 0) - mod_free(mod, mic_priv_data); - - return ret; + return 0; } __cold static void mic_privacy_free(struct processing_module *mod) @@ -129,8 +129,6 @@ __cold static void mic_privacy_free(struct processing_module *mod) if (cd->gtw_type == ipc4_gtw_dmic) mic_privacy_enable_dmic_irq(false); - notifier_unregister(cd->mic_priv, NULL, NOTIFIER_ID_MIC_PRIVACY_STATE_CHANGE); - mod_free(mod, cd->mic_priv); } #endif @@ -818,6 +816,11 @@ static int copier_process(struct processing_module *mod, comp_dbg(dev, "entry"); +#if CONFIG_INTEL_ADSP_MIC_PRIVACY + if (cd->mic_priv) + mic_privacy_take_state(cd->mic_priv); +#endif + switch (dev->ipc_config.type) { case SOF_COMP_HOST: if (!cd->ipc_gtw) diff --git a/src/include/sof/audio/mic_privacy_manager.h b/src/include/sof/audio/mic_privacy_manager.h index 61689343a37e..ccb638c0fc53 100644 --- a/src/include/sof/audio/mic_privacy_manager.h +++ b/src/include/sof/audio/mic_privacy_manager.h @@ -8,18 +8,35 @@ #define ADSP_FW_MIC_PRIVACY_MANAGER_H #include -#include +#include #include #include "../audio/copier/copier_gain.h" #define ADSP_RTC_FREQUENCY 32768 +/* + * The mic privacy state for the copiers is a single word, so that the kernel + * can post it from the mic privacy interrupts and IPC, and the copiers can + * read it in their LL threads without a lock: an 8-bit sequence number, the + * mic disable state and the DMA data zeroing wait time in RTC ticks. + */ +#define MIC_PRIV_STATE_WORD(seq, mute, ramp) ((((uint32_t)(seq) & 0xff) << 24) | \ + ((uint32_t)!!(mute) << 16) | \ + ((uint32_t)(ramp) & 0xffff)) +#define MIC_PRIV_STATE_SEQ(word) (((uint32_t)(word) >> 24) & 0xff) +#define MIC_PRIV_STATE_MUTE(word) (((uint32_t)(word) >> 16) & 0x1) +#define MIC_PRIV_STATE_RAMP(word) ((uint32_t)(word) & 0xffff) + +/* the last mic privacy state, posted by mic_privacy_propagate_settings() */ +extern atomic_t mic_privacy_state_word; + struct mic_privacy_data { enum ipc4_sampling_frequency audio_freq; uint32_t mic_privacy_state; bool dma_data_zeroing; uint32_t fade_in_out_bytes; uint32_t max_ramp_time_in_ms; + uint8_t state_seq; /**< sequence number of the last mic privacy state taken */ struct copier_gain_params mic_priv_gain_params; }; diff --git a/src/include/sof/lib/notifier.h b/src/include/sof/lib/notifier.h index e5413a512cb4..2d1c443897a7 100644 --- a/src/include/sof/lib/notifier.h +++ b/src/include/sof/lib/notifier.h @@ -27,7 +27,6 @@ enum notify_id { NOTIFIER_ID_DMA_COPY, /* struct dma_cb_data* */ NOTIFIER_ID_DMA_IRQ, /* struct dma_chan_data * */ NOTIFIER_ID_DAI_TRIGGER, /* struct dai_group * */ - NOTIFIER_ID_MIC_PRIVACY_STATE_CHANGE, /* struct mic_privacy_settings * */ NOTIFIER_ID_VAD, /* int * (WEBRTC_VAD_SPEECH / WEBRTC_VAD_SILENCE) */ NOTIFIER_ID_COUNT }; diff --git a/src/kernel/audio/mic_privacy_manager/mic_privacy_manager_intel.c b/src/kernel/audio/mic_privacy_manager/mic_privacy_manager_intel.c index a5ff86a04fd1..d10016f4a8c3 100644 --- a/src/kernel/audio/mic_privacy_manager/mic_privacy_manager_intel.c +++ b/src/kernel/audio/mic_privacy_manager/mic_privacy_manager_intel.c @@ -11,6 +11,7 @@ #include #include #include +#include const struct device *mic_priv_dev; @@ -126,11 +127,24 @@ uint32_t mic_privacy_get_policy_register(void) return mic_privacy_api->get_privacy_policy_register_raw_value(); } +/* + * Kernel code writes it, the copiers read it in the LL threads, which can be + * user threads. + */ +APP_SYSUSER_BSS atomic_t mic_privacy_state_word; + +/* Post the mic privacy state for the copiers, which take it in their next copy. */ void mic_privacy_propagate_settings(struct mic_privacy_settings *settings) { - notifier_event(mic_priv_dev, NOTIFIER_ID_MIC_PRIVACY_STATE_CHANGE, - NOTIFIER_TARGET_CORE_ALL_MASK, settings, - sizeof(struct mic_privacy_settings)); + atomic_val_t old; + atomic_val_t new; + + do { + old = atomic_get(&mic_privacy_state_word); + new = MIC_PRIV_STATE_WORD(MIC_PRIV_STATE_SEQ(old) + 1, + settings->mic_privacy_state, + settings->max_ramp_time); + } while (!atomic_cas(&mic_privacy_state_word, old, new)); } uint32_t mic_privacy_get_dma_zeroing_wait_time(void)