Home | History | Annotate | Line # | Download | only in include
pmap.h revision 1.24
      1 /*	$NetBSD: pmap.h,v 1.24 2010/02/22 21:32:55 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 #include <machine/cpufunc.h>
     41 
     42 #include <uvm/uvm_pglist.h>
     43 #include <uvm/uvm_object.h>
     44 
     45 #ifdef	_KERNEL
     46 
     47 struct pmap {
     48 	struct uvm_object pm_obj;	/* object (lck by object lock) */
     49 #define	pm_lock	pm_obj.vmobjlock
     50 	struct vm_page	*pm_ptphint;
     51 	struct vm_page	*pm_pdir_pg;	/* vm_page for pdir */
     52 	volatile uint32_t *pm_pdir;	/* page dir (read-only after create) */
     53 	pa_space_t	pm_space;	/* space id (read-only after create) */
     54 	u_int		pm_pid;		/* prot id (read-only after create) */
     55 
     56 	struct pmap_statistics	pm_stats;
     57 };
     58 
     59 /*
     60  * Flags that indicate attributes of pages or mappings of pages.
     61  *
     62  * We need two flags for cacheability because pages/mappings can be marked
     63  * uncacheable for two reasons,
     64  *
     65  *	1) A page's contents may change under our feet and can never be
     66  *	   cacheable, e.g. I/O space, DMA buffers.
     67  *	2) A page has non-equivalent aliases and must be (temporarily)
     68  *	   marked uncachable.
     69  *
     70  * A page that is marked PVF_NC can *never* be marked cacheable and will have
     71  * all mappings marked PVF_UNCACHEABLE. A page marked PVF_UNCACHEABLE only
     72  * is done so due to non-equivalent aliases this maybe removed is the non-
     73  * equivalent aliases are removed.
     74  *
     75  */
     76 
     77 #define	PVF_NC		0x2000			/* pg is never cacheable */
     78 
     79 #define	PVF_MOD		PTE_PROT(TLB_DIRTY)	/* pg/mp is modified */
     80 #define	PVF_REF		PTE_PROT(TLB_REFTRAP)	/* pg/mp (inv) is referenced */
     81 #define	PVF_WRITE	PTE_PROT(TLB_WRITE)	/* pg/mp is writable */
     82 #define	PVF_UNCACHEABLE	PTE_PROT(TLB_UNCACHEABLE)
     83 						/* pg/mp is uncacheable */
     84 
     85 #define	pmap_is_aliased(pg)	\
     86 	(((pg)->mdpage.pvh_attrs & PVF_NC) == 0 && \
     87 	 ((pg)->mdpage.pvh_attrs & PVF_UNCACHEABLE) != 0)
     88 
     89 #define	HPPA_MAX_PID	0xfffa
     90 #define	HPPA_SID_MAX	0x7ffd
     91 
     92 /*
     93  * DON'T CHANGE THIS - this is assumed in lots of places.
     94  */
     95 #define	HPPA_SID_KERNEL	0
     96 #define	HPPA_PID_KERNEL	2
     97 
     98 struct pv_entry {			/* locked by its list's pvh_lock */
     99 	struct pv_entry	*pv_next;
    100 	struct pmap	*pv_pmap;	/* the pmap */
    101 	vaddr_t		pv_va;		/* the virtual address + flags */
    102 #define	PV_VAMASK	(~(PAGE_SIZE - 1))
    103 #define	PV_KENTER	0x001
    104 
    105 	struct vm_page	*pv_ptp;	/* the vm_page of the PTP */
    106 };
    107 
    108 extern int pmap_hptsize;
    109 extern struct pdc_hwtlb pdc_hwtlb;
    110 
    111 /*
    112  * pool quickmaps
    113  */
    114 static inline vaddr_t hppa_map_poolpage(paddr_t pa)
    115 {
    116 	return (vaddr_t)pa;
    117 }
    118 
    119 static inline paddr_t hppa_unmap_poolpage(vaddr_t va)
    120 {
    121 	pdcache(HPPA_SID_KERNEL, va, PAGE_SIZE);
    122 #if defined(HP8000_CPU) || defined(HP8200_CPU) || \
    123     defined(HP8500_CPU) || defined(HP8600_CPU)
    124 	pdtlb(HPPA_SID_KERNEL, va);
    125 	ficache(HPPA_SID_KERNEL, va, PAGE_SIZE);
    126 	pitlb(HPPA_SID_KERNEL, va);
    127 #endif
    128 
    129 	return (paddr_t)va;
    130 }
    131 
    132 #define	PMAP_MAP_POOLPAGE(pa)	hppa_map_poolpage(pa)
    133 #define	PMAP_UNMAP_POOLPAGE(va)	hppa_unmap_poolpage(va)
    134 
    135 /*
    136  * according to the parisc manual aliased va's should be
    137  * different by high 12 bits only.
    138  */
    139 #define	PMAP_PREFER(o,h,s,td)	do {					\
    140 	vaddr_t pmap_prefer_hint;					\
    141 	pmap_prefer_hint = (*(h) & HPPA_PGAMASK) | ((o) & HPPA_PGAOFF);	\
    142 	if (pmap_prefer_hint < *(h))					\
    143 		pmap_prefer_hint += HPPA_PGALIAS;			\
    144 	*(h) = pmap_prefer_hint;					\
    145 } while(0)
    146 
    147 #define	pmap_sid2pid(s)			(((s) + 1) << 1)
    148 #define	pmap_resident_count(pmap)	((pmap)->pm_stats.resident_count)
    149 #define	pmap_wired_count(pmap)		((pmap)->pm_stats.wired_count)
    150 #define	pmap_update(p)
    151 
    152 #define	pmap_copy(dpmap,spmap,da,len,sa)
    153 
    154 #define	pmap_clear_modify(pg)	pmap_changebit(pg, 0, PTE_PROT(TLB_DIRTY))
    155 #define	pmap_clear_reference(pg) \
    156 				pmap_changebit(pg, PTE_PROT(TLB_REFTRAP), 0)
    157 #define	pmap_is_modified(pg)	pmap_testbit(pg, PTE_PROT(TLB_DIRTY))
    158 #define	pmap_is_referenced(pg)	pmap_testbit(pg, PTE_PROT(TLB_REFTRAP))
    159 #define	pmap_phys_address(ppn)	((ppn) << PAGE_SHIFT)
    160 
    161 void	pmap_activate(struct lwp *);
    162 
    163 void pmap_bootstrap(vaddr_t);
    164 bool pmap_changebit(struct vm_page *, u_int, u_int);
    165 bool pmap_testbit(struct vm_page *, u_int);
    166 void pmap_write_protect(struct pmap *, vaddr_t, vaddr_t, vm_prot_t);
    167 void pmap_remove(struct pmap *pmap, vaddr_t sva, vaddr_t eva);
    168 void pmap_page_remove(struct vm_page *pg);
    169 
    170 static inline void
    171 pmap_deactivate(struct lwp *l)
    172 {
    173 	/* Nothing. */
    174 }
    175 
    176 static inline void
    177 pmap_remove_all(struct pmap *pmap)
    178 {
    179 	/* Nothing. */
    180 }
    181 
    182 static inline int
    183 pmap_prot(struct pmap *pmap, int prot)
    184 {
    185 	extern u_int hppa_prot[];
    186 	return (hppa_prot[prot] | (pmap == pmap_kernel()? 0 : TLB_USER));
    187 }
    188 
    189 static inline void
    190 pmap_page_protect(struct vm_page *pg, vm_prot_t prot)
    191 {
    192 	if ((prot & UVM_PROT_WRITE) == 0) {
    193 		if (prot & (UVM_PROT_RX))
    194 			pmap_changebit(pg, 0, PTE_PROT(TLB_WRITE));
    195 		else
    196 			pmap_page_remove(pg);
    197 	}
    198 }
    199 
    200 static inline void
    201 pmap_protect(struct pmap *pmap, vaddr_t sva, vaddr_t eva, vm_prot_t prot)
    202 {
    203 	if ((prot & UVM_PROT_WRITE) == 0) {
    204 		if (prot & (UVM_PROT_RX))
    205 			pmap_write_protect(pmap, sva, eva, prot);
    206 		else
    207 			pmap_remove(pmap, sva, eva);
    208 	}
    209 }
    210 
    211 #define	pmap_sid(pmap, va) \
    212 	((((va) & 0xc0000000) != 0xc0000000) ? \
    213 	 (pmap)->pm_space : HPPA_SID_KERNEL)
    214 
    215 /*
    216  * MD flags that we use for pmap_kenter_pa:
    217  */
    218 #define	PMAP_NOCACHE	0x01000000	/* set the non-cacheable bit */
    219 
    220 #endif /* _KERNEL */
    221 
    222 #endif /* _HPPA_PMAP_H_ */
    223