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/>.
25 #if 0 // TODO: Fix code for QOM API.
31 static struct BusInfo vlynq_bus_info
= {
33 .size
= sizeof(VLYNQBus
),
36 static int vlynq_qdev_init(DeviceState
*qdev
, DeviceInfo
*base
)
38 VLYNQDevice
*vlynq_dev
= (VLYNQDevice
*)qdev
;
39 VLYNQDeviceInfo
*info
= container_of(base
, VLYNQDeviceInfo
, qdev
);
43 //~ VLYNQBus *bus = FROM_QBUS(VLYNQBus, qdev_get_parent_bus(qdev));
44 //~ devfn = pci_dev->devfn;
45 //~ vlynq_dev = do_pci_register_device(pci_dev, bus, base->name, devfn,
46 //~ info->config_read, info->config_write,
47 //~ info->header_type);
48 //~ if (vlynq_dev == NULL) {
51 rc
= info
->init(vlynq_dev
);
53 //~ do_pci_unregister_device(pci_dev);
59 static int vlynq_unregister_device(DeviceState
*dev
)
61 // TODO: missing implementation.
63 //~ VLYNQDevice *vlynq_dev = DO_UPCAST(VLYNQDevice, qdev, dev);
64 //~ VLYNQDeviceInfo *info = DO_UPCAST(VLYNQDeviceInfo, qdev, dev->info);
68 //~ ret = info->exit(vlynq_dev);
74 //~ pci_unregister_io_regions(pci_dev);
75 //~ do_pci_unregister_device(pci_dev);
79 void vlynq_qdev_register(VLYNQDeviceInfo
*info
)
81 info
->qdev
.init
= vlynq_qdev_init
;
82 //~ info->qdev.unplug = vlynq_unplug_device;
83 info
->qdev
.exit
= vlynq_unregister_device
;
84 info
->qdev
.bus_info
= &vlynq_bus_info
;
85 qdev_register(&info
->qdev
);
89 static int vlynq_slave_init(DeviceState
*dev
, DeviceInfo
*base_info
)
91 VLYNQSlaveInfo
*info
= container_of(base_info
, VLYNQSlaveInfo
, qdev
);
92 VLYNQSlave
*s
= VLYNQ_SLAVE_FROM_QDEV(dev
);
95 bus
= FROM_QBUS(VLYNQBus
, qdev_get_parent_bus(dev
));
96 if (QLIST_FIRST(&bus
->qbus
.children
) != dev
97 || QLIST_NEXT(dev
, sibling
) != NULL
) {
98 hw_error("Too many devices on VLYNQ bus");
102 return info
->init(s
);
105 void vlynq_register_slave(VLYNQSlaveInfo
*info
)
107 assert(info
->qdev
.size
>= sizeof(VLYNQSlave
));
108 info
->qdev
.init
= vlynq_slave_init
;
109 info
->qdev
.bus_info
= &vlynq_bus_info
;
110 qdev_register(&info
->qdev
);
115 DeviceState
*vlynq_create_slave(VLYNQBus
*bus
, const char *name
)
118 dev
= qdev_create(&bus
->qbus
, name
);
119 qdev_init_nofail(dev
);
123 VLYNQBus
*vlynq_create_bus(DeviceState
*parent
, const char *name
)
126 bus
= qbus_create(&vlynq_bus_info
, parent
, name
);
127 return FROM_QBUS(VLYNQBus
, bus
);
131 uint32_t vlynq_transfer(VLYNQBus
*bus
, uint32_t val
)
135 dev
= QLIST_FIRST(&bus
->qbus
.children
);
139 slave
= VLYNQ_SLAVE_FROM_QDEV(dev
);
140 return slave
->info
->transfer(slave
, val
);
143 #endif // Fix code for QOM API.