port92.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * QEMU I/O port 0x92 (System Control Port A, to handle Fast Gate A20)
  3. *
  4. * Copyright (c) 2003-2004 Fabrice Bellard
  5. *
  6. * SPDX-License-Identifier: MIT
  7. */
  8. #include "qemu/osdep.h"
  9. #include "system/runstate.h"
  10. #include "migration/vmstate.h"
  11. #include "hw/irq.h"
  12. #include "hw/isa/isa.h"
  13. #include "hw/i386/pc.h"
  14. #include "trace.h"
  15. #include "qom/object.h"
  16. OBJECT_DECLARE_SIMPLE_TYPE(Port92State, PORT92)
  17. struct Port92State {
  18. ISADevice parent_obj;
  19. MemoryRegion io;
  20. uint8_t outport;
  21. qemu_irq a20_out;
  22. };
  23. static void port92_write(void *opaque, hwaddr addr, uint64_t val,
  24. unsigned size)
  25. {
  26. Port92State *s = opaque;
  27. int oldval = s->outport;
  28. trace_port92_write(val);
  29. s->outport = val;
  30. qemu_set_irq(s->a20_out, (val >> 1) & 1);
  31. if ((val & 1) && !(oldval & 1)) {
  32. qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
  33. }
  34. }
  35. static uint64_t port92_read(void *opaque, hwaddr addr,
  36. unsigned size)
  37. {
  38. Port92State *s = opaque;
  39. uint32_t ret;
  40. ret = s->outport;
  41. trace_port92_read(ret);
  42. return ret;
  43. }
  44. static const VMStateDescription vmstate_port92_isa = {
  45. .name = "port92",
  46. .version_id = 1,
  47. .minimum_version_id = 1,
  48. .fields = (const VMStateField[]) {
  49. VMSTATE_UINT8(outport, Port92State),
  50. VMSTATE_END_OF_LIST()
  51. }
  52. };
  53. static void port92_reset(DeviceState *d)
  54. {
  55. Port92State *s = PORT92(d);
  56. s->outport &= ~1;
  57. }
  58. static const MemoryRegionOps port92_ops = {
  59. .read = port92_read,
  60. .write = port92_write,
  61. .impl = {
  62. .min_access_size = 1,
  63. .max_access_size = 1,
  64. },
  65. .endianness = DEVICE_LITTLE_ENDIAN,
  66. };
  67. static void port92_initfn(Object *obj)
  68. {
  69. Port92State *s = PORT92(obj);
  70. memory_region_init_io(&s->io, OBJECT(s), &port92_ops, s, "port92", 1);
  71. s->outport = 0;
  72. qdev_init_gpio_out_named(DEVICE(obj), &s->a20_out, PORT92_A20_LINE, 1);
  73. }
  74. static void port92_realizefn(DeviceState *dev, Error **errp)
  75. {
  76. ISADevice *isadev = ISA_DEVICE(dev);
  77. Port92State *s = PORT92(dev);
  78. isa_register_ioport(isadev, &s->io, 0x92);
  79. }
  80. static void port92_class_initfn(ObjectClass *klass, void *data)
  81. {
  82. DeviceClass *dc = DEVICE_CLASS(klass);
  83. dc->realize = port92_realizefn;
  84. device_class_set_legacy_reset(dc, port92_reset);
  85. dc->vmsd = &vmstate_port92_isa;
  86. /*
  87. * Reason: unlike ordinary ISA devices, this one needs additional
  88. * wiring: its A20 output line needs to be wired up with
  89. * qdev_connect_gpio_out_named().
  90. */
  91. dc->user_creatable = false;
  92. }
  93. static const TypeInfo port92_info = {
  94. .name = TYPE_PORT92,
  95. .parent = TYPE_ISA_DEVICE,
  96. .instance_size = sizeof(Port92State),
  97. .instance_init = port92_initfn,
  98. .class_init = port92_class_initfn,
  99. };
  100. static void port92_register_types(void)
  101. {
  102. type_register_static(&port92_info);
  103. }
  104. type_init(port92_register_types)