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