2004-12-20 00:18:01 +01:00
|
|
|
/*
|
|
|
|
* QEMU Sparc SLAVIO timer controller emulation
|
|
|
|
*
|
2005-04-06 22:47:48 +02:00
|
|
|
* Copyright (c) 2003-2005 Fabrice Bellard
|
2007-09-16 23:08:06 +02:00
|
|
|
*
|
2004-12-20 00:18:01 +01:00
|
|
|
* 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.
|
|
|
|
*/
|
2009-07-15 10:53:09 +02:00
|
|
|
|
2007-11-17 18:14:51 +01:00
|
|
|
#include "sun4m.h"
|
|
|
|
#include "qemu-timer.h"
|
2009-07-15 10:53:09 +02:00
|
|
|
#include "sysbus.h"
|
2004-12-20 00:18:01 +01:00
|
|
|
|
|
|
|
//#define DEBUG_TIMER
|
|
|
|
|
2005-04-06 22:47:48 +02:00
|
|
|
#ifdef DEBUG_TIMER
|
2009-05-13 19:53:17 +02:00
|
|
|
#define DPRINTF(fmt, ...) \
|
|
|
|
do { printf("TIMER: " fmt , ## __VA_ARGS__); } while (0)
|
2005-04-06 22:47:48 +02:00
|
|
|
#else
|
2009-05-13 19:53:17 +02:00
|
|
|
#define DPRINTF(fmt, ...) do {} while (0)
|
2005-04-06 22:47:48 +02:00
|
|
|
#endif
|
|
|
|
|
2004-12-20 00:18:01 +01:00
|
|
|
/*
|
|
|
|
* Registers of hardware timer in sun4m.
|
|
|
|
*
|
|
|
|
* This is the timer/counter part of chip STP2001 (Slave I/O), also
|
|
|
|
* produced as NCR89C105. See
|
|
|
|
* http://www.ibiblio.org/pub/historic-linux/early-ports/Sparc/NCR/NCR89C105.txt
|
2007-09-16 23:08:06 +02:00
|
|
|
*
|
2004-12-20 00:18:01 +01:00
|
|
|
* The 31-bit counter is incremented every 500ns by bit 9. Bits 8..0
|
|
|
|
* are zero. Bit 31 is 1 when count has been reached.
|
|
|
|
*
|
2005-12-05 21:31:52 +01:00
|
|
|
* Per-CPU timers interrupt local CPU, system timer uses normal
|
|
|
|
* interrupt routing.
|
|
|
|
*
|
2004-12-20 00:18:01 +01:00
|
|
|
*/
|
|
|
|
|
2007-10-06 13:25:43 +02:00
|
|
|
#define MAX_CPUS 16
|
|
|
|
|
2009-08-08 22:08:15 +02:00
|
|
|
typedef struct CPUTimerState {
|
2007-05-27 18:37:49 +02:00
|
|
|
qemu_irq irq;
|
2007-05-24 21:48:41 +02:00
|
|
|
ptimer_state *timer;
|
|
|
|
uint32_t count, counthigh, reached;
|
|
|
|
uint64_t limit;
|
2007-10-07 12:00:55 +02:00
|
|
|
// processor only
|
2008-05-10 12:12:00 +02:00
|
|
|
uint32_t running;
|
2009-08-08 22:08:15 +02:00
|
|
|
} CPUTimerState;
|
|
|
|
|
|
|
|
typedef struct SLAVIO_TIMERState {
|
|
|
|
SysBusDevice busdev;
|
|
|
|
uint32_t num_cpus;
|
|
|
|
CPUTimerState cputimer[MAX_CPUS + 1];
|
|
|
|
uint32_t cputimer_mode;
|
2004-12-20 00:18:01 +01:00
|
|
|
} SLAVIO_TIMERState;
|
|
|
|
|
2009-08-08 22:08:15 +02:00
|
|
|
typedef struct TimerContext {
|
|
|
|
SLAVIO_TIMERState *s;
|
|
|
|
unsigned int timer_index; /* 0 for system, 1 ... MAX_CPUS for CPU timers */
|
|
|
|
} TimerContext;
|
|
|
|
|
2007-10-07 12:00:55 +02:00
|
|
|
#define SYS_TIMER_SIZE 0x14
|
2007-10-06 13:25:43 +02:00
|
|
|
#define CPU_TIMER_SIZE 0x10
|
2004-12-20 00:18:01 +01:00
|
|
|
|
2007-12-01 16:58:22 +01:00
|
|
|
#define TIMER_LIMIT 0
|
|
|
|
#define TIMER_COUNTER 1
|
|
|
|
#define TIMER_COUNTER_NORST 2
|
|
|
|
#define TIMER_STATUS 3
|
|
|
|
#define TIMER_MODE 4
|
|
|
|
|
|
|
|
#define TIMER_COUNT_MASK32 0xfffffe00
|
|
|
|
#define TIMER_LIMIT_MASK32 0x7fffffff
|
|
|
|
#define TIMER_MAX_COUNT64 0x7ffffffffffffe00ULL
|
|
|
|
#define TIMER_MAX_COUNT32 0x7ffffe00ULL
|
|
|
|
#define TIMER_REACHED 0x80000000
|
|
|
|
#define TIMER_PERIOD 500ULL // 500ns
|
|
|
|
#define LIMIT_TO_PERIODS(l) ((l) >> 9)
|
|
|
|
#define PERIODS_TO_LIMIT(l) ((l) << 9)
|
|
|
|
|
2009-08-08 22:08:15 +02:00
|
|
|
static int slavio_timer_is_user(TimerContext *tc)
|
2007-10-07 12:00:55 +02:00
|
|
|
{
|
2009-08-08 22:08:15 +02:00
|
|
|
SLAVIO_TIMERState *s = tc->s;
|
|
|
|
unsigned int timer_index = tc->timer_index;
|
|
|
|
|
|
|
|
return timer_index != 0 && (s->cputimer_mode & (1 << (timer_index - 1)));
|
2007-10-07 12:00:55 +02:00
|
|
|
}
|
|
|
|
|
2004-12-20 00:18:01 +01:00
|
|
|
// Update count, set irq, update expire_time
|
2007-05-24 21:48:41 +02:00
|
|
|
// Convert from ptimer countdown units
|
2009-08-08 22:08:15 +02:00
|
|
|
static void slavio_timer_get_out(CPUTimerState *t)
|
2004-12-20 00:18:01 +01:00
|
|
|
{
|
2007-12-19 18:58:24 +01:00
|
|
|
uint64_t count, limit;
|
2004-12-20 00:18:01 +01:00
|
|
|
|
2009-08-08 22:08:15 +02:00
|
|
|
if (t->limit == 0) { /* free-run system or processor counter */
|
2007-12-19 18:58:24 +01:00
|
|
|
limit = TIMER_MAX_COUNT32;
|
2009-08-08 22:08:15 +02:00
|
|
|
} else {
|
|
|
|
limit = t->limit;
|
|
|
|
}
|
|
|
|
if (t->timer) {
|
|
|
|
count = limit - PERIODS_TO_LIMIT(ptimer_get_count(t->timer));
|
|
|
|
} else {
|
2007-12-27 21:23:20 +01:00
|
|
|
count = 0;
|
2009-08-08 22:08:15 +02:00
|
|
|
}
|
|
|
|
DPRINTF("get_out: limit %" PRIx64 " count %x%08x\n", t->limit, t->counthigh,
|
|
|
|
t->count);
|
|
|
|
t->count = count & TIMER_COUNT_MASK32;
|
|
|
|
t->counthigh = count >> 32;
|
2004-12-20 00:18:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// timer callback
|
|
|
|
static void slavio_timer_irq(void *opaque)
|
|
|
|
{
|
2009-08-08 22:08:15 +02:00
|
|
|
TimerContext *tc = opaque;
|
|
|
|
SLAVIO_TIMERState *s = tc->s;
|
|
|
|
CPUTimerState *t = &s->cputimer[tc->timer_index];
|
|
|
|
|
|
|
|
slavio_timer_get_out(t);
|
|
|
|
DPRINTF("callback: count %x%08x\n", t->counthigh, t->count);
|
|
|
|
t->reached = TIMER_REACHED;
|
|
|
|
if (!slavio_timer_is_user(tc)) {
|
|
|
|
qemu_irq_raise(t->irq);
|
|
|
|
}
|
2004-12-20 00:18:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t slavio_timer_mem_readl(void *opaque, target_phys_addr_t addr)
|
|
|
|
{
|
2009-08-08 22:08:15 +02:00
|
|
|
TimerContext *tc = opaque;
|
|
|
|
SLAVIO_TIMERState *s = tc->s;
|
2007-05-24 21:48:41 +02:00
|
|
|
uint32_t saddr, ret;
|
2009-08-08 22:08:15 +02:00
|
|
|
unsigned int timer_index = tc->timer_index;
|
|
|
|
CPUTimerState *t = &s->cputimer[timer_index];
|
2004-12-20 00:18:01 +01:00
|
|
|
|
2008-12-02 18:47:02 +01:00
|
|
|
saddr = addr >> 2;
|
2004-12-20 00:18:01 +01:00
|
|
|
switch (saddr) {
|
2007-12-01 16:58:22 +01:00
|
|
|
case TIMER_LIMIT:
|
2007-10-06 13:28:21 +02:00
|
|
|
// read limit (system counter mode) or read most signifying
|
|
|
|
// part of counter (user mode)
|
2009-08-08 22:08:15 +02:00
|
|
|
if (slavio_timer_is_user(tc)) {
|
2007-10-07 12:00:55 +02:00
|
|
|
// read user timer MSW
|
2009-08-08 22:08:15 +02:00
|
|
|
slavio_timer_get_out(t);
|
|
|
|
ret = t->counthigh | t->reached;
|
2007-10-07 12:00:55 +02:00
|
|
|
} else {
|
|
|
|
// read limit
|
2007-10-06 13:28:21 +02:00
|
|
|
// clear irq
|
2009-08-08 22:08:15 +02:00
|
|
|
qemu_irq_lower(t->irq);
|
|
|
|
t->reached = 0;
|
|
|
|
ret = t->limit & TIMER_LIMIT_MASK32;
|
2007-10-06 13:28:21 +02:00
|
|
|
}
|
2007-05-24 21:48:41 +02:00
|
|
|
break;
|
2007-12-01 16:58:22 +01:00
|
|
|
case TIMER_COUNTER:
|
2007-10-06 13:28:21 +02:00
|
|
|
// read counter and reached bit (system mode) or read lsbits
|
|
|
|
// of counter (user mode)
|
2009-08-08 22:08:15 +02:00
|
|
|
slavio_timer_get_out(t);
|
|
|
|
if (slavio_timer_is_user(tc)) { // read user timer LSW
|
|
|
|
ret = t->count & TIMER_MAX_COUNT64;
|
|
|
|
} else { // read limit
|
|
|
|
ret = (t->count & TIMER_MAX_COUNT32) |
|
|
|
|
t->reached;
|
|
|
|
}
|
2007-05-24 21:48:41 +02:00
|
|
|
break;
|
2007-12-01 16:58:22 +01:00
|
|
|
case TIMER_STATUS:
|
2007-10-07 12:00:55 +02:00
|
|
|
// only available in processor counter/timer
|
2007-10-06 13:28:21 +02:00
|
|
|
// read start/stop status
|
2009-08-08 22:08:15 +02:00
|
|
|
if (timer_index > 0) {
|
|
|
|
ret = t->running;
|
|
|
|
} else {
|
|
|
|
ret = 0;
|
|
|
|
}
|
2007-05-24 21:48:41 +02:00
|
|
|
break;
|
2007-12-01 16:58:22 +01:00
|
|
|
case TIMER_MODE:
|
2007-10-07 12:00:55 +02:00
|
|
|
// only available in system counter
|
2007-10-06 13:28:21 +02:00
|
|
|
// read user/system mode
|
2009-08-08 22:08:15 +02:00
|
|
|
ret = s->cputimer_mode;
|
2007-05-24 21:48:41 +02:00
|
|
|
break;
|
2004-12-20 00:18:01 +01:00
|
|
|
default:
|
2007-10-07 12:00:55 +02:00
|
|
|
DPRINTF("invalid read address " TARGET_FMT_plx "\n", addr);
|
2007-05-24 21:48:41 +02:00
|
|
|
ret = 0;
|
|
|
|
break;
|
2004-12-20 00:18:01 +01:00
|
|
|
}
|
2007-05-24 21:48:41 +02:00
|
|
|
DPRINTF("read " TARGET_FMT_plx " = %08x\n", addr, ret);
|
|
|
|
|
|
|
|
return ret;
|
2004-12-20 00:18:01 +01:00
|
|
|
}
|
|
|
|
|
2007-12-01 16:58:22 +01:00
|
|
|
static void slavio_timer_mem_writel(void *opaque, target_phys_addr_t addr,
|
|
|
|
uint32_t val)
|
2004-12-20 00:18:01 +01:00
|
|
|
{
|
2009-08-08 22:08:15 +02:00
|
|
|
TimerContext *tc = opaque;
|
|
|
|
SLAVIO_TIMERState *s = tc->s;
|
2004-12-20 00:18:01 +01:00
|
|
|
uint32_t saddr;
|
2009-08-08 22:08:15 +02:00
|
|
|
unsigned int timer_index = tc->timer_index;
|
|
|
|
CPUTimerState *t = &s->cputimer[timer_index];
|
2004-12-20 00:18:01 +01:00
|
|
|
|
2007-05-24 21:48:41 +02:00
|
|
|
DPRINTF("write " TARGET_FMT_plx " %08x\n", addr, val);
|
2008-12-02 18:47:02 +01:00
|
|
|
saddr = addr >> 2;
|
2004-12-20 00:18:01 +01:00
|
|
|
switch (saddr) {
|
2007-12-01 16:58:22 +01:00
|
|
|
case TIMER_LIMIT:
|
2009-08-08 22:08:15 +02:00
|
|
|
if (slavio_timer_is_user(tc)) {
|
2008-01-25 20:51:27 +01:00
|
|
|
uint64_t count;
|
|
|
|
|
2007-10-07 12:00:55 +02:00
|
|
|
// set user counter MSW, reset counter
|
2009-08-08 22:08:15 +02:00
|
|
|
t->limit = TIMER_MAX_COUNT64;
|
|
|
|
t->counthigh = val & (TIMER_MAX_COUNT64 >> 32);
|
|
|
|
t->reached = 0;
|
|
|
|
count = ((uint64_t)t->counthigh << 32) | t->count;
|
2009-07-20 19:19:25 +02:00
|
|
|
DPRINTF("processor %d user timer set to %016" PRIx64 "\n",
|
2009-08-08 22:08:15 +02:00
|
|
|
timer_index, count);
|
|
|
|
if (t->timer) {
|
|
|
|
ptimer_set_count(t->timer, LIMIT_TO_PERIODS(t->limit - count));
|
|
|
|
}
|
2007-10-07 12:00:55 +02:00
|
|
|
} else {
|
|
|
|
// set limit, reset counter
|
2009-08-08 22:08:15 +02:00
|
|
|
qemu_irq_lower(t->irq);
|
|
|
|
t->limit = val & TIMER_MAX_COUNT32;
|
|
|
|
if (t->timer) {
|
|
|
|
if (t->limit == 0) { /* free-run */
|
|
|
|
ptimer_set_limit(t->timer,
|
2008-05-12 18:13:33 +02:00
|
|
|
LIMIT_TO_PERIODS(TIMER_MAX_COUNT32), 1);
|
2009-08-08 22:08:15 +02:00
|
|
|
} else {
|
|
|
|
ptimer_set_limit(t->timer, LIMIT_TO_PERIODS(t->limit), 1);
|
|
|
|
}
|
2007-12-27 21:23:20 +01:00
|
|
|
}
|
2007-10-06 13:25:43 +02:00
|
|
|
}
|
2007-10-07 12:00:55 +02:00
|
|
|
break;
|
2007-12-01 16:58:22 +01:00
|
|
|
case TIMER_COUNTER:
|
2009-08-08 22:08:15 +02:00
|
|
|
if (slavio_timer_is_user(tc)) {
|
2008-01-25 20:51:27 +01:00
|
|
|
uint64_t count;
|
|
|
|
|
2007-10-07 12:00:55 +02:00
|
|
|
// set user counter LSW, reset counter
|
2009-08-08 22:08:15 +02:00
|
|
|
t->limit = TIMER_MAX_COUNT64;
|
|
|
|
t->count = val & TIMER_MAX_COUNT64;
|
|
|
|
t->reached = 0;
|
|
|
|
count = ((uint64_t)t->counthigh) << 32 | t->count;
|
2009-07-20 19:19:25 +02:00
|
|
|
DPRINTF("processor %d user timer set to %016" PRIx64 "\n",
|
2009-08-08 22:08:15 +02:00
|
|
|
timer_index, count);
|
|
|
|
if (t->timer) {
|
|
|
|
ptimer_set_count(t->timer, LIMIT_TO_PERIODS(t->limit - count));
|
|
|
|
}
|
2007-10-07 12:00:55 +02:00
|
|
|
} else
|
|
|
|
DPRINTF("not user timer\n");
|
|
|
|
break;
|
2007-12-01 16:58:22 +01:00
|
|
|
case TIMER_COUNTER_NORST:
|
2007-10-06 13:28:21 +02:00
|
|
|
// set limit without resetting counter
|
2009-08-08 22:08:15 +02:00
|
|
|
t->limit = val & TIMER_MAX_COUNT32;
|
|
|
|
if (t->timer) {
|
|
|
|
if (t->limit == 0) { /* free-run */
|
|
|
|
ptimer_set_limit(t->timer,
|
2008-05-12 18:13:33 +02:00
|
|
|
LIMIT_TO_PERIODS(TIMER_MAX_COUNT32), 0);
|
2009-08-08 22:08:15 +02:00
|
|
|
} else {
|
|
|
|
ptimer_set_limit(t->timer, LIMIT_TO_PERIODS(t->limit), 0);
|
|
|
|
}
|
2007-12-27 21:23:20 +01:00
|
|
|
}
|
2007-10-06 13:28:21 +02:00
|
|
|
break;
|
2007-12-01 16:58:22 +01:00
|
|
|
case TIMER_STATUS:
|
2009-08-08 22:08:15 +02:00
|
|
|
if (slavio_timer_is_user(tc)) {
|
2007-10-07 12:00:55 +02:00
|
|
|
// start/stop user counter
|
2009-08-08 22:08:15 +02:00
|
|
|
if ((val & 1) && !t->running) {
|
|
|
|
DPRINTF("processor %d user timer started\n",
|
|
|
|
timer_index);
|
|
|
|
if (t->timer) {
|
|
|
|
ptimer_run(t->timer, 0);
|
|
|
|
}
|
|
|
|
t->running = 1;
|
|
|
|
} else if (!(val & 1) && t->running) {
|
|
|
|
DPRINTF("processor %d user timer stopped\n",
|
|
|
|
timer_index);
|
|
|
|
if (t->timer) {
|
|
|
|
ptimer_stop(t->timer);
|
|
|
|
}
|
|
|
|
t->running = 0;
|
2007-10-06 13:28:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2007-12-01 16:58:22 +01:00
|
|
|
case TIMER_MODE:
|
2009-08-08 22:08:15 +02:00
|
|
|
if (timer_index == 0) {
|
2007-10-06 13:25:43 +02:00
|
|
|
unsigned int i;
|
|
|
|
|
2009-08-08 22:08:15 +02:00
|
|
|
for (i = 0; i < s->num_cpus; i++) {
|
2008-01-26 10:13:46 +01:00
|
|
|
unsigned int processor = 1 << i;
|
2009-08-08 22:08:15 +02:00
|
|
|
CPUTimerState *curr_timer = &s->cputimer[i + 1];
|
2008-01-26 10:13:46 +01:00
|
|
|
|
|
|
|
// check for a change in timer mode for this processor
|
2009-08-08 22:08:15 +02:00
|
|
|
if ((val & processor) != (s->cputimer_mode & processor)) {
|
2008-01-26 10:13:46 +01:00
|
|
|
if (val & processor) { // counter -> user timer
|
2009-08-08 22:08:15 +02:00
|
|
|
qemu_irq_lower(curr_timer->irq);
|
2008-01-26 10:13:46 +01:00
|
|
|
// counters are always running
|
2009-08-08 22:08:15 +02:00
|
|
|
ptimer_stop(curr_timer->timer);
|
|
|
|
curr_timer->running = 0;
|
2008-01-26 10:13:46 +01:00
|
|
|
// user timer limit is always the same
|
2009-08-08 22:08:15 +02:00
|
|
|
curr_timer->limit = TIMER_MAX_COUNT64;
|
|
|
|
ptimer_set_limit(curr_timer->timer,
|
|
|
|
LIMIT_TO_PERIODS(curr_timer->limit),
|
2008-05-12 18:13:33 +02:00
|
|
|
1);
|
2008-01-26 10:13:46 +01:00
|
|
|
// set this processors user timer bit in config
|
|
|
|
// register
|
2009-08-08 22:08:15 +02:00
|
|
|
s->cputimer_mode |= processor;
|
2008-01-26 10:13:46 +01:00
|
|
|
DPRINTF("processor %d changed from counter to user "
|
2009-08-08 22:08:15 +02:00
|
|
|
"timer\n", timer_index);
|
2008-01-26 10:13:46 +01:00
|
|
|
} else { // user timer -> counter
|
|
|
|
// stop the user timer if it is running
|
2009-08-08 22:08:15 +02:00
|
|
|
if (curr_timer->running) {
|
|
|
|
ptimer_stop(curr_timer->timer);
|
|
|
|
}
|
2008-01-26 10:13:46 +01:00
|
|
|
// start the counter
|
2009-08-08 22:08:15 +02:00
|
|
|
ptimer_run(curr_timer->timer, 0);
|
|
|
|
curr_timer->running = 1;
|
2008-01-26 10:13:46 +01:00
|
|
|
// clear this processors user timer bit in config
|
|
|
|
// register
|
2009-08-08 22:08:15 +02:00
|
|
|
s->cputimer_mode &= ~processor;
|
2008-01-26 10:13:46 +01:00
|
|
|
DPRINTF("processor %d changed from user timer to "
|
2009-08-08 22:08:15 +02:00
|
|
|
"counter\n", timer_index);
|
2008-01-26 10:13:46 +01:00
|
|
|
}
|
2007-10-07 12:00:55 +02:00
|
|
|
}
|
2007-10-06 13:25:43 +02:00
|
|
|
}
|
2009-08-08 22:08:15 +02:00
|
|
|
} else {
|
2007-10-07 12:00:55 +02:00
|
|
|
DPRINTF("not system timer\n");
|
2009-08-08 22:08:15 +02:00
|
|
|
}
|
2007-10-06 13:28:21 +02:00
|
|
|
break;
|
2004-12-20 00:18:01 +01:00
|
|
|
default:
|
2007-10-07 12:00:55 +02:00
|
|
|
DPRINTF("invalid write address " TARGET_FMT_plx "\n", addr);
|
2007-10-06 13:28:21 +02:00
|
|
|
break;
|
2004-12-20 00:18:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-25 20:29:31 +02:00
|
|
|
static CPUReadMemoryFunc * const slavio_timer_mem_read[3] = {
|
2008-01-01 18:06:38 +01:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2004-12-20 00:18:01 +01:00
|
|
|
slavio_timer_mem_readl,
|
|
|
|
};
|
|
|
|
|
2009-08-25 20:29:31 +02:00
|
|
|
static CPUWriteMemoryFunc * const slavio_timer_mem_write[3] = {
|
2008-01-01 18:06:38 +01:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2004-12-20 00:18:01 +01:00
|
|
|
slavio_timer_mem_writel,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void slavio_timer_save(QEMUFile *f, void *opaque)
|
|
|
|
{
|
|
|
|
SLAVIO_TIMERState *s = opaque;
|
2009-08-08 22:08:15 +02:00
|
|
|
unsigned int i;
|
|
|
|
CPUTimerState *curr_timer;
|
|
|
|
|
|
|
|
for (i = 0; i <= MAX_CPUS; i++) {
|
|
|
|
curr_timer = &s->cputimer[i];
|
|
|
|
qemu_put_be64s(f, &curr_timer->limit);
|
|
|
|
qemu_put_be32s(f, &curr_timer->count);
|
|
|
|
qemu_put_be32s(f, &curr_timer->counthigh);
|
|
|
|
qemu_put_be32s(f, &curr_timer->reached);
|
|
|
|
qemu_put_be32s(f, &curr_timer->running);
|
|
|
|
if (curr_timer->timer) {
|
|
|
|
qemu_put_ptimer(f, curr_timer->timer);
|
|
|
|
}
|
|
|
|
}
|
2004-12-20 00:18:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int slavio_timer_load(QEMUFile *f, void *opaque, int version_id)
|
|
|
|
{
|
|
|
|
SLAVIO_TIMERState *s = opaque;
|
2009-08-08 22:08:15 +02:00
|
|
|
unsigned int i;
|
|
|
|
CPUTimerState *curr_timer;
|
2007-09-17 10:09:54 +02:00
|
|
|
|
2007-12-27 21:23:20 +01:00
|
|
|
if (version_id != 3)
|
2004-12-20 00:18:01 +01:00
|
|
|
return -EINVAL;
|
|
|
|
|
2009-08-08 22:08:15 +02:00
|
|
|
for (i = 0; i <= MAX_CPUS; i++) {
|
|
|
|
curr_timer = &s->cputimer[i];
|
|
|
|
qemu_get_be64s(f, &curr_timer->limit);
|
|
|
|
qemu_get_be32s(f, &curr_timer->count);
|
|
|
|
qemu_get_be32s(f, &curr_timer->counthigh);
|
|
|
|
qemu_get_be32s(f, &curr_timer->reached);
|
|
|
|
qemu_get_be32s(f, &curr_timer->running);
|
|
|
|
if (curr_timer->timer) {
|
|
|
|
qemu_get_ptimer(f, curr_timer->timer);
|
|
|
|
}
|
|
|
|
}
|
2007-05-24 21:48:41 +02:00
|
|
|
|
2004-12-20 00:18:01 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void slavio_timer_reset(void *opaque)
|
|
|
|
{
|
|
|
|
SLAVIO_TIMERState *s = opaque;
|
2009-08-08 22:08:15 +02:00
|
|
|
unsigned int i;
|
|
|
|
CPUTimerState *curr_timer;
|
|
|
|
|
|
|
|
for (i = 0; i <= MAX_CPUS; i++) {
|
|
|
|
curr_timer = &s->cputimer[i];
|
|
|
|
curr_timer->limit = 0;
|
|
|
|
curr_timer->count = 0;
|
|
|
|
curr_timer->reached = 0;
|
|
|
|
if (i < s->num_cpus) {
|
|
|
|
ptimer_set_limit(curr_timer->timer,
|
|
|
|
LIMIT_TO_PERIODS(TIMER_MAX_COUNT32), 1);
|
|
|
|
ptimer_run(curr_timer->timer, 0);
|
|
|
|
}
|
|
|
|
curr_timer->running = 1;
|
2007-12-27 21:23:20 +01:00
|
|
|
}
|
2009-08-08 22:08:15 +02:00
|
|
|
s->cputimer_mode = 0;
|
2004-12-20 00:18:01 +01:00
|
|
|
}
|
|
|
|
|
2009-08-14 10:36:05 +02:00
|
|
|
static int slavio_timer_init1(SysBusDevice *dev)
|
2009-07-15 10:53:09 +02:00
|
|
|
{
|
|
|
|
int io;
|
|
|
|
SLAVIO_TIMERState *s = FROM_SYSBUS(SLAVIO_TIMERState, dev);
|
2007-05-24 21:48:41 +02:00
|
|
|
QEMUBH *bh;
|
2009-08-08 22:08:15 +02:00
|
|
|
unsigned int i;
|
|
|
|
TimerContext *tc;
|
2004-12-20 00:18:01 +01:00
|
|
|
|
2009-08-08 22:08:15 +02:00
|
|
|
for (i = 0; i <= MAX_CPUS; i++) {
|
|
|
|
tc = qemu_mallocz(sizeof(TimerContext));
|
|
|
|
tc->s = s;
|
|
|
|
tc->timer_index = i;
|
2009-07-15 10:53:09 +02:00
|
|
|
|
2009-08-08 22:08:15 +02:00
|
|
|
bh = qemu_bh_new(slavio_timer_irq, tc);
|
|
|
|
s->cputimer[i].timer = ptimer_init(bh);
|
|
|
|
ptimer_set_period(s->cputimer[i].timer, TIMER_PERIOD);
|
2004-12-20 00:18:01 +01:00
|
|
|
|
2009-08-08 22:08:15 +02:00
|
|
|
io = cpu_register_io_memory(slavio_timer_mem_read,
|
|
|
|
slavio_timer_mem_write, tc);
|
|
|
|
if (i == 0) {
|
|
|
|
sysbus_init_mmio(dev, SYS_TIMER_SIZE, io);
|
|
|
|
} else {
|
|
|
|
sysbus_init_mmio(dev, CPU_TIMER_SIZE, io);
|
|
|
|
}
|
|
|
|
|
|
|
|
sysbus_init_irq(dev, &s->cputimer[i].irq);
|
2009-07-15 10:53:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
register_savevm("slavio_timer", -1, 3, slavio_timer_save,
|
2007-12-01 16:58:22 +01:00
|
|
|
slavio_timer_load, s);
|
2009-06-27 09:25:07 +02:00
|
|
|
qemu_register_reset(slavio_timer_reset, s);
|
2004-12-20 00:18:01 +01:00
|
|
|
slavio_timer_reset(s);
|
2009-08-14 10:36:05 +02:00
|
|
|
return 0;
|
2007-10-06 13:25:43 +02:00
|
|
|
}
|
|
|
|
|
2009-07-15 10:53:09 +02:00
|
|
|
static SysBusDeviceInfo slavio_timer_info = {
|
|
|
|
.init = slavio_timer_init1,
|
|
|
|
.qdev.name = "slavio_timer",
|
|
|
|
.qdev.size = sizeof(SLAVIO_TIMERState),
|
2009-07-15 13:43:31 +02:00
|
|
|
.qdev.props = (Property[]) {
|
2009-08-03 17:35:32 +02:00
|
|
|
DEFINE_PROP_UINT32("num_cpus", SLAVIO_TIMERState, num_cpus, 0),
|
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
2009-07-15 10:53:09 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static void slavio_timer_register_devices(void)
|
|
|
|
{
|
|
|
|
sysbus_register_withprop(&slavio_timer_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
device_init(slavio_timer_register_devices)
|