2 * QEMU VLYNQ Serial Interface support.
4 * Copyright (C) 2009-2012 Stefan Weil
6 * Portions of the code are copies from ssi.c.
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 2 of the License, or
11 * (at your option) version 3 or any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "qemu/osdep.h"
26 #if 0 // TODO: Fix code for QOM API.
32 static struct BusInfo vlynq_bus_info
= {
34 .size
= sizeof(VLYNQBus
),
37 static int vlynq_qdev_init(DeviceState
*qdev
, DeviceInfo
*base
)
39 VLYNQDevice
*vlynq_dev
= (VLYNQDevice
*)qdev
;
40 VLYNQDeviceInfo
*info
= container_of(base
, VLYNQDeviceInfo
, qdev
);
44 //~ VLYNQBus *bus = FROM_QBUS(VLYNQBus, qdev_get_parent_bus(qdev));
45 //~ devfn = pci_dev->devfn;
46 //~ vlynq_dev = do_pci_register_device(pci_dev, bus, base->name, devfn,
47 //~ info->config_read, info->config_write,
48 //~ info->header_type);
49 //~ if (vlynq_dev == NULL) {
52 rc
= info
->init(vlynq_dev
);
54 //~ do_pci_unregister_device(pci_dev);
60 static int vlynq_unregister_device(DeviceState
*dev
)
62 // TODO: missing implementation.
64 //~ VLYNQDevice *vlynq_dev = DO_UPCAST(VLYNQDevice, qdev, dev);
65 //~ VLYNQDeviceInfo *info = DO_UPCAST(VLYNQDeviceInfo, qdev, dev->info);
69 //~ ret = info->exit(vlynq_dev);
75 //~ pci_unregister_io_regions(pci_dev);
76 //~ do_pci_unregister_device(pci_dev);
80 void vlynq_qdev_register(VLYNQDeviceInfo
*info
)
82 info
->qdev
.init
= vlynq_qdev_init
;
83 //~ info->qdev.unplug = vlynq_unplug_device;
84 info
->qdev
.exit
= vlynq_unregister_device
;
85 info
->qdev
.bus_info
= &vlynq_bus_info
;
86 qdev_register(&info
->qdev
);
90 static int vlynq_slave_init(DeviceState
*dev
, DeviceInfo
*base_info
)
92 VLYNQSlaveInfo
*info
= container_of(base_info
, VLYNQSlaveInfo
, qdev
);
93 VLYNQSlave
*s
= VLYNQ_SLAVE_FROM_QDEV(dev
);
96 bus
= FROM_QBUS(VLYNQBus
, qdev_get_parent_bus(dev
));
97 if (QLIST_FIRST(&bus
->qbus
.children
) != dev
98 || QLIST_NEXT(dev
, sibling
) != NULL
) {
99 hw_error("Too many devices on VLYNQ bus");
103 return info
->init(s
);
106 void vlynq_register_slave(VLYNQSlaveInfo
*info
)
108 assert(info
->qdev
.size
>= sizeof(VLYNQSlave
));
109 info
->qdev
.init
= vlynq_slave_init
;
110 info
->qdev
.bus_info
= &vlynq_bus_info
;
111 qdev_register(&info
->qdev
);
116 DeviceState
*vlynq_create_slave(VLYNQBus
*bus
, const char *name
)
119 dev
= qdev_create(&bus
->qbus
, name
);
120 qdev_init_nofail(dev
);
124 VLYNQBus
*vlynq_create_bus(DeviceState
*parent
, const char *name
)
127 bus
= qbus_create(&vlynq_bus_info
, parent
, name
);
128 return FROM_QBUS(VLYNQBus
, bus
);
132 uint32_t vlynq_transfer(VLYNQBus
*bus
, uint32_t val
)
136 dev
= QLIST_FIRST(&bus
->qbus
.children
);
140 slave
= VLYNQ_SLAVE_FROM_QDEV(dev
);
141 return slave
->info
->transfer(slave
, val
);
144 #endif // Fix code for QOM API.