Home | History | Annotate | Line # | Download | only in include
pmap.h revision 1.16.10.2
      1  1.16.10.2      yamt /*	$NetBSD: pmap.h,v 1.16.10.2 2009/06/20 07:20:04 yamt Exp $	*/
      2        1.1  fredette 
      3  1.16.10.1      yamt /*	$OpenBSD: pmap.h,v 1.35 2007/12/14 18:32:23 deraadt Exp $	*/
      4        1.1  fredette 
      5        1.1  fredette /*
      6  1.16.10.1      yamt  * Copyright (c) 2002-2004 Michael Shalayeff
      7        1.1  fredette  * All rights reserved.
      8        1.1  fredette  *
      9        1.1  fredette  * Redistribution and use in source and binary forms, with or without
     10        1.1  fredette  * modification, are permitted provided that the following conditions
     11        1.1  fredette  * are met:
     12        1.1  fredette  * 1. Redistributions of source code must retain the above copyright
     13        1.1  fredette  *    notice, this list of conditions and the following disclaimer.
     14        1.1  fredette  * 2. Redistributions in binary form must reproduce the above copyright
     15        1.1  fredette  *    notice, this list of conditions and the following disclaimer in the
     16        1.1  fredette  *    documentation and/or other materials provided with the distribution.
     17        1.1  fredette  *
     18        1.1  fredette  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19        1.1  fredette  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20        1.1  fredette  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21  1.16.10.1      yamt  * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
     22  1.16.10.1      yamt  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     23  1.16.10.1      yamt  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     24  1.16.10.1      yamt  * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     25  1.16.10.1      yamt  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     26  1.16.10.1      yamt  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     27  1.16.10.1      yamt  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
     28  1.16.10.1      yamt  * THE POSSIBILITY OF SUCH DAMAGE.
     29        1.1  fredette  */
     30        1.1  fredette 
     31        1.1  fredette /*
     32        1.1  fredette  *	Pmap header for hppa.
     33        1.1  fredette  */
     34        1.1  fredette 
     35        1.1  fredette #ifndef	_HPPA_PMAP_H_
     36        1.1  fredette #define	_HPPA_PMAP_H_
     37        1.1  fredette 
     38  1.16.10.1      yamt #include <sys/mutex.h>
     39        1.1  fredette #include <machine/pte.h>
     40  1.16.10.1      yamt #include <machine/cpufunc.h>
     41  1.16.10.1      yamt 
     42  1.16.10.1      yamt #include <uvm/uvm_pglist.h>
     43  1.16.10.1      yamt #include <uvm/uvm_object.h>
     44  1.16.10.1      yamt 
     45  1.16.10.1      yamt #ifdef	_KERNEL
     46        1.1  fredette 
     47        1.1  fredette struct pmap {
     48  1.16.10.1      yamt 	struct uvm_object pm_obj;	/* object (lck by object lock) */
     49  1.16.10.1      yamt #define	pm_lock	pm_obj.vmobjlock
     50  1.16.10.1      yamt 	struct vm_page	*pm_ptphint;
     51  1.16.10.1      yamt 	struct vm_page	*pm_pdir_pg;	/* vm_page for pdir */
     52  1.16.10.2      yamt 	volatile uint32_t *pm_pdir;	/* page dir (read-only after create) */
     53  1.16.10.1      yamt 	pa_space_t	pm_space;	/* space id (read-only after create) */
     54  1.16.10.1      yamt 	u_int		pm_pid;		/* prot id (read-only after create) */
     55        1.1  fredette 
     56  1.16.10.1      yamt 	struct pmap_statistics	pm_stats;
     57  1.16.10.1      yamt };
     58        1.5       chs 
     59  1.16.10.1      yamt #define	PMAP_NC		0x100
     60        1.5       chs 
     61  1.16.10.1      yamt /*
     62  1.16.10.1      yamt  * Flags that indicate attributes of pages or mappings of pages.
     63  1.16.10.1      yamt  *
     64  1.16.10.1      yamt  * We need two flags for cacheability because pages/mappings can be marked
     65  1.16.10.1      yamt  * uncacheable for two reasons,
     66  1.16.10.1      yamt  *
     67  1.16.10.1      yamt  *	1) A page's contents may change under our feet and can never be
     68  1.16.10.1      yamt  *	   cacheable, e.g. I/O space, DMA buffers.
     69  1.16.10.1      yamt  *	2) A page has non-equivalent aliases and must be (temporarily)
     70  1.16.10.1      yamt  *	   marked uncachable.
     71  1.16.10.1      yamt  *
     72  1.16.10.1      yamt  * A page that is marked PVF_NC can *never* be marked cacheable and will have
     73  1.16.10.1      yamt  * all mappings marked PVF_UNCACHEABLE. A page marked PVF_UNCACHEABLE only
     74  1.16.10.1      yamt  * is done so due to non-equivalent aliases this maybe removed is the non-
     75  1.16.10.1      yamt  * equivalent aliases are removed.
     76  1.16.10.1      yamt  *
     77  1.16.10.1      yamt  */
     78        1.1  fredette 
     79  1.16.10.1      yamt #define	PVF_NC		0x2000			/* pg is never cacheable */
     80  1.16.10.1      yamt 
     81  1.16.10.1      yamt #define	PVF_MOD		PTE_PROT(TLB_DIRTY)	/* pg/mp is modified */
     82  1.16.10.1      yamt #define	PVF_REF		PTE_PROT(TLB_REFTRAP)	/* pg/mp (inv) is referenced */
     83  1.16.10.1      yamt #define	PVF_WRITE	PTE_PROT(TLB_WRITE)	/* pg/mp is writable */
     84  1.16.10.1      yamt #define	PVF_UNCACHEABLE	PTE_PROT(TLB_UNCACHEABLE)
     85  1.16.10.1      yamt 						/* pg/mp is uncacheable */
     86  1.16.10.1      yamt 
     87  1.16.10.1      yamt #define	pmap_is_aliased(pg)	\
     88  1.16.10.1      yamt 	(((pg)->mdpage.pvh_attrs & PVF_NC) == 0 && \
     89  1.16.10.1      yamt 	 ((pg)->mdpage.pvh_attrs & PVF_UNCACHEABLE) != 0)
     90  1.16.10.1      yamt 
     91  1.16.10.1      yamt #define	HPPA_MAX_PID	0xfffa
     92  1.16.10.1      yamt #define	HPPA_SID_MAX	0x7ffd
     93  1.16.10.1      yamt 
     94  1.16.10.1      yamt /*
     95  1.16.10.1      yamt  * DON'T CHANGE THIS - this is assumed in lots of places.
     96  1.16.10.1      yamt  */
     97  1.16.10.1      yamt #define	HPPA_SID_KERNEL	0
     98  1.16.10.1      yamt #define	HPPA_PID_KERNEL	2
     99  1.16.10.1      yamt 
    100  1.16.10.1      yamt struct pv_entry {			/* locked by its list's pvh_lock */
    101  1.16.10.1      yamt 	struct pv_entry	*pv_next;
    102  1.16.10.1      yamt 	struct pmap	*pv_pmap;	/* the pmap */
    103  1.16.10.1      yamt 	vaddr_t		pv_va;		/* the virtual address + flags */
    104  1.16.10.1      yamt #define	PV_VAMASK	(~(PAGE_SIZE - 1))
    105  1.16.10.1      yamt #define	PV_KENTER	0x001
    106  1.16.10.1      yamt 
    107  1.16.10.1      yamt 	struct vm_page	*pv_ptp;	/* the vm_page of the PTP */
    108  1.16.10.1      yamt };
    109  1.16.10.1      yamt 
    110  1.16.10.1      yamt extern int pmap_hptsize;
    111  1.16.10.1      yamt extern struct pdc_hwtlb pdc_hwtlb;
    112  1.16.10.1      yamt 
    113  1.16.10.1      yamt /*
    114  1.16.10.1      yamt  * pool quickmaps
    115  1.16.10.1      yamt  */
    116  1.16.10.1      yamt static inline vaddr_t hppa_map_poolpage(paddr_t pa)
    117  1.16.10.1      yamt {
    118  1.16.10.1      yamt 	return (vaddr_t)pa;
    119  1.16.10.1      yamt }
    120  1.16.10.1      yamt 
    121  1.16.10.1      yamt static inline paddr_t hppa_unmap_poolpage(vaddr_t va)
    122  1.16.10.1      yamt {
    123  1.16.10.1      yamt 	pdcache(HPPA_SID_KERNEL, va, PAGE_SIZE);
    124  1.16.10.1      yamt 
    125  1.16.10.1      yamt 	return (paddr_t)va;
    126  1.16.10.1      yamt }
    127  1.16.10.1      yamt 
    128  1.16.10.1      yamt #define	PMAP_MAP_POOLPAGE(pa)	hppa_map_poolpage(pa)
    129  1.16.10.1      yamt #define	PMAP_UNMAP_POOLPAGE(va)	hppa_unmap_poolpage(va)
    130        1.1  fredette 
    131        1.1  fredette /*
    132        1.1  fredette  * according to the parisc manual aliased va's should be
    133        1.1  fredette  * different by high 12 bits only.
    134        1.1  fredette  */
    135        1.8    atatat #define	PMAP_PREFER(o,h,s,td)	do {					\
    136        1.1  fredette 	vaddr_t pmap_prefer_hint;					\
    137        1.1  fredette 	pmap_prefer_hint = (*(h) & HPPA_PGAMASK) | ((o) & HPPA_PGAOFF);	\
    138        1.1  fredette 	if (pmap_prefer_hint < *(h))					\
    139        1.1  fredette 		pmap_prefer_hint += HPPA_PGALIAS;			\
    140        1.1  fredette 	*(h) = pmap_prefer_hint;					\
    141        1.1  fredette } while(0)
    142        1.1  fredette 
    143  1.16.10.1      yamt #define	pmap_sid2pid(s)			(((s) + 1) << 1)
    144  1.16.10.1      yamt #define	pmap_resident_count(pmap)	((pmap)->pm_stats.resident_count)
    145  1.16.10.1      yamt #define	pmap_wired_count(pmap)		((pmap)->pm_stats.wired_count)
    146        1.1  fredette #define	pmap_update(p)
    147  1.16.10.1      yamt 
    148  1.16.10.1      yamt #define	pmap_copy(dpmap,spmap,da,len,sa)
    149  1.16.10.1      yamt 
    150  1.16.10.1      yamt #define	pmap_clear_modify(pg)	pmap_changebit(pg, 0, PTE_PROT(TLB_DIRTY))
    151  1.16.10.1      yamt #define	pmap_clear_reference(pg) \
    152  1.16.10.1      yamt 				pmap_changebit(pg, PTE_PROT(TLB_REFTRAP), 0)
    153  1.16.10.1      yamt #define	pmap_is_modified(pg)	pmap_testbit(pg, PTE_PROT(TLB_DIRTY))
    154  1.16.10.1      yamt #define	pmap_is_referenced(pg)	pmap_testbit(pg, PTE_PROT(TLB_REFTRAP))
    155  1.16.10.1      yamt #define	pmap_phys_address(ppn)	((ppn) << PAGE_SHIFT)
    156  1.16.10.1      yamt 
    157       1.12     skrll void	pmap_activate(struct lwp *);
    158        1.6       chs 
    159  1.16.10.1      yamt void pmap_bootstrap(vaddr_t);
    160  1.16.10.1      yamt bool pmap_changebit(struct vm_page *, u_int, u_int);
    161  1.16.10.1      yamt bool pmap_testbit(struct vm_page *, u_int);
    162  1.16.10.1      yamt void pmap_write_protect(struct pmap *, vaddr_t, vaddr_t, vm_prot_t);
    163  1.16.10.1      yamt void pmap_remove(struct pmap *pmap, vaddr_t sva, vaddr_t eva);
    164  1.16.10.1      yamt void pmap_page_remove(struct vm_page *pg);
    165  1.16.10.1      yamt 
    166  1.16.10.1      yamt static inline void
    167       1.12     skrll pmap_deactivate(struct lwp *l)
    168        1.6       chs {
    169  1.16.10.1      yamt 	/* Nothing. */
    170        1.6       chs }
    171        1.1  fredette 
    172  1.16.10.1      yamt static inline void
    173        1.3       chs pmap_remove_all(struct pmap *pmap)
    174        1.2       chs {
    175        1.2       chs 	/* Nothing. */
    176        1.2       chs }
    177        1.1  fredette 
    178  1.16.10.1      yamt static inline int
    179  1.16.10.1      yamt pmap_prot(struct pmap *pmap, int prot)
    180        1.1  fredette {
    181  1.16.10.1      yamt 	extern u_int hppa_prot[];
    182  1.16.10.1      yamt 	return (hppa_prot[prot] | (pmap == pmap_kernel()? 0 : TLB_USER));
    183  1.16.10.1      yamt }
    184        1.5       chs 
    185  1.16.10.1      yamt static inline void
    186  1.16.10.1      yamt pmap_page_protect(struct vm_page *pg, vm_prot_t prot)
    187  1.16.10.1      yamt {
    188  1.16.10.1      yamt 	if ((prot & UVM_PROT_WRITE) == 0) {
    189  1.16.10.1      yamt 		if (prot & (UVM_PROT_RX))
    190  1.16.10.1      yamt 			pmap_changebit(pg, 0, PTE_PROT(TLB_WRITE));
    191  1.16.10.1      yamt 		else
    192  1.16.10.1      yamt 			pmap_page_remove(pg);
    193  1.16.10.1      yamt 	}
    194  1.16.10.1      yamt }
    195  1.16.10.1      yamt 
    196  1.16.10.1      yamt static inline void
    197  1.16.10.1      yamt pmap_protect(struct pmap *pmap, vaddr_t sva, vaddr_t eva, vm_prot_t prot)
    198  1.16.10.1      yamt {
    199  1.16.10.1      yamt 	if ((prot & UVM_PROT_WRITE) == 0) {
    200  1.16.10.1      yamt 		if (prot & (UVM_PROT_RX))
    201  1.16.10.1      yamt 			pmap_write_protect(pmap, sva, eva, prot);
    202  1.16.10.1      yamt 		else
    203  1.16.10.1      yamt 			pmap_remove(pmap, sva, eva);
    204  1.16.10.1      yamt 	}
    205        1.1  fredette }
    206        1.1  fredette 
    207        1.7       chs #define	pmap_sid(pmap, va) \
    208        1.7       chs 	((((va) & 0xc0000000) != 0xc0000000) ? \
    209  1.16.10.1      yamt 	 (pmap)->pm_space : HPPA_SID_KERNEL)
    210        1.7       chs 
    211        1.1  fredette #endif /* _KERNEL */
    212        1.1  fredette 
    213        1.1  fredette #endif /* _HPPA_PMAP_H_ */
    214