NetBSD/sys/arch/sparc64/include/pmap.h
chs f54a093e81 many improvements:
- use struct vm_page_md for attaching pv entries to struct vm_page
 - change pseg_set()'s return value to indicate whether the spare page
   was used as an L2 or L3 PTP.
 - use a pool for pv entries instead of malloc().
 - put PTPs on a list attached to the pmap so we can free them
   more efficiently (by just walking the list) in pmap_destroy().
 - use the new pmap_remove_all() interface to avoid flushing the cache and TLB
   for each pmap_remove() that's done as we are tearing down an address space.
 - in pmap_enter(), handle replacing an existing mapping more efficiently
   than just calling pmap_remove() on it.  also, skip flushing the
   TSB and TLB if there was no previous mapping, since there can't be
   anything we need to flush.  also, preload the TSB if we're pre-setting
   the mod/ref bits.
 - allocate hardware contexts like the MIPS pmap:
   allocate them all sequentially without reuse, then once we run out
   just invalidate all user TLB entries and flush the entire L1 dcache.
 - fix pmap_extract() for the case where the va is not page-aligned and
   nothing is mapped there.
 - fix calculation of TSB size.  it was comparing physmem (which is
   in units of pages) to constants that only make sense if they are
   in units of bytes.
 - avoid sleeping in pmap_enter(), instead let the caller do it.
 - use pmap_kenter_pa() instead of pmap_enter() where appropriate.
 - remove code to handle impossible cases in various functions.
 - tweak asm code to pipeline a little better.
 - remove many unnecessary spls and membars.
 - lots of code cleanup.
 - no doubt other stuff that I've forgotten.

the result of all this is that a fork+exit microbenchmark is 34% faster
and a fork+exec+exit microbenchmark is 28% faster.
2002-09-22 07:19:43 +00:00

204 lines
6.2 KiB
C

