memory: Introduce DEVICE_HOST_ENDIAN for ram device
[qemu/ar7.git] / hw / ipack / ipack.c
blob6021e6d135c1dbc0d3504c8651ed46ac48fe37a8
1 /*
2 * QEMU IndustryPack emulation
4 * Copyright (C) 2012 Igalia, S.L.
5 * Author: Alberto Garcia <berto@igalia.com>
7 * This code is licensed under the GNU GPL v2 or (at your option) any
8 * later version.
9 */
11 #include "qemu/osdep.h"
12 #include "qapi/error.h"
13 #include "hw/ipack/ipack.h"
15 IPackDevice *ipack_device_find(IPackBus *bus, int32_t slot)
17 BusChild *kid;
19 QTAILQ_FOREACH(kid, &BUS(bus)->children, sibling) {
20 DeviceState *qdev = kid->child;
21 IPackDevice *ip = IPACK_DEVICE(qdev);
22 if (ip->slot == slot) {
23 return ip;
26 return NULL;
29 void ipack_bus_new_inplace(IPackBus *bus, size_t bus_size,
30 DeviceState *parent,
31 const char *name, uint8_t n_slots,
32 qemu_irq_handler handler)
34 qbus_create_inplace(bus, bus_size, TYPE_IPACK_BUS, parent, name);
35 bus->n_slots = n_slots;
36 bus->set_irq = handler;
39 static void ipack_device_realize(DeviceState *dev, Error **errp)
41 IPackDevice *idev = IPACK_DEVICE(dev);
42 IPackBus *bus = IPACK_BUS(qdev_get_parent_bus(dev));
43 IPackDeviceClass *k = IPACK_DEVICE_GET_CLASS(dev);
45 if (idev->slot < 0) {
46 idev->slot = bus->free_slot;
48 if (idev->slot >= bus->n_slots) {
49 error_setg(errp, "Only %" PRIu8 " slots available.", bus->n_slots);
50 return;
52 bus->free_slot = idev->slot + 1;
54 idev->irq = qemu_allocate_irqs(bus->set_irq, idev, 2);
56 k->realize(dev, errp);
59 static void ipack_device_unrealize(DeviceState *dev, Error **errp)
61 IPackDevice *idev = IPACK_DEVICE(dev);
62 IPackDeviceClass *k = IPACK_DEVICE_GET_CLASS(dev);
63 Error *err = NULL;
65 if (k->unrealize) {
66 k->unrealize(dev, &err);
67 error_propagate(errp, err);
68 return;
71 qemu_free_irqs(idev->irq, 2);
74 static Property ipack_device_props[] = {
75 DEFINE_PROP_INT32("slot", IPackDevice, slot, -1),
76 DEFINE_PROP_END_OF_LIST()
79 static void ipack_device_class_init(ObjectClass *klass, void *data)
81 DeviceClass *k = DEVICE_CLASS(klass);
83 set_bit(DEVICE_CATEGORY_INPUT, k->categories);
84 k->bus_type = TYPE_IPACK_BUS;
85 k->realize = ipack_device_realize;
86 k->unrealize = ipack_device_unrealize;
87 k->props = ipack_device_props;
90 const VMStateDescription vmstate_ipack_device = {
91 .name = "ipack_device",
92 .version_id = 1,
93 .minimum_version_id = 1,
94 .fields = (VMStateField[]) {
95 VMSTATE_INT32(slot, IPackDevice),
96 VMSTATE_END_OF_LIST()
100 static const TypeInfo ipack_device_info = {
101 .name = TYPE_IPACK_DEVICE,
102 .parent = TYPE_DEVICE,
103 .instance_size = sizeof(IPackDevice),
104 .class_size = sizeof(IPackDeviceClass),
105 .class_init = ipack_device_class_init,
106 .abstract = true,
109 static const TypeInfo ipack_bus_info = {
110 .name = TYPE_IPACK_BUS,
111 .parent = TYPE_BUS,
112 .instance_size = sizeof(IPackBus),
115 static void ipack_register_types(void)
117 type_register_static(&ipack_device_info);
118 type_register_static(&ipack_bus_info);
121 type_init(ipack_register_types)