Statistics
| Branch: | Revision:

root / hw / timer.c @ 546fa6ab

History | View | Annotate | Download (2.6 kB)

1 7993f8bc bellard
/*
2 7993f8bc bellard
 * QEMU Sparc timer controller emulation
3 7993f8bc bellard
 * 
4 7993f8bc bellard
 * Copyright (c) 2003-2004 Fabrice Bellard
5 7993f8bc bellard
 * 
6 7993f8bc bellard
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 7993f8bc bellard
 * of this software and associated documentation files (the "Software"), to deal
8 7993f8bc bellard
 * in the Software without restriction, including without limitation the rights
9 7993f8bc bellard
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 7993f8bc bellard
 * copies of the Software, and to permit persons to whom the Software is
11 7993f8bc bellard
 * furnished to do so, subject to the following conditions:
12 7993f8bc bellard
 *
13 7993f8bc bellard
 * The above copyright notice and this permission notice shall be included in
14 7993f8bc bellard
 * all copies or substantial portions of the Software.
15 7993f8bc bellard
 *
16 7993f8bc bellard
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 7993f8bc bellard
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 7993f8bc bellard
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 7993f8bc bellard
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 7993f8bc bellard
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 7993f8bc bellard
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 7993f8bc bellard
 * THE SOFTWARE.
23 7993f8bc bellard
 */
24 7993f8bc bellard
#include "vl.h"
25 7993f8bc bellard
26 7993f8bc bellard
/*
27 7993f8bc bellard
 * Registers of hardware timer in sun4m.
28 7993f8bc bellard
 */
29 7993f8bc bellard
struct sun4m_timer_percpu {
30 7993f8bc bellard
        volatile unsigned int l14_timer_limit; /* Initial value is 0x009c4000 */
31 7993f8bc bellard
        volatile unsigned int l14_cur_count;
32 7993f8bc bellard
};
33 7993f8bc bellard
34 7993f8bc bellard
struct sun4m_timer_global {
35 7993f8bc bellard
        volatile unsigned int l10_timer_limit;
36 7993f8bc bellard
        volatile unsigned int l10_cur_count;
37 7993f8bc bellard
};
38 7993f8bc bellard
39 7993f8bc bellard
typedef struct TIMERState {
40 7993f8bc bellard
    uint32_t addr;
41 7993f8bc bellard
    uint32_t timer_regs[2];
42 7993f8bc bellard
    int irq;
43 7993f8bc bellard
} TIMERState;
44 7993f8bc bellard
45 7993f8bc bellard
static uint32_t timer_mem_readl(void *opaque, target_phys_addr_t addr)
46 7993f8bc bellard
{
47 7993f8bc bellard
    TIMERState *s = opaque;
48 7993f8bc bellard
    uint32_t saddr;
49 7993f8bc bellard
50 7993f8bc bellard
    saddr = (addr - s->addr) >> 2;
51 7993f8bc bellard
    switch (saddr) {
52 7993f8bc bellard
    default:
53 7993f8bc bellard
        return s->timer_regs[saddr];
54 7993f8bc bellard
        break;
55 7993f8bc bellard
    }
56 7993f8bc bellard
    return 0;
57 7993f8bc bellard
}
58 7993f8bc bellard
59 7993f8bc bellard
static void timer_mem_writel(void *opaque, target_phys_addr_t addr, uint32_t val)
60 7993f8bc bellard
{
61 7993f8bc bellard
    TIMERState *s = opaque;
62 7993f8bc bellard
    uint32_t saddr;
63 7993f8bc bellard
64 7993f8bc bellard
    saddr = (addr - s->addr) >> 2;
65 7993f8bc bellard
    switch (saddr) {
66 7993f8bc bellard
    default:
67 7993f8bc bellard
        s->timer_regs[saddr] = val;
68 7993f8bc bellard
        break;
69 7993f8bc bellard
    }
70 7993f8bc bellard
}
71 7993f8bc bellard
72 7993f8bc bellard
static CPUReadMemoryFunc *timer_mem_read[3] = {
73 7993f8bc bellard
    timer_mem_readl,
74 7993f8bc bellard
    timer_mem_readl,
75 7993f8bc bellard
    timer_mem_readl,
76 7993f8bc bellard
};
77 7993f8bc bellard
78 7993f8bc bellard
static CPUWriteMemoryFunc *timer_mem_write[3] = {
79 7993f8bc bellard
    timer_mem_writel,
80 7993f8bc bellard
    timer_mem_writel,
81 7993f8bc bellard
    timer_mem_writel,
82 7993f8bc bellard
};
83 7993f8bc bellard
84 7993f8bc bellard
void timer_init(uint32_t addr, int irq)
85 7993f8bc bellard
{
86 7993f8bc bellard
    int timer_io_memory;
87 7993f8bc bellard
    TIMERState *s;
88 7993f8bc bellard
89 7993f8bc bellard
    s = qemu_mallocz(sizeof(TIMERState));
90 7993f8bc bellard
    if (!s)
91 7993f8bc bellard
        return;
92 7993f8bc bellard
    s->addr = addr;
93 7993f8bc bellard
    s->irq = irq;
94 7993f8bc bellard
95 7993f8bc bellard
    timer_io_memory = cpu_register_io_memory(0, timer_mem_read, timer_mem_write, s);
96 7993f8bc bellard
    cpu_register_physical_memory(addr, 2, timer_io_memory);
97 7993f8bc bellard
}