/* $NetBSD: pmap.h,v 1.23 2002/09/22 07:19:45 chs Exp $ */
/*-
* Copyright (C) 1995, 1996 Wolfgang Solfrank.
* Copyright (C) 1995, 1996 TooLs GmbH.
* 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by TooLs GmbH.
* 4. The name of TooLs GmbH may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``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 TOOLS GMBH 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.
*/
#ifndef _MACHINE_PMAP_H_
#define _MACHINE_PMAP_H_
#ifndef _LOCORE
#include <machine/pte.h>
#include <sys/queue.h>
#include <uvm/uvm_object.h>
#endif
/*
* This scheme uses 2-level page tables.
*
* While we're still in 32-bit mode we do the following:
*
* offset: 13 bits
* 1st level: 1024 64-bit TTEs in an 8K page for 10 bits
* 2nd level: 512 32-bit pointers in the pmap for 9 bits
* -------
* total: 32 bits
*
* In 64-bit mode the Spitfire and Blackbird CPUs support only
* 44-bit virtual addresses. All addresses between
* 0x0000 07ff ffff ffff and 0xffff f800 0000 0000 are in the
* "VA hole" and trap, so we don't have to track them. However,
* we do need to keep them in mind during PT walking. If they
* ever change the size of the address "hole" we need to rework
* all the page table handling.
*
* offset: 13 bits
* 1st level: 1024 64-bit TTEs in an 8K page for 10 bits
* 2nd level: 1024 64-bit pointers in an 8K page for 10 bits
* 3rd level: 1024 64-bit pointers in the segmap for 10 bits
* -------
* total: 43 bits
*
* Of course, this means for 32-bit spaces we always have a (practically)
* wasted page for the segmap (only one entry used) and half a page wasted
* for the page directory. We still have need of one extra bit 8^(.
*/
#define HOLESHIFT (43)
#define PTSZ (NBPG/8)
#define PDSZ (PTSZ)
#define STSZ (PTSZ)
#define PTSHIFT (13)
#define PDSHIFT (10+PTSHIFT)
#define STSHIFT (10+PDSHIFT)
#define PTMASK (PTSZ-1)
#define PDMASK (PDSZ-1)
#define STMASK (STSZ-1)
#ifndef _LOCORE
/*
* Support for big page sizes. This maps the page size to the
* page bits.
*/
struct page_size_map {
u_int64_t mask;
u_int64_t code;
#ifdef DEBUG
u_int64_t use;
#endif
};
extern struct page_size_map page_size_map[];
/*
* Pmap stuff
*/
#define va_to_seg(v) (int)((((paddr_t)(v))>>STSHIFT)&STMASK)
#define va_to_dir(v) (int)((((paddr_t)(v))>>PDSHIFT)&PDMASK)
#define va_to_pte(v) (int)((((paddr_t)(v))>>PTSHIFT)&PTMASK)
struct pmap {
struct uvm_object pm_obj;
#define pm_lock pm_obj.vmobjlock
#define pm_refs pm_obj.uo_refs
LIST_ENTRY(pmap) pm_list;
int pm_ctx; /* Current context */
/*
* This contains 64-bit pointers to pages that contain
* 1024 64-bit pointers to page tables. All addresses
* are physical.
*
* !!! Only touch this through pseg_get() and pseg_set() !!!
*/
paddr_t pm_physaddr; /* physical address of pm_segs */
int64_t *pm_segs;
};
/*
* This comes from the PROM and is used to map prom entries.
*/
struct prom_map {
u_int64_t vstart;
u_int64_t vsize;
u_int64_t tte;
};
#define PMAP_NC 0x001 /* Set the E bit in the page */
#define PMAP_NVC 0x002 /* Don't enable the virtual cache */
#define PMAP_LITTLE 0x004 /* Map in little endian mode */
/* Large page size hints --
we really should use another param to pmap_enter() */
#define PMAP_8K 0x000
#define PMAP_64K 0x008 /* Use 64K page */
#define PMAP_512K 0x010
#define PMAP_4M 0x018
#define PMAP_SZ_TO_TTE(x) (((x)&0x018)<<58)
/* If these bits are different in va's to the same PA
then there is an aliasing in the d$ */
#define VA_ALIAS_MASK (1 << 14)
typedef struct pmap *pmap_t;
#ifdef _KERNEL
extern struct pmap kernel_pmap_;
#define pmap_kernel() (&kernel_pmap_)
int pmap_count_res __P((struct pmap *));
int pmap_count_wired __P((struct pmap *));
#define pmap_resident_count(pm) pmap_count_res((pm))
#define pmap_wired_count(pm) pmap_count_wired((pm))
#define pmap_phys_address(x) (x)
void pmap_activate_pmap(struct pmap *);
static __inline void
pmap_update(struct pmap *pmap)
{
if (pmap->pm_refs > 0) {
return;
}
pmap->pm_refs = 1;
pmap_activate_pmap(pmap);
}
void pmap_bootstrap __P((u_long kernelstart, u_long kernelend, u_int numctx));
/* make sure all page mappings are modulo 16K to prevent d$ aliasing */
#define PMAP_PREFER(pa, va) (*(va)+=(((*(va))^(pa))&(1<<(PGSHIFT))))
#define PMAP_GROWKERNEL /* turn on pmap_growkernel interface */
#define PMAP_NEED_PROCWR
#define __HAVE_PMAP_PREDESTROY
#define __HAVE_PMAP_ACTIVATE_KERNEL
void pmap_procwr(struct proc *, vaddr_t, size_t);
/* SPARC specific? */
int pmap_dumpsize __P((void));
int pmap_dumpmmu __P((int (*)__P((dev_t, daddr_t, caddr_t, size_t)),
daddr_t));
int pmap_pa_exists __P((paddr_t));
struct proc;
void switchexit __P((struct proc *));
/* SPARC64 specific */
int ctx_alloc __P((struct pmap *));
void ctx_free __P((struct pmap *));
#endif /* _KERNEL */
#endif /* _LOCORE */
#endif /* _MACHINE_PMAP_H_ */