25
#include "qemu/osdep.h"
26
#include "qapi/error.h"
27
#include "qemu/module.h"
28
#include "hw/isa/isa.h"
29
#include "hw/qdev-properties.h"
30
#include "migration/vmstate.h"
31
#include "hw/dma/i8257.h"
32
#include "qom/object.h"
34
#define TYPE_I82374 "i82374"
35
OBJECT_DECLARE_SIMPLE_TYPE(I82374State, I82374)
40
#define DPRINTF(fmt, ...) \
41
do { fprintf(stderr, "i82374: " fmt , ## __VA_ARGS__); } while (0)
43
#define DPRINTF(fmt, ...) \
46
#define BADF(fmt, ...) \
47
do { fprintf(stderr, "i82374 ERROR: " fmt , ## __VA_ARGS__); } while (0)
57
static const VMStateDescription vmstate_i82374 = {
60
.minimum_version_id = 0,
61
.fields = (const VMStateField[]) {
62
VMSTATE_UINT8_ARRAY(commands, I82374State, 8),
67
static uint32_t i82374_read_isr(void *opaque, uint32_t nport)
71
BADF("%s: %08x\n", __func__, nport);
73
DPRINTF("%s: %08x=%08x\n", __func__, nport, val);
77
static void i82374_write_command(void *opaque, uint32_t nport, uint32_t data)
79
DPRINTF("%s: %08x=%08x\n", __func__, nport, data);
83
BADF("%s: %08x=%08x\n", __func__, nport, data);
87
static uint32_t i82374_read_status(void *opaque, uint32_t nport)
91
BADF("%s: %08x\n", __func__, nport);
93
DPRINTF("%s: %08x=%08x\n", __func__, nport, val);
97
static void i82374_write_descriptor(void *opaque, uint32_t nport, uint32_t data)
99
DPRINTF("%s: %08x=%08x\n", __func__, nport, data);
101
BADF("%s: %08x=%08x\n", __func__, nport, data);
104
static uint32_t i82374_read_descriptor(void *opaque, uint32_t nport)
108
BADF("%s: %08x\n", __func__, nport);
110
DPRINTF("%s: %08x=%08x\n", __func__, nport, val);
114
static const MemoryRegionPortio i82374_portio_list[] = {
115
{ 0x0A, 1, 1, .read = i82374_read_isr, },
116
{ 0x10, 8, 1, .write = i82374_write_command, },
117
{ 0x18, 8, 1, .read = i82374_read_status, },
119
.write = i82374_write_descriptor, .read = i82374_read_descriptor, },
120
PORTIO_END_OF_LIST(),
123
static void i82374_realize(DeviceState *dev, Error **errp)
125
I82374State *s = I82374(dev);
126
ISABus *isa_bus = isa_bus_from_device(ISA_DEVICE(dev));
128
if (isa_bus_get_dma(isa_bus, 0)) {
129
error_setg(errp, "DMA already initialized on ISA bus");
132
i8257_dma_init(OBJECT(dev), isa_bus, true);
134
portio_list_init(&s->port_list, OBJECT(s), i82374_portio_list, s,
136
portio_list_add(&s->port_list, isa_address_space_io(&s->parent_obj),
139
memset(s->commands, 0, sizeof(s->commands));
142
static Property i82374_properties[] = {
143
DEFINE_PROP_UINT32("iobase", I82374State, iobase, 0x400),
144
DEFINE_PROP_END_OF_LIST()
147
static void i82374_class_init(ObjectClass *klass, void *data)
149
DeviceClass *dc = DEVICE_CLASS(klass);
151
dc->realize = i82374_realize;
152
dc->vmsd = &vmstate_i82374;
153
device_class_set_props(dc, i82374_properties);
156
static const TypeInfo i82374_info = {
158
.parent = TYPE_ISA_DEVICE,
159
.instance_size = sizeof(I82374State),
160
.class_init = i82374_class_init,
163
static void i82374_register_types(void)
165
type_register_static(&i82374_info);
168
type_init(i82374_register_types)