aliguori | 610626a | 2009-03-12 20:25:12 +0000 | [diff] [blame] | 1 | /* |
| 2 | * ioapic.c IOAPIC emulation logic |
| 3 | * |
| 4 | * Copyright (c) 2004-2005 Fabrice Bellard |
| 5 | * |
| 6 | * Split the ioapic logic from apic.c |
| 7 | * Xiantao Zhang <xiantao.zhang@intel.com> |
| 8 | * |
| 9 | * This library is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU Lesser General Public |
| 11 | * License as published by the Free Software Foundation; either |
| 12 | * version 2 of the License, or (at your option) any later version. |
| 13 | * |
| 14 | * This library is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 | * Lesser General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU Lesser General Public |
Blue Swirl | 8167ee8 | 2009-07-16 20:47:01 +0000 | [diff] [blame] | 20 | * License along with this library; if not, see <http://www.gnu.org/licenses/>. |
aliguori | 610626a | 2009-03-12 20:25:12 +0000 | [diff] [blame] | 21 | */ |
| 22 | |
Peter Maydell | b6a0aa0 | 2016-01-26 18:17:03 +0000 | [diff] [blame] | 23 | #include "qemu/osdep.h" |
Pavel Butsykin | 6bde8fd | 2015-09-22 16:18:21 +0300 | [diff] [blame] | 24 | #include "monitor/monitor.h" |
Paolo Bonzini | 83c9f4c | 2013-02-04 15:40:22 +0100 | [diff] [blame] | 25 | #include "hw/hw.h" |
Paolo Bonzini | 0d09e41 | 2013-02-05 17:06:20 +0100 | [diff] [blame] | 26 | #include "hw/i386/pc.h" |
Paolo Bonzini | d613f8c | 2015-12-04 11:04:13 +0100 | [diff] [blame^] | 27 | #include "hw/i386/apic.h" |
Paolo Bonzini | 0d09e41 | 2013-02-05 17:06:20 +0100 | [diff] [blame] | 28 | #include "hw/i386/ioapic.h" |
| 29 | #include "hw/i386/ioapic_internal.h" |
Paolo Bonzini | 15eafc2 | 2015-12-17 17:16:08 +0100 | [diff] [blame] | 30 | #include "include/hw/pci/msi.h" |
| 31 | #include "sysemu/kvm.h" |
aliguori | 610626a | 2009-03-12 20:25:12 +0000 | [diff] [blame] | 32 | |
| 33 | //#define DEBUG_IOAPIC |
| 34 | |
Blue Swirl | 9af9b33 | 2010-05-31 18:59:45 +0000 | [diff] [blame] | 35 | #ifdef DEBUG_IOAPIC |
| 36 | #define DPRINTF(fmt, ...) \ |
| 37 | do { printf("ioapic: " fmt , ## __VA_ARGS__); } while (0) |
| 38 | #else |
| 39 | #define DPRINTF(fmt, ...) |
| 40 | #endif |
| 41 | |
Paolo Bonzini | 15eafc2 | 2015-12-17 17:16:08 +0100 | [diff] [blame] | 42 | #define APIC_DELIVERY_MODE_SHIFT 8 |
| 43 | #define APIC_POLARITY_SHIFT 14 |
| 44 | #define APIC_TRIG_MODE_SHIFT 15 |
| 45 | |
Jan Kiszka | 244ac3a | 2011-10-16 19:38:22 +0200 | [diff] [blame] | 46 | static IOAPICCommonState *ioapics[MAX_IOAPICS]; |
Jan Kiszka | 0280b57 | 2011-02-03 22:54:11 +0100 | [diff] [blame] | 47 | |
xiaoqiang zhao | db0f888 | 2013-11-05 18:16:05 +0800 | [diff] [blame] | 48 | /* global variable from ioapic_common.c */ |
| 49 | extern int ioapic_no; |
| 50 | |
Jan Kiszka | 244ac3a | 2011-10-16 19:38:22 +0200 | [diff] [blame] | 51 | static void ioapic_service(IOAPICCommonState *s) |
aliguori | 610626a | 2009-03-12 20:25:12 +0000 | [diff] [blame] | 52 | { |
| 53 | uint8_t i; |
| 54 | uint8_t trig_mode; |
| 55 | uint8_t vector; |
| 56 | uint8_t delivery_mode; |
| 57 | uint32_t mask; |
| 58 | uint64_t entry; |
| 59 | uint8_t dest; |
| 60 | uint8_t dest_mode; |
aliguori | 610626a | 2009-03-12 20:25:12 +0000 | [diff] [blame] | 61 | |
| 62 | for (i = 0; i < IOAPIC_NUM_PINS; i++) { |
| 63 | mask = 1 << i; |
| 64 | if (s->irr & mask) { |
Paolo Bonzini | 15eafc2 | 2015-12-17 17:16:08 +0100 | [diff] [blame] | 65 | int coalesce = 0; |
| 66 | |
aliguori | 610626a | 2009-03-12 20:25:12 +0000 | [diff] [blame] | 67 | entry = s->ioredtbl[i]; |
| 68 | if (!(entry & IOAPIC_LVT_MASKED)) { |
Jan Kiszka | 1f5e71a | 2011-02-03 22:54:14 +0100 | [diff] [blame] | 69 | trig_mode = ((entry >> IOAPIC_LVT_TRIGGER_MODE_SHIFT) & 1); |
| 70 | dest = entry >> IOAPIC_LVT_DEST_SHIFT; |
| 71 | dest_mode = (entry >> IOAPIC_LVT_DEST_MODE_SHIFT) & 1; |
| 72 | delivery_mode = |
| 73 | (entry >> IOAPIC_LVT_DELIV_MODE_SHIFT) & IOAPIC_DM_MASK; |
Jan Kiszka | 0280b57 | 2011-02-03 22:54:11 +0100 | [diff] [blame] | 74 | if (trig_mode == IOAPIC_TRIGGER_EDGE) { |
aliguori | 610626a | 2009-03-12 20:25:12 +0000 | [diff] [blame] | 75 | s->irr &= ~mask; |
Jan Kiszka | 0280b57 | 2011-02-03 22:54:11 +0100 | [diff] [blame] | 76 | } else { |
Paolo Bonzini | 15eafc2 | 2015-12-17 17:16:08 +0100 | [diff] [blame] | 77 | coalesce = s->ioredtbl[i] & IOAPIC_LVT_REMOTE_IRR; |
Jan Kiszka | 0280b57 | 2011-02-03 22:54:11 +0100 | [diff] [blame] | 78 | s->ioredtbl[i] |= IOAPIC_LVT_REMOTE_IRR; |
| 79 | } |
Jan Kiszka | 1f5e71a | 2011-02-03 22:54:14 +0100 | [diff] [blame] | 80 | if (delivery_mode == IOAPIC_DM_EXTINT) { |
aliguori | 610626a | 2009-03-12 20:25:12 +0000 | [diff] [blame] | 81 | vector = pic_read_irq(isa_pic); |
Jan Kiszka | 1f5e71a | 2011-02-03 22:54:14 +0100 | [diff] [blame] | 82 | } else { |
| 83 | vector = entry & IOAPIC_VECTOR_MASK; |
| 84 | } |
Paolo Bonzini | 15eafc2 | 2015-12-17 17:16:08 +0100 | [diff] [blame] | 85 | #ifdef CONFIG_KVM |
| 86 | if (kvm_irqchip_is_split()) { |
| 87 | if (trig_mode == IOAPIC_TRIGGER_EDGE) { |
| 88 | kvm_set_irq(kvm_state, i, 1); |
| 89 | kvm_set_irq(kvm_state, i, 0); |
| 90 | } else { |
| 91 | if (!coalesce) { |
| 92 | kvm_set_irq(kvm_state, i, 1); |
| 93 | } |
| 94 | } |
| 95 | continue; |
| 96 | } |
| 97 | #else |
| 98 | (void)coalesce; |
| 99 | #endif |
| 100 | apic_deliver_irq(dest, dest_mode, delivery_mode, vector, |
| 101 | trig_mode); |
aliguori | 610626a | 2009-03-12 20:25:12 +0000 | [diff] [blame] | 102 | } |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 | |
Blue Swirl | 7d0500c | 2010-06-17 16:32:47 +0000 | [diff] [blame] | 107 | static void ioapic_set_irq(void *opaque, int vector, int level) |
aliguori | 610626a | 2009-03-12 20:25:12 +0000 | [diff] [blame] | 108 | { |
Jan Kiszka | 244ac3a | 2011-10-16 19:38:22 +0200 | [diff] [blame] | 109 | IOAPICCommonState *s = opaque; |
aliguori | 610626a | 2009-03-12 20:25:12 +0000 | [diff] [blame] | 110 | |
| 111 | /* ISA IRQs map to GSI 1-1 except for IRQ0 which maps |
| 112 | * to GSI 2. GSI maps to ioapic 1-1. This is not |
| 113 | * the cleanest way of doing it but it should work. */ |
| 114 | |
Jan Kiszka | 1f5e71a | 2011-02-03 22:54:14 +0100 | [diff] [blame] | 115 | DPRINTF("%s: %s vec %x\n", __func__, level ? "raise" : "lower", vector); |
| 116 | if (vector == 0) { |
aliguori | 610626a | 2009-03-12 20:25:12 +0000 | [diff] [blame] | 117 | vector = 2; |
Jan Kiszka | 1f5e71a | 2011-02-03 22:54:14 +0100 | [diff] [blame] | 118 | } |
aliguori | 610626a | 2009-03-12 20:25:12 +0000 | [diff] [blame] | 119 | if (vector >= 0 && vector < IOAPIC_NUM_PINS) { |
| 120 | uint32_t mask = 1 << vector; |
| 121 | uint64_t entry = s->ioredtbl[vector]; |
| 122 | |
Jan Kiszka | 1f5e71a | 2011-02-03 22:54:14 +0100 | [diff] [blame] | 123 | if (((entry >> IOAPIC_LVT_TRIGGER_MODE_SHIFT) & 1) == |
| 124 | IOAPIC_TRIGGER_LEVEL) { |
aliguori | 610626a | 2009-03-12 20:25:12 +0000 | [diff] [blame] | 125 | /* level triggered */ |
| 126 | if (level) { |
| 127 | s->irr |= mask; |
Paolo Bonzini | c5955a5 | 2015-07-30 10:19:24 +0200 | [diff] [blame] | 128 | if (!(entry & IOAPIC_LVT_REMOTE_IRR)) { |
| 129 | ioapic_service(s); |
| 130 | } |
aliguori | 610626a | 2009-03-12 20:25:12 +0000 | [diff] [blame] | 131 | } else { |
| 132 | s->irr &= ~mask; |
| 133 | } |
| 134 | } else { |
Jan Kiszka | 47f7be3 | 2011-04-09 13:18:59 +0200 | [diff] [blame] | 135 | /* According to the 82093AA manual, we must ignore edge requests |
| 136 | * if the input pin is masked. */ |
| 137 | if (level && !(entry & IOAPIC_LVT_MASKED)) { |
aliguori | 610626a | 2009-03-12 20:25:12 +0000 | [diff] [blame] | 138 | s->irr |= mask; |
| 139 | ioapic_service(s); |
| 140 | } |
| 141 | } |
| 142 | } |
| 143 | } |
| 144 | |
Paolo Bonzini | 15eafc2 | 2015-12-17 17:16:08 +0100 | [diff] [blame] | 145 | static void ioapic_update_kvm_routes(IOAPICCommonState *s) |
| 146 | { |
| 147 | #ifdef CONFIG_KVM |
| 148 | int i; |
| 149 | |
| 150 | if (kvm_irqchip_is_split()) { |
| 151 | for (i = 0; i < IOAPIC_NUM_PINS; i++) { |
| 152 | uint64_t entry = s->ioredtbl[i]; |
| 153 | uint8_t trig_mode; |
| 154 | uint8_t delivery_mode; |
| 155 | uint8_t dest; |
| 156 | uint8_t dest_mode; |
| 157 | uint64_t pin_polarity; |
| 158 | MSIMessage msg; |
| 159 | |
| 160 | trig_mode = ((entry >> IOAPIC_LVT_TRIGGER_MODE_SHIFT) & 1); |
| 161 | dest = entry >> IOAPIC_LVT_DEST_SHIFT; |
| 162 | dest_mode = (entry >> IOAPIC_LVT_DEST_MODE_SHIFT) & 1; |
| 163 | pin_polarity = (entry >> IOAPIC_LVT_TRIGGER_MODE_SHIFT) & 1; |
| 164 | delivery_mode = |
| 165 | (entry >> IOAPIC_LVT_DELIV_MODE_SHIFT) & IOAPIC_DM_MASK; |
| 166 | |
| 167 | msg.address = APIC_DEFAULT_ADDRESS; |
| 168 | msg.address |= dest_mode << 2; |
| 169 | msg.address |= dest << 12; |
| 170 | |
| 171 | msg.data = entry & IOAPIC_VECTOR_MASK; |
| 172 | msg.data |= delivery_mode << APIC_DELIVERY_MODE_SHIFT; |
| 173 | msg.data |= pin_polarity << APIC_POLARITY_SHIFT; |
| 174 | msg.data |= trig_mode << APIC_TRIG_MODE_SHIFT; |
| 175 | |
| 176 | kvm_irqchip_update_msi_route(kvm_state, i, msg, NULL); |
| 177 | } |
| 178 | kvm_irqchip_commit_routes(kvm_state); |
| 179 | } |
| 180 | #endif |
| 181 | } |
| 182 | |
Jan Kiszka | 0280b57 | 2011-02-03 22:54:11 +0100 | [diff] [blame] | 183 | void ioapic_eoi_broadcast(int vector) |
| 184 | { |
Jan Kiszka | 244ac3a | 2011-10-16 19:38:22 +0200 | [diff] [blame] | 185 | IOAPICCommonState *s; |
Jan Kiszka | 0280b57 | 2011-02-03 22:54:11 +0100 | [diff] [blame] | 186 | uint64_t entry; |
| 187 | int i, n; |
| 188 | |
| 189 | for (i = 0; i < MAX_IOAPICS; i++) { |
| 190 | s = ioapics[i]; |
| 191 | if (!s) { |
| 192 | continue; |
| 193 | } |
| 194 | for (n = 0; n < IOAPIC_NUM_PINS; n++) { |
| 195 | entry = s->ioredtbl[n]; |
Jan Kiszka | 1f5e71a | 2011-02-03 22:54:14 +0100 | [diff] [blame] | 196 | if ((entry & IOAPIC_LVT_REMOTE_IRR) |
| 197 | && (entry & IOAPIC_VECTOR_MASK) == vector) { |
Jan Kiszka | 0280b57 | 2011-02-03 22:54:11 +0100 | [diff] [blame] | 198 | s->ioredtbl[n] = entry & ~IOAPIC_LVT_REMOTE_IRR; |
| 199 | if (!(entry & IOAPIC_LVT_MASKED) && (s->irr & (1 << n))) { |
| 200 | ioapic_service(s); |
| 201 | } |
| 202 | } |
| 203 | } |
| 204 | } |
| 205 | } |
| 206 | |
Pavel Butsykin | 6bde8fd | 2015-09-22 16:18:21 +0300 | [diff] [blame] | 207 | void ioapic_dump_state(Monitor *mon, const QDict *qdict) |
| 208 | { |
| 209 | int i; |
| 210 | |
| 211 | for (i = 0; i < MAX_IOAPICS; i++) { |
| 212 | if (ioapics[i] != 0) { |
| 213 | ioapic_print_redtbl(mon, ioapics[i]); |
| 214 | } |
| 215 | } |
| 216 | } |
| 217 | |
Jan Kiszka | 4d5bf5f | 2011-10-17 13:11:27 +0200 | [diff] [blame] | 218 | static uint64_t |
Avi Kivity | a8170e5 | 2012-10-23 12:30:10 +0200 | [diff] [blame] | 219 | ioapic_mem_read(void *opaque, hwaddr addr, unsigned int size) |
aliguori | 610626a | 2009-03-12 20:25:12 +0000 | [diff] [blame] | 220 | { |
Jan Kiszka | 244ac3a | 2011-10-16 19:38:22 +0200 | [diff] [blame] | 221 | IOAPICCommonState *s = opaque; |
aliguori | 610626a | 2009-03-12 20:25:12 +0000 | [diff] [blame] | 222 | int index; |
| 223 | uint32_t val = 0; |
| 224 | |
Jan Kiszka | 1f5e71a | 2011-02-03 22:54:14 +0100 | [diff] [blame] | 225 | switch (addr & 0xff) { |
| 226 | case IOAPIC_IOREGSEL: |
aliguori | 610626a | 2009-03-12 20:25:12 +0000 | [diff] [blame] | 227 | val = s->ioregsel; |
Jan Kiszka | 1f5e71a | 2011-02-03 22:54:14 +0100 | [diff] [blame] | 228 | break; |
| 229 | case IOAPIC_IOWIN: |
Jan Kiszka | 1a44096 | 2011-10-17 13:11:29 +0200 | [diff] [blame] | 230 | if (size != 4) { |
| 231 | break; |
| 232 | } |
aliguori | 610626a | 2009-03-12 20:25:12 +0000 | [diff] [blame] | 233 | switch (s->ioregsel) { |
Jan Kiszka | 1f5e71a | 2011-02-03 22:54:14 +0100 | [diff] [blame] | 234 | case IOAPIC_REG_ID: |
Paolo Bonzini | 2f5a3b1 | 2015-07-30 10:21:00 +0200 | [diff] [blame] | 235 | case IOAPIC_REG_ARB: |
Jan Kiszka | 1f5e71a | 2011-02-03 22:54:14 +0100 | [diff] [blame] | 236 | val = s->id << IOAPIC_ID_SHIFT; |
| 237 | break; |
| 238 | case IOAPIC_REG_VER: |
| 239 | val = IOAPIC_VERSION | |
| 240 | ((IOAPIC_NUM_PINS - 1) << IOAPIC_VER_ENTRIES_SHIFT); |
| 241 | break; |
Jan Kiszka | 1f5e71a | 2011-02-03 22:54:14 +0100 | [diff] [blame] | 242 | default: |
| 243 | index = (s->ioregsel - IOAPIC_REG_REDTBL_BASE) >> 1; |
| 244 | if (index >= 0 && index < IOAPIC_NUM_PINS) { |
| 245 | if (s->ioregsel & 1) { |
| 246 | val = s->ioredtbl[index] >> 32; |
| 247 | } else { |
| 248 | val = s->ioredtbl[index] & 0xffffffff; |
aliguori | 610626a | 2009-03-12 20:25:12 +0000 | [diff] [blame] | 249 | } |
Jan Kiszka | 1f5e71a | 2011-02-03 22:54:14 +0100 | [diff] [blame] | 250 | } |
aliguori | 610626a | 2009-03-12 20:25:12 +0000 | [diff] [blame] | 251 | } |
Blue Swirl | 9af9b33 | 2010-05-31 18:59:45 +0000 | [diff] [blame] | 252 | DPRINTF("read: %08x = %08x\n", s->ioregsel, val); |
Jan Kiszka | 1f5e71a | 2011-02-03 22:54:14 +0100 | [diff] [blame] | 253 | break; |
aliguori | 610626a | 2009-03-12 20:25:12 +0000 | [diff] [blame] | 254 | } |
| 255 | return val; |
| 256 | } |
| 257 | |
Jan Kiszka | 1f5e71a | 2011-02-03 22:54:14 +0100 | [diff] [blame] | 258 | static void |
Avi Kivity | a8170e5 | 2012-10-23 12:30:10 +0200 | [diff] [blame] | 259 | ioapic_mem_write(void *opaque, hwaddr addr, uint64_t val, |
Jan Kiszka | 4d5bf5f | 2011-10-17 13:11:27 +0200 | [diff] [blame] | 260 | unsigned int size) |
aliguori | 610626a | 2009-03-12 20:25:12 +0000 | [diff] [blame] | 261 | { |
Jan Kiszka | 244ac3a | 2011-10-16 19:38:22 +0200 | [diff] [blame] | 262 | IOAPICCommonState *s = opaque; |
aliguori | 610626a | 2009-03-12 20:25:12 +0000 | [diff] [blame] | 263 | int index; |
| 264 | |
Jan Kiszka | 1f5e71a | 2011-02-03 22:54:14 +0100 | [diff] [blame] | 265 | switch (addr & 0xff) { |
| 266 | case IOAPIC_IOREGSEL: |
aliguori | 610626a | 2009-03-12 20:25:12 +0000 | [diff] [blame] | 267 | s->ioregsel = val; |
Jan Kiszka | 1f5e71a | 2011-02-03 22:54:14 +0100 | [diff] [blame] | 268 | break; |
| 269 | case IOAPIC_IOWIN: |
Jan Kiszka | 1a44096 | 2011-10-17 13:11:29 +0200 | [diff] [blame] | 270 | if (size != 4) { |
| 271 | break; |
| 272 | } |
Jason Wang | 0c1f781 | 2012-03-19 11:19:57 +0800 | [diff] [blame] | 273 | DPRINTF("write: %08x = %08" PRIx64 "\n", s->ioregsel, val); |
aliguori | 610626a | 2009-03-12 20:25:12 +0000 | [diff] [blame] | 274 | switch (s->ioregsel) { |
Jan Kiszka | 1f5e71a | 2011-02-03 22:54:14 +0100 | [diff] [blame] | 275 | case IOAPIC_REG_ID: |
| 276 | s->id = (val >> IOAPIC_ID_SHIFT) & IOAPIC_ID_MASK; |
| 277 | break; |
| 278 | case IOAPIC_REG_VER: |
| 279 | case IOAPIC_REG_ARB: |
| 280 | break; |
| 281 | default: |
| 282 | index = (s->ioregsel - IOAPIC_REG_REDTBL_BASE) >> 1; |
| 283 | if (index >= 0 && index < IOAPIC_NUM_PINS) { |
| 284 | if (s->ioregsel & 1) { |
| 285 | s->ioredtbl[index] &= 0xffffffff; |
| 286 | s->ioredtbl[index] |= (uint64_t)val << 32; |
| 287 | } else { |
| 288 | s->ioredtbl[index] &= ~0xffffffffULL; |
| 289 | s->ioredtbl[index] |= val; |
aliguori | 610626a | 2009-03-12 20:25:12 +0000 | [diff] [blame] | 290 | } |
Jan Kiszka | 1f5e71a | 2011-02-03 22:54:14 +0100 | [diff] [blame] | 291 | ioapic_service(s); |
| 292 | } |
aliguori | 610626a | 2009-03-12 20:25:12 +0000 | [diff] [blame] | 293 | } |
Jan Kiszka | 1f5e71a | 2011-02-03 22:54:14 +0100 | [diff] [blame] | 294 | break; |
aliguori | 610626a | 2009-03-12 20:25:12 +0000 | [diff] [blame] | 295 | } |
Paolo Bonzini | 15eafc2 | 2015-12-17 17:16:08 +0100 | [diff] [blame] | 296 | |
| 297 | ioapic_update_kvm_routes(s); |
aliguori | 610626a | 2009-03-12 20:25:12 +0000 | [diff] [blame] | 298 | } |
| 299 | |
Jan Kiszka | 4d5bf5f | 2011-10-17 13:11:27 +0200 | [diff] [blame] | 300 | static const MemoryRegionOps ioapic_io_ops = { |
| 301 | .read = ioapic_mem_read, |
| 302 | .write = ioapic_mem_write, |
| 303 | .endianness = DEVICE_NATIVE_ENDIAN, |
aliguori | 610626a | 2009-03-12 20:25:12 +0000 | [diff] [blame] | 304 | }; |
| 305 | |
xiaoqiang zhao | db0f888 | 2013-11-05 18:16:05 +0800 | [diff] [blame] | 306 | static void ioapic_realize(DeviceState *dev, Error **errp) |
aliguori | 610626a | 2009-03-12 20:25:12 +0000 | [diff] [blame] | 307 | { |
xiaoqiang zhao | db0f888 | 2013-11-05 18:16:05 +0800 | [diff] [blame] | 308 | IOAPICCommonState *s = IOAPIC_COMMON(dev); |
xiaoqiang zhao | f977185 | 2013-11-05 18:16:04 +0800 | [diff] [blame] | 309 | |
Paolo Bonzini | 1437c94 | 2013-06-06 21:25:08 -0400 | [diff] [blame] | 310 | memory_region_init_io(&s->io_memory, OBJECT(s), &ioapic_io_ops, s, |
| 311 | "ioapic", 0x1000); |
aliguori | 610626a | 2009-03-12 20:25:12 +0000 | [diff] [blame] | 312 | |
xiaoqiang zhao | f977185 | 2013-11-05 18:16:04 +0800 | [diff] [blame] | 313 | qdev_init_gpio_in(dev, ioapic_set_irq, IOAPIC_NUM_PINS); |
aliguori | 610626a | 2009-03-12 20:25:12 +0000 | [diff] [blame] | 314 | |
xiaoqiang zhao | db0f888 | 2013-11-05 18:16:05 +0800 | [diff] [blame] | 315 | ioapics[ioapic_no] = s; |
aliguori | 610626a | 2009-03-12 20:25:12 +0000 | [diff] [blame] | 316 | } |
Blue Swirl | 9605111 | 2010-06-19 07:41:43 +0000 | [diff] [blame] | 317 | |
Anthony Liguori | 999e12b | 2012-01-24 13:12:29 -0600 | [diff] [blame] | 318 | static void ioapic_class_init(ObjectClass *klass, void *data) |
| 319 | { |
| 320 | IOAPICCommonClass *k = IOAPIC_COMMON_CLASS(klass); |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 321 | DeviceClass *dc = DEVICE_CLASS(klass); |
Anthony Liguori | 999e12b | 2012-01-24 13:12:29 -0600 | [diff] [blame] | 322 | |
xiaoqiang zhao | db0f888 | 2013-11-05 18:16:05 +0800 | [diff] [blame] | 323 | k->realize = ioapic_realize; |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 324 | dc->reset = ioapic_reset_common; |
Anthony Liguori | 999e12b | 2012-01-24 13:12:29 -0600 | [diff] [blame] | 325 | } |
| 326 | |
Andreas Färber | 8c43a6f | 2013-01-10 16:19:07 +0100 | [diff] [blame] | 327 | static const TypeInfo ioapic_info = { |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 328 | .name = "ioapic", |
| 329 | .parent = TYPE_IOAPIC_COMMON, |
| 330 | .instance_size = sizeof(IOAPICCommonState), |
| 331 | .class_init = ioapic_class_init, |
Blue Swirl | 9605111 | 2010-06-19 07:41:43 +0000 | [diff] [blame] | 332 | }; |
| 333 | |
Andreas Färber | 83f7d43 | 2012-02-09 15:20:55 +0100 | [diff] [blame] | 334 | static void ioapic_register_types(void) |
Blue Swirl | 9605111 | 2010-06-19 07:41:43 +0000 | [diff] [blame] | 335 | { |
Anthony Liguori | 39bffca | 2011-12-07 21:34:16 -0600 | [diff] [blame] | 336 | type_register_static(&ioapic_info); |
Blue Swirl | 9605111 | 2010-06-19 07:41:43 +0000 | [diff] [blame] | 337 | } |
| 338 | |
Andreas Färber | 83f7d43 | 2012-02-09 15:20:55 +0100 | [diff] [blame] | 339 | type_init(ioapic_register_types) |