18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci// Copyright (C) 2017 Arm Ltd.
38c2ecf20Sopenharmony_ci#ifndef __ASM_SDEI_H
48c2ecf20Sopenharmony_ci#define __ASM_SDEI_H
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci/* Values for sdei_exit_mode */
78c2ecf20Sopenharmony_ci#define SDEI_EXIT_HVC  0
88c2ecf20Sopenharmony_ci#define SDEI_EXIT_SMC  1
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#define SDEI_STACK_SIZE		IRQ_STACK_SIZE
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#include <linux/linkage.h>
158c2ecf20Sopenharmony_ci#include <linux/preempt.h>
168c2ecf20Sopenharmony_ci#include <linux/types.h>
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci#include <asm/virt.h>
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ciDECLARE_PER_CPU(struct sdei_registered_event *, sdei_active_normal_event);
218c2ecf20Sopenharmony_ciDECLARE_PER_CPU(struct sdei_registered_event *, sdei_active_critical_event);
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ciextern unsigned long sdei_exit_mode;
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci/* Software Delegated Exception entry point from firmware*/
268c2ecf20Sopenharmony_ciasmlinkage void __sdei_asm_handler(unsigned long event_num, unsigned long arg,
278c2ecf20Sopenharmony_ci				   unsigned long pc, unsigned long pstate);
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci/* and its CONFIG_UNMAP_KERNEL_AT_EL0 trampoline */
308c2ecf20Sopenharmony_ciasmlinkage void __sdei_asm_entry_trampoline(unsigned long event_num,
318c2ecf20Sopenharmony_ci						   unsigned long arg,
328c2ecf20Sopenharmony_ci						   unsigned long pc,
338c2ecf20Sopenharmony_ci						   unsigned long pstate);
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci/* Abort a running handler. Context is discarded. */
368c2ecf20Sopenharmony_civoid __sdei_handler_abort(void);
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci/*
398c2ecf20Sopenharmony_ci * The above entry point does the minimum to call C code. This function does
408c2ecf20Sopenharmony_ci * anything else, before calling the driver.
418c2ecf20Sopenharmony_ci */
428c2ecf20Sopenharmony_cistruct sdei_registered_event;
438c2ecf20Sopenharmony_ciasmlinkage unsigned long __sdei_handler(struct pt_regs *regs,
448c2ecf20Sopenharmony_ci					struct sdei_registered_event *arg);
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ciunsigned long sdei_arch_get_entry_point(int conduit);
478c2ecf20Sopenharmony_ci#define sdei_arch_get_entry_point(x)	sdei_arch_get_entry_point(x)
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_cistruct stack_info;
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_cibool _on_sdei_stack(unsigned long sp, struct stack_info *info);
528c2ecf20Sopenharmony_cistatic inline bool on_sdei_stack(unsigned long sp,
538c2ecf20Sopenharmony_ci				struct stack_info *info)
548c2ecf20Sopenharmony_ci{
558c2ecf20Sopenharmony_ci	if (!IS_ENABLED(CONFIG_VMAP_STACK))
568c2ecf20Sopenharmony_ci		return false;
578c2ecf20Sopenharmony_ci	if (!IS_ENABLED(CONFIG_ARM_SDE_INTERFACE))
588c2ecf20Sopenharmony_ci		return false;
598c2ecf20Sopenharmony_ci	if (in_nmi())
608c2ecf20Sopenharmony_ci		return _on_sdei_stack(sp, info);
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci	return false;
638c2ecf20Sopenharmony_ci}
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci#endif /* __ASSEMBLY__ */
668c2ecf20Sopenharmony_ci#endif	/* __ASM_SDEI_H */
67