Home | History | Annotate | Line # | Download | only in ibm4xx
pmap.h revision 1.13.52.1
      1  1.13.52.1     haad /*	$NetBSD: pmap.h,v 1.13.52.1 2008/12/13 01:13:23 haad 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/tlb.h>
     73        1.1   simonb 
     74        1.1   simonb #define KERNEL_PID	1	/* TLB PID to use for kernel translation */
     75        1.1   simonb 
     76        1.1   simonb /*
     77        1.1   simonb  * A TTE is a 16KB or greater TLB entry w/size and endiannes bits
     78        1.1   simonb  * stuffed in the (unused) low bits of the PA.
     79        1.1   simonb  */
     80        1.1   simonb #define	TTE_PA_MASK		0xffffc000
     81        1.3      eeh #define	TTE_RPN_MASK(sz)	(~((1 << (10 + 2 * (sz))) - 1))
     82        1.3      eeh #define	TTE_ENDIAN		0x00002000
     83        1.1   simonb #define	TTE_SZ_MASK		0x00001c00
     84        1.1   simonb #define	TTE_SZ_SHIFT		10
     85        1.1   simonb 
     86        1.1   simonb /* TTE_SZ_1K and TTE_SZ_4K are not allowed. */
     87        1.1   simonb #define	TTE_SZ_16K	(TLB_SIZE_16K << TTE_SZ_SHIFT)
     88        1.1   simonb #define	TTE_SZ_64K	(TLB_SIZE_64K << TTE_SZ_SHIFT)
     89        1.1   simonb #define	TTE_SZ_256K	(TLB_SIZE_256K << TTE_SZ_SHIFT)
     90        1.1   simonb #define	TTE_SZ_1M	(TLB_SIZE_1M << TTE_SZ_SHIFT)
     91        1.1   simonb #define	TTE_SZ_4M	(TLB_SIZE_4M << TTE_SZ_SHIFT)
     92        1.1   simonb #define	TTE_SZ_16M	(TLB_SIZE_16M << TTE_SZ_SHIFT)
     93        1.1   simonb 
     94        1.1   simonb #define	TTE_EX		TLB_EX
     95        1.1   simonb #define	TTE_WR		TLB_WR
     96        1.1   simonb #define TTE_ZSEL_MASK	TLB_ZSEL_MASK
     97        1.1   simonb #define TTE_ZSEL_SHFT	TLB_ZSEL_SHFT
     98        1.1   simonb #define TTE_W		TLB_W
     99        1.1   simonb #define TTE_I		TLB_I
    100        1.1   simonb #define TTE_M		TLB_M
    101        1.1   simonb #define TTE_G		TLB_G
    102        1.1   simonb 
    103        1.1   simonb #define	ZONE_PRIV	0
    104        1.1   simonb #define	ZONE_USER	1
    105        1.1   simonb 
    106        1.1   simonb #define	TTE_PA(p)	((p)&TTE_PA_MASK)
    107        1.1   simonb #define TTE_ZONE(z)	TLB_ZONE(z)
    108        1.1   simonb 
    109        1.1   simonb /*
    110        1.1   simonb  * Definitions for sizes of 1st and 2nd level page tables.
    111        1.1   simonb  *
    112        1.1   simonb  */
    113        1.6  thorpej #define	PTSZ		(PAGE_SIZE / 4)
    114        1.6  thorpej #define	PTMAP		(PTSZ * PAGE_SIZE)
    115        1.1   simonb #define	PTMSK		((PTMAP - 1) & ~(PGOFSET))
    116        1.1   simonb 
    117        1.1   simonb #define	PTIDX(v)	(((v) & PTMSK) >> PGSHIFT)
    118        1.1   simonb 
    119        1.1   simonb /* 2nd level tables map in any bits not mapped by 1st level tables. */
    120        1.6  thorpej #define	STSZ		((0xffffffffU / (PAGE_SIZE * PTSZ)) + 1)
    121        1.1   simonb #define	STMAP		(0xffffffffU)
    122        1.1   simonb #define	STMSK		(~(PTMAP - 1))
    123        1.1   simonb 
    124        1.1   simonb #define	STIDX(v)	((v) >> (PGSHIFT + 12))
    125        1.1   simonb 
    126        1.1   simonb 
    127        1.1   simonb /*
    128        1.1   simonb  * Extra flags to pass to pmap_enter() -- make sure they don't conflict
    129        1.1   simonb  * w/PMAP_CANFAIL or PMAP_WIRED
    130        1.1   simonb  */
    131        1.1   simonb #define	PME_NOCACHE	0x100
    132        1.1   simonb #define	PME_WRITETHROUG	0x200
    133        1.7      scw #define	PMAP_NC		PME_NOCACHE	/* XXX: OEA pmap compat. for bus_dma */
    134        1.1   simonb 
    135        1.1   simonb #ifndef _LOCORE
    136        1.1   simonb 
    137        1.1   simonb /*
    138        1.1   simonb  * Pmap stuff
    139        1.1   simonb  */
    140        1.1   simonb struct pmap {
    141        1.1   simonb 	volatile tlbpid_t pm_ctx;	/* PID to identify PMAP's entries in TLB */
    142        1.1   simonb 	int pm_refs;			/* ref count */
    143        1.1   simonb 	struct pmap_statistics pm_stats; /* pmap statistics */
    144        1.1   simonb 	volatile u_int *pm_ptbl[STSZ];	/* Array of 64 pointers to page tables. */
    145        1.1   simonb };
    146        1.1   simonb 
    147        1.1   simonb #ifdef	_KERNEL
    148        1.2      eeh #define	PMAP_GROWKERNEL
    149        1.1   simonb 
    150       1.10      chs #define	PMAP_ATTR_REF		0x1
    151       1.10      chs #define	PMAP_ATTR_CHG		0x2
    152       1.10      chs 
    153       1.10      chs #define pmap_clear_modify(pg)	(pmap_check_attr((pg), PMAP_ATTR_CHG, 1))
    154       1.10      chs #define	pmap_clear_reference(pg)(pmap_check_attr((pg), PMAP_ATTR_REF, 1))
    155       1.10      chs #define	pmap_is_modified(pg)	(pmap_check_attr((pg), PMAP_ATTR_CHG, 0))
    156       1.10      chs #define	pmap_is_referenced(pg)	(pmap_check_attr((pg), PMAP_ATTR_REF, 0))
    157        1.1   simonb 
    158        1.1   simonb #define	pmap_phys_address(x)		(x)
    159        1.1   simonb 
    160        1.1   simonb #define	pmap_resident_count(pmap)	((pmap)->pm_stats.resident_count)
    161       1.10      chs #define	pmap_wired_count(pmap)		((pmap)->pm_stats.wired_count)
    162        1.1   simonb 
    163        1.1   simonb void pmap_unwire(struct pmap *pm, vaddr_t va);
    164        1.1   simonb void pmap_bootstrap(u_int kernelstart, u_int kernelend);
    165       1.13  thorpej bool pmap_extract(struct pmap *, vaddr_t, paddr_t *);
    166       1.13  thorpej bool pmap_check_attr(struct vm_page *, u_int, int);
    167        1.1   simonb void pmap_real_memory(paddr_t *, psize_t *);
    168        1.1   simonb int pmap_tlbmiss(vaddr_t va, int ctx);
    169        1.4      chs 
    170       1.12    perry static inline void
    171        1.5      chs pmap_remove_all(struct pmap *pmap)
    172        1.4      chs {
    173        1.4      chs 	/* Nothing. */
    174        1.4      chs }
    175        1.1   simonb 
    176       1.10      chs int	ctx_alloc(struct pmap *);
    177       1.10      chs void	ctx_free(struct pmap *);
    178        1.1   simonb 
    179        1.1   simonb #define PMAP_NEED_PROCWR
    180        1.1   simonb void pmap_procwr(struct proc *, vaddr_t, size_t);
    181        1.1   simonb 
    182        1.1   simonb /*
    183        1.1   simonb  * Alternate mapping hooks for pool pages.  Avoids thrashing the TLB.
    184        1.1   simonb  *
    185        1.1   simonb  * Note: This won't work if we have more memory than can be direct-mapped
    186        1.1   simonb  * VA==PA all at once.  But pmap_copy_page() and pmap_zero_page() will have
    187        1.1   simonb  * this problem, too.
    188        1.1   simonb  */
    189        1.1   simonb #define	PMAP_MAP_POOLPAGE(pa)	(pa)
    190        1.1   simonb #define	PMAP_UNMAP_POOLPAGE(pa)	(pa)
    191        1.1   simonb 
    192       1.12    perry static inline paddr_t vtophys(vaddr_t);
    193        1.1   simonb 
    194       1.12    perry static inline paddr_t
    195        1.1   simonb vtophys(vaddr_t va)
    196        1.1   simonb {
    197        1.1   simonb 	paddr_t pa;
    198        1.1   simonb 
    199        1.1   simonb 	/* XXX should check battable */
    200        1.1   simonb 
    201        1.1   simonb 	if (pmap_extract(pmap_kernel(), va, &pa))
    202        1.1   simonb 		return pa;
    203        1.1   simonb 	return va;
    204        1.1   simonb }
    205        1.1   simonb #endif	/* _KERNEL */
    206        1.1   simonb #endif	/* _LOCORE */
    207        1.1   simonb #endif	/* _IBM4XX_PMAP_H_ */
    208