Add qemu 2.4.0
[kvmfornfv.git] / qemu / hw / cpu / icc_bus.c
1 /* icc_bus.c
2  * emulate x86 ICC (Interrupt Controller Communications) bus
3  *
4  * Copyright (c) 2013 Red Hat, Inc
5  *
6  * Authors:
7  *     Igor Mammedov <imammedo@redhat.com>
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, see <http://www.gnu.org/licenses/>
21  */
22 #include "hw/cpu/icc_bus.h"
23 #include "hw/sysbus.h"
24
25 /* icc-bridge implementation */
26
27 static const TypeInfo icc_bus_info = {
28     .name = TYPE_ICC_BUS,
29     .parent = TYPE_BUS,
30     .instance_size = sizeof(ICCBus),
31 };
32
33
34 /* icc-device implementation */
35
36 static void icc_device_realize(DeviceState *dev, Error **errp)
37 {
38     ICCDeviceClass *idc = ICC_DEVICE_GET_CLASS(dev);
39
40     /* convert to QOM */
41     if (idc->realize) {
42         idc->realize(dev, errp);
43     }
44
45 }
46
47 static void icc_device_class_init(ObjectClass *oc, void *data)
48 {
49     DeviceClass *dc = DEVICE_CLASS(oc);
50
51     dc->realize = icc_device_realize;
52     dc->bus_type = TYPE_ICC_BUS;
53 }
54
55 static const TypeInfo icc_device_info = {
56     .name = TYPE_ICC_DEVICE,
57     .parent = TYPE_DEVICE,
58     .abstract = true,
59     .instance_size = sizeof(ICCDevice),
60     .class_size = sizeof(ICCDeviceClass),
61     .class_init = icc_device_class_init,
62 };
63
64
65 /*  icc-bridge implementation */
66
67 typedef struct ICCBridgeState {
68     /*< private >*/
69     SysBusDevice parent_obj;
70     /*< public >*/
71
72     ICCBus icc_bus;
73     MemoryRegion apic_container;
74 } ICCBridgeState;
75
76 #define ICC_BRIDGE(obj) OBJECT_CHECK(ICCBridgeState, (obj), TYPE_ICC_BRIDGE)
77
78 static void icc_bridge_init(Object *obj)
79 {
80     ICCBridgeState *s = ICC_BRIDGE(obj);
81     SysBusDevice *sb = SYS_BUS_DEVICE(obj);
82
83     qbus_create_inplace(&s->icc_bus, sizeof(s->icc_bus), TYPE_ICC_BUS,
84                         DEVICE(s), "icc");
85
86     /* Do not change order of registering regions,
87      * APIC must be first registered region, board maps it by 0 index
88      */
89     memory_region_init(&s->apic_container, obj, "icc-apic-container",
90                        APIC_SPACE_SIZE);
91     sysbus_init_mmio(sb, &s->apic_container);
92     s->icc_bus.apic_address_space = &s->apic_container;
93 }
94
95 static void icc_bridge_class_init(ObjectClass *oc, void *data)
96 {
97     DeviceClass *dc = DEVICE_CLASS(oc);
98
99     set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
100 }
101
102 static const TypeInfo icc_bridge_info = {
103     .name  = TYPE_ICC_BRIDGE,
104     .parent = TYPE_SYS_BUS_DEVICE,
105     .instance_init  = icc_bridge_init,
106     .instance_size  = sizeof(ICCBridgeState),
107     .class_init = icc_bridge_class_init,
108 };
109
110
111 static void icc_bus_register_types(void)
112 {
113     type_register_static(&icc_bus_info);
114     type_register_static(&icc_device_info);
115     type_register_static(&icc_bridge_info);
116 }
117
118 type_init(icc_bus_register_types)