bellard | 80cabfa | 2004-03-14 12:20:30 +0000 | [diff] [blame] | 1 | /* |
| 2 | * QEMU 8253/8254 interval timer emulation |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 3 | * |
bellard | 80cabfa | 2004-03-14 12:20:30 +0000 | [diff] [blame] | 4 | * Copyright (c) 2003-2004 Fabrice Bellard |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 5 | * |
bellard | 80cabfa | 2004-03-14 12:20:30 +0000 | [diff] [blame] | 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to deal |
| 8 | * in the Software without restriction, including without limitation the rights |
| 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | * copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in |
| 14 | * all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 22 | * THE SOFTWARE. |
| 23 | */ |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 24 | #include "hw.h" |
| 25 | #include "pc.h" |
| 26 | #include "isa.h" |
| 27 | #include "qemu-timer.h" |
Jan Kiszka | b1277b0 | 2012-02-01 20:31:39 +0100 | [diff] [blame] | 28 | #include "i8254.h" |
Jan Kiszka | d11e859 | 2012-03-02 20:28:46 +0100 | [diff] [blame] | 29 | #include "i8254_internal.h" |
bellard | 80cabfa | 2004-03-14 12:20:30 +0000 | [diff] [blame] | 30 | |
bellard | b0a21b5 | 2004-03-31 18:58:38 +0000 | [diff] [blame] | 31 | //#define DEBUG_PIT |
| 32 | |
bellard | ec844b9 | 2004-05-03 23:18:25 +0000 | [diff] [blame] | 33 | #define RW_STATE_LSB 1 |
| 34 | #define RW_STATE_MSB 2 |
| 35 | #define RW_STATE_WORD0 3 |
| 36 | #define RW_STATE_WORD1 4 |
bellard | 80cabfa | 2004-03-14 12:20:30 +0000 | [diff] [blame] | 37 | |
bellard | b0a21b5 | 2004-03-31 18:58:38 +0000 | [diff] [blame] | 38 | static void pit_irq_timer_update(PITChannelState *s, int64_t current_time); |
| 39 | |
bellard | 80cabfa | 2004-03-14 12:20:30 +0000 | [diff] [blame] | 40 | static int pit_get_count(PITChannelState *s) |
| 41 | { |
| 42 | uint64_t d; |
| 43 | int counter; |
| 44 | |
Paolo Bonzini | 7447545 | 2011-03-11 16:47:48 +0100 | [diff] [blame] | 45 | d = muldiv64(qemu_get_clock_ns(vm_clock) - s->count_load_time, PIT_FREQ, |
Juan Quintela | 6ee093c | 2009-09-10 03:04:26 +0200 | [diff] [blame] | 46 | get_ticks_per_sec()); |
bellard | 80cabfa | 2004-03-14 12:20:30 +0000 | [diff] [blame] | 47 | switch(s->mode) { |
| 48 | case 0: |
| 49 | case 1: |
| 50 | case 4: |
| 51 | case 5: |
| 52 | counter = (s->count - d) & 0xffff; |
| 53 | break; |
| 54 | case 3: |
| 55 | /* XXX: may be incorrect for odd counts */ |
| 56 | counter = s->count - ((2 * d) % s->count); |
| 57 | break; |
| 58 | default: |
| 59 | counter = s->count - (d % s->count); |
| 60 | break; |
| 61 | } |
| 62 | return counter; |
| 63 | } |
| 64 | |
bellard | 80cabfa | 2004-03-14 12:20:30 +0000 | [diff] [blame] | 65 | /* val must be 0 or 1 */ |
Jan Kiszka | d11e859 | 2012-03-02 20:28:46 +0100 | [diff] [blame] | 66 | static void pit_set_channel_gate(PITCommonState *s, PITChannelState *sc, |
| 67 | int val) |
bellard | 80cabfa | 2004-03-14 12:20:30 +0000 | [diff] [blame] | 68 | { |
Jan Kiszka | d11e859 | 2012-03-02 20:28:46 +0100 | [diff] [blame] | 69 | switch (sc->mode) { |
bellard | 80cabfa | 2004-03-14 12:20:30 +0000 | [diff] [blame] | 70 | default: |
| 71 | case 0: |
| 72 | case 4: |
| 73 | /* XXX: just disable/enable counting */ |
| 74 | break; |
| 75 | case 1: |
| 76 | case 5: |
Jan Kiszka | d11e859 | 2012-03-02 20:28:46 +0100 | [diff] [blame] | 77 | if (sc->gate < val) { |
bellard | 80cabfa | 2004-03-14 12:20:30 +0000 | [diff] [blame] | 78 | /* restart counting on rising edge */ |
Jan Kiszka | d11e859 | 2012-03-02 20:28:46 +0100 | [diff] [blame] | 79 | sc->count_load_time = qemu_get_clock_ns(vm_clock); |
| 80 | pit_irq_timer_update(sc, sc->count_load_time); |
bellard | 80cabfa | 2004-03-14 12:20:30 +0000 | [diff] [blame] | 81 | } |
| 82 | break; |
| 83 | case 2: |
| 84 | case 3: |
Jan Kiszka | d11e859 | 2012-03-02 20:28:46 +0100 | [diff] [blame] | 85 | if (sc->gate < val) { |
bellard | 80cabfa | 2004-03-14 12:20:30 +0000 | [diff] [blame] | 86 | /* restart counting on rising edge */ |
Jan Kiszka | d11e859 | 2012-03-02 20:28:46 +0100 | [diff] [blame] | 87 | sc->count_load_time = qemu_get_clock_ns(vm_clock); |
| 88 | pit_irq_timer_update(sc, sc->count_load_time); |
bellard | 80cabfa | 2004-03-14 12:20:30 +0000 | [diff] [blame] | 89 | } |
| 90 | /* XXX: disable/enable counting */ |
| 91 | break; |
| 92 | } |
Jan Kiszka | d11e859 | 2012-03-02 20:28:46 +0100 | [diff] [blame] | 93 | sc->gate = val; |
bellard | fd06c37 | 2006-04-24 21:58:30 +0000 | [diff] [blame] | 94 | } |
| 95 | |
bellard | 80cabfa | 2004-03-14 12:20:30 +0000 | [diff] [blame] | 96 | static inline void pit_load_count(PITChannelState *s, int val) |
| 97 | { |
| 98 | if (val == 0) |
| 99 | val = 0x10000; |
Paolo Bonzini | 7447545 | 2011-03-11 16:47:48 +0100 | [diff] [blame] | 100 | s->count_load_time = qemu_get_clock_ns(vm_clock); |
bellard | 80cabfa | 2004-03-14 12:20:30 +0000 | [diff] [blame] | 101 | s->count = val; |
bellard | b0a21b5 | 2004-03-31 18:58:38 +0000 | [diff] [blame] | 102 | pit_irq_timer_update(s, s->count_load_time); |
bellard | 80cabfa | 2004-03-14 12:20:30 +0000 | [diff] [blame] | 103 | } |
| 104 | |
bellard | ec844b9 | 2004-05-03 23:18:25 +0000 | [diff] [blame] | 105 | /* if already latched, do not latch again */ |
| 106 | static void pit_latch_count(PITChannelState *s) |
| 107 | { |
| 108 | if (!s->count_latched) { |
| 109 | s->latched_count = pit_get_count(s); |
| 110 | s->count_latched = s->rw_mode; |
| 111 | } |
| 112 | } |
| 113 | |
bellard | b41a2cd | 2004-03-14 21:46:48 +0000 | [diff] [blame] | 114 | static void pit_ioport_write(void *opaque, uint32_t addr, uint32_t val) |
bellard | 80cabfa | 2004-03-14 12:20:30 +0000 | [diff] [blame] | 115 | { |
Jan Kiszka | d11e859 | 2012-03-02 20:28:46 +0100 | [diff] [blame] | 116 | PITCommonState *pit = opaque; |
bellard | 80cabfa | 2004-03-14 12:20:30 +0000 | [diff] [blame] | 117 | int channel, access; |
| 118 | PITChannelState *s; |
| 119 | |
| 120 | addr &= 3; |
| 121 | if (addr == 3) { |
| 122 | channel = val >> 6; |
bellard | ec844b9 | 2004-05-03 23:18:25 +0000 | [diff] [blame] | 123 | if (channel == 3) { |
| 124 | /* read back command */ |
| 125 | for(channel = 0; channel < 3; channel++) { |
| 126 | s = &pit->channels[channel]; |
| 127 | if (val & (2 << channel)) { |
| 128 | if (!(val & 0x20)) { |
| 129 | pit_latch_count(s); |
| 130 | } |
| 131 | if (!(val & 0x10) && !s->status_latched) { |
| 132 | /* status latch */ |
| 133 | /* XXX: add BCD and null count */ |
Jan Kiszka | 4aa5d28 | 2012-02-01 20:31:43 +0100 | [diff] [blame] | 134 | s->status = |
| 135 | (pit_get_out(s, |
| 136 | qemu_get_clock_ns(vm_clock)) << 7) | |
bellard | ec844b9 | 2004-05-03 23:18:25 +0000 | [diff] [blame] | 137 | (s->rw_mode << 4) | |
| 138 | (s->mode << 1) | |
| 139 | s->bcd; |
| 140 | s->status_latched = 1; |
| 141 | } |
| 142 | } |
| 143 | } |
| 144 | } else { |
| 145 | s = &pit->channels[channel]; |
| 146 | access = (val >> 4) & 3; |
| 147 | if (access == 0) { |
| 148 | pit_latch_count(s); |
| 149 | } else { |
| 150 | s->rw_mode = access; |
| 151 | s->read_state = access; |
| 152 | s->write_state = access; |
| 153 | |
| 154 | s->mode = (val >> 1) & 7; |
| 155 | s->bcd = val & 1; |
| 156 | /* XXX: update irq timer ? */ |
| 157 | } |
bellard | 80cabfa | 2004-03-14 12:20:30 +0000 | [diff] [blame] | 158 | } |
| 159 | } else { |
bellard | ec844b9 | 2004-05-03 23:18:25 +0000 | [diff] [blame] | 160 | s = &pit->channels[addr]; |
| 161 | switch(s->write_state) { |
| 162 | default: |
bellard | 80cabfa | 2004-03-14 12:20:30 +0000 | [diff] [blame] | 163 | case RW_STATE_LSB: |
| 164 | pit_load_count(s, val); |
| 165 | break; |
| 166 | case RW_STATE_MSB: |
| 167 | pit_load_count(s, val << 8); |
| 168 | break; |
| 169 | case RW_STATE_WORD0: |
bellard | ec844b9 | 2004-05-03 23:18:25 +0000 | [diff] [blame] | 170 | s->write_latch = val; |
| 171 | s->write_state = RW_STATE_WORD1; |
| 172 | break; |
bellard | 80cabfa | 2004-03-14 12:20:30 +0000 | [diff] [blame] | 173 | case RW_STATE_WORD1: |
bellard | ec844b9 | 2004-05-03 23:18:25 +0000 | [diff] [blame] | 174 | pit_load_count(s, s->write_latch | (val << 8)); |
| 175 | s->write_state = RW_STATE_WORD0; |
bellard | 80cabfa | 2004-03-14 12:20:30 +0000 | [diff] [blame] | 176 | break; |
| 177 | } |
| 178 | } |
| 179 | } |
| 180 | |
bellard | b41a2cd | 2004-03-14 21:46:48 +0000 | [diff] [blame] | 181 | static uint32_t pit_ioport_read(void *opaque, uint32_t addr) |
bellard | 80cabfa | 2004-03-14 12:20:30 +0000 | [diff] [blame] | 182 | { |
Jan Kiszka | d11e859 | 2012-03-02 20:28:46 +0100 | [diff] [blame] | 183 | PITCommonState *pit = opaque; |
bellard | 80cabfa | 2004-03-14 12:20:30 +0000 | [diff] [blame] | 184 | int ret, count; |
| 185 | PITChannelState *s; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 186 | |
bellard | 80cabfa | 2004-03-14 12:20:30 +0000 | [diff] [blame] | 187 | addr &= 3; |
bellard | ec844b9 | 2004-05-03 23:18:25 +0000 | [diff] [blame] | 188 | s = &pit->channels[addr]; |
| 189 | if (s->status_latched) { |
| 190 | s->status_latched = 0; |
| 191 | ret = s->status; |
| 192 | } else if (s->count_latched) { |
| 193 | switch(s->count_latched) { |
| 194 | default: |
| 195 | case RW_STATE_LSB: |
bellard | 80cabfa | 2004-03-14 12:20:30 +0000 | [diff] [blame] | 196 | ret = s->latched_count & 0xff; |
bellard | ec844b9 | 2004-05-03 23:18:25 +0000 | [diff] [blame] | 197 | s->count_latched = 0; |
| 198 | break; |
| 199 | case RW_STATE_MSB: |
| 200 | ret = s->latched_count >> 8; |
| 201 | s->count_latched = 0; |
| 202 | break; |
| 203 | case RW_STATE_WORD0: |
| 204 | ret = s->latched_count & 0xff; |
| 205 | s->count_latched = RW_STATE_MSB; |
| 206 | break; |
| 207 | } |
| 208 | } else { |
| 209 | switch(s->read_state) { |
| 210 | default: |
| 211 | case RW_STATE_LSB: |
| 212 | count = pit_get_count(s); |
| 213 | ret = count & 0xff; |
| 214 | break; |
| 215 | case RW_STATE_MSB: |
| 216 | count = pit_get_count(s); |
| 217 | ret = (count >> 8) & 0xff; |
| 218 | break; |
| 219 | case RW_STATE_WORD0: |
| 220 | count = pit_get_count(s); |
| 221 | ret = count & 0xff; |
| 222 | s->read_state = RW_STATE_WORD1; |
| 223 | break; |
| 224 | case RW_STATE_WORD1: |
| 225 | count = pit_get_count(s); |
| 226 | ret = (count >> 8) & 0xff; |
| 227 | s->read_state = RW_STATE_WORD0; |
| 228 | break; |
| 229 | } |
bellard | 80cabfa | 2004-03-14 12:20:30 +0000 | [diff] [blame] | 230 | } |
| 231 | return ret; |
| 232 | } |
| 233 | |
bellard | b0a21b5 | 2004-03-31 18:58:38 +0000 | [diff] [blame] | 234 | static void pit_irq_timer_update(PITChannelState *s, int64_t current_time) |
| 235 | { |
| 236 | int64_t expire_time; |
| 237 | int irq_level; |
| 238 | |
Jan Kiszka | ce967e2 | 2012-02-01 20:31:41 +0100 | [diff] [blame] | 239 | if (!s->irq_timer || s->irq_disabled) { |
bellard | b0a21b5 | 2004-03-31 18:58:38 +0000 | [diff] [blame] | 240 | return; |
Jan Kiszka | ce967e2 | 2012-02-01 20:31:41 +0100 | [diff] [blame] | 241 | } |
bellard | b0a21b5 | 2004-03-31 18:58:38 +0000 | [diff] [blame] | 242 | expire_time = pit_get_next_transition_time(s, current_time); |
Jan Kiszka | 4aa5d28 | 2012-02-01 20:31:43 +0100 | [diff] [blame] | 243 | irq_level = pit_get_out(s, current_time); |
pbrook | d537cf6 | 2007-04-07 18:14:41 +0000 | [diff] [blame] | 244 | qemu_set_irq(s->irq, irq_level); |
bellard | b0a21b5 | 2004-03-31 18:58:38 +0000 | [diff] [blame] | 245 | #ifdef DEBUG_PIT |
| 246 | printf("irq_level=%d next_delay=%f\n", |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 247 | irq_level, |
Juan Quintela | 6ee093c | 2009-09-10 03:04:26 +0200 | [diff] [blame] | 248 | (double)(expire_time - current_time) / get_ticks_per_sec()); |
bellard | b0a21b5 | 2004-03-31 18:58:38 +0000 | [diff] [blame] | 249 | #endif |
| 250 | s->next_transition_time = expire_time; |
| 251 | if (expire_time != -1) |
| 252 | qemu_mod_timer(s->irq_timer, expire_time); |
| 253 | else |
| 254 | qemu_del_timer(s->irq_timer); |
| 255 | } |
| 256 | |
| 257 | static void pit_irq_timer(void *opaque) |
| 258 | { |
| 259 | PITChannelState *s = opaque; |
| 260 | |
| 261 | pit_irq_timer_update(s, s->next_transition_time); |
| 262 | } |
| 263 | |
Blue Swirl | 64d7e9a | 2011-02-13 19:54:40 +0000 | [diff] [blame] | 264 | static void pit_reset(DeviceState *dev) |
bellard | 80cabfa | 2004-03-14 12:20:30 +0000 | [diff] [blame] | 265 | { |
Jan Kiszka | d11e859 | 2012-03-02 20:28:46 +0100 | [diff] [blame] | 266 | PITCommonState *pit = DO_UPCAST(PITCommonState, dev.qdev, dev); |
bellard | 80cabfa | 2004-03-14 12:20:30 +0000 | [diff] [blame] | 267 | PITChannelState *s; |
bellard | 80cabfa | 2004-03-14 12:20:30 +0000 | [diff] [blame] | 268 | |
Jan Kiszka | d11e859 | 2012-03-02 20:28:46 +0100 | [diff] [blame] | 269 | pit_reset_common(pit); |
| 270 | |
| 271 | s = &pit->channels[0]; |
| 272 | if (!s->irq_disabled) { |
| 273 | qemu_mod_timer(s->irq_timer, s->next_transition_time); |
bellard | 80cabfa | 2004-03-14 12:20:30 +0000 | [diff] [blame] | 274 | } |
bellard | d7d02e3 | 2004-06-20 12:58:36 +0000 | [diff] [blame] | 275 | } |
| 276 | |
Jan Kiszka | ce967e2 | 2012-02-01 20:31:41 +0100 | [diff] [blame] | 277 | /* When HPET is operating in legacy mode, suppress the ignored timer IRQ, |
| 278 | * reenable it when legacy mode is left again. */ |
| 279 | static void pit_irq_control(void *opaque, int n, int enable) |
aliguori | 16b29ae | 2008-12-17 23:28:44 +0000 | [diff] [blame] | 280 | { |
Jan Kiszka | d11e859 | 2012-03-02 20:28:46 +0100 | [diff] [blame] | 281 | PITCommonState *pit = opaque; |
Jan Kiszka | ce967e2 | 2012-02-01 20:31:41 +0100 | [diff] [blame] | 282 | PITChannelState *s = &pit->channels[0]; |
| 283 | |
| 284 | if (enable) { |
| 285 | s->irq_disabled = 0; |
| 286 | pit_irq_timer_update(s, qemu_get_clock_ns(vm_clock)); |
| 287 | } else { |
| 288 | s->irq_disabled = 1; |
| 289 | qemu_del_timer(s->irq_timer); |
| 290 | } |
aliguori | 16b29ae | 2008-12-17 23:28:44 +0000 | [diff] [blame] | 291 | } |
| 292 | |
Richard Henderson | 60ea6aa | 2011-08-10 15:28:15 -0700 | [diff] [blame] | 293 | static const MemoryRegionPortio pit_portio[] = { |
| 294 | { 0, 4, 1, .write = pit_ioport_write }, |
| 295 | { 0, 3, 1, .read = pit_ioport_read }, |
| 296 | PORTIO_END_OF_LIST() |
| 297 | }; |
| 298 | |
| 299 | static const MemoryRegionOps pit_ioport_ops = { |
| 300 | .old_portio = pit_portio |
| 301 | }; |
| 302 | |
Jan Kiszka | 3fbc1c0 | 2012-03-02 20:28:47 +0100 | [diff] [blame] | 303 | static void pit_post_load(PITCommonState *s) |
| 304 | { |
| 305 | PITChannelState *sc = &s->channels[0]; |
| 306 | |
| 307 | if (sc->next_transition_time != -1) { |
| 308 | qemu_mod_timer(sc->irq_timer, sc->next_transition_time); |
| 309 | } else { |
| 310 | qemu_del_timer(sc->irq_timer); |
| 311 | } |
| 312 | } |
| 313 | |
Jan Kiszka | d11e859 | 2012-03-02 20:28:46 +0100 | [diff] [blame] | 314 | static int pit_initfn(PITCommonState *pit) |
bellard | d7d02e3 | 2004-06-20 12:58:36 +0000 | [diff] [blame] | 315 | { |
bellard | d7d02e3 | 2004-06-20 12:58:36 +0000 | [diff] [blame] | 316 | PITChannelState *s; |
| 317 | |
| 318 | s = &pit->channels[0]; |
| 319 | /* the timer 0 is connected to an IRQ */ |
Paolo Bonzini | 7447545 | 2011-03-11 16:47:48 +0100 | [diff] [blame] | 320 | s->irq_timer = qemu_new_timer_ns(vm_clock, pit_irq_timer, s); |
Jan Kiszka | d11e859 | 2012-03-02 20:28:46 +0100 | [diff] [blame] | 321 | qdev_init_gpio_out(&pit->dev.qdev, &s->irq, 1); |
bellard | 80cabfa | 2004-03-14 12:20:30 +0000 | [diff] [blame] | 322 | |
Richard Henderson | 60ea6aa | 2011-08-10 15:28:15 -0700 | [diff] [blame] | 323 | memory_region_init_io(&pit->ioports, &pit_ioport_ops, pit, "pit", 4); |
bellard | d7d02e3 | 2004-06-20 12:58:36 +0000 | [diff] [blame] | 324 | |
Jan Kiszka | d11e859 | 2012-03-02 20:28:46 +0100 | [diff] [blame] | 325 | qdev_init_gpio_in(&pit->dev.qdev, pit_irq_control, 1); |
Jan Kiszka | ca22a3a | 2011-03-06 16:09:49 +0100 | [diff] [blame] | 326 | |
Blue Swirl | 64d7e9a | 2011-02-13 19:54:40 +0000 | [diff] [blame] | 327 | return 0; |
bellard | 80cabfa | 2004-03-14 12:20:30 +0000 | [diff] [blame] | 328 | } |
Blue Swirl | 64d7e9a | 2011-02-13 19:54:40 +0000 | [diff] [blame] | 329 | |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 330 | static Property pit_properties[] = { |
Jan Kiszka | d11e859 | 2012-03-02 20:28:46 +0100 | [diff] [blame] | 331 | DEFINE_PROP_HEX32("iobase", PITCommonState, iobase, -1), |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 332 | DEFINE_PROP_END_OF_LIST(), |
| 333 | }; |
| 334 | |
Anthony Liguori | 8f04ee0 | 2011-12-04 11:52:49 -0600 | [diff] [blame] | 335 | static void pit_class_initfn(ObjectClass *klass, void *data) |
| 336 | { |
Jan Kiszka | d11e859 | 2012-03-02 20:28:46 +0100 | [diff] [blame] | 337 | PITCommonClass *k = PIT_COMMON_CLASS(klass); |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 338 | DeviceClass *dc = DEVICE_CLASS(klass); |
Jan Kiszka | d11e859 | 2012-03-02 20:28:46 +0100 | [diff] [blame] | 339 | |
| 340 | k->init = pit_initfn; |
| 341 | k->set_channel_gate = pit_set_channel_gate; |
| 342 | k->get_channel_info = pit_get_channel_info_common; |
Jan Kiszka | 3fbc1c0 | 2012-03-02 20:28:47 +0100 | [diff] [blame] | 343 | k->post_load = pit_post_load; |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 344 | dc->reset = pit_reset; |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 345 | dc->props = pit_properties; |
Anthony Liguori | 8f04ee0 | 2011-12-04 11:52:49 -0600 | [diff] [blame] | 346 | } |
| 347 | |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 348 | static TypeInfo pit_info = { |
| 349 | .name = "isa-pit", |
Jan Kiszka | d11e859 | 2012-03-02 20:28:46 +0100 | [diff] [blame] | 350 | .parent = TYPE_PIT_COMMON, |
| 351 | .instance_size = sizeof(PITCommonState), |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 352 | .class_init = pit_class_initfn, |
Blue Swirl | 64d7e9a | 2011-02-13 19:54:40 +0000 | [diff] [blame] | 353 | }; |
| 354 | |
Andreas Färber | 83f7d43 | 2012-02-09 15:20:55 +0100 | [diff] [blame] | 355 | static void pit_register_types(void) |
Blue Swirl | 64d7e9a | 2011-02-13 19:54:40 +0000 | [diff] [blame] | 356 | { |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 357 | type_register_static(&pit_info); |
Blue Swirl | 64d7e9a | 2011-02-13 19:54:40 +0000 | [diff] [blame] | 358 | } |
Andreas Färber | 83f7d43 | 2012-02-09 15:20:55 +0100 | [diff] [blame] | 359 | |
| 360 | type_init(pit_register_types) |