]>
Commit | Line | Data |
---|---|---|
90d37239 PB |
1 | /* |
2 | * QEMU Synchronous Serial Interface support | |
3 | * | |
4 | * Copyright (c) 2009 CodeSourcery. | |
5 | * Written by Paul Brook | |
6 | * | |
8e31bf38 | 7 | * This code is licensed under the GNU GPL v2. |
6b620ca3 PB |
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. | |
90d37239 PB |
11 | */ |
12 | ||
13 | #include "ssi.h" | |
14 | ||
15 | struct SSIBus { | |
02e2da45 | 16 | BusState qbus; |
90d37239 PB |
17 | }; |
18 | ||
0d936928 AL |
19 | #define TYPE_SSI_BUS "SSI" |
20 | #define SSI_BUS(obj) OBJECT_CHECK(SSIBus, (obj), TYPE_SSI_BUS) | |
21 | ||
22 | static const TypeInfo ssi_bus_info = { | |
23 | .name = TYPE_SSI_BUS, | |
24 | .parent = TYPE_BUS, | |
25 | .instance_size = sizeof(SSIBus), | |
10c4c98a GH |
26 | }; |
27 | ||
d307af79 | 28 | static int ssi_slave_init(DeviceState *dev) |
90d37239 | 29 | { |
cd6c4cf2 AL |
30 | SSISlave *s = SSI_SLAVE(dev); |
31 | SSISlaveClass *ssc = SSI_SLAVE_GET_CLASS(s); | |
02e2da45 | 32 | SSIBus *bus; |
0866aca1 | 33 | BusChild *kid; |
02e2da45 PB |
34 | |
35 | bus = FROM_QBUS(SSIBus, qdev_get_parent_bus(dev)); | |
0866aca1 AL |
36 | kid = QTAILQ_FIRST(&bus->qbus.children); |
37 | if (kid->child != dev || QTAILQ_NEXT(kid, sibling) != NULL) { | |
02e2da45 PB |
38 | hw_error("Too many devices on SSI bus"); |
39 | } | |
90d37239 | 40 | |
cd6c4cf2 | 41 | return ssc->init(s); |
90d37239 PB |
42 | } |
43 | ||
39bffca2 | 44 | static void ssi_slave_class_init(ObjectClass *klass, void *data) |
90d37239 | 45 | { |
39bffca2 AL |
46 | DeviceClass *dc = DEVICE_CLASS(klass); |
47 | dc->init = ssi_slave_init; | |
0d936928 | 48 | dc->bus_type = TYPE_SSI_BUS; |
90d37239 PB |
49 | } |
50 | ||
39bffca2 AL |
51 | static TypeInfo ssi_slave_info = { |
52 | .name = TYPE_SSI_SLAVE, | |
53 | .parent = TYPE_DEVICE, | |
54 | .class_init = ssi_slave_class_init, | |
55 | .class_size = sizeof(SSISlaveClass), | |
56 | .abstract = true, | |
57 | }; | |
58 | ||
90d37239 PB |
59 | DeviceState *ssi_create_slave(SSIBus *bus, const char *name) |
60 | { | |
61 | DeviceState *dev; | |
02e2da45 | 62 | dev = qdev_create(&bus->qbus, name); |
e23a1b33 | 63 | qdev_init_nofail(dev); |
90d37239 PB |
64 | return dev; |
65 | } | |
66 | ||
02e2da45 | 67 | SSIBus *ssi_create_bus(DeviceState *parent, const char *name) |
90d37239 | 68 | { |
02e2da45 | 69 | BusState *bus; |
0d936928 | 70 | bus = qbus_create(TYPE_SSI_BUS, parent, name); |
02e2da45 | 71 | return FROM_QBUS(SSIBus, bus); |
90d37239 PB |
72 | } |
73 | ||
74 | uint32_t ssi_transfer(SSIBus *bus, uint32_t val) | |
75 | { | |
0866aca1 | 76 | BusChild *kid; |
02e2da45 | 77 | SSISlave *slave; |
cd6c4cf2 | 78 | SSISlaveClass *ssc; |
0866aca1 AL |
79 | |
80 | kid = QTAILQ_FIRST(&bus->qbus.children); | |
81 | if (!kid) { | |
90d37239 PB |
82 | return 0; |
83 | } | |
0866aca1 | 84 | slave = SSI_SLAVE(kid->child); |
cd6c4cf2 AL |
85 | ssc = SSI_SLAVE_GET_CLASS(slave); |
86 | return ssc->transfer(slave, val); | |
90d37239 | 87 | } |
39bffca2 | 88 | |
83f7d43a | 89 | static void ssi_slave_register_types(void) |
39bffca2 | 90 | { |
0d936928 | 91 | type_register_static(&ssi_bus_info); |
39bffca2 AL |
92 | type_register_static(&ssi_slave_info); |
93 | } | |
94 | ||
83f7d43a | 95 | type_init(ssi_slave_register_types) |