xref: /titanic_41/usr/src/uts/sun4u/opl/ml/drmach_asm.s (revision 07d06da50d310a325b457d6330165aebab1e0064)
125cf1a30Sjl139090/*
225cf1a30Sjl139090 * CDDL HEADER START
325cf1a30Sjl139090 *
425cf1a30Sjl139090 * The contents of this file are subject to the terms of the
525cf1a30Sjl139090 * Common Development and Distribution License (the "License").
625cf1a30Sjl139090 * You may not use this file except in compliance with the License.
725cf1a30Sjl139090 *
825cf1a30Sjl139090 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
925cf1a30Sjl139090 * or http://www.opensolaris.org/os/licensing.
1025cf1a30Sjl139090 * See the License for the specific language governing permissions
1125cf1a30Sjl139090 * and limitations under the License.
1225cf1a30Sjl139090 *
1325cf1a30Sjl139090 * When distributing Covered Code, include this CDDL HEADER in each
1425cf1a30Sjl139090 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1525cf1a30Sjl139090 * If applicable, add the following below this CDDL HEADER, with the
1625cf1a30Sjl139090 * fields enclosed by brackets "[]" replaced with your own identifying
1725cf1a30Sjl139090 * information: Portions Copyright [yyyy] [name of copyright owner]
1825cf1a30Sjl139090 *
1925cf1a30Sjl139090 * CDDL HEADER END
2025cf1a30Sjl139090 */
21*07d06da5SSurya Prakki
2225cf1a30Sjl139090/*
23*07d06da5SSurya Prakki * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
2425cf1a30Sjl139090 * Use is subject to license terms.
2525cf1a30Sjl139090 */
2625cf1a30Sjl139090
2725cf1a30Sjl139090/*
2825cf1a30Sjl139090 * This file is through cpp before being used as
2925cf1a30Sjl139090 * an inline.  It contains support routines used
3025cf1a30Sjl139090 * only by DR for the copy-rename sequence.
3125cf1a30Sjl139090 */
3225cf1a30Sjl139090
3325cf1a30Sjl139090#if defined(lint)
3425cf1a30Sjl139090#include <sys/types.h>
3525cf1a30Sjl139090#else
3625cf1a30Sjl139090#include "assym.h"
3725cf1a30Sjl139090#include "drmach_offsets.h"
3825cf1a30Sjl139090#endif /* lint */
3925cf1a30Sjl139090
4025cf1a30Sjl139090#include <sys/asm_linkage.h>
4125cf1a30Sjl139090#include <sys/param.h>
4225cf1a30Sjl139090#include <sys/privregs.h>
4325cf1a30Sjl139090#include <sys/spitregs.h>
4425cf1a30Sjl139090#include <sys/mmu.h>
4525cf1a30Sjl139090#include <sys/machthread.h>
4625cf1a30Sjl139090#include <sys/pte.h>
4725cf1a30Sjl139090#include <sys/stack.h>
4825cf1a30Sjl139090#include <sys/vis.h>
4925cf1a30Sjl139090#include <sys/intreg.h>
5025cf1a30Sjl139090#include <sys/cheetahregs.h>
5125cf1a30Sjl139090#include <sys/drmach.h>
52b307f191Sbm42561#include <sys/sbd_ioctl.h>
5325cf1a30Sjl139090
5425cf1a30Sjl139090#if !defined(lint)
5525cf1a30Sjl139090
5625cf1a30Sjl139090/*
5725cf1a30Sjl139090 * turn off speculative mode to prevent unwanted memory access
5825cf1a30Sjl139090 * when we are in the FMEM loops
5925cf1a30Sjl139090 */
6025cf1a30Sjl139090
6125cf1a30Sjl139090#define	FJSV_SPECULATIVE_OFF(reg, tmp1, tmp2)				\
6225cf1a30Sjl139090	rdpr	%pstate, reg						;\
6325cf1a30Sjl139090	andn	reg, PSTATE_IE, tmp1					;\
6425cf1a30Sjl139090	wrpr	%g0, tmp1, %pstate					;\
6525cf1a30Sjl139090	ldxa	[%g0]ASI_MCNTL, tmp1					;\
6625cf1a30Sjl139090	set	1, tmp2							;\
6725cf1a30Sjl139090	sllx	tmp2, MCNTL_SPECULATIVE_SHIFT, tmp2						;\
6825cf1a30Sjl139090	or	tmp1, tmp2, tmp1					;\
6925cf1a30Sjl139090	stxa	tmp1, [%g0]ASI_MCNTL					;\
7025cf1a30Sjl139090	membar #Sync
7125cf1a30Sjl139090#endif
7225cf1a30Sjl139090
7325cf1a30Sjl139090
7425cf1a30Sjl139090#if defined(lint)
7525cf1a30Sjl139090/*ARGSUSED*/
7625cf1a30Sjl139090void
7725cf1a30Sjl139090drmach_fmem_loop_script(caddr_t critical, int size, caddr_t stat)
7825cf1a30Sjl139090{ return; }
7925cf1a30Sjl139090#else /* lint */
8025cf1a30Sjl139090	.align  8
8125cf1a30Sjl139090	ENTRY_NP(drmach_fmem_loop_script)
8225cf1a30Sjl139090	/* turn off speculative mode */
8325cf1a30Sjl139090	FJSV_SPECULATIVE_OFF(%o5, %o3, %o4);
8425cf1a30Sjl139090
8525cf1a30Sjl139090	/* read the critical region to get everything in the cache */
8625cf1a30Sjl139090	mov	%o0, %o3
8725cf1a30Sjl1390900:
8825cf1a30Sjl139090	ldx	[%o3], %o4
8925cf1a30Sjl139090	sub	%o1, 8, %o1
9025cf1a30Sjl139090	brnz	%o1, 0b
9125cf1a30Sjl139090	 add	%o3, 8, %o3
9225cf1a30Sjl139090
9325cf1a30Sjl139090	/* clear L2_CTRL_UGE_TRAP error bit */
9425cf1a30Sjl139090	mov	ASI_L2_CTRL_RW_ADDR, %o1
9525cf1a30Sjl139090	ldxa	[%o1]ASI_L2_CTRL, %o3
9625cf1a30Sjl139090	sethi	%hi(ASI_L2_CTRL_UGE_TRAP), %o4
9725cf1a30Sjl139090	btst	%o3, %o4
9825cf1a30Sjl139090	bz,pn	%xcc, 1f
9925cf1a30Sjl139090	 nop
10025cf1a30Sjl139090	stxa	%o4, [%o1]ASI_L2_CTRL
10125cf1a30Sjl139090
10225cf1a30Sjl139090	/* now tell the master CPU that we are ready */
10325cf1a30Sjl1390901:
10425cf1a30Sjl139090	set	FMEM_LOOP_FMEM_READY, %o3
10525cf1a30Sjl139090	stb	%o3, [%o2]
10625cf1a30Sjl139090	membar #Sync
10725cf1a30Sjl139090	ba	 5f
10825cf1a30Sjl139090	 nop
10925cf1a30Sjl139090
11025cf1a30Sjl139090	/*
11125cf1a30Sjl139090	 * note that we branch to 5f, which branches right back to 2 here.
11225cf1a30Sjl139090	 * The trick is that when that branch instruction has already been
11325cf1a30Sjl139090	 * patched to a branch to itself - an infinite loop.
11425cf1a30Sjl139090	 * The master thread will patch it back to "ba 2b" when it
11525cf1a30Sjl139090	 * completes.
11625cf1a30Sjl139090	 */
11725cf1a30Sjl139090
11825cf1a30Sjl139090	/* Once we are back, we first check if there has been any
11925cf1a30Sjl139090	 * L2_CTRL_UGE_TRAP errors, if so we have to fail the
12025cf1a30Sjl139090	 * operation.  This will cause a panic because the system
12125cf1a30Sjl139090	 * is already in inconsistent state.
12225cf1a30Sjl139090	 */
12325cf1a30Sjl1390902:
12425cf1a30Sjl139090	mov	ASI_L2_CTRL_RW_ADDR, %o3
12525cf1a30Sjl139090	ldxa	[%o3]ASI_L2_CTRL, %o3
12625cf1a30Sjl139090	sethi	%hi(ASI_L2_CTRL_UGE_TRAP), %o4
12725cf1a30Sjl139090	btst	%o3, %o4
12825cf1a30Sjl139090	bz,pn	%xcc, 3f
12925cf1a30Sjl139090	 mov	%g0, %o4
130b307f191Sbm42561	set	EOPL_FMEM_HW_ERROR, %o4
13125cf1a30Sjl139090
13225cf1a30Sjl139090	/* set error code and stat code */
13325cf1a30Sjl1390903:
13425cf1a30Sjl139090	set	FMEM_LOOP_DONE, %o3
13525cf1a30Sjl139090	stb	%o3, [%o2]
13625cf1a30Sjl139090
13725cf1a30Sjl139090	/* turn on speculative mode again */
13825cf1a30Sjl139090	ldxa	[%g0]ASI_MCNTL, %o0
13925cf1a30Sjl139090	set	1, %o1
14025cf1a30Sjl139090	sllx	%o1, MCNTL_SPECULATIVE_SHIFT, %o1
14125cf1a30Sjl139090	andn	%o0, %o1, %o0
14225cf1a30Sjl139090	ba	4f
14325cf1a30Sjl139090	 nop
14425cf1a30Sjl139090.align 32
14525cf1a30Sjl1390904:
14625cf1a30Sjl139090	stxa	%o0, [%g0]ASI_MCNTL
14725cf1a30Sjl139090	membar	#Sync
14825cf1a30Sjl139090	wrpr	%g0, %o5, %pstate
14925cf1a30Sjl139090	retl
15025cf1a30Sjl139090	 mov	%o4, %o0
15125cf1a30Sjl139090.align 8
15225cf1a30Sjl1390905:
15325cf1a30Sjl139090	ALTENTRY(drmach_fmem_loop_script_rtn)
15425cf1a30Sjl139090	/*
15525cf1a30Sjl139090	 * busy wait will affect sibling strands so
15625cf1a30Sjl139090	 * we put sleep instruction in the delay slot
15725cf1a30Sjl139090	 */
15825cf1a30Sjl139090	ba	2b
15925cf1a30Sjl139090.word	 0x81b01060
16025cf1a30Sjl139090	SET_SIZE(drmach_fmem_loop_script)
16125cf1a30Sjl139090#endif /* lint */
16225cf1a30Sjl139090
16325cf1a30Sjl139090#if defined(lint)
16425cf1a30Sjl139090/*ARGSUSED*/
16525cf1a30Sjl139090void
16625cf1a30Sjl139090drmach_flush_icache(void)
16725cf1a30Sjl139090{ return; }
16825cf1a30Sjl139090#else /* lint */
16925cf1a30Sjl139090	.align  8
17025cf1a30Sjl139090	ENTRY_NP(drmach_flush_icache)
17125cf1a30Sjl139090	stxa	%g0, [%g0]ASI_ALL_FLUSH_L1I
17225cf1a30Sjl139090	membar	#Sync
17325cf1a30Sjl139090	retl
17425cf1a30Sjl139090	 nop
17525cf1a30Sjl139090	SET_SIZE(drmach_flush_icache)
17625cf1a30Sjl139090#endif
17725cf1a30Sjl139090
17825cf1a30Sjl139090#if defined(lint)
17925cf1a30Sjl139090/*ARGSUSED*/
18025cf1a30Sjl139090int
18125cf1a30Sjl139090drmach_fmem_exec_script(caddr_t critical, int size)
18225cf1a30Sjl139090{ return (0); }
18325cf1a30Sjl139090#else /* lint */
18425cf1a30Sjl139090.align 32
18525cf1a30Sjl139090	ENTRY_NP(drmach_fmem_exec_script)
18625cf1a30Sjl139090	/* turn off speculative mode */
18725cf1a30Sjl139090	FJSV_SPECULATIVE_OFF(%o5, %o3, %o4);
18825cf1a30Sjl139090	/* save locals to save area */
18925cf1a30Sjl139090	add	%o0, SAVE_LOCAL, %o2
19025cf1a30Sjl139090	stx	%l0, [%o2+8*0]
19125cf1a30Sjl139090	stx	%l1, [%o2+8*1]
19225cf1a30Sjl139090	stx	%l2, [%o2+8*2]
19325cf1a30Sjl139090	stx	%l3, [%o2+8*3]
19425cf1a30Sjl139090	stx	%l4, [%o2+8*4]
19525cf1a30Sjl139090	stx	%l5, [%o2+8*5]
19625cf1a30Sjl139090	stx	%l6, [%o2+8*6]
19725cf1a30Sjl139090	stx	%l7, [%o2+8*7]
19825cf1a30Sjl139090	mov	%o5, %l6
19925cf1a30Sjl139090	/* l7 is set only when FMEM cmd is issued to SCF */
20025cf1a30Sjl139090	mov	%g0, %l7
20125cf1a30Sjl139090
20225cf1a30Sjl139090	/* read the critical region to put everything in the cache */
20325cf1a30Sjl139090	mov	%o0, %o2
20425cf1a30Sjl1390900:
20525cf1a30Sjl139090	ldx	[%o2], %o4
20625cf1a30Sjl139090	sub	%o1, 8, %o1
20725cf1a30Sjl139090	brnz	%o1, 0b
20825cf1a30Sjl139090	 add	%o2, 8, %o2
20925cf1a30Sjl139090	ba	4f
21025cf1a30Sjl139090	 nop
21125cf1a30Sjl139090
21225cf1a30Sjl139090	/* we branch to 4f but eventually we branch back here to finish up */
21325cf1a30Sjl1390901:
21425cf1a30Sjl139090	mov	%l6, %o5
21525cf1a30Sjl139090	/*
21625cf1a30Sjl139090	 * save some registers for debugging
21725cf1a30Sjl139090	 * l0 - SCF_REG_BASE
21825cf1a30Sjl139090	 * l1 - SCF_TD
21925cf1a30Sjl139090	 * l2 - SCF_TD + 8
22025cf1a30Sjl139090	 * l5 - DELAY
22125cf1a30Sjl139090	 */
22225cf1a30Sjl139090	add	%o0, SAVE_LOG, %o1
22325cf1a30Sjl139090	stx	%l0, [%o1+8*0]
22425cf1a30Sjl139090	stx	%l1, [%o1+8*1]
22525cf1a30Sjl139090	stx	%l2, [%o1+8*2]
22625cf1a30Sjl139090	stx	%l5, [%o1+8*3]
22725cf1a30Sjl139090
22825cf1a30Sjl139090	add	%o0, FMEM_ISSUED, %o1
22925cf1a30Sjl139090	st	%l7, [%o1]
23025cf1a30Sjl139090
23125cf1a30Sjl139090	/* Check for L2_CTRL_UGE_TRAP error */
23225cf1a30Sjl139090	mov	ASI_L2_CTRL_RW_ADDR, %l0
23325cf1a30Sjl139090	ldxa	[%l0]ASI_L2_CTRL, %l1
23425cf1a30Sjl139090	sethi	%hi(ASI_L2_CTRL_UGE_TRAP), %l2
23525cf1a30Sjl139090	btst	%l1, %l2
23625cf1a30Sjl139090	bz,pn	%xcc, 2f
23725cf1a30Sjl139090	 nop
238b307f191Sbm42561	set	EOPL_FMEM_HW_ERROR, %o4
23925cf1a30Sjl1390902:
24025cf1a30Sjl139090	/* restore all locals */
24125cf1a30Sjl139090	add	%o0, SAVE_LOCAL, %o1
24225cf1a30Sjl139090	ldx	[%o1+8*0], %l0
24325cf1a30Sjl139090	ldx	[%o1+8*1], %l1
24425cf1a30Sjl139090	ldx	[%o1+8*2], %l2
24525cf1a30Sjl139090	ldx	[%o1+8*3], %l3
24625cf1a30Sjl139090	ldx	[%o1+8*4], %l4
24725cf1a30Sjl139090	ldx	[%o1+8*5], %l5
24825cf1a30Sjl139090	ldx	[%o1+8*6], %l6
24925cf1a30Sjl139090	ldx	[%o1+8*7], %l7
25025cf1a30Sjl139090
25125cf1a30Sjl139090	/* turn on speculative mode */
25225cf1a30Sjl139090	ldxa	[%g0]ASI_MCNTL, %o1
25325cf1a30Sjl139090	set	1, %o2
25425cf1a30Sjl139090	sllx	%o2, MCNTL_SPECULATIVE_SHIFT, %o2
25525cf1a30Sjl139090	andn	%o1, %o2, %o1
25625cf1a30Sjl139090	ba	3f
25725cf1a30Sjl139090	 nop
25825cf1a30Sjl139090.align 32
25925cf1a30Sjl1390903:
26025cf1a30Sjl139090	stxa	%o1, [%g0]ASI_MCNTL
26125cf1a30Sjl139090	membar	#Sync
26225cf1a30Sjl139090	/* return error code here */
26325cf1a30Sjl139090	mov	%o4, %o0
26425cf1a30Sjl139090	retl
26525cf1a30Sjl139090	 wrpr	%g0, %o5, %pstate
26625cf1a30Sjl139090
26725cf1a30Sjl139090	/* clear L2_CTRL_UGE_TRAP error bit */
26825cf1a30Sjl1390904:
26925cf1a30Sjl139090	mov	ASI_L2_CTRL_RW_ADDR, %l0
27025cf1a30Sjl139090	ldxa	[%l0]ASI_L2_CTRL, %l1
27125cf1a30Sjl139090	sethi	%hi(ASI_L2_CTRL_UGE_TRAP), %l2
27225cf1a30Sjl139090	btst	%l1, %l2
27325cf1a30Sjl139090	bz,pn	%xcc, 5f
27425cf1a30Sjl139090	 nop
27525cf1a30Sjl139090	stxa	%l2, [%l0]ASI_L2_CTRL
27625cf1a30Sjl1390905:
27725cf1a30Sjl139090	/* set up the register locations and parameters */
27825cf1a30Sjl139090	ldx	[%o0 + SCF_REG_BASE], %l0
27925cf1a30Sjl139090	ldx	[%o0 + SCF_TD], %l1
28025cf1a30Sjl139090	ldx	[%o0 + SCF_TD+8], %l2
28125cf1a30Sjl139090	ldx	[%o0 + DELAY], %l5
28225cf1a30Sjl139090
2834fe85d41SJames Anderson	/* check if SCF is ONLINE */
2844fe85d41SJames Anderson	add	%l0, SCF_STATUS_EX, %o1
2854fe85d41SJames Anderson	lduwa	[%o1]ASI_IO, %o2
2864fe85d41SJames Anderson	sethi	%hi(SCF_STATUS_EX_ONLINE), %o3
2874fe85d41SJames Anderson	btst	%o2, %o3
2884fe85d41SJames Anderson	bne	%xcc, 6f
2894fe85d41SJames Anderson	 nop
2904fe85d41SJames Anderson	set	EOPL_FMEM_SCF_OFFLINE, %o4
2914fe85d41SJames Anderson	ba	1b
2924fe85d41SJames Anderson	 nop
2934fe85d41SJames Anderson
29425cf1a30Sjl139090	/* check if SCF is busy */
29525cf1a30Sjl139090	add	%l0, SCF_COMMAND, %o1
29625cf1a30Sjl139090	lduha	[%o1]ASI_IO, %o2
29725cf1a30Sjl139090	sethi	%hi(SCF_CMD_BUSY), %o3
29825cf1a30Sjl139090	btst	%o2, %o3
29925cf1a30Sjl139090	be	%xcc, 6f
30025cf1a30Sjl139090	 nop
301b307f191Sbm42561	set	EOPL_FMEM_SCF_BUSY, %o4
30225cf1a30Sjl139090	ba	1b
303b307f191Sbm42561	 nop
30425cf1a30Sjl139090
30525cf1a30Sjl139090	/* clear STATUS bit */
30625cf1a30Sjl1390906:
30725cf1a30Sjl139090	add	%l0, SCF_STATUS, %o1
30825cf1a30Sjl139090	lduha	[%o1]ASI_IO, %o2
30925cf1a30Sjl139090	sethi	%hi(SCF_STATUS_READY), %o3
31025cf1a30Sjl139090	btst	%o2, %o3
31125cf1a30Sjl139090	be	%xcc, 7f
31225cf1a30Sjl139090	 nop
31325cf1a30Sjl139090	stha	%o3, [%o1]ASI_IO
31425cf1a30Sjl139090
31525cf1a30Sjl139090	/* clear CMD_COMPLETE bit */
31625cf1a30Sjl1390907:
31725cf1a30Sjl139090	mov	SCF_STATUS_CMD_COMPLETE, %o3
31825cf1a30Sjl139090	btst	%o2, %o3
31925cf1a30Sjl139090	be,a	%xcc, 8f
32025cf1a30Sjl139090	 nop
32125cf1a30Sjl139090	stha	%o3, [%o1]ASI_IO
32225cf1a30Sjl1390908:
32325cf1a30Sjl139090	add	%l0, (SCF_TDATA+0xe), %o1
32425cf1a30Sjl139090	mov	%l2, %o4
32525cf1a30Sjl139090	mov	SCF_RETRY_CNT, %o5
32625cf1a30Sjl139090
32725cf1a30Sjl139090	sethi	%hi(0xffff), %l2
32825cf1a30Sjl139090	or	%l2, %lo(0xffff), %l2
32925cf1a30Sjl139090
33025cf1a30Sjl139090	and	%o4, %l2, %o3
33125cf1a30Sjl139090
33225cf1a30Sjl139090	/*
33325cf1a30Sjl139090	 * o1 points to SCFBASE.SCF_TDATA[0xe]
33425cf1a30Sjl139090	 * l0 points to SCFBASE
33525cf1a30Sjl139090	 * crticial->SCF_TD[0] = source board #
33625cf1a30Sjl139090	 * crticial->SCF_TD[1] = target board #
33725cf1a30Sjl139090	 * l1 = critical->SCF_TD[0 - 7]
33825cf1a30Sjl139090	 * l2 = 0xffff
33925cf1a30Sjl139090	 * o4 = critical->SCF_TD[8 - 15]
34025cf1a30Sjl139090	 * o3 = (*o4) & 0xffff
34125cf1a30Sjl139090
34225cf1a30Sjl139090	/*
34325cf1a30Sjl139090	 * Because there is no parity protection on the ebus
34425cf1a30Sjl139090	 * we read the data back after the write to verify
34525cf1a30Sjl139090	 * we write 2 bytes at a time.
34625cf1a30Sjl139090	 * If the data read is not the same as data written
347b307f191Sbm42561	 * we retry up to a limit of SCF_RETRY_CNT
34825cf1a30Sjl139090	 */
34925cf1a30Sjl1390909:
35025cf1a30Sjl139090	stha	%o3, [%o1]ASI_IO
35125cf1a30Sjl139090	lduha	[%o1]ASI_IO, %o2
35225cf1a30Sjl139090	sub	%o5, 1, %o5
353b307f191Sbm42561	brnz	%o5, 7f
354b307f191Sbm42561	 nop
355b307f191Sbm42561	set	EOPL_FMEM_RETRY_OUT, %o4
356b307f191Sbm42561	ba	1b
357b307f191Sbm42561	 nop
358b307f191Sbm425617:
35925cf1a30Sjl139090	cmp	%o2, %o3
36025cf1a30Sjl139090	bne,a	9b
36125cf1a30Sjl139090	 nop
36225cf1a30Sjl139090
36325cf1a30Sjl139090	sub	%o1, %l0, %o2
36425cf1a30Sjl139090	cmp	%o2, (SCF_TDATA+0x8)
36525cf1a30Sjl139090	bne	%xcc, 2f
36625cf1a30Sjl139090	 srlx	%o4, 16, %o4
36725cf1a30Sjl139090	mov	%l1, %o4
36825cf1a30Sjl139090
36925cf1a30Sjl139090	/* if we have reach TDATA+8, we switch to l1 */
37025cf1a30Sjl139090	/* XXX: Why we need 2 loops??? */
37125cf1a30Sjl1390902:
37225cf1a30Sjl139090	sub	%o1, 2, %o1
37325cf1a30Sjl139090	mov	SCF_RETRY_CNT, %o5
37425cf1a30Sjl139090	and	%o4, %l2, %o3
37525cf1a30Sjl139090
37625cf1a30Sjl139090	sub	%o1, %l0, %o2
37725cf1a30Sjl139090	cmp	%o2, (SCF_TDATA)
37825cf1a30Sjl139090	bge,a	9b
37925cf1a30Sjl139090	 nop
38025cf1a30Sjl139090
38125cf1a30Sjl139090	/* if we reach TDATA, we are done */
38225cf1a30Sjl139090
38325cf1a30Sjl139090	/* read from SCF back to our buffer for debugging */
38425cf1a30Sjl139090	add	%l0, (SCF_TDATA), %o1
38525cf1a30Sjl139090	ldxa	[%o1]ASI_IO, %o2
38625cf1a30Sjl139090	stx	%o2, [%o0+SCF_TD]
38725cf1a30Sjl139090
38825cf1a30Sjl139090	add	%l0, (SCF_TDATA+8), %o1
38925cf1a30Sjl139090	ldxa	[%o1]ASI_IO, %o2
39025cf1a30Sjl139090	stx	%o2, [%o0+SCF_TD+8]
39125cf1a30Sjl139090
392b307f191Sbm42561	/* The following code conforms to the FMEM
393b307f191Sbm42561	   sequence (4) as described in the Columbus2
394b307f191Sbm42561	   logical spec section 4.6
395b307f191Sbm42561	*/
396b307f191Sbm42561
397b307f191Sbm42561	/* read from SCF SB INFO register */
398b307f191Sbm42561	sethi	%hi(SCF_SB_INFO_OFFSET), %o2
399b307f191Sbm42561	or	%o2, %lo(SCF_SB_INFO_OFFSET), %o2
400b307f191Sbm42561	add	%l0, %o2, %o1
401b307f191Sbm42561	lduba	[%o1]ASI_IO, %o2
402b307f191Sbm42561
403b307f191Sbm42561	/* If BUSY bit is set, abort */
404b307f191Sbm42561	or	%g0, (SCF_SB_INFO_BUSY), %o1
405b307f191Sbm42561	btst	%o1, %o2
406b307f191Sbm42561	set	EOPL_FMEM_SCF_BUSY, %o4
407b307f191Sbm42561	bne	1b
408b307f191Sbm42561	 nop
40925cf1a30Sjl139090
41025cf1a30Sjl139090	rd	STICK, %l1
41125cf1a30Sjl139090	add	%l5, %l1, %l5
41225cf1a30Sjl139090
41325cf1a30Sjl139090	/* Now tell SCF to do it */
41425cf1a30Sjl139090	add	%l0, SCF_COMMAND, %o1
41525cf1a30Sjl139090
41625cf1a30Sjl139090	/* 0x10A6 is the magic command */
41725cf1a30Sjl139090	sethi	%hi(0x10A6), %o2
41825cf1a30Sjl139090	or	%o2, %lo(0x10A6), %o2
41925cf1a30Sjl139090	stha	%o2, [%o1]ASI_IO
42025cf1a30Sjl139090
42125cf1a30Sjl139090	mov	1, %l7			! FMEM is issued
42225cf1a30Sjl139090
42325cf1a30Sjl139090	add	%l0, SCF_STATUS, %o1
42425cf1a30Sjl139090	sethi	%hi(SCF_STATUS_READY), %o2
42525cf1a30Sjl139090	mov	SCF_STATUS_CMD_COMPLETE, %o3
42625cf1a30Sjl139090
42725cf1a30Sjl139090	/* read STATUS_READY bit and clear it only if it is set */
42825cf1a30Sjl139090	/* XXX: this STATUS_READY checking seems meaningless */
42925cf1a30Sjl1390903:
43025cf1a30Sjl139090	lduha	[%o1]ASI_IO, %o4
43125cf1a30Sjl139090	btst	%o2, %o4
43225cf1a30Sjl139090	be	%xcc, 4f		! STATUS_READY is not set
43325cf1a30Sjl139090	 nop
43425cf1a30Sjl139090	stha	%o2, [%o1]ASI_IO	! Clear if the bit is set
43525cf1a30Sjl139090
43625cf1a30Sjl139090	/* check CMD_COMPLETE bit and clear */
43725cf1a30Sjl1390904:
43825cf1a30Sjl139090	btst	%o3, %o4
43925cf1a30Sjl139090	be	%xcc, 5f		! CMD_COMPLETE is not set
44025cf1a30Sjl139090	 nop
44125cf1a30Sjl139090	stha	%o3, [%o1]ASI_IO	! Now we are done and clear it
44225cf1a30Sjl139090	ba	%xcc, 6f
443b307f191Sbm42561	 mov	ESBD_NOERROR, %o4
44425cf1a30Sjl139090
44525cf1a30Sjl139090	/* timeout delay checking */
44625cf1a30Sjl1390905:
44725cf1a30Sjl139090	rd	STICK, %l2
44825cf1a30Sjl139090	cmp	%l5, %l2
44925cf1a30Sjl139090	bge	%xcc, 3b
45025cf1a30Sjl139090	 nop
451b307f191Sbm42561	set	EOPL_FMEM_TIMEOUT, %o4
45225cf1a30Sjl139090
45325cf1a30Sjl139090	/* we are done or timed out */
45425cf1a30Sjl1390906:
45525cf1a30Sjl139090	ba,a	1b
45625cf1a30Sjl139090	 nop
45725cf1a30Sjl139090	SET_SIZE(drmach_fmem_exec_script)
45825cf1a30Sjl139090#endif /* lint */
45925cf1a30Sjl139090
46025cf1a30Sjl139090#if defined(lint)
46125cf1a30Sjl139090/*ARGSUSED*/
46225cf1a30Sjl139090void
46325cf1a30Sjl139090drmach_fmem_exec_script_end(caddr_t critical, int size)
46425cf1a30Sjl139090{ return; }
46525cf1a30Sjl139090#else /* lint */
46625cf1a30Sjl139090	ENTRY_NP(drmach_fmem_exec_script_end)
46725cf1a30Sjl139090	nop
46825cf1a30Sjl139090	SET_SIZE(drmach_fmem_exec_script_end)
46925cf1a30Sjl139090#endif /* lint */
47025cf1a30Sjl139090
47125cf1a30Sjl139090#if defined(lint)
47225cf1a30Sjl139090uint64_t
47325cf1a30Sjl139090patch_inst(uint64_t *x, uint64_t y)
47425cf1a30Sjl139090{
47525cf1a30Sjl139090	*x = y;
47625cf1a30Sjl139090	return (0);
47725cf1a30Sjl139090}
47825cf1a30Sjl139090
47925cf1a30Sjl139090#else   /* lint */
48025cf1a30Sjl139090
48125cf1a30Sjl139090	ENTRY_NP(patch_inst)
48225cf1a30Sjl139090	ldx	[%o0], %o2
48325cf1a30Sjl139090	casx	[%o0], %o2, %o1
48425cf1a30Sjl139090	flush	%o0
48525cf1a30Sjl139090	membar #Sync
48625cf1a30Sjl139090	ldx	[%o0], %o2
48725cf1a30Sjl139090	retl
48825cf1a30Sjl139090	 mov	%o2, %o0
48925cf1a30Sjl139090	SET_SIZE(patch_inst)
49025cf1a30Sjl139090
49125cf1a30Sjl139090#endif /* lint */
49225cf1a30Sjl139090
49325cf1a30Sjl139090#if defined(lint)
49425cf1a30Sjl139090void
49525cf1a30Sjl139090drmach_sys_trap()
49625cf1a30Sjl139090{
49725cf1a30Sjl139090}
49825cf1a30Sjl139090#else   /* lint */
49925cf1a30Sjl139090	ENTRY_NP(drmach_sys_trap)
50025cf1a30Sjl139090	mov	-1, %g4
50125cf1a30Sjl139090	set	sys_trap, %g5
50225cf1a30Sjl139090	jmp	%g5
50325cf1a30Sjl139090	 nop
50425cf1a30Sjl139090	SET_SIZE(drmach_sys_trap)
50525cf1a30Sjl139090#endif /* lint */
50625cf1a30Sjl139090
50725cf1a30Sjl139090#if defined(lint)
50825cf1a30Sjl139090uint64_t
50925cf1a30Sjl139090drmach_get_stick()
51025cf1a30Sjl139090{
51125cf1a30Sjl139090	return (0);
51225cf1a30Sjl139090}
51325cf1a30Sjl139090#else   /* lint */
51425cf1a30Sjl139090	ENTRY_NP(drmach_get_stick)
51525cf1a30Sjl139090	retl
51625cf1a30Sjl139090	rd	STICK, %o0
51725cf1a30Sjl139090	SET_SIZE(drmach_get_stick)
51825cf1a30Sjl139090#endif /* lint */
51925cf1a30Sjl139090
52025cf1a30Sjl139090#if defined(lint)
52125cf1a30Sjl139090/*ARGSUSED*/
52225cf1a30Sjl139090void
523*07d06da5SSurya Prakkidrmach_flush(drmach_copy_rename_critical_t *x, uint_t y)
52425cf1a30Sjl139090{}
52525cf1a30Sjl139090
52625cf1a30Sjl139090#else /* lint */
52725cf1a30Sjl139090	ENTRY_NP(drmach_flush)
52825cf1a30Sjl139090	mov	%o0, %o2
52925cf1a30Sjl1390900:
53025cf1a30Sjl139090	flush	%o2
53125cf1a30Sjl139090	sub	%o1, 8, %o1
53225cf1a30Sjl139090	brnz	%o1, 0b
53325cf1a30Sjl139090	 add	%o2, 8, %o2
53425cf1a30Sjl139090	retl
53525cf1a30Sjl139090	 nop
53625cf1a30Sjl139090	SET_SIZE(drmach_flush)
53725cf1a30Sjl139090#endif /* lint */
538