pmap.h revision 1.2
11.2Sdbj/* $ NetBSD: pmap.h,v 1.12 1998/08/22 10:55:34 scw Exp $ */
21.2Sdbj
31.2Sdbj/*
41.2Sdbj * This file was taken from from mvme68k/include/pmap.h and
51.2Sdbj * should probably be re-synced when needed.
61.2Sdbj * Darrin B Jewell <jewell@mit.edu>  Fri Aug 28 03:22:07 1998
71.2Sdbj * original cvs id: NetBSD: pmap.h,v 1.12 1998/08/22 10:55:34 scw Exp
81.2Sdbj */
91.1Sdbj
101.1Sdbj/*
111.1Sdbj * Copyright (c) 1987 Carnegie-Mellon University
121.1Sdbj * Copyright (c) 1991, 1993
131.1Sdbj *	The Regents of the University of California.  All rights reserved.
141.1Sdbj *
151.1Sdbj * This code is derived from software contributed to Berkeley by
161.1Sdbj * the Systems Programming Group of the University of Utah Computer
171.1Sdbj * Science Department.
181.1Sdbj *
191.1Sdbj * Redistribution and use in source and binary forms, with or without
201.1Sdbj * modification, are permitted provided that the following conditions
211.1Sdbj * are met:
221.1Sdbj * 1. Redistributions of source code must retain the above copyright
231.1Sdbj *    notice, this list of conditions and the following disclaimer.
241.1Sdbj * 2. Redistributions in binary form must reproduce the above copyright
251.1Sdbj *    notice, this list of conditions and the following disclaimer in the
261.1Sdbj *    documentation and/or other materials provided with the distribution.
271.1Sdbj * 3. All advertising materials mentioning features or use of this software
281.1Sdbj *    must display the following acknowledgement:
291.1Sdbj *	This product includes software developed by the University of
301.1Sdbj *	California, Berkeley and its contributors.
311.1Sdbj * 4. Neither the name of the University nor the names of its contributors
321.1Sdbj *    may be used to endorse or promote products derived from this software
331.1Sdbj *    without specific prior written permission.
341.1Sdbj *
351.1Sdbj * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
361.1Sdbj * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
371.1Sdbj * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
381.1Sdbj * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
391.1Sdbj * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
401.1Sdbj * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
411.1Sdbj * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
421.1Sdbj * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
431.1Sdbj * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
441.1Sdbj * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
451.1Sdbj * SUCH DAMAGE.
461.1Sdbj *
471.1Sdbj *	@(#)pmap.h	8.1 (Berkeley) 6/10/93
481.1Sdbj */
491.1Sdbj
501.1Sdbj#ifndef	_MACHINE_PMAP_H_
511.1Sdbj#define	_MACHINE_PMAP_H_
521.1Sdbj
531.1Sdbj#include <machine/pte.h>
541.1Sdbj
551.1Sdbj#if defined(M68040) && 0
561.1Sdbj#define HP_SEG_SIZE	(mmutype == MMU_68040 ? 0x40000 : NBSEG)
571.1Sdbj#else
581.1Sdbj#define HP_SEG_SIZE	NBSEG
591.1Sdbj#endif
601.1Sdbj
611.1Sdbj/*
621.1Sdbj * Pmap stuff
631.1Sdbj */
641.1Sdbjstruct pmap {
651.1Sdbj	pt_entry_t		*pm_ptab;	/* KVA of page table */
661.1Sdbj	st_entry_t		*pm_stab;	/* KVA of segment table */
671.1Sdbj	int			pm_stfree;	/* 040: free lev2 blocks */
681.1Sdbj	st_entry_t		*pm_stpa;	/* 040: ST phys addr */
691.1Sdbj	short			pm_sref;	/* segment table ref count */
701.1Sdbj	short			pm_count;	/* pmap reference count */
711.1Sdbj	simple_lock_data_t	pm_lock;	/* lock on pmap */
721.1Sdbj	struct pmap_statistics	pm_stats;	/* pmap statistics */
731.1Sdbj	long			pm_ptpages;	/* more stats: PT pages */
741.1Sdbj};
751.1Sdbj
761.1Sdbjtypedef struct pmap	*pmap_t;
771.1Sdbj
781.1Sdbj/*
791.1Sdbj * On the 040 we keep track of which level 2 blocks are already in use
801.1Sdbj * with the pm_stfree mask.  Bits are arranged from LSB (block 0) to MSB
811.1Sdbj * (block 31).  For convenience, the level 1 table is considered to be
821.1Sdbj * block 0.
831.1Sdbj *
841.1Sdbj * MAX[KU]L2SIZE control how many pages of level 2 descriptors are allowed.
851.1Sdbj * for the kernel and users.  8 implies only the initial "segment table"
861.1Sdbj * page is used.  WARNING: don't change MAXUL2SIZE unless you can allocate
871.1Sdbj * physically contiguous pages for the ST in pmap.c!
881.1Sdbj */
891.1Sdbj#define	MAXKL2SIZE	32
901.1Sdbj#define MAXUL2SIZE	8
911.1Sdbj#define l2tobm(n)	(1 << (n))
921.1Sdbj#define	bmtol2(n)	(ffs(n) - 1)
931.1Sdbj
941.1Sdbj/*
951.1Sdbj * Macros for speed
961.1Sdbj */
971.1Sdbj#define	PMAP_ACTIVATE(pmap, loadhw)					\
981.1Sdbj{									\
991.1Sdbj	if ((loadhw))							\
1001.2Sdbj		loadustp(m68k_btop((paddr_t)(pmap)->pm_stpa));	\
1011.1Sdbj}
1021.1Sdbj
1031.1Sdbj/*
1041.1Sdbj * For each vm_page_t, there is a list of all currently valid virtual
1051.1Sdbj * mappings of that page.  An entry is a pv_entry, the list is pv_table.
1061.1Sdbj */
1071.1Sdbjstruct pv_entry {
1081.1Sdbj	struct pv_entry	*pv_next;	/* next pv_entry */
1091.1Sdbj	struct pmap	*pv_pmap;	/* pmap where mapping lies */
1101.2Sdbj	vaddr_t		pv_va;		/* virtual address for mapping */
1111.1Sdbj	st_entry_t	*pv_ptste;	/* non-zero if VA maps a PT page */
1121.1Sdbj	struct pmap	*pv_ptpmap;	/* if pv_ptste, pmap for PT page */
1131.1Sdbj	int		pv_flags;	/* flags */
1141.1Sdbj};
1151.1Sdbj
1161.1Sdbj#define	PV_CI		0x01	/* header: all entries are cache inhibited */
1171.1Sdbj#define PV_PTPAGE	0x02	/* header: entry maps a page table page */
1181.1Sdbj
1191.1Sdbjstruct pv_page;
1201.1Sdbj
1211.1Sdbjstruct pv_page_info {
1221.1Sdbj	TAILQ_ENTRY(pv_page) pgi_list;
1231.1Sdbj	struct pv_entry *pgi_freelist;
1241.1Sdbj	int pgi_nfree;
1251.1Sdbj};
1261.1Sdbj
1271.1Sdbj/*
1281.1Sdbj * This is basically:
1291.1Sdbj * ((NBPG - sizeof(struct pv_page_info)) / sizeof(struct pv_entry))
1301.1Sdbj */
1311.1Sdbj#define	NPVPPG	170
1321.1Sdbj
1331.1Sdbjstruct pv_page {
1341.1Sdbj	struct pv_page_info pvp_pgi;
1351.1Sdbj	struct pv_entry pvp_pv[NPVPPG];
1361.1Sdbj};
1371.1Sdbj
1381.1Sdbj#ifdef	_KERNEL
1391.1Sdbj
1401.1Sdbjextern struct pmap	kernel_pmap_store;
1411.1Sdbj
1421.1Sdbj#define pmap_kernel()	(&kernel_pmap_store)
1431.1Sdbj#define	active_pmap(pm) \
1441.1Sdbj	((pm) == pmap_kernel() || (pm) == curproc->p_vmspace->vm_map.pmap)
1451.1Sdbj#define	active_user_pmap(pm) \
1461.1Sdbj	(curproc && \
1471.1Sdbj	 (pm) != pmap_kernel() && (pm) == curproc->p_vmspace->vm_map.pmap)
1481.1Sdbj
1491.1Sdbjextern struct pv_entry	*pv_table;	/* array of entries, one per page */
1501.1Sdbj
1511.2Sdbj#ifndef MACHINE_NEW_NONCONTIG
1521.1Sdbj#define pmap_page_index(pa)		atop(pa - vm_first_phys)
1531.1Sdbj#endif
1541.1Sdbj
1551.1Sdbj#define	pmap_resident_count(pmap)	((pmap)->pm_stats.resident_count)
1561.1Sdbj#define	pmap_wired_count(pmap)		((pmap)->pm_stats.wired_count)
1571.1Sdbj
1581.1Sdbjextern pt_entry_t	*Sysmap;
1591.1Sdbjextern char		*vmmap;		/* map for mem, dumps, etc. */
1601.2Sdbj
1611.2Sdbjvaddr_t	pmap_map __P((vaddr_t, paddr_t, paddr_t, int));
1621.2Sdbj
1631.1Sdbj#endif /* _KERNEL */
1641.1Sdbj
1651.1Sdbj#endif /* !_MACHINE_PMAP_H_ */
166