| 
									
										
										
										
											2007-10-08 13:26:33 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2008-03-14 01:04:24 +00:00
										 |  |  |  * QEMU ETRAX Timers | 
					
						
							| 
									
										
										
										
											2007-10-08 13:26:33 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Copyright (c) 2007 Edgar E. Iglesias, Axis Communications AB. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Permission is hereby granted, free of charge, to any person obtaining a copy | 
					
						
							|  |  |  |  * of this software and associated documentation files (the "Software"), to deal | 
					
						
							|  |  |  |  * in the Software without restriction, including without limitation the rights | 
					
						
							|  |  |  |  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | 
					
						
							|  |  |  |  * copies of the Software, and to permit persons to whom the Software is | 
					
						
							|  |  |  |  * furnished to do so, subject to the following conditions: | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The above copyright notice and this permission notice shall be included in | 
					
						
							|  |  |  |  * all copies or substantial portions of the Software. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 
					
						
							|  |  |  |  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 
					
						
							|  |  |  |  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | 
					
						
							|  |  |  |  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | 
					
						
							|  |  |  |  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | 
					
						
							|  |  |  |  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | 
					
						
							|  |  |  |  * THE SOFTWARE. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2019-05-23 16:35:07 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-26 18:17:18 +00:00
										 |  |  | #include "qemu/osdep.h"
 | 
					
						
							| 
									
										
										
										
											2013-02-04 15:40:22 +01:00
										 |  |  | #include "hw/sysbus.h"
 | 
					
						
							| 
									
										
										
										
											2019-08-12 07:23:38 +02:00
										 |  |  | #include "sysemu/reset.h"
 | 
					
						
							| 
									
										
										
										
											2019-08-12 07:23:59 +02:00
										 |  |  | #include "sysemu/runstate.h"
 | 
					
						
							| 
									
										
										
										
											2019-05-23 16:35:07 +02:00
										 |  |  | #include "qemu/module.h"
 | 
					
						
							| 
									
										
										
										
											2012-12-17 18:20:00 +01:00
										 |  |  | #include "qemu/timer.h"
 | 
					
						
							| 
									
										
										
										
											2019-08-12 07:23:42 +02:00
										 |  |  | #include "hw/irq.h"
 | 
					
						
							| 
									
										
										
										
											2013-02-04 15:40:22 +01:00
										 |  |  | #include "hw/ptimer.h"
 | 
					
						
							| 
									
										
										
										
											2020-09-03 16:43:22 -04:00
										 |  |  | #include "qom/object.h"
 | 
					
						
							| 
									
										
										
										
											2007-10-08 13:26:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-01 17:25:33 +00:00
										 |  |  | #define D(x)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-14 01:50:49 +00:00
										 |  |  | #define RW_TMR0_DIV   0x00
 | 
					
						
							|  |  |  | #define R_TMR0_DATA   0x04
 | 
					
						
							|  |  |  | #define RW_TMR0_CTRL  0x08
 | 
					
						
							|  |  |  | #define RW_TMR1_DIV   0x10
 | 
					
						
							|  |  |  | #define R_TMR1_DATA   0x14
 | 
					
						
							|  |  |  | #define RW_TMR1_CTRL  0x18
 | 
					
						
							|  |  |  | #define R_TIME        0x38
 | 
					
						
							|  |  |  | #define RW_WD_CTRL    0x40
 | 
					
						
							| 
									
										
										
										
											2008-05-27 21:04:41 +00:00
										 |  |  | #define R_WD_STAT     0x44
 | 
					
						
							| 
									
										
										
										
											2008-03-14 01:50:49 +00:00
										 |  |  | #define RW_INTR_MASK  0x48
 | 
					
						
							|  |  |  | #define RW_ACK_INTR   0x4c
 | 
					
						
							|  |  |  | #define R_INTR        0x50
 | 
					
						
							|  |  |  | #define R_MASKED_INTR 0x54
 | 
					
						
							| 
									
										
										
										
											2007-10-08 13:26:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												hw: Replace anti-social QOM type names
