summaryrefslogtreecommitdiffstats
path: root/arch/riscv/lib/clear_page.S
blob: d7a256eb53f404feaf8ebc750453968bc5352188 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* SPDX-License-Identifier: GPL-2.0-only */
/*
 * Copyright (c) 2023 Ventana Micro Systems Inc.
 */

#include <linux/linkage.h>
#include <asm/asm.h>
#include <asm/alternative-macros.h>
#include <asm-generic/export.h>
#include <asm/hwcap.h>
#include <asm/insn-def.h>
#include <asm/page.h>

#define CBOZ_ALT(order, old, new)				\
	ALTERNATIVE(old, new, 0,				\
		    ((order) << 16) | RISCV_ISA_EXT_ZICBOZ,	\
		    CONFIG_RISCV_ISA_ZICBOZ)

/* void clear_page(void *page) */
SYM_FUNC_START(clear_page)
	li	a2, PAGE_SIZE

	/*
	 * If Zicboz isn't present, or somehow has a block
	 * size larger than 4K, then fallback to memset.
	 */
	CBOZ_ALT(12, "j .Lno_zicboz", "nop")

	lw	a1, riscv_cboz_block_size
	add	a2, a0, a2
.Lzero_loop:
	CBO_zero(a0)
	add	a0, a0, a1
	CBOZ_ALT(11, "bltu a0, a2, .Lzero_loop; ret", "nop; nop")
	CBO_zero(a0)
	add	a0, a0, a1
	CBOZ_ALT(10, "bltu a0, a2, .Lzero_loop; ret", "nop; nop")
	CBO_zero(a0)
	add	a0, a0, a1
	CBO_zero(a0)
	add	a0, a0, a1
	CBOZ_ALT(9, "bltu a0, a2, .Lzero_loop; ret", "nop; nop")
	CBO_zero(a0)
	add	a0, a0, a1
	CBO_zero(a0)
	add	a0, a0, a1
	CBO_zero(a0)
	add	a0, a0, a1
	CBO_zero(a0)
	add	a0, a0, a1
	CBOZ_ALT(8, "bltu a0, a2, .Lzero_loop; ret", "nop; nop")
	CBO_zero(a0)
	add	a0, a0, a1
	CBO_zero(a0)
	add	a0, a0, a1
	CBO_zero(a0)
	add	a0, a0, a1
	CBO_zero(a0)
	add	a0, a0, a1
	CBO_zero(a0)
	add	a0, a0, a1
	CBO_zero(a0)
	add	a0, a0, a1
	CBO_zero(a0)
	add	a0, a0, a1
	CBO_zero(a0)
	add	a0, a0, a1
	bltu	a0, a2, .Lzero_loop
	ret
.Lno_zicboz:
	li	a1, 0
	tail	__memset
SYM_FUNC_END(clear_page)
EXPORT_SYMBOL(clear_page)