From owner-svn-src-projects@FreeBSD.ORG Sat Mar 13 22:30:37 2010 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 79047106566B; Sat, 13 Mar 2010 22:30:37 +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 677B88FC0A; Sat, 13 Mar 2010 22:30:37 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o2DMUbNC052381; Sat, 13 Mar 2010 22:30:37 GMT (envelope-from nwhitehorn@svn.freebsd.org) Received: (from nwhitehorn@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o2DMUb9x052378; Sat, 13 Mar 2010 22:30:37 GMT (envelope-from nwhitehorn@svn.freebsd.org) Message-Id: <201003132230.o2DMUb9x052378@svn.freebsd.org> From: Nathan Whitehorn Date: Sat, 13 Mar 2010 22:30:37 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r205135 - in projects/ppc64/sys: conf powerpc/aim X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 13 Mar 2010 22:30:37 -0000 Author: nwhitehorn Date: Sat Mar 13 22:30:37 2010 New Revision: 205135 URL: http://svn.freebsd.org/changeset/base/205135 Log: Missed a file. Reported by: Andreas Tobler Added: projects/ppc64/sys/powerpc/aim/slb.c Modified: projects/ppc64/sys/conf/files.powerpc64 Modified: projects/ppc64/sys/conf/files.powerpc64 ============================================================================== --- projects/ppc64/sys/conf/files.powerpc64 Sat Mar 13 21:53:48 2010 (r205134) +++ projects/ppc64/sys/conf/files.powerpc64 Sat Mar 13 22:30:37 2010 (r205135) @@ -63,6 +63,7 @@ powerpc/aim/nexus.c optional aim powerpc/aim/ofw_machdep.c optional aim powerpc/aim/ofwmagic.S optional aim powerpc/aim/platform_chrp.c optional aim +powerpc/aim/slb.c optional aim powerpc/aim/swtch64.S optional aim powerpc/aim/trap.c optional aim powerpc/aim/uma_machdep.c optional aim Added: projects/ppc64/sys/powerpc/aim/slb.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/ppc64/sys/powerpc/aim/slb.c Sat Mar 13 22:30:37 2010 (r205135) @@ -0,0 +1,133 @@ +/*- + * Copyright (c) 2010 Nathan Whitehorn + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include + +#include +#include + +#include + +uint64_t +va_to_vsid_noalloc(pmap_t pm, vm_offset_t va) +{ + uint64_t slbe, slbv, i; + + slbe = (uintptr_t)va >> ADDR_SR_SHFT; + slbe = (slbe << SLBE_ESID_SHIFT) | SLBE_VALID; + slbv = 0; + + for (i = 0; i < sizeof(pm->pm_slb)/sizeof(pm->pm_slb[0]); i++) { + if (pm->pm_slb[i].slbe == (slbe | i)) { + slbv = pm->pm_slb[i].slbv; + return ((slbv & SLBV_VSID_MASK) >> SLBV_VSID_SHIFT); + } + } + + /* XXX: Have a long list for processes mapping more than 16 GB */ + + return (0); +} + +uint64_t +va_to_vsid(pmap_t pm, vm_offset_t va) +{ + uint64_t vsid; + + vsid = va_to_vsid_noalloc(pm, va); + + /* + * If there is no vsid for this VA, we need to add a new entry + * to the PMAP's segment table. + */ + + if (vsid == 0) + vsid = allocate_vsid(pm, (uintptr_t)va >> ADDR_SR_SHFT); + + return (vsid); +} + +uintptr_t moea64_get_unique_vsid(void); + +uint64_t +allocate_vsid(pmap_t pm, uint64_t esid) +{ + uint64_t vsid; + + vsid = moea64_get_unique_vsid(); + + /* + * Someone probably wants this soon, and it may be a wired + * SLB mapping, so pre-spill this entry. + */ + slb_spill(pm, esid, vsid); + + return (vsid); +} + +/* Lock entries mapping kernel text and stacks */ + +#define SLB_SPILLABLE(slbe) \ + (((slbe & SLBE_ESID_MASK) < VM_MIN_KERNEL_ADDRESS && \ + (slbe & SLBE_ESID_MASK) > SEGMENT_LENGTH) || \ + (slbe & SLBE_ESID_MASK) > VM_MAX_KERNEL_ADDRESS) + +void +slb_spill(pmap_t pm, uint64_t esid, uint64_t vsid) +{ + uint64_t slbe, slbv; + int i, j; + + slbv = vsid << SLBV_VSID_SHIFT; + slbe = (esid << SLBE_ESID_SHIFT) | SLBE_VALID; + + /* Hunt for a likely candidate */ + + for (i = mftb() % 64, j = 0; j < 64; j++, i = (i+1) % 64) { + if (pm == kernel_pmap && i == USER_SR) + continue; + + if (!(pm->pm_slb[i].slbe & SLBE_VALID) || + SLB_SPILLABLE(pm->pm_slb[i].slbe)) { + pm->pm_slb[i].slbv = slbv; + pm->pm_slb[i].slbe = slbe | i; + + if (pm == kernel_pmap && pmap_bootstrapped) { + /* slbie not required */ + __asm __volatile ("slbmte %0, %1" :: + "r"(kernel_pmap->pm_slb[i].slbv), + "r"(kernel_pmap->pm_slb[i].slbe)); + } + return; + } + } + + panic("SLB spill on ESID %#lx, but no available candidates!\n", esid); +} +