Several QOM type names contain ',':
    ARM,bitband-memory
    etraxfs,pic
    etraxfs,serial
    etraxfs,timer
    fsl,imx25
    fsl,imx31
    fsl,imx6
    fsl,imx6ul
    fsl,imx7
    grlib,ahbpnp
    grlib,apbpnp
    grlib,apbuart
    grlib,gptimer
    grlib,irqmp
    qemu,register
    SUNW,bpp
    SUNW,CS4231
    SUNW,DBRI
    SUNW,DBRI.prom
    SUNW,fdtwo
    SUNW,sx
    SUNW,tcx
    xilinx,zynq_slcr
    xlnx,zynqmp
    xlnx,zynqmp-pmu-soc
    xlnx,zynq-xadc
These are all device types.  They can't be plugged with -device /
device_add, except for xlnx,zynqmp-pmu-soc, and I doubt that one
actually works.
They *can* be used with -device / device_add to request help.
Usability is poor, though: you have to double the comma, like this:
    $ qemu-system-x86_64 -device SUNW,,fdtwo,help
Trap for the unwary.  The fact that this was broken in
device-introspect-test for more than six years until commit e27bd49876
fixed it demonstrates that "the unwary" includes seasoned developers.
One QOM type name contains ' ': "ICH9 SMB".  Because having to
remember just one way to quote would be too easy.
Rename the "SUNW,FOO types to "sun-FOO".  Summarily replace ',' and '
' by '-' in the other type names.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20210304140229.575481-2-armbru@redhat.com>
Reviewed-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
											
										 
											2021-03-04 15:02:28 +01:00
										 |  |  | #define TYPE_ETRAX_FS_TIMER "etraxfs-timer"
 | 
					
						
							| 
									
										
										
										
											2020-09-03 16:43:22 -04:00
										 |  |  | typedef struct ETRAXTimerState ETRAXTimerState; | 
					
						
							| 
									
										
										
										
											2020-08-31 17:07:33 -04:00
										 |  |  | DECLARE_INSTANCE_CHECKER(ETRAXTimerState, ETRAX_TIMER, | 
					
						
							|  |  |  |                          TYPE_ETRAX_FS_TIMER) | 
					
						
							| 
									
										
										
										
											2013-07-27 14:34:22 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-03 16:43:22 -04:00
										 |  |  | struct ETRAXTimerState { | 
					
						
							| 
									
										
										
										
											2013-07-27 14:34:22 +02:00
										 |  |  |     SysBusDevice parent_obj; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-11 13:47:46 +02:00
										 |  |  |     MemoryRegion mmio; | 
					
						
							| 
									
										
										
										
											2009-05-16 02:08:16 +02:00
										 |  |  |     qemu_irq irq; | 
					
						
							|  |  |  |     qemu_irq nmi; | 
					
						
							| 
									
										
										
										
											2009-05-16 01:46:26 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ptimer_state *ptimer_t0; | 
					
						
							|  |  |  |     ptimer_state *ptimer_t1; | 
					
						
							|  |  |  |     ptimer_state *ptimer_wd; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     int wd_hits; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* Control registers.  */ | 
					
						
							|  |  |  |     uint32_t rw_tmr0_div; | 
					
						
							|  |  |  |     uint32_t r_tmr0_data; | 
					
						
							|  |  |  |     uint32_t rw_tmr0_ctrl; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     uint32_t rw_tmr1_div; | 
					
						
							|  |  |  |     uint32_t r_tmr1_data; | 
					
						
							|  |  |  |     uint32_t rw_tmr1_ctrl; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     uint32_t rw_wd_ctrl; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     uint32_t rw_intr_mask; | 
					
						
							|  |  |  |     uint32_t rw_ack_intr; | 
					
						
							|  |  |  |     uint32_t r_intr; | 
					
						
							|  |  |  |     uint32_t r_masked_intr; | 
					
						
							| 
									
										
										
										
											2020-09-03 16:43:22 -04:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2007-10-08 13:26:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-11 13:47:46 +02:00
										 |  |  | static uint64_t | 
					
						
							| 
									
										
										
										
											2012-10-23 12:30:10 +02:00
										 |  |  | timer_read(void *opaque, hwaddr addr, unsigned int size) | 
					
						
							| 
									
										
										
										
											2007-10-08 13:26:33 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-07-27 14:30:31 +02:00
										 |  |  |     ETRAXTimerState *t = opaque; | 
					
						
							| 
									
										
										
										
											2009-05-16 01:46:26 +02:00
										 |  |  |     uint32_t r = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     switch (addr) { | 
					
						
							|  |  |  |     case R_TMR0_DATA: | 
					
						
							|  |  |  |         r = ptimer_get_count(t->ptimer_t0); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case R_TMR1_DATA: | 
					
						
							|  |  |  |         r = ptimer_get_count(t->ptimer_t1); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case R_TIME: | 
					
						
							| 
									
										
										
										
											2013-08-21 16:03:08 +01:00
										 |  |  |         r = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) / 10; | 
					
						
							| 
									
										
										
										
											2009-05-16 01:46:26 +02:00
										 |  |  |         break; | 
					
						
							|  |  |  |     case RW_INTR_MASK: | 
					
						
							|  |  |  |         r = t->rw_intr_mask; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case R_MASKED_INTR: | 
					
						
							|  |  |  |         r = t->r_intr & t->rw_intr_mask; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     default: | 
					
						
							|  |  |  |         D(printf ("%s %x\n", __func__, addr)); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return r; | 
					
						
							| 
									
										
										
										
											2007-10-08 13:26:33 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-27 14:30:31 +02:00
										 |  |  | static void update_ctrl(ETRAXTimerState *t, int tnum) | 
					
						
							| 
									
										
										
										
											2007-10-08 13:26:33 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-05-16 01:46:26 +02:00
										 |  |  |     unsigned int op; | 
					
						
							|  |  |  |     unsigned int freq; | 
					
						
							|  |  |  |     unsigned int freq_hz; | 
					
						
							|  |  |  |     unsigned int div; | 
					
						
							|  |  |  |     uint32_t ctrl; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ptimer_state *timer; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (tnum == 0) { | 
					
						
							|  |  |  |         ctrl = t->rw_tmr0_ctrl; | 
					
						
							|  |  |  |         div = t->rw_tmr0_div; | 
					
						
							|  |  |  |         timer = t->ptimer_t0; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         ctrl = t->rw_tmr1_ctrl; | 
					
						
							|  |  |  |         div = t->rw_tmr1_div; | 
					
						
							|  |  |  |         timer = t->ptimer_t1; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     op = ctrl & 3; | 
					
						
							|  |  |  |     freq = ctrl >> 2; | 
					
						
							|  |  |  |     freq_hz = 32000000; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     switch (freq) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |     case 0: | 
					
						
							|  |  |  |     case 1: | 
					
						
							|  |  |  |         D(printf ("extern or disabled timer clock?\n")); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case 4: freq_hz =  29493000; break; | 
					
						
							|  |  |  |     case 5: freq_hz =  32000000; break; | 
					
						
							|  |  |  |     case 6: freq_hz =  32768000; break; | 
					
						
							|  |  |  |     case 7: freq_hz = 100000000; break; | 
					
						
							|  |  |  |     default: | 
					
						
							|  |  |  |         abort(); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     D(printf ("freq_hz=%d div=%d\n", freq_hz, div)); | 
					
						
							| 
									
										
										
										
											2019-10-22 16:50:36 +01:00
										 |  |  |     ptimer_transaction_begin(timer); | 
					
						
							| 
									
										
										
										
											2009-05-16 01:46:26 +02:00
										 |  |  |     ptimer_set_freq(timer, freq_hz); | 
					
						
							|  |  |  |     ptimer_set_limit(timer, div, 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     switch (op) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         case 0: | 
					
						
							|  |  |  |             /* Load.  */ | 
					
						
							|  |  |  |             ptimer_set_limit(timer, div, 1); | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         case 1: | 
					
						
							|  |  |  |             /* Hold.  */ | 
					
						
							|  |  |  |             ptimer_stop(timer); | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         case 2: | 
					
						
							|  |  |  |             /* Run.  */ | 
					
						
							|  |  |  |             ptimer_run(timer, 0); | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         default: | 
					
						
							|  |  |  |             abort(); | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-10-22 16:50:36 +01:00
										 |  |  |     ptimer_transaction_commit(timer); | 
					
						
							| 
									
										
										
										
											2007-10-08 13:26:33 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-27 14:30:31 +02:00
										 |  |  | static void timer_update_irq(ETRAXTimerState *t) | 
					
						
							| 
									
										
										
										
											2007-10-08 13:26:33 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-05-16 01:46:26 +02:00
										 |  |  |     t->r_intr &= ~(t->rw_ack_intr); | 
					
						
							|  |  |  |     t->r_masked_intr = t->r_intr & t->rw_intr_mask; | 
					
						
							| 
									
										
										
										
											2008-05-02 22:32:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-16 01:46:26 +02:00
										 |  |  |     D(printf("%s: masked_intr=%x\n", __func__, t->r_masked_intr)); | 
					
						
							| 
									
										
										
										
											2009-05-16 02:08:16 +02:00
										 |  |  |     qemu_set_irq(t->irq, !!t->r_masked_intr); | 
					
						
							| 
									
										
										
										
											2007-10-08 13:26:33 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-05-27 21:04:41 +00:00
										 |  |  | static void timer0_hit(void *opaque) | 
					
						
							| 
									
										
										
										
											2008-05-02 22:32:02 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-07-27 14:30:31 +02:00
										 |  |  |     ETRAXTimerState *t = opaque; | 
					
						
							| 
									
										
										
										
											2009-05-16 01:46:26 +02:00
										 |  |  |     t->r_intr |= 1; | 
					
						
							|  |  |  |     timer_update_irq(t); | 
					
						
							| 
									
										
										
										
											2008-05-02 22:32:02 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-05-27 21:04:41 +00:00
										 |  |  | static void timer1_hit(void *opaque) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-07-27 14:30:31 +02:00
										 |  |  |     ETRAXTimerState *t = opaque; | 
					
						
							| 
									
										
										
										
											2009-05-16 01:46:26 +02:00
										 |  |  |     t->r_intr |= 2; | 
					
						
							|  |  |  |     timer_update_irq(t); | 
					
						
							| 
									
										
										
										
											2008-05-27 21:04:41 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void watchdog_hit(void *opaque) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-07-27 14:30:31 +02:00
										 |  |  |     ETRAXTimerState *t = opaque; | 
					
						
							| 
									
										
										
										
											2009-05-16 01:46:26 +02:00
										 |  |  |     if (t->wd_hits == 0) { | 
					
						
							|  |  |  |         /* real hw gives a single tick before reseting but we are
 | 
					
						
							|  |  |  |            a bit friendlier to compensate for our slower execution.  */ | 
					
						
							|  |  |  |         ptimer_set_count(t->ptimer_wd, 10); | 
					
						
							|  |  |  |         ptimer_run(t->ptimer_wd, 1); | 
					
						
							| 
									
										
										
										
											2009-05-16 02:08:16 +02:00
										 |  |  |         qemu_irq_raise(t->nmi); | 
					
						
							| 
									
										
										
										
											2009-05-16 01:46:26 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							| 
									
										
										
										
											2017-05-15 16:41:13 -05:00
										 |  |  |         qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET); | 
					
						
							| 
									
										
										
										
											2009-05-16 01:46:26 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     t->wd_hits++; | 
					
						
							| 
									
										
										
										
											2008-05-27 21:04:41 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-27 14:30:31 +02:00
										 |  |  | static inline void timer_watchdog_update(ETRAXTimerState *t, uint32_t value) | 
					
						
							| 
									
										
										
										
											2008-05-27 21:04:41 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-05-16 01:46:26 +02:00
										 |  |  |     unsigned int wd_en = t->rw_wd_ctrl & (1 << 8); | 
					
						
							|  |  |  |     unsigned int wd_key = t->rw_wd_ctrl >> 9; | 
					
						
							|  |  |  |     unsigned int wd_cnt = t->rw_wd_ctrl & 511; | 
					
						
							|  |  |  |     unsigned int new_key = value >> 9 & ((1 << 7) - 1); | 
					
						
							|  |  |  |     unsigned int new_cmd = (value >> 8) & 1; | 
					
						
							| 
									
										
										
										
											2008-05-27 21:04:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-16 01:46:26 +02:00
										 |  |  |     /* If the watchdog is enabled, they written key must match the
 | 
					
						
							|  |  |  |        complement of the previous.  */ | 
					
						
							|  |  |  |     wd_key = ~wd_key & ((1 << 7) - 1); | 
					
						
							| 
									
										
										
										
											2008-05-27 21:04:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-16 01:46:26 +02:00
										 |  |  |     if (wd_en && wd_key != new_key) | 
					
						
							|  |  |  |         return; | 
					
						
							| 
									
										
										
										
											2008-05-27 21:04:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-16 01:46:26 +02:00
										 |  |  |     D(printf("en=%d new_key=%x oldkey=%x cmd=%d cnt=%d\n",  | 
					
						
							|  |  |  |          wd_en, new_key, wd_key, new_cmd, wd_cnt)); | 
					
						
							| 
									
										
										
										
											2008-05-27 21:04:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-16 01:46:26 +02:00
										 |  |  |     if (t->wd_hits) | 
					
						
							| 
									
										
										
										
											2009-05-16 02:08:16 +02:00
										 |  |  |         qemu_irq_lower(t->nmi); | 
					
						
							| 
									
										
										
										
											2008-06-09 23:33:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-16 01:46:26 +02:00
										 |  |  |     t->wd_hits = 0; | 
					
						
							| 
									
										
										
										
											2008-06-09 23:33:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-22 16:50:36 +01:00
										 |  |  |     ptimer_transaction_begin(t->ptimer_wd); | 
					
						
							| 
									
										
										
										
											2009-05-16 01:46:26 +02:00
										 |  |  |     ptimer_set_freq(t->ptimer_wd, 760); | 
					
						
							|  |  |  |     if (wd_cnt == 0) | 
					
						
							|  |  |  |         wd_cnt = 256; | 
					
						
							|  |  |  |     ptimer_set_count(t->ptimer_wd, wd_cnt); | 
					
						
							|  |  |  |     if (new_cmd) | 
					
						
							|  |  |  |         ptimer_run(t->ptimer_wd, 1); | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |         ptimer_stop(t->ptimer_wd); | 
					
						
							| 
									
										
										
										
											2008-05-27 21:04:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-16 01:46:26 +02:00
										 |  |  |     t->rw_wd_ctrl = value; | 
					
						
							| 
									
										
										
										
											2019-10-22 16:50:36 +01:00
										 |  |  |     ptimer_transaction_commit(t->ptimer_wd); | 
					
						
							| 
									
										
										
										
											2008-05-27 21:04:41 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-10-08 13:26:33 +00:00
										 |  |  | static void | 
					
						
							| 
									
										
										
										
											2012-10-23 12:30:10 +02:00
										 |  |  | timer_write(void *opaque, hwaddr addr, | 
					
						
							| 
									
										
										
										
											2011-08-11 13:47:46 +02:00
										 |  |  |             uint64_t val64, unsigned int size) | 
					
						
							| 
									
										
										
										
											2007-10-08 13:26:33 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-07-27 14:30:31 +02:00
										 |  |  |     ETRAXTimerState *t = opaque; | 
					
						
							| 
									
										
										
										
											2011-08-11 13:47:46 +02:00
										 |  |  |     uint32_t value = val64; | 
					
						
							| 
									
										
										
										
											2009-05-16 01:46:26 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     switch (addr) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         case RW_TMR0_DIV: | 
					
						
							|  |  |  |             t->rw_tmr0_div = value; | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         case RW_TMR0_CTRL: | 
					
						
							|  |  |  |             D(printf ("RW_TMR0_CTRL=%x\n", value)); | 
					
						
							|  |  |  |             t->rw_tmr0_ctrl = value; | 
					
						
							|  |  |  |             update_ctrl(t, 0); | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         case RW_TMR1_DIV: | 
					
						
							|  |  |  |             t->rw_tmr1_div = value; | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         case RW_TMR1_CTRL: | 
					
						
							|  |  |  |             D(printf ("RW_TMR1_CTRL=%x\n", value)); | 
					
						
							|  |  |  |             t->rw_tmr1_ctrl = value; | 
					
						
							|  |  |  |             update_ctrl(t, 1); | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         case RW_INTR_MASK: | 
					
						
							|  |  |  |             D(printf ("RW_INTR_MASK=%x\n", value)); | 
					
						
							|  |  |  |             t->rw_intr_mask = value; | 
					
						
							|  |  |  |             timer_update_irq(t); | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         case RW_WD_CTRL: | 
					
						
							|  |  |  |             timer_watchdog_update(t, value); | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         case RW_ACK_INTR: | 
					
						
							|  |  |  |             t->rw_ack_intr = value; | 
					
						
							|  |  |  |             timer_update_irq(t); | 
					
						
							|  |  |  |             t->rw_ack_intr = 0; | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         default: | 
					
						
							|  |  |  |             printf ("%s " TARGET_FMT_plx " %x\n", | 
					
						
							|  |  |  |                 __func__, addr, value); | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2007-10-08 13:26:33 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-11 13:47:46 +02:00
										 |  |  | static const MemoryRegionOps timer_ops = { | 
					
						
							|  |  |  |     .read = timer_read, | 
					
						
							|  |  |  |     .write = timer_write, | 
					
						
							|  |  |  |     .endianness = DEVICE_LITTLE_ENDIAN, | 
					
						
							|  |  |  |     .valid = { | 
					
						
							|  |  |  |         .min_access_size = 4, | 
					
						
							|  |  |  |         .max_access_size = 4 | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2007-10-08 13:26:33 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-05-27 21:04:41 +00:00
										 |  |  | static void etraxfs_timer_reset(void *opaque) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-07-27 14:30:31 +02:00
										 |  |  |     ETRAXTimerState *t = opaque; | 
					
						
							| 
									
										
										
										
											2009-05-16 01:46:26 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-22 16:50:36 +01:00
										 |  |  |     ptimer_transaction_begin(t->ptimer_t0); | 
					
						
							| 
									
										
										
										
											2009-05-16 01:46:26 +02:00
										 |  |  |     ptimer_stop(t->ptimer_t0); | 
					
						
							| 
									
										
										
										
											2019-10-22 16:50:36 +01:00
										 |  |  |     ptimer_transaction_commit(t->ptimer_t0); | 
					
						
							|  |  |  |     ptimer_transaction_begin(t->ptimer_t1); | 
					
						
							| 
									
										
										
										
											2009-05-16 01:46:26 +02:00
										 |  |  |     ptimer_stop(t->ptimer_t1); | 
					
						
							| 
									
										
										
										
											2019-10-22 16:50:36 +01:00
										 |  |  |     ptimer_transaction_commit(t->ptimer_t1); | 
					
						
							|  |  |  |     ptimer_transaction_begin(t->ptimer_wd); | 
					
						
							| 
									
										
										
										
											2009-05-16 01:46:26 +02:00
										 |  |  |     ptimer_stop(t->ptimer_wd); | 
					
						
							| 
									
										
										
										
											2019-10-22 16:50:36 +01:00
										 |  |  |     ptimer_transaction_commit(t->ptimer_wd); | 
					
						
							| 
									
										
										
										
											2009-05-16 01:46:26 +02:00
										 |  |  |     t->rw_wd_ctrl = 0; | 
					
						
							|  |  |  |     t->r_intr = 0; | 
					
						
							|  |  |  |     t->rw_intr_mask = 0; | 
					
						
							| 
									
										
										
										
											2009-05-16 02:08:16 +02:00
										 |  |  |     qemu_irq_lower(t->irq); | 
					
						
							| 
									
										
										
										
											2008-05-27 21:04:41 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-13 13:48:00 +00:00
										 |  |  | static void etraxfs_timer_realize(DeviceState *dev, Error **errp) | 
					
						
							| 
									
										
										
										
											2007-10-08 13:26:33 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-07-27 14:34:22 +02:00
										 |  |  |     ETRAXTimerState *t = ETRAX_TIMER(dev); | 
					
						
							| 
									
										
										
										
											2018-12-13 13:48:00 +00:00
										 |  |  |     SysBusDevice *sbd = SYS_BUS_DEVICE(dev); | 
					
						
							| 
									
										
										
										
											2007-10-08 13:26:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-22 16:50:36 +01:00
										 |  |  |     t->ptimer_t0 = ptimer_init(timer0_hit, t, PTIMER_POLICY_DEFAULT); | 
					
						
							|  |  |  |     t->ptimer_t1 = ptimer_init(timer1_hit, t, PTIMER_POLICY_DEFAULT); | 
					
						
							|  |  |  |     t->ptimer_wd = ptimer_init(watchdog_hit, t, PTIMER_POLICY_DEFAULT); | 
					
						
							| 
									
										
										
										
											2009-05-16 02:08:16 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-13 13:48:00 +00:00
										 |  |  |     sysbus_init_irq(sbd, &t->irq); | 
					
						
							|  |  |  |     sysbus_init_irq(sbd, &t->nmi); | 
					
						
							| 
									
										
										
										
											2007-10-08 13:26:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-06 21:25:08 -04:00
										 |  |  |     memory_region_init_io(&t->mmio, OBJECT(t), &timer_ops, t, | 
					
						
							|  |  |  |                           "etraxfs-timer", 0x5c); | 
					
						
							| 
									
										
										
										
											2018-12-13 13:48:00 +00:00
										 |  |  |     sysbus_init_mmio(sbd, &t->mmio); | 
					
						
							| 
									
										
										
										
											2009-06-27 09:25:07 +02:00
										 |  |  |     qemu_register_reset(etraxfs_timer_reset, t); | 
					
						
							| 
									
										
										
										
											2007-10-08 13:26:33 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-05-16 02:08:16 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-24 13:12:29 -06:00
										 |  |  | static void etraxfs_timer_class_init(ObjectClass *klass, void *data) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-12-13 13:48:00 +00:00
										 |  |  |     DeviceClass *dc = DEVICE_CLASS(klass); | 
					
						
							| 
									
										
										
										
											2012-01-24 13:12:29 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-13 13:48:00 +00:00
										 |  |  |     dc->realize = etraxfs_timer_realize; | 
					
						
							| 
									
										
										
										
											2012-01-24 13:12:29 -06:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-10 16:19:07 +01:00
										 |  |  | static const TypeInfo etraxfs_timer_info = { | 
					
						
							| 
									
										
										
										
											2013-07-27 14:34:22 +02:00
										 |  |  |     .name          = TYPE_ETRAX_FS_TIMER, | 
					
						
							| 
									
										
										
										
											2011-12-07 21:34:16 -06:00
										 |  |  |     .parent        = TYPE_SYS_BUS_DEVICE, | 
					
						
							| 
									
										
										
										
											2013-07-27 14:30:31 +02:00
										 |  |  |     .instance_size = sizeof(ETRAXTimerState), | 
					
						
							| 
									
										
										
										
											2011-12-07 21:34:16 -06:00
										 |  |  |     .class_init    = etraxfs_timer_class_init, | 
					
						
							| 
									
										
										
										
											2012-01-24 13:12:29 -06:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-09 15:20:55 +01:00
										 |  |  | static void etraxfs_timer_register_types(void) | 
					
						
							| 
									
										
										
										
											2009-05-16 02:08:16 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-07 21:34:16 -06:00
										 |  |  |     type_register_static(&etraxfs_timer_info); | 
					
						
							| 
									
										
										
										
											2009-05-16 02:08:16 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-09 15:20:55 +01:00
										 |  |  | type_init(etraxfs_timer_register_types) |