blob: 40d6224a4e62bd465731688ba8de185f749b6191 [file] [log] [blame]
blueswir179383c92008-08-30 09:51:20 +00001#ifndef HW_ISA_H
2#define HW_ISA_H
Gerd Hoffmannf915a112009-07-31 12:30:14 +02003
pbrook87ecb682007-11-17 17:14:51 +00004/* ISA bus */
5
Paolo Bonzini022c62c2012-12-17 18:19:49 +01006#include "exec/memory.h"
Paolo Bonzinidf43d492016-03-16 10:24:54 +01007#include "exec/ioport.h"
Markus Armbrustera27bd6c2019-08-12 07:23:51 +02008#include "hw/qdev-core.h"
Eduardo Habkostdb1015e2020-09-03 16:43:22 -04009#include "qom/object.h"
Gerd Hoffmannf915a112009-07-31 12:30:14 +020010
Jan Kiszkab881fbe2011-10-07 09:19:35 +020011#define ISA_NUM_IRQS 16
12
Anthony Liguori8f04ee02011-12-04 11:52:49 -060013#define TYPE_ISA_DEVICE "isa-device"
Philippe Mathieu-Daudé97cfb5e2023-02-14 12:48:15 +010014OBJECT_DECLARE_SIMPLE_TYPE(ISADevice, ISA_DEVICE)
Anthony Liguori8f04ee02011-12-04 11:52:49 -060015
Anthony Liguori0d936922012-05-02 09:00:20 +020016#define TYPE_ISA_BUS "ISA"
Eduardo Habkost80633962020-09-16 14:25:19 -040017OBJECT_DECLARE_SIMPLE_TYPE(ISABus, ISA_BUS)
Anthony Liguori0d936922012-05-02 09:00:20 +020018
Hervé Poussineau5484f302016-02-03 11:28:57 -050019#define TYPE_ISADMA "isa-dma"
20
Eduardo Habkostdb1015e2020-09-03 16:43:22 -040021typedef struct IsaDmaClass IsaDmaClass;
Eduardo Habkost8110fa12020-08-31 17:07:33 -040022DECLARE_CLASS_CHECKERS(IsaDmaClass, ISADMA,
23 TYPE_ISADMA)
Hervé Poussineau5484f302016-02-03 11:28:57 -050024#define ISADMA(obj) \
25 INTERFACE_CHECK(IsaDma, (obj), TYPE_ISADMA)
26
Hervé Poussineau5484f302016-02-03 11:28:57 -050027typedef enum {
28 ISADMA_TRANSFER_VERIFY,
29 ISADMA_TRANSFER_READ,
30 ISADMA_TRANSFER_WRITE,
31 ISADMA_TRANSFER_ILLEGAL,
32} IsaDmaTransferMode;
33
Markus Armbrusterbd36a612016-03-09 12:55:26 +010034typedef int (*IsaDmaTransferHandler)(void *opaque, int nchan, int pos,
35 int size);
36
Eduardo Habkostdb1015e2020-09-03 16:43:22 -040037struct IsaDmaClass {
Hervé Poussineau5484f302016-02-03 11:28:57 -050038 InterfaceClass parent;
39
Hervé Poussineau5484f302016-02-03 11:28:57 -050040 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,
Markus Armbrusterbd36a612016-03-09 12:55:26 +010047 IsaDmaTransferHandler transfer_handler,
Hervé Poussineau5484f302016-02-03 11:28:57 -050048 void *opaque);
Eduardo Habkostdb1015e2020-09-03 16:43:22 -040049};
Hervé Poussineau5484f302016-02-03 11:28:57 -050050
Hervé Poussineaud1a1be12011-12-15 22:09:52 +010051struct ISABus {
Andreas Färber2ae0e482013-06-07 14:11:07 +020052 /*< private >*/
53 BusState parent_obj;
54 /*< public >*/
55
Hervé Poussineaubb2ed002015-02-01 09:12:50 +010056 MemoryRegion *address_space;
Hervé Poussineaud1a1be12011-12-15 22:09:52 +010057 MemoryRegion *address_space_io;
Philippe Mathieu-Daudé70678872023-02-09 13:32:18 +010058 qemu_irq *irqs_in;
Hervé Poussineau5484f302016-02-03 11:28:57 -050059 IsaDma *dma[2];
Hervé Poussineaud1a1be12011-12-15 22:09:52 +010060};
61
Gerd Hoffmannf915a112009-07-31 12:30:14 +020062struct ISADevice {
Andreas Färber4a17cc42013-06-07 13:49:13 +020063 /*< private >*/
64 DeviceState parent_obj;
65 /*< public >*/
66
Richard Hendersonebf47c22011-08-15 11:59:09 -070067 int ioport_id;
Gerd Hoffmannf915a112009-07-31 12:30:14 +020068};
69
Hervé Poussineaubb2ed002015-02-01 09:12:50 +010070ISABus *isa_bus_new(DeviceState *dev, MemoryRegion *address_space,
Markus Armbrusterd10e5432015-12-17 17:35:18 +010071 MemoryRegion *address_space_io, Error **errp);
Philippe Mathieu-Daudé70678872023-02-09 13:32:18 +010072void isa_bus_register_input_irqs(ISABus *bus, qemu_irq *irqs_in);
Hervé Poussineau5484f302016-02-03 11:28:57 -050073void isa_bus_dma(ISABus *bus, IsaDma *dma8, IsaDma *dma16);
Philippe Mathieu-Daudédc8d6cf2023-02-15 15:38:19 +010074IsaDma *isa_bus_get_dma(ISABus *bus, int nchan);
Philippe Mathieu-Daudéd2fbec52023-02-09 11:55:03 +010075/**
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 */
82qemu_irq isa_bus_get_irq(ISABus *bus, unsigned irqnum);
Markus Armbruster0fe9d902020-06-10 07:32:07 +020083ISADevice *isa_new(const char *name);
84ISADevice *isa_try_new(const char *name);
85bool isa_realize_and_unref(ISADevice *dev, ISABus *bus, Error **errp);
Hervé Poussineau48a18b32011-12-15 22:09:51 +010086ISADevice *isa_create_simple(ISABus *bus, const char *name);
pbrook87ecb682007-11-17 17:14:51 +000087
Aurelien Jarno14e7a642012-09-08 16:58:57 +020088ISADevice *isa_vga_init(ISABus *bus);
89
Philippe Mathieu-Daudé88b58772023-02-09 11:59:43 +010090qemu_irq isa_get_irq(ISADevice *dev, unsigned isairq);
91void isa_connect_gpio_out(ISADevice *isadev, int gpioirq, unsigned isairq);
92MemoryRegion *isa_address_space(ISADevice *dev);
93MemoryRegion *isa_address_space_io(ISADevice *dev);
Philippe Mathieu-Daudé23c69bb2023-02-07 22:47:20 +010094ISABus *isa_bus_from_device(ISADevice *dev);
Philippe Mathieu-Daudé88b58772023-02-09 11:59:43 +010095
Avi Kivityd7500732011-09-26 14:52:44 +030096/**
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 */
106void 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.
Marc-André Lureaue305a162016-07-13 02:11:59 +0200117 * @piolist: the PortioList associated with the io ports
Avi Kivityd7500732011-09-26 14:52:44 +0300118 * @start: the base I/O port against which the portio->offset is applied.
119 * @portio: the ports, sorted by offset.
Hervé Poussineau520902a2013-08-13 12:38:34 +0200120 * @opaque: passed into the portio callbacks.
Avi Kivityd7500732011-09-26 14:52:44 +0300121 * @name: passed into memory_region_init_io.
Thomas Huth9405d872021-04-16 14:52:56 +0200122 *
123 * Returns: 0 on success, negative error code otherwise (e.g. if the
124 * ISA bus is not available)
Avi Kivityd7500732011-09-26 14:52:44 +0300125 */
Thomas Huth9405d872021-04-16 14:52:56 +0200126int isa_register_portio_list(ISADevice *dev,
127 PortioList *piolist,
128 uint16_t start,
129 const MemoryRegionPortio *portio,
130 void *opaque, const char *name);
Avi Kivityd7500732011-09-26 14:52:44 +0300131
blueswir179383c92008-08-30 09:51:20 +0000132#endif