1*4a5d661aSToomas Soome /*- 2*4a5d661aSToomas Soome * Copyright (C) 1995-1997, 1999 Wolfgang Solfrank. 3*4a5d661aSToomas Soome * Copyright (C) 1995-1997, 1999 TooLs GmbH. 4*4a5d661aSToomas Soome * All rights reserved. 5*4a5d661aSToomas Soome * 6*4a5d661aSToomas Soome * Redistribution and use in source and binary forms, with or without 7*4a5d661aSToomas Soome * modification, are permitted provided that the following conditions 8*4a5d661aSToomas Soome * are met: 9*4a5d661aSToomas Soome * 1. Redistributions of source code must retain the above copyright 10*4a5d661aSToomas Soome * notice, this list of conditions and the following disclaimer. 11*4a5d661aSToomas Soome * 2. Redistributions in binary form must reproduce the above copyright 12*4a5d661aSToomas Soome * notice, this list of conditions and the following disclaimer in the 13*4a5d661aSToomas Soome * documentation and/or other materials provided with the distribution. 14*4a5d661aSToomas Soome * 3. All advertising materials mentioning features or use of this software 15*4a5d661aSToomas Soome * must display the following acknowledgement: 16*4a5d661aSToomas Soome * This product includes software developed by TooLs GmbH. 17*4a5d661aSToomas Soome * 4. The name of TooLs GmbH may not be used to endorse or promote products 18*4a5d661aSToomas Soome * derived from this software without specific prior written permission. 19*4a5d661aSToomas Soome * 20*4a5d661aSToomas Soome * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR 21*4a5d661aSToomas Soome * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22*4a5d661aSToomas Soome * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23*4a5d661aSToomas Soome * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24*4a5d661aSToomas Soome * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25*4a5d661aSToomas Soome * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26*4a5d661aSToomas Soome * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27*4a5d661aSToomas Soome * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28*4a5d661aSToomas Soome * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29*4a5d661aSToomas Soome * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30*4a5d661aSToomas Soome * 31*4a5d661aSToomas Soome * $NetBSD: syncicache.c,v 1.2 1999/05/05 12:36:40 tsubai Exp $ 32*4a5d661aSToomas Soome */ 33*4a5d661aSToomas Soome 34*4a5d661aSToomas Soome #ifndef lint 35*4a5d661aSToomas Soome static const char rcsid[] = 36*4a5d661aSToomas Soome "$FreeBSD$"; 37*4a5d661aSToomas Soome #endif /* not lint */ 38*4a5d661aSToomas Soome 39*4a5d661aSToomas Soome #include <sys/param.h> 40*4a5d661aSToomas Soome #if defined(_KERNEL) || defined(_STANDALONE) 41*4a5d661aSToomas Soome #include <sys/time.h> 42*4a5d661aSToomas Soome #include <sys/proc.h> 43*4a5d661aSToomas Soome #include <vm/vm.h> 44*4a5d661aSToomas Soome #endif 45*4a5d661aSToomas Soome #include <sys/sysctl.h> 46*4a5d661aSToomas Soome 47*4a5d661aSToomas Soome #include <machine/cpu.h> 48*4a5d661aSToomas Soome #include <machine/md_var.h> 49*4a5d661aSToomas Soome 50*4a5d661aSToomas Soome #ifdef _STANDALONE 51*4a5d661aSToomas Soome int cacheline_size = 32; 52*4a5d661aSToomas Soome #endif 53*4a5d661aSToomas Soome 54*4a5d661aSToomas Soome #if !defined(_KERNEL) && !defined(_STANDALONE) 55*4a5d661aSToomas Soome #include <stdlib.h> 56*4a5d661aSToomas Soome 57*4a5d661aSToomas Soome int cacheline_size = 0; 58*4a5d661aSToomas Soome 59*4a5d661aSToomas Soome static void getcachelinesize(void); 60*4a5d661aSToomas Soome 61*4a5d661aSToomas Soome static void 62*4a5d661aSToomas Soome getcachelinesize() 63*4a5d661aSToomas Soome { 64*4a5d661aSToomas Soome static int cachemib[] = { CTL_MACHDEP, CPU_CACHELINE }; 65*4a5d661aSToomas Soome int clen; 66*4a5d661aSToomas Soome 67*4a5d661aSToomas Soome clen = sizeof(cacheline_size); 68*4a5d661aSToomas Soome 69*4a5d661aSToomas Soome if (sysctl(cachemib, sizeof(cachemib) / sizeof(cachemib[0]), 70*4a5d661aSToomas Soome &cacheline_size, &clen, NULL, 0) < 0 || !cacheline_size) { 71*4a5d661aSToomas Soome abort(); 72*4a5d661aSToomas Soome } 73*4a5d661aSToomas Soome } 74*4a5d661aSToomas Soome #endif 75*4a5d661aSToomas Soome 76*4a5d661aSToomas Soome void 77*4a5d661aSToomas Soome __syncicache(void *from, int len) 78*4a5d661aSToomas Soome { 79*4a5d661aSToomas Soome int l, off; 80*4a5d661aSToomas Soome char *p; 81*4a5d661aSToomas Soome 82*4a5d661aSToomas Soome #if !defined(_KERNEL) && !defined(_STANDALONE) 83*4a5d661aSToomas Soome if (!cacheline_size) 84*4a5d661aSToomas Soome getcachelinesize(); 85*4a5d661aSToomas Soome #endif 86*4a5d661aSToomas Soome 87*4a5d661aSToomas Soome off = (u_int)from & (cacheline_size - 1); 88*4a5d661aSToomas Soome l = len += off; 89*4a5d661aSToomas Soome p = (char *)from - off; 90*4a5d661aSToomas Soome 91*4a5d661aSToomas Soome do { 92*4a5d661aSToomas Soome __asm __volatile ("dcbst 0,%0" :: "r"(p)); 93*4a5d661aSToomas Soome p += cacheline_size; 94*4a5d661aSToomas Soome } while ((l -= cacheline_size) > 0); 95*4a5d661aSToomas Soome __asm __volatile ("sync"); 96*4a5d661aSToomas Soome p = (char *)from - off; 97*4a5d661aSToomas Soome do { 98*4a5d661aSToomas Soome __asm __volatile ("icbi 0,%0" :: "r"(p)); 99*4a5d661aSToomas Soome p += cacheline_size; 100*4a5d661aSToomas Soome } while ((len -= cacheline_size) > 0); 101*4a5d661aSToomas Soome __asm __volatile ("sync; isync"); 102*4a5d661aSToomas Soome } 103*4a5d661aSToomas Soome 104