/*
* Copyright (c) 1996-2002 Eduardo Horvath
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
#ifndef _SPARC_CTLREG_H_
#define _SPARC_CTLREG_H_
/*
* Sun 4u control registers. (includes address space definitions
* and some registers in control space).
*/
/*
* The Alternate address spaces.
*
* 0x00-0x7f are privileged
* 0x80-0xff can be used by users
*/
#define ASI_LITTLE 0x08 /* This bit should make an ASI little endian */
#define ASI_NUCLEUS 0x04 /* [4u] kernel address space */
#define ASI_NUCLEUS_LITTLE 0x0c /* [4u] kernel address space, little endian */
#define ASI_AS_IF_USER_PRIMARY 0x10 /* [4u] primary user address space */
#define ASI_AS_IF_USER_SECONDARY 0x11 /* [4u] secondary user address space */
#define ASI_PHYS_CACHED 0x14 /* [4u] MMU bypass to main memory */
#define ASI_PHYS_NON_CACHED 0x15 /* [4u] MMU bypass to I/O location */
#define ASI_AS_IF_USER_PRIMARY_LITTLE 0x18 /* [4u] primary user address space, little endian */
#define ASI_AS_IF_USER_SECONDARY_LITTLE 0x19 /* [4u] secondary user address space, little endian */
#define ASI_PHYS_CACHED_LITTLE 0x1c /* [4u] MMU bypass to main memory, little endian */
#define ASI_PHYS_NON_CACHED_LITTLE 0x1d /* [4u] MMU bypass to I/O location, little endian */
#define ASI_MMU_CONTEXTID 0x21 /* [4v] MMU context control - both IMMU and DMMU */
#define ASI_NUCLEUS_QUAD_LDD 0x24 /* [4u] use w/LDDA to load 128-bit item */
#define ASI_QUEUE 0x25 /* [4v] interrupt queue registers */
#define ASI_NUCLEUS_QUAD_LDD_LITTLE 0x2c /* [4u] use w/LDDA to load 128-bit item, little endian */
/* Get the CPU's Fireplane agent ID */
#define FIREPLANE_CR_AID(x) (((x) >> 17) & 0x3ff)
#define CPU_FIREPLANEID FIREPLANE_CR_AID(ldxa(0, ASI_MID_REG))
/* Get the CPU's Jupiter Bus interrupt target ID */
#define JUPITER_CR_ITID(x) ((x) & 0x3ff)
#define CPU_JUPITERID JUPITER_CR_ITID(ldxa(0, ASI_MID_REG))
/*
* [4u] MMU and Cache Control Register (MCCR)
* use ASI = 0x45
*/
#define ASI_MCCR ASI_LSU_CONTROL_REGISTER
#define MCCR 0x00
/*
* The following are the control registers
* They work on both MMUs unless noted.
* III = cheetah only
*
* Register contents are defined later on individual registers.
*/
#define TSB_TAG_TARGET 0x0
#define TLB_DATA_IN 0x0
#define CTX_PRIMARY 0x08 /* primary context -- DMMU only */
#define CTX_SECONDARY 0x10 /* secondary context -- DMMU only */
#define SFSR 0x18
#define SFAR 0x20 /* fault address -- DMMU only */
#define TSB 0x28
#define TLB_TAG_ACCESS 0x30
#define VIRTUAL_WATCHPOINT 0x38
#define PHYSICAL_WATCHPOINT 0x40
#define TSB_PEXT 0x48 /* III primary ext */
#define TSB_SEXT 0x50 /* III 2ndary ext -- DMMU only */
#define TSB_NEXT 0x58 /* III nucleus ext */
/*
* TLB demap registers. TTEs are defined in v9pte.h
*
* Use the address space to select between IMMU and DMMU.
* The address of the register selects which context register
* to read the ASI from.
*
* The data stored in the register is interpreted as the VA to
* use. The DEMAP_CTX_<> registers ignore the address and demap the
* entire ASI.
*
*/
#define ASI_IMMU_DEMAP 0x57 /* [4u] IMMU TLB demap */
#define ASI_DMMU_DEMAP 0x5f /* [4u] IMMU TLB demap */
#define DEMAP_PAGE_NUCLEUS ((0x02)<<4) /* Demap page from kernel AS */
#define DEMAP_PAGE_PRIMARY ((0x00)<<4) /* Demap a page from primary CTXT */
#define DEMAP_PAGE_SECONDARY ((0x01)<<4) /* Demap page from secondary CTXT (DMMU only) */
#define DEMAP_CTX_NUCLEUS ((0x06)<<4) /* Demap all of kernel CTXT */
#define DEMAP_CTX_PRIMARY ((0x04)<<4) /* Demap all of primary CTXT */
#define DEMAP_CTX_SECONDARY ((0x05)<<4) /* Demap all of secondary CTXT */
#define DEMAP_ALL ((0x08)<<4) /* Demap all non-locked TLB entries [USIII] */
/*
* These define the sizes of the TLB in various CPUs.
* They're mostly not necessary except for diagnostic code.
*/
#define TLB_SIZE_SPITFIRE 64
#define TLB_SIZE_CHEETAH_I16 16
#define TLB_SIZE_CHEETAH_I128 128
#define TLB_SIZE_CHEETAH_D16 16
#define TLB_SIZE_CHEETAH_D512_0 512
#define TLB_SIZE_CHEETAH_D512_1 512
#define TLB_CHEETAH_I16 (0 << 16)
#define TLB_CHEETAH_I128 (2 << 16)
#define TLB_CHEETAH_D16 (0 << 16)
#define TLB_CHEETAH_D512_0 (2 << 16)
#define TLB_CHEETAH_D512_1 (3 << 16)
/*
* Interrupt registers. This really gets hairy.
*/
#define IDDR_0H 0x40 /* Store data to send in these regs */
#define IDDR_0L 0x48 /* unimplemented */
#define IDDR_1H 0x50
#define IDDR_1L 0x58 /* unimplemented */
#define IDDR_2H 0x60
#define IDDR_2L 0x68 /* unimplemented */
#define IDDR_3H 0x70 /* unimplemented */
#define IDDR_3L 0x78 /* unimplemented */
/*
* Error registers
*/
/* Since we won't try to fix async errs, we don't care about the bits in the regs */
#define ASI_AFAR 0x4d /* Asynchronous fault address register */
#define AFAR 0x00
#define ASI_AFSR 0x4c /* Asynchronous fault status register */
#define AFSR 0x00
/*
* ``Routines'' to load and store from/to alternate address space.
* The location can be a variable, the asi value (address space indicator)
* must be a constant.
*
* N.B.: You can put as many special functions here as you like, since
* they cost no kernel space or time if they are not used.
*
* These were static inline functions, but gcc screws up the constraints
* on the address space identifiers (the "n"umeric value part) because
* it inlines too late, so we have to use the funny valued-macro syntax.
*/
/*
* Apparently the definition of bypass ASIs is that they all use the
* D$ so we need to flush the D$ to make sure we don't get data pollution.
*/
/* load byte from alternate address space */
SPARC64_LD_DEF(lduba, uint8_t, uint32_t)
/* load half-word from alternate address space */
SPARC64_LD_DEF(lduha, uint16_t, uint32_t)
/* load unsigned int from alternate address space */
SPARC64_LD_DEF(lda, uint32_t, uint32_t)
/* load unsigned word from alternate address space */
SPARC64_LD_DEF(lduwa, uint32_t, uint32_t)
/* load signed int from alternate address space */
SPARC64_LD_DEF(ldswa, int, int)
/* load 64-bit unsigned int from alternate address space */
SPARC64_LD_DEF64(ldxa, uint64_t)
/* store byte to alternate address space */
SPARC64_ST_DEF(stba, uint8_t)
/* store half-word to alternate address space */
SPARC64_ST_DEF(stha, uint16_t)
/* store unsigned int to alternate address space */
SPARC64_ST_DEF(sta, uint32_t)
/* store 64-bit unsigned int to alternate address space */
SPARC64_ST_DEF64(stxa, uint64_t)
/*
* SPARC V9 memory barrier instructions.
*/
/* Make all stores complete before next store */
#define membar_StoreStore() __asm volatile("membar #StoreStore" : :)
/* Make all loads complete before next store */
#define membar_LoadStore() __asm volatile("membar #LoadStore" : :)
/* Make all stores complete before next load */
#define membar_StoreLoad() __asm volatile("membar #StoreLoad" : :)
/* Make all loads complete before next load */
#define membar_LoadLoad() __asm volatile("membar #LoadLoad" : :)
/* Complete all outstanding memory operations and exceptions */
#define membar_Sync() __asm volatile("membar #Sync" : :)
/* Complete all outstanding memory operations */
#define membar_MemIssue() __asm volatile("membar #MemIssue" : :)
/* Complete all outstanding stores before any new loads */
#define membar_Lookaside() __asm volatile("membar #Lookaside" : :)