]> Git Repo - qemu.git/blame - hw/ipack/ipack.c
hw/intc/arm_gicv3: Fix secure-GIC NS ICC_PMR and ICC_RPR accesses
[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 <[email protected]>
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"
1f9c4cfd 13#include "hw/ipack/ipack.h"
9c16fa79
AG
14
15IPackDevice *ipack_device_find(IPackBus *bus, int32_t slot)
16{
17 BusChild *kid;
18
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;
24 }
25 }
26 return NULL;
27}
28
77cbb28a
AF
29void ipack_bus_new_inplace(IPackBus *bus, size_t bus_size,
30 DeviceState *parent,
9c16fa79
AG
31 const char *name, uint8_t n_slots,
32 qemu_irq_handler handler)
33{
fb17dfe0 34 qbus_create_inplace(bus, bus_size, TYPE_IPACK_BUS, parent, name);
9c16fa79
AG
35 bus->n_slots = n_slots;
36 bus->set_irq = handler;
37}
38
5c570902 39static void ipack_device_realize(DeviceState *dev, Error **errp)
9c16fa79 40{
5c570902
AF
41 IPackDevice *idev = IPACK_DEVICE(dev);
42 IPackBus *bus = IPACK_BUS(qdev_get_parent_bus(dev));
9c16fa79
AG
43 IPackDeviceClass *k = IPACK_DEVICE_GET_CLASS(dev);
44
5c570902
AF
45 if (idev->slot < 0) {
46 idev->slot = bus->free_slot;
9c16fa79 47 }
5c570902
AF
48 if (idev->slot >= bus->n_slots) {
49 error_setg(errp, "Only %" PRIu8 " slots available.", bus->n_slots);
50 return;
9c16fa79 51 }
5c570902 52 bus->free_slot = idev->slot + 1;
9c16fa79 53
5c570902 54 idev->irq = qemu_allocate_irqs(bus->set_irq, idev, 2);
9c16fa79 55
5c570902 56 k->realize(dev, errp);
9c16fa79
AG
57}
58
5c570902 59static void ipack_device_unrealize(DeviceState *dev, Error **errp)
9c16fa79 60{
5c570902 61 IPackDevice *idev = IPACK_DEVICE(dev);
9c16fa79 62 IPackDeviceClass *k = IPACK_DEVICE_GET_CLASS(dev);
5c570902 63 Error *err = NULL;
9c16fa79 64
5c570902
AF
65 if (k->unrealize) {
66 k->unrealize(dev, &err);
67 error_propagate(errp, err);
68 return;
9c16fa79
AG
69 }
70
f173d57a 71 qemu_free_irqs(idev->irq, 2);
9c16fa79
AG
72}
73
74static Property ipack_device_props[] = {
75 DEFINE_PROP_INT32("slot", IPackDevice, slot, -1),
76 DEFINE_PROP_END_OF_LIST()
77};
78
79static void ipack_device_class_init(ObjectClass *klass, void *data)
80{
81 DeviceClass *k = DEVICE_CLASS(klass);
5c570902 82
125ee0ed 83 set_bit(DEVICE_CATEGORY_INPUT, k->categories);
9c16fa79 84 k->bus_type = TYPE_IPACK_BUS;
5c570902
AF
85 k->realize = ipack_device_realize;
86 k->unrealize = ipack_device_unrealize;
9c16fa79
AG
87 k->props = ipack_device_props;
88}
89
90const VMStateDescription vmstate_ipack_device = {
91 .name = "ipack_device",
92 .version_id = 1,
93 .minimum_version_id = 1,
35d08458 94 .fields = (VMStateField[]) {
9c16fa79
AG
95 VMSTATE_INT32(slot, IPackDevice),
96 VMSTATE_END_OF_LIST()
97 }
98};
99
100static 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,
107};
108
109static const TypeInfo ipack_bus_info = {
110 .name = TYPE_IPACK_BUS,
111 .parent = TYPE_BUS,
112 .instance_size = sizeof(IPackBus),
113};
114
115static void ipack_register_types(void)
116{
117 type_register_static(&ipack_device_info);
118 type_register_static(&ipack_bus_info);
119}
120
121type_init(ipack_register_types)
This page took 0.290047 seconds and 4 git commands to generate.