2
0

i8259_common.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * QEMU 8259 - common bits of emulated and KVM kernel model
  3. *
  4. * Copyright (c) 2003-2004 Fabrice Bellard
  5. * Copyright (c) 2011 Jan Kiszka, Siemens AG
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a copy
  8. * of this software and associated documentation files (the "Software"), to deal
  9. * in the Software without restriction, including without limitation the rights
  10. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. * copies of the Software, and to permit persons to whom the Software is
  12. * furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in
  15. * all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  20. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  23. * THE SOFTWARE.
  24. */
  25. #include "hw/i386/pc.h"
  26. #include "hw/isa/i8259_internal.h"
  27. void pic_reset_common(PICCommonState *s)
  28. {
  29. s->last_irr = 0;
  30. s->irr &= s->elcr;
  31. s->imr = 0;
  32. s->isr = 0;
  33. s->priority_add = 0;
  34. s->irq_base = 0;
  35. s->read_reg_select = 0;
  36. s->poll = 0;
  37. s->special_mask = 0;
  38. s->init_state = 0;
  39. s->auto_eoi = 0;
  40. s->rotate_on_auto_eoi = 0;
  41. s->special_fully_nested_mode = 0;
  42. s->init4 = 0;
  43. s->single_mode = 0;
  44. /* Note: ELCR is not reset */
  45. }
  46. static void pic_dispatch_pre_save(void *opaque)
  47. {
  48. PICCommonState *s = opaque;
  49. PICCommonClass *info = PIC_COMMON_GET_CLASS(s);
  50. if (info->pre_save) {
  51. info->pre_save(s);
  52. }
  53. }
  54. static int pic_dispatch_post_load(void *opaque, int version_id)
  55. {
  56. PICCommonState *s = opaque;
  57. PICCommonClass *info = PIC_COMMON_GET_CLASS(s);
  58. if (info->post_load) {
  59. info->post_load(s);
  60. }
  61. return 0;
  62. }
  63. static void pic_common_realize(DeviceState *dev, Error **errp)
  64. {
  65. PICCommonState *s = PIC_COMMON(dev);
  66. isa_register_ioport(NULL, &s->base_io, s->iobase);
  67. if (s->elcr_addr != -1) {
  68. isa_register_ioport(NULL, &s->elcr_io, s->elcr_addr);
  69. }
  70. qdev_set_legacy_instance_id(dev, s->iobase, 1);
  71. }
  72. ISADevice *i8259_init_chip(const char *name, ISABus *bus, bool master)
  73. {
  74. DeviceState *dev;
  75. ISADevice *isadev;
  76. isadev = isa_create(bus, name);
  77. dev = DEVICE(isadev);
  78. qdev_prop_set_uint32(dev, "iobase", master ? 0x20 : 0xa0);
  79. qdev_prop_set_uint32(dev, "elcr_addr", master ? 0x4d0 : 0x4d1);
  80. qdev_prop_set_uint8(dev, "elcr_mask", master ? 0xf8 : 0xde);
  81. qdev_prop_set_bit(dev, "master", master);
  82. qdev_init_nofail(dev);
  83. return isadev;
  84. }
  85. static const VMStateDescription vmstate_pic_common = {
  86. .name = "i8259",
  87. .version_id = 1,
  88. .minimum_version_id = 1,
  89. .minimum_version_id_old = 1,
  90. .pre_save = pic_dispatch_pre_save,
  91. .post_load = pic_dispatch_post_load,
  92. .fields = (VMStateField[]) {
  93. VMSTATE_UINT8(last_irr, PICCommonState),
  94. VMSTATE_UINT8(irr, PICCommonState),
  95. VMSTATE_UINT8(imr, PICCommonState),
  96. VMSTATE_UINT8(isr, PICCommonState),
  97. VMSTATE_UINT8(priority_add, PICCommonState),
  98. VMSTATE_UINT8(irq_base, PICCommonState),
  99. VMSTATE_UINT8(read_reg_select, PICCommonState),
  100. VMSTATE_UINT8(poll, PICCommonState),
  101. VMSTATE_UINT8(special_mask, PICCommonState),
  102. VMSTATE_UINT8(init_state, PICCommonState),
  103. VMSTATE_UINT8(auto_eoi, PICCommonState),
  104. VMSTATE_UINT8(rotate_on_auto_eoi, PICCommonState),
  105. VMSTATE_UINT8(special_fully_nested_mode, PICCommonState),
  106. VMSTATE_UINT8(init4, PICCommonState),
  107. VMSTATE_UINT8(single_mode, PICCommonState),
  108. VMSTATE_UINT8(elcr, PICCommonState),
  109. VMSTATE_END_OF_LIST()
  110. }
  111. };
  112. static Property pic_properties_common[] = {
  113. DEFINE_PROP_UINT32("iobase", PICCommonState, iobase, -1),
  114. DEFINE_PROP_UINT32("elcr_addr", PICCommonState, elcr_addr, -1),
  115. DEFINE_PROP_UINT8("elcr_mask", PICCommonState, elcr_mask, -1),
  116. DEFINE_PROP_BIT("master", PICCommonState, master, 0, false),
  117. DEFINE_PROP_END_OF_LIST(),
  118. };
  119. static void pic_common_class_init(ObjectClass *klass, void *data)
  120. {
  121. DeviceClass *dc = DEVICE_CLASS(klass);
  122. dc->vmsd = &vmstate_pic_common;
  123. dc->props = pic_properties_common;
  124. dc->realize = pic_common_realize;
  125. /*
  126. * Reason: unlike ordinary ISA devices, the PICs need additional
  127. * wiring: its IRQ input lines are set up by board code, and the
  128. * wiring of the slave to the master is hard-coded in device model
  129. * code.
  130. */
  131. dc->cannot_instantiate_with_device_add_yet = true;
  132. }
  133. static const TypeInfo pic_common_type = {
  134. .name = TYPE_PIC_COMMON,
  135. .parent = TYPE_ISA_DEVICE,
  136. .instance_size = sizeof(PICCommonState),
  137. .class_size = sizeof(PICCommonClass),
  138. .class_init = pic_common_class_init,
  139. .abstract = true,
  140. };
  141. static void pic_common_register_types(void)
  142. {
  143. type_register_static(&pic_common_type);
  144. }
  145. type_init(pic_common_register_types)