root / hw / ssi.c @ 8294a64d
History | View | Annotate | Download (1.9 kB)
1 |
/*
|
---|---|
2 |
* QEMU Synchronous Serial Interface support
|
3 |
*
|
4 |
* Copyright (c) 2009 CodeSourcery.
|
5 |
* Written by Paul Brook
|
6 |
*
|
7 |
* This code is licensed under the GNU GPL v2.
|
8 |
*
|
9 |
* Contributions after 2012-01-13 are licensed under the terms of the
|
10 |
* GNU GPL, version 2 or (at your option) any later version.
|
11 |
*/
|
12 |
|
13 |
#include "ssi.h" |
14 |
|
15 |
struct SSIBus {
|
16 |
BusState qbus; |
17 |
}; |
18 |
|
19 |
static struct BusInfo ssi_bus_info = { |
20 |
.name = "SSI",
|
21 |
.size = sizeof(SSIBus),
|
22 |
}; |
23 |
|
24 |
static int ssi_slave_init(DeviceState *dev) |
25 |
{ |
26 |
SSISlave *s = SSI_SLAVE(dev); |
27 |
SSISlaveClass *ssc = SSI_SLAVE_GET_CLASS(s); |
28 |
SSIBus *bus; |
29 |
|
30 |
bus = FROM_QBUS(SSIBus, qdev_get_parent_bus(dev)); |
31 |
if (QTAILQ_FIRST(&bus->qbus.children) != dev
|
32 |
|| QTAILQ_NEXT(dev, sibling) != NULL) {
|
33 |
hw_error("Too many devices on SSI bus");
|
34 |
} |
35 |
|
36 |
return ssc->init(s);
|
37 |
} |
38 |
|
39 |
static void ssi_slave_class_init(ObjectClass *klass, void *data) |
40 |
{ |
41 |
DeviceClass *dc = DEVICE_CLASS(klass); |
42 |
dc->init = ssi_slave_init; |
43 |
dc->bus_info = &ssi_bus_info; |
44 |
} |
45 |
|
46 |
static TypeInfo ssi_slave_info = {
|
47 |
.name = TYPE_SSI_SLAVE, |
48 |
.parent = TYPE_DEVICE, |
49 |
.class_init = ssi_slave_class_init, |
50 |
.class_size = sizeof(SSISlaveClass),
|
51 |
.abstract = true,
|
52 |
}; |
53 |
|
54 |
DeviceState *ssi_create_slave(SSIBus *bus, const char *name) |
55 |
{ |
56 |
DeviceState *dev; |
57 |
dev = qdev_create(&bus->qbus, name); |
58 |
qdev_init_nofail(dev); |
59 |
return dev;
|
60 |
} |
61 |
|
62 |
SSIBus *ssi_create_bus(DeviceState *parent, const char *name) |
63 |
{ |
64 |
BusState *bus; |
65 |
bus = qbus_create(&ssi_bus_info, parent, name); |
66 |
return FROM_QBUS(SSIBus, bus);
|
67 |
} |
68 |
|
69 |
uint32_t ssi_transfer(SSIBus *bus, uint32_t val) |
70 |
{ |
71 |
DeviceState *dev; |
72 |
SSISlave *slave; |
73 |
SSISlaveClass *ssc; |
74 |
dev = QTAILQ_FIRST(&bus->qbus.children); |
75 |
if (!dev) {
|
76 |
return 0; |
77 |
} |
78 |
slave = SSI_SLAVE(dev); |
79 |
ssc = SSI_SLAVE_GET_CLASS(slave); |
80 |
return ssc->transfer(slave, val);
|
81 |
} |
82 |
|
83 |
static void ssi_slave_register_types(void) |
84 |
{ |
85 |
type_register_static(&ssi_slave_info); |
86 |
} |
87 |
|
88 |
type_init(ssi_slave_register_types) |