Home | History | Annotate | Line # | Download | only in ibm4xx
pmap.h revision 1.2.4.3
      1  1.2.4.3  nathanw /*	$NetBSD: pmap.h,v 1.2.4.3 2002/10/18 02:39:31 nathanw Exp $	*/
      2  1.2.4.2  nathanw 
      3  1.2.4.2  nathanw /*
      4  1.2.4.2  nathanw  * Copyright 2001 Wasabi Systems, Inc.
      5  1.2.4.2  nathanw  * All rights reserved.
      6  1.2.4.2  nathanw  *
      7  1.2.4.2  nathanw  * Written by Eduardo Horvath and Simon Burge for Wasabi Systems, Inc.
      8  1.2.4.2  nathanw  *
      9  1.2.4.2  nathanw  * Redistribution and use in source and binary forms, with or without
     10  1.2.4.2  nathanw  * modification, are permitted provided that the following conditions
     11  1.2.4.2  nathanw  * are met:
     12  1.2.4.2  nathanw  * 1. Redistributions of source code must retain the above copyright
     13  1.2.4.2  nathanw  *    notice, this list of conditions and the following disclaimer.
     14  1.2.4.2  nathanw  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.2.4.2  nathanw  *    notice, this list of conditions and the following disclaimer in the
     16  1.2.4.2  nathanw  *    documentation and/or other materials provided with the distribution.
     17  1.2.4.2  nathanw  * 3. All advertising materials mentioning features or use of this software
     18  1.2.4.2  nathanw  *    must display the following acknowledgement:
     19  1.2.4.2  nathanw  *      This product includes software developed for the NetBSD Project by
     20  1.2.4.2  nathanw  *      Wasabi Systems, Inc.
     21  1.2.4.2  nathanw  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     22  1.2.4.2  nathanw  *    or promote products derived from this software without specific prior
     23  1.2.4.2  nathanw  *    written permission.
     24  1.2.4.2  nathanw  *
     25  1.2.4.2  nathanw  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     26  1.2.4.2  nathanw  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27  1.2.4.2  nathanw  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28  1.2.4.2  nathanw  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     29  1.2.4.2  nathanw  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30  1.2.4.2  nathanw  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31  1.2.4.2  nathanw  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32  1.2.4.2  nathanw  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33  1.2.4.2  nathanw  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34  1.2.4.2  nathanw  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35  1.2.4.2  nathanw  * POSSIBILITY OF SUCH DAMAGE.
     36  1.2.4.2  nathanw  */
     37  1.2.4.2  nathanw 
     38  1.2.4.2  nathanw /*-
     39  1.2.4.2  nathanw  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
     40  1.2.4.2  nathanw  * Copyright (C) 1995, 1996 TooLs GmbH.
     41  1.2.4.2  nathanw  * All rights reserved.
     42  1.2.4.2  nathanw  *
     43  1.2.4.2  nathanw  * Redistribution and use in source and binary forms, with or without
     44  1.2.4.2  nathanw  * modification, are permitted provided that the following conditions
     45  1.2.4.2  nathanw  * are met:
     46  1.2.4.2  nathanw  * 1. Redistributions of source code must retain the above copyright
     47  1.2.4.2  nathanw  *    notice, this list of conditions and the following disclaimer.
     48  1.2.4.2  nathanw  * 2. Redistributions in binary form must reproduce the above copyright
     49  1.2.4.2  nathanw  *    notice, this list of conditions and the following disclaimer in the
     50  1.2.4.2  nathanw  *    documentation and/or other materials provided with the distribution.
     51  1.2.4.2  nathanw  * 3. All advertising materials mentioning features or use of this software
     52  1.2.4.2  nathanw  *    must display the following acknowledgement:
     53  1.2.4.2  nathanw  *	This product includes software developed by TooLs GmbH.
     54  1.2.4.2  nathanw  * 4. The name of TooLs GmbH may not be used to endorse or promote products
     55  1.2.4.2  nathanw  *    derived from this software without specific prior written permission.
     56  1.2.4.2  nathanw  *
     57  1.2.4.2  nathanw  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
     58  1.2.4.2  nathanw  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     59  1.2.4.2  nathanw  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     60  1.2.4.2  nathanw  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     61  1.2.4.2  nathanw  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     62  1.2.4.2  nathanw  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     63  1.2.4.2  nathanw  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     64  1.2.4.2  nathanw  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     65  1.2.4.2  nathanw  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     66  1.2.4.2  nathanw  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     67  1.2.4.2  nathanw  */
     68  1.2.4.2  nathanw 
     69  1.2.4.2  nathanw #ifndef	_IBM4XX_PMAP_H_
     70  1.2.4.2  nathanw #define	_IBM4XX_PMAP_H_
     71  1.2.4.2  nathanw 
     72  1.2.4.2  nathanw #include <powerpc/ibm4xx/pte.h>
     73  1.2.4.2  nathanw #include <powerpc/ibm4xx/tlb.h>
     74  1.2.4.2  nathanw 
     75  1.2.4.2  nathanw #define KERNEL_PID	1	/* TLB PID to use for kernel translation */
     76  1.2.4.2  nathanw 
     77  1.2.4.2  nathanw /*
     78  1.2.4.2  nathanw  * A TTE is a 16KB or greater TLB entry w/size and endiannes bits
     79  1.2.4.2  nathanw  * stuffed in the (unused) low bits of the PA.
     80  1.2.4.2  nathanw  */
     81  1.2.4.2  nathanw #define	TTE_PA_MASK		0xffffc000
     82  1.2.4.2  nathanw #define	TTE_RPN_MASK(sz)	(~((1 << (10 + 2 * (sz))) - 1))
     83  1.2.4.2  nathanw #define	TTE_ENDIAN		0x00002000
     84  1.2.4.2  nathanw #define	TTE_SZ_MASK		0x00001c00
     85  1.2.4.2  nathanw #define	TTE_SZ_SHIFT		10
     86  1.2.4.2  nathanw 
     87  1.2.4.2  nathanw /* TTE_SZ_1K and TTE_SZ_4K are not allowed. */
     88  1.2.4.2  nathanw #define	TTE_SZ_16K	(TLB_SIZE_16K << TTE_SZ_SHIFT)
     89  1.2.4.2  nathanw #define	TTE_SZ_64K	(TLB_SIZE_64K << TTE_SZ_SHIFT)
     90  1.2.4.2  nathanw #define	TTE_SZ_256K	(TLB_SIZE_256K << TTE_SZ_SHIFT)
     91  1.2.4.2  nathanw #define	TTE_SZ_1M	(TLB_SIZE_1M << TTE_SZ_SHIFT)
     92  1.2.4.2  nathanw #define	TTE_SZ_4M	(TLB_SIZE_4M << TTE_SZ_SHIFT)
     93  1.2.4.2  nathanw #define	TTE_SZ_16M	(TLB_SIZE_16M << TTE_SZ_SHIFT)
     94  1.2.4.2  nathanw 
     95  1.2.4.2  nathanw #define	TTE_EX		TLB_EX
     96  1.2.4.2  nathanw #define	TTE_WR		TLB_WR
     97  1.2.4.2  nathanw #define TTE_ZSEL_MASK	TLB_ZSEL_MASK
     98  1.2.4.2  nathanw #define TTE_ZSEL_SHFT	TLB_ZSEL_SHFT
     99  1.2.4.2  nathanw #define TTE_W		TLB_W
    100  1.2.4.2  nathanw #define TTE_I		TLB_I
    101  1.2.4.2  nathanw #define TTE_M		TLB_M
    102  1.2.4.2  nathanw #define TTE_G		TLB_G
    103  1.2.4.2  nathanw 
    104  1.2.4.2  nathanw #define	ZONE_PRIV	0
    105  1.2.4.2  nathanw #define	ZONE_USER	1
    106  1.2.4.2  nathanw 
    107  1.2.4.2  nathanw #define	TTE_PA(p)	((p)&TTE_PA_MASK)
    108  1.2.4.2  nathanw #define TTE_ZONE(z)	TLB_ZONE(z)
    109  1.2.4.2  nathanw 
    110  1.2.4.2  nathanw #define	MKTTE(pa,sz,zn,e,fl)	(((pa)&TTE_PA_MASK)|((sz)&TTE_SZ_MASK)|\
    111  1.2.4.2  nathanw 	(TTE_ZONE(zn))|(fl)|((e)?TTE_ENDIAN:0)
    112  1.2.4.2  nathanw 
    113  1.2.4.2  nathanw /*
    114  1.2.4.2  nathanw  * Definitions for sizes of 1st and 2nd level page tables.
    115  1.2.4.2  nathanw  *
    116  1.2.4.2  nathanw  */
    117  1.2.4.2  nathanw #define	PTSZ		(NBPG / 4)
    118  1.2.4.2  nathanw #define	PTMAP		(PTSZ * NBPG)
    119  1.2.4.2  nathanw #define	PTMSK		((PTMAP - 1) & ~(PGOFSET))
    120  1.2.4.2  nathanw 
    121  1.2.4.2  nathanw #define	PTIDX(v)	(((v) & PTMSK) >> PGSHIFT)
    122  1.2.4.2  nathanw 
    123  1.2.4.2  nathanw /* 2nd level tables map in any bits not mapped by 1st level tables. */
    124  1.2.4.2  nathanw #define	STSZ		((0xffffffffU / (NBPG * PTSZ)) + 1)
    125  1.2.4.2  nathanw #define	STMAP		(0xffffffffU)
    126  1.2.4.2  nathanw #define	STMSK		(~(PTMAP - 1))
    127  1.2.4.2  nathanw 
    128  1.2.4.2  nathanw #define	STIDX(v)	((v) >> (PGSHIFT + 12))
    129  1.2.4.2  nathanw 
    130  1.2.4.2  nathanw 
    131  1.2.4.2  nathanw /*
    132  1.2.4.2  nathanw  * Extra flags to pass to pmap_enter() -- make sure they don't conflict
    133  1.2.4.2  nathanw  * w/PMAP_CANFAIL or PMAP_WIRED
    134  1.2.4.2  nathanw  */
    135  1.2.4.2  nathanw #define	PME_NOCACHE	0x100
    136  1.2.4.2  nathanw #define	PME_WRITETHROUG	0x200
    137  1.2.4.2  nathanw 
    138  1.2.4.2  nathanw #ifndef _LOCORE
    139  1.2.4.2  nathanw 
    140  1.2.4.2  nathanw /*
    141  1.2.4.2  nathanw  * Pmap stuff
    142  1.2.4.2  nathanw  */
    143  1.2.4.2  nathanw struct pmap {
    144  1.2.4.2  nathanw 	volatile tlbpid_t pm_ctx;	/* PID to identify PMAP's entries in TLB */
    145  1.2.4.2  nathanw 	int pm_refs;			/* ref count */
    146  1.2.4.2  nathanw 	struct pmap_statistics pm_stats; /* pmap statistics */
    147  1.2.4.2  nathanw 	volatile u_int *pm_ptbl[STSZ];	/* Array of 64 pointers to page tables. */
    148  1.2.4.2  nathanw };
    149  1.2.4.2  nathanw 
    150  1.2.4.2  nathanw typedef	struct pmap *pmap_t;
    151  1.2.4.2  nathanw 
    152  1.2.4.2  nathanw #ifdef	_KERNEL
    153  1.2.4.2  nathanw #define	PMAP_GROWKERNEL
    154  1.2.4.2  nathanw extern struct pmap kernel_pmap_;
    155  1.2.4.2  nathanw #define	pmap_kernel()	(&kernel_pmap_)
    156  1.2.4.2  nathanw 
    157  1.2.4.2  nathanw #define pmap_clear_modify(pg)		(check_attr((pg), PTE_HI_CHG, 1))
    158  1.2.4.2  nathanw #define	pmap_clear_reference(pg)	(check_attr((pg), PTE_HI_REF, 1))
    159  1.2.4.2  nathanw #define	pmap_is_modified(pg)		(check_attr((pg), PTE_HI_CHG, 0))
    160  1.2.4.2  nathanw #define	pmap_is_referenced(pg)		(check_attr((pg), PTE_HI_REF, 0))
    161  1.2.4.2  nathanw 
    162  1.2.4.2  nathanw #define	pmap_phys_address(x)		(x)
    163  1.2.4.2  nathanw 
    164  1.2.4.2  nathanw #define	pmap_resident_count(pmap)	((pmap)->pm_stats.resident_count)
    165  1.2.4.2  nathanw 
    166  1.2.4.2  nathanw void pmap_unwire(struct pmap *pm, vaddr_t va);
    167  1.2.4.2  nathanw void pmap_bootstrap(u_int kernelstart, u_int kernelend);
    168  1.2.4.2  nathanw boolean_t pmap_extract(struct pmap *, vaddr_t, paddr_t *);
    169  1.2.4.2  nathanw boolean_t check_attr(struct vm_page *, u_int, int);
    170  1.2.4.2  nathanw int ptereadonly(struct vm_page *);
    171  1.2.4.2  nathanw void pmap_real_memory(paddr_t *, psize_t *);
    172  1.2.4.2  nathanw int pmap_tlbmiss(vaddr_t va, int ctx);
    173  1.2.4.2  nathanw 
    174  1.2.4.3  nathanw static __inline void
    175  1.2.4.3  nathanw pmap_remove_all(struct pmap *pmap)
    176  1.2.4.3  nathanw {
    177  1.2.4.3  nathanw 	/* Nothing. */
    178  1.2.4.3  nathanw }
    179  1.2.4.3  nathanw 
    180  1.2.4.2  nathanw int	ctx_alloc(struct pmap*);
    181  1.2.4.2  nathanw void	ctx_free(struct pmap*);
    182  1.2.4.2  nathanw 
    183  1.2.4.2  nathanw #define PMAP_NEED_PROCWR
    184  1.2.4.2  nathanw void pmap_procwr(struct proc *, vaddr_t, size_t);
    185  1.2.4.2  nathanw 
    186  1.2.4.2  nathanw /*
    187  1.2.4.2  nathanw  * Alternate mapping hooks for pool pages.  Avoids thrashing the TLB.
    188  1.2.4.2  nathanw  *
    189  1.2.4.2  nathanw  * Note: This won't work if we have more memory than can be direct-mapped
    190  1.2.4.2  nathanw  * VA==PA all at once.  But pmap_copy_page() and pmap_zero_page() will have
    191  1.2.4.2  nathanw  * this problem, too.
    192  1.2.4.2  nathanw  */
    193  1.2.4.2  nathanw #define	PMAP_MAP_POOLPAGE(pa)	(pa)
    194  1.2.4.2  nathanw #define	PMAP_UNMAP_POOLPAGE(pa)	(pa)
    195  1.2.4.2  nathanw 
    196  1.2.4.2  nathanw static __inline paddr_t vtophys(vaddr_t);
    197  1.2.4.2  nathanw 
    198  1.2.4.2  nathanw static __inline paddr_t
    199  1.2.4.2  nathanw vtophys(vaddr_t va)
    200  1.2.4.2  nathanw {
    201  1.2.4.2  nathanw 	paddr_t pa;
    202  1.2.4.2  nathanw 
    203  1.2.4.2  nathanw 	/* XXX should check battable */
    204  1.2.4.2  nathanw 
    205  1.2.4.2  nathanw 	if (pmap_extract(pmap_kernel(), va, &pa))
    206  1.2.4.2  nathanw 		return pa;
    207  1.2.4.2  nathanw 	return va;
    208  1.2.4.2  nathanw }
    209  1.2.4.2  nathanw #endif	/* _KERNEL */
    210  1.2.4.2  nathanw #endif	/* _LOCORE */
    211  1.2.4.2  nathanw #endif	/* _IBM4XX_PMAP_H_ */
    212