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