Home | History | Annotate | Line # | Download | only in include
ctlreg.h revision 1.56
      1  1.56  nakayama /*	$NetBSD: ctlreg.h,v 1.56 2011/10/08 08:49:07 nakayama Exp $ */
      2   1.1       eeh 
      3   1.1       eeh /*
      4  1.30       eeh  * Copyright (c) 1996-2002 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.11       eeh  *
     12  1.11       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.11       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.1       eeh 
     26  1.33    petrov #ifndef _SPARC_CTLREG_H_
     27  1.33    petrov #define _SPARC_CTLREG_H_
     28  1.33    petrov 
     29   1.1       eeh /*
     30   1.1       eeh  * Sun 4u control registers. (includes address space definitions
     31   1.1       eeh  * and some registers in control space).
     32   1.1       eeh  */
     33   1.1       eeh 
     34   1.1       eeh /*
     35   1.1       eeh  * The Alternate address spaces.
     36   1.1       eeh  *
     37   1.1       eeh  * 0x00-0x7f are privileged
     38   1.1       eeh  * 0x80-0xff can be used by users
     39   1.1       eeh  */
     40   1.1       eeh 
     41  1.26       eeh #define	ASI_LITTLE	0x08		/* This bit should make an ASI little endian */
     42   1.1       eeh 
     43  1.26       eeh #define	ASI_NUCLEUS			0x04	/* [4u] kernel address space */
     44  1.26       eeh #define	ASI_NUCLEUS_LITTLE		0x0c	/* [4u] kernel address space, little endian */
     45   1.1       eeh 
     46  1.26       eeh #define	ASI_AS_IF_USER_PRIMARY		0x10	/* [4u] primary user address space */
     47  1.26       eeh #define	ASI_AS_IF_USER_SECONDARY	0x11	/* [4u] secondary user address space */
     48   1.1       eeh 
     49  1.26       eeh #define	ASI_PHYS_CACHED			0x14	/* [4u] MMU bypass to main memory */
     50  1.26       eeh #define	ASI_PHYS_NON_CACHED		0x15	/* [4u] MMU bypass to I/O location */
     51  1.26       eeh 
     52  1.26       eeh #define	ASI_AS_IF_USER_PRIMARY_LITTLE	0x18	/* [4u] primary user address space, little endian  */
     53  1.35      heas #define	ASI_AS_IF_USER_SECONDARY_LITTLE	0x19	/* [4u] secondary user address space, little endian  */
     54  1.26       eeh 
     55  1.26       eeh #define	ASI_PHYS_CACHED_LITTLE		0x1c	/* [4u] MMU bypass to main memory, little endian */
     56  1.26       eeh #define	ASI_PHYS_NON_CACHED_LITTLE	0x1d	/* [4u] MMU bypass to I/O location, little endian */
     57  1.26       eeh 
     58  1.26       eeh #define	ASI_NUCLEUS_QUAD_LDD		0x24	/* [4u] use w/LDDA to load 128-bit item */
     59  1.26       eeh #define	ASI_NUCLEUS_QUAD_LDD_LITTLE	0x2c	/* [4u] use w/LDDA to load 128-bit item, little endian */
     60  1.26       eeh 
     61  1.26       eeh #define	ASI_FLUSH_D_PAGE_PRIMARY	0x38	/* [4u] flush D-cache page using primary context */
     62  1.26       eeh #define	ASI_FLUSH_D_PAGE_SECONDARY	0x39	/* [4u] flush D-cache page using secondary context */
     63  1.26       eeh #define	ASI_FLUSH_D_CTX_PRIMARY		0x3a	/* [4u] flush D-cache context using primary context */
     64  1.26       eeh #define	ASI_FLUSH_D_CTX_SECONDARY	0x3b	/* [4u] flush D-cache context using secondary context */
     65  1.26       eeh 
     66  1.46       mrg #define	ASI_DCACHE_INVALIDATE		0x42	/* [III] invalidate D-cache */
     67  1.46       mrg #define	ASI_DCACHE_UTAG			0x43	/* [III] diagnostic access to D-cache micro tag */
     68  1.46       mrg #define	ASI_DCACHE_SNOOP_TAG		0x44	/* [III] diagnostic access to D-cache snoop tag RAM */
     69  1.46       mrg 
     70  1.26       eeh #define	ASI_LSU_CONTROL_REGISTER	0x45	/* [4u] load/store unit control register */
     71  1.26       eeh 
     72  1.26       eeh #define	ASI_DCACHE_DATA			0x46	/* [4u] diagnostic access to D-cache data RAM */
     73  1.26       eeh #define	ASI_DCACHE_TAG			0x47	/* [4u] diagnostic access to D-cache tag RAM */
     74  1.26       eeh 
     75  1.26       eeh #define	ASI_INTR_DISPATCH_STATUS	0x48	/* [4u] interrupt dispatch status register */
     76  1.26       eeh #define	ASI_INTR_RECEIVE		0x49	/* [4u] interrupt receive status register */
     77  1.26       eeh #define	ASI_MID_REG			0x4a	/* [4u] hardware config and MID */
     78  1.26       eeh #define	ASI_ERROR_EN_REG		0x4b	/* [4u] asynchronous error enables */
     79  1.26       eeh #define	ASI_AFSR			0x4c	/* [4u] asynchronous fault status register */
     80  1.26       eeh #define	ASI_AFAR			0x4d	/* [4u] asynchronous fault address register */
     81  1.26       eeh 
     82  1.51       mrg #define	ASI_ICACHE_DATA			0x66	/* [4u] diagnostic access to I-cache data RAM */
     83  1.51       mrg #define	ASI_ICACHE_TAG			0x67	/* [4u] diagnostic access to I-cache tag RAM */
     84  1.51       mrg #define	ASI_FLUSH_I_PAGE_PRIMARY	0x68	/* [4u] flush I-cache page using primary context */
     85  1.51       mrg #define	ASI_FLUSH_I_PAGE_SECONDARY	0x69	/* [4u] flush I-cache page using secondary context */
     86  1.51       mrg #define	ASI_FLUSH_I_CTX_PRIMARY		0x6a	/* [4u] flush I-cache context using primary context */
     87  1.51       mrg #define	ASI_FLUSH_I_CTX_SECONDARY	0x6b	/* [4u] flush I-cache context using secondary context */
     88  1.26       eeh 
     89  1.26       eeh #define	ASI_BLOCK_AS_IF_USER_PRIMARY	0x70	/* [4u] primary user address space, block loads/stores */
     90  1.26       eeh #define	ASI_BLOCK_AS_IF_USER_SECONDARY	0x71	/* [4u] secondary user address space, block loads/stores */
     91  1.26       eeh 
     92  1.26       eeh #define	ASI_ECACHE_DIAG			0x76	/* [4u] diag access to E-cache tag and data */
     93  1.26       eeh #define	ASI_DATAPATH_ERR_REG_WRITE	0x77	/* [4u] ASI is reused */
     94  1.26       eeh 
     95  1.26       eeh #define	ASI_BLOCK_AS_IF_USER_PRIMARY_LITTLE	0x78	/* [4u] primary user address space, block loads/stores */
     96  1.26       eeh #define	ASI_BLOCK_AS_IF_USER_SECONDARY_LITTLE	0x79	/* [4u] secondary user address space, block loads/stores */
     97  1.26       eeh 
     98  1.26       eeh #define	ASI_INTERRUPT_RECEIVE_DATA	0x7f	/* [4u] interrupt receive data registers {0,1,2} */
     99  1.26       eeh #define	ASI_DATAPATH_ERR_REG_READ	0x7f	/* [4u] read access to datapath error registers (ASI reused) */
    100  1.26       eeh 
    101  1.26       eeh #define	ASI_PRIMARY			0x80	/* [4u] primary address space */
    102  1.26       eeh #define	ASI_SECONDARY			0x81	/* [4u] secondary address space */
    103  1.28       eeh #define	ASI_PRIMARY_NOFAULT		0x82	/* [4u] primary address space, no fault */
    104  1.28       eeh #define	ASI_SECONDARY_NOFAULT		0x83	/* [4u] secondary address space, no fault */
    105  1.26       eeh 
    106  1.26       eeh #define	ASI_PRIMARY_LITTLE		0x88	/* [4u] primary address space, little endian */
    107  1.26       eeh #define	ASI_SECONDARY_LITTLE		0x89	/* [4u] secondary address space, little endian */
    108  1.28       eeh #define	ASI_PRIMARY_NOFAULT_LITTLE	0x8a	/* [4u] primary address space, no fault, little endian */
    109  1.28       eeh #define	ASI_SECONDARY_NOFAULT_LITTLE	0x8b	/* [4u] secondary address space, no fault, little endian */
    110  1.26       eeh 
    111  1.26       eeh #define	ASI_PST8_PRIMARY		0xc0	/* [VIS] Eight 8-bit partial store, primary */
    112  1.26       eeh #define	ASI_PST8_SECONDARY		0xc1	/* [VIS] Eight 8-bit partial store, secondary */
    113  1.26       eeh #define	ASI_PST16_PRIMARY		0xc2	/* [VIS] Four 16-bit partial store, primary */
    114  1.26       eeh #define	ASI_PST16_SECONDARY		0xc3	/* [VIS] Fout 16-bit partial store, secondary */
    115  1.26       eeh #define	ASI_PST32_PRIMARY		0xc4	/* [VIS] Two 32-bit partial store, primary */
    116  1.26       eeh #define	ASI_PST32_SECONDARY		0xc5	/* [VIS] Two 32-bit partial store, secondary */
    117  1.26       eeh 
    118  1.26       eeh #define	ASI_PST8_PRIMARY_LITTLE		0xc8	/* [VIS] Eight 8-bit partial store, primary, little endian */
    119  1.26       eeh #define	ASI_PST8_SECONDARY_LITTLE	0xc9	/* [VIS] Eight 8-bit partial store, secondary, little endian */
    120  1.26       eeh #define	ASI_PST16_PRIMARY_LITTLE	0xca	/* [VIS] Four 16-bit partial store, primary, little endian */
    121  1.26       eeh #define	ASI_PST16_SECONDARY_LITTLE	0xcb	/* [VIS] Fout 16-bit partial store, secondary, little endian */
    122  1.26       eeh #define	ASI_PST32_PRIMARY_LITTLE	0xcc	/* [VIS] Two 32-bit partial store, primary, little endian */
    123  1.26       eeh #define	ASI_PST32_SECONDARY_LITTLE	0xcd	/* [VIS] Two 32-bit partial store, secondary, little endian */
    124  1.26       eeh 
    125  1.26       eeh #define	ASI_FL8_PRIMARY			0xd0	/* [VIS] One 8-bit load/store floating, primary */
    126  1.26       eeh #define	ASI_FL8_SECONDARY		0xd1	/* [VIS] One 8-bit load/store floating, secondary */
    127  1.26       eeh #define	ASI_FL16_PRIMARY		0xd2	/* [VIS] One 16-bit load/store floating, primary */
    128  1.26       eeh #define	ASI_FL16_SECONDARY		0xd3	/* [VIS] One 16-bit load/store floating, secondary */
    129  1.26       eeh 
    130  1.26       eeh #define	ASI_FL8_PRIMARY_LITTLE		0xd8	/* [VIS] One 8-bit load/store floating, primary, little endian */
    131  1.26       eeh #define	ASI_FL8_SECONDARY_LITTLE	0xd9	/* [VIS] One 8-bit load/store floating, secondary, little endian */
    132  1.26       eeh #define	ASI_FL16_PRIMARY_LITTLE		0xda	/* [VIS] One 16-bit load/store floating, primary, little endian */
    133  1.26       eeh #define	ASI_FL16_SECONDARY_LITTLE	0xdb	/* [VIS] One 16-bit load/store floating, secondary, little endian */
    134  1.26       eeh 
    135  1.26       eeh #define	ASI_BLOCK_COMMIT_PRIMARY	0xe0	/* [4u] block store with commit, primary */
    136  1.26       eeh #define	ASI_BLOCK_COMMIT_SECONDARY	0xe1	/* [4u] block store with commit, secondary */
    137  1.26       eeh #define	ASI_BLOCK_PRIMARY		0xf0	/* [4u] block load/store, primary */
    138  1.26       eeh #define	ASI_BLOCK_SECONDARY		0xf1	/* [4u] block load/store, secondary */
    139  1.26       eeh #define	ASI_BLOCK_PRIMARY_LITTLE	0xf8	/* [4u] block load/store, primary, little endian */
    140  1.26       eeh #define	ASI_BLOCK_SECONDARY_LITTLE	0xf9	/* [4u] block load/store, secondary, little endian */
    141   1.1       eeh 
    142   1.1       eeh 
    143   1.1       eeh /*
    144   1.1       eeh  * These are the shorter names used by Solaris
    145   1.1       eeh  */
    146   1.1       eeh 
    147  1.26       eeh #define	ASI_N		ASI_NUCLEUS
    148  1.26       eeh #define	ASI_NL		ASI_NUCLEUS_LITTLE
    149  1.26       eeh #define	ASI_AIUP	ASI_AS_IF_USER_PRIMARY
    150  1.26       eeh #define	ASI_AIUS	ASI_AS_IF_USER_SECONDARY
    151  1.26       eeh #define	ASI_AIUPL	ASI_AS_IF_USER_PRIMARY_LITTLE
    152  1.26       eeh #define	ASI_AIUSL	ASI_AS_IF_USER_SECONDARY_LITTLE
    153  1.26       eeh #define	ASI_P		ASI_PRIMARY
    154  1.26       eeh #define	ASI_S		ASI_SECONDARY
    155  1.28       eeh #define	ASI_PNF		ASI_PRIMARY_NOFAULT
    156  1.28       eeh #define	ASI_SNF		ASI_SECONDARY_NOFAULT
    157  1.26       eeh #define	ASI_PL		ASI_PRIMARY_LITTLE
    158  1.26       eeh #define	ASI_SL		ASI_SECONDARY_LITTLE
    159  1.28       eeh #define	ASI_PNFL	ASI_PRIMARY_NOFAULT_LITTLE
    160  1.28       eeh #define	ASI_SNFL	ASI_SECONDARY_NOFAULT_LITTLE
    161  1.26       eeh #define	ASI_FL8_P	ASI_FL8_PRIMARY
    162  1.26       eeh #define	ASI_FL8_S	ASI_FL8_SECONDARY
    163  1.26       eeh #define	ASI_FL16_P	ASI_FL16_PRIMARY
    164  1.26       eeh #define	ASI_FL16_S	ASI_FL16_SECONDARY
    165  1.26       eeh #define	ASI_FL8_PL	ASI_FL8_PRIMARY_LITTLE
    166  1.26       eeh #define	ASI_FL8_SL	ASI_FL8_SECONDARY_LITTLE
    167  1.26       eeh #define	ASI_FL16_PL	ASI_FL16_PRIMARY_LITTLE
    168  1.26       eeh #define	ASI_FL16_SL	ASI_FL16_SECONDARY_LITTLE
    169  1.26       eeh #define	ASI_BLK_AIUP	ASI_BLOCK_AS_IF_USER_PRIMARY
    170  1.26       eeh #define	ASI_BLK_AIUPL	ASI_BLOCK_AS_IF_USER_PRIMARY_LITTLE
    171  1.26       eeh #define	ASI_BLK_AIUS	ASI_BLOCK_AS_IF_USER_SECONDARY
    172  1.26       eeh #define	ASI_BLK_AIUSL	ASI_BLOCK_AS_IF_USER_SECONDARY_LITTLE
    173  1.26       eeh #define	ASI_BLK_COMMIT_P		ASI_BLOCK_COMMIT_PRIMARY
    174  1.26       eeh #define	ASI_BLK_COMMIT_PRIMARY		ASI_BLOCK_COMMIT_PRIMARY
    175  1.26       eeh #define	ASI_BLK_COMMIT_S		ASI_BLOCK_COMMIT_SECONDARY
    176  1.26       eeh #define	ASI_BLK_COMMIT_SECONDARY	ASI_BLOCK_COMMIT_SECONDARY
    177  1.26       eeh #define	ASI_BLK_P			ASI_BLOCK_PRIMARY
    178  1.26       eeh #define	ASI_BLK_PL			ASI_BLOCK_PRIMARY_LITTLE
    179  1.26       eeh #define	ASI_BLK_S			ASI_BLOCK_SECONDARY
    180  1.26       eeh #define	ASI_BLK_SL			ASI_BLOCK_SECONDARY_LITTLE
    181   1.1       eeh 
    182  1.28       eeh /* Alternative spellings */
    183  1.28       eeh #define ASI_PRIMARY_NO_FAULT		ASI_PRIMARY_NOFAULT
    184  1.28       eeh #define ASI_PRIMARY_NO_FAULT_LITTLE	ASI_PRIMARY_NOFAULT_LITTLE
    185  1.28       eeh #define ASI_SECONDARY_NO_FAULT		ASI_SECONDARY_NOFAULT
    186  1.28       eeh #define ASI_SECONDARY_NO_FAULT_LITTLE	ASI_SECONDARY_NOFAULT_LITTLE
    187  1.28       eeh 
    188  1.29       eeh #define	PHYS_ASI(x)	(((x) | 0x09) == 0x1d)
    189  1.26       eeh #define	LITTLE_ASI(x)	((x) & ASI_LITTLE)
    190  1.14       eeh 
    191   1.1       eeh /*
    192   1.1       eeh  * The following are 4u control registers
    193   1.1       eeh  */
    194  1.18       eeh 
    195  1.18       eeh /* Get the CPU's UPAID */
    196  1.36    petrov #define	UPA_CR_MID_SHIFT	(17)
    197  1.36    petrov #define	UPA_CR_MID_SIZE		(5)
    198  1.36    petrov #define	UPA_CR_MID_MASK \
    199  1.36    petrov 	(((1 << UPA_CR_MID_SIZE) - 1) << UPA_CR_MID_SHIFT)
    200  1.36    petrov 
    201  1.36    petrov #define	UPA_CR_MID(x)	(((x)>>UPA_CR_MID_SHIFT)&((1 << UPA_CR_MID_SIZE) - 1))
    202  1.36    petrov 
    203  1.36    petrov #ifdef _LOCORE
    204  1.36    petrov 
    205  1.36    petrov #define	UPA_GET_MID(r1) \
    206  1.36    petrov 	ldxa	[%g0] ASI_MID_REG, r1 ; \
    207  1.36    petrov 	srlx	r1, UPA_CR_MID_SHIFT, r1 ; \
    208  1.36    petrov 	and	r1, (1 << UPA_CR_MID_SIZE) - 1, r1
    209  1.36    petrov 
    210  1.36    petrov #else
    211  1.18       eeh #define	CPU_UPAID	UPA_CR_MID(ldxa(0, ASI_MID_REG))
    212  1.36    petrov #endif
    213  1.55       mrg 
    214  1.55       mrg /* Get the CPU's Fireplane agent ID */
    215  1.55       mrg #define FIREPLANE_CR_AID(x)	(((x) >> 17) & 0x3ff)
    216  1.55       mrg #define CPU_FIREPLANEID		FIREPLANE_CR_AID(ldxa(0, ASI_MID_REG))
    217  1.55       mrg 
    218  1.55       mrg /* Get the CPU's Jupiter Bus interrupt target ID */
    219  1.55       mrg #define JUPITER_CR_ITID(x)	((x) & 0x3ff)
    220  1.55       mrg #define CPU_JUPITERID		JUPITER_CR_ITID(ldxa(0, ASI_MID_REG))
    221   1.1       eeh 
    222   1.1       eeh /*
    223   1.1       eeh  * [4u] MMU and Cache Control Register (MCCR)
    224   1.1       eeh  * use ASI = 0x45
    225   1.1       eeh  */
    226  1.26       eeh #define	ASI_MCCR	ASI_LSU_CONTROL_REGISTER
    227  1.26       eeh #define	MCCR		0x00
    228   1.1       eeh 
    229   1.1       eeh /* MCCR Bits and their meanings */
    230  1.26       eeh #define	MCCR_DMMU_EN	0x08
    231  1.26       eeh #define	MCCR_IMMU_EN	0x04
    232  1.26       eeh #define	MCCR_DCACHE_EN	0x02
    233  1.26       eeh #define	MCCR_ICACHE_EN	0x01
    234  1.54       mrg #define	MCCR_RAW_EN	0x400000000000
    235   1.1       eeh 
    236   1.1       eeh 
    237   1.1       eeh /*
    238   1.1       eeh  * MMU control registers
    239   1.1       eeh  */
    240   1.1       eeh 
    241   1.1       eeh /* Choose an MMU */
    242  1.26       eeh #define	ASI_DMMU		0x58
    243  1.26       eeh #define	ASI_IMMU		0x50
    244   1.1       eeh 
    245   1.1       eeh /* Other assorted MMU ASIs */
    246  1.26       eeh #define	ASI_IMMU_8KPTR		0x51
    247  1.26       eeh #define	ASI_IMMU_64KPTR		0x52
    248  1.26       eeh #define	ASI_IMMU_DATA_IN	0x54
    249  1.26       eeh #define	ASI_IMMU_TLB_DATA	0x55
    250  1.26       eeh #define	ASI_IMMU_TLB_TAG	0x56
    251  1.26       eeh #define	ASI_DMMU_8KPTR		0x59
    252  1.26       eeh #define	ASI_DMMU_64KPTR		0x5a
    253  1.26       eeh #define	ASI_DMMU_DATA_IN	0x5c
    254  1.26       eeh #define	ASI_DMMU_TLB_DATA	0x5d
    255  1.26       eeh #define	ASI_DMMU_TLB_TAG	0x5e
    256   1.1       eeh 
    257   1.1       eeh /*
    258   1.1       eeh  * The following are the control registers
    259   1.1       eeh  * They work on both MMUs unless noted.
    260  1.46       mrg  * III = cheetah only
    261   1.1       eeh  *
    262   1.1       eeh  * Register contents are defined later on individual registers.
    263   1.1       eeh  */
    264  1.26       eeh #define	TSB_TAG_TARGET		0x0
    265  1.26       eeh #define	TLB_DATA_IN		0x0
    266  1.26       eeh #define	CTX_PRIMARY		0x08	/* primary context -- DMMU only */
    267  1.26       eeh #define	CTX_SECONDARY		0x10	/* secondary context -- DMMU only */
    268  1.26       eeh #define	SFSR			0x18
    269  1.26       eeh #define	SFAR			0x20	/* fault address -- DMMU only */
    270  1.26       eeh #define	TSB			0x28
    271  1.26       eeh #define	TLB_TAG_ACCESS		0x30
    272  1.26       eeh #define	VIRTUAL_WATCHPOINT	0x38
    273  1.26       eeh #define	PHYSICAL_WATCHPOINT	0x40
    274  1.46       mrg #define	TSB_PEXT		0x48	/* III primary ext */
    275  1.46       mrg #define	TSB_SEXT		0x50	/* III 2ndary ext -- DMMU only */
    276  1.46       mrg #define	TSB_NEXT		0x58	/* III nucleus ext */
    277   1.1       eeh 
    278   1.1       eeh /* Tag Target bits */
    279  1.26       eeh #define	TAG_TARGET_VA_MASK	0x03ffffffffffffffffLL
    280  1.26       eeh #define	TAG_TARGET_VA(x)	(((x)<<22)&TAG_TARGET_VA_MASK)
    281  1.26       eeh #define	TAG_TARGET_CONTEXT(x)	((x)>>48)
    282  1.26       eeh #define	TAG_TARGET(c,v)		((((uint64_t)c)<<48)|(((uint64_t)v)&TAG_TARGET_VA_MASK))
    283   1.1       eeh 
    284   1.1       eeh /* SFSR bits for both D_SFSR and I_SFSR */
    285  1.26       eeh #define	SFSR_ASI(x)		((x)>>16)
    286  1.26       eeh #define	SFSR_FT_VA_OOR_2	0x02000 /* IMMU: jumpl or return to unsupportd VA */
    287  1.26       eeh #define	SFSR_FT_VA_OOR_1	0x01000 /* fault at unsupported VA */
    288  1.26       eeh #define	SFSR_FT_NFO		0x00800	/* DMMU: Access to page marked NFO */
    289  1.26       eeh #define	SFSR_ILL_ASI		0x00400	/* DMMU: Illegal (unsupported) ASI */
    290  1.26       eeh #define	SFSR_FT_IO_ATOMIC	0x00200	/* DMMU: Atomic access to noncacheable page */
    291  1.26       eeh #define	SFSR_FT_ILL_NF		0x00100	/* DMMU: NF load or flush to page marked E (has side effects) */
    292  1.26       eeh #define	SFSR_FT_PRIV		0x00080	/* Privilege violation */
    293  1.26       eeh #define	SFSR_FT_E		0x00040	/* DMUU: value of E bit associated address */
    294  1.26       eeh #define	SFSR_CTXT(x)		(((x)>>4)&0x3)
    295  1.26       eeh #define	SFSR_CTXT_IS_PRIM(x)	(SFSR_CTXT(x)==0x00)
    296  1.26       eeh #define	SFSR_CTXT_IS_SECOND(x)	(SFSR_CTXT(x)==0x01)
    297  1.26       eeh #define	SFSR_CTXT_IS_NUCLEUS(x)	(SFSR_CTXT(x)==0x02)
    298  1.26       eeh #define	SFSR_PRIV		0x00008	/* value of PSTATE.PRIV for faulting access */
    299  1.26       eeh #define	SFSR_W			0x00004 /* DMMU: attempted write */
    300  1.26       eeh #define	SFSR_OW			0x00002 /* Overwrite; prev vault was still valid */
    301  1.26       eeh #define	SFSR_FV			0x00001	/* Fault is valid */
    302  1.33    petrov #define	SFSR_FT	(SFSR_FT_VA_OOR_2|SFSR_FT_VA_OOR_1|SFSR_FT_NFO| \
    303  1.33    petrov 		SFSR_ILL_ASI|SFSR_FT_IO_ATOMIC|SFSR_FT_ILL_NF|SFSR_FT_PRIV)
    304   1.1       eeh 
    305  1.26       eeh #define	SFSR_BITS "\177\20" \
    306  1.33    petrov 	"f\20\30ASI\0" "b\16VAT\0" "b\15VAD\0" "b\14NFO\0" "b\13ASI\0" "b\12A\0" \
    307  1.33    petrov 	"b\11NF\0" "b\10PRIV\0" "b\7E\0" "b\6NUCLEUS\0" "b\5SECONDCTX\0" "b\4PRIV\0" \
    308  1.33    petrov 	"b\3W\0" "b\2OW\0" "b\1FV\0"
    309   1.3       eeh 
    310   1.3       eeh /* ASFR bits */
    311  1.26       eeh #define	ASFR_ME			0x100000000LL
    312  1.26       eeh #define	ASFR_PRIV		0x080000000LL
    313  1.26       eeh #define	ASFR_ISAP		0x040000000LL
    314  1.26       eeh #define	ASFR_ETP		0x020000000LL
    315  1.26       eeh #define	ASFR_IVUE		0x010000000LL
    316  1.26       eeh #define	ASFR_TO			0x008000000LL
    317  1.26       eeh #define	ASFR_BERR		0x004000000LL
    318  1.26       eeh #define	ASFR_LDP		0x002000000LL
    319  1.26       eeh #define	ASFR_CP			0x001000000LL
    320  1.26       eeh #define	ASFR_WP			0x000800000LL
    321  1.26       eeh #define	ASFR_EDP		0x000400000LL
    322  1.26       eeh #define	ASFR_UE			0x000200000LL
    323  1.26       eeh #define	ASFR_CE			0x000100000LL
    324  1.26       eeh #define	ASFR_ETS		0x0000f0000LL
    325  1.26       eeh #define	ASFT_P_SYND		0x00000ffffLL
    326   1.3       eeh 
    327  1.26       eeh #define	AFSR_BITS "\177\20" \
    328   1.3       eeh         "b\40ME\0"      "b\37PRIV\0"    "b\36ISAP\0"    "b\35ETP\0" \
    329   1.3       eeh         "b\34IVUE\0"    "b\33TO\0"      "b\32BERR\0"    "b\31LDP\0" \
    330   1.3       eeh         "b\30CP\0"      "b\27WP\0"      "b\26EDP\0"     "b\25UE\0" \
    331   1.3       eeh         "b\24CE\0"      "f\20\4ETS\0"   "f\0\20P_SYND\0"
    332   1.3       eeh 
    333   1.1       eeh /*
    334   1.1       eeh  * Here's the spitfire TSB control register bits.
    335   1.1       eeh  *
    336   1.1       eeh  * Each TSB entry is 16-bytes wide.  The TSB must be size aligned
    337   1.1       eeh  */
    338  1.26       eeh #define	TSB_SIZE_512		0x0	/* 8kB, etc. */
    339  1.26       eeh #define	TSB_SIZE_1K		0x01
    340  1.26       eeh #define	TSB_SIZE_2K		0x02
    341  1.26       eeh #define	TSB_SIZE_4K		0x03
    342   1.1       eeh #define	TSB_SIZE_8K		0x04
    343  1.26       eeh #define	TSB_SIZE_16K		0x05
    344  1.26       eeh #define	TSB_SIZE_32K		0x06
    345  1.26       eeh #define	TSB_SIZE_64K		0x07
    346  1.26       eeh #define	TSB_SPLIT		0x1000
    347  1.26       eeh #define	TSB_BASE		0xffffffffffffe000
    348   1.1       eeh 
    349   1.1       eeh /*  TLB Tag Access bits */
    350  1.26       eeh #define	TLB_TAG_ACCESS_VA	0xffffffffffffe000
    351  1.26       eeh #define	TLB_TAG_ACCESS_CTX	0x0000000000001fff
    352   1.1       eeh 
    353   1.1       eeh /*
    354   1.1       eeh  * TLB demap registers.  TTEs are defined in v9pte.h
    355   1.1       eeh  *
    356   1.1       eeh  * Use the address space to select between IMMU and DMMU.
    357   1.1       eeh  * The address of the register selects which context register
    358   1.1       eeh  * to read the ASI from.
    359   1.1       eeh  *
    360   1.1       eeh  * The data stored in the register is interpreted as the VA to
    361   1.1       eeh  * use.  The DEMAP_CTX_<> registers ignore the address and demap the
    362   1.1       eeh  * entire ASI.
    363   1.1       eeh  *
    364   1.1       eeh  */
    365  1.26       eeh #define	ASI_IMMU_DEMAP			0x57	/* [4u] IMMU TLB demap */
    366  1.26       eeh #define	ASI_DMMU_DEMAP			0x5f	/* [4u] IMMU TLB demap */
    367   1.1       eeh 
    368  1.26       eeh #define	DEMAP_PAGE_NUCLEUS		((0x02)<<4)	/* Demap page from kernel AS */
    369  1.26       eeh #define	DEMAP_PAGE_PRIMARY		((0x00)<<4)	/* Demap a page from primary CTXT */
    370  1.26       eeh #define	DEMAP_PAGE_SECONDARY		((0x01)<<4)	/* Demap page from secondary CTXT (DMMU only) */
    371  1.26       eeh #define	DEMAP_CTX_NUCLEUS		((0x06)<<4)	/* Demap all of kernel CTXT */
    372  1.26       eeh #define	DEMAP_CTX_PRIMARY		((0x04)<<4)	/* Demap all of primary CTXT */
    373  1.26       eeh #define	DEMAP_CTX_SECONDARY		((0x05)<<4)	/* Demap all of secondary CTXT */
    374  1.49       mrg #define	DEMAP_ALL			((0x08)<<4)	/* Demap all non-locked TLB entries [USIII] */
    375   1.1       eeh 
    376   1.1       eeh /*
    377  1.50       mrg  * These define the sizes of the TLB in various CPUs.
    378  1.50       mrg  * They're mostly not necessary except for diagnostic code.
    379  1.50       mrg  */
    380  1.50       mrg #define TLB_SIZE_SPITFIRE		64
    381  1.50       mrg #define TLB_SIZE_CHEETAH_I16		16
    382  1.50       mrg #define TLB_SIZE_CHEETAH_I128		128
    383  1.50       mrg #define TLB_SIZE_CHEETAH_D16		16
    384  1.50       mrg #define TLB_SIZE_CHEETAH_D512_0		512
    385  1.50       mrg #define TLB_SIZE_CHEETAH_D512_1		512
    386  1.52       mrg #define TLB_CHEETAH_I16			(0 << 16)
    387  1.52       mrg #define TLB_CHEETAH_I128		(2 << 16)
    388  1.52       mrg #define TLB_CHEETAH_D16			(0 << 16)
    389  1.52       mrg #define TLB_CHEETAH_D512_0		(2 << 16)
    390  1.52       mrg #define TLB_CHEETAH_D512_1		(3 << 16)
    391  1.50       mrg 
    392  1.50       mrg /*
    393   1.1       eeh  * Interrupt registers.  This really gets hairy.
    394   1.1       eeh  */
    395   1.1       eeh 
    396   1.1       eeh /* IRSR -- Interrupt Receive Status Ragister */
    397  1.26       eeh #define	ASI_IRSR	0x49
    398  1.26       eeh #define	IRSR		0x00
    399  1.26       eeh #define	IRSR_BUSY	0x020
    400  1.26       eeh #define	IRSR_MID(x)	(x&0x1f)
    401   1.1       eeh 
    402   1.1       eeh /* IRDR -- Interrupt Receive Data Registers */
    403  1.26       eeh #define	ASI_IRDR	0x7f
    404  1.26       eeh #define	IRDR_0H		0x40
    405  1.26       eeh #define	IRDR_0L		0x48	/* unimplemented */
    406  1.26       eeh #define	IRDR_1H		0x50
    407  1.26       eeh #define	IRDR_1L		0x58	/* unimplemented */
    408  1.26       eeh #define	IRDR_2H		0x60
    409  1.26       eeh #define	IRDR_2L		0x68	/* unimplemented */
    410  1.26       eeh #define	IRDR_3H		0x70	/* unimplemented */
    411  1.26       eeh #define	IRDR_3L		0x78	/* unimplemented */
    412   1.1       eeh 
    413   1.1       eeh /* SOFTINT ASRs */
    414  1.26       eeh #define	SET_SOFTINT	%asr20	/* Sets these bits */
    415  1.26       eeh #define	CLEAR_SOFTINT	%asr21	/* Clears these bits */
    416  1.26       eeh #define	SOFTINT		%asr22	/* Reads the register */
    417  1.26       eeh #define	TICK_CMPR	%asr23
    418   1.1       eeh 
    419   1.1       eeh #define	TICK_INT	0x01	/* level-14 clock tick */
    420  1.26       eeh #define	SOFTINT1	(0x1<<1)
    421  1.26       eeh #define	SOFTINT2	(0x1<<2)
    422  1.26       eeh #define	SOFTINT3	(0x1<<3)
    423  1.26       eeh #define	SOFTINT4	(0x1<<4)
    424  1.26       eeh #define	SOFTINT5	(0x1<<5)
    425  1.26       eeh #define	SOFTINT6	(0x1<<6)
    426  1.26       eeh #define	SOFTINT7	(0x1<<7)
    427  1.26       eeh #define	SOFTINT8	(0x1<<8)
    428  1.26       eeh #define	SOFTINT9	(0x1<<9)
    429  1.26       eeh #define	SOFTINT10	(0x1<<10)
    430  1.26       eeh #define	SOFTINT11	(0x1<<11)
    431  1.26       eeh #define	SOFTINT12	(0x1<<12)
    432  1.26       eeh #define	SOFTINT13	(0x1<<13)
    433  1.26       eeh #define	SOFTINT14	(0x1<<14)
    434  1.26       eeh #define	SOFTINT15	(0x1<<15)
    435   1.1       eeh 
    436   1.1       eeh /* Interrupt Dispatch -- usually reserved for cross-calls */
    437  1.26       eeh #define	ASR_IDSR	0x48 /* Interrupt dispatch status reg */
    438  1.26       eeh #define	IDSR		0x00
    439  1.26       eeh #define	IDSR_NACK	0x02
    440  1.26       eeh #define	IDSR_BUSY	0x01
    441  1.26       eeh 
    442  1.26       eeh #define	ASI_INTERRUPT_DISPATCH		0x77	/* [4u] spitfire interrupt dispatch regs */
    443  1.31       chs 
    444  1.31       chs /* Interrupt delivery initiation */
    445  1.31       chs #define	IDCR(x)		((((uint64_t)(x)) << 14) | 0x70)
    446  1.31       chs 
    447  1.31       chs #define	IDDR_0H		0x40	/* Store data to send in these regs */
    448  1.26       eeh #define	IDDR_0L		0x48	/* unimplemented */
    449  1.26       eeh #define	IDDR_1H		0x50
    450  1.26       eeh #define	IDDR_1L		0x58	/* unimplemented */
    451  1.26       eeh #define	IDDR_2H		0x60
    452  1.26       eeh #define	IDDR_2L		0x68	/* unimplemented */
    453  1.26       eeh #define	IDDR_3H		0x70	/* unimplemented */
    454  1.26       eeh #define	IDDR_3L		0x78	/* unimplemented */
    455   1.1       eeh 
    456   1.1       eeh /*
    457   1.1       eeh  * Error registers
    458   1.1       eeh  */
    459   1.1       eeh 
    460   1.1       eeh /* Since we won't try to fix async errs, we don't care about the bits in the regs */
    461  1.26       eeh #define	ASI_AFAR	0x4d	/* Asynchronous fault address register */
    462  1.26       eeh #define	AFAR		0x00
    463  1.26       eeh #define	ASI_AFSR	0x4c	/* Asynchronous fault status register */
    464  1.26       eeh #define	AFSR		0x00
    465  1.26       eeh 
    466  1.26       eeh #define	ASI_P_EER	0x4b	/* Error enable register */
    467  1.26       eeh #define	P_EER		0x00
    468  1.26       eeh #define	P_EER_ISAPEN	0x04	/* Enable fatal on ISAP */
    469  1.26       eeh #define	P_EER_NCEEN	0x02	/* Enable trap on uncorrectable errs */
    470  1.26       eeh #define	P_EER_CEEN	0x01	/* Enable trap on correctable errs */
    471  1.26       eeh 
    472  1.26       eeh #define	ASI_DATAPATH_READ	0x7f /* Read the regs */
    473  1.26       eeh #define	ASI_DATAPATH_WRITE	0x77 /* Write to the regs */
    474  1.26       eeh #define	P_DPER_0	0x00	/* Datapath err reg 0 */
    475  1.26       eeh #define	P_DPER_1	0x18	/* Datapath err reg 1 */
    476  1.26       eeh #define	P_DCR_0		0x20	/* Datapath control reg 0 */
    477  1.26       eeh #define	P_DCR_1		0x38	/* Datapath control reg 0 */
    478   1.1       eeh 
    479   1.2       eeh 
    480   1.2       eeh /* From sparc64/asm.h which I think I'll deprecate since it makes bus.h a pain. */
    481   1.2       eeh 
    482  1.21       eeh #ifndef _LOCORE
    483   1.1       eeh /*
    484   1.2       eeh  * GCC __asm constructs for doing assembly stuff.
    485   1.1       eeh  */
    486   1.2       eeh 
    487   1.2       eeh /*
    488   1.2       eeh  * ``Routines'' to load and store from/to alternate address space.
    489   1.2       eeh  * The location can be a variable, the asi value (address space indicator)
    490   1.2       eeh  * must be a constant.
    491   1.1       eeh  *
    492   1.2       eeh  * N.B.: You can put as many special functions here as you like, since
    493   1.2       eeh  * they cost no kernel space or time if they are not used.
    494   1.1       eeh  *
    495   1.2       eeh  * These were static inline functions, but gcc screws up the constraints
    496   1.2       eeh  * on the address space identifiers (the "n"umeric value part) because
    497   1.2       eeh  * it inlines too late, so we have to use the funny valued-macro syntax.
    498   1.2       eeh  */
    499   1.6       eeh 
    500  1.20       eeh /*
    501  1.20       eeh  * Apparently the definition of bypass ASIs is that they all use the
    502  1.20       eeh  * D$ so we need to flush the D$ to make sure we don't get data pollution.
    503  1.20       eeh  */
    504   1.6       eeh 
    505  1.21       eeh #ifdef __arch64__
    506  1.21       eeh 
    507  1.47  nakayama /* 64-bit kernel, non-constant */
    508  1.47  nakayama #define SPARC64_LD_NONCONST(ld)	\
    509  1.47  nakayama 	__asm volatile(							\
    510  1.47  nakayama 		"wr %2,%%g0,%%asi;	"				\
    511  1.47  nakayama 		#ld " [%1]%%asi,%0	"				\
    512  1.47  nakayama 		: "=r" (_v)						\
    513  1.47  nakayama 		: "r" ((__uintptr_t)(loc)), "r" (asi))
    514  1.47  nakayama 
    515  1.47  nakayama #if defined(__GNUC__) && defined(__OPTIMIZE__)
    516  1.47  nakayama #define SPARC64_LD_DEF(ld, type, vtype)	\
    517  1.47  nakayama static __inline type ld(paddr_t loc, int asi)				\
    518  1.47  nakayama {									\
    519  1.47  nakayama 	vtype _v;							\
    520  1.47  nakayama 	if (__builtin_constant_p(asi))					\
    521  1.47  nakayama 		__asm volatile(						\
    522  1.47  nakayama 			#ld " [%1]%2,%0		"			\
    523  1.47  nakayama 			: "=r" (_v)					\
    524  1.47  nakayama 			: "r" ((__uintptr_t)(loc)), "n" (asi));		\
    525  1.47  nakayama 	else								\
    526  1.47  nakayama 		SPARC64_LD_NONCONST(ld);				\
    527  1.47  nakayama 	return _v;							\
    528  1.47  nakayama }
    529  1.47  nakayama #else
    530  1.47  nakayama #define SPARC64_LD_DEF(ld, type, vtype)	\
    531  1.47  nakayama static __inline type ld(paddr_t loc, int asi)				\
    532  1.47  nakayama {									\
    533  1.47  nakayama 	vtype _v;							\
    534  1.47  nakayama 	SPARC64_LD_NONCONST(ld);					\
    535  1.47  nakayama 	return _v;							\
    536  1.21       eeh }
    537  1.21       eeh #endif
    538  1.47  nakayama #define SPARC64_LD_DEF64(ld, type)	SPARC64_LD_DEF(ld, type, uint64_t)
    539  1.21       eeh 
    540  1.47  nakayama #else	/* __arch64__ */
    541  1.21       eeh 
    542  1.47  nakayama /* 32-bit kernel, MMU bypass, non-constant */
    543  1.47  nakayama #define SPARC64_LD_PHYS_NONCONST(ld)	\
    544  1.47  nakayama 	__asm volatile(							\
    545  1.53  nakayama 		"clruw %2;		"				\
    546  1.47  nakayama 		"rdpr %%pstate,%1;	"				\
    547  1.47  nakayama 		"sllx %3,32,%0;		"				\
    548  1.47  nakayama 		"wrpr %1,8,%%pstate;	"				\
    549  1.47  nakayama 		"or %0,%2,%0;		"				\
    550  1.47  nakayama 		"wr %4,%%g0,%%asi;	"				\
    551  1.47  nakayama 		#ld " [%0]%%asi,%0;	"				\
    552  1.47  nakayama 		"wrpr %1,0,%%pstate	"				\
    553  1.47  nakayama 		: "=&r" (_v),  "=&r" (_pstate)				\
    554  1.47  nakayama 		: "r" ((uint32_t)(loc)), "r" (_hi), "r" (asi))
    555  1.47  nakayama /* 32-bit kernel, non-constant */
    556  1.47  nakayama #define SPARC64_LD_NONCONST(ld)	\
    557  1.47  nakayama 	__asm volatile(							\
    558  1.47  nakayama 		"wr %2,%%g0,%%asi;	"				\
    559  1.47  nakayama 		#ld " [%1]%%asi,%0	"				\
    560  1.47  nakayama 		: "=&r" (_v)						\
    561  1.47  nakayama 		: "r" ((uint32_t)(loc)), "r" (asi))
    562  1.47  nakayama /* 32-bit kernel, MMU bypass, non-constant, 64-bit value */
    563  1.47  nakayama #define SPARC64_LD_PHYS_NONCONST64(ld)	\
    564  1.47  nakayama 	__asm volatile(							\
    565  1.53  nakayama 		"clruw %2;		"				\
    566  1.47  nakayama 		"rdpr %%pstate,%1;	"				\
    567  1.47  nakayama 		"sllx %3,32,%0;		"				\
    568  1.47  nakayama 		"wrpr %1,8,%%pstate;	"				\
    569  1.47  nakayama 		"or %0,%2,%0;		"				\
    570  1.47  nakayama 		"wr %4,%%g0,%%asi;	"				\
    571  1.47  nakayama 		#ld " [%0]%%asi,%0;	"				\
    572  1.47  nakayama 		"wrpr %1,0,%%pstate;	"				\
    573  1.47  nakayama 		"srlx %0,32,%1;		"				\
    574  1.47  nakayama 		"srl %0,0,%0		"				\
    575  1.47  nakayama 		: "=&r" (_vlo), "=&r" (_vhi)				\
    576  1.47  nakayama 		: "r" ((uint32_t)(loc)), "r" (_hi), "r" (asi))
    577  1.47  nakayama /* 32-bit kernel, non-constant, 64-bit value  */
    578  1.47  nakayama #define SPARC64_LD_NONCONST64(ld)	\
    579  1.47  nakayama 	__asm volatile(							\
    580  1.47  nakayama 		"wr %3,%%g0,%%asi;	"				\
    581  1.47  nakayama 		#ld " [%2]%%asi,%0;	"				\
    582  1.47  nakayama 		"srlx %0,32,%1;		"				\
    583  1.47  nakayama 		"srl %0,0,%0		"				\
    584  1.47  nakayama 		: "=&r" (_vlo), "=&r" (_vhi)				\
    585  1.47  nakayama 		: "r" ((uint32_t)(loc)), "r" (asi))
    586  1.47  nakayama 
    587  1.47  nakayama #if defined(__GNUC__) && defined(__OPTIMIZE__)
    588  1.47  nakayama #define SPARC64_LD_DEF(ld, type, vtype)	\
    589  1.47  nakayama static __inline type ld(paddr_t loc, int asi)				\
    590  1.47  nakayama {									\
    591  1.47  nakayama 	vtype _v;							\
    592  1.47  nakayama 	uint32_t _hi, _pstate;						\
    593  1.47  nakayama 	if (PHYS_ASI(asi)) {						\
    594  1.47  nakayama 		_hi = (uint64_t)(loc) >> 32;				\
    595  1.47  nakayama 		if (__builtin_constant_p(asi))				\
    596  1.47  nakayama 			__asm volatile(					\
    597  1.53  nakayama 				"clruw %2;		"		\
    598  1.47  nakayama 				"rdpr %%pstate,%1;	"		\
    599  1.47  nakayama 				"sllx %3,32,%0;		"		\
    600  1.47  nakayama 				"wrpr %1,8,%%pstate;	"		\
    601  1.47  nakayama 				"or %0,%2,%0;		"		\
    602  1.47  nakayama 				#ld " [%0]%4,%0;	"		\
    603  1.47  nakayama 				"wrpr %1,0,%%pstate;	"		\
    604  1.47  nakayama 				: "=&r" (_v),  "=&r" (_pstate)		\
    605  1.47  nakayama 				: "r" ((uint32_t)(loc)), "r" (_hi),	\
    606  1.47  nakayama 				  "n" (asi));				\
    607  1.47  nakayama 		else							\
    608  1.47  nakayama 			SPARC64_LD_PHYS_NONCONST(ld);			\
    609  1.47  nakayama 	} else {							\
    610  1.47  nakayama 		if (__builtin_constant_p(asi))				\
    611  1.47  nakayama 			__asm volatile(					\
    612  1.47  nakayama 				#ld " [%1]%2,%0		"		\
    613  1.47  nakayama 				: "=&r" (_v)				\
    614  1.47  nakayama 				: "r" ((uint32_t)(loc)), "n" (asi));	\
    615  1.47  nakayama 		else							\
    616  1.47  nakayama 			SPARC64_LD_NONCONST(ld);			\
    617  1.47  nakayama 	}								\
    618  1.47  nakayama 	return _v;							\
    619  1.47  nakayama }
    620  1.47  nakayama #define SPARC64_LD_DEF64(ld, type)	\
    621  1.47  nakayama static __inline type ld(paddr_t loc, int asi)				\
    622  1.47  nakayama {									\
    623  1.47  nakayama 	uint32_t _vlo, _vhi, _hi;					\
    624  1.47  nakayama 	if (PHYS_ASI(asi)) {						\
    625  1.47  nakayama 		_hi = (uint64_t)(loc) >> 32;				\
    626  1.47  nakayama 		if (__builtin_constant_p(asi))				\
    627  1.47  nakayama 			__asm volatile(					\
    628  1.53  nakayama 				"clruw %2;		"		\
    629  1.47  nakayama 				"rdpr %%pstate,%1;	"		\
    630  1.47  nakayama 				"sllx %3,32,%0;		"		\
    631  1.47  nakayama 				"wrpr %1,8,%%pstate;	"		\
    632  1.47  nakayama 				"or %0,%2,%0;		"		\
    633  1.47  nakayama 				#ld " [%0]%4,%0;	"		\
    634  1.47  nakayama 				"wrpr %1,0,%%pstate;	"		\
    635  1.47  nakayama 				"srlx %0,32,%1;		"		\
    636  1.47  nakayama 				"srl %0,0,%0		"		\
    637  1.47  nakayama 				: "=&r" (_vlo),  "=&r" (_vhi)		\
    638  1.47  nakayama 				: "r" ((uint32_t)(loc)), "r" (_hi),	\
    639  1.47  nakayama 				  "n" (asi));				\
    640  1.47  nakayama 		else							\
    641  1.47  nakayama 			SPARC64_LD_PHYS_NONCONST64(ld);			\
    642  1.47  nakayama 	} else {							\
    643  1.47  nakayama 		if (__builtin_constant_p(asi))				\
    644  1.47  nakayama 			__asm volatile(					\
    645  1.47  nakayama 				#ld " [%2]%3,%0;	"		\
    646  1.47  nakayama 				"srlx %0,32,%1;		"		\
    647  1.47  nakayama 				"srl %0,0,%0		"		\
    648  1.47  nakayama 				: "=&r" (_vlo),  "=&r" (_vhi)		\
    649  1.47  nakayama 				: "r" ((uint32_t)(loc)), "n" (asi));	\
    650  1.47  nakayama 		else							\
    651  1.47  nakayama 			SPARC64_LD_NONCONST64(ld);			\
    652  1.47  nakayama 	}								\
    653  1.47  nakayama 	return ((uint64_t)_vhi << 32) | _vlo;				\
    654  1.47  nakayama }
    655  1.47  nakayama #else
    656  1.47  nakayama #define SPARC64_LD_DEF(ld, type, vtype)	\
    657  1.47  nakayama static __inline type ld(paddr_t loc, int asi)				\
    658  1.47  nakayama {									\
    659  1.47  nakayama 	vtype _v;							\
    660  1.47  nakayama 	uint32_t _hi, _pstate;						\
    661  1.47  nakayama 	if (PHYS_ASI(asi)) {						\
    662  1.47  nakayama 		_hi = (uint64_t)(loc) >> 32;				\
    663  1.47  nakayama 		SPARC64_LD_PHYS_NONCONST(ld);				\
    664  1.47  nakayama 	} else								\
    665  1.47  nakayama 		SPARC64_LD_NONCONST(ld);				\
    666  1.47  nakayama 	return _v;							\
    667  1.47  nakayama }
    668  1.47  nakayama #define SPARC64_LD_DEF64(ld, type)	\
    669  1.47  nakayama static __inline type ld(paddr_t loc, int asi)				\
    670  1.47  nakayama {									\
    671  1.47  nakayama 	uint32_t _vlo, _vhi, _hi;					\
    672  1.47  nakayama 	if (PHYS_ASI(asi)) {						\
    673  1.47  nakayama 		_hi = (uint64_t)(loc) >> 32;				\
    674  1.47  nakayama 		SPARC64_LD_PHYS_NONCONST64(ld);				\
    675  1.47  nakayama 	} else								\
    676  1.47  nakayama 		SPARC64_LD_NONCONST64(ld);				\
    677  1.47  nakayama 	return ((uint64_t)_vhi << 32) | _vlo;				\
    678  1.21       eeh }
    679  1.21       eeh #endif
    680  1.21       eeh 
    681  1.47  nakayama #endif	/* __arch64__ */
    682  1.21       eeh 
    683  1.47  nakayama /* load byte from alternate address space */
    684  1.47  nakayama SPARC64_LD_DEF(lduba, uint8_t, uint32_t)
    685  1.47  nakayama /* load half-word from alternate address space */
    686  1.47  nakayama SPARC64_LD_DEF(lduha, uint16_t, uint32_t)
    687  1.21       eeh /* load unsigned int from alternate address space */
    688  1.47  nakayama SPARC64_LD_DEF(lda, uint32_t, uint32_t)
    689  1.21       eeh /* load signed int from alternate address space */
    690  1.47  nakayama SPARC64_LD_DEF(ldswa, int, int)
    691  1.47  nakayama /* load 64-bit unsigned int from alternate address space */
    692  1.47  nakayama SPARC64_LD_DEF64(ldxa, uint64_t)
    693  1.21       eeh 
    694  1.21       eeh 
    695  1.47  nakayama #ifdef __arch64__
    696  1.21       eeh 
    697  1.47  nakayama /* 64-bit kernel, non-constant */
    698  1.47  nakayama #define SPARC64_ST_NONCONST(st)	\
    699  1.47  nakayama 	__asm volatile(							\
    700  1.47  nakayama 		"wr %2,%%g0,%%asi;	"				\
    701  1.47  nakayama 		#st " %0,[%1]%%asi	"				\
    702  1.47  nakayama 		: : "r" (value), "r" ((__uintptr_t)(loc)),		\
    703  1.47  nakayama 		    "r" (asi))
    704  1.47  nakayama 
    705  1.47  nakayama #if defined(__GNUC__) && defined(__OPTIMIZE__)
    706  1.47  nakayama #define SPARC64_ST_DEF(st, type)	\
    707  1.47  nakayama static __inline void st(paddr_t loc, int asi, type value)		\
    708  1.47  nakayama {									\
    709  1.47  nakayama 	if (__builtin_constant_p(asi))					\
    710  1.47  nakayama 		__asm volatile(						\
    711  1.47  nakayama 			#st " %0,[%1]%2		"			\
    712  1.47  nakayama 			: : "r" (value), "r" ((__uintptr_t)(loc)),	\
    713  1.47  nakayama 			    "n" (asi));					\
    714  1.47  nakayama 	else								\
    715  1.47  nakayama 		SPARC64_ST_NONCONST(st);				\
    716  1.47  nakayama }
    717  1.47  nakayama #else
    718  1.47  nakayama #define SPARC64_ST_DEF(st, type)	\
    719  1.47  nakayama static __inline void st(paddr_t loc, int asi, type value)		\
    720  1.47  nakayama {									\
    721  1.47  nakayama 	SPARC64_ST_NONCONST(st);					\
    722  1.21       eeh }
    723  1.47  nakayama #endif
    724  1.47  nakayama #define SPARC64_ST_DEF64(st, type)	SPARC64_ST_DEF(st, type)
    725  1.21       eeh 
    726  1.47  nakayama #else	/* __arch64__ */
    727  1.21       eeh 
    728  1.47  nakayama /* 32-bit kernel, MMU bypass, non-constant */
    729  1.47  nakayama #define SPARC64_ST_PHYS_NONCONST(st)	\
    730  1.47  nakayama 	__asm volatile(							\
    731  1.53  nakayama 		"clruw %3;		"				\
    732  1.47  nakayama 		"rdpr %%pstate,%1;	"				\
    733  1.47  nakayama 		"sllx %4,32,%0;		"				\
    734  1.47  nakayama 		"wrpr %1,8,%%pstate;	"				\
    735  1.47  nakayama 		"or %0,%3,%0;		"				\
    736  1.47  nakayama 		"wr %5,%%g0,%%asi;	"				\
    737  1.47  nakayama 		#st " %2,[%0]%%asi;	"				\
    738  1.47  nakayama 		"wrpr %1,0,%%pstate	"				\
    739  1.47  nakayama 		: "=&r" (_hi), "=&r" (_pstate)				\
    740  1.47  nakayama 		: "r" (value), "r" ((uint32_t)(loc)),			\
    741  1.47  nakayama 		  "r" (_hi), "r" (asi))
    742  1.47  nakayama /* 32-bit kernel, non-constant */
    743  1.47  nakayama #define SPARC64_ST_NONCONST(st)	\
    744  1.47  nakayama 	__asm volatile(							\
    745  1.47  nakayama 		"wr %2,%%g0,%%asi;	"				\
    746  1.47  nakayama 		#st " %0,[%1]%%asi	"				\
    747  1.47  nakayama 		: : "r" (value), "r" ((uint32_t)(loc)), "r" (asi))
    748  1.47  nakayama /* 32-bit kernel, MMU bypass, non-constant, 64-bit value */
    749  1.47  nakayama #define SPARC64_ST_PHYS_NONCONST64(st)	\
    750  1.47  nakayama 	__asm volatile(							\
    751  1.53  nakayama 		"clruw %3;		"				\
    752  1.53  nakayama 		"clruw %5;		"				\
    753  1.47  nakayama 		"sllx %4,32,%1;		"				\
    754  1.47  nakayama 		"sllx %6,32,%0; 	"				\
    755  1.47  nakayama 		"rdpr %%pstate,%2;	"				\
    756  1.47  nakayama 		"or %1,%3,%1;		"				\
    757  1.47  nakayama 		"wrpr %2,8,%%pstate;	"				\
    758  1.47  nakayama 		"or %0,%5,%0;		"				\
    759  1.47  nakayama 		"wr %7,%%g0,%%asi;	"				\
    760  1.47  nakayama 		#st " %1,[%0]%%asi;	"				\
    761  1.47  nakayama 		"wrpr %2,0,%%pstate	"				\
    762  1.47  nakayama 		: "=&r" (_hi), "=&r" (_vhi), "=&r" (_vlo)		\
    763  1.47  nakayama 		: "r" (_vlo), "r" (_vhi),				\
    764  1.47  nakayama 		  "r" ((uint32_t)(loc)), "r" (_hi), "r" (asi))
    765  1.47  nakayama /* 32-bit kernel, non-constant, 64-bit value */
    766  1.47  nakayama #define SPARC64_ST_NONCONST64(st)	\
    767  1.47  nakayama 	__asm volatile(							\
    768  1.53  nakayama 		"clruw %1;		"				\
    769  1.47  nakayama 		"sllx %2,32,%0;		"				\
    770  1.47  nakayama 		"or %0,%1,%0;		"				\
    771  1.47  nakayama 		"wr %4,%%g0,%%asi;	"				\
    772  1.47  nakayama 		#st " %0,[%3]%%asi	"				\
    773  1.47  nakayama 		: "=&r" (_vhi)						\
    774  1.47  nakayama 		: "r" (_vlo), "r" (_vhi),				\
    775  1.47  nakayama 		  "r" ((uint32_t)(loc)), "r" (asi))
    776  1.47  nakayama 
    777  1.47  nakayama #if defined(__GNUC__) && defined(__OPTIMIZE__)
    778  1.47  nakayama #define SPARC64_ST_DEF(st, type)	\
    779  1.47  nakayama static __inline void st(paddr_t loc, int asi, type value)		\
    780  1.47  nakayama {									\
    781  1.47  nakayama 	uint32_t _hi, _pstate;						\
    782  1.47  nakayama 	if (PHYS_ASI(asi)) {						\
    783  1.47  nakayama 		_hi = (uint64_t)(loc) >> 32;				\
    784  1.47  nakayama 		if (__builtin_constant_p(asi))				\
    785  1.47  nakayama 			__asm volatile(					\
    786  1.53  nakayama 				"clruw %3;		"		\
    787  1.47  nakayama 				"sllx %4,32,%0;		"		\
    788  1.47  nakayama 				"rdpr %%pstate,%1;	"		\
    789  1.47  nakayama 				"or %0,%3,%0;		"		\
    790  1.47  nakayama 				"wrpr %1,8,%%pstate;	"		\
    791  1.47  nakayama 				#st " %2,[%0]%5;	"		\
    792  1.47  nakayama 				"wrpr %1,0,%%pstate	"		\
    793  1.47  nakayama 				: "=&r" (_hi), "=&r" (_pstate)		\
    794  1.47  nakayama 				: "r" (value), "r" ((uint32_t)(loc)),	\
    795  1.47  nakayama 				  "r" (_hi), "n" (asi));		\
    796  1.47  nakayama 		else							\
    797  1.47  nakayama 			SPARC64_ST_PHYS_NONCONST(st);			\
    798  1.47  nakayama 	} else {							\
    799  1.47  nakayama 		if (__builtin_constant_p(asi))				\
    800  1.47  nakayama 			__asm volatile(					\
    801  1.47  nakayama 				#st " %0,[%1]%2		"		\
    802  1.47  nakayama 				: : "r" (value), "r" ((uint32_t)(loc)),	\
    803  1.47  nakayama 				  "n" (asi));				\
    804  1.47  nakayama 		else							\
    805  1.47  nakayama 			SPARC64_ST_NONCONST(st);			\
    806  1.47  nakayama 	}								\
    807  1.47  nakayama }
    808  1.47  nakayama #define SPARC64_ST_DEF64(st, type)	\
    809  1.47  nakayama static __inline void st(paddr_t loc, int asi, type value)		\
    810  1.47  nakayama {									\
    811  1.47  nakayama 	uint32_t _vlo, _vhi, _hi;					\
    812  1.47  nakayama 	_vlo = value;							\
    813  1.47  nakayama 	_vhi = (uint64_t)(value) >> 32;					\
    814  1.47  nakayama 	if (PHYS_ASI(asi)) {						\
    815  1.47  nakayama 		_hi = (uint64_t)(loc) >> 32;				\
    816  1.47  nakayama 		if (__builtin_constant_p(asi))				\
    817  1.47  nakayama 			__asm volatile(					\
    818  1.53  nakayama 				"clruw %3;		"		\
    819  1.53  nakayama 				"clruw %5;		"		\
    820  1.47  nakayama 				"sllx %4,32,%1;		"		\
    821  1.47  nakayama 				"sllx %6,32,%0; 	"		\
    822  1.47  nakayama 				"rdpr %%pstate,%2;	"		\
    823  1.47  nakayama 				"or %1,%3,%1;		"		\
    824  1.47  nakayama 				"or %0,%5,%0;		"		\
    825  1.47  nakayama 				"wrpr %2,8,%%pstate;	"		\
    826  1.47  nakayama 				#st " %1,[%0]%7;	"		\
    827  1.47  nakayama 				"wrpr %2,0,%%pstate	"		\
    828  1.47  nakayama 				: "=&r" (_hi), "=&r" (_vhi), "=&r" (_vlo) \
    829  1.47  nakayama 				: "r" (_vlo), "r" (_vhi),		\
    830  1.47  nakayama 				  "r" ((uint32_t)(loc)), "r" (_hi),	\
    831  1.47  nakayama 				  "n" (asi));				\
    832  1.47  nakayama 		else							\
    833  1.47  nakayama 			SPARC64_ST_PHYS_NONCONST64(st);			\
    834  1.47  nakayama 	} else {							\
    835  1.47  nakayama 		if (__builtin_constant_p(asi))				\
    836  1.47  nakayama 			__asm volatile(					\
    837  1.53  nakayama 				"clruw %1;		"		\
    838  1.47  nakayama 				"sllx %2,32,%0;		"		\
    839  1.47  nakayama 				"or %0,%1,%0;		"		\
    840  1.47  nakayama 				#st " %0,[%3]%4		"		\
    841  1.47  nakayama 				: "=&r" (_vhi)				\
    842  1.47  nakayama 				: "r" (_vlo), "r" (_vhi),		\
    843  1.47  nakayama 				  "r" ((uint32_t)(loc)), "n" (asi));	\
    844  1.47  nakayama 		else							\
    845  1.47  nakayama 			SPARC64_ST_NONCONST64(st);			\
    846  1.47  nakayama 	}								\
    847  1.47  nakayama }
    848  1.47  nakayama #else
    849  1.47  nakayama #define SPARC64_ST_DEF(st, type)	\
    850  1.47  nakayama static __inline void st(paddr_t loc, int asi, type value)		\
    851  1.47  nakayama {									\
    852  1.47  nakayama 	uint32_t _hi, _pstate;						\
    853  1.47  nakayama 	if (PHYS_ASI(asi)) {						\
    854  1.47  nakayama 		_hi = (uint64_t)(loc) >> 32;				\
    855  1.47  nakayama 		SPARC64_ST_PHYS_NONCONST(st);				\
    856  1.47  nakayama 	} else								\
    857  1.47  nakayama 		SPARC64_ST_NONCONST(st);				\
    858  1.47  nakayama }
    859  1.47  nakayama #define SPARC64_ST_DEF64(st, type)	\
    860  1.47  nakayama static __inline void st(paddr_t loc, int asi, type value)		\
    861  1.47  nakayama {									\
    862  1.47  nakayama 	uint32_t _vlo, _vhi, _hi;					\
    863  1.47  nakayama 	_vlo = value;							\
    864  1.47  nakayama 	_vhi = (uint64_t)(value) >> 32;					\
    865  1.47  nakayama 	if (PHYS_ASI(asi)) {						\
    866  1.47  nakayama 		_hi = (uint64_t)(loc) >> 32;				\
    867  1.47  nakayama 		SPARC64_ST_PHYS_NONCONST64(st);				\
    868  1.47  nakayama 	} else								\
    869  1.47  nakayama 		SPARC64_ST_NONCONST64(st);				\
    870  1.21       eeh }
    871  1.21       eeh #endif
    872  1.21       eeh 
    873  1.47  nakayama #endif	/* __arch64__ */
    874  1.21       eeh 
    875  1.21       eeh /* store byte to alternate address space */
    876  1.47  nakayama SPARC64_ST_DEF(stba, uint8_t)
    877  1.21       eeh /* store half-word to alternate address space */
    878  1.47  nakayama SPARC64_ST_DEF(stha, uint16_t)
    879  1.47  nakayama /* store unsigned int to alternate address space */
    880  1.47  nakayama SPARC64_ST_DEF(sta, uint32_t)
    881  1.47  nakayama /* store 64-bit unsigned int to alternate address space */
    882  1.47  nakayama SPARC64_ST_DEF64(stxa, uint64_t)
    883  1.21       eeh 
    884  1.21       eeh 
    885  1.43    martin /* set dmmu secondary context */
    886  1.43    martin static __inline void
    887  1.43    martin dmmu_set_secondary_context(uint ctx)
    888  1.43    martin {
    889  1.43    martin 	__asm volatile(
    890  1.44   hannken 		"stxa %0,[%1]%2;	"
    891  1.43    martin 		"membar #Sync		"
    892  1.47  nakayama 		: : "r" (ctx), "r" (CTX_SECONDARY), "n" (ASI_DMMU)
    893  1.43    martin 		: "memory");
    894  1.43    martin }
    895  1.43    martin 
    896   1.2       eeh /* flush address from data cache */
    897  1.48  nakayama #define	flush(loc) __asm volatile("flush %0" : : "r" ((__uintptr_t)(loc)))
    898   1.6       eeh 
    899   1.6       eeh /*
    900   1.6       eeh  * SPARC V9 memory barrier instructions.
    901   1.6       eeh  */
    902   1.6       eeh /* Make all stores complete before next store */
    903  1.56  nakayama #define	membar_StoreStore() __asm volatile("membar #StoreStore" : :)
    904   1.6       eeh /* Make all loads complete before next store */
    905  1.56  nakayama #define	membar_LoadStore() __asm volatile("membar #LoadStore" : :)
    906   1.6       eeh /* Make all stores complete before next load */
    907  1.56  nakayama #define	membar_StoreLoad() __asm volatile("membar #StoreLoad" : :)
    908   1.6       eeh /* Make all loads complete before next load */
    909  1.56  nakayama #define	membar_LoadLoad() __asm volatile("membar #LoadLoad" : :)
    910   1.6       eeh /* Complete all outstanding memory operations and exceptions */
    911  1.56  nakayama #define	membar_Sync() __asm volatile("membar #Sync" : :)
    912   1.6       eeh /* Complete all outstanding memory operations */
    913  1.56  nakayama #define	membar_MemIssue() __asm volatile("membar #MemIssue" : :)
    914   1.6       eeh /* Complete all outstanding stores before any new loads */
    915  1.56  nakayama #define	membar_Lookaside() __asm volatile("membar #Lookaside" : :)
    916   1.2       eeh 
    917  1.56  nakayama #define membar_Load() __asm volatile("membar #LoadLoad | #LoadStore" : :)
    918  1.56  nakayama #define membar_Store() __asm volatile("membar #LoadStore | #StoreStore" : :)
    919  1.36    petrov 
    920   1.9       eeh #endif
    921  1.33    petrov 
    922  1.33    petrov #endif /* _SPARC_CTLREG_H_ */
    923