drm/panthor: Don't add write fences to the shared BOs
[drm/drm-misc.git] / arch / x86 / xen / apic.c
blobbb0f3f3684461c68b91a62cc5124f841997bdd16
1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/init.h>
3 #include <linux/thread_info.h>
5 #include <asm/x86_init.h>
6 #include <asm/apic.h>
7 #include <asm/io_apic.h>
8 #include <asm/xen/hypercall.h>
10 #include <xen/xen.h>
11 #include <xen/interface/physdev.h>
12 #include "xen-ops.h"
14 static unsigned int xen_io_apic_read(unsigned apic, unsigned reg)
16 struct physdev_apic apic_op;
17 int ret;
19 apic_op.apic_physbase = mpc_ioapic_addr(apic);
20 apic_op.reg = reg;
21 ret = HYPERVISOR_physdev_op(PHYSDEVOP_apic_read, &apic_op);
22 if (!ret)
23 return apic_op.value;
25 /* fallback to return an emulated IO_APIC values */
26 if (reg == 0x1)
27 return 0x00170020;
28 else if (reg == 0x0)
29 return apic << 24;
31 return 0xfd;
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,
45 int ret, cpu;
47 if (reg == APIC_LVR)
48 return 0x14;
49 if (reg != APIC_ID)
50 return 0;
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);
59 if (ret)
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);
69 return;
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)
78 WARN_ON_ONCE(1);
81 static u64 xen_apic_icr_read(void)
83 return 0;
86 static void xen_apic_icr_write(u32 low, u32 id)
88 /* Warn to see if there's any stray references */
89 WARN_ON(1);
92 static int xen_apic_probe_pv(void)
94 if (xen_pv_domain())
95 return 1;
97 return 0;
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;
109 else
110 return BAD_APICID;
113 static struct apic xen_pv_apic __ro_after_init = {
114 .name = "Xen PV",
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 */
120 .disable_esr = 0,
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,
129 #ifdef CONFIG_SMP
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,
135 #endif
136 .read = xen_apic_read,
137 .write = xen_apic_write,
138 .eoi = xen_apic_eoi,
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;