xref: /onnv-gate/usr/src/uts/sparc/ml/fd_asm.s (revision 457:d8f2995c64aa)
10Sstevel@tonic-gate/*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate * with the License.
80Sstevel@tonic-gate *
90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate * See the License for the specific language governing permissions
120Sstevel@tonic-gate * and limitations under the License.
130Sstevel@tonic-gate *
140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate *
200Sstevel@tonic-gate * CDDL HEADER END
210Sstevel@tonic-gate */
220Sstevel@tonic-gate/*
23*457Sbmc * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*457Sbmc * Use is subject to license terms.
250Sstevel@tonic-gate */
260Sstevel@tonic-gate
270Sstevel@tonic-gate#ident	"%Z%%M%	%I%	%E% SMI"
280Sstevel@tonic-gate
290Sstevel@tonic-gate/*
300Sstevel@tonic-gate * This file contains no entry points which can be called directly from
310Sstevel@tonic-gate * C and hence is of no interest to lint. However, we want to avoid the
320Sstevel@tonic-gate * dreaded "Empty translation unit"  warning.
330Sstevel@tonic-gate */
340Sstevel@tonic-gate
350Sstevel@tonic-gate#if defined(lint)
360Sstevel@tonic-gate#include <sys/types.h>
370Sstevel@tonic-gate
380Sstevel@tonic-gate/*ARGSUSED*/
390Sstevel@tonic-gateu_int
400Sstevel@tonic-gatefd_intr(caddr_t arg)
410Sstevel@tonic-gate{
420Sstevel@tonic-gate	return (0);
430Sstevel@tonic-gate}
440Sstevel@tonic-gate
450Sstevel@tonic-gate#else	/* lint */
460Sstevel@tonic-gate
470Sstevel@tonic-gate#include <sys/asm_linkage.h>
480Sstevel@tonic-gate#include <sys/fdreg.h>
490Sstevel@tonic-gate#include <sys/fdvar.h>
500Sstevel@tonic-gate#include "fd_assym.h"
510Sstevel@tonic-gate
520Sstevel@tonic-gate/*
530Sstevel@tonic-gate * Since this is part of a Sparc "generic" module, it may be loaded during
540Sstevel@tonic-gate * reconfigure time on systems that do not support the fast interrupt
550Sstevel@tonic-gate * handler.  On these machines the symbol "impl_setintreg_on" will be
560Sstevel@tonic-gate * undefined but we don't want to cause error messages when we load.
570Sstevel@tonic-gate */
580Sstevel@tonic-gate	.weak	impl_setintreg_on
590Sstevel@tonic-gate	.type	impl_setintreg_on, #function
600Sstevel@tonic-gate	.weak	fd_softintr_cookie
610Sstevel@tonic-gate	.type	fd_softintr_cookie, #object
620Sstevel@tonic-gate
630Sstevel@tonic-gate#define	Tmp2	%l4	/* temp register prior to dispatch to right opmode */
640Sstevel@tonic-gate#define	Reg	%l4	/* pointer to the chip's registers */
650Sstevel@tonic-gate#define	Fdc	%l3	/* pointer to fdctlr structure */
660Sstevel@tonic-gate#define	Adr	%l5	/* data address pointer */
670Sstevel@tonic-gate#define	Len	%l6	/* data length counter */
680Sstevel@tonic-gate#define	Tmp	%l7	/* general scratch */
690Sstevel@tonic-gate#define	TRIGGER	0x33
700Sstevel@tonic-gate	ENTRY(fd_intr)		! fd standard interrupt handler
710Sstevel@tonic-gate	save	%sp, -SA(MINFRAME), %sp
720Sstevel@tonic-gate	!
730Sstevel@tonic-gate	! Traverse the list of controllers until we find the first
740Sstevel@tonic-gate	! controller expecting an interrupt. Unfortunately, the
750Sstevel@tonic-gate	! 82072 floppy controller really doesn't have a way to tell
760Sstevel@tonic-gate	! you that it is interrupting.
770Sstevel@tonic-gate	!
780Sstevel@tonic-gate	set	fdctlrs, Fdc		! load list of controllers
790Sstevel@tonic-gate	ldn	[Fdc], Fdc		! get the first in the list...
800Sstevel@tonic-gate1:	tst	Fdc			! do we have any more to check
810Sstevel@tonic-gate	bz	.panic			! Nothing to service. Panic
820Sstevel@tonic-gate	nop
830Sstevel@tonic-gate
840Sstevel@tonic-gate3:	ldub	[Fdc + FD_OPMODE], Tmp2	! load opmode into Tmp2
850Sstevel@tonic-gate	and	Tmp2, 0x3, Tmp2		! opmode must be 1, 2, or 3
860Sstevel@tonic-gate	tst	Tmp2			! non-zero?
870Sstevel@tonic-gate	bnz	.mutex_enter		! yes!
880Sstevel@tonic-gate	nop
890Sstevel@tonic-gate	ldn	[Fdc + FD_NEXT], Tmp	! Try next ctlr...
900Sstevel@tonic-gate	tst	Tmp
910Sstevel@tonic-gate	bnz,a	1b
920Sstevel@tonic-gate	mov	Tmp, Fdc
930Sstevel@tonic-gate					! no more controllers
940Sstevel@tonic-gate	mov	0x2, Tmp2		! must be spurious or "ready" int
950Sstevel@tonic-gate.mutex_enter:
960Sstevel@tonic-gate	!
970Sstevel@tonic-gate	! grab high level mutex for this controller
980Sstevel@tonic-gate	!
990Sstevel@tonic-gate	sethi	%hi(asm_mutex_spin_enter), %l7
1000Sstevel@tonic-gate	jmpl	%l7 + %lo(asm_mutex_spin_enter), %l7
1010Sstevel@tonic-gate	add	Fdc, FD_HILOCK, %l6
1020Sstevel@tonic-gate	!
1030Sstevel@tonic-gate	! dispatch to correct handler
1040Sstevel@tonic-gate	!
1050Sstevel@tonic-gate	cmp	Tmp2, 3			!case 3: results ?
1060Sstevel@tonic-gate	be,a	.opmode3		! yes...
1070Sstevel@tonic-gate	ldn	[Fdc + FD_REG], Reg	! load pointer to h/w registers
1080Sstevel@tonic-gate	cmp	Tmp2, 2			!case 2: seek/recalibrate ?
1090Sstevel@tonic-gate	be	.opmode2		! yes..
1100Sstevel@tonic-gate	ldn	[Fdc + FD_REG], Reg	! load pointer to h/w registers
1110Sstevel@tonic-gate	!
1120Sstevel@tonic-gate	! opmode 1:
1130Sstevel@tonic-gate	! read/write/format data-xfer case - they have a result phase
1140Sstevel@tonic-gate	!
1150Sstevel@tonic-gate.opmode1:
1160Sstevel@tonic-gate	ld	[Fdc + FD_RLEN], Len
1170Sstevel@tonic-gate	!
1180Sstevel@tonic-gate	! XXX- test for null raddr
1190Sstevel@tonic-gate	!
1200Sstevel@tonic-gate	ldn	[Fdc + FD_RADDR], Adr
1210Sstevel@tonic-gate
1220Sstevel@tonic-gate	!
1230Sstevel@tonic-gate	! while the fifo ready bit set, then data/status available
1240Sstevel@tonic-gate	!
1250Sstevel@tonic-gate1:	ldub	[Reg], Tmp		! get csr
1260Sstevel@tonic-gate	andcc	Tmp, RQM, %g0		!
1270Sstevel@tonic-gate	be	4f			! branch if bit clear
1280Sstevel@tonic-gate	andcc	Tmp, NDM, %g0		! NDM set means data
1290Sstevel@tonic-gate	be	7f			! if not set, it is status time
1300Sstevel@tonic-gate	andcc	Tmp, DIO, %g0		! check for input vs. output data
1310Sstevel@tonic-gate	be	2f			!
1320Sstevel@tonic-gate	sub	Len, 0x1, Len		! predecrement length...
1330Sstevel@tonic-gate	ldub	[Reg + 0x1], Tmp	! DIO set, *addr = *fifo
1340Sstevel@tonic-gate	b	3f			!
1350Sstevel@tonic-gate	stb	Tmp, [Adr]		!
1360Sstevel@tonic-gate2:	ldsb	[Adr], Tmp		! *fifo = *addr
1370Sstevel@tonic-gate	stb	Tmp, [Reg + 0x1]	!
1380Sstevel@tonic-gate3:	tst	Len			! if (len == 0) send TC
1390Sstevel@tonic-gate	bne	1b			! branch if not....
1400Sstevel@tonic-gate	add	Adr, 0x1, Adr		!
1410Sstevel@tonic-gate	b	6f			!
1420Sstevel@tonic-gate	.empty				!
1430Sstevel@tonic-gate	!
1440Sstevel@tonic-gate	! save updated len, addr
1450Sstevel@tonic-gate	!
1460Sstevel@tonic-gate4:	st	Len, [Fdc + FD_RLEN]
1470Sstevel@tonic-gate	b	.out			! not done yet, return
1480Sstevel@tonic-gate	stn	Adr, [Fdc + FD_RADDR]
1490Sstevel@tonic-gate	!
1500Sstevel@tonic-gate	! END OF TRANSFER - if read/write, toggle the TC
1510Sstevel@tonic-gate	! bit in AUXIO_REG then save status and set state = 3.
1520Sstevel@tonic-gate	!
1530Sstevel@tonic-gate5:
1540Sstevel@tonic-gate	!
1550Sstevel@tonic-gate	! Stash len and addr before they get lost
1560Sstevel@tonic-gate	!
1570Sstevel@tonic-gate	st	Len, [Fdc + FD_RLEN]
1580Sstevel@tonic-gate6:	stn	Adr, [Fdc + FD_RADDR]
1590Sstevel@tonic-gate	!
1600Sstevel@tonic-gate	! Begin TC delay...
1610Sstevel@tonic-gate	! Old comment:
1620Sstevel@tonic-gate	!	five nops provide 100ns of delay at 10MIPS to ensure
1630Sstevel@tonic-gate	!	TC is wide enough at slowest possible floppy clock
1640Sstevel@tonic-gate	!	(500ns @ 250Kbps).
1650Sstevel@tonic-gate	!
1660Sstevel@tonic-gate	! I gather this mean that we have to give 100ns delay for TC.
1670Sstevel@tonic-gate	!
1680Sstevel@tonic-gate	! At 100 Mips, that would be 1 * 10 (10) nops.
1690Sstevel@tonic-gate	!
1700Sstevel@tonic-gate
1710Sstevel@tonic-gate	ldn	[Fdc + FD_AUXIOVA], Adr
1720Sstevel@tonic-gate	ldub	[Fdc + FD_AUXIODATA], Tmp2
1730Sstevel@tonic-gate	ldub	[Adr], Tmp
1740Sstevel@tonic-gate	or	Tmp, Tmp2, Tmp
1750Sstevel@tonic-gate	stb	Tmp, [Adr]
1760Sstevel@tonic-gate	nop; nop; nop; nop; nop; nop; nop; nop; nop; nop	! 10 nops
1770Sstevel@tonic-gate	!
1780Sstevel@tonic-gate	! End TC delay...now clear the TC bit
1790Sstevel@tonic-gate	!
1800Sstevel@tonic-gate	ldub	[Fdc + FD_AUXIODATA2], Tmp2
1810Sstevel@tonic-gate	andn	Tmp, Tmp2, Tmp
1820Sstevel@tonic-gate	stb	Tmp, [Adr]
1830Sstevel@tonic-gate
1840Sstevel@tonic-gate	!
1850Sstevel@tonic-gate	! set opmode to 3 to indicate going into status mode
1860Sstevel@tonic-gate	!
1870Sstevel@tonic-gate	mov	3, Tmp
1880Sstevel@tonic-gate	b	.out
1890Sstevel@tonic-gate	stb	Tmp, [Fdc + FD_OPMODE]
1900Sstevel@tonic-gate	!
1910Sstevel@tonic-gate	! error status state: save old pointers, go direct to result snarfing
1920Sstevel@tonic-gate	!
1930Sstevel@tonic-gate7:	st	Len, [Fdc + FD_RLEN]
1940Sstevel@tonic-gate	stn	Adr, [Fdc + FD_RADDR]
1950Sstevel@tonic-gate	mov	0x3, Tmp
1960Sstevel@tonic-gate	b	.opmode3
1970Sstevel@tonic-gate	stb	Tmp, [Fdc + FD_OPMODE]
1980Sstevel@tonic-gate	!
1990Sstevel@tonic-gate	! opmode 2:
2000Sstevel@tonic-gate	! recalibrate/seek - no result phase, must do sense interrupt status.
2010Sstevel@tonic-gate	!
2020Sstevel@tonic-gate.opmode2:
2030Sstevel@tonic-gate	ldub	[Reg], Tmp			! Tmp = *csr
2040Sstevel@tonic-gate1:	andcc	Tmp, CB, %g0			! is CB set?
2050Sstevel@tonic-gate	bne	1b				! yes, keep waiting
2060Sstevel@tonic-gate	ldub	[Reg], Tmp			!! Tmp = *csr
2070Sstevel@tonic-gate	!
2080Sstevel@tonic-gate	! wait!!! should we check rqm first???  ABSOLUTELY YES!!!!
2090Sstevel@tonic-gate	!
2100Sstevel@tonic-gate1:	andcc	Tmp, RQM, %g0		!
2110Sstevel@tonic-gate	be,a	1b			! branch if bit clear
2120Sstevel@tonic-gate	ldub	[Reg], Tmp		! busy wait until RQM set
2130Sstevel@tonic-gate	mov	SNSISTAT, Tmp		! cmd for SENSE_INTERRUPT_STATUS
2140Sstevel@tonic-gate	stb	Tmp, [Reg + 0x1]
2150Sstevel@tonic-gate	!
2160Sstevel@tonic-gate	! NOTE: we ignore DIO here, assume it is set before RQM!
2170Sstevel@tonic-gate	!
2180Sstevel@tonic-gate	ldub	[Reg], Tmp			! busy wait until RQM set
2190Sstevel@tonic-gate1:	andcc	Tmp, RQM, Tmp
2200Sstevel@tonic-gate	be,a	1b				! branch if bit clear
2210Sstevel@tonic-gate	ldub	[Reg], Tmp			! busy wait until RQM set
2220Sstevel@tonic-gate	!
2230Sstevel@tonic-gate	! fdc->c_csb.csb_rslt[0] = *fifo;
2240Sstevel@tonic-gate	!
2250Sstevel@tonic-gate	ldub	[Reg + 0x1], Tmp
2260Sstevel@tonic-gate	stb	Tmp, [Fdc + FD_RSLT]
2270Sstevel@tonic-gate	ldub	[Reg], Tmp			! busy wait until RQM set
2280Sstevel@tonic-gate1:	andcc	Tmp, RQM, Tmp
2290Sstevel@tonic-gate	be,a	1b				! branch if bit clear
2300Sstevel@tonic-gate	ldub	[Reg], Tmp			! busy wait until RQM set
2310Sstevel@tonic-gate	!
2320Sstevel@tonic-gate	! fdc->c_csb.csb_rslt[1] = *fifo;
2330Sstevel@tonic-gate	!
2340Sstevel@tonic-gate	ldub	[Reg + 0x1], Tmp
2350Sstevel@tonic-gate	b	.notify
2360Sstevel@tonic-gate	stb	Tmp, [Fdc + FD_RSLT + 1]
2370Sstevel@tonic-gate	!
2380Sstevel@tonic-gate	! case 3: result mode
2390Sstevel@tonic-gate	! We are in result mode make sure all status bytes are read out
2400Sstevel@tonic-gate	!
2410Sstevel@tonic-gate	! We have to have *both* RQM and DIO set.
2420Sstevel@tonic-gate	!
2430Sstevel@tonic-gate.opmode3:
2440Sstevel@tonic-gate	add	Fdc, FD_RSLT, Adr		! load address of csb->csb_rslt
2450Sstevel@tonic-gate	add	Adr, 10, Len			! put an upper bound on it..
2460Sstevel@tonic-gate	ldub	[Reg], Tmp			!
2470Sstevel@tonic-gate1:	andcc	Tmp, CB, %g0			! is CB set?
2480Sstevel@tonic-gate	be	.notify				! no, jump around, must be done
2490Sstevel@tonic-gate	andcc	Tmp, RQM, %g0			! check for RQM in delay slot
2500Sstevel@tonic-gate	be,a	1b				! No RQM, go back
2510Sstevel@tonic-gate	ldub	[Reg], Tmp			! and load control reg in delay
2520Sstevel@tonic-gate	andcc	Tmp, DIO, %g0			! DIO set?
2530Sstevel@tonic-gate	be,a	1b				! No DIO, go back
2540Sstevel@tonic-gate	ldub	[Reg], Tmp			! and load control reg in delay
2550Sstevel@tonic-gate	!
2560Sstevel@tonic-gate	! CB && DIO && RQM all true.
2570Sstevel@tonic-gate	! Time to get a byte.
2580Sstevel@tonic-gate	!
2590Sstevel@tonic-gate	ldub	[Reg + 0x1], Tmp		! *fifo into Tmp
2600Sstevel@tonic-gate	cmp	Adr, Len			! already at our limit?
2610Sstevel@tonic-gate	bge,a	1b				! Yes, go back..
2620Sstevel@tonic-gate	ldub	[Reg], Tmp			! and load control reg in delay
2630Sstevel@tonic-gate	stb	Tmp, [Adr]			! store new byte
2640Sstevel@tonic-gate	add	Adr, 1, Adr			! increment address
2650Sstevel@tonic-gate	b	1b				! and pop back to the top
2660Sstevel@tonic-gate	ldub	[Reg], Tmp			! and load control reg in delay
2670Sstevel@tonic-gate
2680Sstevel@tonic-gate	!
2690Sstevel@tonic-gate	! schedule 2nd stage interrupt
2700Sstevel@tonic-gate	!
2710Sstevel@tonic-gate.notify:
2720Sstevel@tonic-gate	!
2730Sstevel@tonic-gate	! if fast traps are enabled, use the platform dependent
2740Sstevel@tonic-gate	! impl_setintreg_on function.
2750Sstevel@tonic-gate	!
2760Sstevel@tonic-gate	ldub    [Fdc + FD_FASTTRAP], Tmp
2770Sstevel@tonic-gate	tst     Tmp
2780Sstevel@tonic-gate	bnz	.fast
2790Sstevel@tonic-gate	nop
2800Sstevel@tonic-gate
2810Sstevel@tonic-gate	!
2820Sstevel@tonic-gate	! fast traps are not in use.  Do not schedule the soft interrupt
2830Sstevel@tonic-gate	! at this time.  Wait to trigger it at the end of the handler
2840Sstevel@tonic-gate	! when the mutexes have been released
2850Sstevel@tonic-gate	!
2860Sstevel@tonic-gate	mov   	TRIGGER, Tmp2
2870Sstevel@tonic-gate	b	.out
2880Sstevel@tonic-gate	nop
2890Sstevel@tonic-gate
2900Sstevel@tonic-gate	!
2910Sstevel@tonic-gate	! fast traps are enabled.  Schedule the soft interrupt.
2920Sstevel@tonic-gate	! impl_setintreg uses %l4-%l7
2930Sstevel@tonic-gate	!
2940Sstevel@tonic-gate.fast:	sethi   %hi(fd_softintr_cookie), %l6
2950Sstevel@tonic-gate	sethi	%hi(impl_setintreg_on), %l7
2960Sstevel@tonic-gate	jmpl	%l7 + %lo(impl_setintreg_on), %l7
2970Sstevel@tonic-gate	ld      [%l6 + %lo(fd_softintr_cookie)], %l6
2980Sstevel@tonic-gate	!
2990Sstevel@tonic-gate	! set new opmode to 4
3000Sstevel@tonic-gate	!
3010Sstevel@tonic-gate	mov	0x4, Tmp
3020Sstevel@tonic-gate	stb	Tmp, [Fdc + FD_OPMODE]
3030Sstevel@tonic-gate
3040Sstevel@tonic-gate	!
3050Sstevel@tonic-gate	! and fall through to exit
3060Sstevel@tonic-gate	!
3070Sstevel@tonic-gate.out:
3080Sstevel@tonic-gate	!
3090Sstevel@tonic-gate	! update high level interrupt counter...
3100Sstevel@tonic-gate	!
3110Sstevel@tonic-gate	ldn	[Fdc + FD_HIINTCT], Adr
3120Sstevel@tonic-gate	tst	Adr
3130Sstevel@tonic-gate	be,a	1f
3140Sstevel@tonic-gate	nop
3150Sstevel@tonic-gate	ld	[Adr], Tmp
3160Sstevel@tonic-gate	inc	Tmp
3170Sstevel@tonic-gate	st	Tmp, [Adr]
3180Sstevel@tonic-gate1:
3190Sstevel@tonic-gate	!
3200Sstevel@tonic-gate	! Release mutex
3210Sstevel@tonic-gate	!
3220Sstevel@tonic-gate	sethi	%hi(asm_mutex_spin_exit), %l7
3230Sstevel@tonic-gate	jmpl	%l7 + %lo(asm_mutex_spin_exit), %l7
3240Sstevel@tonic-gate	add	Fdc, FD_HILOCK, %l6
3250Sstevel@tonic-gate
3260Sstevel@tonic-gate	!
3270Sstevel@tonic-gate	! schedule the soft interrupt if needed
3280Sstevel@tonic-gate	!
3290Sstevel@tonic-gate	cmp	Tmp2, TRIGGER
3300Sstevel@tonic-gate	bne	.end
3310Sstevel@tonic-gate	nop
3320Sstevel@tonic-gate
3330Sstevel@tonic-gate   	!
3340Sstevel@tonic-gate	! set new opmode to 4
3350Sstevel@tonic-gate        !
3360Sstevel@tonic-gate	mov     0x4, Tmp
3370Sstevel@tonic-gate        stb     Tmp, [Fdc + FD_OPMODE]
3380Sstevel@tonic-gate
3390Sstevel@tonic-gate	! invoke ddi_trigger_softintr.  load
3400Sstevel@tonic-gate	! softid parameter in the delay slot
3410Sstevel@tonic-gate	!
3420Sstevel@tonic-gate	call	ddi_trigger_softintr
3430Sstevel@tonic-gate	ldn	[Fdc + FD_SOFTID], %o0
3440Sstevel@tonic-gate
3450Sstevel@tonic-gate.end:	mov	1, %i0
3460Sstevel@tonic-gate	ret
3470Sstevel@tonic-gate	restore
3480Sstevel@tonic-gate	SET_SIZE(fd_intr)
3490Sstevel@tonic-gate
3500Sstevel@tonic-gate.panic:
3510Sstevel@tonic-gate        ! invoke a kernel panic
3520Sstevel@tonic-gate        sethi   %hi(panic_msg), %o1
3530Sstevel@tonic-gate        ldn    [%o1 + %lo(panic_msg)], %o1
3540Sstevel@tonic-gate        mov     3, %o0
3550Sstevel@tonic-gate        call    cmn_err
3560Sstevel@tonic-gate	nop
3570Sstevel@tonic-gate
3580Sstevel@tonic-gate
3590Sstevel@tonic-gate#endif  /* lint */
360