From 925da68b6349d9b8cce6bfc73b58568b9715fc8c Mon Sep 17 00:00:00 2001 From: Tomasz Lauda Date: Tue, 14 Jan 2020 12:18:29 +0100 Subject: [PATCH] timer: replace timer_data Replaces void pointer to timer_data with pointers to timer handler and handler data. We had multiple definitions of timer_data structure and they were all the same. This way we can remove unnecessary static data. Signed-off-by: Tomasz Lauda --- src/arch/xtensa/drivers/timer.c | 19 +++---------------- src/arch/xtensa/include/arch/drivers/timer.h | 3 ++- src/drivers/intel/baytrail/timer.c | 16 +++------------- 3 files changed, 8 insertions(+), 30 deletions(-) diff --git a/src/arch/xtensa/drivers/timer.c b/src/arch/xtensa/drivers/timer.c index 2c4ece4a3..007237eb0 100644 --- a/src/arch/xtensa/drivers/timer.c +++ b/src/arch/xtensa/drivers/timer.c @@ -11,17 +11,9 @@ #include #include -struct timer_data { - void (*handler2)(void *arg); - void *arg2; -}; - -static struct timer_data xtimer[ARCH_TIMER_COUNT]; - void timer_64_handler(void *arg) { struct timer *timer = arg; - struct timer_data *tdata = timer->timer_data; uint32_t ccompare; if (timer->id >= ARCH_TIMER_COUNT) @@ -37,7 +29,7 @@ void timer_64_handler(void *arg) arch_timer_clear(timer); } else { /* no roll over, run the handler */ - tdata->handler2(tdata->arg2); + timer->handler(timer->data); } /* get next timeout value */ @@ -54,16 +46,11 @@ void timer_64_handler(void *arg) int timer64_register(struct timer *timer, void(*handler)(void *arg), void *arg) { - struct timer_data *tdata; - if (timer->id >= ARCH_TIMER_COUNT) return -EINVAL; - tdata = &xtimer[timer->id]; - - tdata->handler2 = handler; - tdata->arg2 = arg; - timer->timer_data = tdata; + timer->handler = handler; + timer->data = arg; timer->hitime = 0; timer->hitimeout = 0; return 0; diff --git a/src/arch/xtensa/include/arch/drivers/timer.h b/src/arch/xtensa/include/arch/drivers/timer.h index 799e43104..ecff8284a 100644 --- a/src/arch/xtensa/include/arch/drivers/timer.h +++ b/src/arch/xtensa/include/arch/drivers/timer.h @@ -20,7 +20,8 @@ struct timer { int irq; int logical_irq; /* used for external timers */ const char *irq_name; - void *timer_data; /* used by core */ + void (*handler)(void *data); /* optional timer handler */ + void *data; /* optional timer handler's data */ uint32_t hitime; /* high end of 64bit timer */ uint32_t hitimeout; uint32_t lowtimeout; diff --git a/src/drivers/intel/baytrail/timer.c b/src/drivers/intel/baytrail/timer.c index 25448332c..887b7d7bc 100644 --- a/src/drivers/intel/baytrail/timer.c +++ b/src/drivers/intel/baytrail/timer.c @@ -18,17 +18,9 @@ #include #include -struct timer_data { - void (*handler2)(void *arg); - void *arg2; -}; - -static struct timer_data xtimer[1] = {}; - static void platform_timer_64_handler(void *arg) { struct timer *timer = arg; - struct timer_data *tdata = timer->timer_data; uint32_t timeout; /* get timeout value - will tell us timeout reason */ @@ -43,7 +35,7 @@ static void platform_timer_64_handler(void *arg) timer->hitime++; } else { /* no roll over, run the handler */ - tdata->handler2(tdata->arg2); + timer->handler(timer->data); } /* get next timeout value */ @@ -183,14 +175,12 @@ void platform_dai_wallclock(struct comp_dev *dai, uint64_t *wallclock) static int platform_timer_register(struct timer *timer, void (*handler)(void *arg), void *arg) { - struct timer_data *tdata = &xtimer[0]; uint32_t flags; int ret; flags = arch_interrupt_global_disable(); - tdata->handler2 = handler; - tdata->arg2 = arg; - timer->timer_data = tdata; + timer->handler = handler; + timer->data = arg; timer->hitime = 0; timer->hitimeout = 0; ret = arch_interrupt_register(timer->irq,