From 12810ed37d54b79b36746e528e97cbada53503ee Mon Sep 17 00:00:00 2001 From: matt Date: Tue, 26 Mar 2002 21:20:24 +0000 Subject: [PATCH] Use size_t in prototype (so this will be LP64 clean for PPC64 someday). Calculate len separately for icache & dcache in case each has different cacheline widths. Make the code for both loops the same except for the dcbst/icbi. Deal with sizes >=2GB properly (like that'll happen but ...) --- lib/libc/arch/powerpc/gen/syncicache.c | 19 ++++++++++--------- sys/arch/powerpc/include/cpu.h | 4 ++-- sys/lib/libkern/arch/powerpc/syncicache.c | 19 ++++++++++--------- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/lib/libc/arch/powerpc/gen/syncicache.c b/lib/libc/arch/powerpc/gen/syncicache.c index 569d4c361645..43501132860d 100644 --- a/lib/libc/arch/powerpc/gen/syncicache.c +++ b/lib/libc/arch/powerpc/gen/syncicache.c @@ -1,4 +1,4 @@ -/* $NetBSD: syncicache.c,v 1.8 2002/03/18 05:10:58 dbj Exp $ */ +/* $NetBSD: syncicache.c,v 1.9 2002/03/26 21:20:24 matt Exp $ */ /* * Copyright (C) 1995-1997, 1999 Wolfgang Solfrank. @@ -92,11 +92,11 @@ getcachelinesize(void) #endif void -__syncicache(void *from, int len) +__syncicache(void *from, size_t len) { - int l, off; + size_t l, off; + size_t linesz; char *p; - int linesz; #if !defined(_KERNEL) && !defined(_STANDALONE) if (!_cachelinesize) @@ -105,24 +105,25 @@ __syncicache(void *from, int len) if (CACHEINFO.dcache_size > 0) { linesz = CACHEINFO.dcache_line_size; - off = (u_int)from & (linesz - 1); - l = len += off; + off = (uintptr_t)from & (linesz - 1); + l = (len + off + linesz - 1) & ~(linesz - 1); p = (char *)from - off; do { __asm__ __volatile ("dcbst 0,%0" :: "r"(p)); p += linesz; - } while ((l -= linesz) > 0); + } while ((l -= linesz) != 0); } __asm__ __volatile ("sync"); if (CACHEINFO.icache_size > 0 ) { linesz = CACHEINFO.icache_line_size; - off = (u_int)from & (linesz - 1); + off = (uintptr_t)from & (linesz - 1); + l = (len + off + linesz - 1) & ~(linesz - 1); p = (char *)from - off; do { __asm__ __volatile ("icbi 0,%0" :: "r"(p)); p += linesz; - } while ((len -= linesz) > 0); + } while ((l -= linesz) != 0); } __asm__ __volatile ("isync"); } diff --git a/sys/arch/powerpc/include/cpu.h b/sys/arch/powerpc/include/cpu.h index 4dc6eecdc3ae..3b4ee28e5a15 100644 --- a/sys/arch/powerpc/include/cpu.h +++ b/sys/arch/powerpc/include/cpu.h @@ -1,4 +1,4 @@ -/* $NetBSD: cpu.h,v 1.14 2002/03/13 00:38:13 eeh Exp $ */ +/* $NetBSD: cpu.h,v 1.15 2002/03/26 21:20:24 matt Exp $ */ /* * Copyright (C) 1999 Wolfgang Solfrank. @@ -184,7 +184,7 @@ extern void icache_flush(vaddr_t, vsize_t); #endif #endif -void __syncicache(void *, int); +void __syncicache(void *, size_t); /* diff --git a/sys/lib/libkern/arch/powerpc/syncicache.c b/sys/lib/libkern/arch/powerpc/syncicache.c index edf8e8704fac..65bb0a8e3aee 100644 --- a/sys/lib/libkern/arch/powerpc/syncicache.c +++ b/sys/lib/libkern/arch/powerpc/syncicache.c @@ -1,4 +1,4 @@ -/* $NetBSD: syncicache.c,v 1.6 2002/03/18 05:10:59 dbj Exp $ */ +/* $NetBSD: syncicache.c,v 1.7 2002/03/26 21:20:24 matt Exp $ */ /* * Copyright (C) 1995-1997, 1999 Wolfgang Solfrank. @@ -92,11 +92,11 @@ getcachelinesize(void) #endif void -__syncicache(void *from, int len) +__syncicache(void *from, size_t len) { - int l, off; + size_t l, off; + size_t linesz; char *p; - int linesz; #if !defined(_KERNEL) && !defined(_STANDALONE) if (!_cachelinesize) @@ -105,24 +105,25 @@ __syncicache(void *from, int len) if (CACHEINFO.dcache_size > 0) { linesz = CACHEINFO.dcache_line_size; - off = (u_int)from & (linesz - 1); - l = len += off; + off = (uintptr_t)from & (linesz - 1); + l = (len + off + linesz - 1) & ~(linesz - 1); p = (char *)from - off; do { __asm__ __volatile ("dcbst 0,%0" :: "r"(p)); p += linesz; - } while ((l -= linesz) > 0); + } while ((l -= linesz) != 0); } __asm__ __volatile ("sync"); if (CACHEINFO.icache_size > 0 ) { linesz = CACHEINFO.icache_line_size; - off = (u_int)from & (linesz - 1); + off = (uintptr_t)from & (linesz - 1); + l = (len + off + linesz - 1) & ~(linesz - 1); p = (char *)from - off; do { __asm__ __volatile ("icbi 0,%0" :: "r"(p)); p += linesz; - } while ((len -= linesz) > 0); + } while ((l -= linesz) != 0); } __asm__ __volatile ("isync"); }