Blame view

hw/ssi.c 1.54 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
};
16
17
18
19
20
static struct BusInfo ssi_bus_info = {
    .name = "SSI",
    .size = sizeof(SSIBus),
};
Paul Brook authored
21
static void ssi_slave_init(DeviceState *dev, DeviceInfo *base_info)
Paul Brook authored
22
{
Paul Brook authored
23
    SSISlaveInfo *info = container_of(base_info, SSISlaveInfo, qdev);
Paul Brook authored
24
    SSISlave *s = SSI_SLAVE_FROM_QDEV(dev);
Paul Brook authored
25
26
27
28
29
30
31
    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
32
33
34
35
36

    s->info = info;
    info->init(s);
}
37
void ssi_register_slave(SSISlaveInfo *info)
Paul Brook authored
38
{
39
    assert(info->qdev.size >= sizeof(SSISlave));
Paul Brook authored
40
    info->qdev.init = ssi_slave_init;
41
    info->qdev.bus_info = &ssi_bus_info;
42
    qdev_register(&info->qdev);
Paul Brook authored
43
44
45
46
47
}

DeviceState *ssi_create_slave(SSIBus *bus, const char *name)
{
    DeviceState *dev;
Paul Brook authored
48
    dev = qdev_create(&bus->qbus, name);
Paul Brook authored
49
50
51
52
    qdev_init(dev);
    return dev;
}
Paul Brook authored
53
SSIBus *ssi_create_bus(DeviceState *parent, const char *name)
Paul Brook authored
54
{
Paul Brook authored
55
    BusState *bus;
56
    bus = qbus_create(&ssi_bus_info, parent, name);
Paul Brook authored
57
    return FROM_QBUS(SSIBus, bus);
Paul Brook authored
58
59
60
61
}

uint32_t ssi_transfer(SSIBus *bus, uint32_t val)
{
Paul Brook authored
62
63
64
65
    DeviceState *dev;
    SSISlave *slave;
    dev = LIST_FIRST(&bus->qbus.children);
    if (!dev) {
Paul Brook authored
66
67
        return 0;
    }
Paul Brook authored
68
69
    slave = SSI_SLAVE_FROM_QDEV(dev);
    return slave->info->transfer(slave, val);
Paul Brook authored
70
}