pmap.h revision 85142
154359Sroberto/*
254359Sroberto * Copyright (c) 1991 Regents of the University of California.
354359Sroberto * All rights reserved.
454359Sroberto *
554359Sroberto * This code is derived from software contributed to Berkeley by
654359Sroberto * the Systems Programming Group of the University of Utah Computer
754359Sroberto * Science Department and William Jolitz of UUNET Technologies Inc.
854359Sroberto *
954359Sroberto * Redistribution and use in source and binary forms, with or without
1054359Sroberto * modification, are permitted provided that the following conditions
1154359Sroberto * are met:
1254359Sroberto * 1. Redistributions of source code must retain the above copyright
1354359Sroberto *    notice, this list of conditions and the following disclaimer.
1454359Sroberto * 2. Redistributions in binary form must reproduce the above copyright
1554359Sroberto *    notice, this list of conditions and the following disclaimer in the
1654359Sroberto *    documentation and/or other materials provided with the distribution.
1754359Sroberto * 3. All advertising materials mentioning features or use of this software
1854359Sroberto *    must display the following acknowledgement:
1954359Sroberto *	This product includes software developed by the University of
2054359Sroberto *	California, Berkeley and its contributors.
2154359Sroberto * 4. Neither the name of the University nor the names of its contributors
2254359Sroberto *    may be used to endorse or promote products derived from this software
2354359Sroberto *    without specific prior written permission.
2454359Sroberto *
2554359Sroberto * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2654359Sroberto * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2754359Sroberto * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2854359Sroberto * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2954359Sroberto * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3054359Sroberto * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3154359Sroberto * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3254359Sroberto * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3354359Sroberto * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3454359Sroberto * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3554359Sroberto * SUCH DAMAGE.
3654359Sroberto *
3754359Sroberto * Derived from hp300 version by Mike Hibler, this version by William
3854359Sroberto * Jolitz uses a recursive map [a pde points to the page directory] to
3954359Sroberto * map the page tables using the pagetables themselves. This is done to
4054359Sroberto * reduce the impact on kernel virtual memory for lots of sparse address
4154359Sroberto * space, and to reduce the cost of memory to each process.
4254359Sroberto *
4354359Sroberto *	from: hp300: @(#)pmap.h	7.2 (Berkeley) 12/16/90
4454359Sroberto *	from: @(#)pmap.h	7.4 (Berkeley) 5/12/91
4554359Sroberto *	from: i386 pmap.h,v 1.54 1997/11/20 19:30:35 bde Exp
4654359Sroberto * $FreeBSD: head/sys/ia64/include/pmap.h 85142 2001-10-19 09:47:02Z dfr $
4754359Sroberto */
4854359Sroberto
4954359Sroberto#ifndef _MACHINE_PMAP_H_
5054359Sroberto#define	_MACHINE_PMAP_H_
5154359Sroberto
5254359Sroberto#include <sys/queue.h>
5354359Sroberto#include <machine/pte.h>
5454359Sroberto
5554359Sroberto#ifdef _KERNEL
5654359Sroberto
5754359Sroberto#ifndef NKPT
5854359Sroberto#define	NKPT		30	/* initial number of kernel page tables */
5954359Sroberto#endif
6054359Sroberto#define MAXKPT		(PAGE_SIZE/sizeof(vm_offset_t))
6154359Sroberto
6254359Sroberto
6354359Sroberto/*
6454359Sroberto *	Routine:	pmap_kextract
6554359Sroberto *	Function:
6654359Sroberto *		Extract the physical page address associated
6754359Sroberto *		kernel virtual address.
6854359Sroberto */
6954359Srobertostatic __inline vm_offset_t
7054359Srobertopmap_kextract(vm_offset_t va)
7154359Sroberto{
7254359Sroberto	return ia64_tpa(va);
7354359Sroberto}
7454359Sroberto
7554359Sroberto#define	vtophys(va)	pmap_kextract(((vm_offset_t) (va)))
7654359Sroberto
7754359Sroberto#endif /* _KERNEL */
7854359Sroberto
7954359Sroberto/*
8054359Sroberto * Pmap stuff
8154359Sroberto */
8254359Srobertostruct	pv_entry;
8354359Sroberto
8454359Srobertostruct md_page {
8554359Sroberto	int			pv_list_count;
8654359Sroberto	TAILQ_HEAD(,pv_entry)	pv_list;
8754359Sroberto};
8854359Sroberto
8954359Srobertostruct pmap {
9054359Sroberto	TAILQ_HEAD(,pv_entry)	pm_pvlist;	/* list of mappings in pmap */
9154359Sroberto	u_int64_t		pm_rid;		/* base RID for pmap */
9254359Sroberto	int			pm_count;	/* reference count */
9354359Sroberto	int			pm_flags;	/* pmap flags */
9454359Sroberto	int			pm_active;	/* active flag */
9554359Sroberto	struct pmap_statistics	pm_stats;	/* pmap statistics */
9654359Sroberto	struct vm_page		*pm_ptphint;	/* pmap ptp hint */
9754359Sroberto};
9854359Sroberto
9954359Sroberto#define pmap_resident_count(pmap) (pmap)->pm_stats.resident_count
10054359Sroberto
10154359Sroberto#define PM_FLAG_LOCKED	0x1
10254359Sroberto#define PM_FLAG_WANTED	0x2
10354359Sroberto
10454359Srobertotypedef struct pmap	*pmap_t;
10554359Sroberto
10654359Sroberto#ifdef _KERNEL
10754359Srobertoextern pmap_t		kernel_pmap;
10854359Sroberto#endif
10954359Sroberto
11054359Sroberto/*
11154359Sroberto * For each vm_page_t, there is a list of all currently valid virtual
11254359Sroberto * mappings of that page.  An entry is a pv_entry_t, the list is pv_table.
11354359Sroberto */
11454359Srobertotypedef struct pv_entry {
11554359Sroberto	pmap_t		pv_pmap;	/* pmap where mapping lies */
11654359Sroberto	vm_offset_t	pv_va;		/* virtual address for mapping */
11754359Sroberto	TAILQ_ENTRY(pv_entry)	pv_list;
11854359Sroberto	TAILQ_ENTRY(pv_entry)	pv_plist;
11954359Sroberto} *pv_entry_t;
12054359Sroberto
12154359Sroberto#define	PV_ENTRY_NULL	((pv_entry_t) 0)
12254359Sroberto
12354359Sroberto#ifdef	_KERNEL
12454359Sroberto
12554359Srobertoextern vm_offset_t avail_end;
12654359Srobertoextern vm_offset_t avail_start;
12754359Srobertoextern vm_offset_t clean_eva;
12854359Srobertoextern vm_offset_t clean_sva;
12954359Srobertoextern vm_offset_t phys_avail[];
13054359Srobertoextern vm_offset_t virtual_avail;
13154359Srobertoextern vm_offset_t virtual_end;
13254359Sroberto
13354359Srobertovm_offset_t pmap_steal_memory __P((vm_size_t));
13454359Srobertovoid	pmap_bootstrap __P((void));
13554359Srobertovoid	pmap_setdevram __P((unsigned long long basea, vm_offset_t sizea));
13654359Srobertoint	pmap_uses_prom_console __P((void));
13754359Srobertopmap_t	pmap_kernel __P((void));
13854359Srobertovoid	*pmap_mapdev __P((vm_offset_t, vm_size_t));
13954359Srobertovoid	pmap_unmapdev __P((vm_offset_t, vm_size_t));
14054359Srobertounsigned *pmap_pte __P((pmap_t, vm_offset_t)) __pure2;
14154359Srobertovm_page_t pmap_use_pt __P((pmap_t, vm_offset_t));
14254359Srobertovoid	pmap_set_opt	__P((unsigned *));
14354359Srobertovoid	pmap_set_opt_bsp	__P((void));
14454359Srobertostruct pmap *pmap_install __P((struct pmap *pmap));
14554359Sroberto
14654359Sroberto#endif /* _KERNEL */
14754359Sroberto
14854359Sroberto#endif /* !_MACHINE_PMAP_H_ */
14954359Sroberto