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>
16 static unsigned int xen_io_apic_read(unsigned apic, unsigned reg)
18 struct physdev_apic apic_op;
21 apic_op.apic_physbase = mpc_ioapic_addr(apic);
23 ret = HYPERVISOR_physdev_op(PHYSDEVOP_apic_read, &apic_op);
27 /* fallback to return an emulated IO_APIC values */
36 static u32 xen_get_apic_id(u32 x)
38 return ((x)>>24) & 0xFFu;
41 static u32 xen_apic_read(u32 reg)
43 struct xen_platform_op op = {
44 .cmd = XENPF_get_cpuinfo,
45 .interface_version = XENPF_INTERFACE_VERSION,
54 cpu = smp_processor_id();
55 if (!xen_initial_domain())
56 return cpu ? cpuid_to_apicid[cpu] << 24 : 0;
58 op.u.pcpu_info.xen_cpuid = cpu;
60 ret = HYPERVISOR_platform_op(&op);
62 op.u.pcpu_info.apic_id = BAD_APICID;
64 return op.u.pcpu_info.apic_id << 24;
67 static void xen_apic_write(u32 reg, u32 val)
69 if (reg == APIC_LVTPC) {
70 (void)pmu_apic_update(reg);
74 /* Warn to see if there's any stray references */
75 WARN(1,"register: %x, value: %x\n", reg, val);
78 static void xen_apic_eoi(void)
83 static u64 xen_apic_icr_read(void)
88 static void xen_apic_icr_write(u32 low, u32 id)
90 /* Warn to see if there's any stray references */
94 static int xen_apic_probe_pv(void)
102 static int xen_madt_oem_check(char *oem_id, char *oem_table_id)
104 return xen_pv_domain();
107 static u32 xen_cpu_present_to_apicid(int cpu)
109 if (cpu_present(cpu))
110 return cpu_data(cpu).topo.apicid;
115 static struct apic xen_pv_apic __ro_after_init = {
117 .probe = xen_apic_probe_pv,
118 .acpi_madt_oem_check = xen_madt_oem_check,
120 /* .delivery_mode and .dest_mode_logical not used by XENPV */
124 .cpu_present_to_apicid = xen_cpu_present_to_apicid,
126 .max_apic_id = UINT_MAX,
127 .get_apic_id = xen_get_apic_id,
129 .calc_dest_apicid = apic_flat_calc_apicid,
132 .send_IPI_mask = xen_send_IPI_mask,
133 .send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself,
134 .send_IPI_allbutself = xen_send_IPI_allbutself,
135 .send_IPI_all = xen_send_IPI_all,
136 .send_IPI_self = xen_send_IPI_self,
138 .read = xen_apic_read,
139 .write = xen_apic_write,
142 .icr_read = xen_apic_icr_read,
143 .icr_write = xen_apic_icr_write,
145 apic_driver(xen_pv_apic);
147 void __init xen_init_apic(void)
149 x86_apic_ops.io_apic_read = xen_io_apic_read;