1 // SPDX-License-Identifier: GPL-2.0
4 * Hyper-V specific APIC code.
6 * Copyright (C) 2018, Microsoft, Inc.
8 * Author : K. Y. Srinivasan <kys@microsoft.com>
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License version 2 as published
12 * by the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
17 * NON INFRINGEMENT. See the GNU General Public License for more
22 #include <linux/types.h>
23 #include <linux/version.h>
24 #include <linux/vmalloc.h>
26 #include <linux/clockchips.h>
27 #include <linux/hyperv.h>
28 #include <linux/slab.h>
29 #include <linux/cpuhotplug.h>
30 #include <asm/hypervisor.h>
31 #include <asm/mshyperv.h>
34 #if IS_ENABLED(CONFIG_HYPERV)
36 static u64 hv_apic_icr_read(void)
40 rdmsrl(HV_X64_MSR_ICR, reg_val);
44 static void hv_apic_icr_write(u32 low, u32 id)
48 reg_val = SET_APIC_DEST_FIELD(id);
49 reg_val = reg_val << 32;
52 wrmsrl(HV_X64_MSR_ICR, reg_val);
55 static u32 hv_apic_read(u32 reg)
61 rdmsr(HV_X64_MSR_EOI, reg_val, hi);
64 rdmsr(HV_X64_MSR_TPR, reg_val, hi);
68 return native_apic_mem_read(reg);
72 static void hv_apic_write(u32 reg, u32 val)
76 wrmsr(HV_X64_MSR_EOI, val, 0);
79 wrmsr(HV_X64_MSR_TPR, val, 0);
82 native_apic_mem_write(reg, val);
86 static void hv_apic_eoi_write(u32 reg, u32 val)
88 wrmsr(HV_X64_MSR_EOI, val, 0);
91 void __init hv_apic_init(void)
93 if (ms_hyperv.hints & HV_X64_APIC_ACCESS_RECOMMENDED) {
94 pr_info("Hyper-V: Using MSR based APIC access\n");
95 apic_set_eoi_write(hv_apic_eoi_write);
96 apic->read = hv_apic_read;
97 apic->write = hv_apic_write;
98 apic->icr_write = hv_apic_icr_write;
99 apic->icr_read = hv_apic_icr_read;
103 #endif /* CONFIG_HYPERV */
104 #endif /* CONFIG_X86_64 */