From owner-svn-src-all@FreeBSD.ORG Sun Apr 12 03:03:55 2009 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 961421065675; Sun, 12 Apr 2009 03:03:55 +0000 (UTC) (envelope-from nwhitehorn@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 829478FC1E; Sun, 12 Apr 2009 03:03:55 +0000 (UTC) (envelope-from nwhitehorn@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n3C33t1W008786; Sun, 12 Apr 2009 03:03:55 GMT (envelope-from nwhitehorn@svn.freebsd.org) Received: (from nwhitehorn@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n3C33txo008783; Sun, 12 Apr 2009 03:03:55 GMT (envelope-from nwhitehorn@svn.freebsd.org) Message-Id: <200904120303.n3C33txo008783@svn.freebsd.org> From: Nathan Whitehorn Date: Sun, 12 Apr 2009 03:03:55 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r190953 - in head/sys/powerpc: aim include X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 12 Apr 2009 03:03:56 -0000 Author: nwhitehorn Date: Sun Apr 12 03:03:55 2009 New Revision: 190953 URL: http://svn.freebsd.org/changeset/base/190953 Log: Rework the way we get the cacheline size. Instead of having a table of CPUs known to use 128 byte cache lines and defaulting to 32, use the dcbz instruction to measure it. Also make dcbz behave the way you would expect on PPC 970. Modified: head/sys/powerpc/aim/machdep.c head/sys/powerpc/include/hid.h head/sys/powerpc/include/spr.h Modified: head/sys/powerpc/aim/machdep.c ============================================================================== --- head/sys/powerpc/aim/machdep.c Sun Apr 12 03:02:42 2009 (r190952) +++ head/sys/powerpc/aim/machdep.c Sun Apr 12 03:03:55 2009 (r190953) @@ -117,6 +117,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -254,8 +255,8 @@ powerpc_init(u_int startkernel, u_int en size_t trap_offset; void *kmdp; char *env; - int vers; uint32_t msr, scratch; + uint8_t *cache_check; end = 0; kmdp = NULL; @@ -326,37 +327,61 @@ powerpc_init(u_int startkernel, u_int en } /* - * Set cacheline_size based on the CPU model. + * Init KDB */ - vers = mfpvr() >> 16; - switch (vers) { + kdb_init(); + + /* + * PowerPC 970 CPUs have a misfeature requested by Apple that makes + * them pretend they have a 32-byte cacheline. Turn this off + * before we measure the cacheline size. + */ + + switch (mfpvr() >> 16) { case IBM970: case IBM970FX: case IBM970MP: case IBM970GX: - cacheline_size = 128; + scratch = mfspr64upper(SPR_HID5,msr); + scratch &= ~HID5_970_DCBZ_SIZE_HI; + mtspr64(SPR_HID5, scratch, mfspr(SPR_HID5), msr); break; - default: - cacheline_size = 32; } /* - * Init KDB + * Initialize the interrupt tables and figure out our cache line + * size and whether or not we need the 64-bit bridge code. */ - kdb_init(); - /* - * XXX: Initialize the interrupt tables. - * Disable translation in case the vector area - * hasn't been mapped (G5) + * Disable translation in case the vector area hasn't been + * mapped (G5). */ + msr = mfmsr(); mtmsr(msr & ~(PSL_IR | PSL_DR)); isync(); /* + * Measure the cacheline size using dcbz + * + * Use EXC_PGM as a playground. We are about to overwrite it + * anyway, we know it exists, and we know it is cache-aligned. + */ + + cache_check = (void *)EXC_PGM; + + for (cacheline_size = 0; cacheline_size < 0x100; cacheline_size++) + cache_check[cacheline_size] = 0xff; + + __asm __volatile("dcbz %0,0":: "r" (cache_check) : "memory"); + + /* Find the first byte dcbz did not zero to get the cache line size */ + for (cacheline_size = 0; cacheline_size < 0x100 && + cache_check[cacheline_size] == 0; cacheline_size++); + + /* * Figure out whether we need to use the 64 bit PMAP. This works by * executing an instruction that is only legal on 64-bit PPC (mtmsrd), * and setting ppc64 = 0 if that causes a trap. Modified: head/sys/powerpc/include/hid.h ============================================================================== --- head/sys/powerpc/include/hid.h Sun Apr 12 03:02:42 2009 (r190952) +++ head/sys/powerpc/include/hid.h Sun Apr 12 03:03:55 2009 (r190953) @@ -147,4 +147,6 @@ * 7457: XBSEN = Extended BAT Block Size Enable */ +#define HID5_970_DCBZ_SIZE_HI 0x01000000 /* dcbz does a 32-byte store */ + #endif /* _POWERPC_HID_H_ */ Modified: head/sys/powerpc/include/spr.h ============================================================================== --- head/sys/powerpc/include/spr.h Sun Apr 12 03:02:42 2009 (r190952) +++ head/sys/powerpc/include/spr.h Sun Apr 12 03:03:55 2009 (r190953) @@ -391,6 +391,8 @@ #define SPR_SRR3 0x3df /* 4.. Save/Restore Register 3 */ #define SPR_HID0 0x3f0 /* ..8 Hardware Implementation Register 0 */ #define SPR_HID1 0x3f1 /* ..8 Hardware Implementation Register 1 */ +#define SPR_HID4 0x3f4 /* ..8 Hardware Implementation Register 4 */ +#define SPR_HID5 0x3f6 /* ..8 Hardware Implementation Register 5 */ #if defined(AIM) #define SPR_DBSR 0x3f0 /* 4.. Debug Status Register */