1139790Simp/*-
266458Sdfr * Copyright (c) 1991 Regents of the University of California.
366458Sdfr * All rights reserved.
466458Sdfr *
566458Sdfr * This code is derived from software contributed to Berkeley by
666458Sdfr * the Systems Programming Group of the University of Utah Computer
766458Sdfr * Science Department and William Jolitz of UUNET Technologies Inc.
866458Sdfr *
966458Sdfr * Redistribution and use in source and binary forms, with or without
1066458Sdfr * modification, are permitted provided that the following conditions
1166458Sdfr * are met:
1266458Sdfr * 1. Redistributions of source code must retain the above copyright
1366458Sdfr *    notice, this list of conditions and the following disclaimer.
1466458Sdfr * 2. Redistributions in binary form must reproduce the above copyright
1566458Sdfr *    notice, this list of conditions and the following disclaimer in the
1666458Sdfr *    documentation and/or other materials provided with the distribution.
1766458Sdfr * 4. Neither the name of the University nor the names of its contributors
1866458Sdfr *    may be used to endorse or promote products derived from this software
1966458Sdfr *    without specific prior written permission.
2066458Sdfr *
2166458Sdfr * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2266458Sdfr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2366458Sdfr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2466458Sdfr * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2566458Sdfr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2666458Sdfr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2766458Sdfr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2866458Sdfr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2966458Sdfr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3066458Sdfr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3166458Sdfr * SUCH DAMAGE.
3266458Sdfr *
3366458Sdfr * Derived from hp300 version by Mike Hibler, this version by William
3466458Sdfr * Jolitz uses a recursive map [a pde points to the page directory] to
3566458Sdfr * map the page tables using the pagetables themselves. This is done to
3666458Sdfr * reduce the impact on kernel virtual memory for lots of sparse address
3766458Sdfr * space, and to reduce the cost of memory to each process.
3866458Sdfr *
3966458Sdfr *	from: hp300: @(#)pmap.h	7.2 (Berkeley) 12/16/90
4066458Sdfr *	from: @(#)pmap.h	7.4 (Berkeley) 5/12/91
4166458Sdfr *	from: i386 pmap.h,v 1.54 1997/11/20 19:30:35 bde Exp
4266458Sdfr * $FreeBSD$
4366458Sdfr */
4466458Sdfr
4566458Sdfr#ifndef _MACHINE_PMAP_H_
4666458Sdfr#define	_MACHINE_PMAP_H_
4766458Sdfr
4866458Sdfr#include <sys/queue.h>
49132378Salc#include <sys/_lock.h>
50132378Salc#include <sys/_mutex.h>
51135590Smarcel#include <machine/atomic.h>
5283900Sdfr#include <machine/pte.h>
53219808Smarcel#include <machine/vmparam.h>
5466458Sdfr
5566458Sdfr#ifdef _KERNEL
5666458Sdfr
5785142Sdfr#define MAXKPT		(PAGE_SIZE/sizeof(vm_offset_t))
5885142Sdfr
59153179Sjhb#define	vtophys(va)	pmap_kextract((vm_offset_t)(va))
6066458Sdfr
6166458Sdfr#endif /* _KERNEL */
6266458Sdfr
6366458Sdfr/*
6466458Sdfr * Pmap stuff
6566458Sdfr */
6666458Sdfrstruct	pv_entry;
67242121Salcstruct	pv_chunk;
6866458Sdfr
6966458Sdfrstruct md_page {
7066458Sdfr	TAILQ_HEAD(,pv_entry)	pv_list;
71223873Smarcel	vm_memattr_t		memattr;
7266458Sdfr};
7366458Sdfr
7466458Sdfrstruct pmap {
75132378Salc	struct mtx		pm_mtx;
76242121Salc	TAILQ_HEAD(,pv_chunk)	pm_pvchunk;	/* list of mappings in pmap */
77219808Smarcel	uint32_t		pm_rid[IA64_VM_MINKERN_REGION];
7866458Sdfr	struct pmap_statistics	pm_stats;	/* pmap statistics */
7966458Sdfr};
8066458Sdfr
8166458Sdfrtypedef struct pmap	*pmap_t;
8266458Sdfr
8366458Sdfr#ifdef _KERNEL
8495710Speterextern struct pmap	kernel_pmap_store;
8595710Speter#define kernel_pmap	(&kernel_pmap_store)
86132378Salc
87132378Salc#define	PMAP_LOCK(pmap)		mtx_lock(&(pmap)->pm_mtx)
88132378Salc#define	PMAP_LOCK_ASSERT(pmap, type) \
89132378Salc				mtx_assert(&(pmap)->pm_mtx, (type))
90132378Salc#define	PMAP_LOCK_DESTROY(pmap)	mtx_destroy(&(pmap)->pm_mtx)
91132378Salc#define	PMAP_LOCK_INIT(pmap)	mtx_init(&(pmap)->pm_mtx, "pmap", \
92132378Salc				    NULL, MTX_DEF)
93132378Salc#define	PMAP_LOCKED(pmap)	mtx_owned(&(pmap)->pm_mtx)
94132378Salc#define	PMAP_MTX(pmap)		(&(pmap)->pm_mtx)
95132378Salc#define	PMAP_TRYLOCK(pmap)	mtx_trylock(&(pmap)->pm_mtx)
96132378Salc#define	PMAP_UNLOCK(pmap)	mtx_unlock(&(pmap)->pm_mtx)
9766458Sdfr#endif
9866458Sdfr
9966458Sdfr/*
10066458Sdfr * For each vm_page_t, there is a list of all currently valid virtual
101164250Sru * mappings of that page.  An entry is a pv_entry_t, the list is pv_list.
10266458Sdfr */
10366458Sdfrtypedef struct pv_entry {
10466458Sdfr	vm_offset_t	pv_va;		/* virtual address for mapping */
10566458Sdfr	TAILQ_ENTRY(pv_entry)	pv_list;
10666458Sdfr} *pv_entry_t;
10766458Sdfr
10866458Sdfr#ifdef	_KERNEL
10966458Sdfr
110216094Salcextern vm_paddr_t phys_avail[];
11166458Sdfrextern vm_offset_t virtual_avail;
11266458Sdfrextern vm_offset_t virtual_end;
11366458Sdfr
114149777Smarcelextern uint64_t pmap_vhpt_base[];
115149777Smarcelextern int pmap_vhpt_log2size;
116149777Smarcel
117268201Smarcel#define	pmap_mapbios(pa,sz)	pmap_mapdev_attr(pa,sz,VM_MEMATTR_UNCACHEABLE)
118268201Smarcel#define	pmap_mapdev(pa,sz)	pmap_mapdev_attr(pa,sz,VM_MEMATTR_UNCACHEABLE)
119268201Smarcel#define	pmap_unmapbios(va,sz)	pmap_unmapdev(va,sz)
120268201Smarcel
121223873Smarcel#define	pmap_page_get_memattr(m)	((m)->md.memattr)
122268201Smarcel#define	pmap_page_is_mapped(m)		(!TAILQ_EMPTY(&(m)->md.pv_list))
123237168Salc#define	pmap_page_is_write_mapped(m)	(((m)->aflags & PGA_WRITEABLE) != 0)
124130965Salc
125268201Smarcelvoid	pmap_kenter(vm_offset_t va, vm_paddr_t pa);
126268201Smarcelvm_paddr_t pmap_kextract(vm_offset_t va);
127268201Smarcelvoid	pmap_kremove(vm_offset_t);
128268201Smarcelvoid	*pmap_mapdev_attr(vm_paddr_t, vm_size_t, vm_memattr_t);
129268201Smarcelvoid	pmap_page_set_memattr(vm_page_t, vm_memattr_t);
130268201Smarcelvoid	pmap_unmapdev(vm_offset_t, vm_size_t);
131268201Smarcel
132268201Smarcel/* Machine-architecture private */
133200200Smarcelvm_offset_t pmap_alloc_vhpt(void);
13492843Salfredvoid	pmap_bootstrap(void);
135268184Smarcelvoid	pmap_invalidate_all(void);
136268201Smarcelvm_offset_t pmap_mapdev_priv(vm_paddr_t, vm_size_t, vm_memattr_t);
137223873Smarcelvm_offset_t pmap_page_to_va(vm_page_t);
138223873Smarcelvm_offset_t pmap_steal_memory(vm_size_t);
139223873Smarcelstruct pmap *pmap_switch(struct pmap *pmap);
14066458Sdfr
14166458Sdfr#endif /* _KERNEL */
14266458Sdfr
14366458Sdfr#endif /* !_MACHINE_PMAP_H_ */
144