xref: /titanic_44/usr/src/uts/sun4u/cpu/us3_jalapeno_asm.s (revision 750ba2244c23d03e3f43b4967911885b36bbac55)
17c478bd9Sstevel@tonic-gate/*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate * with the License.
87c478bd9Sstevel@tonic-gate *
97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate * and limitations under the License.
137c478bd9Sstevel@tonic-gate *
147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate *
207c478bd9Sstevel@tonic-gate * CDDL HEADER END
217c478bd9Sstevel@tonic-gate */
227c478bd9Sstevel@tonic-gate/*
23*750ba224Sanbui * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate *
267c478bd9Sstevel@tonic-gate * Assembly code support for the jalapeno module
277c478bd9Sstevel@tonic-gate */
287c478bd9Sstevel@tonic-gate
297c478bd9Sstevel@tonic-gate#pragma ident	"%Z%%M%	%I%	%E% SMI"
307c478bd9Sstevel@tonic-gate
317c478bd9Sstevel@tonic-gate#if !defined(lint)
327c478bd9Sstevel@tonic-gate#include "assym.h"
337c478bd9Sstevel@tonic-gate#endif	/* lint */
347c478bd9Sstevel@tonic-gate
357c478bd9Sstevel@tonic-gate#include <sys/asm_linkage.h>
367c478bd9Sstevel@tonic-gate#include <sys/mmu.h>
377c478bd9Sstevel@tonic-gate#include <vm/hat_sfmmu.h>
387c478bd9Sstevel@tonic-gate#include <sys/machparam.h>
397c478bd9Sstevel@tonic-gate#include <sys/machcpuvar.h>
407c478bd9Sstevel@tonic-gate#include <sys/machthread.h>
417c478bd9Sstevel@tonic-gate#include <sys/machtrap.h>
427c478bd9Sstevel@tonic-gate#include <sys/privregs.h>
437c478bd9Sstevel@tonic-gate#include <sys/asm_linkage.h>
447c478bd9Sstevel@tonic-gate#include <sys/trap.h>
457c478bd9Sstevel@tonic-gate#include <sys/cheetahregs.h>
467c478bd9Sstevel@tonic-gate#include <sys/us3_module.h>
477c478bd9Sstevel@tonic-gate#include <sys/xc_impl.h>
487c478bd9Sstevel@tonic-gate#include <sys/intreg.h>
497c478bd9Sstevel@tonic-gate#include <sys/async.h>
507c478bd9Sstevel@tonic-gate#include <sys/clock.h>
517c478bd9Sstevel@tonic-gate#include <sys/cheetahasm.h>
527c478bd9Sstevel@tonic-gate
537c478bd9Sstevel@tonic-gate#ifdef TRAPTRACE
547c478bd9Sstevel@tonic-gate#include <sys/traptrace.h>
557c478bd9Sstevel@tonic-gate#endif /* TRAPTRACE */
567c478bd9Sstevel@tonic-gate
577c478bd9Sstevel@tonic-gate#if !defined(lint)
587c478bd9Sstevel@tonic-gate
597c478bd9Sstevel@tonic-gate/* BEGIN CSTYLED */
607c478bd9Sstevel@tonic-gate
617c478bd9Sstevel@tonic-gate#if defined(JALAPENO) && defined(JALAPENO_ERRATA_85)
627c478bd9Sstevel@tonic-gate
637c478bd9Sstevel@tonic-gate#define	CHK_JP_ERRATA85_ENABLED(scr, label)				\
647c478bd9Sstevel@tonic-gate	ASM_LD(scr, jp_errata_85_active);				\
657c478bd9Sstevel@tonic-gate	cmp	scr, 1;							\
667c478bd9Sstevel@tonic-gate	bne	%icc, label;						\
677c478bd9Sstevel@tonic-gate	nop
687c478bd9Sstevel@tonic-gate
697c478bd9Sstevel@tonic-gate#define	SET_64BIT_PA(dest, scr, hi32, lo32)				\
707c478bd9Sstevel@tonic-gate	set	hi32, scr;						\
717c478bd9Sstevel@tonic-gate	sllx	scr, 32, scr;						\
727c478bd9Sstevel@tonic-gate	sethi	%hi(lo32), dest;					\
737c478bd9Sstevel@tonic-gate	or	dest, %lo(lo32), dest;					\
747c478bd9Sstevel@tonic-gate	or	scr, dest, dest
757c478bd9Sstevel@tonic-gate
767c478bd9Sstevel@tonic-gate/*
777c478bd9Sstevel@tonic-gate * Macro to trigger Jalapeno/Tomatillo speed change
787c478bd9Sstevel@tonic-gate *   j_chng_pa - scratch register
797c478bd9Sstevel@tonic-gate *   scr - scratch register
807c478bd9Sstevel@tonic-gate */
817c478bd9Sstevel@tonic-gate#define	JP_ESTAR_TRIGGER(j_chng_pa, scr)				\
827c478bd9Sstevel@tonic-gate	SET_64BIT_PA(j_chng_pa, scr, TOM_HIGH_PA, M_T_J_CHNG_INIT_PA);	\
837c478bd9Sstevel@tonic-gate	ldxa	[j_chng_pa]ASI_IO, scr;					\
847c478bd9Sstevel@tonic-gate5:									\
857c478bd9Sstevel@tonic-gate	and	scr, TOM_TRIGGER_MASK, scr;				\
867c478bd9Sstevel@tonic-gate	cmp	scr, TOM_TRIGGER;					\
877c478bd9Sstevel@tonic-gate	be,pt %icc, 5b;			/* wait while 10 */		\
887c478bd9Sstevel@tonic-gate	ldxa	[j_chng_pa]ASI_IO, scr;					\
897c478bd9Sstevel@tonic-gate	andn	scr, TOM_TRIGGER_MASK, scr;				\
907c478bd9Sstevel@tonic-gate	stxa	scr, [j_chng_pa]ASI_IO;	/* clear j_chng[1:0] */		\
917c478bd9Sstevel@tonic-gate	or	scr, TOM_TRIGGER, scr;					\
927c478bd9Sstevel@tonic-gate	stxa	scr, [j_chng_pa]ASI_IO;	/* trigger j_chng */		\
937c478bd9Sstevel@tonic-gate	ldxa	[j_chng_pa]ASI_IO, scr;					\
947c478bd9Sstevel@tonic-gate6:									\
957c478bd9Sstevel@tonic-gate	and	scr, TOM_TRIGGER_MASK, scr;				\
967c478bd9Sstevel@tonic-gate	cmp	scr, TOM_TRIGGER;					\
977c478bd9Sstevel@tonic-gate	be,pt %icc, 6b;			/* wait while 10 */		\
987c478bd9Sstevel@tonic-gate	ldxa	[j_chng_pa]ASI_IO, scr;					\
997c478bd9Sstevel@tonic-gate	andn	scr, TOM_TRIGGER_MASK, scr;				\
1007c478bd9Sstevel@tonic-gate	stxa	scr, [j_chng_pa]ASI_IO;	/* deassert j_chng */
1017c478bd9Sstevel@tonic-gate
1027c478bd9Sstevel@tonic-gate/*
1037c478bd9Sstevel@tonic-gate * Macro to set Jalapeno CPU speed
1047c478bd9Sstevel@tonic-gate *   speed - new speed constant
1057c478bd9Sstevel@tonic-gate *   scr1  - scratch register
1067c478bd9Sstevel@tonic-gate *   scr2  - scratch register
1077c478bd9Sstevel@tonic-gate */
1087c478bd9Sstevel@tonic-gate#define	SET_JP_SPEED(speed, scr1, scr2)					\
1097c478bd9Sstevel@tonic-gate	ldxa	[%g0]ASI_JBUS_CONFIG, scr1;				\
1107c478bd9Sstevel@tonic-gate	set	JBUS_CONFIG_ECLK_MASK, scr2;				\
1117c478bd9Sstevel@tonic-gate	andn	scr1, scr2, scr1;					\
1127c478bd9Sstevel@tonic-gate	set	speed, scr2;						\
1137c478bd9Sstevel@tonic-gate	or	scr1, scr2, scr1;					\
1147c478bd9Sstevel@tonic-gate	stxa	scr1, [%g0]ASI_JBUS_CONFIG;
1157c478bd9Sstevel@tonic-gate
1167c478bd9Sstevel@tonic-gate/*
1177c478bd9Sstevel@tonic-gate * macro to set Master Tomatillo speed
1187c478bd9Sstevel@tonic-gate *   speed - tomatillo speed constant
1197c478bd9Sstevel@tonic-gate *   tpa   - tomatillo estar control register PA
1207c478bd9Sstevel@tonic-gate *   scr  - scratch register
1217c478bd9Sstevel@tonic-gate */
1227c478bd9Sstevel@tonic-gate#define	SET_TOM_SPEED(speed, tpa, scr)					\
1237c478bd9Sstevel@tonic-gate	ldxa	[tpa]ASI_IO, scr;					\
1247c478bd9Sstevel@tonic-gate	andn	scr, TOM_ESTAR_ELCK_MASK, scr;				\
1257c478bd9Sstevel@tonic-gate	or	scr, speed, scr;					\
1267c478bd9Sstevel@tonic-gate	stxa	scr, [tpa]ASI_IO;
1277c478bd9Sstevel@tonic-gate
1287c478bd9Sstevel@tonic-gate/*
1297c478bd9Sstevel@tonic-gate * macro to check and set Slave Tomatillo speed
1307c478bd9Sstevel@tonic-gate *   speed - tomatillo speed constant
1317c478bd9Sstevel@tonic-gate *   scr1   - scratch register
1327c478bd9Sstevel@tonic-gate *   scr2   - scratch register
1337c478bd9Sstevel@tonic-gate */
1347c478bd9Sstevel@tonic-gate
1357c478bd9Sstevel@tonic-gate#define	SET_SLAVE_T_SPEED(speed, scr1, scr2)				\
1367c478bd9Sstevel@tonic-gate	ldxa	[%g0]ASI_JBUS_CONFIG, scr2;				\
1377c478bd9Sstevel@tonic-gate	srlx	scr2, JBUS_SLAVE_T_PORT_BIT, scr2;			\
1387c478bd9Sstevel@tonic-gate	btst	1, scr2;						\
1397c478bd9Sstevel@tonic-gate	bz,pt	%icc, 4f;						\
1407c478bd9Sstevel@tonic-gate	nop;								\
1417c478bd9Sstevel@tonic-gate	SET_64BIT_PA(scr1, scr2, TOM_HIGH_PA, S_T_ESTAR_CTRL_PA);	\
1427c478bd9Sstevel@tonic-gate	SET_TOM_SPEED(speed, scr1, scr2);				\
1437c478bd9Sstevel@tonic-gate4:
1447c478bd9Sstevel@tonic-gate
1457c478bd9Sstevel@tonic-gate
1467c478bd9Sstevel@tonic-gate/*
1477c478bd9Sstevel@tonic-gate * macro to adjust ASI_MCU_CTL_REG1[26:25] fsm bits according to
1487c478bd9Sstevel@tonic-gate * new cpu speed: fsm[1:0]=11b for full speed, fsm[1:0]=0 for estar speed
1497c478bd9Sstevel@tonic-gate *    value - fsm bit value constant
1507c478bd9Sstevel@tonic-gate *    scr1  - scratch register
1517c478bd9Sstevel@tonic-gate *    scr2  - scratch register
1527c478bd9Sstevel@tonic-gate */
1537c478bd9Sstevel@tonic-gate#define	JP_ADJUST_FSM(value, scr1, scr2)				\
1547c478bd9Sstevel@tonic-gate	ldxa	[%g0]ASI_MCU_CTRL, scr1;				\
1557c478bd9Sstevel@tonic-gate	set	JP_MCU_FSM_MASK, scr2;					\
1567c478bd9Sstevel@tonic-gate	andn	scr1, scr2, scr1;					\
1577c478bd9Sstevel@tonic-gate	set	value, scr2;						\
1587c478bd9Sstevel@tonic-gate	or	scr1, scr2, scr1;					\
1597c478bd9Sstevel@tonic-gate	stxa	scr1, [%g0]ASI_MCU_CTRL;				\
1607c478bd9Sstevel@tonic-gate	membar	#Sync;
1617c478bd9Sstevel@tonic-gate
1627c478bd9Sstevel@tonic-gate/*
1637c478bd9Sstevel@tonic-gate * JP_FORCE_FULL_SPEED and its fellow macros are for Jalapeno
1647c478bd9Sstevel@tonic-gate * workstation to work around Errata 85. The front portion of
1657c478bd9Sstevel@tonic-gate * it packs JP speed(14..13) and Tomatillo speed(5..0) into one
1667c478bd9Sstevel@tonic-gate * register.
1677c478bd9Sstevel@tonic-gate *
1687c478bd9Sstevel@tonic-gate * Current code assumes that these two fields are non-overlapping.
1697c478bd9Sstevel@tonic-gate * If that assumption changes, then this code won't work. If so, we
1707c478bd9Sstevel@tonic-gate * force a compile time error by not defining the JP_FORCE_FULL_SPEED
1717c478bd9Sstevel@tonic-gate * and JP_RESTORE_SPEED macros below.
1727c478bd9Sstevel@tonic-gate */
1737c478bd9Sstevel@tonic-gate
1747c478bd9Sstevel@tonic-gate#if !(JBUS_CONFIG_ECLK_MASK & TOM_SPEED_MASK)
1757c478bd9Sstevel@tonic-gate
1767c478bd9Sstevel@tonic-gate/*
1777c478bd9Sstevel@tonic-gate * Macro to force Jalapeno/Tomatillo to full speed
1787c478bd9Sstevel@tonic-gate *   old_lvl - register used to save original cpu, tomatillo speed
1797c478bd9Sstevel@tonic-gate *   scr2 - scratch register
1807c478bd9Sstevel@tonic-gate *   scr3 - scratch register
1817c478bd9Sstevel@tonic-gate *   scr4 - scratch register
1827c478bd9Sstevel@tonic-gate */
1837c478bd9Sstevel@tonic-gate#define	JP_FORCE_FULL_SPEED(old_lvl, scr2, scr3, scr4)			\
1847c478bd9Sstevel@tonic-gate	ldxa	[%g0]ASI_JBUS_CONFIG, old_lvl;				\
1857c478bd9Sstevel@tonic-gate	set	JBUS_CONFIG_ECLK_MASK, scr4;				\
1867c478bd9Sstevel@tonic-gate	and	old_lvl, scr4, old_lvl;					\
1877c478bd9Sstevel@tonic-gate	SET_64BIT_PA(scr2, scr3, TOM_HIGH_PA, M_T_ESTAR_CTRL_PA);	\
1887c478bd9Sstevel@tonic-gate	ldxa	[scr2]ASI_IO, scr3;					\
1897c478bd9Sstevel@tonic-gate	set	TOM_ESTAR_ELCK_MASK, scr4;				\
1907c478bd9Sstevel@tonic-gate	and	scr3, scr4, scr3;					\
1917c478bd9Sstevel@tonic-gate	or	old_lvl, scr3, old_lvl;					\
1927c478bd9Sstevel@tonic-gate	/* original jp and tomatillo speed saved in old_lvl */		\
1937c478bd9Sstevel@tonic-gate									\
1947c478bd9Sstevel@tonic-gate	/* either intended or currently at full speed */		\
1957c478bd9Sstevel@tonic-gate	set	JBUS_CONFIG_ECLK_MASK, scr4;				\
1967c478bd9Sstevel@tonic-gate	andcc	old_lvl, scr4, %g0;					\
1977c478bd9Sstevel@tonic-gate	bz,pt	%icc, 8f;						\
1987c478bd9Sstevel@tonic-gate	nop;								\
1997c478bd9Sstevel@tonic-gate	/* go through 1/2 speed. */					\
2007c478bd9Sstevel@tonic-gate	SET_JP_SPEED(JBUS_CONFIG_ECLK_2, scr3, scr4);			\
2017c478bd9Sstevel@tonic-gate	SET_TOM_SPEED(TOM_HALF_SPEED, scr2, scr3);			\
2027c478bd9Sstevel@tonic-gate	SET_SLAVE_T_SPEED(TOM_HALF_SPEED, scr3, scr4);			\
2037c478bd9Sstevel@tonic-gate	JP_ADJUST_FSM(0, scr3, scr4);					\
2047c478bd9Sstevel@tonic-gate	set	jp_estar_tl0_data, scr3;				\
2057c478bd9Sstevel@tonic-gate	ldx	[scr3], %g0;						\
2067c478bd9Sstevel@tonic-gate	membar	#Sync;		/* or busy wait 1us */			\
2077c478bd9Sstevel@tonic-gate	JP_ESTAR_TRIGGER(scr3, scr4);					\
2087c478bd9Sstevel@tonic-gate8:									\
2097c478bd9Sstevel@tonic-gate	/* bring to 1:1 speed */					\
2107c478bd9Sstevel@tonic-gate	SET_JP_SPEED(JBUS_CONFIG_ECLK_1, scr3, scr4);			\
2117c478bd9Sstevel@tonic-gate	SET_TOM_SPEED(TOM_FULL_SPEED, scr2, scr3);			\
2127c478bd9Sstevel@tonic-gate	SET_SLAVE_T_SPEED(TOM_FULL_SPEED, scr3, scr4);			\
2137c478bd9Sstevel@tonic-gate	JP_ADJUST_FSM(JP_MCU_FSM_MASK, scr3, scr4);			\
2147c478bd9Sstevel@tonic-gate	JP_ESTAR_TRIGGER(scr3, scr4)
2157c478bd9Sstevel@tonic-gate
2167c478bd9Sstevel@tonic-gate
2177c478bd9Sstevel@tonic-gate/*
2187c478bd9Sstevel@tonic-gate * Macro to restore Jalapeno/Tomatillo to original speed
2197c478bd9Sstevel@tonic-gate *     old_lvl - register contains saved original cpu, tomatillo speed
2207c478bd9Sstevel@tonic-gate *     scr2 - scratch register
2217c478bd9Sstevel@tonic-gate *     scr3 - scratch register
2227c478bd9Sstevel@tonic-gate *     scr4 - scratch register
2237c478bd9Sstevel@tonic-gate *
2247c478bd9Sstevel@tonic-gate * If trap had occured in the middle of ppm cpu speed transtion, then
2257c478bd9Sstevel@tonic-gate * old_lvl[31:10] contains the intended new speed written into jbus_config.
2267c478bd9Sstevel@tonic-gate * if old_lvl[9:0] is inconsistent with old_lvl[31:10], then the trap surely
2277c478bd9Sstevel@tonic-gate * interrupted the ppm cpu speed transition, otherwise nothing for sure.
2287c478bd9Sstevel@tonic-gate * We'll restore the intended/then-current speed, that should cause no
2297c478bd9Sstevel@tonic-gate * trouble to subsequent ppm cpu speed change code.
2307c478bd9Sstevel@tonic-gate */
2317c478bd9Sstevel@tonic-gate#define	JP_RESTORE_SPEED(old_lvl, scr2, scr3, scr4)			\
2327c478bd9Sstevel@tonic-gate	srlx	old_lvl, JBUS_CONFIG_ECLK_SHIFT, scr2;			\
2337c478bd9Sstevel@tonic-gate	and	scr2, 3, scr2;						\
2347c478bd9Sstevel@tonic-gate	add	scr2, 1, scr2;						\
2357c478bd9Sstevel@tonic-gate	cmp	scr2, 3;						\
2367c478bd9Sstevel@tonic-gate	bne,pt	%icc, 7f;						\
2377c478bd9Sstevel@tonic-gate	  nop;								\
2387c478bd9Sstevel@tonic-gate	set	TOM_SLOW_SPEED, scr2;					\
2397c478bd9Sstevel@tonic-gate	/* scr2 contains tom speed according to intended jp speed */	\
2407c478bd9Sstevel@tonic-gate7:									\
2417c478bd9Sstevel@tonic-gate	andn	old_lvl, TOM_ESTAR_ELCK_MASK, old_lvl;			\
2427c478bd9Sstevel@tonic-gate	or	scr2, old_lvl, old_lvl;					\
2437c478bd9Sstevel@tonic-gate	/* updated old_lvl to contain intended jp and tom speed */	\
2447c478bd9Sstevel@tonic-gate	andcc	old_lvl, TOM_FULL_SPEED, %g0;				\
2457c478bd9Sstevel@tonic-gate	bnz,pt	%icc, 9f;	/* intended full, already at full */	\
2467c478bd9Sstevel@tonic-gate	nop;								\
2477c478bd9Sstevel@tonic-gate									\
2487c478bd9Sstevel@tonic-gate	/* go to half speed */						\
2497c478bd9Sstevel@tonic-gate	SET_JP_SPEED(JBUS_CONFIG_ECLK_2, scr3, scr4);			\
2507c478bd9Sstevel@tonic-gate	SET_64BIT_PA(scr2, scr3, TOM_HIGH_PA, M_T_ESTAR_CTRL_PA);	\
2517c478bd9Sstevel@tonic-gate	SET_TOM_SPEED(TOM_HALF_SPEED, scr2, scr3);			\
2527c478bd9Sstevel@tonic-gate	SET_SLAVE_T_SPEED(TOM_HALF_SPEED, scr3, scr4);			\
2537c478bd9Sstevel@tonic-gate	JP_ADJUST_FSM(0, scr3, scr4);					\
2547c478bd9Sstevel@tonic-gate	set	jp_estar_tl0_data, scr3;				\
2557c478bd9Sstevel@tonic-gate	ldx	[scr3], %g0;						\
2567c478bd9Sstevel@tonic-gate	membar	#Sync;							\
2577c478bd9Sstevel@tonic-gate	JP_ESTAR_TRIGGER(scr3, scr4);					\
2587c478bd9Sstevel@tonic-gate	andcc	old_lvl, TOM_SLOW_SPEED, %g0;				\
2597c478bd9Sstevel@tonic-gate	bz,pt	%icc, 9f;	/* intended 1:2, already at 1:2 */	\
2607c478bd9Sstevel@tonic-gate	  nop;								\
2617c478bd9Sstevel@tonic-gate									\
2627c478bd9Sstevel@tonic-gate	/* go to 1:32 speed */						\
2637c478bd9Sstevel@tonic-gate	SET_JP_SPEED(JBUS_CONFIG_ECLK_32, scr3, scr4);			\
2647c478bd9Sstevel@tonic-gate	SET_TOM_SPEED(TOM_SLOW_SPEED, scr2, scr3);			\
2657c478bd9Sstevel@tonic-gate	SET_SLAVE_T_SPEED(TOM_SLOW_SPEED, scr3, scr4);			\
2667c478bd9Sstevel@tonic-gate	JP_ESTAR_TRIGGER(scr3, scr4);					\
2677c478bd9Sstevel@tonic-gate9:
2687c478bd9Sstevel@tonic-gate
2697c478bd9Sstevel@tonic-gate#endif /* !(JBUS_CONFIG_ECLK_MASK & TOM_SPEED_MASK) */
2707c478bd9Sstevel@tonic-gate#endif	/* JALAPENO && JALAPENO_ERRATA_85 */
2717c478bd9Sstevel@tonic-gate
2727c478bd9Sstevel@tonic-gate/*
2737c478bd9Sstevel@tonic-gate * Jalapeno version to reflush an Ecache line by index.
2747c478bd9Sstevel@tonic-gate * Will flush all 4 ways (with only one scratch register).
2757c478bd9Sstevel@tonic-gate * Note that the code will be faster if we use 2 scratch registers.
2767c478bd9Sstevel@tonic-gate */
2777c478bd9Sstevel@tonic-gate#define	ECACHE_REFLUSH_LINE(ec_set_size, index, scr1)			\
2787c478bd9Sstevel@tonic-gate	JP_EC_DIAG_ACCESS_MEMBAR;					\
2797c478bd9Sstevel@tonic-gate	ldxa	[index]ASI_EC_DIAG, %g0;				\
2807c478bd9Sstevel@tonic-gate	JP_EC_DIAG_ACCESS_MEMBAR;					\
2817c478bd9Sstevel@tonic-gate	mov	1, scr1;						\
2827c478bd9Sstevel@tonic-gate	sllx	scr1, JP_ECFLUSH_EC_WAY_SHIFT, scr1;			\
2837c478bd9Sstevel@tonic-gate	add	scr1, index, scr1;					\
2847c478bd9Sstevel@tonic-gate	JP_EC_DIAG_ACCESS_MEMBAR;					\
2857c478bd9Sstevel@tonic-gate	ldxa	[scr1]ASI_EC_DIAG, %g0;					\
2867c478bd9Sstevel@tonic-gate	JP_EC_DIAG_ACCESS_MEMBAR;					\
2877c478bd9Sstevel@tonic-gate	mov	2, scr1;						\
2887c478bd9Sstevel@tonic-gate	sllx	scr1, JP_ECFLUSH_EC_WAY_SHIFT, scr1;			\
2897c478bd9Sstevel@tonic-gate	add	scr1, index, scr1;					\
2907c478bd9Sstevel@tonic-gate	JP_EC_DIAG_ACCESS_MEMBAR;					\
2917c478bd9Sstevel@tonic-gate	ldxa	[scr1]ASI_EC_DIAG, %g0;					\
2927c478bd9Sstevel@tonic-gate	JP_EC_DIAG_ACCESS_MEMBAR;					\
2937c478bd9Sstevel@tonic-gate	mov	3, scr1;						\
2947c478bd9Sstevel@tonic-gate	sllx	scr1, JP_ECFLUSH_EC_WAY_SHIFT, scr1;			\
2957c478bd9Sstevel@tonic-gate	add	scr1, index, scr1;					\
2967c478bd9Sstevel@tonic-gate	JP_EC_DIAG_ACCESS_MEMBAR;					\
2977c478bd9Sstevel@tonic-gate	ldxa	[scr1]ASI_EC_DIAG, %g0;					\
2987c478bd9Sstevel@tonic-gate	JP_EC_DIAG_ACCESS_MEMBAR
2997c478bd9Sstevel@tonic-gate
3007c478bd9Sstevel@tonic-gate/*
3017c478bd9Sstevel@tonic-gate * Jalapeno version of ecache_flush_line.  Uses Jalapeno Ecache Displacement
3027c478bd9Sstevel@tonic-gate * Flush feature to flush all 4 sets/ways.
3037c478bd9Sstevel@tonic-gate */
3047c478bd9Sstevel@tonic-gate#define	ECACHE_FLUSH_LINE(physaddr, ec_set_size, scr1, scr2)		\
3057c478bd9Sstevel@tonic-gate	CPU_INDEX(scr1, scr2);						\
3067c478bd9Sstevel@tonic-gate	sllx	scr1, JP_ECFLUSH_PORTID_SHIFT, scr1;			\
3077c478bd9Sstevel@tonic-gate	set	JP_ECACHE_IDX_DISP_FLUSH, scr2;				\
3087c478bd9Sstevel@tonic-gate	or	scr2, scr1, scr2;					\
3097c478bd9Sstevel@tonic-gate	sub	ec_set_size, 1, scr1;					\
3107c478bd9Sstevel@tonic-gate	and	physaddr, scr1, scr1;					\
3117c478bd9Sstevel@tonic-gate	or	scr2, scr1, scr1;					\
3127c478bd9Sstevel@tonic-gate	ECACHE_REFLUSH_LINE(ec_set_size, scr1, scr2)
3137c478bd9Sstevel@tonic-gate
3147c478bd9Sstevel@tonic-gate/*
3157c478bd9Sstevel@tonic-gate * Macro for getting ecache size from cpunodes structure
3167c478bd9Sstevel@tonic-gate *  scr1:    Scratch, ecache size returned in this
3177c478bd9Sstevel@tonic-gate *  scr2:    Scratch
3187c478bd9Sstevel@tonic-gate */
3197c478bd9Sstevel@tonic-gate#define	GET_ECACHE_SIZE(scr1, scr2)					\
3207c478bd9Sstevel@tonic-gate	CPU_INDEX(scr1, scr2);						\
3217c478bd9Sstevel@tonic-gate	mulx	scr1, CPU_NODE_SIZE, scr1;				\
3227c478bd9Sstevel@tonic-gate	set	cpunodes + ECACHE_SIZE, scr2;				\
3237c478bd9Sstevel@tonic-gate	ld	[scr1 + scr2], scr1
3247c478bd9Sstevel@tonic-gate
3257c478bd9Sstevel@tonic-gate/* END CSTYLED */
3267c478bd9Sstevel@tonic-gate
3277c478bd9Sstevel@tonic-gate#endif	/* !lint */
3287c478bd9Sstevel@tonic-gate
3297c478bd9Sstevel@tonic-gate#if defined(lint)
3307c478bd9Sstevel@tonic-gate
3317c478bd9Sstevel@tonic-gate/* ARGSUSED */
3327c478bd9Sstevel@tonic-gatevoid
3337c478bd9Sstevel@tonic-gateshipit(int upaid, int bn)
3347c478bd9Sstevel@tonic-gate{ return; }
3357c478bd9Sstevel@tonic-gate
3367c478bd9Sstevel@tonic-gate#else	/* lint */
3377c478bd9Sstevel@tonic-gate
3387c478bd9Sstevel@tonic-gate/*
3397c478bd9Sstevel@tonic-gate * Ship mondo to aid using implicit busy/nack pair (bn ignored)
3407c478bd9Sstevel@tonic-gate */
3417c478bd9Sstevel@tonic-gate	ENTRY_NP(shipit)
3427c478bd9Sstevel@tonic-gate	sll	%o0, IDCR_PID_SHIFT, %g1	! IDCR<18:14> = agent id
3437c478bd9Sstevel@tonic-gate	or	%g1, IDCR_OFFSET, %g1		! IDCR<13:0> = 0x70
3447c478bd9Sstevel@tonic-gate	stxa	%g0, [%g1]ASI_INTR_DISPATCH	! interrupt vector dispatch
3457c478bd9Sstevel@tonic-gate	membar	#Sync
3467c478bd9Sstevel@tonic-gate	retl
3477c478bd9Sstevel@tonic-gate	nop
3487c478bd9Sstevel@tonic-gate	SET_SIZE(shipit)
3497c478bd9Sstevel@tonic-gate
3507c478bd9Sstevel@tonic-gate#endif	/* lint */
3517c478bd9Sstevel@tonic-gate
3527c478bd9Sstevel@tonic-gate
3537c478bd9Sstevel@tonic-gate/*
3547c478bd9Sstevel@tonic-gate * flush_ecache:
3557c478bd9Sstevel@tonic-gate *	%o0 - 64 bit physical address
3567c478bd9Sstevel@tonic-gate *	%o1 - ecache size
3577c478bd9Sstevel@tonic-gate *	%o2 - ecache linesize
3587c478bd9Sstevel@tonic-gate */
3597c478bd9Sstevel@tonic-gate#if defined(lint)
3607c478bd9Sstevel@tonic-gate
3617c478bd9Sstevel@tonic-gate/*ARGSUSED*/
3627c478bd9Sstevel@tonic-gatevoid
3637c478bd9Sstevel@tonic-gateflush_ecache(uint64_t physaddr, size_t ecache_size, size_t ecache_linesize)
3647c478bd9Sstevel@tonic-gate{}
3657c478bd9Sstevel@tonic-gate
3667c478bd9Sstevel@tonic-gate#else /* !lint */
3677c478bd9Sstevel@tonic-gate
3687c478bd9Sstevel@tonic-gate	ENTRY(flush_ecache)
3697c478bd9Sstevel@tonic-gate#if defined(JALAPENO) && defined(JALAPENO_ERRATA_85)
3707c478bd9Sstevel@tonic-gate	CHK_JP_ERRATA85_ENABLED(%g1, flush_ecache_1);
3717c478bd9Sstevel@tonic-gate	JP_FORCE_FULL_SPEED(%o3, %g1, %g2, %g3);	/* %o3: saved speed */
3727c478bd9Sstevel@tonic-gateflush_ecache_1:
3737c478bd9Sstevel@tonic-gate#endif	/* JALAPENO && JALAPENO_ERRATA_85 */
3747c478bd9Sstevel@tonic-gate
3757c478bd9Sstevel@tonic-gate	/*
3767c478bd9Sstevel@tonic-gate	 * Flush the entire Ecache using displacement flush.
3777c478bd9Sstevel@tonic-gate	 */
3787c478bd9Sstevel@tonic-gate	ECACHE_FLUSHALL(%o1, %o2, %o0, %o4)
3797c478bd9Sstevel@tonic-gate
3807c478bd9Sstevel@tonic-gate#if defined(JALAPENO) && defined(JALAPENO_ERRATA_85)
3817c478bd9Sstevel@tonic-gate	CHK_JP_ERRATA85_ENABLED(%g1, flush_ecache_2);
3827c478bd9Sstevel@tonic-gate	JP_RESTORE_SPEED(%o3, %g1, %g2, %g3);		/* %o3: saved speed */
3837c478bd9Sstevel@tonic-gateflush_ecache_2:
3847c478bd9Sstevel@tonic-gate#endif	/* JALAPENO && JALAPENO_ERRATA_85 */
3857c478bd9Sstevel@tonic-gate
3867c478bd9Sstevel@tonic-gate	retl
3877c478bd9Sstevel@tonic-gate	nop
3887c478bd9Sstevel@tonic-gate	SET_SIZE(flush_ecache)
3897c478bd9Sstevel@tonic-gate
3907c478bd9Sstevel@tonic-gate#endif /* lint */
3917c478bd9Sstevel@tonic-gate
3927c478bd9Sstevel@tonic-gate
3937c478bd9Sstevel@tonic-gate#if defined(lint)
3947c478bd9Sstevel@tonic-gate
3957c478bd9Sstevel@tonic-gatevoid
3967c478bd9Sstevel@tonic-gatefast_ecc_err(void)
3977c478bd9Sstevel@tonic-gate{}
3987c478bd9Sstevel@tonic-gate
3997c478bd9Sstevel@tonic-gate#else	/* lint */
4007c478bd9Sstevel@tonic-gate
4017c478bd9Sstevel@tonic-gate	.section ".text"
4027c478bd9Sstevel@tonic-gate	.align	64
4037c478bd9Sstevel@tonic-gate	ENTRY_NP(fast_ecc_err)
4047c478bd9Sstevel@tonic-gate
4057c478bd9Sstevel@tonic-gate	/*
4067c478bd9Sstevel@tonic-gate	 * Turn off CEEN and NCEEN.
4077c478bd9Sstevel@tonic-gate	 */
4087c478bd9Sstevel@tonic-gate	ldxa	[%g0]ASI_ESTATE_ERR, %g3
4097c478bd9Sstevel@tonic-gate	andn	%g3, EN_REG_NCEEN + EN_REG_CEEN, %g4
4107c478bd9Sstevel@tonic-gate	stxa	%g4, [%g0]ASI_ESTATE_ERR
4117c478bd9Sstevel@tonic-gate	membar	#Sync			! membar sync required
4127c478bd9Sstevel@tonic-gate
4137c478bd9Sstevel@tonic-gate	/*
4147c478bd9Sstevel@tonic-gate	 * Do the CPU log out capture.
4157c478bd9Sstevel@tonic-gate	 *   %g3 = "failed?" return value.
4167c478bd9Sstevel@tonic-gate	 *   %g2 = Input = AFAR. Output the clo_flags info which is passed
4177c478bd9Sstevel@tonic-gate	 *         into this macro via %g4. Output only valid if cpu_private
4187c478bd9Sstevel@tonic-gate	 *         struct has not been initialized.
4197c478bd9Sstevel@tonic-gate	 *   CHPR_FECCTL0_LOGOUT = cpu logout structure offset input
4207c478bd9Sstevel@tonic-gate	 *   %g4 = Trap information stored in the cpu logout flags field
4217c478bd9Sstevel@tonic-gate	 *   %g5 = scr1
4227c478bd9Sstevel@tonic-gate	 *   %g6 = scr2
4237c478bd9Sstevel@tonic-gate	 *   %g3 = scr3
4247c478bd9Sstevel@tonic-gate	 *   %g4 = scr4
4257c478bd9Sstevel@tonic-gate	 */
4267c478bd9Sstevel@tonic-gate	and	%g3, EN_REG_CEEN, %g4		! store the CEEN value, TL=0
4277c478bd9Sstevel@tonic-gate	set	CHPR_FECCTL0_LOGOUT, %g6
4287c478bd9Sstevel@tonic-gate	DO_CPU_LOGOUT(%g3, %g2, %g6, %g4, %g5, %g6, %g3, %g4)
4297c478bd9Sstevel@tonic-gate
4307c478bd9Sstevel@tonic-gate	/*
4317c478bd9Sstevel@tonic-gate	 * Flush the Ecache to get the error out of the Ecache.  If the UCC
4327c478bd9Sstevel@tonic-gate	 * or UCU is on a dirty line, then the following flush will turn
4337c478bd9Sstevel@tonic-gate	 * that into a WDC or WDU, respectively.
4347c478bd9Sstevel@tonic-gate	 */
4357c478bd9Sstevel@tonic-gate	CPU_INDEX(%g4, %g5)
4367c478bd9Sstevel@tonic-gate	mulx	%g4, CPU_NODE_SIZE, %g4
4377c478bd9Sstevel@tonic-gate	set	cpunodes, %g5
4387c478bd9Sstevel@tonic-gate	add	%g4, %g5, %g4
4397c478bd9Sstevel@tonic-gate	ld	[%g4 + ECACHE_LINESIZE], %g5
4407c478bd9Sstevel@tonic-gate	ld	[%g4 + ECACHE_SIZE], %g4
4417c478bd9Sstevel@tonic-gate#if defined(JALAPENO) && defined(JALAPENO_ERRATA_85)
4427c478bd9Sstevel@tonic-gate	CHK_JP_ERRATA85_ENABLED(%g6, fast_ecc_err_1);
4437c478bd9Sstevel@tonic-gate        set     jp_estar_tl0_data, %g6
4447c478bd9Sstevel@tonic-gate        stx     %g2, [%g6 + 0]
4457c478bd9Sstevel@tonic-gate        stx     %g3, [%g6 + 8]
4467c478bd9Sstevel@tonic-gate	JP_FORCE_FULL_SPEED(%g2, %g3, %g6, %g7)		/* %g2: saved speed */
4477c478bd9Sstevel@tonic-gatefast_ecc_err_1:
4487c478bd9Sstevel@tonic-gate#endif	/* JALAPENO && JALAPENO_ERRATA_85 */
4497c478bd9Sstevel@tonic-gate	ECACHE_FLUSHALL(%g4, %g5, %g6, %g7)
4507c478bd9Sstevel@tonic-gate#if defined(JALAPENO) && defined(JALAPENO_ERRATA_85)
4517c478bd9Sstevel@tonic-gate	CHK_JP_ERRATA85_ENABLED(%g6, fast_ecc_err_2);
4527c478bd9Sstevel@tonic-gate	JP_RESTORE_SPEED(%g2, %g3, %g6, %g7)		/* %g2: saved speed */
4537c478bd9Sstevel@tonic-gate        set     jp_estar_tl0_data, %g6
4547c478bd9Sstevel@tonic-gate        ldx     [%g6 + 0], %g2
4557c478bd9Sstevel@tonic-gate        ldx     [%g6 + 8], %g3
4567c478bd9Sstevel@tonic-gatefast_ecc_err_2:
4577c478bd9Sstevel@tonic-gate#endif	/* JALAPENO && JALAPENO_ERRATA_85 */
4587c478bd9Sstevel@tonic-gate
4597c478bd9Sstevel@tonic-gate	/*
4607c478bd9Sstevel@tonic-gate	 * Flush the Dcache.  Since bad data could have been installed in
4617c478bd9Sstevel@tonic-gate	 * the Dcache we must flush it before re-enabling it.
4627c478bd9Sstevel@tonic-gate	 */
4637c478bd9Sstevel@tonic-gate	ASM_LD(%g5, dcache_size)
4647c478bd9Sstevel@tonic-gate	ASM_LD(%g6, dcache_linesize)
4657c478bd9Sstevel@tonic-gate	CH_DCACHE_FLUSHALL(%g5, %g6, %g7)
4667c478bd9Sstevel@tonic-gate
4677c478bd9Sstevel@tonic-gate	/*
4687c478bd9Sstevel@tonic-gate	 * Flush the Icache.  Since we turned off the Icache to capture the
4697c478bd9Sstevel@tonic-gate	 * Icache line it is now stale or corrupted and we must flush it
4707c478bd9Sstevel@tonic-gate	 * before re-enabling it.
4717c478bd9Sstevel@tonic-gate	 */
4727c478bd9Sstevel@tonic-gate	GET_CPU_PRIVATE_PTR(%g0, %g5, %g7, fast_ecc_err_4);
4737c478bd9Sstevel@tonic-gate	ld	[%g5 + CHPR_ICACHE_LINESIZE], %g6
4747c478bd9Sstevel@tonic-gate	ba,pt	%icc, 5f
4757c478bd9Sstevel@tonic-gate	  ld	[%g5 + CHPR_ICACHE_SIZE], %g5
4767c478bd9Sstevel@tonic-gatefast_ecc_err_4:
4777c478bd9Sstevel@tonic-gate	ASM_LD(%g5, icache_size)
4787c478bd9Sstevel@tonic-gate	ASM_LD(%g6, icache_linesize)
4797c478bd9Sstevel@tonic-gate5:
4807c478bd9Sstevel@tonic-gate	CH_ICACHE_FLUSHALL(%g5, %g6, %g7, %g4)
4817c478bd9Sstevel@tonic-gate
4827c478bd9Sstevel@tonic-gate	/*
4837c478bd9Sstevel@tonic-gate	 * Restore the Dcache and Icache to the previous state.
4847c478bd9Sstevel@tonic-gate	 */
4857c478bd9Sstevel@tonic-gate	stxa	%g1, [%g0]ASI_DCU
4867c478bd9Sstevel@tonic-gate	flush	%g0	/* flush required after changing the IC bit */
4877c478bd9Sstevel@tonic-gate
4887c478bd9Sstevel@tonic-gate	/*
4897c478bd9Sstevel@tonic-gate	 * Make sure our CPU logout operation was successful.
4907c478bd9Sstevel@tonic-gate	 */
4917c478bd9Sstevel@tonic-gate	cmp	%g3, %g0
4927c478bd9Sstevel@tonic-gate	be	8f
4937c478bd9Sstevel@tonic-gate	  nop
4947c478bd9Sstevel@tonic-gate
4957c478bd9Sstevel@tonic-gate	/*
4967c478bd9Sstevel@tonic-gate	 * If the logout structure had been busy, how many times have
4977c478bd9Sstevel@tonic-gate	 * we tried to use it and failed (nesting count)? If we have
4987c478bd9Sstevel@tonic-gate	 * already recursed a substantial number of times, then we can
4997c478bd9Sstevel@tonic-gate	 * assume things are not going to get better by themselves and
5007c478bd9Sstevel@tonic-gate	 * so it would be best to panic.
5017c478bd9Sstevel@tonic-gate	 */
5027c478bd9Sstevel@tonic-gate	cmp	%g3, CLO_NESTING_MAX
5037c478bd9Sstevel@tonic-gate	blt	7f
5047c478bd9Sstevel@tonic-gate	  nop
5057c478bd9Sstevel@tonic-gate
5067c478bd9Sstevel@tonic-gate        call ptl1_panic
5077c478bd9Sstevel@tonic-gate          mov   PTL1_BAD_ECC, %g1
5087c478bd9Sstevel@tonic-gate
5097c478bd9Sstevel@tonic-gate7:
5107c478bd9Sstevel@tonic-gate	/*
5117c478bd9Sstevel@tonic-gate	 * Otherwise, if the logout structure was busy but we have not
5127c478bd9Sstevel@tonic-gate	 * nested more times than our maximum value, then we simply
5137c478bd9Sstevel@tonic-gate	 * issue a retry. Our TL=0 trap handler code will check and
5147c478bd9Sstevel@tonic-gate	 * clear the AFSR after it is done logging what is currently
5157c478bd9Sstevel@tonic-gate	 * in the logout struct and handle this event at that time.
5167c478bd9Sstevel@tonic-gate	 */
5177c478bd9Sstevel@tonic-gate	retry
5187c478bd9Sstevel@tonic-gate8:
5197c478bd9Sstevel@tonic-gate	/*
5207c478bd9Sstevel@tonic-gate	 * Call cpu_fast_ecc_error via systrap at PIL 14 unless we're
5217c478bd9Sstevel@tonic-gate	 * already at PIL 15.
5227c478bd9Sstevel@tonic-gate	 */
5237c478bd9Sstevel@tonic-gate	set	cpu_fast_ecc_error, %g1
5247c478bd9Sstevel@tonic-gate	rdpr	%pil, %g4
5257c478bd9Sstevel@tonic-gate	cmp	%g4, PIL_14
5267c478bd9Sstevel@tonic-gate	ba	sys_trap
5277c478bd9Sstevel@tonic-gate	  movl	%icc, PIL_14, %g4
5287c478bd9Sstevel@tonic-gate
5297c478bd9Sstevel@tonic-gate	SET_SIZE(fast_ecc_err)
5307c478bd9Sstevel@tonic-gate
5317c478bd9Sstevel@tonic-gate#endif	/* lint */
5327c478bd9Sstevel@tonic-gate
5337c478bd9Sstevel@tonic-gate
5347c478bd9Sstevel@tonic-gate/*
5357c478bd9Sstevel@tonic-gate * Fast ECC error at TL>0 handler
5367c478bd9Sstevel@tonic-gate * We get here via trap 70 at TL>0->Software trap 0 at TL>0.  We enter
5377c478bd9Sstevel@tonic-gate * this routine with %g1 and %g2 already saved in %tpc, %tnpc and %tstate.
5387c478bd9Sstevel@tonic-gate * For a complete description of the Fast ECC at TL>0 handling see the
5397c478bd9Sstevel@tonic-gate * comment block "Cheetah/Cheetah+ Fast ECC at TL>0 trap strategy" in
5407c478bd9Sstevel@tonic-gate * us3_common_asm.s
5417c478bd9Sstevel@tonic-gate */
5427c478bd9Sstevel@tonic-gate#if defined(lint)
5437c478bd9Sstevel@tonic-gate
5447c478bd9Sstevel@tonic-gatevoid
5457c478bd9Sstevel@tonic-gatefast_ecc_tl1_err(void)
5467c478bd9Sstevel@tonic-gate{}
5477c478bd9Sstevel@tonic-gate
5487c478bd9Sstevel@tonic-gate#else	/* lint */
5497c478bd9Sstevel@tonic-gate
5507c478bd9Sstevel@tonic-gate	.section ".text"
5517c478bd9Sstevel@tonic-gate	.align	64
5527c478bd9Sstevel@tonic-gate	ENTRY_NP(fast_ecc_tl1_err)
5537c478bd9Sstevel@tonic-gate
5547c478bd9Sstevel@tonic-gate	/*
5557c478bd9Sstevel@tonic-gate	 * This macro turns off the D$/I$ if they are on and saves their
5567c478bd9Sstevel@tonic-gate	 * original state in ch_err_tl1_tmp, saves all the %g registers in the
5577c478bd9Sstevel@tonic-gate	 * ch_err_tl1_data structure, updates the ch_err_tl1_flags and saves
5587c478bd9Sstevel@tonic-gate	 * the %tpc in ch_err_tl1_tpc.  At the end of this macro, %g1 will
5597c478bd9Sstevel@tonic-gate	 * point to the ch_err_tl1_data structure and the original D$/I$ state
5607c478bd9Sstevel@tonic-gate	 * will be saved in ch_err_tl1_tmp.  All %g registers except for %g1
5617c478bd9Sstevel@tonic-gate	 * will be available.
5627c478bd9Sstevel@tonic-gate	 */
5637c478bd9Sstevel@tonic-gate	CH_ERR_TL1_FECC_ENTER;
5647c478bd9Sstevel@tonic-gate
5657c478bd9Sstevel@tonic-gate	/*
5667c478bd9Sstevel@tonic-gate	 * Get the diagnostic logout data.  %g4 must be initialized to
5677c478bd9Sstevel@tonic-gate	 * current CEEN state, %g5 must point to logout structure in
5687c478bd9Sstevel@tonic-gate	 * ch_err_tl1_data_t.  %g3 will contain the nesting count upon
5697c478bd9Sstevel@tonic-gate	 * return.
5707c478bd9Sstevel@tonic-gate	 */
5717c478bd9Sstevel@tonic-gate	ldxa	[%g0]ASI_ESTATE_ERR, %g4
5727c478bd9Sstevel@tonic-gate	and	%g4, EN_REG_CEEN, %g4
5737c478bd9Sstevel@tonic-gate	add	%g1, CH_ERR_TL1_LOGOUT, %g5
5747c478bd9Sstevel@tonic-gate	DO_TL1_CPU_LOGOUT(%g3, %g2, %g4, %g5, %g6, %g3, %g4)
5757c478bd9Sstevel@tonic-gate
5767c478bd9Sstevel@tonic-gate	/*
5777c478bd9Sstevel@tonic-gate	 * If the logout nesting count is exceeded, we're probably
5787c478bd9Sstevel@tonic-gate	 * not making any progress, try to panic instead.
5797c478bd9Sstevel@tonic-gate	 */
5807c478bd9Sstevel@tonic-gate	cmp	%g3, CLO_NESTING_MAX
5817c478bd9Sstevel@tonic-gate	bge	fecc_tl1_err
5827c478bd9Sstevel@tonic-gate	  nop
5837c478bd9Sstevel@tonic-gate
5847c478bd9Sstevel@tonic-gate	/*
5857c478bd9Sstevel@tonic-gate	 * Save the current CEEN and NCEEN state in %g7 and turn them off
5867c478bd9Sstevel@tonic-gate	 * before flushing the Ecache.
5877c478bd9Sstevel@tonic-gate	 */
5887c478bd9Sstevel@tonic-gate	ldxa	[%g0]ASI_ESTATE_ERR, %g7
5897c478bd9Sstevel@tonic-gate	andn	%g7, EN_REG_CEEN | EN_REG_NCEEN, %g5
5907c478bd9Sstevel@tonic-gate	stxa	%g5, [%g0]ASI_ESTATE_ERR
5917c478bd9Sstevel@tonic-gate	membar	#Sync
5927c478bd9Sstevel@tonic-gate
5937c478bd9Sstevel@tonic-gate	/*
5947c478bd9Sstevel@tonic-gate	 * Flush the Ecache, using the largest possible cache size with the
5957c478bd9Sstevel@tonic-gate	 * smallest possible line size since we can't get the actual sizes
5967c478bd9Sstevel@tonic-gate	 * from the cpu_node due to DTLB misses.
5977c478bd9Sstevel@tonic-gate	 */
5987c478bd9Sstevel@tonic-gate	set	JP_ECACHE_MAX_SIZE, %g4
5997c478bd9Sstevel@tonic-gate#if defined(JALAPENO) && defined(JALAPENO_ERRATA_85)
6007c478bd9Sstevel@tonic-gate	CHK_JP_ERRATA85_ENABLED(%g6, fast_ecc_tl1_err_1);
6017c478bd9Sstevel@tonic-gate        set     jp_estar_tl1_data, %g6
6027c478bd9Sstevel@tonic-gate        stx     %g2, [%g6 + 0]
6037c478bd9Sstevel@tonic-gate        stx     %g3, [%g6 + 8]
6047c478bd9Sstevel@tonic-gate	JP_FORCE_FULL_SPEED(%g2, %g3, %g5, %g6)
6057c478bd9Sstevel@tonic-gatefast_ecc_tl1_err_1:
6067c478bd9Sstevel@tonic-gate#endif	/* JALAPENO && JALAPENO_ERRATA_85 */
6077c478bd9Sstevel@tonic-gate	ECACHE_FLUSHALL(%g4, JP_ECACHE_MAX_LSIZE, %g5, %g6)
6087c478bd9Sstevel@tonic-gate#if defined(JALAPENO) && defined(JALAPENO_ERRATA_85)
6097c478bd9Sstevel@tonic-gate	CHK_JP_ERRATA85_ENABLED(%g6, fast_ecc_tl1_err_2);
6107c478bd9Sstevel@tonic-gate	JP_RESTORE_SPEED(%g2, %g3, %g5, %g6)
6117c478bd9Sstevel@tonic-gate        set     jp_estar_tl1_data, %g6
6127c478bd9Sstevel@tonic-gate        ldx     [%g6 + 0], %g2
6137c478bd9Sstevel@tonic-gate        ldx     [%g6 + 8], %g3
6147c478bd9Sstevel@tonic-gatefast_ecc_tl1_err_2:
6157c478bd9Sstevel@tonic-gate#endif	/* JALAPENO && JALAPENO_ERRATA_85 */
6167c478bd9Sstevel@tonic-gate
6177c478bd9Sstevel@tonic-gate	/*
6187c478bd9Sstevel@tonic-gate	 * Restore CEEN and NCEEN to the previous state.
6197c478bd9Sstevel@tonic-gate	 */
6207c478bd9Sstevel@tonic-gate	stxa	%g7, [%g0]ASI_ESTATE_ERR
6217c478bd9Sstevel@tonic-gate	membar	#Sync
6227c478bd9Sstevel@tonic-gate
6237c478bd9Sstevel@tonic-gate	/*
6247c478bd9Sstevel@tonic-gate	 * If we turned off the D$, then flush it and turn it back on.
6257c478bd9Sstevel@tonic-gate	 */
6267c478bd9Sstevel@tonic-gate	ldxa	[%g1 + CH_ERR_TL1_TMP]%asi, %g3
6277c478bd9Sstevel@tonic-gate	andcc	%g3, CH_ERR_TSTATE_DC_ON, %g0
6287c478bd9Sstevel@tonic-gate	bz	%xcc, 3f
6297c478bd9Sstevel@tonic-gate	  nop
6307c478bd9Sstevel@tonic-gate
6317c478bd9Sstevel@tonic-gate	/*
6327c478bd9Sstevel@tonic-gate	 * Flush the D$.
6337c478bd9Sstevel@tonic-gate	 */
6347c478bd9Sstevel@tonic-gate	ASM_LD(%g4, dcache_size)
6357c478bd9Sstevel@tonic-gate	ASM_LD(%g5, dcache_linesize)
6367c478bd9Sstevel@tonic-gate	CH_DCACHE_FLUSHALL(%g4, %g5, %g6)
6377c478bd9Sstevel@tonic-gate
6387c478bd9Sstevel@tonic-gate	/*
6397c478bd9Sstevel@tonic-gate	 * Turn the D$ back on.
6407c478bd9Sstevel@tonic-gate	 */
6417c478bd9Sstevel@tonic-gate	ldxa	[%g0]ASI_DCU, %g3
6427c478bd9Sstevel@tonic-gate	or	%g3, DCU_DC, %g3
6437c478bd9Sstevel@tonic-gate	stxa	%g3, [%g0]ASI_DCU
6447c478bd9Sstevel@tonic-gate	membar	#Sync
6457c478bd9Sstevel@tonic-gate3:
6467c478bd9Sstevel@tonic-gate	/*
6477c478bd9Sstevel@tonic-gate	 * If we turned off the I$, then flush it and turn it back on.
6487c478bd9Sstevel@tonic-gate	 */
6497c478bd9Sstevel@tonic-gate	ldxa	[%g1 + CH_ERR_TL1_TMP]%asi, %g3
6507c478bd9Sstevel@tonic-gate	andcc	%g3, CH_ERR_TSTATE_IC_ON, %g0
6517c478bd9Sstevel@tonic-gate	bz	%xcc, 4f
6527c478bd9Sstevel@tonic-gate	  nop
6537c478bd9Sstevel@tonic-gate
6547c478bd9Sstevel@tonic-gate	/*
6557c478bd9Sstevel@tonic-gate	 * Flush the I$.
6567c478bd9Sstevel@tonic-gate	 */
6577c478bd9Sstevel@tonic-gate	ASM_LD(%g4, icache_size)
6587c478bd9Sstevel@tonic-gate	ASM_LD(%g5, icache_linesize)
6597c478bd9Sstevel@tonic-gate	CH_ICACHE_FLUSHALL(%g4, %g5, %g6, %g3)
6607c478bd9Sstevel@tonic-gate
6617c478bd9Sstevel@tonic-gate	/*
6627c478bd9Sstevel@tonic-gate	 * Turn the I$ back on.  Changing DCU_IC requires flush.
6637c478bd9Sstevel@tonic-gate	 */
6647c478bd9Sstevel@tonic-gate	ldxa	[%g0]ASI_DCU, %g3
6657c478bd9Sstevel@tonic-gate	or	%g3, DCU_IC, %g3
6667c478bd9Sstevel@tonic-gate	stxa	%g3, [%g0]ASI_DCU
6677c478bd9Sstevel@tonic-gate	flush	%g0
6687c478bd9Sstevel@tonic-gate4:
6697c478bd9Sstevel@tonic-gate
6707c478bd9Sstevel@tonic-gate#ifdef TRAPTRACE
6717c478bd9Sstevel@tonic-gate	/*
6727c478bd9Sstevel@tonic-gate	 * Get current trap trace entry physical pointer.
6737c478bd9Sstevel@tonic-gate	 */
6747c478bd9Sstevel@tonic-gate	CPU_INDEX(%g6, %g5)
6757c478bd9Sstevel@tonic-gate	sll	%g6, TRAPTR_SIZE_SHIFT, %g6
6767c478bd9Sstevel@tonic-gate	set	trap_trace_ctl, %g5
6777c478bd9Sstevel@tonic-gate	add	%g6, %g5, %g6
6787c478bd9Sstevel@tonic-gate	ld	[%g6 + TRAPTR_LIMIT], %g5
6797c478bd9Sstevel@tonic-gate	tst	%g5
6807c478bd9Sstevel@tonic-gate	be	%icc, skip_traptrace
6817c478bd9Sstevel@tonic-gate	  nop
6827c478bd9Sstevel@tonic-gate	ldx	[%g6 + TRAPTR_PBASE], %g5
6837c478bd9Sstevel@tonic-gate	ld	[%g6 + TRAPTR_OFFSET], %g4
6847c478bd9Sstevel@tonic-gate	add	%g5, %g4, %g5
6857c478bd9Sstevel@tonic-gate
6867c478bd9Sstevel@tonic-gate	/*
6877c478bd9Sstevel@tonic-gate	 * Create trap trace entry.
6887c478bd9Sstevel@tonic-gate	 */
6897c478bd9Sstevel@tonic-gate	rd	%asi, %g7
6907c478bd9Sstevel@tonic-gate	wr	%g0, TRAPTR_ASI, %asi
6917c478bd9Sstevel@tonic-gate	rd	STICK, %g4
6927c478bd9Sstevel@tonic-gate	stxa	%g4, [%g5 + TRAP_ENT_TICK]%asi
6937c478bd9Sstevel@tonic-gate	rdpr	%tl, %g4
6947c478bd9Sstevel@tonic-gate	stha	%g4, [%g5 + TRAP_ENT_TL]%asi
6957c478bd9Sstevel@tonic-gate	rdpr	%tt, %g4
6967c478bd9Sstevel@tonic-gate	stha	%g4, [%g5 + TRAP_ENT_TT]%asi
6977c478bd9Sstevel@tonic-gate	rdpr	%tpc, %g4
6987c478bd9Sstevel@tonic-gate	stna	%g4, [%g5 + TRAP_ENT_TPC]%asi
6997c478bd9Sstevel@tonic-gate	rdpr	%tstate, %g4
7007c478bd9Sstevel@tonic-gate	stxa	%g4, [%g5 + TRAP_ENT_TSTATE]%asi
7017c478bd9Sstevel@tonic-gate	stna	%sp, [%g5 + TRAP_ENT_SP]%asi
7027c478bd9Sstevel@tonic-gate	stna	%g0, [%g5 + TRAP_ENT_TR]%asi
7037c478bd9Sstevel@tonic-gate	wr	%g0, %g7, %asi
7047c478bd9Sstevel@tonic-gate	ldxa	[%g1 + CH_ERR_TL1_SDW_AFAR]%asi, %g3
7057c478bd9Sstevel@tonic-gate	ldxa	[%g1 + CH_ERR_TL1_SDW_AFSR]%asi, %g4
7067c478bd9Sstevel@tonic-gate	wr	%g0, TRAPTR_ASI, %asi
7077c478bd9Sstevel@tonic-gate	stna	%g3, [%g5 + TRAP_ENT_F1]%asi
7087c478bd9Sstevel@tonic-gate	stna	%g4, [%g5 + TRAP_ENT_F2]%asi
7097c478bd9Sstevel@tonic-gate	wr	%g0, %g7, %asi
7107c478bd9Sstevel@tonic-gate	ldxa	[%g1 + CH_ERR_TL1_AFAR]%asi, %g3
7117c478bd9Sstevel@tonic-gate	ldxa	[%g1 + CH_ERR_TL1_AFSR]%asi, %g4
7127c478bd9Sstevel@tonic-gate	wr	%g0, TRAPTR_ASI, %asi
7137c478bd9Sstevel@tonic-gate	stna	%g3, [%g5 + TRAP_ENT_F3]%asi
7147c478bd9Sstevel@tonic-gate	stna	%g4, [%g5 + TRAP_ENT_F4]%asi
7157c478bd9Sstevel@tonic-gate	wr	%g0, %g7, %asi
7167c478bd9Sstevel@tonic-gate
7177c478bd9Sstevel@tonic-gate	/*
7187c478bd9Sstevel@tonic-gate	 * Advance trap trace pointer.
7197c478bd9Sstevel@tonic-gate	 */
7207c478bd9Sstevel@tonic-gate	ld	[%g6 + TRAPTR_OFFSET], %g5
7217c478bd9Sstevel@tonic-gate	ld	[%g6 + TRAPTR_LIMIT], %g4
7227c478bd9Sstevel@tonic-gate	st	%g5, [%g6 + TRAPTR_LAST_OFFSET]
7237c478bd9Sstevel@tonic-gate	add	%g5, TRAP_ENT_SIZE, %g5
7247c478bd9Sstevel@tonic-gate	sub	%g4, TRAP_ENT_SIZE, %g4
7257c478bd9Sstevel@tonic-gate	cmp	%g5, %g4
7267c478bd9Sstevel@tonic-gate	movge	%icc, 0, %g5
7277c478bd9Sstevel@tonic-gate	st	%g5, [%g6 + TRAPTR_OFFSET]
7287c478bd9Sstevel@tonic-gateskip_traptrace:
7297c478bd9Sstevel@tonic-gate#endif	/* TRAPTRACE */
7307c478bd9Sstevel@tonic-gate
7317c478bd9Sstevel@tonic-gate	/*
7327c478bd9Sstevel@tonic-gate	 * If nesting count is not zero, skip all the AFSR/AFAR
7337c478bd9Sstevel@tonic-gate	 * handling and just do the necessary cache-flushing.
7347c478bd9Sstevel@tonic-gate	 */
7357c478bd9Sstevel@tonic-gate	ldxa	[%g1 + CH_ERR_TL1_NEST_CNT]%asi, %g2
7367c478bd9Sstevel@tonic-gate	brnz	%g2, 6f
7377c478bd9Sstevel@tonic-gate	  nop
7387c478bd9Sstevel@tonic-gate
7397c478bd9Sstevel@tonic-gate	/*
7407c478bd9Sstevel@tonic-gate	 * If a UCU followed by a WDU has occurred go ahead and panic
7417c478bd9Sstevel@tonic-gate	 * since a UE will occur (on the retry) before the UCU and WDU
7427c478bd9Sstevel@tonic-gate	 * messages are enqueued.
7437c478bd9Sstevel@tonic-gate	 */
7447c478bd9Sstevel@tonic-gate	ldxa	[%g1 + CH_ERR_TL1_AFSR]%asi, %g3
7457c478bd9Sstevel@tonic-gate	set	1, %g4
7467c478bd9Sstevel@tonic-gate	sllx	%g4, C_AFSR_UCU_SHIFT, %g4
7477c478bd9Sstevel@tonic-gate	btst	%g4, %g3		! UCU in original AFSR?
7487c478bd9Sstevel@tonic-gate	bz	%xcc, 6f
7497c478bd9Sstevel@tonic-gate	  nop
7507c478bd9Sstevel@tonic-gate	ldxa	[%g0]ASI_AFSR, %g4	! current AFSR
7517c478bd9Sstevel@tonic-gate	or	%g3, %g4, %g3		! %g3 = original + current AFSR
7527c478bd9Sstevel@tonic-gate	set	1, %g4
7537c478bd9Sstevel@tonic-gate	sllx	%g4, C_AFSR_WDU_SHIFT, %g4
7547c478bd9Sstevel@tonic-gate	btst	%g4, %g3		! WDU in original or current AFSR?
7557c478bd9Sstevel@tonic-gate	bnz	%xcc, fecc_tl1_err
7567c478bd9Sstevel@tonic-gate	  nop
7577c478bd9Sstevel@tonic-gate
7587c478bd9Sstevel@tonic-gate6:
7597c478bd9Sstevel@tonic-gate	/*
7607c478bd9Sstevel@tonic-gate	 * We fall into this macro if we've successfully logged the error in
7617c478bd9Sstevel@tonic-gate	 * the ch_err_tl1_data structure and want the PIL15 softint to pick
7627c478bd9Sstevel@tonic-gate	 * it up and log it.  %g1 must point to the ch_err_tl1_data structure.
7637c478bd9Sstevel@tonic-gate	 * Restores the %g registers and issues retry.
7647c478bd9Sstevel@tonic-gate	 */
7657c478bd9Sstevel@tonic-gate	CH_ERR_TL1_EXIT;
7667c478bd9Sstevel@tonic-gate	/*
7677c478bd9Sstevel@tonic-gate	 * Establish panic exit label.
7687c478bd9Sstevel@tonic-gate	 */
7697c478bd9Sstevel@tonic-gate	CH_ERR_TL1_PANIC_EXIT(fecc_tl1_err);
7707c478bd9Sstevel@tonic-gate
7717c478bd9Sstevel@tonic-gate	SET_SIZE(fast_ecc_tl1_err)
7727c478bd9Sstevel@tonic-gate
7737c478bd9Sstevel@tonic-gate#endif	/* lint */
7747c478bd9Sstevel@tonic-gate
7757c478bd9Sstevel@tonic-gate
7767c478bd9Sstevel@tonic-gate#if defined(lint)
7777c478bd9Sstevel@tonic-gate
7787c478bd9Sstevel@tonic-gateuint64_t
7797c478bd9Sstevel@tonic-gateget_jbus_config(void)
7807c478bd9Sstevel@tonic-gate{ return (0); }
7817c478bd9Sstevel@tonic-gate
7827c478bd9Sstevel@tonic-gate/* ARGSUSED */
7837c478bd9Sstevel@tonic-gatevoid
7847c478bd9Sstevel@tonic-gateset_jbus_config(uint64_t jbus_config)
7857c478bd9Sstevel@tonic-gate{}
7867c478bd9Sstevel@tonic-gate
7877c478bd9Sstevel@tonic-gate/* ARGSUSED */
7887c478bd9Sstevel@tonic-gatevoid
7897c478bd9Sstevel@tonic-gateset_mcu_ctl_reg1(uint64_t mcu_ctl)
7907c478bd9Sstevel@tonic-gate{}
7917c478bd9Sstevel@tonic-gate
7927c478bd9Sstevel@tonic-gateuint64_t
7937c478bd9Sstevel@tonic-gateget_mcu_ctl_reg1(void)
7947c478bd9Sstevel@tonic-gate{ return (0); }
7957c478bd9Sstevel@tonic-gate
7967c478bd9Sstevel@tonic-gate#else	/* lint */
7977c478bd9Sstevel@tonic-gate
7987c478bd9Sstevel@tonic-gate	ENTRY(get_jbus_config)
7997c478bd9Sstevel@tonic-gate	ldxa	[%g0]ASI_JBUS_CONFIG, %o0
8007c478bd9Sstevel@tonic-gate	retl
8017c478bd9Sstevel@tonic-gate	nop
8027c478bd9Sstevel@tonic-gate	SET_SIZE(get_jbus_config)
8037c478bd9Sstevel@tonic-gate
8047c478bd9Sstevel@tonic-gate	ENTRY(set_jbus_config)
8057c478bd9Sstevel@tonic-gate	stxa	%o0, [%g0]ASI_JBUS_CONFIG
8067c478bd9Sstevel@tonic-gate	membar	#Sync
8077c478bd9Sstevel@tonic-gate	retl
8087c478bd9Sstevel@tonic-gate	nop
8097c478bd9Sstevel@tonic-gate	SET_SIZE(set_jbus_config)
8107c478bd9Sstevel@tonic-gate
8117c478bd9Sstevel@tonic-gate
8127c478bd9Sstevel@tonic-gate	ENTRY(get_mcu_ctl_reg1)
8137c478bd9Sstevel@tonic-gate	ldxa	[%g0]ASI_MCU_CTRL, %o0	! MCU control reg1 is at offset 0
8147c478bd9Sstevel@tonic-gate	retl
8157c478bd9Sstevel@tonic-gate	nop
8167c478bd9Sstevel@tonic-gate	SET_SIZE(get_mcu_ctl_reg1)
8177c478bd9Sstevel@tonic-gate
8187c478bd9Sstevel@tonic-gate
8197c478bd9Sstevel@tonic-gate	ENTRY(set_mcu_ctl_reg1)
8207c478bd9Sstevel@tonic-gate	stxa	%o0, [%g0]ASI_MCU_CTRL	! MCU control reg1 is at offset 0
8217c478bd9Sstevel@tonic-gate	membar	#Sync
8227c478bd9Sstevel@tonic-gate	retl
8237c478bd9Sstevel@tonic-gate	nop
8247c478bd9Sstevel@tonic-gate	SET_SIZE(set_mcu_ctl_reg1)
8257c478bd9Sstevel@tonic-gate
8267c478bd9Sstevel@tonic-gate#endif	/* lint */
8277c478bd9Sstevel@tonic-gate
8287c478bd9Sstevel@tonic-gate
8297c478bd9Sstevel@tonic-gate#if defined(lint)
8307c478bd9Sstevel@tonic-gate/*
8317c478bd9Sstevel@tonic-gate * scrubphys - Pass in the aligned physical memory address
8327c478bd9Sstevel@tonic-gate * that you want to scrub, along with the ecache set size.
8337c478bd9Sstevel@tonic-gate *
8347c478bd9Sstevel@tonic-gate *	1) Displacement flush the E$ line corresponding to %addr.
8357c478bd9Sstevel@tonic-gate *	   The first ldxa guarantees that the %addr is no longer in
8367c478bd9Sstevel@tonic-gate *	   M, O, or E (goes to I or S (if instruction fetch also happens).
8377c478bd9Sstevel@tonic-gate *	2) "Write" the data using a CAS %addr,%g0,%g0.
8387c478bd9Sstevel@tonic-gate *	   The casxa guarantees a transition from I to M or S to M.
8397c478bd9Sstevel@tonic-gate *	3) Displacement flush the E$ line corresponding to %addr.
8407c478bd9Sstevel@tonic-gate *	   The second ldxa pushes the M line out of the ecache, into the
8417c478bd9Sstevel@tonic-gate *	   writeback buffers, on the way to memory.
8427c478bd9Sstevel@tonic-gate *	4) The "membar #Sync" pushes the cache line out of the writeback
8437c478bd9Sstevel@tonic-gate *	   buffers onto the bus, on the way to dram finally.
8447c478bd9Sstevel@tonic-gate *
8457c478bd9Sstevel@tonic-gate * This is a modified version of the algorithm suggested by Gary Lauterbach.
8467c478bd9Sstevel@tonic-gate * In theory the CAS %addr,%g0,%g0 is supposed to mark the addr's cache line
8477c478bd9Sstevel@tonic-gate * as modified, but then we found out that for spitfire, if it misses in the
8487c478bd9Sstevel@tonic-gate * E$ it will probably install as an M, but if it hits in the E$, then it
8497c478bd9Sstevel@tonic-gate * will stay E, if the store doesn't happen. So the first displacement flush
8507c478bd9Sstevel@tonic-gate * should ensure that the CAS will miss in the E$.  Arrgh.
8517c478bd9Sstevel@tonic-gate */
8527c478bd9Sstevel@tonic-gate/* ARGSUSED */
8537c478bd9Sstevel@tonic-gatevoid
8547c478bd9Sstevel@tonic-gatescrubphys(uint64_t paddr, int ecache_set_size)
8557c478bd9Sstevel@tonic-gate{}
8567c478bd9Sstevel@tonic-gate
8577c478bd9Sstevel@tonic-gate#else	/* lint */
8587c478bd9Sstevel@tonic-gate	ENTRY(scrubphys)
8597c478bd9Sstevel@tonic-gate	rdpr	%pstate, %o4
8607c478bd9Sstevel@tonic-gate	andn	%o4, PSTATE_IE | PSTATE_AM, %o5
8617c478bd9Sstevel@tonic-gate	wrpr	%o5, %g0, %pstate	! clear IE, AM bits
8627c478bd9Sstevel@tonic-gate
8637c478bd9Sstevel@tonic-gate#if defined(JALAPENO) && defined(JALAPENO_ERRATA_85)
8647c478bd9Sstevel@tonic-gate	CHK_JP_ERRATA85_ENABLED(%g1, scrubphys_1);
8657c478bd9Sstevel@tonic-gate	JP_FORCE_FULL_SPEED(%o5, %g1, %g2, %g3)		/* %o5: saved speed */
8667c478bd9Sstevel@tonic-gatescrubphys_1:
8677c478bd9Sstevel@tonic-gate#endif	/* JALAPENO && JALAPENO_ERRATA_85 */
8687c478bd9Sstevel@tonic-gate
8697c478bd9Sstevel@tonic-gate	ECACHE_FLUSH_LINE(%o0, %o1, %o2, %o3)
8707c478bd9Sstevel@tonic-gate	casxa	[%o0]ASI_MEM, %g0, %g0
8717c478bd9Sstevel@tonic-gate	ECACHE_REFLUSH_LINE(%o1, %o2, %o3)
8727c478bd9Sstevel@tonic-gate
8737c478bd9Sstevel@tonic-gate#if defined(JALAPENO) && defined(JALAPENO_ERRATA_85)
8747c478bd9Sstevel@tonic-gate	CHK_JP_ERRATA85_ENABLED(%g1, scrubphys_2);
8757c478bd9Sstevel@tonic-gate	JP_RESTORE_SPEED(%o5, %g1, %g2, %g3)		/* %o5: saved speed */
8767c478bd9Sstevel@tonic-gatescrubphys_2:
8777c478bd9Sstevel@tonic-gate#endif	/* JALAPENO && JALAPENO_ERRATA_85 */
8787c478bd9Sstevel@tonic-gate
8797c478bd9Sstevel@tonic-gate	wrpr	%g0, %o4, %pstate	! restore earlier pstate register value
8807c478bd9Sstevel@tonic-gate
8817c478bd9Sstevel@tonic-gate	retl
8827c478bd9Sstevel@tonic-gate	membar	#Sync			! move the data out of the load buffer
8837c478bd9Sstevel@tonic-gate	SET_SIZE(scrubphys)
8847c478bd9Sstevel@tonic-gate
8857c478bd9Sstevel@tonic-gate#endif	/* lint */
8867c478bd9Sstevel@tonic-gate
8877c478bd9Sstevel@tonic-gate
8887c478bd9Sstevel@tonic-gate#if defined(lint)
8897c478bd9Sstevel@tonic-gate/*
890*750ba224Sanbui * clearphys - Pass in the physical memory address of the checkblock
891*750ba224Sanbui * that you want to push out, cleared with a recognizable pattern,
892*750ba224Sanbui * from the ecache.
893*750ba224Sanbui *
894*750ba224Sanbui * To ensure that the ecc gets recalculated after the bad data is cleared,
895*750ba224Sanbui * we must write out enough data to fill the w$ line (64 bytes). So we read
896*750ba224Sanbui * in an entire ecache subblock's worth of data, and write it back out.
897*750ba224Sanbui * Then we overwrite the 16 bytes of bad data with the pattern.
8987c478bd9Sstevel@tonic-gate */
8997c478bd9Sstevel@tonic-gate/* ARGSUSED */
9007c478bd9Sstevel@tonic-gatevoid
9017c478bd9Sstevel@tonic-gateclearphys(uint64_t paddr, int ecache_set_size, int ecache_linesize)
9027c478bd9Sstevel@tonic-gate{
9037c478bd9Sstevel@tonic-gate}
9047c478bd9Sstevel@tonic-gate
9057c478bd9Sstevel@tonic-gate#else	/* lint */
9067c478bd9Sstevel@tonic-gate	ENTRY(clearphys)
9077c478bd9Sstevel@tonic-gate	/* turn off IE, AM bits */
9087c478bd9Sstevel@tonic-gate	rdpr	%pstate, %o4
9097c478bd9Sstevel@tonic-gate	andn	%o4, PSTATE_IE | PSTATE_AM, %o5
9107c478bd9Sstevel@tonic-gate	wrpr	%o5, %g0, %pstate
9117c478bd9Sstevel@tonic-gate
9127c478bd9Sstevel@tonic-gate	/* turn off NCEEN */
9137c478bd9Sstevel@tonic-gate	ldxa	[%g0]ASI_ESTATE_ERR, %o5
9147c478bd9Sstevel@tonic-gate	andn	%o5, EN_REG_NCEEN, %o3
9157c478bd9Sstevel@tonic-gate	stxa	%o3, [%g0]ASI_ESTATE_ERR
9167c478bd9Sstevel@tonic-gate	membar	#Sync
9177c478bd9Sstevel@tonic-gate
918*750ba224Sanbui	/* align address passed with 64 bytes subblock size */
919*750ba224Sanbui	mov	CH_ECACHE_SUBBLK_SIZE, %o2
920*750ba224Sanbui	andn	%o0, (CH_ECACHE_SUBBLK_SIZE - 1), %g1
921*750ba224Sanbui
922*750ba224Sanbui	/* move the good data into the W$ */
9237c478bd9Sstevel@tonic-gate1:
9247c478bd9Sstevel@tonic-gate	subcc	%o2, 8, %o2
925*750ba224Sanbui	ldxa	[%g1 + %o2]ASI_MEM, %g2
9267c478bd9Sstevel@tonic-gate	bge	1b
927*750ba224Sanbui	  stxa	%g2, [%g1 + %o2]ASI_MEM
928*750ba224Sanbui
929*750ba224Sanbui	/* now overwrite the bad data */
930*750ba224Sanbui	setx	0xbadecc00badecc01, %g1, %g2
931*750ba224Sanbui	stxa	%g2, [%o0]ASI_MEM
932*750ba224Sanbui	mov	8, %g1
933*750ba224Sanbui	stxa	%g2, [%o0 + %g1]ASI_MEM
9347c478bd9Sstevel@tonic-gate
9357c478bd9Sstevel@tonic-gate#if defined(JALAPENO) && defined(JALAPENO_ERRATA_85)
9367c478bd9Sstevel@tonic-gate	CHK_JP_ERRATA85_ENABLED(%g1, clearphys_1);
9377c478bd9Sstevel@tonic-gate	JP_FORCE_FULL_SPEED(%o5, %g1, %g2, %g3)		/* %o5: saved speed */
9387c478bd9Sstevel@tonic-gateclearphys_1:
9397c478bd9Sstevel@tonic-gate#endif	/* JALAPENO && JALAPENO_ERRATA_85 */
9407c478bd9Sstevel@tonic-gate
9417c478bd9Sstevel@tonic-gate	ECACHE_FLUSH_LINE(%o0, %o1, %o2, %o3)
9427c478bd9Sstevel@tonic-gate	casxa	[%o0]ASI_MEM, %g0, %g0
9437c478bd9Sstevel@tonic-gate	ECACHE_REFLUSH_LINE(%o1, %o2, %o3)
9447c478bd9Sstevel@tonic-gate
9457c478bd9Sstevel@tonic-gate#if defined(JALAPENO) && defined(JALAPENO_ERRATA_85)
9467c478bd9Sstevel@tonic-gate	CHK_JP_ERRATA85_ENABLED(%g1, clearphys_2);
9477c478bd9Sstevel@tonic-gate	JP_RESTORE_SPEED(%o5, %g1, %g2, %g3)		/* %o5: saved speed */
9487c478bd9Sstevel@tonic-gateclearphys_2:
9497c478bd9Sstevel@tonic-gate#endif	/* JALAPENO && JALAPENO_ERRATA_85 */
9507c478bd9Sstevel@tonic-gate
9517c478bd9Sstevel@tonic-gate	/* clear the AFSR */
9527c478bd9Sstevel@tonic-gate	ldxa	[%g0]ASI_AFSR, %o1
9537c478bd9Sstevel@tonic-gate	stxa	%o1, [%g0]ASI_AFSR
9547c478bd9Sstevel@tonic-gate	membar	#Sync
9557c478bd9Sstevel@tonic-gate
9567c478bd9Sstevel@tonic-gate	/* turn NCEEN back on */
9577c478bd9Sstevel@tonic-gate	stxa	%o5, [%g0]ASI_ESTATE_ERR
9587c478bd9Sstevel@tonic-gate	membar	#Sync
9597c478bd9Sstevel@tonic-gate
9607c478bd9Sstevel@tonic-gate	/* return and re-enable IE and AM */
9617c478bd9Sstevel@tonic-gate	retl
9627c478bd9Sstevel@tonic-gate	  wrpr	%g0, %o4, %pstate
9637c478bd9Sstevel@tonic-gate	SET_SIZE(clearphys)
9647c478bd9Sstevel@tonic-gate
9657c478bd9Sstevel@tonic-gate#endif	/* lint */
9667c478bd9Sstevel@tonic-gate
9677c478bd9Sstevel@tonic-gate
9687c478bd9Sstevel@tonic-gate#if defined(lint)
9697c478bd9Sstevel@tonic-gate/*
9707c478bd9Sstevel@tonic-gate * Jalapeno Ecache displacement flush the specified line from the E$
9717c478bd9Sstevel@tonic-gate *
9727c478bd9Sstevel@tonic-gate * Register usage:
9737c478bd9Sstevel@tonic-gate *	%o0 - 64 bit physical address for flushing
9747c478bd9Sstevel@tonic-gate *	%o1 - Ecache set size
9757c478bd9Sstevel@tonic-gate */
9767c478bd9Sstevel@tonic-gate/*ARGSUSED*/
9777c478bd9Sstevel@tonic-gatevoid
9787c478bd9Sstevel@tonic-gateecache_flush_line(uint64_t flushaddr, int ec_set_size)
9797c478bd9Sstevel@tonic-gate{
9807c478bd9Sstevel@tonic-gate}
9817c478bd9Sstevel@tonic-gate#else	/* lint */
9827c478bd9Sstevel@tonic-gate	ENTRY(ecache_flush_line)
9837c478bd9Sstevel@tonic-gate
9847c478bd9Sstevel@tonic-gate#if defined(JALAPENO) && defined(JALAPENO_ERRATA_85)
9857c478bd9Sstevel@tonic-gate	CHK_JP_ERRATA85_ENABLED(%g1, ecache_flush_line_1);
9867c478bd9Sstevel@tonic-gate	JP_FORCE_FULL_SPEED(%o5, %g1, %g2, %g3)		/* %o5: saved speed */
9877c478bd9Sstevel@tonic-gateecache_flush_line_1:
9887c478bd9Sstevel@tonic-gate#endif	/* JALAPENO && JALAPENO_ERRATA_85 */
9897c478bd9Sstevel@tonic-gate
9907c478bd9Sstevel@tonic-gate	ECACHE_FLUSH_LINE(%o0, %o1, %o2, %o3)
9917c478bd9Sstevel@tonic-gate
9927c478bd9Sstevel@tonic-gate#if defined(JALAPENO) && defined(JALAPENO_ERRATA_85)
9937c478bd9Sstevel@tonic-gate	CHK_JP_ERRATA85_ENABLED(%g1, ecache_flush_line_2);
9947c478bd9Sstevel@tonic-gate	JP_RESTORE_SPEED(%o5, %g1, %g2, %g3)		/* %o5: saved speed */
9957c478bd9Sstevel@tonic-gateecache_flush_line_2:
9967c478bd9Sstevel@tonic-gate#endif	/* JALAPENO && JALAPENO_ERRATA_85 */
9977c478bd9Sstevel@tonic-gate
9987c478bd9Sstevel@tonic-gate	retl
9997c478bd9Sstevel@tonic-gate	  nop
10007c478bd9Sstevel@tonic-gate	SET_SIZE(ecache_flush_line)
10017c478bd9Sstevel@tonic-gate#endif	/* lint */
10027c478bd9Sstevel@tonic-gate
10037c478bd9Sstevel@tonic-gate
10047c478bd9Sstevel@tonic-gate/*
10057c478bd9Sstevel@tonic-gate * Perform necessary cpu workaround to ensure jbus ordering.
10067c478bd9Sstevel@tonic-gate * Called only from Fire systems.
10077c478bd9Sstevel@tonic-gate * CPU's internal "invalidate FIFOs" are flushed.
10087c478bd9Sstevel@tonic-gate */
10097c478bd9Sstevel@tonic-gate
10107c478bd9Sstevel@tonic-gate#if defined(lint)
10117c478bd9Sstevel@tonic-gatevoid
10127c478bd9Sstevel@tonic-gatejbus_stst_order()
10137c478bd9Sstevel@tonic-gate{}
10147c478bd9Sstevel@tonic-gate#else	/* lint */
10157c478bd9Sstevel@tonic-gate
10167c478bd9Sstevel@tonic-gate#define	VIS_BLOCKSIZE	64
10177c478bd9Sstevel@tonic-gate
10187c478bd9Sstevel@tonic-gate	.seg    ".data"
10197c478bd9Sstevel@tonic-gate	.align  VIS_BLOCKSIZE
10207c478bd9Sstevel@tonic-gate	.type   sync_buf, #object
10217c478bd9Sstevel@tonic-gatesync_buf:
10227c478bd9Sstevel@tonic-gate	.skip   VIS_BLOCKSIZE
10237c478bd9Sstevel@tonic-gate	.size   sync_buf, VIS_BLOCKSIZE
10247c478bd9Sstevel@tonic-gate
10257c478bd9Sstevel@tonic-gate	ENTRY(jbus_stst_order)
10267c478bd9Sstevel@tonic-gate	set	sync_buf, %o1
10277c478bd9Sstevel@tonic-gate
10287c478bd9Sstevel@tonic-gate	rd	%fprs, %o2			! %o2 = saved fprs
10297c478bd9Sstevel@tonic-gate	or	%o2, FPRS_FEF, %o3
10307c478bd9Sstevel@tonic-gate	wr	%g0, %o3, %fprs			! make sure fp is enabled
10317c478bd9Sstevel@tonic-gate	stda    %d0, [%o1]ASI_BLK_COMMIT_P
10327c478bd9Sstevel@tonic-gate	wr	%o2, 0, %fprs			! restore fprs
10337c478bd9Sstevel@tonic-gate
10347c478bd9Sstevel@tonic-gate	retl
10357c478bd9Sstevel@tonic-gate	membar  #Sync
10367c478bd9Sstevel@tonic-gate	SET_SIZE(jbus_stst_order)
10377c478bd9Sstevel@tonic-gate
10387c478bd9Sstevel@tonic-gate#endif	/* lint */
10397c478bd9Sstevel@tonic-gate
10407c478bd9Sstevel@tonic-gate#if defined(lint)
10417c478bd9Sstevel@tonic-gate/*
10427c478bd9Sstevel@tonic-gate * This routine will not be called in Jalapeno systems.
10437c478bd9Sstevel@tonic-gate */
10447c478bd9Sstevel@tonic-gatevoid
10457c478bd9Sstevel@tonic-gateflush_ipb(void)
10467c478bd9Sstevel@tonic-gate{ return; }
10477c478bd9Sstevel@tonic-gate
10487c478bd9Sstevel@tonic-gate#else	/* lint */
10497c478bd9Sstevel@tonic-gate
10507c478bd9Sstevel@tonic-gate	ENTRY(flush_ipb)
10517c478bd9Sstevel@tonic-gate	retl
10527c478bd9Sstevel@tonic-gate	nop
10537c478bd9Sstevel@tonic-gate	SET_SIZE(flush_ipb)
10547c478bd9Sstevel@tonic-gate
10557c478bd9Sstevel@tonic-gate#endif	/* lint */
1056