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