blob: 6f9380007d49c73817dc65354539d1a0c95be950 [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"
Eduardo Habkosta489d192020-09-16 14:25:18 -040014OBJECT_DECLARE_TYPE(ISADevice, ISADeviceClass, 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
Eduardo Habkostdb1015e2020-09-03 16:43:22 -040051struct ISADeviceClass {
Anthony Liguori8f04ee02011-12-04 11:52:49 -060052 DeviceClass parent_class;
Eduardo Habkostdb1015e2020-09-03 16:43:22 -040053};
Gerd Hoffmannf915a112009-07-31 12:30:14 +020054
Hervé Poussineaud1a1be12011-12-15 22:09:52 +010055struct ISABus {
Andreas Färber2ae0e482013-06-07 14:11:07 +020056 /*< private >*/
57 BusState parent_obj;
58 /*< public >*/
59
Hervé Poussineaubb2ed002015-02-01 09:12:50 +010060 MemoryRegion *address_space;
Hervé Poussineaud1a1be12011-12-15 22:09:52 +010061 MemoryRegion *address_space_io;
62 qemu_irq *irqs;
Hervé Poussineau5484f302016-02-03 11:28:57 -050063 IsaDma *dma[2];
Hervé Poussineaud1a1be12011-12-15 22:09:52 +010064};
65
Gerd Hoffmannf915a112009-07-31 12:30:14 +020066struct ISADevice {
Andreas Färber4a17cc42013-06-07 13:49:13 +020067 /*< private >*/
68 DeviceState parent_obj;
69 /*< public >*/
70
Richard Hendersonebf47c22011-08-15 11:59:09 -070071 int ioport_id;
Gerd Hoffmannf915a112009-07-31 12:30:14 +020072};
73
Hervé Poussineaubb2ed002015-02-01 09:12:50 +010074ISABus *isa_bus_new(DeviceState *dev, MemoryRegion *address_space,
Markus Armbrusterd10e5432015-12-17 17:35:18 +010075 MemoryRegion *address_space_io, Error **errp);
Hervé Poussineau48a18b32011-12-15 22:09:51 +010076void isa_bus_irqs(ISABus *bus, qemu_irq *irqs);
Paolo Bonzini3c29e182019-12-13 13:00:43 +010077qemu_irq isa_get_irq(ISADevice *dev, unsigned isairq);
Paolo Bonzini3c29e182019-12-13 13:00:43 +010078void isa_connect_gpio_out(ISADevice *isadev, int gpioirq, unsigned isairq);
Hervé Poussineau5484f302016-02-03 11:28:57 -050079void isa_bus_dma(ISABus *bus, IsaDma *dma8, IsaDma *dma16);
80IsaDma *isa_get_dma(ISABus *bus, int nchan);
Avi Kivityc839ade2011-08-15 17:17:35 +030081MemoryRegion *isa_address_space(ISADevice *dev);
Julien Grallac100272012-09-19 12:50:02 +010082MemoryRegion *isa_address_space_io(ISADevice *dev);
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);
Gerd Hoffmanna53e5812020-04-29 15:59:53 +020089void isa_build_aml(ISABus *bus, Aml *scope);
Aurelien Jarno14e7a642012-09-08 16:58:57 +020090
Avi Kivityd7500732011-09-26 14:52:44 +030091/**
92 * isa_register_ioport: Install an I/O port region on the ISA bus.
93 *
94 * Register an I/O port region via memory_region_add_subregion
95 * inside the ISA I/O address space.
96 *
97 * @dev: the ISADevice against which these are registered; may be NULL.
98 * @io: the #MemoryRegion being registered.
99 * @start: the base I/O port.
100 */
101void isa_register_ioport(ISADevice *dev, MemoryRegion *io, uint16_t start);
102
103/**
104 * isa_register_portio_list: Initialize a set of ISA io ports
105 *
106 * Several ISA devices have many dis-joint I/O ports. Worse, these I/O
107 * ports can be interleaved with I/O ports from other devices. This
108 * function makes it easy to create multiple MemoryRegions for a single
109 * device and use the legacy portio routines.
110 *
111 * @dev: the ISADevice against which these are registered; may be NULL.
Marc-André Lureaue305a162016-07-13 02:11:59 +0200112 * @piolist: the PortioList associated with the io ports
Avi Kivityd7500732011-09-26 14:52:44 +0300113 * @start: the base I/O port against which the portio->offset is applied.
114 * @portio: the ports, sorted by offset.
Hervé Poussineau520902a2013-08-13 12:38:34 +0200115 * @opaque: passed into the portio callbacks.
Avi Kivityd7500732011-09-26 14:52:44 +0300116 * @name: passed into memory_region_init_io.
Thomas Huth9405d872021-04-16 14:52:56 +0200117 *
118 * Returns: 0 on success, negative error code otherwise (e.g. if the
119 * ISA bus is not available)
Avi Kivityd7500732011-09-26 14:52:44 +0300120 */
Thomas Huth9405d872021-04-16 14:52:56 +0200121int isa_register_portio_list(ISADevice *dev,
122 PortioList *piolist,
123 uint16_t start,
124 const MemoryRegionPortio *portio,
125 void *opaque, const char *name);
Avi Kivityd7500732011-09-26 14:52:44 +0300126
Hervé Poussineaua527b542012-03-17 15:39:43 +0100127static inline ISABus *isa_bus_from_device(ISADevice *d)
128{
Andreas Färber3e7b8f42013-01-20 18:56:18 +0100129 return ISA_BUS(qdev_get_parent_bus(DEVICE(d)));
Hervé Poussineaua527b542012-03-17 15:39:43 +0100130}
131
Hervé Poussineau9b74b192018-01-06 16:37:29 +0100132#define TYPE_PIIX4_PCI_DEVICE "piix4-isa"
133
blueswir179383c92008-08-30 09:51:20 +0000134#endif