Home | History | Annotate | Line # | Download | only in include
pte.h revision 1.14
      1  1.14    simonb /*	$NetBSD: pte.h,v 1.14 2005/11/25 14:10:35 simonb Exp $	*/
      2   1.1  jonathan 
      3   1.3  jonathan /*-
      4   1.3  jonathan  * Copyright (c) 1997 The NetBSD Foundation, Inc.
      5   1.3  jonathan  * All rights reserved.
      6   1.3  jonathan  *
      7   1.3  jonathan  * This code is derived from software contributed to The NetBSD Foundation
      8   1.3  jonathan  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
      9   1.3  jonathan  * NASA Ames Research Center.
     10   1.3  jonathan  *
     11   1.3  jonathan  * Redistribution and use in source and binary forms, with or without
     12   1.3  jonathan  * modification, are permitted provided that the following conditions
     13   1.3  jonathan  * are met:
     14   1.3  jonathan  * 1. Redistributions of source code must retain the above copyright
     15   1.3  jonathan  *    notice, this list of conditions and the following disclaimer.
     16   1.3  jonathan  * 2. Redistributions in binary form must reproduce the above copyright
     17   1.3  jonathan  *    notice, this list of conditions and the following disclaimer in the
     18   1.3  jonathan  *    documentation and/or other materials provided with the distribution.
     19   1.3  jonathan  * 3. All advertising materials mentioning features or use of this software
     20   1.3  jonathan  *    must display the following acknowledgement:
     21   1.3  jonathan  *	This product includes software developed by the NetBSD
     22   1.3  jonathan  *	Foundation, Inc. and its contributors.
     23   1.3  jonathan  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24   1.3  jonathan  *    contributors may be used to endorse or promote products derived
     25   1.3  jonathan  *    from this software without specific prior written permission.
     26   1.3  jonathan  *
     27   1.3  jonathan  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28   1.3  jonathan  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29   1.3  jonathan  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30   1.3  jonathan  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31   1.3  jonathan  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32   1.3  jonathan  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33   1.3  jonathan  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34   1.3  jonathan  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35   1.3  jonathan  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36   1.3  jonathan  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37   1.3  jonathan  * POSSIBILITY OF SUCH DAMAGE.
     38   1.3  jonathan  */
     39   1.3  jonathan 
     40   1.1  jonathan /*
     41   1.1  jonathan  * Copyright 1996 The Board of Trustees of The Leland Stanford
     42   1.1  jonathan  * Junior University. All Rights Reserved.
     43   1.1  jonathan  *
     44   1.1  jonathan  * Permission to use, copy, modify, and distribute this
     45   1.1  jonathan  * software and its documentation for any purpose and without
     46   1.1  jonathan  * fee is hereby granted, provided that the above copyright
     47   1.1  jonathan  * notice appear in all copies.  Stanford University
     48   1.1  jonathan  * makes no representations about the suitability of this
     49   1.1  jonathan  * software for any purpose.  It is provided "as is" without
     50   1.1  jonathan  * express or implied warranty.
     51   1.1  jonathan  */
     52   1.1  jonathan 
     53   1.1  jonathan #ifndef  __MIPS_PTE_H__
     54   1.1  jonathan #define  __MIPS_PTE_H__
     55   1.1  jonathan 
     56   1.3  jonathan #include <mips/mips1_pte.h>
     57   1.3  jonathan #include <mips/mips3_pte.h>
     58   1.3  jonathan 
     59   1.3  jonathan #define	PG_ASID	0x000000ff	/* Address space ID */
     60   1.3  jonathan 
     61   1.3  jonathan #ifndef _LOCORE
     62   1.3  jonathan #include <mips/cpu.h>
     63   1.3  jonathan 
     64   1.3  jonathan typedef union pt_entry {
     65   1.3  jonathan 	unsigned int	 pt_entry;	/* for copying, etc. */
     66   1.3  jonathan 	struct mips1_pte pt_mips1_pte;	/* for getting to bits by name */
     67   1.3  jonathan 	struct mips3_pte pt_mips3_pte;
     68   1.3  jonathan } pt_entry_t;
     69   1.3  jonathan 
     70   1.3  jonathan /*
     71   1.3  jonathan  * Macros/inline functions to hide PTE format differences.
     72   1.3  jonathan  */
     73   1.3  jonathan 
     74   1.3  jonathan #define	mips_pg_nv_bit()	(MIPS1_PG_NV)	/* same on mips1 and mips3 */
     75   1.3  jonathan 
     76   1.3  jonathan 
     77   1.6  nisimura int pmap_is_page_ro(pmap_t, vaddr_t, int);
     78   1.3  jonathan 
     79   1.3  jonathan 
     80   1.3  jonathan /* MIPS1-only */
     81  1.12    simonb #if defined(MIPS1) && !defined(MIPS3_PLUS)
     82   1.3  jonathan #define	mips_pg_v(entry)	((entry) & MIPS1_PG_V)
     83   1.3  jonathan #define	mips_pg_wired(entry)	((entry) & MIPS1_PG_WIRED)
     84   1.3  jonathan 
     85   1.8  nisimura #define	mips_pg_m_bit()		(MIPS1_PG_D)
     86   1.3  jonathan #define	mips_pg_rw_bit()	(MIPS1_PG_RW)	/* no RW bits for mips1 */
     87   1.3  jonathan #define	mips_pg_ro_bit()	(MIPS1_PG_RO)
     88   1.3  jonathan #define	mips_pg_ropage_bit()	(MIPS1_PG_RO)	/* XXX not MIPS1_PG_ROPAGE? */
     89   1.3  jonathan #define	mips_pg_rwpage_bit()	(MIPS1_PG_RWPAGE)
     90   1.3  jonathan #define	mips_pg_cwpage_bit()	(MIPS1_PG_CWPAGE)
     91   1.3  jonathan #define	mips_pg_global_bit()	(MIPS1_PG_G)
     92   1.3  jonathan #define	mips_pg_wired_bit()	(MIPS1_PG_WIRED)
     93   1.3  jonathan 
     94   1.3  jonathan #define	PTE_TO_PADDR(pte)	MIPS1_PTE_TO_PADDR((pte))
     95   1.3  jonathan #define	PAGE_IS_RDONLY(pte, va)	MIPS1_PAGE_IS_RDONLY((pte), (va))
     96   1.3  jonathan 
     97  1.10      soda #define	mips_tlbpfn_to_paddr(x)		mips1_tlbpfn_to_paddr((vaddr_t)(x))
     98  1.10      soda #define	mips_paddr_to_tlbpfn(x)		mips1_paddr_to_tlbpfn((x))
     99   1.3  jonathan #endif /* mips1 */
    100   1.3  jonathan 
    101   1.3  jonathan 
    102  1.12    simonb /* MIPS3 (or greater) only */
    103  1.12    simonb #if !defined(MIPS1) && defined(MIPS3_PLUS)
    104   1.3  jonathan #define	mips_pg_v(entry)	((entry) & MIPS3_PG_V)
    105   1.3  jonathan #define	mips_pg_wired(entry)	((entry) & MIPS3_PG_WIRED)
    106   1.3  jonathan 
    107   1.8  nisimura #define	mips_pg_m_bit()		(MIPS3_PG_D)
    108   1.8  nisimura #define	mips_pg_rw_bit()	(MIPS3_PG_D)
    109   1.3  jonathan #define	mips_pg_ro_bit()	(MIPS3_PG_RO)
    110   1.3  jonathan #define	mips_pg_ropage_bit()	(MIPS3_PG_ROPAGE)
    111   1.3  jonathan #define	mips_pg_rwpage_bit()	(MIPS3_PG_RWPAGE)
    112   1.3  jonathan #define	mips_pg_cwpage_bit()	(MIPS3_PG_CWPAGE)
    113   1.3  jonathan #define	mips_pg_global_bit()	(MIPS3_PG_G)
    114   1.3  jonathan #define	mips_pg_wired_bit()	(MIPS3_PG_WIRED)
    115   1.1  jonathan 
    116   1.3  jonathan #define	PTE_TO_PADDR(pte)	MIPS3_PTE_TO_PADDR((pte))
    117   1.3  jonathan #define	PAGE_IS_RDONLY(pte, va)	MIPS3_PAGE_IS_RDONLY((pte), (va))
    118   1.3  jonathan 
    119  1.10      soda #define	mips_tlbpfn_to_paddr(x)		mips3_tlbpfn_to_paddr((vaddr_t)(x))
    120  1.10      soda #define	mips_paddr_to_tlbpfn(x)		mips3_paddr_to_tlbpfn((x))
    121   1.3  jonathan #endif /* mips3 */
    122   1.3  jonathan 
    123  1.12    simonb /* MIPS1 and MIPS3 (or greater) */
    124  1.12    simonb #if defined(MIPS1) && defined(MIPS3_PLUS)
    125   1.1  jonathan 
    126   1.3  jonathan static __inline int
    127   1.3  jonathan     mips_pg_v(unsigned int entry),
    128   1.3  jonathan     mips_pg_wired(unsigned int entry),
    129   1.6  nisimura     PAGE_IS_RDONLY(unsigned int pte, vaddr_t va);
    130   1.3  jonathan 
    131   1.3  jonathan static __inline unsigned int
    132   1.3  jonathan     mips_pg_wired_bit(void), mips_pg_m_bit(void),
    133   1.3  jonathan     mips_pg_ro_bit(void), mips_pg_rw_bit(void),
    134   1.3  jonathan     mips_pg_ropage_bit(void),
    135   1.3  jonathan     mips_pg_cwpage_bit(void),
    136   1.3  jonathan     mips_pg_rwpage_bit(void),
    137   1.9      soda     mips_pg_global_bit(void);
    138   1.9      soda static __inline paddr_t PTE_TO_PADDR(unsigned int pte);
    139   1.3  jonathan 
    140  1.10      soda static __inline paddr_t mips_tlbpfn_to_paddr(unsigned int pfn);
    141  1.10      soda static __inline unsigned int mips_paddr_to_tlbpfn(paddr_t pa);
    142   1.3  jonathan 
    143   1.3  jonathan 
    144   1.3  jonathan static __inline int
    145   1.3  jonathan mips_pg_v(entry)
    146   1.3  jonathan 	unsigned int entry;
    147   1.3  jonathan {
    148  1.12    simonb 	if (MIPS_HAS_R4K_MMU)
    149   1.3  jonathan 		return (entry & MIPS3_PG_V);
    150   1.3  jonathan 	return (entry & MIPS1_PG_V);
    151   1.3  jonathan }
    152   1.3  jonathan 
    153   1.3  jonathan static __inline int
    154   1.3  jonathan mips_pg_wired(entry)
    155   1.3  jonathan 	unsigned int entry;
    156   1.3  jonathan {
    157  1.12    simonb 	if (MIPS_HAS_R4K_MMU)
    158   1.3  jonathan 		return (entry & MIPS3_PG_WIRED);
    159   1.3  jonathan 	return (entry & MIPS1_PG_WIRED);
    160   1.3  jonathan }
    161   1.3  jonathan 
    162   1.3  jonathan static __inline unsigned int
    163  1.14    simonb mips_pg_m_bit(void)
    164   1.3  jonathan {
    165  1.12    simonb 	if (MIPS_HAS_R4K_MMU)
    166   1.7  nisimura 		return (MIPS3_PG_D);
    167   1.7  nisimura 	return (MIPS1_PG_D);
    168   1.3  jonathan }
    169   1.3  jonathan 
    170   1.3  jonathan static __inline unsigned int
    171  1.14    simonb mips_pg_ro_bit(void)
    172   1.3  jonathan {
    173  1.12    simonb 	if (MIPS_HAS_R4K_MMU)
    174   1.3  jonathan 		return (MIPS3_PG_RO);
    175   1.3  jonathan 	return (MIPS1_PG_RO);
    176   1.3  jonathan }
    177   1.3  jonathan 
    178   1.3  jonathan static __inline unsigned int
    179  1.14    simonb mips_pg_rw_bit(void)
    180   1.3  jonathan {
    181  1.12    simonb 	if (MIPS_HAS_R4K_MMU)
    182   1.7  nisimura 		return (MIPS3_PG_D);
    183   1.3  jonathan 	return (MIPS1_PG_RW);
    184   1.3  jonathan }
    185   1.3  jonathan 
    186   1.3  jonathan static __inline unsigned int
    187  1.14    simonb mips_pg_ropage_bit(void)
    188   1.3  jonathan {
    189  1.12    simonb 	if (MIPS_HAS_R4K_MMU)
    190   1.3  jonathan 		return (MIPS3_PG_ROPAGE);
    191   1.3  jonathan 	return (MIPS1_PG_RO);
    192   1.3  jonathan }
    193   1.3  jonathan 
    194   1.3  jonathan static __inline unsigned int
    195  1.14    simonb mips_pg_rwpage_bit(void)
    196   1.3  jonathan {
    197  1.12    simonb 	if (MIPS_HAS_R4K_MMU)
    198   1.3  jonathan 		return (MIPS3_PG_RWPAGE);
    199   1.3  jonathan 	return (MIPS1_PG_RWPAGE);
    200   1.3  jonathan }
    201   1.3  jonathan 
    202   1.3  jonathan static __inline unsigned int
    203  1.14    simonb mips_pg_cwpage_bit(void)
    204   1.3  jonathan {
    205  1.12    simonb 	if (MIPS_HAS_R4K_MMU)
    206   1.3  jonathan 		return (MIPS3_PG_CWPAGE);
    207   1.3  jonathan 	return (MIPS1_PG_CWPAGE);
    208   1.3  jonathan }
    209   1.3  jonathan 
    210   1.3  jonathan 
    211   1.3  jonathan static __inline unsigned int
    212  1.14    simonb mips_pg_global_bit(void)
    213   1.3  jonathan {
    214  1.12    simonb 	if (MIPS_HAS_R4K_MMU)
    215   1.3  jonathan 		return (MIPS3_PG_G);
    216   1.3  jonathan 	return (MIPS1_PG_G);
    217   1.3  jonathan }
    218   1.3  jonathan 
    219   1.3  jonathan static __inline unsigned int
    220  1.14    simonb mips_pg_wired_bit(void)
    221   1.3  jonathan {
    222  1.12    simonb 	if (MIPS_HAS_R4K_MMU)
    223   1.3  jonathan 		return (MIPS3_PG_WIRED);
    224   1.3  jonathan 	return (MIPS1_PG_WIRED);
    225   1.3  jonathan }
    226   1.3  jonathan 
    227   1.9      soda static __inline paddr_t
    228   1.3  jonathan PTE_TO_PADDR(pte)
    229   1.3  jonathan 	unsigned int pte;
    230   1.3  jonathan {
    231  1.12    simonb 	if (MIPS_HAS_R4K_MMU)
    232   1.3  jonathan 		return (MIPS3_PTE_TO_PADDR(pte));
    233   1.3  jonathan 	return (MIPS1_PTE_TO_PADDR(pte));
    234   1.3  jonathan }
    235   1.3  jonathan 
    236   1.3  jonathan static __inline int
    237   1.3  jonathan PAGE_IS_RDONLY(pte, va)
    238   1.3  jonathan 	unsigned int pte;
    239   1.6  nisimura 	vaddr_t va;
    240   1.3  jonathan {
    241  1.12    simonb 	if (MIPS_HAS_R4K_MMU)
    242   1.3  jonathan 		return (MIPS3_PAGE_IS_RDONLY(pte, va));
    243   1.3  jonathan 	return (MIPS1_PAGE_IS_RDONLY(pte, va));
    244   1.3  jonathan }
    245   1.3  jonathan 
    246   1.9      soda static __inline paddr_t
    247  1.10      soda mips_tlbpfn_to_paddr(pfn)
    248   1.9      soda 	unsigned int pfn;
    249   1.3  jonathan {
    250  1.12    simonb 	if (MIPS_HAS_R4K_MMU)
    251  1.10      soda 		return (mips3_tlbpfn_to_paddr(pfn));
    252  1.10      soda 	return (mips1_tlbpfn_to_paddr(pfn));
    253   1.3  jonathan }
    254   1.1  jonathan 
    255   1.9      soda static __inline unsigned int
    256  1.10      soda mips_paddr_to_tlbpfn(pa)
    257   1.9      soda 	paddr_t pa;
    258   1.3  jonathan {
    259  1.12    simonb 	if (MIPS_HAS_R4K_MMU)
    260  1.10      soda 		return (mips3_paddr_to_tlbpfn(pa));
    261  1.10      soda 	return (mips1_paddr_to_tlbpfn(pa));
    262   1.3  jonathan }
    263   1.1  jonathan #endif
    264   1.1  jonathan 
    265   1.3  jonathan #endif /* ! _LOCORE */
    266   1.1  jonathan 
    267   1.1  jonathan #if defined(_KERNEL) && !defined(_LOCORE)
    268   1.1  jonathan /*
    269   1.1  jonathan  * Kernel virtual address to page table entry and visa versa.
    270   1.1  jonathan  */
    271   1.1  jonathan #define	kvtopte(va) \
    272   1.6  nisimura 	(Sysmap + (((vaddr_t)(va) - VM_MIN_KERNEL_ADDRESS) >> PGSHIFT))
    273   1.1  jonathan #define	ptetokv(pte) \
    274   1.1  jonathan 	((((pt_entry_t *)(pte) - Sysmap) << PGSHIFT) + VM_MIN_KERNEL_ADDRESS)
    275   1.1  jonathan 
    276   1.1  jonathan extern	pt_entry_t *Sysmap;		/* kernel pte table */
    277   1.1  jonathan extern	u_int Sysmapsize;		/* number of pte's in Sysmap */
    278   1.1  jonathan #endif	/* defined(_KERNEL) && !defined(_LOCORE) */
    279   1.1  jonathan #endif /* __MIPS_PTE_H__ */
    280