syncicache.c revision 331722
1178676Ssam/*-
2210111Sbschmidt * Copyright (C) 1995-1997, 1999 Wolfgang Solfrank.
3178676Ssam * Copyright (C) 1995-1997, 1999 TooLs GmbH.
4178676Ssam * All rights reserved.
5198429Srpaulo *
6178676Ssam * Redistribution and use in source and binary forms, with or without
7178676Ssam * modification, are permitted provided that the following conditions
8178676Ssam * are met:
9178676Ssam * 1. Redistributions of source code must retain the above copyright
10178676Ssam *    notice, this list of conditions and the following disclaimer.
11178676Ssam * 2. Redistributions in binary form must reproduce the above copyright
12178676Ssam *    notice, this list of conditions and the following disclaimer in the
13178676Ssam *    documentation and/or other materials provided with the distribution.
14178676Ssam * 3. All advertising materials mentioning features or use of this software
15178676Ssam *    must display the following acknowledgement:
16178676Ssam *	This product includes software developed by TooLs GmbH.
17178676Ssam * 4. The name of TooLs GmbH may not be used to endorse or promote products
18178676Ssam *    derived from this software without specific prior written permission.
19178676Ssam *
20178676Ssam * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
21178676Ssam * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22198429Srpaulo * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23198429Srpaulo * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24198429Srpaulo * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25198429Srpaulo * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26178676Ssam * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27198429Srpaulo * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28198429Srpaulo * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29178676Ssam * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30198429Srpaulo *
31198429Srpaulo * $NetBSD: syncicache.c,v 1.2 1999/05/05 12:36:40 tsubai Exp $
32178676Ssam */
33198429Srpaulo
34198429Srpaulo#include <sys/cdefs.h>
35201209Srpaulo__FBSDID("$FreeBSD: stable/11/sys/powerpc/powerpc/syncicache.c 331722 2018-03-29 02:50:57Z eadler $");
36201209Srpaulo
37201209Srpaulo#include <sys/param.h>
38198429Srpaulo#if	defined(_KERNEL) || defined(_STANDALONE)
39178676Ssam#include <sys/time.h>
40178676Ssam#include <sys/proc.h>
41198429Srpaulo#include <vm/vm.h>
42178676Ssam#endif
43178676Ssam#include <sys/sysctl.h>
44198429Srpaulo
45198429Srpaulo#include <machine/cpu.h>
46198429Srpaulo#include <machine/md_var.h>
47198429Srpaulo
48198429Srpaulovoid
49198429Srpaulo__syncicache(void *from, int len)
50198429Srpaulo{
51198429Srpaulo	register_t l, off;
52198429Srpaulo	char	*p;
53198429Srpaulo
54198429Srpaulo	off = (uintptr_t)from & (cacheline_size - 1);
55198429Srpaulo	l = len += off;
56178676Ssam	p = (char *)from - off;
57178676Ssam
58178676Ssam	do {
59198429Srpaulo		__asm __volatile ("dcbst 0,%0" :: "r"(p));
60198429Srpaulo		p += cacheline_size;
61201209Srpaulo	} while ((l -= cacheline_size) > 0);
62198429Srpaulo	__asm __volatile ("sync");
63201209Srpaulo	p = (char *)from - off;
64198429Srpaulo	do {
65178676Ssam		__asm __volatile ("icbi 0,%0" :: "r"(p));
66198429Srpaulo		p += cacheline_size;
67198429Srpaulo	} while ((len -= cacheline_size) > 0);
68198429Srpaulo	__asm __volatile ("sync; isync");
69198429Srpaulo}
70198429Srpaulo
71198429Srpaulo