Home | History | Annotate | Line # | Download | only in include
pte.h revision 1.18
      1  1.18      mrg /*	$NetBSD: pte.h,v 1.18 2006/09/08 23:08:05 mrg Exp $ */
      2   1.1      eeh 
      3   1.1      eeh /*
      4   1.5      eeh  * Copyright (c) 1996-1999 Eduardo Horvath
      5   1.1      eeh  *
      6   1.1      eeh  * Redistribution and use in source and binary forms, with or without
      7   1.1      eeh  * modification, are permitted provided that the following conditions
      8   1.1      eeh  * are met:
      9   1.1      eeh  * 1. Redistributions of source code must retain the above copyright
     10   1.1      eeh  *    notice, this list of conditions and the following disclaimer.
     11   1.5      eeh  *
     12   1.5      eeh  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR  ``AS IS'' AND
     13   1.1      eeh  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     14   1.1      eeh  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     15   1.5      eeh  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR  BE LIABLE
     16   1.1      eeh  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     17   1.1      eeh  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     18   1.1      eeh  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     19   1.1      eeh  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     20   1.1      eeh  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     21   1.1      eeh  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     22   1.1      eeh  * SUCH DAMAGE.
     23   1.1      eeh  *
     24   1.1      eeh  */
     25   1.9  darrenr 
     26  1.18      mrg #ifndef _MACHINE_PTE_H_
     27  1.18      mrg #define _MACHINE_PTE_H_
     28  1.18      mrg 
     29   1.9  darrenr #if defined(_KERNEL_OPT)
     30   1.9  darrenr #include "opt_sparc_arch.h"
     31   1.9  darrenr #endif
     32   1.1      eeh 
     33   1.1      eeh /*
     34   1.1      eeh  * Address translation works as follows:
     35   1.1      eeh  *
     36   1.1      eeh  **
     37   1.1      eeh  * For sun4u:
     38   1.1      eeh  *
     39   1.1      eeh  *	Take your pick; it's all S/W anyway.  We'll start by emulating a sun4.
     40   1.1      eeh  *	Oh, here's the sun4u TTE for reference:
     41   1.1      eeh  *
     42   1.1      eeh  *	struct sun4u_tte {
     43  1.16      cdi  *		uint64	tag_g:1,	(global flag)
     44   1.1      eeh  *			tag_ctxt:15,	(context for mapping)
     45   1.1      eeh  *			tag_unassigned:6,
     46   1.1      eeh  *			tag_va:42;	(virtual address bits<64:22>)
     47  1.16      cdi  *		uint64	data_v:1,	(valid bit)
     48   1.1      eeh  *			data_size:2,	(page size [8K*8**<SIZE>])
     49   1.1      eeh  *			data_nfo:1,	(no-fault only)
     50   1.1      eeh  *			data_ie:1,	(invert endianness [inefficient])
     51   1.1      eeh  *			data_soft2:2,	(reserved for S/W)
     52   1.1      eeh  *			data_pa:36,	(physical address)
     53   1.1      eeh  *			data_soft:6,	(reserved for S/W)
     54   1.1      eeh  *			data_lock:1,	(lock into TLB)
     55   1.1      eeh  *			data_cacheable:2,	(cacheability control)
     56   1.1      eeh  *			data_e:1,	(explicit accesses only)
     57   1.1      eeh  *			data_priv:1,	(privileged page)
     58  1.12      wiz  *			data_w:1,	(writable)
     59   1.1      eeh  *			data_g:1;	(same as tag_g)
     60   1.1      eeh  *	};
     61   1.1      eeh  */
     62   1.1      eeh 
     63   1.1      eeh /* virtual address to virtual page number */
     64   1.8      mrg #define	VA_SUN4_VPG(va)		(((int)(va) >> 13) & 31)
     65   1.8      mrg #define	VA_SUN4C_VPG(va)	(((int)(va) >> 12) & 63)
     66   1.1      eeh #define	VA_SUN4U_VPG(va)	(((int)(va) >> 13) & 31)
     67   1.1      eeh 
     68   1.1      eeh /* virtual address to offset within page */
     69   1.8      mrg #define VA_SUN4_OFF(va)       	(((int)(va)) & 0x1FFF)
     70   1.8      mrg #define VA_SUN4C_OFF(va)     	(((int)(va)) & 0xFFF)
     71   1.1      eeh #define VA_SUN4U_OFF(va)       	(((int)(va)) & 0x1FFF)
     72   1.1      eeh 
     73   1.1      eeh /* When we go to 64-bit VAs we need to handle the hole */
     74   1.1      eeh #define VA_VPG(va)	VA_SUN4U_VPG(va)
     75   1.1      eeh #define VA_OFF(va)	VA_SUN4U_OFF(va)
     76   1.1      eeh 
     77   1.1      eeh #define PG_SHIFT4U	13
     78   1.1      eeh #define MMU_PAGE_ALIGN	8192
     79   1.1      eeh 
     80   1.1      eeh /* If you know where a tte is in the tsb, how do you find its va? */
     81   1.1      eeh #define TSBVA(i)	((tsb[(i)].tag.f.tag_va<<22)|(((i)<<13)&0x3ff000))
     82   1.1      eeh 
     83   1.1      eeh #ifndef _LOCORE
     84   1.1      eeh /*
     85   1.1      eeh  *  This is the spitfire TTE.
     86   1.1      eeh  *
     87   1.1      eeh  *  We could use bitmasks and shifts to construct this if
     88   1.1      eeh  *  we had a 64-bit compiler w/64-bit longs.  Otherwise it's
     89   1.1      eeh  *  a real pain to do this in C.
     90   1.1      eeh  */
     91   1.7      eeh #if 0
     92   1.7      eeh /* We don't use bitfeilds anyway. */
     93   1.1      eeh struct sun4u_tag_fields {
     94  1.16      cdi 	uint64_t	tag_g:1,	/* global flag */
     95   1.1      eeh 		tag_ctxt:15,	/* context for mapping */
     96   1.1      eeh 		tag_unassigned:6,
     97   1.1      eeh 		tag_va:42;	/* virtual address bits<64:22> */
     98   1.1      eeh };
     99   1.1      eeh union sun4u_tag { struct sun4u_tag_fields f; int64_t tag; };
    100   1.1      eeh struct sun4u_data_fields {
    101  1.16      cdi 	uint64_t	data_v:1,	/* valid bit */
    102   1.1      eeh 		data_size:2,	/* page size [8K*8**<SIZE>] */
    103   1.1      eeh 		data_nfo:1,	/* no-fault only */
    104   1.1      eeh 		data_ie:1,	/* invert endianness [inefficient] */
    105   1.1      eeh 		data_soft2:2,	/* reserved for S/W */
    106   1.1      eeh 		data_pa:36,	/* physical address */
    107   1.1      eeh 		data_accessed:1,/* S/W accessed bit */
    108   1.1      eeh 		data_modified:1,/* S/W modified bit */
    109   1.1      eeh 		data_realw:1,	/* S/W real writable bit (to manage modified) */
    110   1.1      eeh 		data_tsblock:1,	/* S/W TSB locked entry */
    111   1.1      eeh 		data_exec:1,	/* S/W Executable */
    112   1.1      eeh 		data_onlyexec:1,/* S/W Executable only */
    113   1.1      eeh 		data_lock:1,	/* lock into TLB */
    114   1.1      eeh 		data_cacheable:2,	/* cacheability control */
    115   1.1      eeh 		data_e:1,	/* explicit accesses only */
    116   1.1      eeh 		data_priv:1,	/* privileged page */
    117  1.12      wiz 		data_w:1,	/* writable */
    118   1.1      eeh 		data_g:1;	/* same as tag_g */
    119   1.1      eeh };
    120   1.1      eeh union sun4u_data { struct sun4u_data_fields f; int64_t data; };
    121   1.1      eeh struct sun4u_tte {
    122   1.1      eeh 	union sun4u_tag tag;
    123   1.1      eeh 	union sun4u_data data;
    124   1.1      eeh };
    125   1.7      eeh #else
    126   1.7      eeh struct sun4u_tte {
    127   1.7      eeh 	int64_t tag;
    128   1.7      eeh 	int64_t data;
    129   1.7      eeh };
    130   1.7      eeh #endif
    131   1.1      eeh typedef struct sun4u_tte pte_t;
    132   1.1      eeh 
    133  1.13      chs /* TLB shootdown handler arguments. */
    134  1.13      chs struct ipi_tlb_args {
    135  1.13      chs 	vaddr_t ita_vaddr;
    136  1.13      chs 	int ita_ctx;
    137  1.13      chs };
    138  1.13      chs 
    139  1.11      chs /* Assembly routines to flush TLB mappings */
    140  1.17      cdi void sp_tlb_flush_pte(vaddr_t, int);
    141  1.17      cdi void sp_tlb_flush_ctx(int);
    142  1.17      cdi void sp_tlb_flush_all(void);
    143  1.13      chs 
    144  1.13      chs #if defined(MULTIPROCESSOR)
    145  1.17      cdi void smp_tlb_flush_pte(vaddr_t, int);
    146  1.17      cdi void smp_tlb_flush_ctx(int);
    147  1.17      cdi void smp_tlb_flush_all(void);
    148  1.13      chs #define	tlb_flush_pte(va,ctx)	smp_tlb_flush_pte(va, ctx)
    149  1.13      chs #define	tlb_flush_ctx(ctx)	smp_tlb_flush_ctx(ctx)
    150  1.13      chs #define	tlb_flush_all()		smp_tlb_flush_all()
    151  1.13      chs #else
    152  1.13      chs #define	tlb_flush_pte(va,ctx)	sp_tlb_flush_pte(va, ctx)
    153  1.13      chs #define	tlb_flush_ctx(ctx)	sp_tlb_flush_ctx(ctx)
    154  1.13      chs #define	tlb_flush_all()		sp_tlb_flush_all()
    155  1.13      chs #endif
    156   1.1      eeh 
    157   1.1      eeh #endif /* _LOCORE */
    158   1.1      eeh 
    159   1.1      eeh /* TSB tag masks */
    160   1.1      eeh #define CTX_MASK		((1<<13)-1)
    161   1.1      eeh #define TSB_TAG_CTX_SHIFT	48
    162   1.1      eeh #define TSB_TAG_VA_SHIFT	22
    163   1.1      eeh #define TSB_TAG_G		0x8000000000000000LL
    164   1.1      eeh 
    165   1.1      eeh #define TSB_TAG_CTX(t)		((((int64_t)(t))>>TSB_TAG_CTX_SHIFT)&CTX_MASK)
    166   1.1      eeh #define TSB_TAG_VA(t)		((((int64_t)(t))<<TSB_TAG_VA_SHIFT))
    167  1.16      cdi #define TSB_TAG(g,ctx,va)	((((uint64_t)((g)!=0))<<63)|(((uint64_t)(ctx)&CTX_MASK)<<TSB_TAG_CTX_SHIFT)|(((uint64_t)va)>>TSB_TAG_VA_SHIFT))
    168   1.1      eeh 
    169   1.6      eeh /* Page sizes */
    170   1.6      eeh #define	PGSZ_8K			0
    171   1.6      eeh #define	PGSZ_64K		1
    172   1.6      eeh #define	PGSZ_512K		2
    173   1.6      eeh #define	PGSZ_4M			3
    174   1.6      eeh 
    175   1.6      eeh #define	PGSZ_SHIFT		61
    176   1.6      eeh #define	TLB_SZ(s)		(((uint64_t)(s))<<PGSZ_SHIFT)
    177   1.6      eeh 
    178   1.1      eeh /* TLB data masks */
    179   1.1      eeh #define TLB_V			0x8000000000000000LL
    180   1.6      eeh #define TLB_8K			TLB_SZ(PGSZ_8K)
    181   1.6      eeh #define TLB_64K			TLB_SZ(PGSZ_64K)
    182   1.6      eeh #define TLB_512K		TLB_SZ(PGSZ_512K)
    183   1.6      eeh #define TLB_4M			TLB_SZ(PGSZ_4M)
    184   1.1      eeh #define TLB_SZ_MASK		0x6000000000000000LL
    185   1.1      eeh #define TLB_NFO			0x1000000000000000LL
    186   1.1      eeh #define TLB_IE			0x0800000000000000LL
    187   1.1      eeh #define TLB_SOFT2_MASK		0x07fe000000000000LL
    188   1.1      eeh #define TLB_DIAG_MASK		0x0001fe0000000000LL
    189   1.1      eeh #define TLB_PA_MASK		0x000001ffffffe000LL
    190   1.1      eeh #define TLB_SOFT_MASK		0x0000000000001f80LL
    191   1.1      eeh /* S/W bits */
    192   1.1      eeh /* Access & TSB locked bits are swapped so I can set access w/one insn */
    193   1.1      eeh /* #define TLB_ACCESS		0x0000000000001000LL */
    194   1.1      eeh #define TLB_ACCESS		0x0000000000000200LL
    195   1.1      eeh #define TLB_MODIFY		0x0000000000000800LL
    196   1.1      eeh #define TLB_REAL_W		0x0000000000000400LL
    197   1.1      eeh /* #define TLB_TSB_LOCK		0x0000000000000200LL */
    198   1.1      eeh #define TLB_TSB_LOCK		0x0000000000001000LL
    199   1.1      eeh #define TLB_EXEC		0x0000000000000100LL
    200   1.1      eeh #define TLB_EXEC_ONLY		0x0000000000000080LL
    201   1.1      eeh /* H/W bits */
    202   1.1      eeh #define TLB_L			0x0000000000000040LL
    203   1.1      eeh #define TLB_CACHE_MASK		0x0000000000000030LL
    204   1.1      eeh #define TLB_CP			0x0000000000000020LL
    205   1.1      eeh #define TLB_CV			0x0000000000000010LL
    206   1.1      eeh #define TLB_E			0x0000000000000008LL
    207   1.1      eeh #define TLB_P			0x0000000000000004LL
    208   1.1      eeh #define TLB_W			0x0000000000000002LL
    209   1.1      eeh #define TLB_G			0x0000000000000001LL
    210  1.10      eeh 
    211  1.10      eeh /* Use a bit in the SOFT2 area to indicate a locked mapping. */
    212  1.10      eeh #define	TLB_WIRED		0x0010000000000000LL
    213   1.1      eeh 
    214   1.1      eeh /*
    215   1.1      eeh  * The following bits are used by locore so they should
    216   1.1      eeh  * be duplicates of the above w/o the "long long"
    217   1.1      eeh  */
    218   1.1      eeh /* S/W bits */
    219   1.1      eeh /* #define TTE_ACCESS		0x0000000000001000 */
    220   1.1      eeh #define TTE_ACCESS		0x0000000000000200
    221   1.1      eeh #define TTE_MODIFY		0x0000000000000800
    222   1.1      eeh #define TTE_REAL_W		0x0000000000000400
    223   1.1      eeh /* #define TTE_TSB_LOCK		0x0000000000000200 */
    224   1.1      eeh #define TTE_TSB_LOCK		0x0000000000001000
    225   1.1      eeh #define TTE_EXEC		0x0000000000000100
    226   1.1      eeh #define TTE_EXEC_ONLY		0x0000000000000080
    227   1.1      eeh /* H/W bits */
    228   1.1      eeh #define TTE_L			0x0000000000000040
    229   1.1      eeh #define TTE_CACHE_MASK		0x0000000000000030
    230   1.1      eeh #define TTE_CP			0x0000000000000020
    231   1.1      eeh #define TTE_CV			0x0000000000000010
    232   1.1      eeh #define TTE_E			0x0000000000000008
    233   1.1      eeh #define TTE_P			0x0000000000000004
    234   1.1      eeh #define TTE_W			0x0000000000000002
    235   1.1      eeh #define TTE_G			0x0000000000000001
    236   1.3      eeh 
    237   1.3      eeh #define TTE_DATA_BITS	"\177\20" \
    238   1.3      eeh         "b\77V\0" "f\75\2SIZE\0" "b\77V\0" "f\75\2SIZE\0" \
    239   1.3      eeh         "=\0008K\0" "=\00164K\0" "=\002512K\0" "=\0034M\0" \
    240   1.3      eeh         "b\74NFO\0"     "b\73IE\0"      "f\62\10SOFT2\0" \
    241   1.3      eeh         "f\51\10DIAG\0" "f\15\33PA<40:13>\0" "f\7\5SOFT\0" \
    242   1.3      eeh         "b\6L\0"        "b\5CP\0"       "b\4CV\0" \
    243   1.3      eeh         "b\3E\0"        "b\2P\0"        "b\1W\0"        "b\0G\0"
    244   1.1      eeh 
    245   1.4      eeh #define TSB_DATA(g,sz,pa,priv,write,cache,aliased,valid,ie) \
    246  1.16      cdi (((valid)?TLB_V:0LL)|TLB_SZ(sz)|(((uint64_t)(pa))&TLB_PA_MASK)|\
    247   1.1      eeh ((cache)?((aliased)?TLB_CP:TLB_CACHE_MASK):TLB_E)|\
    248   1.4      eeh ((priv)?TLB_P:0LL)|((write)?TLB_W:0LL)|((g)?TLB_G:0LL)|((ie)?TLB_IE:0LL))
    249   1.1      eeh 
    250   1.1      eeh #define MMU_CACHE_VIRT	0x3
    251   1.1      eeh #define MMU_CACHE_PHYS	0x2
    252   1.1      eeh #define MMU_CACHE_NONE	0x0
    253   1.1      eeh 
    254   1.1      eeh /* This needs to be updated for sun4u IOMMUs */
    255   1.1      eeh /*
    256   1.1      eeh  * IOMMU PTE bits.
    257   1.1      eeh  */
    258   1.1      eeh #define IOPTE_PPN_MASK  0x07ffff00
    259   1.1      eeh #define IOPTE_PPN_SHIFT 8
    260   1.1      eeh #define IOPTE_RSVD      0x000000f1
    261   1.1      eeh #define IOPTE_WRITE     0x00000004
    262   1.1      eeh #define IOPTE_VALID     0x00000002
    263   1.8      mrg 
    264   1.8      mrg /*
    265   1.8      mrg  * This is purely for compatibility with the old SPARC machines.
    266   1.8      mrg  */
    267   1.8      mrg #define	NBPRG	(1 << 24)	/* bytes per region */
    268   1.8      mrg #define	RGSHIFT	24		/* log2(NBPRG) */
    269   1.8      mrg #define NSEGRG	(NBPRG / NBPSG)	/* segments per region */
    270   1.8      mrg 
    271   1.8      mrg #define	NBPSG	(1 << 18)	/* bytes per segment */
    272   1.8      mrg #define	SGSHIFT	18		/* log2(NBPSG) */
    273   1.8      mrg 
    274   1.8      mrg /* there is no `struct pte'; we just use `int'; this is for non-4M only */
    275   1.8      mrg #define	PG_V		0x80000000
    276   1.8      mrg #define	PG_PFNUM	0x0007ffff	/* n.b.: only 16 bits on sun4c */
    277   1.8      mrg 
    278   1.8      mrg /* virtual address to virtual region number */
    279   1.8      mrg #define	VA_VREG(va)	(((unsigned int)(va) >> RGSHIFT) & 255)
    280   1.8      mrg 
    281   1.8      mrg /* virtual address to virtual segment number */
    282   1.8      mrg #define	VA_VSEG(va)	(((unsigned int)(va) >> SGSHIFT) & 63)
    283   1.8      mrg 
    284   1.8      mrg #ifndef _LOCORE
    285   1.8      mrg typedef u_short pmeg_t;		/* 10 bits needed per Sun-4 segmap entry */
    286   1.8      mrg #endif
    287   1.8      mrg 
    288   1.8      mrg /*
    289   1.8      mrg  * Here are the bit definitions for 4M/SRMMU pte's
    290   1.8      mrg  */
    291   1.8      mrg 		/* MMU TABLE ENTRIES */
    292   1.8      mrg #define SRMMU_TETYPE	0x3		/* mask for table entry type */
    293   1.8      mrg #define SRMMU_TEPTE	0x2		/* Page Table Entry */
    294   1.8      mrg 		/* PTE FIELDS */
    295   1.8      mrg #define SRMMU_PPNMASK	0xFFFFFF00
    296   1.8      mrg #define SRMMU_PPNPASHIFT 0x4 		/* shift to put ppn into PAddr */
    297  1.18      mrg 
    298  1.18      mrg #endif /* _MACHINE_PTE_H_ */
    299