Home | History | Annotate | Line # | Download | only in oea
pmap.h revision 1.12
      1 /*	$NetBSD: pmap.h,v 1.12 2008/02/05 18:10:47 garbled Exp $	*/
      2 
      3 /*-
      4  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
      5  * Copyright (C) 1995, 1996 TooLs GmbH.
      6  * All rights reserved.
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     11  * 1. Redistributions of source code must retain the above copyright
     12  *    notice, this list of conditions and the following disclaimer.
     13  * 2. Redistributions in binary form must reproduce the above copyright
     14  *    notice, this list of conditions and the following disclaimer in the
     15  *    documentation and/or other materials provided with the distribution.
     16  * 3. All advertising materials mentioning features or use of this software
     17  *    must display the following acknowledgement:
     18  *	This product includes software developed by TooLs GmbH.
     19  * 4. The name of TooLs GmbH may not be used to endorse or promote products
     20  *    derived from this software without specific prior written permission.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
     23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     26  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     27  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     28  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     29  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     30  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     31  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32  */
     33 
     34 #ifndef	_POWERPC_OEA_PMAP_H_
     35 #define	_POWERPC_OEA_PMAP_H_
     36 
     37 #include "opt_ppcarch.h"
     38 #include <powerpc/oea/pte.h>
     39 
     40 #ifndef _LOCORE
     41 /*
     42  * Pmap stuff
     43  */
     44 struct pmap {
     45 #ifdef PPC_OEA64
     46 	struct steg *pm_steg_table;		/* segment table pointer */
     47 	/* XXX need way to track exec pages */
     48 #endif
     49 
     50 #if defined(PPC_OEA) || defined (PPC_OEA64_BRIDGE)
     51 	register_t pm_sr[16];			/* segments used in this pmap */
     52 	int pm_exec[16];			/* counts of exec mappings */
     53 #endif
     54 	register_t pm_vsid;			/* VSID bits */
     55 	int pm_refs;				/* ref count */
     56 	struct pmap_statistics pm_stats;	/* pmap statistics */
     57 	unsigned int pm_evictions;		/* pvo's not in page table */
     58 
     59 #ifdef PPC_OEA64
     60 	unsigned int pm_ste_evictions;
     61 #endif
     62 };
     63 
     64 typedef	struct pmap *pmap_t;
     65 
     66 struct pmap_ops {
     67 	int (*pmapop_pte_spill)(struct pmap *, vaddr_t, bool);
     68 	void (*pmapop_real_memory)(paddr_t *, psize_t *);
     69 	void (*pmapop_init)(void);
     70 	void (*pmapop_virtual_space)(vaddr_t *, vaddr_t *);
     71 	pmap_t (*pmapop_create)(void);
     72 	void (*pmapop_reference)(pmap_t);
     73 	void (*pmapop_destroy)(pmap_t);
     74 	void (*pmapop_copy)(pmap_t, pmap_t, vaddr_t, vsize_t, vaddr_t);
     75 	void (*pmapop_update)(pmap_t);
     76 	void (*pmapop_collect)(pmap_t);
     77 	int (*pmapop_enter)(pmap_t, vaddr_t, paddr_t, vm_prot_t, int);
     78 	void (*pmapop_remove)(pmap_t, vaddr_t, vaddr_t);
     79 	void (*pmapop_kenter_pa)(vaddr_t, paddr_t, vm_prot_t);
     80 	void (*pmapop_kremove)(vaddr_t, vsize_t);
     81 	bool (*pmapop_extract)(pmap_t, vaddr_t, paddr_t *);
     82 
     83 	void (*pmapop_protect)(pmap_t, vaddr_t, vaddr_t, vm_prot_t);
     84 	void (*pmapop_unwire)(pmap_t, vaddr_t);
     85 	void (*pmapop_page_protect)(struct vm_page *, vm_prot_t);
     86 	bool (*pmapop_query_bit)(struct vm_page *, int);
     87 	bool (*pmapop_clear_bit)(struct vm_page *, int);
     88 
     89 	void (*pmapop_activate)(struct lwp *);
     90 	void (*pmapop_deactivate)(struct lwp *);
     91 
     92 	void (*pmapop_pinit)(pmap_t);
     93 	void (*pmapop_procwr)(struct proc *, vaddr_t, size_t);
     94 
     95 	void (*pmapop_pte_print)(volatile struct pte *);
     96 	void (*pmapop_pteg_check)(void);
     97 	void (*pmapop_print_mmuregs)(void);
     98 	void (*pmapop_print_pte)(pmap_t, vaddr_t);
     99 	void (*pmapop_pteg_dist)(void);
    100 	void (*pmapop_pvo_verify)(void);
    101 	vaddr_t (*pmapop_steal_memory)(vsize_t, vaddr_t *, vaddr_t *);
    102 	void (*pmapop_bootstrap)(paddr_t, paddr_t);
    103 };
    104 
    105 #ifdef	_KERNEL
    106 #include <sys/cdefs.h>
    107 __BEGIN_DECLS
    108 #include <sys/param.h>
    109 #include <sys/systm.h>
    110 
    111 #if defined (PPC_OEA) || defined (PPC_OEA64_BRIDGE)
    112 extern register_t iosrtable[];
    113 #endif
    114 extern int pmap_use_altivec;
    115 extern struct pmap kernel_pmap_;
    116 #define	pmap_kernel()	(&kernel_pmap_)
    117 
    118 #define pmap_clear_modify(pg)		(pmap_clear_bit((pg), PTE_CHG))
    119 #define	pmap_clear_reference(pg)	(pmap_clear_bit((pg), PTE_REF))
    120 #define	pmap_is_modified(pg)		(pmap_query_bit((pg), PTE_CHG))
    121 #define	pmap_is_referenced(pg)		(pmap_query_bit((pg), PTE_REF))
    122 
    123 #define	pmap_phys_address(x)		(x)
    124 
    125 #define	pmap_resident_count(pmap)	((pmap)->pm_stats.resident_count)
    126 #define	pmap_wired_count(pmap)		((pmap)->pm_stats.wired_count)
    127 
    128 /* ARGSUSED */
    129 static inline void
    130 pmap_remove_all(struct pmap *pmap)
    131 {
    132 	/* Nothing. */
    133 }
    134 
    135 #if (defined(PPC_OEA) + defined(PPC_OEA64) + defined(PPC_OEA64_BRIDGE)) == 1
    136 /*nop*/
    137 #else
    138 #define	PMAP_EXCLUDE_DECLS
    139 #endif
    140 
    141 #ifndef PMAP_NOOPNAMES
    142 
    143 #if !defined(PMAP_EXCLUDE_DECLS)
    144 void pmap_bootstrap(vaddr_t, vaddr_t);
    145 bool pmap_extract(pmap_t, vaddr_t, paddr_t *);
    146 bool pmap_query_bit(struct vm_page *, int);
    147 bool pmap_clear_bit(struct vm_page *, int);
    148 void pmap_real_memory(paddr_t *, psize_t *);
    149 void pmap_procwr(struct proc *, vaddr_t, size_t);
    150 int pmap_pte_spill(pmap_t, vaddr_t, bool);
    151 void pmap_pinit(pmap_t);
    152 
    153 #else
    154 #define	PMAPOPNAME(name) (*pmapops->pmapop_##name)
    155 extern const struct pmap_ops *pmapops;
    156 #define	pmap_pte_spill		PMAPOPNAME(pte_spill)
    157 #define	pmap_real_memory	PMAPOPNAME(real_memory)
    158 #define	pmap_init		PMAPOPNAME(init)
    159 #define	pmap_virtual_space	PMAPOPNAME(virtual_space)
    160 #define	pmap_create		PMAPOPNAME(create)
    161 #define	pmap_reference		PMAPOPNAME(reference)
    162 #define	pmap_destroy		PMAPOPNAME(destroy)
    163 #define	pmap_copy		PMAPOPNAME(copy)
    164 #define	pmap_update		PMAPOPNAME(update)
    165 #define	pmap_collect		PMAPOPNAME(collect)
    166 #define	pmap_enter		PMAPOPNAME(enter)
    167 #define	pmap_remove		PMAPOPNAME(remove)
    168 #define	pmap_kenter_pa		PMAPOPNAME(kenter_pa)
    169 #define	pmap_kremove		PMAPOPNAME(kremove)
    170 #define	pmap_extract		PMAPOPNAME(extract)
    171 #define	pmap_protect		PMAPOPNAME(protect)
    172 #define	pmap_unwire		PMAPOPNAME(unwire)
    173 #define	pmap_page_protect	PMAPOPNAME(page_protect)
    174 #define	pmap_query_bit		PMAPOPNAME(query_bit)
    175 #define	pmap_clear_bit		PMAPOPNAME(clear_bit)
    176 
    177 #define	pmap_activate		PMAPOPNAME(activate)
    178 #define	pmap_deactivate		PMAPOPNAME(deactivate)
    179 
    180 #define	pmap_pinit		PMAPOPNAME(pinit)
    181 #define	pmap_procwr		PMAPOPNAME(procwr)
    182 
    183 #define	pmap_pte_print		PMAPOPNAME(pte_print)
    184 #define	pmap_pteg_check		PMAPOPNAME(pteg_check)
    185 #define	pmap_print_mmuregs	PMAPOPNAME(print_mmuregs)
    186 #define	pmap_print_pte		PMAPOPNAME(print_pte)
    187 #define	pmap_pteg_dist		PMAPOPNAME(pteg_dist)
    188 #define	pmap_pvo_verify		PMAPOPNAME(pvo_verify)
    189 #define	pmap_steal_memory	PMAPOPNAME(steal_memory)
    190 #define	pmap_bootstrap		PMAPOPNAME(bootstrap)
    191 #endif /* PMAP_EXCLUDE_DECLS */
    192 
    193 static inline paddr_t vtophys (vaddr_t);
    194 
    195 /*
    196  * Alternate mapping hooks for pool pages.  Avoids thrashing the TLB.
    197  *
    198  * Note: This won't work if we have more memory than can be direct-mapped
    199  * VA==PA all at once.  But pmap_copy_page() and pmap_zero_page() will have
    200  * this problem, too.
    201  */
    202 #if !defined(PPC_OEA64) && !defined (PPC_OEA64_BRIDGE)
    203 #define	PMAP_MAP_POOLPAGE(pa)	(pa)
    204 #define	PMAP_UNMAP_POOLPAGE(pa)	(pa)
    205 #define POOL_VTOPHYS(va)	vtophys((vaddr_t) va)
    206 #endif
    207 
    208 static inline paddr_t
    209 vtophys(vaddr_t va)
    210 {
    211 	paddr_t pa;
    212 
    213 	if (pmap_extract(pmap_kernel(), va, &pa))
    214 		return pa;
    215 	KASSERT(0);
    216 	return (paddr_t) -1;
    217 }
    218 
    219 extern const struct pmap_ops *pmapops;
    220 extern const struct pmap_ops pmap32_ops;
    221 extern const struct pmap_ops pmap64_ops;
    222 extern const struct pmap_ops pmap64bridge_ops;
    223 
    224 static inline void
    225 pmap_setup32(void)
    226 {
    227 	pmapops = &pmap32_ops;
    228 }
    229 
    230 static inline void
    231 pmap_setup64(void)
    232 {
    233 	pmapops = &pmap64_ops;
    234 }
    235 
    236 static inline void
    237 pmap_setup64bridge(void)
    238 {
    239 	pmapops = &pmap64bridge_ops;
    240 }
    241 
    242 #endif /* !PMAP_NOOPNAMES */
    243 
    244 bool pmap_pageidlezero (paddr_t);
    245 void pmap_syncicache (paddr_t, psize_t);
    246 #ifdef PPC_OEA64
    247 vaddr_t pmap_setusr (vaddr_t);
    248 vaddr_t pmap_unsetusr (void);
    249 #endif
    250 
    251 #ifdef PPC_OEA64_BRIDGE
    252 int pmap_setup_segment0_map(int use_large_pages, ...);
    253 #endif
    254 
    255 #define	PMAP_NC			0x1000
    256 #define PMAP_STEAL_MEMORY
    257 #define PMAP_NEED_PROCWR
    258 
    259 void pmap_zero_page(paddr_t);
    260 void pmap_copy_page(paddr_t, paddr_t);
    261 
    262 __END_DECLS
    263 #endif	/* _KERNEL */
    264 #endif	/* _LOCORE */
    265 
    266 #endif	/* _POWERPC_OEA_PMAP_H_ */
    267