1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/init.h>
3 #include <linux/thread_info.h>
5 #include <asm/x86_init.h>
7 #include <asm/io_apic.h>
8 #include <asm/xen/hypercall.h>
11 #include <xen/interface/physdev.h>
14 static unsigned int xen_io_apic_read(unsigned apic
, unsigned reg
)
16 struct physdev_apic apic_op
;
19 apic_op
.apic_physbase
= mpc_ioapic_addr(apic
);
21 ret
= HYPERVISOR_physdev_op(PHYSDEVOP_apic_read
, &apic_op
);
25 /* fallback to return an emulated IO_APIC values */
34 static u32
xen_get_apic_id(u32 x
)
36 return ((x
)>>24) & 0xFFu
;
39 static u32
xen_apic_read(u32 reg
)
41 struct xen_platform_op op
= {
42 .cmd
= XENPF_get_cpuinfo
,
43 .interface_version
= XENPF_INTERFACE_VERSION
,
52 cpu
= smp_processor_id();
53 if (!xen_initial_domain())
54 return cpu
? cpuid_to_apicid
[cpu
] << 24 : 0;
56 op
.u
.pcpu_info
.xen_cpuid
= cpu
;
58 ret
= HYPERVISOR_platform_op(&op
);
60 op
.u
.pcpu_info
.apic_id
= BAD_APICID
;
62 return op
.u
.pcpu_info
.apic_id
<< 24;
65 static void xen_apic_write(u32 reg
, u32 val
)
67 if (reg
== APIC_LVTPC
) {
68 (void)pmu_apic_update(reg
);
72 /* Warn to see if there's any stray references */
73 WARN(1,"register: %x, value: %x\n", reg
, val
);
76 static void xen_apic_eoi(void)
81 static u64
xen_apic_icr_read(void)
86 static void xen_apic_icr_write(u32 low
, u32 id
)
88 /* Warn to see if there's any stray references */
92 static int xen_apic_probe_pv(void)
100 static int xen_madt_oem_check(char *oem_id
, char *oem_table_id
)
102 return xen_pv_domain();
105 static u32
xen_cpu_present_to_apicid(int cpu
)
107 if (cpu_present(cpu
))
108 return cpu_data(cpu
).topo
.apicid
;
113 static struct apic xen_pv_apic __ro_after_init
= {
115 .probe
= xen_apic_probe_pv
,
116 .acpi_madt_oem_check
= xen_madt_oem_check
,
118 /* .delivery_mode and .dest_mode_logical not used by XENPV */
122 .cpu_present_to_apicid
= xen_cpu_present_to_apicid
,
124 .max_apic_id
= UINT_MAX
,
125 .get_apic_id
= xen_get_apic_id
,
127 .calc_dest_apicid
= apic_flat_calc_apicid
,
130 .send_IPI_mask
= xen_send_IPI_mask
,
131 .send_IPI_mask_allbutself
= xen_send_IPI_mask_allbutself
,
132 .send_IPI_allbutself
= xen_send_IPI_allbutself
,
133 .send_IPI_all
= xen_send_IPI_all
,
134 .send_IPI_self
= xen_send_IPI_self
,
136 .read
= xen_apic_read
,
137 .write
= xen_apic_write
,
140 .icr_read
= xen_apic_icr_read
,
141 .icr_write
= xen_apic_icr_write
,
143 apic_driver(xen_pv_apic
);
145 void __init
xen_init_apic(void)
147 x86_apic_ops
.io_apic_read
= xen_io_apic_read
;