2010-12-25 05:29:37 +01:00
|
|
|
/*
|
|
|
|
* QEMU Intel 82374 emulation (Enhanced DMA controller)
|
|
|
|
*
|
|
|
|
* Copyright (c) 2010 Hervé Poussineau
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2016-01-26 19:17:30 +01:00
|
|
|
#include "qemu/osdep.h"
|
2018-03-26 17:34:37 +02:00
|
|
|
#include "qapi/error.h"
|
2019-05-23 16:35:07 +02:00
|
|
|
#include "qemu/module.h"
|
2013-02-05 17:06:20 +01:00
|
|
|
#include "hw/isa/isa.h"
|
2019-08-12 07:23:51 +02:00
|
|
|
#include "hw/qdev-properties.h"
|
2019-08-12 07:23:45 +02:00
|
|
|
#include "migration/vmstate.h"
|
2018-03-08 23:39:23 +01:00
|
|
|
#include "hw/dma/i8257.h"
|
2020-09-03 22:43:22 +02:00
|
|
|
#include "qom/object.h"
|
2010-12-25 05:29:37 +01:00
|
|
|
|
2016-02-03 17:28:55 +01:00
|
|
|
#define TYPE_I82374 "i82374"
|
2020-09-16 20:25:19 +02:00
|
|
|
OBJECT_DECLARE_SIMPLE_TYPE(I82374State, I82374)
|
2016-02-03 17:28:55 +01:00
|
|
|
|
2010-12-25 05:29:37 +01:00
|
|
|
//#define DEBUG_I82374
|
|
|
|
|
|
|
|
#ifdef DEBUG_I82374
|
|
|
|
#define DPRINTF(fmt, ...) \
|
|
|
|
do { fprintf(stderr, "i82374: " fmt , ## __VA_ARGS__); } while (0)
|
|
|
|
#else
|
|
|
|
#define DPRINTF(fmt, ...) \
|
|
|
|
do {} while (0)
|
|
|
|
#endif
|
|
|
|
#define BADF(fmt, ...) \
|
|
|
|
do { fprintf(stderr, "i82374 ERROR: " fmt , ## __VA_ARGS__); } while (0)
|
|
|
|
|
2020-09-03 22:43:22 +02:00
|
|
|
struct I82374State {
|
2016-02-03 17:28:55 +01:00
|
|
|
ISADevice parent_obj;
|
|
|
|
|
|
|
|
uint32_t iobase;
|
2010-12-25 05:29:37 +01:00
|
|
|
uint8_t commands[8];
|
2014-04-29 15:38:39 +02:00
|
|
|
PortioList port_list;
|
2020-09-03 22:43:22 +02:00
|
|
|
};
|
2010-12-25 05:29:37 +01:00
|
|
|
|
|
|
|
static const VMStateDescription vmstate_i82374 = {
|
|
|
|
.name = "i82374",
|
|
|
|
.version_id = 0,
|
|
|
|
.minimum_version_id = 0,
|
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_UINT8_ARRAY(commands, I82374State, 8),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static uint32_t i82374_read_isr(void *opaque, uint32_t nport)
|
|
|
|
{
|
|
|
|
uint32_t val = 0;
|
|
|
|
|
|
|
|
BADF("%s: %08x\n", __func__, nport);
|
|
|
|
|
|
|
|
DPRINTF("%s: %08x=%08x\n", __func__, nport, val);
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void i82374_write_command(void *opaque, uint32_t nport, uint32_t data)
|
|
|
|
{
|
|
|
|
DPRINTF("%s: %08x=%08x\n", __func__, nport, data);
|
|
|
|
|
|
|
|
if (data != 0x42) {
|
|
|
|
/* Not Stop S/G command */
|
|
|
|
BADF("%s: %08x=%08x\n", __func__, nport, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t i82374_read_status(void *opaque, uint32_t nport)
|
|
|
|
{
|
|
|
|
uint32_t val = 0;
|
|
|
|
|
|
|
|
BADF("%s: %08x\n", __func__, nport);
|
|
|
|
|
|
|
|
DPRINTF("%s: %08x=%08x\n", __func__, nport, val);
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void i82374_write_descriptor(void *opaque, uint32_t nport, uint32_t data)
|
|
|
|
{
|
|
|
|
DPRINTF("%s: %08x=%08x\n", __func__, nport, data);
|
|
|
|
|
|
|
|
BADF("%s: %08x=%08x\n", __func__, nport, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t i82374_read_descriptor(void *opaque, uint32_t nport)
|
|
|
|
{
|
|
|
|
uint32_t val = 0;
|
|
|
|
|
|
|
|
BADF("%s: %08x\n", __func__, nport);
|
|
|
|
|
|
|
|
DPRINTF("%s: %08x=%08x\n", __func__, nport, val);
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2013-06-22 08:06:57 +02:00
|
|
|
static const MemoryRegionPortio i82374_portio_list[] = {
|
|
|
|
{ 0x0A, 1, 1, .read = i82374_read_isr, },
|
|
|
|
{ 0x10, 8, 1, .write = i82374_write_command, },
|
|
|
|
{ 0x18, 8, 1, .read = i82374_read_status, },
|
|
|
|
{ 0x20, 0x20, 1,
|
|
|
|
.write = i82374_write_descriptor, .read = i82374_read_descriptor, },
|
|
|
|
PORTIO_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
2016-02-03 17:28:55 +01:00
|
|
|
static void i82374_realize(DeviceState *dev, Error **errp)
|
2010-12-25 05:29:37 +01:00
|
|
|
{
|
2016-02-03 17:28:55 +01:00
|
|
|
I82374State *s = I82374(dev);
|
2018-03-26 17:34:37 +02:00
|
|
|
ISABus *isa_bus = isa_bus_from_device(ISA_DEVICE(dev));
|
|
|
|
|
|
|
|
if (isa_get_dma(isa_bus, 0)) {
|
|
|
|
error_setg(errp, "DMA already initialized on ISA bus");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
i8257_dma_init(isa_bus, true);
|
2010-12-25 05:29:37 +01:00
|
|
|
|
2016-02-03 17:28:55 +01:00
|
|
|
portio_list_init(&s->port_list, OBJECT(s), i82374_portio_list, s,
|
2014-04-29 15:38:39 +02:00
|
|
|
"i82374");
|
2016-02-03 17:28:55 +01:00
|
|
|
portio_list_add(&s->port_list, isa_address_space_io(&s->parent_obj),
|
|
|
|
s->iobase);
|
2010-12-25 05:29:37 +01:00
|
|
|
|
2016-02-03 17:28:55 +01:00
|
|
|
memset(s->commands, 0, sizeof(s->commands));
|
2010-12-25 05:29:37 +01:00
|
|
|
}
|
|
|
|
|
2011-12-08 04:34:16 +01:00
|
|
|
static Property i82374_properties[] = {
|
2016-02-03 17:28:55 +01:00
|
|
|
DEFINE_PROP_UINT32("iobase", I82374State, iobase, 0x400),
|
2011-12-08 04:34:16 +01:00
|
|
|
DEFINE_PROP_END_OF_LIST()
|
|
|
|
};
|
|
|
|
|
2011-12-04 18:52:49 +01:00
|
|
|
static void i82374_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
2011-12-08 04:34:16 +01:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2011-12-04 18:52:49 +01:00
|
|
|
|
2016-02-03 17:28:55 +01:00
|
|
|
dc->realize = i82374_realize;
|
|
|
|
dc->vmsd = &vmstate_i82374;
|
2020-01-10 16:30:32 +01:00
|
|
|
device_class_set_props(dc, i82374_properties);
|
2011-12-04 18:52:49 +01:00
|
|
|
}
|
|
|
|
|
2016-02-03 17:28:55 +01:00
|
|
|
static const TypeInfo i82374_info = {
|
2013-04-27 22:18:39 +02:00
|
|
|
.name = TYPE_I82374,
|
2011-12-08 04:34:16 +01:00
|
|
|
.parent = TYPE_ISA_DEVICE,
|
2016-02-03 17:28:55 +01:00
|
|
|
.instance_size = sizeof(I82374State),
|
2011-12-04 18:52:49 +01:00
|
|
|
.class_init = i82374_class_init,
|
2010-12-25 05:29:37 +01:00
|
|
|
};
|
|
|
|
|
2012-02-09 15:20:55 +01:00
|
|
|
static void i82374_register_types(void)
|
2010-12-25 05:29:37 +01:00
|
|
|
{
|
2016-02-03 17:28:55 +01:00
|
|
|
type_register_static(&i82374_info);
|
2010-12-25 05:29:37 +01:00
|
|
|
}
|
|
|
|
|
2012-02-09 15:20:55 +01:00
|
|
|
type_init(i82374_register_types)
|