2009-05-15 01:35:09 +04: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-23 03:05:19 +04:00
|
|
|
BusState qbus;
|
2009-05-15 01:35:09 +04:00
|
|
|
};
|
|
|
|
|
2009-05-23 03:05:19 +04:00
|
|
|
static void ssi_slave_init(DeviceState *dev, DeviceInfo *base_info)
|
2009-05-15 01:35:09 +04:00
|
|
|
{
|
2009-05-23 03:05:19 +04:00
|
|
|
SSISlaveInfo *info = container_of(base_info, SSISlaveInfo, qdev);
|
2009-05-15 01:35:09 +04:00
|
|
|
SSISlave *s = SSI_SLAVE_FROM_QDEV(dev);
|
2009-05-23 03:05:19 +04:00
|
|
|
SSIBus *bus;
|
|
|
|
|
|
|
|
bus = FROM_QBUS(SSIBus, qdev_get_parent_bus(dev));
|
|
|
|
if (LIST_FIRST(&bus->qbus.children) != dev
|
|
|
|
|| LIST_NEXT(dev, sibling) != NULL) {
|
|
|
|
hw_error("Too many devices on SSI bus");
|
|
|
|
}
|
2009-05-15 01:35:09 +04:00
|
|
|
|
|
|
|
s->info = info;
|
|
|
|
info->init(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ssi_register_slave(const char *name, int size, SSISlaveInfo *info)
|
|
|
|
{
|
|
|
|
assert(size >= sizeof(SSISlave));
|
2009-05-23 03:05:19 +04:00
|
|
|
info->qdev.init = ssi_slave_init;
|
|
|
|
info->qdev.bus_type = BUS_TYPE_SSI;
|
|
|
|
qdev_register(name, size, &info->qdev);
|
2009-05-15 01:35:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
DeviceState *ssi_create_slave(SSIBus *bus, const char *name)
|
|
|
|
{
|
|
|
|
DeviceState *dev;
|
2009-05-23 03:05:19 +04:00
|
|
|
dev = qdev_create(&bus->qbus, name);
|
2009-05-15 01:35:09 +04:00
|
|
|
qdev_init(dev);
|
|
|
|
return dev;
|
|
|
|
}
|
|
|
|
|
2009-05-23 03:05:19 +04:00
|
|
|
SSIBus *ssi_create_bus(DeviceState *parent, const char *name)
|
2009-05-15 01:35:09 +04:00
|
|
|
{
|
2009-05-23 03:05:19 +04:00
|
|
|
BusState *bus;
|
|
|
|
bus = qbus_create(BUS_TYPE_SSI, sizeof(SSIBus), parent, name);
|
|
|
|
return FROM_QBUS(SSIBus, bus);
|
2009-05-15 01:35:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t ssi_transfer(SSIBus *bus, uint32_t val)
|
|
|
|
{
|
2009-05-23 03:05:19 +04:00
|
|
|
DeviceState *dev;
|
|
|
|
SSISlave *slave;
|
|
|
|
dev = LIST_FIRST(&bus->qbus.children);
|
|
|
|
if (!dev) {
|
2009-05-15 01:35:09 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2009-05-23 03:05:19 +04:00
|
|
|
slave = SSI_SLAVE_FROM_QDEV(dev);
|
|
|
|
return slave->info->transfer(slave, val);
|
2009-05-15 01:35:09 +04:00
|
|
|
}
|