1139825Simp/*-
277957Sbenno * Copyright (C) 1995-1997, 1999 Wolfgang Solfrank.
377957Sbenno * Copyright (C) 1995-1997, 1999 TooLs GmbH.
477957Sbenno * All rights reserved.
577957Sbenno *
677957Sbenno * Redistribution and use in source and binary forms, with or without
777957Sbenno * modification, are permitted provided that the following conditions
877957Sbenno * are met:
977957Sbenno * 1. Redistributions of source code must retain the above copyright
1077957Sbenno *    notice, this list of conditions and the following disclaimer.
1177957Sbenno * 2. Redistributions in binary form must reproduce the above copyright
1277957Sbenno *    notice, this list of conditions and the following disclaimer in the
1377957Sbenno *    documentation and/or other materials provided with the distribution.
1477957Sbenno * 3. All advertising materials mentioning features or use of this software
1577957Sbenno *    must display the following acknowledgement:
1677957Sbenno *	This product includes software developed by TooLs GmbH.
1777957Sbenno * 4. The name of TooLs GmbH may not be used to endorse or promote products
1877957Sbenno *    derived from this software without specific prior written permission.
1977957Sbenno *
2077957Sbenno * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
2177957Sbenno * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2277957Sbenno * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2377957Sbenno * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2477957Sbenno * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
2577957Sbenno * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
2677957Sbenno * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
2777957Sbenno * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
2877957Sbenno * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
2977957Sbenno * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3077957Sbenno *
3177957Sbenno * $NetBSD: syncicache.c,v 1.2 1999/05/05 12:36:40 tsubai Exp $
3277957Sbenno */
3377957Sbenno
34183319Snwhitehorn#ifndef lint
35183319Snwhitehornstatic const char rcsid[] =
36183319Snwhitehorn  "$FreeBSD$";
37183319Snwhitehorn#endif /* not lint */
3877957Sbenno
3977957Sbenno#include <sys/param.h>
4077957Sbenno#if	defined(_KERNEL) || defined(_STANDALONE)
4177957Sbenno#include <sys/time.h>
4277957Sbenno#include <sys/proc.h>
4377957Sbenno#include <vm/vm.h>
4477957Sbenno#endif
4577957Sbenno#include <sys/sysctl.h>
4677957Sbenno
47183319Snwhitehorn#include <machine/cpu.h>
48170473Smarcel#include <machine/md_var.h>
4977957Sbenno
5077957Sbennovoid
5177957Sbenno__syncicache(void *from, int len)
5277957Sbenno{
53209975Snwhitehorn	register_t l, off;
5477957Sbenno	char	*p;
5577957Sbenno
56209975Snwhitehorn	off = (uintptr_t)from & (cacheline_size - 1);
5777957Sbenno	l = len += off;
5877957Sbenno	p = (char *)from - off;
59183319Snwhitehorn
6077957Sbenno	do {
6177957Sbenno		__asm __volatile ("dcbst 0,%0" :: "r"(p));
62183319Snwhitehorn		p += cacheline_size;
63183319Snwhitehorn	} while ((l -= cacheline_size) > 0);
6477957Sbenno	__asm __volatile ("sync");
6577957Sbenno	p = (char *)from - off;
6677957Sbenno	do {
6777957Sbenno		__asm __volatile ("icbi 0,%0" :: "r"(p));
68183319Snwhitehorn		p += cacheline_size;
69183319Snwhitehorn	} while ((len -= cacheline_size) > 0);
70103606Sgrehan	__asm __volatile ("sync; isync");
7177957Sbenno}
72183319Snwhitehorn
73