net: Remove duplicate data from query-rx-filter on multiqueue net devices
[qemu/ar7.git] / hw / ipack / ipack.c
blob59bfe2869e0e1ab7d1f9b3a9db91ad4dfb362e34
1 /*
2 * QEMU IndustryPack emulation
4 * Copyright (C) 2012 Igalia, S.L.
5 * Author: Alberto Garcia <agarcia@igalia.com>
7 * This code is licensed under the GNU GPL v2 or (at your option) any
8 * later version.
9 */
11 #include "hw/ipack/ipack.h"
13 IPackDevice *ipack_device_find(IPackBus *bus, int32_t slot)
15 BusChild *kid;
17 QTAILQ_FOREACH(kid, &BUS(bus)->children, sibling) {
18 DeviceState *qdev = kid->child;
19 IPackDevice *ip = IPACK_DEVICE(qdev);
20 if (ip->slot == slot) {
21 return ip;
24 return NULL;
27 void ipack_bus_new_inplace(IPackBus *bus, size_t bus_size,
28 DeviceState *parent,
29 const char *name, uint8_t n_slots,
30 qemu_irq_handler handler)
32 qbus_create_inplace(bus, bus_size, TYPE_IPACK_BUS, parent, name);
33 bus->n_slots = n_slots;
34 bus->set_irq = handler;
37 static void ipack_device_realize(DeviceState *dev, Error **errp)
39 IPackDevice *idev = IPACK_DEVICE(dev);
40 IPackBus *bus = IPACK_BUS(qdev_get_parent_bus(dev));
41 IPackDeviceClass *k = IPACK_DEVICE_GET_CLASS(dev);
43 if (idev->slot < 0) {
44 idev->slot = bus->free_slot;
46 if (idev->slot >= bus->n_slots) {
47 error_setg(errp, "Only %" PRIu8 " slots available.", bus->n_slots);
48 return;
50 bus->free_slot = idev->slot + 1;
52 idev->irq = qemu_allocate_irqs(bus->set_irq, idev, 2);
54 k->realize(dev, errp);
57 static void ipack_device_unrealize(DeviceState *dev, Error **errp)
59 IPackDevice *idev = IPACK_DEVICE(dev);
60 IPackDeviceClass *k = IPACK_DEVICE_GET_CLASS(dev);
61 Error *err = NULL;
63 if (k->unrealize) {
64 k->unrealize(dev, &err);
65 error_propagate(errp, err);
66 return;
69 qemu_free_irqs(idev->irq, 2);
72 static Property ipack_device_props[] = {
73 DEFINE_PROP_INT32("slot", IPackDevice, slot, -1),
74 DEFINE_PROP_END_OF_LIST()
77 static void ipack_device_class_init(ObjectClass *klass, void *data)
79 DeviceClass *k = DEVICE_CLASS(klass);
81 set_bit(DEVICE_CATEGORY_INPUT, k->categories);
82 k->bus_type = TYPE_IPACK_BUS;
83 k->realize = ipack_device_realize;
84 k->unrealize = ipack_device_unrealize;
85 k->props = ipack_device_props;
88 const VMStateDescription vmstate_ipack_device = {
89 .name = "ipack_device",
90 .version_id = 1,
91 .minimum_version_id = 1,
92 .fields = (VMStateField[]) {
93 VMSTATE_INT32(slot, IPackDevice),
94 VMSTATE_END_OF_LIST()
98 static const TypeInfo ipack_device_info = {
99 .name = TYPE_IPACK_DEVICE,
100 .parent = TYPE_DEVICE,
101 .instance_size = sizeof(IPackDevice),
102 .class_size = sizeof(IPackDeviceClass),
103 .class_init = ipack_device_class_init,
104 .abstract = true,
107 static const TypeInfo ipack_bus_info = {
108 .name = TYPE_IPACK_BUS,
109 .parent = TYPE_BUS,
110 .instance_size = sizeof(IPackBus),
113 static void ipack_register_types(void)
115 type_register_static(&ipack_device_info);
116 type_register_static(&ipack_bus_info);
119 type_init(ipack_register_types)