Blame view

hw/ssi.c 1.49 KB
Paul Brook authored
1
2
3
4
5
6
7
8
9
10
11
12
/*
 * 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 {
Paul Brook authored
13
    BusState qbus;
Paul Brook authored
14
15
};
Paul Brook authored
16
static void ssi_slave_init(DeviceState *dev, DeviceInfo *base_info)
Paul Brook authored
17
{
Paul Brook authored
18
    SSISlaveInfo *info = container_of(base_info, SSISlaveInfo, qdev);
Paul Brook authored
19
    SSISlave *s = SSI_SLAVE_FROM_QDEV(dev);
Paul Brook authored
20
21
22
23
24
25
26
    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");
    }
Paul Brook authored
27
28
29
30
31
32
33
34

    s->info = info;
    info->init(s);
}

void ssi_register_slave(const char *name, int size, SSISlaveInfo *info)
{
    assert(size >= sizeof(SSISlave));
Paul Brook authored
35
36
37
    info->qdev.init = ssi_slave_init;
    info->qdev.bus_type = BUS_TYPE_SSI;
    qdev_register(name, size, &info->qdev);
Paul Brook authored
38
39
40
41
42
}

DeviceState *ssi_create_slave(SSIBus *bus, const char *name)
{
    DeviceState *dev;
Paul Brook authored
43
    dev = qdev_create(&bus->qbus, name);
Paul Brook authored
44
45
46
47
    qdev_init(dev);
    return dev;
}
Paul Brook authored
48
SSIBus *ssi_create_bus(DeviceState *parent, const char *name)
Paul Brook authored
49
{
Paul Brook authored
50
51
52
    BusState *bus;
    bus = qbus_create(BUS_TYPE_SSI, sizeof(SSIBus), parent, name);
    return FROM_QBUS(SSIBus, bus);
Paul Brook authored
53
54
55
56
}

uint32_t ssi_transfer(SSIBus *bus, uint32_t val)
{
Paul Brook authored
57
58
59
60
    DeviceState *dev;
    SSISlave *slave;
    dev = LIST_FIRST(&bus->qbus.children);
    if (!dev) {
Paul Brook authored
61
62
        return 0;
    }
Paul Brook authored
63
64
    slave = SSI_SLAVE_FROM_QDEV(dev);
    return slave->info->transfer(slave, val);
Paul Brook authored
65
}