1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (C) 2020 ARM Limited */
3 
4 #include "mte_def.h"
5 
6 #define ENTRY(name) \
7 	.globl name ;\
8 	.p2align 2;\
9 	.type name, @function ;\
10 name:
11 
12 #define ENDPROC(name) \
13 	.size name, .-name ;
14 
15 	.text
16 /*
17  * mte_insert_random_tag: Insert random tag and might be same as the source tag if
18  *			  the source pointer has it.
19  * Input:
20  *		x0 - source pointer with a tag/no-tag
21  * Return:
22  *		x0 - pointer with random tag
23  */
24 ENTRY(mte_insert_random_tag)
25 	irg	x0, x0, xzr
26 	ret
27 ENDPROC(mte_insert_random_tag)
28 
29 /*
30  * mte_insert_new_tag: Insert new tag and different from the source tag if
31  *		       source pointer has it.
32  * Input:
33  *		x0 - source pointer with a tag/no-tag
34  * Return:
35  *		x0 - pointer with random tag
36  */
37 ENTRY(mte_insert_new_tag)
38 	gmi	x1, x0, xzr
39 	irg	x0, x0, x1
40 	ret
41 ENDPROC(mte_insert_new_tag)
42 
43 /*
44  * mte_get_tag_address: Get the tag from given address.
45  * Input:
46  *		x0 - source pointer
47  * Return:
48  *		x0 - pointer with appended tag
49  */
50 ENTRY(mte_get_tag_address)
51 	ldg	x0, [x0]
52 	ret
53 ENDPROC(mte_get_tag_address)
54 
55 /*
56  * mte_set_tag_address_range: Set the tag range from the given address
57  * Input:
58  *		x0 - source pointer with tag data
59  *		x1 - range
60  * Return:
61  *		none
62  */
63 ENTRY(mte_set_tag_address_range)
64 	cbz	x1, 2f
65 1:
66 	stg	x0, [x0, #0x0]
67 	add	x0, x0, #MT_GRANULE_SIZE
68 	sub	x1, x1, #MT_GRANULE_SIZE
69 	cbnz	x1, 1b
70 2:
71 	ret
72 ENDPROC(mte_set_tag_address_range)
73 
74 /*
75  * mt_clear_tag_address_range: Clear the tag range from the given address
76  * Input:
77  *		x0 - source pointer with tag data
78  *		x1 - range
79  * Return:
80  *		none
81  */
82 ENTRY(mte_clear_tag_address_range)
83 	cbz	x1, 2f
84 1:
85 	stzg	x0, [x0, #0x0]
86 	add	x0, x0, #MT_GRANULE_SIZE
87 	sub	x1, x1, #MT_GRANULE_SIZE
88 	cbnz	x1, 1b
89 2:
90 	ret
91 ENDPROC(mte_clear_tag_address_range)
92 
93 /*
94  * mte_enable_pstate_tco: Enable PSTATE.TCO (tag check override) field
95  * Input:
96  *		none
97  * Return:
98  *		none
99  */
100 ENTRY(mte_enable_pstate_tco)
101 	msr	tco, #MT_PSTATE_TCO_EN
102 	ret
103 ENDPROC(mte_enable_pstate_tco)
104 
105 /*
106  * mte_disable_pstate_tco: Disable PSTATE.TCO (tag check override) field
107  * Input:
108  *		none
109  * Return:
110  *		none
111  */
112 ENTRY(mte_disable_pstate_tco)
113 	msr	tco, #MT_PSTATE_TCO_DIS
114 	ret
115 ENDPROC(mte_disable_pstate_tco)
116 
117 /*
118  * mte_get_pstate_tco: Get PSTATE.TCO (tag check override) field
119  * Input:
120  *		none
121  * Return:
122  *		x0
123  */
124 ENTRY(mte_get_pstate_tco)
125 	mrs	x0, tco
126 	ubfx	x0, x0, #MT_PSTATE_TCO_SHIFT, #1
127 	ret
128 ENDPROC(mte_get_pstate_tco)
129