/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* Assembly code support for the jalapeno module
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#if !defined(lint)
#include "assym.h"
#endif /* lint */
#include <sys/asm_linkage.h>
#include <vm/hat_sfmmu.h>
#include <sys/machparam.h>
#include <sys/machcpuvar.h>
#include <sys/machthread.h>
#include <sys/machtrap.h>
#include <sys/privregs.h>
#include <sys/asm_linkage.h>
#include <sys/cheetahregs.h>
#include <sys/us3_module.h>
#include <sys/cheetahasm.h>
#ifdef TRAPTRACE
#include <sys/traptrace.h>
#endif /* TRAPTRACE */
#if !defined(lint)
/* BEGIN CSTYLED */
#if defined(JALAPENO) && defined(JALAPENO_ERRATA_85)
/*
* j_chng_pa - scratch register
* scr - scratch register
*/
5: \
6: \
/*
* Macro to set Jalapeno CPU speed
* speed - new speed constant
* scr1 - scratch register
* scr2 - scratch register
*/
/*
* macro to set Master Tomatillo speed
* speed - tomatillo speed constant
* tpa - tomatillo estar control register PA
* scr - scratch register
*/
/*
* macro to check and set Slave Tomatillo speed
* speed - tomatillo speed constant
* scr1 - scratch register
* scr2 - scratch register
*/
nop; \
4:
/*
* macro to adjust ASI_MCU_CTL_REG1[26:25] fsm bits according to
* new cpu speed: fsm[1:0]=11b for full speed, fsm[1:0]=0 for estar speed
* value - fsm bit value constant
* scr1 - scratch register
* scr2 - scratch register
*/
/*
* JP_FORCE_FULL_SPEED and its fellow macros are for Jalapeno
* workstation to work around Errata 85. The front portion of
* it packs JP speed(14..13) and Tomatillo speed(5..0) into one
* register.
*
* Current code assumes that these two fields are non-overlapping.
* If that assumption changes, then this code won't work. If so, we
* force a compile time error by not defining the JP_FORCE_FULL_SPEED
* and JP_RESTORE_SPEED macros below.
*/
#if !(JBUS_CONFIG_ECLK_MASK & TOM_SPEED_MASK)
/*
* old_lvl - register used to save original cpu, tomatillo speed
* scr2 - scratch register
* scr3 - scratch register
* scr4 - scratch register
*/
/* original jp and tomatillo speed saved in old_lvl */ \
\
/* either intended or currently at full speed */ \
nop; \
/* go through 1/2 speed. */ \
8: \
/* bring to 1:1 speed */ \
/*
* old_lvl - register contains saved original cpu, tomatillo speed
* scr2 - scratch register
* scr3 - scratch register
* scr4 - scratch register
*
* If trap had occured in the middle of ppm cpu speed transtion, then
* old_lvl[31:10] contains the intended new speed written into jbus_config.
* if old_lvl[9:0] is inconsistent with old_lvl[31:10], then the trap surely
* interrupted the ppm cpu speed transition, otherwise nothing for sure.
* We'll restore the intended/then-current speed, that should cause no
* trouble to subsequent ppm cpu speed change code.
*/
nop; \
/* scr2 contains tom speed according to intended jp speed */ \
7: \
/* updated old_lvl to contain intended jp and tom speed */ \
nop; \
\
/* go to half speed */ \
nop; \
\
/* go to 1:32 speed */ \
9:
#endif /* !(JBUS_CONFIG_ECLK_MASK & TOM_SPEED_MASK) */
#endif /* JALAPENO && JALAPENO_ERRATA_85 */
/*
* Jalapeno version to reflush an Ecache line by index.
* Will flush all 4 ways (with only one scratch register).
* Note that the code will be faster if we use 2 scratch registers.
*/
/*
* Jalapeno version of ecache_flush_line. Uses Jalapeno Ecache Displacement
*/
/*
* Macro for getting ecache size from cpunodes structure
* scr1: Scratch, ecache size returned in this
* scr2: Scratch
*/
/* END CSTYLED */
#endif /* !lint */
#if defined(lint)
/* ARGSUSED */
void
{ return; }
#else /* lint */
/*
*/
#endif /* lint */
/*
* flush_ecache:
* %o0 - 64 bit physical address
* %o1 - ecache size
* %o2 - ecache linesize
*/
#if defined(lint)
/*ARGSUSED*/
void
{}
#else /* !lint */
#if defined(JALAPENO) && defined(JALAPENO_ERRATA_85)
#endif /* JALAPENO && JALAPENO_ERRATA_85 */
/*
* Flush the entire Ecache using displacement flush.
*/
#if defined(JALAPENO) && defined(JALAPENO_ERRATA_85)
#endif /* JALAPENO && JALAPENO_ERRATA_85 */
#endif /* lint */
#if defined(lint)
void
fast_ecc_err(void)
{}
#else /* lint */
.section ".text"
.align 64
/*
* Turn off CEEN and NCEEN.
*/
/*
* Do the CPU log out capture.
* %g3 = "failed?" return value.
* %g2 = Input = AFAR. Output the clo_flags info which is passed
* into this macro via %g4. Output only valid if cpu_private
* struct has not been initialized.
* CHPR_FECCTL0_LOGOUT = cpu logout structure offset input
* %g4 = Trap information stored in the cpu logout flags field
* %g5 = scr1
* %g6 = scr2
* %g3 = scr3
* %g4 = scr4
*/
/*
* Flush the Ecache to get the error out of the Ecache. If the UCC
* or UCU is on a dirty line, then the following flush will turn
* that into a WDC or WDU, respectively.
*/
#if defined(JALAPENO) && defined(JALAPENO_ERRATA_85)
#endif /* JALAPENO && JALAPENO_ERRATA_85 */
#if defined(JALAPENO) && defined(JALAPENO_ERRATA_85)
#endif /* JALAPENO && JALAPENO_ERRATA_85 */
/*
* Flush the Dcache. Since bad data could have been installed in
* the Dcache we must flush it before re-enabling it.
*/
/*
* Flush the Icache. Since we turned off the Icache to capture the
* Icache line it is now stale or corrupted and we must flush it
* before re-enabling it.
*/
5:
/*
* Restore the Dcache and Icache to the previous state.
*/
/*
* Make sure our CPU logout operation was successful.
*/
be 8f
/*
* If the logout structure had been busy, how many times have
* we tried to use it and failed (nesting count)? If we have
* already recursed a substantial number of times, then we can
* assume things are not going to get better by themselves and
* so it would be best to panic.
*/
blt 7f
7:
/*
* Otherwise, if the logout structure was busy but we have not
* nested more times than our maximum value, then we simply
* issue a retry. Our TL=0 trap handler code will check and
* clear the AFSR after it is done logging what is currently
* in the logout struct and handle this event at that time.
*/
8:
/*
* Call cpu_fast_ecc_error via systrap at PIL 14 unless we're
* already at PIL 15.
*/
#endif /* lint */
/*
* Fast ECC error at TL>0 handler
* We get here via trap 70 at TL>0->Software trap 0 at TL>0. We enter
* this routine with %g1 and %g2 already saved in %tpc, %tnpc and %tstate.
* For a complete description of the Fast ECC at TL>0 handling see the
*/
#if defined(lint)
void
fast_ecc_tl1_err(void)
{}
#else /* lint */
.section ".text"
.align 64
/*
* This macro turns off the D$/I$ if they are on and saves their
* original state in ch_err_tl1_tmp, saves all the %g registers in the
* ch_err_tl1_data structure, updates the ch_err_tl1_flags and saves
* the %tpc in ch_err_tl1_tpc. At the end of this macro, %g1 will
* point to the ch_err_tl1_data structure and the original D$/I$ state
* will be saved in ch_err_tl1_tmp. All %g registers except for %g1
* will be available.
*/
/*
* Get the diagnostic logout data. %g4 must be initialized to
* current CEEN state, %g5 must point to logout structure in
* ch_err_tl1_data_t. %g3 will contain the nesting count upon
* return.
*/
/*
* If the logout nesting count is exceeded, we're probably
* not making any progress, try to panic instead.
*/
/*
* Save the current CEEN and NCEEN state in %g7 and turn them off
* before flushing the Ecache.
*/
/*
* Flush the Ecache, using the largest possible cache size with the
* smallest possible line size since we can't get the actual sizes
* from the cpu_node due to DTLB misses.
*/
#if defined(JALAPENO) && defined(JALAPENO_ERRATA_85)
#endif /* JALAPENO && JALAPENO_ERRATA_85 */
#if defined(JALAPENO) && defined(JALAPENO_ERRATA_85)
#endif /* JALAPENO && JALAPENO_ERRATA_85 */
/*
* Restore CEEN and NCEEN to the previous state.
*/
/*
* If we turned off the D$, then flush it and turn it back on.
*/
/*
* Flush the D$.
*/
/*
* Turn the D$ back on.
*/
3:
/*
* If we turned off the I$, then flush it and turn it back on.
*/
/*
* Flush the I$.
*/
/*
* Turn the I$ back on. Changing DCU_IC requires flush.
*/
4:
#ifdef TRAPTRACE
/*
* Get current trap trace entry physical pointer.
*/
/*
* Create trap trace entry.
*/
/*
* Advance trap trace pointer.
*/
#endif /* TRAPTRACE */
/*
* handling and just do the necessary cache-flushing.
*/
/*
* If a UCU followed by a WDU has occurred go ahead and panic
* since a UE will occur (on the retry) before the UCU and WDU
* messages are enqueued.
*/
6:
/*
* We fall into this macro if we've successfully logged the error in
* the ch_err_tl1_data structure and want the PIL15 softint to pick
* it up and log it. %g1 must point to the ch_err_tl1_data structure.
* Restores the %g registers and issues retry.
*/
/*
* Establish panic exit label.
*/
#endif /* lint */
#if defined(lint)
get_jbus_config(void)
{ return (0); }
/* ARGSUSED */
void
{}
/* ARGSUSED */
void
{}
get_mcu_ctl_reg1(void)
{ return (0); }
#else /* lint */
#endif /* lint */
#if defined(lint)
/*
* scrubphys - Pass in the aligned physical memory address
* that you want to scrub, along with the ecache set size.
*
* 1) Displacement flush the E$ line corresponding to %addr.
* The first ldxa guarantees that the %addr is no longer in
* M, O, or E (goes to I or S (if instruction fetch also happens).
* 2) "Write" the data using a CAS %addr,%g0,%g0.
* The casxa guarantees a transition from I to M or S to M.
* 3) Displacement flush the E$ line corresponding to %addr.
* The second ldxa pushes the M line out of the ecache, into the
* writeback buffers, on the way to memory.
* 4) The "membar #Sync" pushes the cache line out of the writeback
* buffers onto the bus, on the way to dram finally.
*
* This is a modified version of the algorithm suggested by Gary Lauterbach.
* In theory the CAS %addr,%g0,%g0 is supposed to mark the addr's cache line
* as modified, but then we found out that for spitfire, if it misses in the
* E$ it will probably install as an M, but if it hits in the E$, then it
* will stay E, if the store doesn't happen. So the first displacement flush
* should ensure that the CAS will miss in the E$. Arrgh.
*/
/* ARGSUSED */
void
{}
#else /* lint */
#if defined(JALAPENO) && defined(JALAPENO_ERRATA_85)
#endif /* JALAPENO && JALAPENO_ERRATA_85 */
#if defined(JALAPENO) && defined(JALAPENO_ERRATA_85)
#endif /* JALAPENO && JALAPENO_ERRATA_85 */
#endif /* lint */
#if defined(lint)
/*
* clearphys - Pass in the physical memory address of the checkblock
* that you want to push out, cleared with a recognizable pattern,
* from the ecache.
*
* To ensure that the ecc gets recalculated after the bad data is cleared,
* we must write out enough data to fill the w$ line (64 bytes). So we read
* in an entire ecache subblock's worth of data, and write it back out.
* Then we overwrite the 16 bytes of bad data with the pattern.
*/
/* ARGSUSED */
void
{
}
#else /* lint */
/* turn off IE, AM bits */
/* turn off NCEEN */
/* align address passed with 64 bytes subblock size */
/* move the good data into the W$ */
1:
bge 1b
/* now overwrite the bad data */
#if defined(JALAPENO) && defined(JALAPENO_ERRATA_85)
#endif /* JALAPENO && JALAPENO_ERRATA_85 */
#if defined(JALAPENO) && defined(JALAPENO_ERRATA_85)
#endif /* JALAPENO && JALAPENO_ERRATA_85 */
/* clear the AFSR */
/* turn NCEEN back on */
/* return and re-enable IE and AM */
#endif /* lint */
#if defined(lint)
/*
* Jalapeno Ecache displacement flush the specified line from the E$
*
* Register usage:
* %o0 - 64 bit physical address for flushing
* %o1 - Ecache set size
*/
/*ARGSUSED*/
void
{
}
#else /* lint */
#if defined(JALAPENO) && defined(JALAPENO_ERRATA_85)
#endif /* JALAPENO && JALAPENO_ERRATA_85 */
#if defined(JALAPENO) && defined(JALAPENO_ERRATA_85)
#endif /* JALAPENO && JALAPENO_ERRATA_85 */
#endif /* lint */
/*
* Perform necessary cpu workaround to ensure jbus ordering.
* Called only from Fire systems.
* CPU's internal "invalidate FIFOs" are flushed.
*/
#if defined(lint)
void
{}
#else /* lint */
.seg ".data"
#endif /* lint */
#if defined(lint)
/*
* This routine will not be called in Jalapeno systems.
*/
void
flush_ipb(void)
{ return; }
#else /* lint */
#endif /* lint */