i82374.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. * QEMU Intel 82374 emulation (Enhanced DMA controller)
  3. *
  4. * Copyright (c) 2010 Hervé Poussineau
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. * THE SOFTWARE.
  23. */
  24. #include "qemu/osdep.h"
  25. #include "qapi/error.h"
  26. #include "qemu/module.h"
  27. #include "hw/isa/isa.h"
  28. #include "hw/qdev-properties.h"
  29. #include "migration/vmstate.h"
  30. #include "hw/dma/i8257.h"
  31. #include "qom/object.h"
  32. #define TYPE_I82374 "i82374"
  33. OBJECT_DECLARE_SIMPLE_TYPE(I82374State, I82374)
  34. //#define DEBUG_I82374
  35. #ifdef DEBUG_I82374
  36. #define DPRINTF(fmt, ...) \
  37. do { fprintf(stderr, "i82374: " fmt , ## __VA_ARGS__); } while (0)
  38. #else
  39. #define DPRINTF(fmt, ...) \
  40. do {} while (0)
  41. #endif
  42. #define BADF(fmt, ...) \
  43. do { fprintf(stderr, "i82374 ERROR: " fmt , ## __VA_ARGS__); } while (0)
  44. struct I82374State {
  45. ISADevice parent_obj;
  46. uint32_t iobase;
  47. uint8_t commands[8];
  48. PortioList port_list;
  49. };
  50. static const VMStateDescription vmstate_i82374 = {
  51. .name = "i82374",
  52. .version_id = 0,
  53. .minimum_version_id = 0,
  54. .fields = (const VMStateField[]) {
  55. VMSTATE_UINT8_ARRAY(commands, I82374State, 8),
  56. VMSTATE_END_OF_LIST()
  57. },
  58. };
  59. static uint32_t i82374_read_isr(void *opaque, uint32_t nport)
  60. {
  61. uint32_t val = 0;
  62. BADF("%s: %08x\n", __func__, nport);
  63. DPRINTF("%s: %08x=%08x\n", __func__, nport, val);
  64. return val;
  65. }
  66. static void i82374_write_command(void *opaque, uint32_t nport, uint32_t data)
  67. {
  68. DPRINTF("%s: %08x=%08x\n", __func__, nport, data);
  69. if (data != 0x42) {
  70. /* Not Stop S/G command */
  71. BADF("%s: %08x=%08x\n", __func__, nport, data);
  72. }
  73. }
  74. static uint32_t i82374_read_status(void *opaque, uint32_t nport)
  75. {
  76. uint32_t val = 0;
  77. BADF("%s: %08x\n", __func__, nport);
  78. DPRINTF("%s: %08x=%08x\n", __func__, nport, val);
  79. return val;
  80. }
  81. static void i82374_write_descriptor(void *opaque, uint32_t nport, uint32_t data)
  82. {
  83. DPRINTF("%s: %08x=%08x\n", __func__, nport, data);
  84. BADF("%s: %08x=%08x\n", __func__, nport, data);
  85. }
  86. static uint32_t i82374_read_descriptor(void *opaque, uint32_t nport)
  87. {
  88. uint32_t val = 0;
  89. BADF("%s: %08x\n", __func__, nport);
  90. DPRINTF("%s: %08x=%08x\n", __func__, nport, val);
  91. return val;
  92. }
  93. static const MemoryRegionPortio i82374_portio_list[] = {
  94. { 0x0A, 1, 1, .read = i82374_read_isr, },
  95. { 0x10, 8, 1, .write = i82374_write_command, },
  96. { 0x18, 8, 1, .read = i82374_read_status, },
  97. { 0x20, 0x20, 1,
  98. .write = i82374_write_descriptor, .read = i82374_read_descriptor, },
  99. PORTIO_END_OF_LIST(),
  100. };
  101. static void i82374_realize(DeviceState *dev, Error **errp)
  102. {
  103. I82374State *s = I82374(dev);
  104. ISABus *isa_bus = isa_bus_from_device(ISA_DEVICE(dev));
  105. if (isa_bus_get_dma(isa_bus, 0)) {
  106. error_setg(errp, "DMA already initialized on ISA bus");
  107. return;
  108. }
  109. i8257_dma_init(OBJECT(dev), isa_bus, true);
  110. portio_list_init(&s->port_list, OBJECT(s), i82374_portio_list, s,
  111. "i82374");
  112. portio_list_add(&s->port_list, isa_address_space_io(&s->parent_obj),
  113. s->iobase);
  114. memset(s->commands, 0, sizeof(s->commands));
  115. }
  116. static const Property i82374_properties[] = {
  117. DEFINE_PROP_UINT32("iobase", I82374State, iobase, 0x400),
  118. };
  119. static void i82374_class_init(ObjectClass *klass, void *data)
  120. {
  121. DeviceClass *dc = DEVICE_CLASS(klass);
  122. dc->realize = i82374_realize;
  123. dc->vmsd = &vmstate_i82374;
  124. device_class_set_props(dc, i82374_properties);
  125. dc->desc = "Intel 82374 DMA controller";
  126. set_bit(DEVICE_CATEGORY_MISC, dc->categories);
  127. }
  128. static const TypeInfo i82374_info = {
  129. .name = TYPE_I82374,
  130. .parent = TYPE_ISA_DEVICE,
  131. .instance_size = sizeof(I82374State),
  132. .class_init = i82374_class_init,
  133. };
  134. static void i82374_register_types(void)
  135. {
  136. type_register_static(&i82374_info);
  137. }
  138. type_init(i82374_register_types)