2 * emulate x86 ICC (Interrupt Controller Communications) bus
4 * Copyright (c) 2013 Red Hat, Inc
7 * Igor Mammedov <imammedo@redhat.com>
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.
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.
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/>
22 #include "hw/cpu/icc_bus.h"
23 #include "hw/sysbus.h"
25 /* icc-bridge implementation */
27 static void icc_bus_init(Object
*obj
)
29 BusState
*b
= BUS(obj
);
31 b
->allow_hotplug
= true;
34 static const TypeInfo icc_bus_info
= {
37 .instance_size
= sizeof(ICCBus
),
38 .instance_init
= icc_bus_init
,
42 /* icc-device implementation */
44 static void icc_device_realize(DeviceState
*dev
, Error
**errp
)
46 ICCDevice
*id
= ICC_DEVICE(dev
);
47 ICCDeviceClass
*idc
= ICC_DEVICE_GET_CLASS(id
);
50 if (idc
->init(id
) < 0) {
51 error_setg(errp
, "%s initialization failed.",
52 object_get_typename(OBJECT(dev
)));
57 static void icc_device_class_init(ObjectClass
*oc
, void *data
)
59 DeviceClass
*dc
= DEVICE_CLASS(oc
);
61 dc
->realize
= icc_device_realize
;
62 dc
->bus_type
= TYPE_ICC_BUS
;
65 static const TypeInfo icc_device_info
= {
66 .name
= TYPE_ICC_DEVICE
,
67 .parent
= TYPE_DEVICE
,
69 .instance_size
= sizeof(ICCDevice
),
70 .class_size
= sizeof(ICCDeviceClass
),
71 .class_init
= icc_device_class_init
,
75 /* icc-bridge implementation */
77 typedef struct ICCBridgeState
{
79 SysBusDevice parent_obj
;
83 MemoryRegion apic_container
;
86 #define ICC_BRIGDE(obj) OBJECT_CHECK(ICCBridgeState, (obj), TYPE_ICC_BRIDGE)
88 static void icc_bridge_init(Object
*obj
)
90 ICCBridgeState
*s
= ICC_BRIGDE(obj
);
91 SysBusDevice
*sb
= SYS_BUS_DEVICE(obj
);
93 qbus_create_inplace(&s
->icc_bus
, TYPE_ICC_BUS
, DEVICE(s
), "icc");
95 /* Do not change order of registering regions,
96 * APIC must be first registered region, board maps it by 0 index
98 memory_region_init(&s
->apic_container
, "icc-apic-container",
100 sysbus_init_mmio(sb
, &s
->apic_container
);
101 s
->icc_bus
.apic_address_space
= &s
->apic_container
;
104 static const TypeInfo icc_bridge_info
= {
105 .name
= TYPE_ICC_BRIDGE
,
106 .parent
= TYPE_SYS_BUS_DEVICE
,
107 .instance_init
= icc_bridge_init
,
108 .instance_size
= sizeof(ICCBridgeState
),
112 static void icc_bus_register_types(void)
114 type_register_static(&icc_bus_info
);
115 type_register_static(&icc_device_info
);
116 type_register_static(&icc_bridge_info
);
119 type_init(icc_bus_register_types
)