share/mk/: Fix includes
[man-pages.git] / man2 / cacheflush.2
blobbc38355e646b7567434867d5f60ee5a3d9656c59
1 .\" Written by Ralf Baechle (ralf@waldorf-gmbh.de),
2 .\" Copyright (c) 1994, 1995 Waldorf GMBH
3 .\"
4 .\" SPDX-License-Identifier: GPL-2.0-or-later
5 .\"
6 .TH cacheflush 2 (date) "Linux man-pages (unreleased)"
7 .SH NAME
8 cacheflush \- flush contents of instruction and/or data cache
9 .SH LIBRARY
10 Standard C library
11 .RI ( libc ", " \-lc )
12 .SH SYNOPSIS
13 .nf
14 .B #include <sys/cachectl.h>
16 .BI "int cacheflush(void " addr [. nbytes "], int "nbytes ", int "cache );
17 .fi
19 .IR Note :
20 On some architectures,
21 there is no glibc wrapper for this system call; see NOTES.
22 .SH DESCRIPTION
23 .BR cacheflush ()
24 flushes the contents of the indicated cache(s) for the
25 user addresses in the range
26 .I addr
28 .IR (addr+nbytes\-1) .
29 .I cache
30 may be one of:
31 .TP
32 .B ICACHE
33 Flush the instruction cache.
34 .TP
35 .B DCACHE
36 Write back to memory and invalidate the affected valid cache lines.
37 .TP
38 .B BCACHE
39 Same as
40 .BR (ICACHE|DCACHE) .
41 .SH RETURN VALUE
42 .BR cacheflush ()
43 returns 0 on success.
44 On error, it returns \-1 and sets
45 .I errno
46 to indicate the error.
47 .SH ERRORS
48 .TP
49 .B EFAULT
50 Some or all of the address range
51 .I addr
53 .I (addr+nbytes\-1)
54 is not accessible.
55 .TP
56 .B EINVAL
57 .I cache
58 is not one of
59 .BR ICACHE ,
60 .BR DCACHE ,
62 .B BCACHE
63 (but see BUGS).
64 .SH VERSIONS
65 .BR cacheflush ()
66 should not be used in programs intended to be portable.
67 On Linux, this call first appeared on the MIPS architecture,
68 but nowadays, Linux provides a
69 .BR cacheflush ()
70 system call on some other architectures, but with different arguments.
71 .SS Architecture-specific variants
72 glibc provides a wrapper for this system call,
73 with the prototype shown in SYNOPSIS,
74 for the following architectures:
75 ARC, CSKY, MIPS, and NIOS2.
77 On some other architectures,
78 Linux provides this system call, with different arguments:
79 .TP
80 M68K:
81 .nf
82 .BI "int cacheflush(unsigned long " addr ", int " scope ", int " cache ,
83 .BI "               unsigned long " len );
84 .fi
85 .TP
86 SH:
87 .nf
88 .BI "int cacheflush(unsigned long " addr ", unsigned long " len ", int " op );
89 .fi
90 .TP
91 NDS32:
92 .nf
93 .BI "int cacheflush(unsigned int " start ", unsigned int " end ", int " cache );
94 .fi
96 On the above architectures,
97 glibc does not provide a wrapper for this system call; call it using
98 .BR syscall (2).
99 .SS GCC alternative
100 Unless you need the finer grained control that this system call provides,
101 you probably want to use the GCC built-in function
102 .BR __builtin___clear_cache (),
103 which provides a portable interface
104 across platforms supported by GCC and compatible compilers:
106 .in +4n
108 .BI "void __builtin___clear_cache(void *" begin ", void *" end );
112 On platforms that don't require instruction cache flushes,
113 .BR __builtin___clear_cache ()
114 has no effect.
116 .IR Note :
117 On some GCC-compatible compilers,
118 the prototype for this built-in function uses
119 .I char *
120 instead of
121 .I void *
122 for the parameters.
123 .SH STANDARDS
124 Historically, this system call was available on all MIPS UNIX variants
125 including RISC/os, IRIX, Ultrix, NetBSD, OpenBSD, and FreeBSD
126 (and also on some non-UNIX MIPS operating systems), so that
127 the existence of this call in MIPS operating systems is a de-facto
128 standard.
129 .SH BUGS
130 Linux kernels older than Linux 2.6.11 ignore the
131 .I addr
133 .I nbytes
134 arguments, making this function fairly expensive.
135 Therefore, the whole cache is always flushed.
137 This function always behaves as if
138 .B BCACHE
139 has been passed for the
140 .I cache
141 argument and does not do any error checking on the
142 .I cache
143 argument.