/*-1* SPDX-License-Identifier: BSD-4-Clause2*3* Copyright (C) 1995-1997, 1999 Wolfgang Solfrank.4* Copyright (C) 1995-1997, 1999 TooLs GmbH.5* All rights reserved.6*7* Redistribution and use in source and binary forms, with or without8* modification, are permitted provided that the following conditions9* are met:10* 1. Redistributions of source code must retain the above copyright11* notice, this list of conditions and the following disclaimer.12* 2. Redistributions in binary form must reproduce the above copyright13* notice, this list of conditions and the following disclaimer in the14* documentation and/or other materials provided with the distribution.15* 3. All advertising materials mentioning features or use of this software16* must display the following acknowledgement:17* This product includes software developed by TooLs GmbH.18* 4. The name of TooLs GmbH may not be used to endorse or promote products19* derived from this software without specific prior written permission.20*21* THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR22* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES23* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.24* IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,25* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,26* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;27* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,28* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR29* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF30* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.31*32* $NetBSD: syncicache.c,v 1.2 1999/05/05 12:36:40 tsubai Exp $33*/3435#include <sys/param.h>36#if defined(_KERNEL) || defined(_STANDALONE)37#include <sys/time.h>38#include <sys/proc.h>39#include <vm/vm.h>40#endif41#include <sys/sysctl.h>4243#include <machine/cpu.h>44#include <machine/md_var.h>4546#ifdef _STANDALONE47int cacheline_size = 32;48#endif4950#if !defined(_KERNEL) && !defined(_STANDALONE)51#include <stdlib.h>5253int cacheline_size = 0;5455static void getcachelinesize(void);5657static void58getcachelinesize()59{60static int cachemib[] = { CTL_MACHDEP, CPU_CACHELINE };61int clen;6263clen = sizeof(cacheline_size);6465if (sysctl(cachemib, nitems(cachemib), &cacheline_size, &clen,66NULL, 0) < 0 || !cacheline_size) {67abort();68}69}70#endif7172void73__syncicache(void *from, int len)74{75int l, off;76char *p;7778#if !defined(_KERNEL) && !defined(_STANDALONE)79if (!cacheline_size)80getcachelinesize();81#endif8283off = (u_int)from & (cacheline_size - 1);84l = len += off;85p = (char *)from - off;8687do {88__asm __volatile ("dcbst 0,%0" :: "r"(p));89p += cacheline_size;90} while ((l -= cacheline_size) > 0);91__asm __volatile ("sync");92p = (char *)from - off;93do {94__asm __volatile ("icbi 0,%0" :: "r"(p));95p += cacheline_size;96} while ((len -= cacheline_size) > 0);97__asm __volatile ("sync; isync");98}99100101102