2009-05-14 21:35:09 +00:00
|
|
|
/*
|
|
|
|
* QEMU Synchronous Serial Interface support
|
|
|
|
*
|
|
|
|
* Copyright (c) 2009 CodeSourcery.
|
|
|
|
* Written by Paul Brook
|
|
|
|
*
|
|
|
|
* This code is licenced under the GNU GPL v2.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ssi.h"
|
|
|
|
|
|
|
|
struct SSIBus {
|
2009-05-22 23:05:19 +00:00
|
|
|
BusState qbus;
|
2009-05-14 21:35:09 +00:00
|
|
|
};
|
|
|
|
|
2009-06-30 12:12:08 +00:00
|
|
|
static struct BusInfo ssi_bus_info = {
|
|
|
|
.name = "SSI",
|
|
|
|
.size = sizeof(SSIBus),
|
|
|
|
};
|
|
|
|
|
2009-08-14 08:36:05 +00:00
|
|
|
static int ssi_slave_init(DeviceState *dev, DeviceInfo *base_info)
|
2009-05-14 21:35:09 +00:00
|
|
|
{
|
2009-05-22 23:05:19 +00:00
|
|
|
SSISlaveInfo *info = container_of(base_info, SSISlaveInfo, qdev);
|
2009-05-14 21:35:09 +00:00
|
|
|
SSISlave *s = SSI_SLAVE_FROM_QDEV(dev);
|
2009-05-22 23:05:19 +00:00
|
|
|
SSIBus *bus;
|
|
|
|
|
|
|
|
bus = FROM_QBUS(SSIBus, qdev_get_parent_bus(dev));
|
2009-09-12 07:36:22 +00:00
|
|
|
if (QLIST_FIRST(&bus->qbus.children) != dev
|
|
|
|
|| QLIST_NEXT(dev, sibling) != NULL) {
|
2009-05-22 23:05:19 +00:00
|
|
|
hw_error("Too many devices on SSI bus");
|
|
|
|
}
|
2009-05-14 21:35:09 +00:00
|
|
|
|
|
|
|
s->info = info;
|
2009-08-14 08:36:05 +00:00
|
|
|
return info->init(s);
|
2009-05-14 21:35:09 +00:00
|
|
|
}
|
|
|
|
|
2009-06-10 07:41:42 +00:00
|
|
|
void ssi_register_slave(SSISlaveInfo *info)
|
2009-05-14 21:35:09 +00:00
|
|
|
{
|
2009-06-10 07:41:42 +00:00
|
|
|
assert(info->qdev.size >= sizeof(SSISlave));
|
2009-05-22 23:05:19 +00:00
|
|
|
info->qdev.init = ssi_slave_init;
|
2009-06-30 12:12:08 +00:00
|
|
|
info->qdev.bus_info = &ssi_bus_info;
|
2009-06-10 07:41:42 +00:00
|
|
|
qdev_register(&info->qdev);
|
2009-05-14 21:35:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DeviceState *ssi_create_slave(SSIBus *bus, const char *name)
|
|
|
|
{
|
|
|
|
DeviceState *dev;
|
2009-05-22 23:05:19 +00:00
|
|
|
dev = qdev_create(&bus->qbus, name);
|
2009-10-06 23:15:58 +00:00
|
|
|
qdev_init_nofail(dev);
|
2009-05-14 21:35:09 +00:00
|
|
|
return dev;
|
|
|
|
}
|
|
|
|
|
2009-05-22 23:05:19 +00:00
|
|
|
SSIBus *ssi_create_bus(DeviceState *parent, const char *name)
|
2009-05-14 21:35:09 +00:00
|
|
|
{
|
2009-05-22 23:05:19 +00:00
|
|
|
BusState *bus;
|
2009-06-30 12:12:08 +00:00
|
|
|
bus = qbus_create(&ssi_bus_info, parent, name);
|
2009-05-22 23:05:19 +00:00
|
|
|
return FROM_QBUS(SSIBus, bus);
|
2009-05-14 21:35:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t ssi_transfer(SSIBus *bus, uint32_t val)
|
|
|
|
{
|
2009-05-22 23:05:19 +00:00
|
|
|
DeviceState *dev;
|
|
|
|
SSISlave *slave;
|
2009-09-12 07:36:22 +00:00
|
|
|
dev = QLIST_FIRST(&bus->qbus.children);
|
2009-05-22 23:05:19 +00:00
|
|
|
if (!dev) {
|
2009-05-14 21:35:09 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2009-05-22 23:05:19 +00:00
|
|
|
slave = SSI_SLAVE_FROM_QDEV(dev);
|
|
|
|
return slave->info->transfer(slave, val);
|
2009-05-14 21:35:09 +00:00
|
|
|
}
|