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