xref: /openbmc/qemu/hw/i386/xen/xen_apic.c (revision 9884abee)
1 /*
2  * Xen basic APIC support
3  *
4  * Copyright (c) 2012 Citrix
5  *
6  * Authors:
7  *  Wei Liu <wei.liu2@citrix.com>
8  *
9  * This work is licensed under the terms of the GNU GPL version 2 or
10  * later. See the COPYING file in the top-level directory.
11  */
12 #include "qemu/osdep.h"
13 #include "hw/i386/apic_internal.h"
14 #include "hw/pci/msi.h"
15 #include "hw/xen/xen.h"
16 
17 static uint64_t xen_apic_mem_read(void *opaque, hwaddr addr,
18                                   unsigned size)
19 {
20     return ~(uint64_t)0;
21 }
22 
23 static void xen_apic_mem_write(void *opaque, hwaddr addr,
24                                uint64_t data, unsigned size)
25 {
26     if (size != sizeof(uint32_t)) {
27         fprintf(stderr, "Xen: APIC write data size = %d, invalid\n", size);
28         return;
29     }
30 
31     xen_hvm_inject_msi(addr, data);
32 }
33 
34 static const MemoryRegionOps xen_apic_io_ops = {
35     .read = xen_apic_mem_read,
36     .write = xen_apic_mem_write,
37     .endianness = DEVICE_NATIVE_ENDIAN,
38 };
39 
40 static void xen_apic_realize(DeviceState *dev, Error **errp)
41 {
42     APICCommonState *s = APIC_COMMON(dev);
43 
44     s->vapic_control = 0;
45     memory_region_init_io(&s->io_memory, OBJECT(s), &xen_apic_io_ops, s,
46                           "xen-apic-msi", APIC_SPACE_SIZE);
47 
48 #if defined(CONFIG_XEN_CTRL_INTERFACE_VERSION) \
49     && CONFIG_XEN_CTRL_INTERFACE_VERSION >= 420
50     msi_supported = true;
51 #endif
52 }
53 
54 static void xen_apic_set_base(APICCommonState *s, uint64_t val)
55 {
56 }
57 
58 static void xen_apic_set_tpr(APICCommonState *s, uint8_t val)
59 {
60 }
61 
62 static uint8_t xen_apic_get_tpr(APICCommonState *s)
63 {
64     return 0;
65 }
66 
67 static void xen_apic_vapic_base_update(APICCommonState *s)
68 {
69 }
70 
71 static void xen_apic_external_nmi(APICCommonState *s)
72 {
73 }
74 
75 static void xen_apic_class_init(ObjectClass *klass, void *data)
76 {
77     APICCommonClass *k = APIC_COMMON_CLASS(klass);
78 
79     k->realize = xen_apic_realize;
80     k->set_base = xen_apic_set_base;
81     k->set_tpr = xen_apic_set_tpr;
82     k->get_tpr = xen_apic_get_tpr;
83     k->vapic_base_update = xen_apic_vapic_base_update;
84     k->external_nmi = xen_apic_external_nmi;
85 }
86 
87 static const TypeInfo xen_apic_info = {
88     .name = "xen-apic",
89     .parent = TYPE_APIC_COMMON,
90     .instance_size = sizeof(APICCommonState),
91     .class_init = xen_apic_class_init,
92 };
93 
94 static void xen_apic_register_types(void)
95 {
96     type_register_static(&xen_apic_info);
97 }
98 
99 type_init(xen_apic_register_types)
100