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
13 IPackDevice
*ipack_device_find(IPackBus
*bus
, int32_t slot
)
17 QTAILQ_FOREACH(kid
, &BUS(bus
)->children
, sibling
) {
18 DeviceState
*qdev
= kid
->child
;
19 IPackDevice
*ip
= IPACK_DEVICE(qdev
);
20 if (ip
->slot
== slot
) {
27 void ipack_bus_new_inplace(IPackBus
*bus
, DeviceState
*parent
,
28 const char *name
, uint8_t n_slots
,
29 qemu_irq_handler handler
)
31 qbus_create_inplace(&bus
->qbus
, TYPE_IPACK_BUS
, parent
, name
);
32 bus
->n_slots
= n_slots
;
33 bus
->set_irq
= handler
;
36 static int ipack_device_dev_init(DeviceState
*qdev
)
38 IPackBus
*bus
= IPACK_BUS(qdev_get_parent_bus(qdev
));
39 IPackDevice
*dev
= IPACK_DEVICE(qdev
);
40 IPackDeviceClass
*k
= IPACK_DEVICE_GET_CLASS(dev
);
43 dev
->slot
= bus
->free_slot
;
45 if (dev
->slot
>= bus
->n_slots
) {
48 bus
->free_slot
= dev
->slot
+ 1;
50 dev
->irq
= qemu_allocate_irqs(bus
->set_irq
, dev
, 2);
55 static int ipack_device_dev_exit(DeviceState
*qdev
)
57 IPackDevice
*dev
= IPACK_DEVICE(qdev
);
58 IPackDeviceClass
*k
= IPACK_DEVICE_GET_CLASS(dev
);
64 qemu_free_irqs(dev
->irq
);
69 static Property ipack_device_props
[] = {
70 DEFINE_PROP_INT32("slot", IPackDevice
, slot
, -1),
71 DEFINE_PROP_END_OF_LIST()
74 static void ipack_device_class_init(ObjectClass
*klass
, void *data
)
76 DeviceClass
*k
= DEVICE_CLASS(klass
);
77 k
->bus_type
= TYPE_IPACK_BUS
;
78 k
->init
= ipack_device_dev_init
;
79 k
->exit
= ipack_device_dev_exit
;
80 k
->props
= ipack_device_props
;
83 const VMStateDescription vmstate_ipack_device
= {
84 .name
= "ipack_device",
86 .minimum_version_id
= 1,
87 .minimum_version_id_old
= 1,
88 .fields
= (VMStateField
[]) {
89 VMSTATE_INT32(slot
, IPackDevice
),
94 static const TypeInfo ipack_device_info
= {
95 .name
= TYPE_IPACK_DEVICE
,
96 .parent
= TYPE_DEVICE
,
97 .instance_size
= sizeof(IPackDevice
),
98 .class_size
= sizeof(IPackDeviceClass
),
99 .class_init
= ipack_device_class_init
,
103 static const TypeInfo ipack_bus_info
= {
104 .name
= TYPE_IPACK_BUS
,
106 .instance_size
= sizeof(IPackBus
),
109 static void ipack_register_types(void)
111 type_register_static(&ipack_device_info
);
112 type_register_static(&ipack_bus_info
);
115 type_init(ipack_register_types
)