1 /* $OpenBSD: syncicache.c,v 1.5 2022/10/21 21:26:49 gkoehler Exp $ */
2
3 /*-
4 * SPDX-License-Identifier: BSD-4-Clause
5 *
6 * Copyright (C) 1995-1997, 1999 Wolfgang Solfrank.
7 * Copyright (C) 1995-1997, 1999 TooLs GmbH.
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by TooLs GmbH.
21 * 4. The name of TooLs GmbH may not be used to endorse or promote products
22 * derived from this software without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
30 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
32 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *
35 * $NetBSD: syncicache.c,v 1.2 1999/05/05 12:36:40 tsubai Exp $
36 */
37
38 #include <sys/param.h>
39
40 #include <machine/cpufunc.h>
41
42 void
__syncicache(void * from,size_t len)43 __syncicache(void *from, size_t len)
44 {
45 #if 0
46 size_t by, i;
47
48 by = cacheline_size;
49 i = 0;
50 do {
51 __asm volatile ("dcbst %0,%1" :: "r"(from), "r"(i));
52 i += by;
53 } while (i < len);
54 __asm volatile ("sync");
55 i = 0;
56 do {
57 __asm volatile ("icbi %0,%1" :: "r"(from), "r"(i));
58 i += by;
59 } while (i < len);
60 __asm volatile ("sync; isync");
61 #else
62 sync();
63 __asm volatile ("icbi 0,%0" :: "b"(from));
64 isync();
65 #endif
66 }
67