]> git.proxmox.com Git - mirror_qemu.git/blame - hw/ipack/ipack.c
Include hw/qdev-properties.h less
[mirror_qemu.git] / hw / ipack / ipack.c
CommitLineData
9c16fa79
AG
1/*
2 * QEMU IndustryPack emulation
3 *
4 * Copyright (C) 2012 Igalia, S.L.
b996aed5 5 * Author: Alberto Garcia <berto@igalia.com>
9c16fa79
AG
6 *
7 * This code is licensed under the GNU GPL v2 or (at your option) any
8 * later version.
9 */
10
0430891c 11#include "qemu/osdep.h"
da34e65c 12#include "qapi/error.h"
0b8fa32f 13#include "qemu/module.h"
1f9c4cfd 14#include "hw/ipack/ipack.h"
64552b6b 15#include "hw/irq.h"
a27bd6c7 16#include "hw/qdev-properties.h"
d6454270 17#include "migration/vmstate.h"
9c16fa79
AG
18
19IPackDevice *ipack_device_find(IPackBus *bus, int32_t slot)
20{
21 BusChild *kid;
22
23 QTAILQ_FOREACH(kid, &BUS(bus)->children, sibling) {
24 DeviceState *qdev = kid->child;
25 IPackDevice *ip = IPACK_DEVICE(qdev);
26 if (ip->slot == slot) {
27 return ip;
28 }
29 }
30 return NULL;
31}
32
77cbb28a
AF
33void ipack_bus_new_inplace(IPackBus *bus, size_t bus_size,
34 DeviceState *parent,
9c16fa79
AG
35 const char *name, uint8_t n_slots,
36 qemu_irq_handler handler)
37{
fb17dfe0 38 qbus_create_inplace(bus, bus_size, TYPE_IPACK_BUS, parent, name);
9c16fa79
AG
39 bus->n_slots = n_slots;
40 bus->set_irq = handler;
41}
42
5c570902 43static void ipack_device_realize(DeviceState *dev, Error **errp)
9c16fa79 44{
5c570902
AF
45 IPackDevice *idev = IPACK_DEVICE(dev);
46 IPackBus *bus = IPACK_BUS(qdev_get_parent_bus(dev));
9c16fa79
AG
47 IPackDeviceClass *k = IPACK_DEVICE_GET_CLASS(dev);
48
5c570902
AF
49 if (idev->slot < 0) {
50 idev->slot = bus->free_slot;
9c16fa79 51 }
5c570902
AF
52 if (idev->slot >= bus->n_slots) {
53 error_setg(errp, "Only %" PRIu8 " slots available.", bus->n_slots);
54 return;
9c16fa79 55 }
5c570902 56 bus->free_slot = idev->slot + 1;
9c16fa79 57
5c570902 58 idev->irq = qemu_allocate_irqs(bus->set_irq, idev, 2);
9c16fa79 59
5c570902 60 k->realize(dev, errp);
9c16fa79
AG
61}
62
5c570902 63static void ipack_device_unrealize(DeviceState *dev, Error **errp)
9c16fa79 64{
5c570902 65 IPackDevice *idev = IPACK_DEVICE(dev);
9c16fa79 66 IPackDeviceClass *k = IPACK_DEVICE_GET_CLASS(dev);
5c570902 67 Error *err = NULL;
9c16fa79 68
5c570902
AF
69 if (k->unrealize) {
70 k->unrealize(dev, &err);
71 error_propagate(errp, err);
72 return;
9c16fa79
AG
73 }
74
f173d57a 75 qemu_free_irqs(idev->irq, 2);
9c16fa79
AG
76}
77
78static Property ipack_device_props[] = {
79 DEFINE_PROP_INT32("slot", IPackDevice, slot, -1),
80 DEFINE_PROP_END_OF_LIST()
81};
82
83static void ipack_device_class_init(ObjectClass *klass, void *data)
84{
85 DeviceClass *k = DEVICE_CLASS(klass);
5c570902 86
125ee0ed 87 set_bit(DEVICE_CATEGORY_INPUT, k->categories);
9c16fa79 88 k->bus_type = TYPE_IPACK_BUS;
5c570902
AF
89 k->realize = ipack_device_realize;
90 k->unrealize = ipack_device_unrealize;
9c16fa79
AG
91 k->props = ipack_device_props;
92}
93
94const VMStateDescription vmstate_ipack_device = {
95 .name = "ipack_device",
96 .version_id = 1,
97 .minimum_version_id = 1,
35d08458 98 .fields = (VMStateField[]) {
9c16fa79
AG
99 VMSTATE_INT32(slot, IPackDevice),
100 VMSTATE_END_OF_LIST()
101 }
102};
103
104static const TypeInfo ipack_device_info = {
105 .name = TYPE_IPACK_DEVICE,
106 .parent = TYPE_DEVICE,
107 .instance_size = sizeof(IPackDevice),
108 .class_size = sizeof(IPackDeviceClass),
109 .class_init = ipack_device_class_init,
110 .abstract = true,
111};
112
113static const TypeInfo ipack_bus_info = {
114 .name = TYPE_IPACK_BUS,
115 .parent = TYPE_BUS,
116 .instance_size = sizeof(IPackBus),
117};
118
119static void ipack_register_types(void)
120{
121 type_register_static(&ipack_device_info);
122 type_register_static(&ipack_bus_info);
123}
124
125type_init(ipack_register_types)