xref: /csrg-svn/sys/sparc/include/pmap.h (revision 63320)
155123Storek /*
2*63320Sbostic  * Copyright (c) 1992, 1993
3*63320Sbostic  *	The Regents of the University of California.  All rights reserved.
455123Storek  *
555123Storek  * This software was developed by the Computer Systems Engineering group
655123Storek  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
755123Storek  * contributed to Berkeley.
855123Storek  *
955501Sbostic  * All advertising materials mentioning features or use of this software
1055501Sbostic  * must display the following acknowledgement:
1155501Sbostic  *	This product includes software developed by the University of
1259210Storek  *	California, Lawrence Berkeley Laboratory.
1355501Sbostic  *
1455123Storek  * %sccs.include.redist.c%
1555123Storek  *
16*63320Sbostic  *	@(#)pmap.h	8.1 (Berkeley) 06/11/93
1755123Storek  *
1860354Storek  * from: $Header: pmap.h,v 1.11 93/05/25 10:36:09 torek Exp $
1955123Storek  */
2055123Storek 
2155123Storek #ifndef	_SPARC_PMAP_H_
2255123Storek #define _SPARC_PMAP_H_
2355123Storek 
2456538Sbostic #include <machine/pte.h>
2555123Storek 
2655123Storek /*
2755123Storek  * Pmap structure.
2855123Storek  *
2955123Storek  * The pmap structure really comes in two variants, one---a single
3055123Storek  * instance---for kernel virtual memory and the other---up to nproc
3155123Storek  * instances---for user virtual memory.  Unfortunately, we have to mash
3255123Storek  * both into the same structure.  Fortunately, they are almost the same.
3355123Storek  *
3455123Storek  * The kernel begins at 0xf8000000 and runs to 0xffffffff (although
3555123Storek  * some of this is not actually used).  Kernel space, including DVMA
3655123Storek  * space (for now?), is mapped identically into all user contexts.
3755123Storek  * There is no point in duplicating this mapping in each user process
3855123Storek  * so they do not appear in the user structures.
3955123Storek  *
4055123Storek  * User space begins at 0x00000000 and runs through 0x1fffffff,
4155123Storek  * then has a `hole', then resumes at 0xe0000000 and runs until it
4255123Storek  * hits the kernel space at 0xf8000000.  This can be mapped
4355123Storek  * contiguously by ignorning the top two bits and pretending the
4455123Storek  * space goes from 0 to 37ffffff.  Typically the lower range is
4555123Storek  * used for text+data and the upper for stack, but the code here
4655123Storek  * makes no such distinction.
4755123Storek  *
4855123Storek  * Since each virtual segment covers 256 kbytes, the user space
4955123Storek  * requires 3584 segments, while the kernel (including DVMA) requires
5055123Storek  * only 512 segments.
5155123Storek  *
5255123Storek  * The segment map entry for virtual segment vseg is offset in
5355123Storek  * pmap->pm_rsegmap by 0 if pmap is not the kernel pmap, or by
5455123Storek  * NUSEG if it is.  We keep a pointer called pmap->pm_segmap
5555123Storek  * pre-offset by this value.  pmap->pm_segmap thus contains the
5655123Storek  * values to be loaded into the user portion of the hardware segment
5755123Storek  * map so as to reach the proper PMEGs within the MMU.  The kernel
5855123Storek  * mappings are `set early' and are always valid in every context
5955123Storek  * (every change is always propagated immediately).
6055123Storek  *
6155123Storek  * The PMEGs within the MMU are loaded `on demand'; when a PMEG is
6255123Storek  * taken away from context `c', the pmap for context c has its
6355123Storek  * corresponding pm_segmap[vseg] entry marked invalid (the MMU segment
6455123Storek  * map entry is also made invalid at the same time).  Thus
6555123Storek  * pm_segmap[vseg] is the `invalid pmeg' number (127 or 511) whenever
6655123Storek  * the corresponding PTEs are not actually in the MMU.  On the other
6755123Storek  * hand, pm_pte[vseg] is NULL only if no pages in that virtual segment
6855123Storek  * are in core; otherwise it points to a copy of the 32 or 64 PTEs that
6955123Storek  * must be loaded in the MMU in order to reach those pages.
7055123Storek  * pm_npte[vseg] counts the number of valid pages in each vseg.
7155123Storek  *
7255123Storek  * XXX performance: faster to count valid bits?
7355123Storek  *
7455123Storek  * The kernel pmap cannot malloc() PTEs since malloc() will sometimes
7555123Storek  * allocate a new virtual segment.  Since kernel mappings are never
7655123Storek  * `stolen' out of the the MMU, we just keep all its PTEs there, and
7755123Storek  * have no software copies.  Its mmu entries are nonetheless kept on lists
7855123Storek  * so that the code that fiddles with mmu lists has something to fiddle.
7955123Storek  */
8055123Storek #define	NKSEG	((int)((-(unsigned)KERNBASE) / NBPSG))	/* i.e., 512 */
8155123Storek #define	NUSEG	(4096 - NKSEG)				/* i.e., 3584 */
8255123Storek 
8355123Storek /* data appearing in both user and kernel pmaps */
8455123Storek struct pmap_common {
8555123Storek 	union	ctxinfo *pmc_ctx;	/* current context, if any */
8655123Storek 	int	pmc_ctxnum;		/* current context's number */
8755123Storek #if NCPUS > 1
8855123Storek 	simple_lock_data_t pmc_lock;	/* spinlock */
8955123Storek #endif
9055123Storek 	int	pmc_refcount;		/* just what it says */
9155123Storek 	struct	mmuentry *pmc_mmuforw;	/* pmap pmeg chain */
9255123Storek 	struct	mmuentry **pmc_mmuback;	/* (two way street) */
9355123Storek 	pmeg_t	*pmc_segmap;		/* points to pm_rsegmap per above */
9455123Storek 	u_char	*pmc_npte;		/* points to pm_rnpte */
9555123Storek 	int	**pmc_pte;		/* points to pm_rpte */
9655123Storek };
9755123Storek 
9855123Storek /* data appearing only in user pmaps */
9955123Storek struct pmap {
10055123Storek 	struct	pmap_common pmc;
10155123Storek 	pmeg_t	pm_rsegmap[NUSEG];	/* segment map */
10255123Storek 	u_char	pm_rnpte[NUSEG];	/* number of valid PTEs per seg */
10355123Storek 	int	*pm_rpte[NUSEG];	/* points to PTEs for valid segments */
10455123Storek };
10555123Storek 
10655123Storek /* data appearing only in the kernel pmap */
10755123Storek struct kpmap {
10855123Storek 	struct	pmap_common pmc;
10955123Storek 	pmeg_t	pm_rsegmap[NKSEG];	/* segment map */
11055123Storek 	u_char	pm_rnpte[NKSEG];	/* number of valid PTEs per kseg */
11155123Storek 	int	*pm_rpte[NKSEG];	/* always NULL */
11255123Storek };
11355123Storek 
11455123Storek #define	pm_ctx		pmc.pmc_ctx
11555123Storek #define	pm_ctxnum	pmc.pmc_ctxnum
11655123Storek #define	pm_lock		pmc.pmc_lock
11755123Storek #define	pm_refcount	pmc.pmc_refcount
11855123Storek #define	pm_mmuforw	pmc.pmc_mmuforw
11955123Storek #define	pm_mmuback	pmc.pmc_mmuback
12055123Storek #define	pm_segmap	pmc.pmc_segmap
12155123Storek #define	pm_npte		pmc.pmc_npte
12255123Storek #define	pm_pte		pmc.pmc_pte
12355123Storek 
12455123Storek #ifdef KERNEL
12555123Storek 
12655123Storek typedef struct pmap *pmap_t;
12755123Storek #define PMAP_NULL	((pmap_t)0)
12855123Storek 
12955123Storek extern struct kpmap kernel_pmap_store;
13055123Storek #define	kernel_pmap ((struct pmap *)(&kernel_pmap_store))
13155123Storek 
13255123Storek #define PMAP_ACTIVATE(pmap, pcb, iscurproc)
13355123Storek #define PMAP_DEACTIVATE(pmap, pcb)
13455123Storek 
13555123Storek /*
13655123Storek  * Since PTEs also contain type bits, we have to have some way
13755123Storek  * to tell pmap_enter `this is an IO page' or `this is not to
13855123Storek  * be cached'.  Since physical addresses are always aligned, we
13955123Storek  * can do this with the low order bits.
14055123Storek  *
14155123Storek  * The ordering below is important: PMAP_PGTYPE << PG_TNC must give
14255123Storek  * exactly the PG_NC and PG_TYPE bits.
14355123Storek  */
14455123Storek #define	PMAP_OBIO	1		/* tells pmap_enter to use PG_OBIO */
14555123Storek #define	PMAP_VME16	2		/* etc */
14655123Storek #define	PMAP_VME32	3		/* etc */
14755123Storek #define	PMAP_NC		4		/* tells pmap_enter to set PG_NC */
14855123Storek #define	PMAP_TNC	7		/* mask to get PG_TYPE & PG_NC */
14955123Storek 
15060354Storek #endif /* KERNEL */
15155123Storek 
15255123Storek #endif /* _SPARC_PMAP_H_ */
153