Home | History | Annotate | Line # | Download | only in include
pmap.h revision 1.16.18.8
      1 /*	$NetBSD: pmap.h,v 1.16.18.8 2009/01/19 13:16:14 skrll Exp $	*/
      2 
      3 /*	$OpenBSD: pmap.h,v 1.35 2007/12/14 18:32:23 deraadt Exp $	*/
      4 
      5 /*
      6  * Copyright (c) 2002-2004 Michael Shalayeff
      7  * All rights reserved.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21  * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
     22  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     24  * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     26  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     27  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
     28  * THE POSSIBILITY OF SUCH DAMAGE.
     29  */
     30 
     31 /*
     32  *	Pmap header for hppa.
     33  */
     34 
     35 #ifndef	_HPPA_PMAP_H_
     36 #define	_HPPA_PMAP_H_
     37 
     38 #include <sys/mutex.h>
     39 #include <machine/pte.h>
     40 
     41 #include <uvm/uvm_pglist.h>
     42 #include <uvm/uvm_object.h>
     43 
     44 #ifdef	_KERNEL
     45 
     46 struct pmap {
     47 	struct uvm_object pm_obj;	/* object (lck by object lock) */
     48 #define	pm_lock	pm_obj.vmobjlock
     49 	struct vm_page	*pm_ptphint;
     50 	struct vm_page	*pm_pdir_pg;	/* vm_page for pdir */
     51 	volatile u_int32_t *pm_pdir;	/* page dir (read-only after create) */
     52 	pa_space_t	pm_space;	/* space id (read-only after create) */
     53 	u_int		pm_pid;		/* prot id (read-only after create) */
     54 
     55 	struct pmap_statistics	pm_stats;
     56 };
     57 
     58 #define	PMAP_NC		0x100
     59 
     60 #define	HPPA_MAX_PID	0xfffa
     61 #define	HPPA_SID_MAX	0x7ffd
     62 #if 0
     63 #define	HPPA_SID_KERNEL	0
     64 #endif
     65 #define	HPPA_PID_KERNEL	2
     66 
     67 struct pv_entry {			/* locked by its list's pvh_lock */
     68 	struct pv_entry	*pv_next;
     69 	struct pmap	*pv_pmap;	/* the pmap */
     70 	vaddr_t		pv_va;		/* the virtual address */
     71 	struct vm_page	*pv_ptp;	/* the vm_page of the PTP */
     72 };
     73 
     74 extern struct pmap kernel_pmap_store;
     75 
     76 #if defined(HP7100LC_CPU) || defined(HP7300LC_CPU)
     77 extern int pmap_hptsize;
     78 extern struct pdc_hwtlb pdc_hwtlb;
     79 #endif
     80 
     81 /*
     82  * pool quickmaps
     83  */
     84 #define	PMAP_MAP_POOLPAGE(pa)	(pa)
     85 #define	PMAP_UNMAP_POOLPAGE(va)	(va)
     86 
     87 /*
     88  * according to the parisc manual aliased va's should be
     89  * different by high 12 bits only.
     90  */
     91 #define	PMAP_PREFER(o,h,s,td)	do {					\
     92 	vaddr_t pmap_prefer_hint;					\
     93 	pmap_prefer_hint = (*(h) & HPPA_PGAMASK) | ((o) & HPPA_PGAOFF);	\
     94 	if (pmap_prefer_hint < *(h))					\
     95 		pmap_prefer_hint += HPPA_PGALIAS;			\
     96 	*(h) = pmap_prefer_hint;					\
     97 } while(0)
     98 
     99 #define	pmap_sid2pid(s)			(((s) + 1) << 1)
    100 #define	pmap_resident_count(pmap)	((pmap)->pm_stats.resident_count)
    101 #define	pmap_wired_count(pmap)		((pmap)->pm_stats.wired_count)
    102 #define	pmap_update(p)
    103 
    104 #define	pmap_copy(dpmap,spmap,da,len,sa)
    105 
    106 #define	pmap_clear_modify(pg)	pmap_changebit(pg, 0, PTE_PROT(TLB_DIRTY))
    107 #define	pmap_clear_reference(pg) \
    108 				pmap_changebit(pg, PTE_PROT(TLB_REFTRAP), 0)
    109 #define	pmap_is_modified(pg)	pmap_testbit(pg, PTE_PROT(TLB_DIRTY))
    110 #define	pmap_is_referenced(pg)	pmap_testbit(pg, PTE_PROT(TLB_REFTRAP))
    111 #define	pmap_phys_address(ppn)	((ppn) << PAGE_SHIFT)
    112 
    113 void	pmap_activate(struct lwp *);
    114 
    115 void pmap_bootstrap(vaddr_t);
    116 bool pmap_changebit(struct vm_page *, u_int, u_int);
    117 bool pmap_testbit(struct vm_page *, u_int);
    118 void pmap_write_protect(struct pmap *, vaddr_t, vaddr_t, vm_prot_t);
    119 void pmap_remove(struct pmap *pmap, vaddr_t sva, vaddr_t eva);
    120 void pmap_page_remove(struct vm_page *pg);
    121 
    122 static inline void
    123 pmap_deactivate(struct lwp *l)
    124 {
    125 	/* Nothing. */
    126 }
    127 
    128 static inline void
    129 pmap_remove_all(struct pmap *pmap)
    130 {
    131 	/* Nothing. */
    132 }
    133 
    134 static inline int
    135 pmap_prot(struct pmap *pmap, int prot)
    136 {
    137 	extern u_int hppa_prot[];
    138 	return (hppa_prot[prot] | (pmap == pmap_kernel()? 0 : TLB_USER));
    139 }
    140 
    141 static inline void
    142 pmap_page_protect(struct vm_page *pg, vm_prot_t prot)
    143 {
    144 	if ((prot & UVM_PROT_WRITE) == 0) {
    145 		if (prot & (UVM_PROT_RX))
    146 			pmap_changebit(pg, 0, PTE_PROT(TLB_WRITE));
    147 		else
    148 			pmap_page_remove(pg);
    149 	}
    150 }
    151 
    152 static inline void
    153 pmap_protect(struct pmap *pmap, vaddr_t sva, vaddr_t eva, vm_prot_t prot)
    154 {
    155 	if ((prot & UVM_PROT_WRITE) == 0) {
    156 		if (prot & (UVM_PROT_RX))
    157 			pmap_write_protect(pmap, sva, eva, prot);
    158 		else
    159 			pmap_remove(pmap, sva, eva);
    160 	}
    161 }
    162 
    163 #define	pmap_sid(pmap, va) \
    164 	((((va) & 0xc0000000) != 0xc0000000) ? \
    165 	 (pmap)->pm_space : HPPA_SID_KERNEL)
    166 
    167 #endif /* _KERNEL */
    168 
    169 #endif /* _HPPA_PMAP_H_ */
    170