xref: /openbsd-src/sys/arch/macppc/stand/cache.c (revision 103c086e19642966bfe961a5a93373021c22310f)
1 /*	$OpenBSD: cache.c,v 1.3 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 "libsa.h"
39 
40 #define CACHELINESIZE   32                      /* For now              XXX */
41 
42 void
syncicache(void * from,size_t len)43 syncicache(void *from, size_t len)
44 {
45 	size_t	by, i;
46 
47 	by = CACHELINESIZE;
48 	i = 0;
49 	do {
50 		__asm volatile ("dcbst %0,%1" :: "r"(from), "r"(i));
51 		i += by;
52 	} while (i < len);
53 	__asm volatile ("sync");
54 	i = 0;
55 	do {
56 		__asm volatile ("icbi %0,%1" :: "r"(from), "r"(i));
57 		i += by;
58 	} while (i < len);
59 	__asm volatile ("sync; isync");
60 }
61