Home | History | Annotate | Line # | Download | only in include
pmap.h revision 1.13
      1  1.13      jtc /*	$NetBSD: pmap.h,v 1.13 1995/03/28 18:19:59 jtc Exp $ */
      2   1.8  deraadt 
      3   1.1  deraadt /*
      4   1.1  deraadt  * Copyright (c) 1992, 1993
      5   1.1  deraadt  *	The Regents of the University of California.  All rights reserved.
      6   1.1  deraadt  *
      7   1.1  deraadt  * This software was developed by the Computer Systems Engineering group
      8   1.1  deraadt  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
      9   1.1  deraadt  * contributed to Berkeley.
     10   1.1  deraadt  *
     11   1.1  deraadt  * All advertising materials mentioning features or use of this software
     12   1.1  deraadt  * must display the following acknowledgement:
     13   1.1  deraadt  *	This product includes software developed by the University of
     14   1.1  deraadt  *	California, Lawrence Berkeley Laboratory.
     15   1.1  deraadt  *
     16   1.1  deraadt  * Redistribution and use in source and binary forms, with or without
     17   1.1  deraadt  * modification, are permitted provided that the following conditions
     18   1.1  deraadt  * are met:
     19   1.1  deraadt  * 1. Redistributions of source code must retain the above copyright
     20   1.1  deraadt  *    notice, this list of conditions and the following disclaimer.
     21   1.1  deraadt  * 2. Redistributions in binary form must reproduce the above copyright
     22   1.1  deraadt  *    notice, this list of conditions and the following disclaimer in the
     23   1.1  deraadt  *    documentation and/or other materials provided with the distribution.
     24   1.1  deraadt  * 3. All advertising materials mentioning features or use of this software
     25   1.1  deraadt  *    must display the following acknowledgement:
     26   1.1  deraadt  *	This product includes software developed by the University of
     27   1.1  deraadt  *	California, Berkeley and its contributors.
     28   1.1  deraadt  * 4. Neither the name of the University nor the names of its contributors
     29   1.1  deraadt  *    may be used to endorse or promote products derived from this software
     30   1.1  deraadt  *    without specific prior written permission.
     31   1.1  deraadt  *
     32   1.1  deraadt  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     33   1.1  deraadt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     34   1.1  deraadt  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     35   1.1  deraadt  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     36   1.1  deraadt  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     37   1.1  deraadt  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     38   1.1  deraadt  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     39   1.1  deraadt  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     40   1.1  deraadt  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     41   1.1  deraadt  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     42   1.1  deraadt  * SUCH DAMAGE.
     43   1.1  deraadt  *
     44   1.1  deraadt  *	@(#)pmap.h	8.1 (Berkeley) 6/11/93
     45   1.1  deraadt  */
     46   1.1  deraadt 
     47   1.1  deraadt #ifndef	_SPARC_PMAP_H_
     48   1.1  deraadt #define _SPARC_PMAP_H_
     49   1.1  deraadt 
     50   1.1  deraadt #include <machine/pte.h>
     51   1.1  deraadt 
     52   1.1  deraadt /*
     53   1.1  deraadt  * Pmap structure.
     54   1.1  deraadt  *
     55   1.1  deraadt  * The pmap structure really comes in two variants, one---a single
     56   1.1  deraadt  * instance---for kernel virtual memory and the other---up to nproc
     57   1.1  deraadt  * instances---for user virtual memory.  Unfortunately, we have to mash
     58   1.1  deraadt  * both into the same structure.  Fortunately, they are almost the same.
     59   1.1  deraadt  *
     60   1.1  deraadt  * The kernel begins at 0xf8000000 and runs to 0xffffffff (although
     61   1.1  deraadt  * some of this is not actually used).  Kernel space, including DVMA
     62   1.1  deraadt  * space (for now?), is mapped identically into all user contexts.
     63   1.1  deraadt  * There is no point in duplicating this mapping in each user process
     64   1.1  deraadt  * so they do not appear in the user structures.
     65   1.1  deraadt  *
     66   1.1  deraadt  * User space begins at 0x00000000 and runs through 0x1fffffff,
     67   1.1  deraadt  * then has a `hole', then resumes at 0xe0000000 and runs until it
     68   1.1  deraadt  * hits the kernel space at 0xf8000000.  This can be mapped
     69   1.1  deraadt  * contiguously by ignorning the top two bits and pretending the
     70   1.1  deraadt  * space goes from 0 to 37ffffff.  Typically the lower range is
     71   1.1  deraadt  * used for text+data and the upper for stack, but the code here
     72   1.1  deraadt  * makes no such distinction.
     73   1.1  deraadt  *
     74   1.1  deraadt  * Since each virtual segment covers 256 kbytes, the user space
     75   1.1  deraadt  * requires 3584 segments, while the kernel (including DVMA) requires
     76   1.1  deraadt  * only 512 segments.
     77   1.1  deraadt  *
     78   1.1  deraadt  * The segment map entry for virtual segment vseg is offset in
     79   1.1  deraadt  * pmap->pm_rsegmap by 0 if pmap is not the kernel pmap, or by
     80   1.1  deraadt  * NUSEG if it is.  We keep a pointer called pmap->pm_segmap
     81   1.1  deraadt  * pre-offset by this value.  pmap->pm_segmap thus contains the
     82   1.1  deraadt  * values to be loaded into the user portion of the hardware segment
     83   1.1  deraadt  * map so as to reach the proper PMEGs within the MMU.  The kernel
     84   1.1  deraadt  * mappings are `set early' and are always valid in every context
     85   1.1  deraadt  * (every change is always propagated immediately).
     86   1.1  deraadt  *
     87   1.1  deraadt  * The PMEGs within the MMU are loaded `on demand'; when a PMEG is
     88   1.1  deraadt  * taken away from context `c', the pmap for context c has its
     89   1.1  deraadt  * corresponding pm_segmap[vseg] entry marked invalid (the MMU segment
     90   1.1  deraadt  * map entry is also made invalid at the same time).  Thus
     91   1.1  deraadt  * pm_segmap[vseg] is the `invalid pmeg' number (127 or 511) whenever
     92   1.1  deraadt  * the corresponding PTEs are not actually in the MMU.  On the other
     93   1.1  deraadt  * hand, pm_pte[vseg] is NULL only if no pages in that virtual segment
     94   1.1  deraadt  * are in core; otherwise it points to a copy of the 32 or 64 PTEs that
     95   1.1  deraadt  * must be loaded in the MMU in order to reach those pages.
     96   1.1  deraadt  * pm_npte[vseg] counts the number of valid pages in each vseg.
     97   1.1  deraadt  *
     98   1.1  deraadt  * XXX performance: faster to count valid bits?
     99   1.1  deraadt  *
    100   1.1  deraadt  * The kernel pmap cannot malloc() PTEs since malloc() will sometimes
    101   1.1  deraadt  * allocate a new virtual segment.  Since kernel mappings are never
    102   1.1  deraadt  * `stolen' out of the the MMU, we just keep all its PTEs there, and
    103   1.1  deraadt  * have no software copies.  Its mmu entries are nonetheless kept on lists
    104   1.1  deraadt  * so that the code that fiddles with mmu lists has something to fiddle.
    105   1.1  deraadt  */
    106   1.1  deraadt #define	NKSEG	((int)((-(unsigned)KERNBASE) / NBPSG))	/* i.e., 512 */
    107   1.1  deraadt #define	NUSEG	(4096 - NKSEG)				/* i.e., 3584 */
    108   1.1  deraadt 
    109   1.1  deraadt /* data appearing in both user and kernel pmaps */
    110   1.5       pk struct pmap {
    111   1.5       pk 	union	ctxinfo *pm_ctx;	/* current context, if any */
    112   1.5       pk 	int	pm_ctxnum;		/* current context's number */
    113   1.1  deraadt #if NCPUS > 1
    114   1.5       pk 	simple_lock_data_t pm_lock;	/* spinlock */
    115   1.1  deraadt #endif
    116   1.5       pk 	int	pm_refcount;		/* just what it says */
    117   1.5       pk 	struct	mmuentry *pm_mmuforw;	/* pmap pmeg chain */
    118   1.5       pk 	struct	mmuentry **pm_mmuback;	/* (two way street) */
    119   1.5       pk 	void	*pm_segstore;
    120   1.5       pk 	pmeg_t	*pm_segmap;		/* points to pm_rsegmap per above */
    121   1.5       pk 	u_char	*pm_npte;		/* points to pm_rnpte */
    122   1.5       pk 	int	**pm_pte;		/* points to pm_rpte */
    123   1.5       pk 	int	pm_gap_start;		/* Starting with this vseg there's */
    124   1.5       pk 	int	pm_gap_end;		/* no valid mapping until here */
    125   1.6  deraadt 	struct pmap_statistics	pm_stats;	/* pmap statistics */
    126   1.1  deraadt };
    127   1.1  deraadt 
    128   1.1  deraadt /* data appearing only in user pmaps */
    129   1.5       pk struct usegmap {
    130   1.5       pk 	pmeg_t	us_segmap[NUSEG];	/* segment map */
    131   1.5       pk 	u_char	us_npte[NUSEG];		/* number of valid PTEs per seg */
    132   1.5       pk 	int	*us_pte[NUSEG];		/* points to PTEs for valid segments */
    133   1.1  deraadt };
    134   1.1  deraadt 
    135   1.1  deraadt /* data appearing only in the kernel pmap */
    136   1.5       pk struct ksegmap {
    137   1.5       pk 	pmeg_t	ks_segmap[NKSEG];	/* segment map */
    138   1.5       pk 	u_char	ks_npte[NKSEG];		/* number of valid PTEs per kseg */
    139   1.5       pk 	int	*ks_pte[NKSEG];		/* always NULL */
    140   1.1  deraadt };
    141   1.1  deraadt 
    142   1.3       pk typedef struct pmap *pmap_t;
    143   1.3       pk 
    144  1.13      jtc #ifdef _KERNEL
    145   1.1  deraadt 
    146   1.1  deraadt #define PMAP_NULL	((pmap_t)0)
    147   1.1  deraadt 
    148   1.5       pk extern struct pmap	kernel_pmap_store;
    149   1.5       pk extern struct ksegmap	kernel_segmap_store;
    150   1.4  deraadt extern pmap_t		kernel_pmap;
    151  1.10  mycroft extern vm_offset_t	vm_first_phys, vm_num_phys;
    152   1.1  deraadt 
    153   1.1  deraadt /*
    154   1.1  deraadt  * Since PTEs also contain type bits, we have to have some way
    155   1.1  deraadt  * to tell pmap_enter `this is an IO page' or `this is not to
    156   1.1  deraadt  * be cached'.  Since physical addresses are always aligned, we
    157   1.1  deraadt  * can do this with the low order bits.
    158   1.1  deraadt  *
    159   1.1  deraadt  * The ordering below is important: PMAP_PGTYPE << PG_TNC must give
    160   1.1  deraadt  * exactly the PG_NC and PG_TYPE bits.
    161   1.1  deraadt  */
    162   1.1  deraadt #define	PMAP_OBIO	1		/* tells pmap_enter to use PG_OBIO */
    163   1.1  deraadt #define	PMAP_VME16	2		/* etc */
    164   1.1  deraadt #define	PMAP_VME32	3		/* etc */
    165   1.1  deraadt #define	PMAP_NC		4		/* tells pmap_enter to set PG_NC */
    166   1.1  deraadt #define	PMAP_TNC	7		/* mask to get PG_TYPE & PG_NC */
    167   1.1  deraadt 
    168  1.12       pk void		pmap_bootstrap __P((int nmmu, int nctx));
    169  1.12       pk int		pmap_count_ptes __P((struct pmap *));
    170   1.9       pk vm_offset_t	pmap_prefer __P((vm_offset_t, vm_offset_t));
    171  1.12       pk int		pmap_pa_exists __P((vm_offset_t));
    172   1.7  deraadt 
    173   1.7  deraadt #define	pmap_resident_count(pmap)	pmap_count_ptes(pmap)
    174  1.10  mycroft #define	managed(pa)	((unsigned)((pa) - vm_first_phys) < vm_num_phys)
    175   1.9       pk 
    176  1.10  mycroft #define PMAP_ACTIVATE(pmap, pcb, iscurproc)
    177  1.10  mycroft #define PMAP_DEACTIVATE(pmap, pcb)
    178  1.10  mycroft #define PMAP_PREFER(pa, va)		pmap_prefer((pa), (va))
    179   1.7  deraadt 
    180  1.13      jtc #endif /* _KERNEL */
    181   1.1  deraadt 
    182   1.1  deraadt #endif /* _SPARC_PMAP_H_ */
    183