1 /* SPDX-License-Identifier: BSD-3-Clause 2 * 3 * Copyright(c) 2017 Intel Corporation. All rights reserved. 4 * 5 * Author: Liam Girdwood <liam.r.girdwood@linux.intel.com> 6 */ 7 8 #ifndef __SOF_LIB_AGENT_H__ 9 #define __SOF_LIB_AGENT_H__ 10 11 #include <sof/atomic.h> 12 #include <sof/lib/memory.h> 13 #include <sof/lib/perf_cnt.h> 14 #include <sof/schedule/task.h> 15 #include <sof/sof.h> 16 17 #include <stdbool.h> 18 #include <stdint.h> 19 20 struct sof; 21 22 /* simple agent */ 23 struct sa { 24 uint64_t last_check; /* time of last activity checking */ 25 uint64_t panic_timeout; /* threshold of panic */ 26 uint64_t warn_timeout; /* threshold of warning */ 27 #if CONFIG_PERFORMANCE_COUNTERS 28 struct perf_cnt_data pcd; 29 #endif 30 struct task work; 31 atomic_t panic_cnt; /**< ref counter for panic_on_delay property */ 32 bool panic_on_delay; /**< emits panic on delay if true */ 33 }; 34 35 #if CONFIG_HAVE_AGENT 36 37 /** 38 * Enables or disables panic on agent delay. 39 * @param enabled True for panic enabling, false otherwise. 40 */ sa_set_panic_on_delay(bool enabled)41static inline void sa_set_panic_on_delay(bool enabled) 42 { 43 struct sa *sa = sof_get()->sa; 44 45 if (enabled) 46 atomic_add(&sa->panic_cnt, 1); 47 else 48 atomic_sub(&sa->panic_cnt, 1); 49 50 /* enable panic only if no refs */ 51 sa->panic_on_delay = !atomic_read(&sa->panic_cnt); 52 53 } 54 55 void sa_init(struct sof *sof, uint64_t timeout); 56 void sa_exit(struct sof *sof); 57 58 #else 59 sa_init(struct sof * sof,uint64_t timeout)60static inline void sa_init(struct sof *sof, uint64_t timeout) { } sa_exit(struct sof * sof)61static inline void sa_exit(struct sof *sof) { } sa_set_panic_on_delay(bool enabled)62static inline void sa_set_panic_on_delay(bool enabled) { } 63 64 #endif 65 66 #endif /* __SOF_LIB_AGENT_H__ */ 67