ioapic_common.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * IOAPIC emulation logic - common bits of emulated and KVM kernel model
  3. *
  4. * Copyright (c) 2004-2005 Fabrice Bellard
  5. * Copyright (c) 2009 Xiantao Zhang, Intel
  6. * Copyright (c) 2011 Jan Kiszka, Siemens AG
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2 of the License, or (at your option) any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #include "ioapic.h"
  22. #include "ioapic_internal.h"
  23. #include "sysbus.h"
  24. void ioapic_reset_common(DeviceState *dev)
  25. {
  26. IOAPICCommonState *s = IOAPIC_COMMON(dev);
  27. int i;
  28. s->id = 0;
  29. s->ioregsel = 0;
  30. s->irr = 0;
  31. for (i = 0; i < IOAPIC_NUM_PINS; i++) {
  32. s->ioredtbl[i] = 1 << IOAPIC_LVT_MASKED_SHIFT;
  33. }
  34. }
  35. static void ioapic_dispatch_pre_save(void *opaque)
  36. {
  37. IOAPICCommonState *s = IOAPIC_COMMON(opaque);
  38. IOAPICCommonClass *info = IOAPIC_COMMON_GET_CLASS(s);
  39. if (info->pre_save) {
  40. info->pre_save(s);
  41. }
  42. }
  43. static int ioapic_dispatch_post_load(void *opaque, int version_id)
  44. {
  45. IOAPICCommonState *s = IOAPIC_COMMON(opaque);
  46. IOAPICCommonClass *info = IOAPIC_COMMON_GET_CLASS(s);
  47. if (info->post_load) {
  48. info->post_load(s);
  49. }
  50. return 0;
  51. }
  52. static int ioapic_init_common(SysBusDevice *dev)
  53. {
  54. IOAPICCommonState *s = FROM_SYSBUS(IOAPICCommonState, dev);
  55. IOAPICCommonClass *info;
  56. static int ioapic_no;
  57. if (ioapic_no >= MAX_IOAPICS) {
  58. return -1;
  59. }
  60. info = IOAPIC_COMMON_GET_CLASS(s);
  61. info->init(s, ioapic_no);
  62. sysbus_init_mmio(&s->busdev, &s->io_memory);
  63. ioapic_no++;
  64. return 0;
  65. }
  66. static const VMStateDescription vmstate_ioapic_common = {
  67. .name = "ioapic",
  68. .version_id = 3,
  69. .minimum_version_id = 1,
  70. .minimum_version_id_old = 1,
  71. .pre_save = ioapic_dispatch_pre_save,
  72. .post_load = ioapic_dispatch_post_load,
  73. .fields = (VMStateField[]) {
  74. VMSTATE_UINT8(id, IOAPICCommonState),
  75. VMSTATE_UINT8(ioregsel, IOAPICCommonState),
  76. VMSTATE_UNUSED_V(2, 8), /* to account for qemu-kvm's v2 format */
  77. VMSTATE_UINT32_V(irr, IOAPICCommonState, 2),
  78. VMSTATE_UINT64_ARRAY(ioredtbl, IOAPICCommonState, IOAPIC_NUM_PINS),
  79. VMSTATE_END_OF_LIST()
  80. }
  81. };
  82. static void ioapic_common_class_init(ObjectClass *klass, void *data)
  83. {
  84. SysBusDeviceClass *sc = SYS_BUS_DEVICE_CLASS(klass);
  85. DeviceClass *dc = DEVICE_CLASS(klass);
  86. sc->init = ioapic_init_common;
  87. dc->vmsd = &vmstate_ioapic_common;
  88. dc->no_user = 1;
  89. }
  90. static const TypeInfo ioapic_common_type = {
  91. .name = TYPE_IOAPIC_COMMON,
  92. .parent = TYPE_SYS_BUS_DEVICE,
  93. .instance_size = sizeof(IOAPICCommonState),
  94. .class_size = sizeof(IOAPICCommonClass),
  95. .class_init = ioapic_common_class_init,
  96. .abstract = true,
  97. };
  98. static void register_types(void)
  99. {
  100. type_register_static(&ioapic_common_type);
  101. }
  102. type_init(register_types)