Skip to content

Commit e188097

Browse files
committed
Merge feature/arm64-hyperv-synthetic-clocks-timers/6.6 into v6.6.36
* commit 'b63263237d73f1e1d76e2c2049e31b607ef78bec': arm64: hyperv: Fix build breakage for non-ARM64 architectures arm64: hyperv: Enable Hyper-V synthetic clocks/timers
2 parents 7b629a6 + b632632 commit e188097

6 files changed

Lines changed: 64 additions & 7 deletions

File tree

arch/arm64/hyperv/mshyperv.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,22 @@
1919

2020
static bool hyperv_initialized;
2121

22-
static int __init hyperv_init(void)
22+
void __init hyperv_early_init(void)
2323
{
2424
struct hv_get_vp_registers_output result;
2525
u32 a, b, c, d;
2626
u64 guest_id;
27-
int ret;
2827

2928
/*
3029
* Allow for a kernel built with CONFIG_HYPERV to be running in
3130
* a non-Hyper-V environment, including on DT instead of ACPI.
3231
* In such cases, do nothing and return success.
3332
*/
3433
if (acpi_disabled)
35-
return 0;
34+
return;
3635

3736
if (strncmp((char *)&acpi_gbl_FADT.hypervisor_id, "MsHyperV", 8))
38-
return 0;
37+
return;
3938

4039
/* Setup the guest ID */
4140
guest_id = hv_generate_guest_id(LINUX_VERSION_CODE);
@@ -63,6 +62,13 @@ static int __init hyperv_init(void)
6362
pr_info("Hyper-V: Host Build %d.%d.%d.%d-%d-%d\n",
6463
b >> 16, b & 0xFFFF, a, d & 0xFFFFFF, c, d >> 24);
6564

65+
hyperv_initialized = true;
66+
}
67+
68+
static int __init hyperv_init(void)
69+
{
70+
int ret;
71+
6672
ret = hv_common_init();
6773
if (ret)
6874
return ret;
@@ -74,7 +80,6 @@ static int __init hyperv_init(void)
7480
return ret;
7581
}
7682

77-
hyperv_initialized = true;
7883
return 0;
7984
}
8085

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef _ASM_ARM64_HYPERV_TIMER_H
3+
#define _ASM_ARM64_HYPERV_TIMER_H
4+
5+
#include <asm/mshyperv.h>
6+
7+
#endif

arch/arm64/include/asm/mshyperv.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@
2121
#include <linux/types.h>
2222
#include <linux/arm-smccc.h>
2323
#include <asm/hyperv-tlfs.h>
24+
#include <clocksource/arm_arch_timer.h>
25+
26+
#if IS_ENABLED(CONFIG_HYPERV)
27+
void __init hyperv_early_init(void);
28+
#else
29+
static inline void hyperv_early_init(void) {};
30+
#endif
2431

2532
extern u64 hv_do_hvc(u64 control, ...);
2633
extern u64 hv_do_hvc_fast_get(u64 control, u64 input1, u64 input2, u64 input3,
@@ -45,6 +52,17 @@ static inline u64 hv_get_register(unsigned int reg)
4552
return hv_get_vpreg(reg);
4653
}
4754

55+
/* Define the interrupt ID used by STIMER0 Direct Mode interrupts. This
56+
* value can't come from ACPI tables because it is needed before the
57+
* Linux ACPI subsystem is initialized.
58+
*/
59+
#define HYPERV_STIMER0_VECTOR 31
60+
61+
static inline u64 hv_get_raw_timer(void)
62+
{
63+
return arch_timer_read_counter();
64+
}
65+
4866
/* SMCCC hypercall parameters */
4967
#define HV_SMCCC_FUNC_NUMBER 1
5068
#define HV_FUNC_ID ARM_SMCCC_CALL_VAL( \

arch/arm64/kernel/setup.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#include <asm/traps.h>
5353
#include <asm/efi.h>
5454
#include <asm/xen/hypervisor.h>
55+
#include <asm/mshyperv.h>
5556
#include <asm/mmu_context.h>
5657

5758
static int num_standard_resources;
@@ -354,6 +355,9 @@ void __init __no_sanitize_address setup_arch(char **cmdline_p)
354355
if (acpi_disabled)
355356
unflatten_device_tree();
356357

358+
/* Do after acpi_boot_table_init() so local FADT is available */
359+
hyperv_early_init();
360+
357361
bootmem_init();
358362

359363
kasan_init();

drivers/clocksource/hyperv_timer.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,11 @@ static __always_inline u64 read_hv_clock_msr(void)
376376
* noinstr. Notable; while HV_REGISTER_TIME_REF_COUNT is a synthetic
377377
* register it doesn't need the GHCB path.
378378
*/
379+
#ifdef CONFIG_ARM64
380+
return hv_get_register(HV_REGISTER_TIME_REF_COUNT);
381+
#else
379382
return hv_raw_get_register(HV_REGISTER_TIME_REF_COUNT);
383+
#endif
380384
}
381385

382386
/*
@@ -390,7 +394,12 @@ static __always_inline u64 read_hv_clock_msr(void)
390394
static union {
391395
struct ms_hyperv_tsc_page page;
392396
u8 reserved[PAGE_SIZE];
393-
} tsc_pg __bss_decrypted __aligned(PAGE_SIZE);
397+
} tsc_pg
398+
#ifdef CONFIG_ARM64
399+
__aligned(PAGE_SIZE);
400+
#else
401+
__bss_decrypted __aligned(PAGE_SIZE);
402+
#endif
394403

395404
static struct ms_hyperv_tsc_page *tsc_page = &tsc_pg.page;
396405
static unsigned long tsc_pfn;
@@ -612,3 +621,17 @@ void __init hv_remap_tsc_clocksource(void)
612621
if (!tsc_page)
613622
pr_err("Failed to remap Hyper-V TSC page.\n");
614623
}
624+
625+
/* Initialize everything on ARM64 */
626+
static int __init hyperv_timer_init(struct acpi_table_header *table)
627+
{
628+
if (!hv_is_hyperv_initialized())
629+
return -EINVAL;
630+
631+
hv_init_clocksource();
632+
if (hv_stimer_alloc(true))
633+
return -EINVAL;
634+
635+
return 0;
636+
}
637+
TIMER_ACPI_DECLARE(hyperv, ACPI_SIG_GTDT, hyperv_timer_init);

drivers/hv/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ config HYPERV_VTL_MODE
3939
If unsure, say N
4040

4141
config HYPERV_TIMER
42-
def_bool HYPERV && X86
42+
def_bool HYPERV
4343

4444
config HYPERV_UTILS
4545
tristate "Microsoft Hyper-V Utilities driver"

0 commit comments

Comments
 (0)