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