Home | History | Annotate | Line # | Download | only in arm32
pmap.h revision 1.45
      1 /*	$NetBSD: pmap.h,v 1.45 2002/04/09 19:37:17 thorpej Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1994,1995 Mark Brinicombe.
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *	This product includes software developed by Mark Brinicombe
     18  * 4. The name of the author may not be used to endorse or promote products
     19  *    derived from this software without specific prior written permission.
     20  *
     21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  */
     32 
     33 #ifndef	_ARM32_PMAP_H_
     34 #define	_ARM32_PMAP_H_
     35 
     36 #ifdef _KERNEL
     37 
     38 #include <arm/cpufunc.h>
     39 #include <arm/arm32/pte.h>
     40 #include <uvm/uvm_object.h>
     41 
     42 /*
     43  * a pmap describes a processes' 4GB virtual address space.  this
     44  * virtual address space can be broken up into 4096 1MB regions which
     45  * are described by L1 PTEs in the L1 table.
     46  *
     47  * There is a line drawn at KERNEL_BASE.  Everything below that line
     48  * changes when the VM context is switched.  Everything above that line
     49  * is the same no matter which VM context is running.  This is achieved
     50  * by making the L1 PTEs for those slots above KERNEL_BASE reference
     51  * kernel L2 tables.
     52  *
     53  * The L2 tables are mapped linearly starting at PTE_BASE.  PTE_BASE
     54  * is below KERNEL_BASE, which means that the current process's PTEs
     55  * are always available starting at PTE_BASE.  Another region of KVA
     56  * above KERNEL_BASE, APTE_BASE, is reserved for mapping in the PTEs
     57  * of another process, should we need to manipulate them.
     58  *
     59  * The basic layout of the virtual address space thus looks like this:
     60  *
     61  *	0xffffffff
     62  *	.
     63  *	.
     64  *	.
     65  *	KERNEL_BASE
     66  *	--------------------
     67  *	PTE_BASE
     68  *	.
     69  *	.
     70  *	.
     71  *	0x00000000
     72  */
     73 
     74 /*
     75  * The pmap structure itself.
     76  */
     77 struct pmap {
     78 	struct uvm_object	pm_obj;		/* uvm_object */
     79 #define	pm_lock	pm_obj.vmobjlock
     80 	LIST_ENTRY(pmap)	pm_list;	/* list (lck by pm_list lock) */
     81 	pd_entry_t		*pm_pdir;	/* KVA of page directory */
     82 	struct l1pt		*pm_l1pt;	/* L1 table metadata */
     83 	paddr_t                 pm_pptpt;	/* PA of pt's page table */
     84 	vaddr_t                 pm_vptpt;	/* VA of pt's page table */
     85 	struct pmap_statistics	pm_stats;	/* pmap statistics */
     86 	struct vm_page		*pm_ptphint;	/* recently used PT */
     87 };
     88 
     89 typedef struct pmap *pmap_t;
     90 
     91 /*
     92  * Physical / virtual address structure. In a number of places (particularly
     93  * during bootstrapping) we need to keep track of the physical and virtual
     94  * addresses of various pages
     95  */
     96 typedef struct pv_addr {
     97 	SLIST_ENTRY(pv_addr) pv_list;
     98 	paddr_t pv_pa;
     99 	vaddr_t pv_va;
    100 } pv_addr_t;
    101 
    102 /*
    103  * Determine various modes for PTEs (user vs. kernel, cacheable
    104  * vs. non-cacheable).
    105  */
    106 #define	PTE_KERNEL	0
    107 #define	PTE_USER	1
    108 #define	PTE_NOCACHE	0
    109 #define	PTE_CACHE	1
    110 
    111 /*
    112  * Flags that indicate attributes of pages or mappings of pages.
    113  *
    114  * The PVF_MOD and PVF_REF flags are stored in the mdpage for each
    115  * page.  PVF_WIRED, PVF_WRITE, and PVF_NC are kept in individual
    116  * pv_entry's for each page.  They live in the same "namespace" so
    117  * that we can clear multiple attributes at a time.
    118  *
    119  * Note the "non-cacheable" flag generally means the page has
    120  * multiple mappings in a given address space.
    121  */
    122 #define	PVF_MOD		0x01		/* page is modified */
    123 #define	PVF_REF		0x02		/* page is referenced */
    124 #define	PVF_WIRED	0x04		/* mapping is wired */
    125 #define	PVF_WRITE	0x08		/* mapping is writable */
    126 #define	PVF_NC		0x10		/* mapping is non-cacheable */
    127 
    128 /*
    129  * Commonly referenced structures
    130  */
    131 extern struct pmap	kernel_pmap_store;
    132 extern int		pmap_debug_level; /* Only exists if PMAP_DEBUG */
    133 
    134 /*
    135  * Macros that we need to export
    136  */
    137 #define pmap_kernel()			(&kernel_pmap_store)
    138 #define	pmap_resident_count(pmap)	((pmap)->pm_stats.resident_count)
    139 #define	pmap_wired_count(pmap)		((pmap)->pm_stats.wired_count)
    140 
    141 #define	pmap_is_modified(pg)	\
    142 	(((pg)->mdpage.pvh_attrs & PVF_MOD) != 0)
    143 #define	pmap_is_referenced(pg)	\
    144 	(((pg)->mdpage.pvh_attrs & PVF_REF) != 0)
    145 
    146 #define	pmap_copy(dp, sp, da, l, sa)	/* nothing */
    147 
    148 #define pmap_phys_address(ppn)		(arm_ptob((ppn)))
    149 
    150 /*
    151  * Functions that we need to export
    152  */
    153 vaddr_t	pmap_map(vaddr_t, vaddr_t, vaddr_t, int);
    154 void	pmap_procwr(struct proc *, vaddr_t, int);
    155 
    156 #define	PMAP_NEED_PROCWR
    157 #define PMAP_GROWKERNEL		/* turn on pmap_growkernel interface */
    158 
    159 /* Functions we use internally. */
    160 void	pmap_bootstrap(pd_entry_t *, pv_addr_t);
    161 void	pmap_debug(int);
    162 int	pmap_handled_emulation(struct pmap *, vaddr_t);
    163 int	pmap_modified_emulation(struct pmap *, vaddr_t);
    164 void	pmap_postinit(void);
    165 
    166 void	vector_page_setprot(int);
    167 
    168 /* Bootstrapping routines. */
    169 void	pmap_map_section(vaddr_t, vaddr_t, paddr_t, int, int);
    170 void	pmap_map_entry(vaddr_t, vaddr_t, paddr_t, int, int);
    171 vsize_t	pmap_map_chunk(vaddr_t, vaddr_t, paddr_t, vsize_t, int, int);
    172 void	pmap_link_l2pt(vaddr_t, vaddr_t, pv_addr_t *);
    173 
    174 /*
    175  * Special page zero routine for use by the idle loop (no cache cleans).
    176  */
    177 boolean_t	pmap_pageidlezero __P((paddr_t));
    178 #define PMAP_PAGEIDLEZERO(pa)	pmap_pageidlezero((pa))
    179 
    180 /*
    181  * The current top of kernel VM
    182  */
    183 extern vaddr_t	pmap_curmaxkvaddr;
    184 
    185 /*
    186  * Useful macros and constants
    187  */
    188 
    189 /* Virtual address to page table entry */
    190 #define vtopte(va) \
    191 	(((pt_entry_t *)PTE_BASE) + arm_btop((vaddr_t) (va)))
    192 
    193 /* Virtual address to physical address */
    194 #define vtophys(va) \
    195 	((*vtopte(va) & L2_S_FRAME) | ((vaddr_t) (va) & L2_S_OFFSET))
    196 
    197 #define	l1pte_valid(pde)	((pde) != 0)
    198 #define	l1pte_section_p(pde)	(((pde) & L1_TYPE_MASK) == L1_TYPE_S)
    199 #define	l1pte_page_p(pde)	(((pde) & L1_TYPE_MASK) == L1_TYPE_C)
    200 #define	l1pte_fpage_p(pde)	(((pde) & L1_TYPE_MASK) == L1_TYPE_F)
    201 
    202 #define	l2pte_valid(pte)	((pte) != 0)
    203 #define	l2pte_pa(pte)		((pte) & L2_S_FRAME)
    204 
    205 /* L1 and L2 page table macros */
    206 #define pmap_pdei(v)		((v & L1_S_FRAME) >> L1_S_SHIFT)
    207 #define pmap_pde(m, v)		(&((m)->pm_pdir[pmap_pdei(v)]))
    208 
    209 #define pmap_pde_v(pde)		l1pte_valid(*(pde))
    210 #define pmap_pde_section(pde)	l1pte_section_p(*(pde))
    211 #define pmap_pde_page(pde)	l1pte_page_p(*(pde))
    212 #define pmap_pde_fpage(pde)	l1pte_fpage_p(*(pde))
    213 
    214 #define	pmap_pte_v(pte)		l2pte_valid(*(pte))
    215 #define	pmap_pte_pa(pte)	l2pte_pa(*(pte))
    216 
    217 
    218 /* Size of the kernel part of the L1 page table */
    219 #define KERNEL_PD_SIZE	\
    220 	(L1_TABLE_SIZE - (KERNEL_BASE >> L1_S_SHIFT) * sizeof(pd_entry_t))
    221 
    222 /*
    223  * tell MI code that the cache is virtually-indexed *and* virtually-tagged.
    224  */
    225 #define PMAP_CACHE_VIVT
    226 
    227 /*
    228  * These macros define the various bit masks in the PTE.
    229  *
    230  * We use these macros since we use different bits on different processor
    231  * models.
    232  */
    233 #define	L1_S_PROT_U		(L1_S_AP(AP_U))
    234 #define	L1_S_PROT_W		(L1_S_AP(AP_W))
    235 #define	L1_S_PROT_MASK		(L1_S_PROT_U|L1_S_PROT_W)
    236 
    237 #define	L1_S_CACHE_MASK		(L1_S_B|L1_S_C)
    238 
    239 #define	L2_L_PROT_U		(L2_AP(AP_U))
    240 #define	L2_L_PROT_W		(L2_AP(AP_W))
    241 #define	L2_L_PROT_MASK		(L2_L_PROT_U|L2_L_PROT_W)
    242 
    243 #define	L2_S_PROT_U		(L2_AP(AP_U))
    244 #define	L2_S_PROT_W		(L2_AP(AP_W))
    245 #define	L2_S_PROT_MASK		(L2_S_PROT_U|L2_S_PROT_W)
    246 
    247 #define	L2_CACHE_MASK		(L2_B|L2_C)
    248 
    249 /*
    250  * These macros return various bits based on kernel/user and protection.
    251  * Note that the compiler will usually fold these at compile time.
    252  */
    253 #define	L1_S_PROT(ku, pr)	((((ku) == PTE_USER) ? L1_S_PROT_U : 0) | \
    254 				 (((pr) & VM_PROT_WRITE) ? L1_S_PROT_W : 0))
    255 
    256 #define	L2_L_PROT(ku, pr)	((((ku) == PTE_USER) ? L2_L_PROT_U : 0) | \
    257 				 (((pr) & VM_PROT_WRITE) ? L2_L_PROT_W : 0))
    258 
    259 #define	L2_S_PROT(ku, pr)	((((ku) == PTE_USER) ? L2_S_PROT_U : 0) | \
    260 				 (((pr) & VM_PROT_WRITE) ? L2_S_PROT_W : 0))
    261 
    262 extern pt_entry_t		pte_cache_mode;
    263 
    264 /*
    265  * The following macros are used to construct prototype PTEs.
    266  */
    267 #define	L1_S_PROTO		(L1_TYPE_S | L1_S_IMP)	/* XXX IMP */
    268 #define	L1_C_PROTO		(L1_TYPE_C | L1_C_IMP2)	/* XXX IMP */
    269 
    270 #define	L2_L_PROTO		(L2_TYPE_L)
    271 
    272 #define	L2_S_PROTO		(L2_TYPE_S)
    273 
    274 #endif /* _KERNEL */
    275 
    276 #endif	/* _ARM32_PMAP_H_ */
    277