Home | History | Annotate | Line # | Download | only in sparc
bsd_fdintr.s revision 1.9
      1  1.9       pk /*	$NetBSD: bsd_fdintr.s,v 1.9 1996/12/08 23:41:39 pk Exp $ */
      2  1.4       pk 
      3  1.1       pk /*
      4  1.1       pk  * Copyright (c) 1995 Paul Kranenburg
      5  1.1       pk  * All rights reserved.
      6  1.1       pk  *
      7  1.1       pk  * Redistribution and use in source and binary forms, with or without
      8  1.1       pk  * modification, are permitted provided that the following conditions
      9  1.1       pk  * are met:
     10  1.1       pk  * 1. Redistributions of source code must retain the above copyright
     11  1.1       pk  *    notice, this list of conditions and the following disclaimer.
     12  1.1       pk  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1       pk  *    notice, this list of conditions and the following disclaimer in the
     14  1.1       pk  *    documentation and/or other materials provided with the distribution.
     15  1.1       pk  * 3. All advertising materials mentioning features or use of this software
     16  1.1       pk  *    must display the following acknowledgement:
     17  1.1       pk  *      This product includes software developed by Paul Kranenburg.
     18  1.1       pk  * 4. The name of the author may not be used to endorse or promote products
     19  1.1       pk  *    derived from this software without specific prior written permission
     20  1.1       pk  *
     21  1.1       pk  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22  1.1       pk  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23  1.1       pk  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24  1.1       pk  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25  1.1       pk  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26  1.1       pk  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27  1.1       pk  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28  1.1       pk  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29  1.1       pk  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30  1.1       pk  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  1.1       pk  *
     32  1.1       pk  */
     33  1.1       pk 
     34  1.1       pk #ifndef FDC_C_HANDLER
     35  1.6  mycroft #include "assym.h"
     36  1.9       pk #include <machine/param.h>
     37  1.9       pk #include <machine/psl.h>
     38  1.1       pk #include <sparc/sparc/intreg.h>
     39  1.1       pk #include <sparc/sparc/auxreg.h>
     40  1.1       pk #include <sparc/sparc/vaddrs.h>
     41  1.1       pk #include <sparc/dev/fdreg.h>
     42  1.1       pk #include <sparc/dev/fdvar.h>
     43  1.9       pk 
     44  1.1       pk /* XXX this goes in a header file -- currently, it's hidden in locore.s */
     45  1.1       pk #define INTREG_ADDR 0xf8002000
     46  1.1       pk 
     47  1.9       pk #define FD_SET_SWINTR_4C				\
     48  1.9       pk 	sethi	%hi(INTREG_ADDR), %l5;			\
     49  1.9       pk 	ldub	[%l5 + %lo(INTREG_ADDR)], %l6;		\
     50  1.9       pk 	or	%l6, IE_L4, %l6;			\
     51  1.9       pk 	stb	%l6, [%l5 + %lo(INTREG_ADDR)]
     52  1.9       pk 
     53  1.9       pk ! raise(0,PIL_AUSOFT)	! NOTE: CPU#0 and PIL_AUSOFT=4
     54  1.9       pk #define FD_SET_SWINTR_4M				\
     55  1.9       pk 	sethi	%hi(1 << (16 + 4)), %l5;		\
     56  1.9       pk 	set	ICR_PI_SET, %l6;			\
     57  1.9       pk 	st	%l5, [%l6]
     58  1.9       pk 
     59  1.9       pk /* set software interrupt */
     60  1.9       pk #if defined(SUN4C) && !defined(SUN4M)
     61  1.9       pk #define FD_SET_SWINTR	FD_SET_SWINTR_4C
     62  1.9       pk #elif !defined(SUN4C) && defined(SUN4M)
     63  1.9       pk #define FD_SET_SWINTR	FD_SET_SWINTR_4M
     64  1.9       pk #else
     65  1.9       pk #define FD_SET_SWINTR					\
     66  1.9       pk 	sethi	%hi(_cputyp), %l5;			\
     67  1.9       pk 	ld	[%l5 + %lo(_cputyp)], %l5;		\
     68  1.9       pk 	cmp	%l5, CPU_SUN4M;				\
     69  1.9       pk 	be	8f;					\
     70  1.9       pk 	FD_SET_SWINTR_4C;				\
     71  1.9       pk 	ba,a	9f;					\
     72  1.9       pk 8:							\
     73  1.9       pk 	FD_SET_SWINTR_4M;				\
     74  1.9       pk 9:
     75  1.9       pk #endif
     76  1.9       pk 
     77  1.1       pk /* Timeout waiting for chip ready */
     78  1.1       pk #define POLL_TIMO	100000
     79  1.1       pk 
     80  1.1       pk /*
     81  1.1       pk  * register mnemonics. note overlapping assignments.
     82  1.1       pk  */
     83  1.1       pk #define R_fdc	%l0
     84  1.1       pk #define R_msr	%l1
     85  1.1       pk #define R_fifo	%l2
     86  1.1       pk #define R_buf	%l3
     87  1.1       pk #define R_tc	%l4
     88  1.1       pk #define R_stat	%l3
     89  1.1       pk #define R_nstat	%l4
     90  1.1       pk #define R_stcnt	%l5
     91  1.1       pk /* use %l6 and %l7 as short term temporaries */
     92  1.1       pk 
     93  1.1       pk 
     94  1.1       pk 	.seg	"data"
     95  1.1       pk 	.align	8
     96  1.1       pk 	.global _fdciop
     97  1.1       pk /* A save haven for three precious registers */
     98  1.1       pk save_l:
     99  1.1       pk 	.word	0
    100  1.1       pk 	.word	0
    101  1.1       pk 	.word	0
    102  1.1       pk /* Pointer to a `struct fdcio', set in fd.c */
    103  1.1       pk _fdciop:
    104  1.1       pk 	.word	0
    105  1.1       pk 
    106  1.1       pk 	.seg	"text"
    107  1.1       pk 	.align	4
    108  1.1       pk 	.global _fdchwintr
    109  1.1       pk 
    110  1.1       pk _fdchwintr:
    111  1.1       pk 	set	save_l, %l7
    112  1.1       pk 	std	%l0, [%l7]
    113  1.1       pk 	st	%l2, [%l7 + 8]
    114  1.2       pk 
    115  1.2       pk 	! tally interrupt
    116  1.2       pk 	sethi	%hi(_cnt+V_INTR), %l7
    117  1.2       pk 	ld	[%l7 + %lo(_cnt+V_INTR)], %l6
    118  1.2       pk 	inc	%l6
    119  1.2       pk 	st	%l6, [%l7 + %lo(_cnt+V_INTR)]
    120  1.1       pk 
    121  1.1       pk 	! load fdc, if it's NULL there's nothing to do: schedule soft interrupt
    122  1.1       pk 	sethi	%hi(_fdciop), %l7
    123  1.1       pk 	ld	[%l7 + %lo(_fdciop)], R_fdc
    124  1.3       pk 
    125  1.3       pk 	! tally interrupt
    126  1.3       pk 	ld	[R_fdc + FDC_EVCNT], %l6
    127  1.3       pk 	inc	%l6
    128  1.3       pk 	st	%l6, [R_fdc + FDC_EVCNT]
    129  1.1       pk 
    130  1.1       pk 	! load chips register addresses
    131  1.1       pk 	ld	[R_fdc + FDC_REG_MSR], R_msr	! get chip MSR reg addr
    132  1.1       pk 	ld	[R_fdc + FDC_REG_FIFO], R_fifo	! get chip FIFO reg addr
    133  1.1       pk 	!!ld	[R_fdc + FDC_REG_DOR], R_dor	! get chip DOR reg addr
    134  1.1       pk 
    135  1.1       pk 	! find out what we are supposed to do
    136  1.8       pk 	ld	[R_fdc + FDC_ISTATE], %l7	! examine flags
    137  1.1       pk 	cmp	%l7, ISTATE_SENSEI
    138  1.1       pk 	be	sensei
    139  1.1       pk 	 nop
    140  1.1       pk 	cmp	%l7, ISTATE_DMA
    141  1.1       pk 	bne	spurious
    142  1.1       pk 	 nop
    143  1.1       pk 
    144  1.1       pk 	! pseudo DMA
    145  1.1       pk 	ld	[R_fdc + FDC_TC], R_tc		! residual count
    146  1.1       pk 	ld	[R_fdc + FDC_DATA], R_buf	! IO buffer
    147  1.1       pk 
    148  1.1       pk 	ldub	[R_msr], %l7			! get MSR value
    149  1.1       pk nextc:
    150  1.1       pk 	btst	NE7_RQM, %l7			! room in fifo?
    151  1.1       pk 	bnz,a	0f
    152  1.1       pk 	 btst	NE7_NDM, %l7			! overrun?
    153  1.1       pk 
    154  1.1       pk 	! we filled/emptied the FIFO; update fdc->sc_buf & fdc->sc_tc
    155  1.1       pk 	st	R_tc, [R_fdc + FDC_TC]
    156  1.1       pk 	b	x
    157  1.1       pk 	st	R_buf, [R_fdc + FDC_DATA]
    158  1.1       pk 
    159  1.1       pk 0:
    160  1.1       pk 	bz	resultphase			! overrun/underrun
    161  1.1       pk 	btst	NE7_DIO, %l7			! IO direction
    162  1.1       pk 	bz	1f
    163  1.1       pk 	 deccc	R_tc
    164  1.1       pk 	ldub	[R_fifo], %l7			! reading:
    165  1.1       pk 	b	2f
    166  1.1       pk 	stb	%l7, [R_buf]			!    *fdc->sc_bufp = *reg_fifo
    167  1.1       pk 
    168  1.1       pk 1:
    169  1.1       pk 	ldub	[R_buf], %l7			! writing:
    170  1.1       pk 	stb	%l7, [R_fifo]			!    *reg_fifo = *fdc->sc_bufp
    171  1.1       pk 2:
    172  1.1       pk 	inc	R_buf				! fdc->sc_bufp++
    173  1.1       pk 	bne,a	nextc				! if (--fdc->sc_tc) goto ...
    174  1.1       pk 	 ldub	[R_msr], %l7			! get MSR value
    175  1.1       pk 
    176  1.9       pk 	! xfer done: update fdc->sc_buf & fdc->sc_tc, mark istate DONE
    177  1.1       pk 	st	R_tc, [R_fdc + FDC_TC]
    178  1.1       pk 	st	R_buf, [R_fdc + FDC_DATA]
    179  1.1       pk 
    180  1.1       pk 	! flip TC bit in auxreg
    181  1.1       pk 	sethi	%hi(_auxio_reg), %l6
    182  1.1       pk 	ld	[%l6 + %lo(_auxio_reg)], %l6
    183  1.1       pk 	ldub	[%l6], %l7
    184  1.1       pk 	or	%l7, AUXIO_MB1|AUXIO_FTC, %l7
    185  1.1       pk 	stb	%l7, [%l6]
    186  1.1       pk 
    187  1.1       pk 	! we have some time to kill; anticipate on upcoming
    188  1.1       pk 	! result phase.
    189  1.1       pk 	add	R_fdc, FDC_STATUS, R_stat	! &fdc->sc_status[0]
    190  1.1       pk 	mov	-1, %l7
    191  1.1       pk 	st	%l7, [R_fdc + FDC_NSTAT]	! fdc->sc_nstat = -1;
    192  1.1       pk 
    193  1.1       pk 	ldub	[%l6], %l7
    194  1.1       pk 	andn	%l7, AUXIO_FTC, %l7
    195  1.1       pk 	or	%l7, AUXIO_MB1, %l7
    196  1.1       pk 	stb	%l7, [%l6]
    197  1.1       pk 	b	resultphase1
    198  1.1       pk 	 nop
    199  1.1       pk 
    200  1.1       pk spurious:
    201  1.1       pk 	mov	ISTATE_SPURIOUS, %l7
    202  1.1       pk 	st	%l7, [R_fdc + FDC_ISTATE]
    203  1.1       pk 	b,a	ssi
    204  1.1       pk 
    205  1.1       pk sensei:
    206  1.1       pk 	ldub	[R_msr], %l7
    207  1.1       pk 	set	POLL_TIMO, %l6
    208  1.1       pk 1:	deccc	%l6				! timeout?
    209  1.1       pk 	be	ssi
    210  1.1       pk 	and	%l7, (NE7_RQM | NE7_DIO | NE7_CB), %l7
    211  1.1       pk 	cmp	%l7, NE7_RQM
    212  1.1       pk 	bne,a	1b				! loop till chip ready
    213  1.1       pk 	 ldub	[R_msr], %l7
    214  1.1       pk 	mov	NE7CMD_SENSEI, %l7
    215  1.1       pk 	stb	%l7, [R_fifo]
    216  1.1       pk 
    217  1.1       pk resultphase:
    218  1.1       pk 	! prepare for result phase
    219  1.1       pk 	add	R_fdc, FDC_STATUS, R_stat	! &fdc->sc_status[0]
    220  1.1       pk 	mov	-1, %l7
    221  1.1       pk 	st	%l7, [R_fdc + FDC_NSTAT]	! fdc->sc_nstat = -1;
    222  1.1       pk 
    223  1.1       pk resultphase1:
    224  1.1       pk 	clr	R_stcnt
    225  1.1       pk 	ldub	[R_msr], %l7
    226  1.1       pk 	set	POLL_TIMO, %l6
    227  1.1       pk 1:	deccc	%l6				! timeout?
    228  1.1       pk 	be	ssi
    229  1.1       pk 	and	%l7, (NE7_RQM | NE7_DIO | NE7_CB), %l7
    230  1.1       pk 	cmp	%l7, NE7_RQM
    231  1.1       pk 	be	3f				! done
    232  1.1       pk 	cmp	%l7, (NE7_RQM | NE7_DIO | NE7_CB)
    233  1.1       pk 	bne,a	1b				! loop till chip ready
    234  1.1       pk 	 ldub	[R_msr], %l7
    235  1.1       pk 
    236  1.1       pk 	cmp	R_stcnt, FDC_NSTATUS		! status overrun?
    237  1.1       pk 	bge	2f				! if so, load but dont store
    238  1.1       pk 	ldub	[R_fifo], %l7			! load the status byte
    239  1.1       pk 	stb	%l7, [R_stat]
    240  1.1       pk 	inc	R_stat
    241  1.1       pk 	inc	R_stcnt
    242  1.1       pk 2:	b	1b
    243  1.1       pk 	 ldub	[R_msr], %l7
    244  1.1       pk 
    245  1.1       pk 3:
    246  1.9       pk 	! got status, update sc_nstat and mark istate DONE
    247  1.1       pk 	st	R_stcnt, [R_fdc + FDC_NSTAT]
    248  1.9       pk 	mov	ISTATE_DONE, %l7
    249  1.1       pk 	st	%l7, [R_fdc + FDC_ISTATE]
    250  1.1       pk 
    251  1.1       pk ssi:
    252  1.1       pk 	! set software interrupt
    253  1.9       pk 	FD_SET_SWINTR
    254  1.1       pk 
    255  1.1       pk x:
    256  1.1       pk 	/*
    257  1.1       pk 	 * Restore psr -- note: psr delay honored by pc restore loads.
    258  1.1       pk 	 */
    259  1.1       pk 	set	save_l, %l7
    260  1.1       pk 	ldd	[%l7], %l0
    261  1.1       pk 	mov	%l0, %psr
    262  1.1       pk 	 nop
    263  1.1       pk 	ld	[%l7 + 8], %l2
    264  1.1       pk 	jmp	%l1
    265  1.1       pk 	rett	%l2
    266  1.1       pk #endif
    267