Commit 549030db authored by Gu Yuchen's avatar Gu Yuchen Committed by guzitao
Browse files

sw64: implementing VDSO with generic code

Sunway inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/IB73UR



--------------------------------

The vdso has been changed to a generic code implementation,
adapting to the GENERIC_GETTIMEOFDAY, HAVE_GENERIC_VDSO, and
ARCH_CLOCKSOURCE_INIT options.

Signed-off-by: default avatarGu Yuchen <guyuchen@wxiat.com>
Reviewed-by: default avatarHe Sheng <hesheng@wxiat.com>
Signed-off-by: default avatarGu Zitao <guzitao@wxiat.com>
parent f432f271
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@ config SW64
	select ACPI_REDUCED_HARDWARE_ONLY
	select ACPI_SYSTEM_POWER_STATES_SUPPORT	if ACPI
	select ARCH_ATOMIC
	select ARCH_CLOCKSOURCE_INIT
	select ARCH_HAS_ACPI_TABLE_UPGRADE if ACPI
	select ARCH_HAS_ELF_RANDOMIZE
	select ARCH_HAS_PHYS_TO_DMA
@@ -63,6 +64,7 @@ config SW64
	select DMA_OPS if PCI
	select GENERIC_ARCH_TOPOLOGY
	select GENERIC_CLOCKEVENTS
	select GENERIC_GETTIMEOFDAY if HAVE_GENERIC_VDSO
	select GENERIC_IRQ_LEGACY
	select GENERIC_IRQ_MIGRATION if SMP
	select GENERIC_IRQ_PROBE
@@ -91,6 +93,7 @@ config SW64
	select HAVE_FTRACE_MCOUNT_RECORD
	select HAVE_FUNCTION_GRAPH_TRACER
	select HAVE_FUNCTION_TRACER
	select HAVE_GENERIC_VDSO if MMU && 64BIT
	select HAVE_IDE
	select HAVE_KPROBES
	select HAVE_KPROBES_ON_FTRACE
+4 −0
Original line number Diff line number Diff line
@@ -49,6 +49,10 @@ export LIBS_Y

boot := arch/sw_64/boot

PHONY += vdso_install
vdso_install:
	$(Q)$(MAKE) $(build)=arch/sw64/kernel/vdso $@

#Default target when executing make with no arguments
all: $(boot)/vmlinux.bin.gz

+7 −0
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _ASM_CLOCKSOURCE_H
#define _ASM_CLOCKSOURCE_H

#include <asm/vdso/clocksource.h>

#endif
+8 −0
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef __ASM_VDSOCLOCKSOURCE_H
#define __ASM_VDSOCLOCKSOURCE_H

#define VDSO_ARCH_CLOCKMODES	\
	VDSO_CLOCKMODE_ARCHTIMER

#endif
+105 −0
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef __ASM_VDSO_GETTIMEOFDAY_H
#define __ASM_VDSO_GETTIMEOFDAY_H

#ifndef __ASSEMBLY__

#include <asm/barrier.h>
#include <asm/unistd.h>
#include <asm/csr.h>
#include <uapi/linux/time.h>
#include <asm/hmcall.h>
#include <linux/kernel.h>
#define VDSO_HAS_CLOCK_GETRES	1

static __always_inline
int gettimeofday_fallback(struct __kernel_old_timeval *_tv,
			  struct timezone *_tz)
{
	long retval;
	long error;
	asm volatile(
	"	mov		%2, $16\n"
	"	mov		%3, $17\n"
	"	ldi		$0, %4\n"
	"	sys_call	%5\n"
	"	mov		$0, %0\n"
	"	mov		$19, %1"
	: "=r"(retval), "=r"(error)
	: "r"(_tv), "r"(_tz), "i"(__NR_gettimeofday), "i"(HMC_callsys)
	: "$0", "$16", "$17", "$19");
	if (unlikely(error))
		return -retval;
	else
		return retval;
}

static __always_inline
long clock_gettime_fallback(clockid_t _clkid, struct __kernel_timespec *_ts)
{
	long retval;
	long error;
	asm volatile(
	"	mov		%2, $16\n"
	"	mov		%3, $17\n"
	"	ldi		$0, %4\n"
	"	sys_call	%5\n"
	"	mov		$0, %0\n"
	"	mov		$19, %1"
	: "=r"(retval), "=r"(error)
	: "r"(_clkid), "r"(_ts), "i"(__NR_clock_gettime), "i"(HMC_callsys)
	: "$0", "$16", "$17", "$19");
	if (unlikely(error))
		return -retval;
	else
		return retval;
}

static __always_inline
int clock_getres_fallback(clockid_t _clkid, struct __kernel_timespec *_ts)
{
	long retval;
	long error;
	asm volatile(
	"	mov		%2, $16\n"
	"	mov		%3, $17\n"
	"	ldi		$0, %4\n"
	"	sys_call	%5\n"
	"	mov		$0, %0\n"
	"	mov		$19, %1"
	: "=r"(retval), "=r"(error)
	: "r"(_clkid), "r"(_ts), "i"(__NR_clock_getres), "i"(HMC_callsys)
	: "$0", "$16", "$17", "$19");
	if (unlikely(error))
		return -retval;
	else
		return retval;
}

#if defined(CONFIG_SUBARCH_C3B)
static __always_inline u64 __arch_get_hw_counter(s32 clock_mode,
						 const struct vdso_data *vd)
{
	register unsigned long __r0 __asm__("$0");

	__asm__ __volatile__(
		"sys_call %1" : "=r"(__r0) : "i" (HMC_longtime));

	return __r0;
}
#elif defined(CONFIG_SUBARCH_C4)
static __always_inline u64 __arch_get_hw_counter(s32 clock_mode,
						 const struct vdso_data *vd)
{
	return sw64_read_csr(CSR_SHTCLOCK);
}
#endif

static __always_inline const struct vdso_data *__arch_get_vdso_data(void)
{
	return _vdso_data;
}

#endif /* !__ASSEMBLY__ */

#endif /* __ASM_VDSO_GETTIMEOFDAY_H */
Loading