blob: 7ce9315651518cf88e47d4a08670b9088bfbcfa1 [file] [log] [blame]
Marc Zyngier55c74012012-12-10 16:40:18 +00001/*
2 * Copyright (C) 2012,2013 - ARM Ltd
3 * Author: Marc Zyngier <marc.zyngier@arm.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include <linux/linkage.h>
Marc Zyngier55c74012012-12-10 16:40:18 +000019
Marc Zyngierb81125c2015-01-29 13:52:12 +000020#include <asm/alternative.h>
Mark Rutlandc6d01a92014-11-24 13:59:30 +000021#include <asm/assembler.h>
Marc Zyngierb81125c2015-01-29 13:52:12 +000022#include <asm/cpufeature.h>
Marc Zyngier55c74012012-12-10 16:40:18 +000023
Marc Zyngierb20c9f22014-02-26 18:47:36 +000024/*
Ard Biesheuvela0bf9772016-02-16 13:52:39 +010025 * u64 __kvm_call_hyp(void *hypfn, ...);
Marc Zyngierb20c9f22014-02-26 18:47:36 +000026 *
27 * This is not really a variadic function in the classic C-way and care must
28 * be taken when calling this to ensure parameters are passed in registers
29 * only, since the stack will change between the caller and the callee.
30 *
31 * Call the function with the first argument containing a pointer to the
32 * function you wish to call in Hyp mode, and subsequent arguments will be
33 * passed as x0, x1, and x2 (a maximum of 3 arguments in addition to the
34 * function pointer can be passed). The function being called must be mapped
35 * in Hyp mode (see init_hyp_mode in arch/arm/kvm/arm.c). Return values are
Marc Zyngier1ea66d22015-10-25 15:51:41 +000036 * passed in x0.
Marc Zyngierb20c9f22014-02-26 18:47:36 +000037 *
Geoff Levandad72e592016-04-27 17:47:03 +010038 * A function pointer with a value less than 0xfff has a special meaning,
39 * and is used to implement __hyp_get_vectors in the same way as in
Marc Zyngierb20c9f22014-02-26 18:47:36 +000040 * arch/arm64/kernel/hyp_stub.S.
James Morse00a44cd2016-04-27 17:47:02 +010041 * HVC behaves as a 'bl' call and will clobber lr.
Marc Zyngierb20c9f22014-02-26 18:47:36 +000042 */
Ard Biesheuvela0bf9772016-02-16 13:52:39 +010043ENTRY(__kvm_call_hyp)
James Morse00a44cd2016-04-27 17:47:02 +010044alternative_if_not ARM64_HAS_VIRT_HOST_EXTN
45 str lr, [sp, #-16]!
Marc Zyngier55c74012012-12-10 16:40:18 +000046 hvc #0
James Morse00a44cd2016-04-27 17:47:02 +010047 ldr lr, [sp], #16
Marc Zyngier55c74012012-12-10 16:40:18 +000048 ret
Marc Zyngierb81125c2015-01-29 13:52:12 +000049alternative_else
50 b __vhe_hyp_call
51 nop
James Morse00a44cd2016-04-27 17:47:02 +010052 nop
53 nop
Marc Zyngierb81125c2015-01-29 13:52:12 +000054alternative_endif
Ard Biesheuvela0bf9772016-02-16 13:52:39 +010055ENDPROC(__kvm_call_hyp)