hw/timer/slavio_timer.c: Switch to transaction-based ptimer API
Switch the slavio_timer code away from bottom-half based ptimers to the new transaction-based ptimer API. This just requires adding begin/commit calls around the various places that modify the ptimer state, and using the new ptimer_init() function to create the timer. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Message-id: 20191021134357.14266-4-peter.maydell@linaro.org Tested-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
		
							parent
							
								
									5e3478925d
								
							
						
					
					
						commit
						2ee62f32a7
					
				| @ -30,7 +30,6 @@ | |||||||
| #include "hw/sysbus.h" | #include "hw/sysbus.h" | ||||||
| #include "migration/vmstate.h" | #include "migration/vmstate.h" | ||||||
| #include "trace.h" | #include "trace.h" | ||||||
| #include "qemu/main-loop.h" |  | ||||||
| #include "qemu/module.h" | #include "qemu/module.h" | ||||||
| 
 | 
 | ||||||
| /*
 | /*
 | ||||||
| @ -213,6 +212,7 @@ static void slavio_timer_mem_writel(void *opaque, hwaddr addr, | |||||||
|     saddr = addr >> 2; |     saddr = addr >> 2; | ||||||
|     switch (saddr) { |     switch (saddr) { | ||||||
|     case TIMER_LIMIT: |     case TIMER_LIMIT: | ||||||
|  |         ptimer_transaction_begin(t->timer); | ||||||
|         if (slavio_timer_is_user(tc)) { |         if (slavio_timer_is_user(tc)) { | ||||||
|             uint64_t count; |             uint64_t count; | ||||||
| 
 | 
 | ||||||
| @ -234,6 +234,7 @@ static void slavio_timer_mem_writel(void *opaque, hwaddr addr, | |||||||
|                 ptimer_set_limit(t->timer, LIMIT_TO_PERIODS(t->limit), 1); |                 ptimer_set_limit(t->timer, LIMIT_TO_PERIODS(t->limit), 1); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |         ptimer_transaction_commit(t->timer); | ||||||
|         break; |         break; | ||||||
|     case TIMER_COUNTER: |     case TIMER_COUNTER: | ||||||
|         if (slavio_timer_is_user(tc)) { |         if (slavio_timer_is_user(tc)) { | ||||||
| @ -245,7 +246,9 @@ static void slavio_timer_mem_writel(void *opaque, hwaddr addr, | |||||||
|             t->reached = 0; |             t->reached = 0; | ||||||
|             count = ((uint64_t)t->counthigh) << 32 | t->count; |             count = ((uint64_t)t->counthigh) << 32 | t->count; | ||||||
|             trace_slavio_timer_mem_writel_limit(timer_index, count); |             trace_slavio_timer_mem_writel_limit(timer_index, count); | ||||||
|  |             ptimer_transaction_begin(t->timer); | ||||||
|             ptimer_set_count(t->timer, LIMIT_TO_PERIODS(t->limit - count)); |             ptimer_set_count(t->timer, LIMIT_TO_PERIODS(t->limit - count)); | ||||||
|  |             ptimer_transaction_commit(t->timer); | ||||||
|         } else { |         } else { | ||||||
|             trace_slavio_timer_mem_writel_counter_invalid(); |             trace_slavio_timer_mem_writel_counter_invalid(); | ||||||
|         } |         } | ||||||
| @ -253,13 +256,16 @@ static void slavio_timer_mem_writel(void *opaque, hwaddr addr, | |||||||
|     case TIMER_COUNTER_NORST: |     case TIMER_COUNTER_NORST: | ||||||
|         // set limit without resetting counter
 |         // set limit without resetting counter
 | ||||||
|         t->limit = val & TIMER_MAX_COUNT32; |         t->limit = val & TIMER_MAX_COUNT32; | ||||||
|  |         ptimer_transaction_begin(t->timer); | ||||||
|         if (t->limit == 0) { /* free-run */ |         if (t->limit == 0) { /* free-run */ | ||||||
|             ptimer_set_limit(t->timer, LIMIT_TO_PERIODS(TIMER_MAX_COUNT32), 0); |             ptimer_set_limit(t->timer, LIMIT_TO_PERIODS(TIMER_MAX_COUNT32), 0); | ||||||
|         } else { |         } else { | ||||||
|             ptimer_set_limit(t->timer, LIMIT_TO_PERIODS(t->limit), 0); |             ptimer_set_limit(t->timer, LIMIT_TO_PERIODS(t->limit), 0); | ||||||
|         } |         } | ||||||
|  |         ptimer_transaction_commit(t->timer); | ||||||
|         break; |         break; | ||||||
|     case TIMER_STATUS: |     case TIMER_STATUS: | ||||||
|  |         ptimer_transaction_begin(t->timer); | ||||||
|         if (slavio_timer_is_user(tc)) { |         if (slavio_timer_is_user(tc)) { | ||||||
|             // start/stop user counter
 |             // start/stop user counter
 | ||||||
|             if (val & 1) { |             if (val & 1) { | ||||||
| @ -271,6 +277,7 @@ static void slavio_timer_mem_writel(void *opaque, hwaddr addr, | |||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         t->run = val & 1; |         t->run = val & 1; | ||||||
|  |         ptimer_transaction_commit(t->timer); | ||||||
|         break; |         break; | ||||||
|     case TIMER_MODE: |     case TIMER_MODE: | ||||||
|         if (timer_index == 0) { |         if (timer_index == 0) { | ||||||
| @ -280,6 +287,7 @@ static void slavio_timer_mem_writel(void *opaque, hwaddr addr, | |||||||
|                 unsigned int processor = 1 << i; |                 unsigned int processor = 1 << i; | ||||||
|                 CPUTimerState *curr_timer = &s->cputimer[i + 1]; |                 CPUTimerState *curr_timer = &s->cputimer[i + 1]; | ||||||
| 
 | 
 | ||||||
|  |                 ptimer_transaction_begin(curr_timer->timer); | ||||||
|                 // check for a change in timer mode for this processor
 |                 // check for a change in timer mode for this processor
 | ||||||
|                 if ((val & processor) != (s->cputimer_mode & processor)) { |                 if ((val & processor) != (s->cputimer_mode & processor)) { | ||||||
|                     if (val & processor) { // counter -> user timer
 |                     if (val & processor) { // counter -> user timer
 | ||||||
| @ -306,6 +314,7 @@ static void slavio_timer_mem_writel(void *opaque, hwaddr addr, | |||||||
|                         trace_slavio_timer_mem_writel_mode_counter(timer_index); |                         trace_slavio_timer_mem_writel_mode_counter(timer_index); | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|  |                 ptimer_transaction_commit(curr_timer->timer); | ||||||
|             } |             } | ||||||
|         } else { |         } else { | ||||||
|             trace_slavio_timer_mem_writel_mode_invalid(); |             trace_slavio_timer_mem_writel_mode_invalid(); | ||||||
| @ -365,10 +374,12 @@ static void slavio_timer_reset(DeviceState *d) | |||||||
|         curr_timer->count = 0; |         curr_timer->count = 0; | ||||||
|         curr_timer->reached = 0; |         curr_timer->reached = 0; | ||||||
|         if (i <= s->num_cpus) { |         if (i <= s->num_cpus) { | ||||||
|  |             ptimer_transaction_begin(curr_timer->timer); | ||||||
|             ptimer_set_limit(curr_timer->timer, |             ptimer_set_limit(curr_timer->timer, | ||||||
|                              LIMIT_TO_PERIODS(TIMER_MAX_COUNT32), 1); |                              LIMIT_TO_PERIODS(TIMER_MAX_COUNT32), 1); | ||||||
|             ptimer_run(curr_timer->timer, 0); |             ptimer_run(curr_timer->timer, 0); | ||||||
|             curr_timer->run = 1; |             curr_timer->run = 1; | ||||||
|  |             ptimer_transaction_commit(curr_timer->timer); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|     s->cputimer_mode = 0; |     s->cputimer_mode = 0; | ||||||
| @ -378,7 +389,6 @@ static void slavio_timer_init(Object *obj) | |||||||
| { | { | ||||||
|     SLAVIO_TIMERState *s = SLAVIO_TIMER(obj); |     SLAVIO_TIMERState *s = SLAVIO_TIMER(obj); | ||||||
|     SysBusDevice *dev = SYS_BUS_DEVICE(obj); |     SysBusDevice *dev = SYS_BUS_DEVICE(obj); | ||||||
|     QEMUBH *bh; |  | ||||||
|     unsigned int i; |     unsigned int i; | ||||||
|     TimerContext *tc; |     TimerContext *tc; | ||||||
| 
 | 
 | ||||||
| @ -390,9 +400,11 @@ static void slavio_timer_init(Object *obj) | |||||||
|         tc->s = s; |         tc->s = s; | ||||||
|         tc->timer_index = i; |         tc->timer_index = i; | ||||||
| 
 | 
 | ||||||
|         bh = qemu_bh_new(slavio_timer_irq, tc); |         s->cputimer[i].timer = ptimer_init(slavio_timer_irq, tc, | ||||||
|         s->cputimer[i].timer = ptimer_init_with_bh(bh, PTIMER_POLICY_DEFAULT); |                                            PTIMER_POLICY_DEFAULT); | ||||||
|  |         ptimer_transaction_begin(s->cputimer[i].timer); | ||||||
|         ptimer_set_period(s->cputimer[i].timer, TIMER_PERIOD); |         ptimer_set_period(s->cputimer[i].timer, TIMER_PERIOD); | ||||||
|  |         ptimer_transaction_commit(s->cputimer[i].timer); | ||||||
| 
 | 
 | ||||||
|         size = i == 0 ? SYS_TIMER_SIZE : CPU_TIMER_SIZE; |         size = i == 0 ? SYS_TIMER_SIZE : CPU_TIMER_SIZE; | ||||||
|         snprintf(timer_name, sizeof(timer_name), "timer-%i", i); |         snprintf(timer_name, sizeof(timer_name), "timer-%i", i); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Peter Maydell
						Peter Maydell