isa.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #ifndef HW_ISA_H
  2. #define HW_ISA_H
  3. /* ISA bus */
  4. #include "exec/memory.h"
  5. #include "exec/ioport.h"
  6. #include "hw/qdev-core.h"
  7. #include "qom/object.h"
  8. #define ISA_NUM_IRQS 16
  9. #define TYPE_ISA_DEVICE "isa-device"
  10. OBJECT_DECLARE_SIMPLE_TYPE(ISADevice, ISA_DEVICE)
  11. #define TYPE_ISA_BUS "ISA"
  12. OBJECT_DECLARE_SIMPLE_TYPE(ISABus, ISA_BUS)
  13. #define TYPE_ISADMA "isa-dma"
  14. typedef struct IsaDmaClass IsaDmaClass;
  15. DECLARE_CLASS_CHECKERS(IsaDmaClass, ISADMA,
  16. TYPE_ISADMA)
  17. #define ISADMA(obj) \
  18. INTERFACE_CHECK(IsaDma, (obj), TYPE_ISADMA)
  19. typedef enum {
  20. ISADMA_TRANSFER_VERIFY,
  21. ISADMA_TRANSFER_READ,
  22. ISADMA_TRANSFER_WRITE,
  23. ISADMA_TRANSFER_ILLEGAL,
  24. } IsaDmaTransferMode;
  25. typedef int (*IsaDmaTransferHandler)(void *opaque, int nchan, int pos,
  26. int size);
  27. struct IsaDmaClass {
  28. InterfaceClass parent;
  29. bool (*has_autoinitialization)(IsaDma *obj, int nchan);
  30. int (*read_memory)(IsaDma *obj, int nchan, void *buf, int pos, int len);
  31. int (*write_memory)(IsaDma *obj, int nchan, void *buf, int pos, int len);
  32. void (*hold_DREQ)(IsaDma *obj, int nchan);
  33. void (*release_DREQ)(IsaDma *obj, int nchan);
  34. void (*schedule)(IsaDma *obj);
  35. void (*register_channel)(IsaDma *obj, int nchan,
  36. IsaDmaTransferHandler transfer_handler,
  37. void *opaque);
  38. };
  39. struct ISABus {
  40. /*< private >*/
  41. BusState parent_obj;
  42. /*< public >*/
  43. MemoryRegion *address_space;
  44. MemoryRegion *address_space_io;
  45. qemu_irq *irqs_in;
  46. IsaDma *dma[2];
  47. };
  48. struct ISADevice {
  49. /*< private >*/
  50. DeviceState parent_obj;
  51. /*< public >*/
  52. int ioport_id;
  53. };
  54. ISABus *isa_bus_new(DeviceState *dev, MemoryRegion *address_space,
  55. MemoryRegion *address_space_io, Error **errp);
  56. void isa_bus_register_input_irqs(ISABus *bus, qemu_irq *irqs_in);
  57. void isa_bus_dma(ISABus *bus, IsaDma *dma8, IsaDma *dma16);
  58. IsaDma *isa_bus_get_dma(ISABus *bus, int nchan);
  59. /**
  60. * isa_bus_get_irq: Return input IRQ on ISA bus.
  61. * @bus: the #ISABus to plug ISA devices on.
  62. * @irqnum: the ISA IRQ number.
  63. *
  64. * Return IRQ @irqnum from the PIC associated on ISA @bus.
  65. */
  66. qemu_irq isa_bus_get_irq(ISABus *bus, unsigned irqnum);
  67. ISADevice *isa_new(const char *name);
  68. ISADevice *isa_try_new(const char *name);
  69. bool isa_realize_and_unref(ISADevice *dev, ISABus *bus, Error **errp);
  70. ISADevice *isa_create_simple(ISABus *bus, const char *name);
  71. ISADevice *isa_vga_init(ISABus *bus);
  72. qemu_irq isa_get_irq(ISADevice *dev, unsigned isairq);
  73. void isa_connect_gpio_out(ISADevice *isadev, int gpioirq, unsigned isairq);
  74. MemoryRegion *isa_address_space(ISADevice *dev);
  75. MemoryRegion *isa_address_space_io(ISADevice *dev);
  76. ISABus *isa_bus_from_device(ISADevice *dev);
  77. /**
  78. * isa_register_ioport: Install an I/O port region on the ISA bus.
  79. *
  80. * Register an I/O port region via memory_region_add_subregion
  81. * inside the ISA I/O address space.
  82. *
  83. * @dev: the ISADevice against which these are registered; may be NULL.
  84. * @io: the #MemoryRegion being registered.
  85. * @start: the base I/O port.
  86. */
  87. void isa_register_ioport(ISADevice *dev, MemoryRegion *io, uint16_t start);
  88. /**
  89. * isa_register_portio_list: Initialize a set of ISA io ports
  90. *
  91. * Several ISA devices have many dis-joint I/O ports. Worse, these I/O
  92. * ports can be interleaved with I/O ports from other devices. This
  93. * function makes it easy to create multiple MemoryRegions for a single
  94. * device and use the legacy portio routines.
  95. *
  96. * @dev: the ISADevice against which these are registered; may be NULL.
  97. * @piolist: the PortioList associated with the io ports
  98. * @start: the base I/O port against which the portio->offset is applied.
  99. * @portio: the ports, sorted by offset.
  100. * @opaque: passed into the portio callbacks.
  101. * @name: passed into memory_region_init_io.
  102. *
  103. * Returns: 0 on success, negative error code otherwise (e.g. if the
  104. * ISA bus is not available)
  105. */
  106. int isa_register_portio_list(ISADevice *dev,
  107. PortioList *piolist,
  108. uint16_t start,
  109. const MemoryRegionPortio *portio,
  110. void *opaque, const char *name);
  111. #endif