1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Copyright (C) 2019 Western Digital Corporation or its affiliates.
4 *
5 * Authors:
6 *     Anup Patel <anup.patel@wdc.com>
7 */
8
9#include <linux/linkage.h>
10#include <asm/asm.h>
11
12	.text
13	.altmacro
14	.option norelax
15
16	/*
17	 * Instruction encoding of hfence.gvma is:
18	 * HFENCE.GVMA rs1, rs2
19	 * HFENCE.GVMA zero, rs2
20	 * HFENCE.GVMA rs1
21	 * HFENCE.GVMA
22	 *
23	 * rs1!=zero and rs2!=zero ==> HFENCE.GVMA rs1, rs2
24	 * rs1==zero and rs2!=zero ==> HFENCE.GVMA zero, rs2
25	 * rs1!=zero and rs2==zero ==> HFENCE.GVMA rs1
26	 * rs1==zero and rs2==zero ==> HFENCE.GVMA
27	 *
28	 * Instruction encoding of HFENCE.GVMA is:
29	 * 0110001 rs2(5) rs1(5) 000 00000 1110011
30	 */
31
32ENTRY(__kvm_riscv_hfence_gvma_vmid_gpa)
33	/*
34	 * rs1 = a0 (GPA >> 2)
35	 * rs2 = a1 (VMID)
36	 * HFENCE.GVMA a0, a1
37	 * 0110001 01011 01010 000 00000 1110011
38	 */
39	.word 0x62b50073
40	ret
41ENDPROC(__kvm_riscv_hfence_gvma_vmid_gpa)
42
43ENTRY(__kvm_riscv_hfence_gvma_vmid)
44	/*
45	 * rs1 = zero
46	 * rs2 = a0 (VMID)
47	 * HFENCE.GVMA zero, a0
48	 * 0110001 01010 00000 000 00000 1110011
49	 */
50	.word 0x62a00073
51	ret
52ENDPROC(__kvm_riscv_hfence_gvma_vmid)
53
54ENTRY(__kvm_riscv_hfence_gvma_gpa)
55	/*
56	 * rs1 = a0 (GPA >> 2)
57	 * rs2 = zero
58	 * HFENCE.GVMA a0
59	 * 0110001 00000 01010 000 00000 1110011
60	 */
61	.word 0x62050073
62	ret
63ENDPROC(__kvm_riscv_hfence_gvma_gpa)
64
65ENTRY(__kvm_riscv_hfence_gvma_all)
66	/*
67	 * rs1 = zero
68	 * rs2 = zero
69	 * HFENCE.GVMA
70	 * 0110001 00000 00000 000 00000 1110011
71	 */
72	.word 0x62000073
73	ret
74ENDPROC(__kvm_riscv_hfence_gvma_all)
75