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