diff options
Diffstat (limited to 'virt/kvm/ioapic.c')
-rw-r--r-- | virt/kvm/ioapic.c | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/virt/kvm/ioapic.c b/virt/kvm/ioapic.c index 1150c6d5c7b8..469b9faae665 100644 --- a/virt/kvm/ioapic.c +++ b/virt/kvm/ioapic.c | |||
@@ -220,10 +220,15 @@ void kvm_ioapic_update_eoi(struct kvm *kvm, int vector, int trigger_mode) | |||
220 | __kvm_ioapic_update_eoi(ioapic, i, trigger_mode); | 220 | __kvm_ioapic_update_eoi(ioapic, i, trigger_mode); |
221 | } | 221 | } |
222 | 222 | ||
223 | static inline struct kvm_ioapic *to_ioapic(struct kvm_io_device *dev) | ||
224 | { | ||
225 | return container_of(dev, struct kvm_ioapic, dev); | ||
226 | } | ||
227 | |||
223 | static int ioapic_in_range(struct kvm_io_device *this, gpa_t addr, | 228 | static int ioapic_in_range(struct kvm_io_device *this, gpa_t addr, |
224 | int len, int is_write) | 229 | int len, int is_write) |
225 | { | 230 | { |
226 | struct kvm_ioapic *ioapic = (struct kvm_ioapic *)this->private; | 231 | struct kvm_ioapic *ioapic = to_ioapic(this); |
227 | 232 | ||
228 | return ((addr >= ioapic->base_address && | 233 | return ((addr >= ioapic->base_address && |
229 | (addr < ioapic->base_address + IOAPIC_MEM_LENGTH))); | 234 | (addr < ioapic->base_address + IOAPIC_MEM_LENGTH))); |
@@ -232,7 +237,7 @@ static int ioapic_in_range(struct kvm_io_device *this, gpa_t addr, | |||
232 | static void ioapic_mmio_read(struct kvm_io_device *this, gpa_t addr, int len, | 237 | static void ioapic_mmio_read(struct kvm_io_device *this, gpa_t addr, int len, |
233 | void *val) | 238 | void *val) |
234 | { | 239 | { |
235 | struct kvm_ioapic *ioapic = (struct kvm_ioapic *)this->private; | 240 | struct kvm_ioapic *ioapic = to_ioapic(this); |
236 | u32 result; | 241 | u32 result; |
237 | 242 | ||
238 | ioapic_debug("addr %lx\n", (unsigned long)addr); | 243 | ioapic_debug("addr %lx\n", (unsigned long)addr); |
@@ -269,7 +274,7 @@ static void ioapic_mmio_read(struct kvm_io_device *this, gpa_t addr, int len, | |||
269 | static void ioapic_mmio_write(struct kvm_io_device *this, gpa_t addr, int len, | 274 | static void ioapic_mmio_write(struct kvm_io_device *this, gpa_t addr, int len, |
270 | const void *val) | 275 | const void *val) |
271 | { | 276 | { |
272 | struct kvm_ioapic *ioapic = (struct kvm_ioapic *)this->private; | 277 | struct kvm_ioapic *ioapic = to_ioapic(this); |
273 | u32 data; | 278 | u32 data; |
274 | 279 | ||
275 | ioapic_debug("ioapic_mmio_write addr=%p len=%d val=%p\n", | 280 | ioapic_debug("ioapic_mmio_write addr=%p len=%d val=%p\n", |
@@ -314,6 +319,12 @@ void kvm_ioapic_reset(struct kvm_ioapic *ioapic) | |||
314 | ioapic->id = 0; | 319 | ioapic->id = 0; |
315 | } | 320 | } |
316 | 321 | ||
322 | static const struct kvm_io_device_ops ioapic_mmio_ops = { | ||
323 | .read = ioapic_mmio_read, | ||
324 | .write = ioapic_mmio_write, | ||
325 | .in_range = ioapic_in_range, | ||
326 | }; | ||
327 | |||
317 | int kvm_ioapic_init(struct kvm *kvm) | 328 | int kvm_ioapic_init(struct kvm *kvm) |
318 | { | 329 | { |
319 | struct kvm_ioapic *ioapic; | 330 | struct kvm_ioapic *ioapic; |
@@ -323,10 +334,7 @@ int kvm_ioapic_init(struct kvm *kvm) | |||
323 | return -ENOMEM; | 334 | return -ENOMEM; |
324 | kvm->arch.vioapic = ioapic; | 335 | kvm->arch.vioapic = ioapic; |
325 | kvm_ioapic_reset(ioapic); | 336 | kvm_ioapic_reset(ioapic); |
326 | ioapic->dev.read = ioapic_mmio_read; | 337 | kvm_iodevice_init(&ioapic->dev, &ioapic_mmio_ops); |
327 | ioapic->dev.write = ioapic_mmio_write; | ||
328 | ioapic->dev.in_range = ioapic_in_range; | ||
329 | ioapic->dev.private = ioapic; | ||
330 | ioapic->kvm = kvm; | 338 | ioapic->kvm = kvm; |
331 | kvm_io_bus_register_dev(&kvm->mmio_bus, &ioapic->dev); | 339 | kvm_io_bus_register_dev(&kvm->mmio_bus, &ioapic->dev); |
332 | return 0; | 340 | return 0; |