/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Kernel Physical Mapping (kpm) segment driver (segkpm).
*
* This driver delivers along with the hat_kpm* interfaces an alternative
* mechanism for kernel mappings within the 64-bit Solaris operating system,
* which allows the mapping of all physical memory into the kernel address
* space at once. This is feasible in 64 bit kernels, e.g. for Ultrasparc II
* and beyond processors, since the available VA range is much larger than
* possible physical memory. Momentarily all physical memory is supported,
* that is represented by the list of memory segments (memsegs).
*
* Segkpm mappings have also very low overhead and large pages are used
* (when possible) to minimize the TLB and TSB footprint. It is also
* extentable for other than Sparc architectures (e.g. AMD64). Main
* advantage is the avoidance of the TLB-shootdown X-calls, which are
* normally needed when a kernel (global) mapping has to be removed.
*
* First example of a kernel facility that uses the segkpm mapping scheme
* is seg_map, where it is used as an alternative to hat_memload().
* See also hat layer for more information about the hat_kpm* routines.
*/
#include <sys/sysmacros.h>
#include <vm/seg_kmem.h>
/*
* Global kpm controls.
* See also platform and mmu specific controls.
*
* . Set by default on 64bit platforms that have kpm support.
* . Will be disabled from platform layer if not supported.
*
* . Can be useful for critical debugging of kpm clients.
* . Set to zero by default for platforms that support kpm large pages.
* The use of kpm large pages reduces the footprint of kpm meta data
* and has all the other advantages of using large pages (e.g TLB
* miss reduction).
* . Set by default for platforms that don't support kpm large pages or
* where large pages cannot be used for other reasons (e.g. there are
* only few full associative TLB entries available for large pages).
*
* . Set by default.
* . Will be disabled when kpm_enable is zero.
* . Will be disabled when MAXBSIZE != PAGESIZE.
*
*/
int kpm_smallpages = 0;
/*
* Private seg op routines.
*/
static void segkpm_dump(struct seg *);
static void segkpm_badop(void);
static int segkpm_notsup(void);
SEGKPM_BADOP(int), /* dup */
SEGKPM_BADOP(int), /* unmap */
SEGKPM_BADOP(void), /* free */
SEGKPM_BADOP(int), /* faulta */
SEGKPM_BADOP(int), /* setprot */
SEGKPM_BADOP(int), /* checkprot */
SEGKPM_BADOP(int), /* kluster */
SEGKPM_BADOP(int), /* sync */
SEGKPM_BADOP(int), /* lockop */
SEGKPM_BADOP(int), /* getprot */
SEGKPM_BADOP(int), /* gettype */
SEGKPM_BADOP(int), /* getvp */
SEGKPM_BADOP(int), /* advise */
segkpm_dump, /* dump */
SEGKPM_NOTSUP, /* pagelock */
SEGKPM_BADOP(int), /* setpgsz */
SEGKPM_BADOP(int), /* getmemid */
segkpm_capable, /* capable */
seg_inherit_notsup /* inherit */
};
/*
* kpm_pgsz and kpm_pgshft are set by platform layer.
*/
#ifdef SEGKPM_SUPPORT
int
{
ushort_t *p;
int i, j;
/*
* (1) Segkpm virtual addresses are based on physical adresses.
* From this and in opposite to other segment drivers it is
* often required to allocate a page first to be able to
* calculate the final segkpm virtual address.
* (2) Page allocation is done by calling page_create_va(),
* one important input argument is a virtual address (also
* expressed by the "va" in the function name). This function
* is highly optimized to select the right page for an optimal
* processor and platform support (e.g. virtual addressed
* caches (VAC), physical addressed caches, NUMA).
*
* Because of (1) the approach is to generate a faked virtual
* address for calling page_create_va(). In order to exploit
* the abilities of (2), especially to utilize the cache
* hierarchy (3) and to avoid VAC alias conflicts (4) the
* selection has to be done carefully. For each virtual color
* a separate counter is provided (4). The count values are
* used for the utilization of all cache lines (3) and are
* corresponding to the cache bins.
*/
p = skd->skd_va_select =
for (i = 0; i < NCPU; i++)
for (j = 0; j < b->nvcolors; j++, p++)
*p = j;
return (0);
}
/*
* This routine is called via a machine specific fault handling
* routine.
*/
/* ARGSUSED */
{
switch (type) {
case F_INVAL:
case F_SOFTLOCK:
case F_SOFTUNLOCK:
return (0);
default:
return (FC_NOSUPPORT);
}
/*NOTREACHED*/
}
/*
* Create a virtual address that can be used for invocations of
* page_create_va. Goal is to utilize the cache hierarchy (round
* robin bins) and to select the right color for virtual indexed
* caches. It isn't exact since we also increment the bin counter
* when the caller uses VOP_GETPAGE and gets a hit in the page
* cache, but we keep the bins turning for cache distribution
* (see also segkpm_create block comment).
*/
{
int vcolor;
ushort_t *p;
atomic_add_16(p, nvcolors);
return (va);
}
/*
* Unload mapping if the instance has an active kpm mapping.
*/
void
{
return;
}
goto retry;
/*
* Check if segkpm mapping is not unloaded in the meantime
*/
return;
}
}
static void
{
panic("segkpm_badop");
}
#else /* SEGKPM_SUPPORT */
/* segkpm stubs */
/*ARGSUSED*/
/* ARGSUSED */
{
return ((faultcode_t)0);
}
/* ARGSUSED */
/* ARGSUSED */
static void
segkpm_badop() {}
#endif /* SEGKPM_SUPPORT */
static int
{
return (ENOTSUP);
}
/*
* segkpm pages are not dumped, so we just return
*/
/*ARGSUSED*/
static void
{}
/*
* We claim to have no special capabilities.
*/
/*ARGSUSED*/
static int
{
return (0);
}