xref: /netbsd-src/sys/arch/emips/ebus/icap_ebus.c (revision 3af7ad6d6dce2a0584fc0839ba1515772508f1ce)
1*3af7ad6dSmrg /*	$NetBSD: icap_ebus.c,v 1.7 2018/03/04 21:41:48 mrg Exp $	*/
25f7e80a8Spooka 
35f7e80a8Spooka /*-
45f7e80a8Spooka  * Copyright (c) 2010 The NetBSD Foundation, Inc.
55f7e80a8Spooka  * All rights reserved.
65f7e80a8Spooka  *
75f7e80a8Spooka  * This code was written by Alessandro Forin and Neil Pittman
85f7e80a8Spooka  * at Microsoft Research and contributed to The NetBSD Foundation
95f7e80a8Spooka  * by Microsoft Corporation.
105f7e80a8Spooka  *
115f7e80a8Spooka  * Redistribution and use in source and binary forms, with or without
125f7e80a8Spooka  * modification, are permitted provided that the following conditions
135f7e80a8Spooka  * are met:
145f7e80a8Spooka  * 1. Redistributions of source code must retain the above copyright
155f7e80a8Spooka  *    notice, this list of conditions and the following disclaimer.
165f7e80a8Spooka  * 2. Redistributions in binary form must reproduce the above copyright
175f7e80a8Spooka  *    notice, this list of conditions and the following disclaimer in the
185f7e80a8Spooka  *    documentation and/or other materials provided with the distribution.
195f7e80a8Spooka  *
205f7e80a8Spooka  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
215f7e80a8Spooka  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
225f7e80a8Spooka  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
235f7e80a8Spooka  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
245f7e80a8Spooka  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
255f7e80a8Spooka  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
265f7e80a8Spooka  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
275f7e80a8Spooka  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
285f7e80a8Spooka  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
295f7e80a8Spooka  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
305f7e80a8Spooka  * POSSIBILITY OF SUCH DAMAGE.
315f7e80a8Spooka  */
325f7e80a8Spooka 
335f7e80a8Spooka #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
34*3af7ad6dSmrg __KERNEL_RCSID(0, "$NetBSD: icap_ebus.c,v 1.7 2018/03/04 21:41:48 mrg Exp $");
355f7e80a8Spooka 
365f7e80a8Spooka #include <sys/param.h>
375f7e80a8Spooka #include <sys/systm.h>
385f7e80a8Spooka #include <sys/buf.h>
395f7e80a8Spooka #include <sys/bufq.h>
405f7e80a8Spooka #include <sys/proc.h>
415f7e80a8Spooka #include <sys/errno.h>
425f7e80a8Spooka #include <sys/ioctl.h>
435f7e80a8Spooka #include <sys/device.h>
445f7e80a8Spooka #include <sys/conf.h>
455f7e80a8Spooka #include <uvm/uvm_param.h>
465f7e80a8Spooka 
475f7e80a8Spooka #include <emips/ebus/ebusvar.h>
485f7e80a8Spooka #include <emips/emips/machdep.h>
495f7e80a8Spooka #include <machine/emipsreg.h>
505f7e80a8Spooka 
515f7e80a8Spooka #define DEBUG_INTR   0x01
525f7e80a8Spooka #define DEBUG_XFERS  0x02
535f7e80a8Spooka #define DEBUG_STATUS 0x04
545f7e80a8Spooka #define DEBUG_FUNCS  0x08
555f7e80a8Spooka #define DEBUG_PROBE  0x10
565f7e80a8Spooka #define DEBUG_WRITES 0x20
575f7e80a8Spooka #define DEBUG_READS  0x40
585f7e80a8Spooka #define DEBUG_ERRORS 0x80
595f7e80a8Spooka #ifdef DEBUG
605f7e80a8Spooka int icap_debug = DEBUG_ERRORS;
615f7e80a8Spooka #define ICAP_DEBUG(x) (icap_debug & (x))
625f7e80a8Spooka #define DBGME(_lev_,_x_) if ((_lev_) & icap_debug) _x_
635f7e80a8Spooka #else
645f7e80a8Spooka #define ICAP_DEBUG(x) (0)
655f7e80a8Spooka #define DBGME(_lev_,_x_)
665f7e80a8Spooka #endif
675f7e80a8Spooka #define DEBUG_PRINT(_args_,_lev_) DBGME(_lev_,printf _args_)
685f7e80a8Spooka 
695f7e80a8Spooka /*
705f7e80a8Spooka  * Device softc
715f7e80a8Spooka  */
725f7e80a8Spooka struct icap_softc {
735f7e80a8Spooka 	device_t sc_dev;
745f7e80a8Spooka 	struct _Icap *sc_dp;
755f7e80a8Spooka 	struct bufq_state *sc_buflist;
765f7e80a8Spooka 	struct buf *sc_bp;
775f7e80a8Spooka 	char *sc_data;
785f7e80a8Spooka 	int sc_count;
795f7e80a8Spooka };
805f7e80a8Spooka 
815f7e80a8Spooka /* Required funcs
825f7e80a8Spooka  */
83cbab9cadSchs static int	icap_ebus_match (device_t, cfdata_t, void *);
84cbab9cadSchs static void	icap_ebus_attach (device_t, device_t, void *);
855f7e80a8Spooka 
865f7e80a8Spooka static dev_type_open(icapopen);
875f7e80a8Spooka static dev_type_close(icapclose);
885f7e80a8Spooka static dev_type_read(icapread);
895f7e80a8Spooka static dev_type_write(icapwrite);
905f7e80a8Spooka static dev_type_ioctl(icapioctl);
915f7e80a8Spooka static dev_type_strategy(icapstrategy);
925f7e80a8Spooka 
935f7e80a8Spooka /* Other functions
945f7e80a8Spooka  */
955f7e80a8Spooka extern paddr_t kvtophys(vaddr_t);
965f7e80a8Spooka static void icapstart(struct icap_softc *sc);
975f7e80a8Spooka static int  icap_ebus_intr(void *cookie, void *f);
985f7e80a8Spooka static void icap_reset(struct icap_softc *sc);
995f7e80a8Spooka 
1005f7e80a8Spooka /* Config stuff
1015f7e80a8Spooka  */
1025f7e80a8Spooka extern struct cfdriver icap_cd;
1035f7e80a8Spooka 
1045f7e80a8Spooka CFATTACH_DECL_NEW(icap_ebus, sizeof (struct icap_softc),
1055f7e80a8Spooka     icap_ebus_match, icap_ebus_attach, NULL, NULL);
1065f7e80a8Spooka 
1075f7e80a8Spooka static int
icap_ebus_match(device_t parent,cfdata_t match,void * aux)108cbab9cadSchs icap_ebus_match(device_t parent, cfdata_t match, void *aux)
1095f7e80a8Spooka {
1105f7e80a8Spooka 	struct ebus_attach_args *ia = aux;
1115f7e80a8Spooka     struct _Icap *f = (struct _Icap *)ia->ia_vaddr;
1125f7e80a8Spooka 
1135f7e80a8Spooka 	DEBUG_PRINT(("icap_match %x\n", (f) ? f->Tag : 0), DEBUG_PROBE);
1145f7e80a8Spooka 	if (strcmp("icap", ia->ia_name) != 0)
1155f7e80a8Spooka 		return (0);
1165f7e80a8Spooka     if ((f == NULL) ||
1175f7e80a8Spooka         (! (f->Tag == PMTTAG_ICAP)))
1185f7e80a8Spooka 		return (0);
1195f7e80a8Spooka 
1205f7e80a8Spooka 	return (1);
1215f7e80a8Spooka }
1225f7e80a8Spooka 
1235f7e80a8Spooka static void
icap_ebus_attach(device_t parent,device_t self,void * aux)124cbab9cadSchs icap_ebus_attach(device_t parent, device_t self, void *aux)
1255f7e80a8Spooka {
1265f7e80a8Spooka 	struct icap_softc *sc = device_private(self);
1275f7e80a8Spooka 	struct ebus_attach_args *ia =aux;
1285f7e80a8Spooka 
1295f7e80a8Spooka 	DEBUG_PRINT(("icap_attach %p\n", sc), DEBUG_PROBE);
1305f7e80a8Spooka 
1315f7e80a8Spooka 	sc->sc_dev = self;
1325f7e80a8Spooka 	sc->sc_dp = (struct _Icap*)ia->ia_vaddr;
1335f7e80a8Spooka 	bufq_alloc(&sc->sc_buflist, "fcfs", 0);
1345f7e80a8Spooka 	sc->sc_bp = NULL;
1355f7e80a8Spooka 	sc->sc_data = NULL;
1365f7e80a8Spooka 	sc->sc_count = 0;
1375f7e80a8Spooka 
1385f7e80a8Spooka #if DEBUG
1395f7e80a8Spooka     printf(" virt=%p", (void*)sc->sc_dp);
1405f7e80a8Spooka #endif
1415f7e80a8Spooka 	printf(": %s\n", "Internal Configuration Access Port");
1425f7e80a8Spooka 
1435f7e80a8Spooka 	ebus_intr_establish(parent, (void*)ia->ia_cookie, IPL_BIO,
1445f7e80a8Spooka 	    icap_ebus_intr, sc);
1455f7e80a8Spooka 
1465f7e80a8Spooka 	icap_reset(sc);
1475f7e80a8Spooka }
1485f7e80a8Spooka 
1495f7e80a8Spooka /* The character device handlers
1505f7e80a8Spooka  */
1515f7e80a8Spooka const struct cdevsw icap_cdevsw = {
152a68f9396Sdholland 	.d_open = icapopen,
153a68f9396Sdholland 	.d_close = icapclose,
154a68f9396Sdholland 	.d_read = icapread,
155a68f9396Sdholland 	.d_write = icapwrite,
156a68f9396Sdholland 	.d_ioctl = icapioctl,
157a68f9396Sdholland 	.d_stop = nostop,
158a68f9396Sdholland 	.d_tty = notty,
159a68f9396Sdholland 	.d_poll = nopoll,
160a68f9396Sdholland 	.d_mmap = nommap,
161a68f9396Sdholland 	.d_kqfilter = nokqfilter,
162f9228f42Sdholland 	.d_discard = nodiscard,
163a68f9396Sdholland 	.d_flag = 0
1645f7e80a8Spooka };
1655f7e80a8Spooka 
1665f7e80a8Spooka /*
1675f7e80a8Spooka  * Handle an open request on the device.
1685f7e80a8Spooka  */
1695f7e80a8Spooka static int
icapopen(dev_t device,int flags,int fmt,struct lwp * process)1705f7e80a8Spooka icapopen(dev_t device, int flags, int fmt, struct lwp *process)
1715f7e80a8Spooka {
1725f7e80a8Spooka 	struct icap_softc *sc;
1735f7e80a8Spooka 
1745f7e80a8Spooka 	DEBUG_PRINT(("icapopen\n"), DEBUG_FUNCS);
1755f7e80a8Spooka 	sc = device_lookup_private(&icap_cd, minor(device));
1765f7e80a8Spooka 	if (sc == NULL)
1775f7e80a8Spooka 		return (ENXIO);
1785f7e80a8Spooka 
1795f7e80a8Spooka 	return 0;
1805f7e80a8Spooka }
1815f7e80a8Spooka 
1825f7e80a8Spooka /*
1835f7e80a8Spooka  * Handle the close request for the device.
1845f7e80a8Spooka  */
1855f7e80a8Spooka static int
icapclose(dev_t device,int flags,int fmt,struct lwp * process)1865f7e80a8Spooka icapclose(dev_t device, int flags, int fmt, struct lwp *process)
1875f7e80a8Spooka {
1885f7e80a8Spooka 	DEBUG_PRINT(("icapclose\n"), DEBUG_FUNCS);
1895f7e80a8Spooka 	return 0; /* this always succeeds */
1905f7e80a8Spooka }
1915f7e80a8Spooka 
1925f7e80a8Spooka /*
1935f7e80a8Spooka  * Handle the read request for the device.
1945f7e80a8Spooka  */
1955f7e80a8Spooka static int
icapread(dev_t dev,struct uio * uio,int flags)1965f7e80a8Spooka icapread(dev_t dev, struct uio *uio, int flags)
1975f7e80a8Spooka {
1985f7e80a8Spooka 	DEBUG_PRINT(("icapread\n"), DEBUG_READS);
1995f7e80a8Spooka 	return (physio(icapstrategy, NULL, dev, B_READ, minphys, uio));
2005f7e80a8Spooka }
2015f7e80a8Spooka 
2025f7e80a8Spooka /*
2035f7e80a8Spooka  * Handle the write request for the device.
2045f7e80a8Spooka  */
2055f7e80a8Spooka static int
icapwrite(dev_t dev,struct uio * uio,int flags)2065f7e80a8Spooka icapwrite(dev_t dev, struct uio *uio, int flags)
2075f7e80a8Spooka {
2085f7e80a8Spooka 	DEBUG_PRINT(("icapwrite\n"), DEBUG_WRITES);
2095f7e80a8Spooka 	return (physio(icapstrategy, NULL, dev, B_WRITE, minphys, uio));
2105f7e80a8Spooka }
2115f7e80a8Spooka 
2125f7e80a8Spooka /*
2135f7e80a8Spooka  * Handle the ioctl request for the device.
2145f7e80a8Spooka  */
2155f7e80a8Spooka static int
icapioctl(dev_t dev,u_long xfer,void * addr,int flag,struct lwp * l)2165f7e80a8Spooka icapioctl(dev_t dev, u_long xfer, void *addr, int flag, struct lwp *l)
2175f7e80a8Spooka {
2185f7e80a8Spooka 
2195f7e80a8Spooka 	return ENOTTY;
2205f7e80a8Spooka }
2215f7e80a8Spooka 
2225f7e80a8Spooka /*
2235f7e80a8Spooka  * Strategy function for the device.
2245f7e80a8Spooka  */
2255f7e80a8Spooka static void
icapstrategy(struct buf * bp)2265f7e80a8Spooka icapstrategy(struct buf *bp)
2275f7e80a8Spooka {
2285f7e80a8Spooka 	struct icap_softc *sc;
2295f7e80a8Spooka 	int s;
2305f7e80a8Spooka 
2315f7e80a8Spooka 	DEBUG_PRINT(("icapstrategy\n"), DEBUG_FUNCS);
2325f7e80a8Spooka 
2335f7e80a8Spooka 	/* We did nothing lest we did */
2345f7e80a8Spooka 	bp->b_resid = bp->b_bcount;
2355f7e80a8Spooka 
2365f7e80a8Spooka 	/* Do we know you.  */
2375f7e80a8Spooka 	sc = device_lookup_private(&icap_cd, minor(bp->b_dev));
2385f7e80a8Spooka 	if (sc == NULL) {
239c69eb063Stsutsui 		DEBUG_PRINT(("icapstrategy: nodev %" PRIx64 "\n",bp->b_dev),
2405f7e80a8Spooka 		    DEBUG_ERRORS);
2415f7e80a8Spooka 		bp->b_error = ENXIO;
2425f7e80a8Spooka 		biodone(bp);
2435f7e80a8Spooka 		return;
2445f7e80a8Spooka 	    }
2455f7e80a8Spooka 
2465f7e80a8Spooka 	/* Add to Q. If Q was empty get it started */
2475f7e80a8Spooka 	s = splbio();
2485f7e80a8Spooka 	bufq_put(sc->sc_buflist, bp);
2495f7e80a8Spooka 	if (bufq_peek(sc->sc_buflist) == bp) {
2505f7e80a8Spooka 		icapstart(sc);
2515f7e80a8Spooka 	}
2525f7e80a8Spooka 	splx(s);
2535f7e80a8Spooka }
2545f7e80a8Spooka 
2555f7e80a8Spooka /*
2565f7e80a8Spooka  * Get the next I/O request started
2575f7e80a8Spooka  */
2585f7e80a8Spooka static void
icapstart(struct icap_softc * sc)2595f7e80a8Spooka icapstart(struct icap_softc *sc)
2605f7e80a8Spooka {
2615f7e80a8Spooka 	paddr_t phys, phys2;
2625f7e80a8Spooka 	vaddr_t virt;
2635f7e80a8Spooka 	size_t count;
2645f7e80a8Spooka 	uint32_t fl;
2655f7e80a8Spooka 	struct buf *bp = sc->sc_bp;
2665f7e80a8Spooka 
2675f7e80a8Spooka 	DEBUG_PRINT(("icapstart %p %p\n",sc,bp), DEBUG_FUNCS);
2685f7e80a8Spooka 
2695f7e80a8Spooka     /* Were we idle?
2705f7e80a8Spooka      */
2715f7e80a8Spooka  recheck:
2725f7e80a8Spooka     if (bp == NULL) {
2735f7e80a8Spooka 
2745f7e80a8Spooka         /* Yes, get the next request if any
2755f7e80a8Spooka          */
2765f7e80a8Spooka         bp = bufq_get(sc->sc_buflist);
2775f7e80a8Spooka         DEBUG_PRINT(("icapnext: %p\n",bp), DEBUG_XFERS);
2785f7e80a8Spooka         if (bp == NULL)
2795f7e80a8Spooka             return;
2805f7e80a8Spooka     }
2815f7e80a8Spooka 
2825f7e80a8Spooka     /* Done with this request?
2835f7e80a8Spooka      */
2845f7e80a8Spooka     if ((bp->b_resid == 0) || bp->b_error) {
2855f7e80a8Spooka 
2865f7e80a8Spooka         /* Yes, complete and move to next, if any
2875f7e80a8Spooka          */
2885f7e80a8Spooka         sc->sc_bp = NULL;
2895f7e80a8Spooka         biodone(bp);
2905f7e80a8Spooka         DEBUG_PRINT(("icapdone %p\n",bp), DEBUG_XFERS);
2915f7e80a8Spooka         bp = NULL;
2925f7e80a8Spooka         goto recheck;
2935f7e80a8Spooka     }
2945f7e80a8Spooka 
2955f7e80a8Spooka     /* If new request init the xfer info
2965f7e80a8Spooka      */
2975f7e80a8Spooka     if (sc->sc_bp == NULL) {
2985f7e80a8Spooka         sc->sc_bp = bp;
2995f7e80a8Spooka         sc->sc_data = bp->b_data;
3005f7e80a8Spooka         sc->sc_count = bp->b_resid;
3015f7e80a8Spooka     }
3025f7e80a8Spooka 
3035f7e80a8Spooka     /* Loop filling as many buffers as will fit in the FIFO
3045f7e80a8Spooka      */
3055f7e80a8Spooka     fl = (bp->b_flags & B_READ) ? ICAPS_F_RECV : ICAPS_F_XMIT;
3065f7e80a8Spooka     for (;;) {
3075f7e80a8Spooka 
3085f7e80a8Spooka         /* Make sure there's still room in the FIFO, no errors.
3095f7e80a8Spooka          */
3105f7e80a8Spooka         if (sc->sc_dp->Control & (ICAPC_IF_FULL|ICAPC_ERROR))
3115f7e80a8Spooka             break;
3125f7e80a8Spooka 
3135f7e80a8Spooka         /* How much data do we xfer and where
3145f7e80a8Spooka          */
3155f7e80a8Spooka         virt = (vaddr_t)sc->sc_data;
3165f7e80a8Spooka         phys = kvtophys(virt);
3175f7e80a8Spooka         count = round_page(virt) - virt;
3185f7e80a8Spooka         if (count == 0) count = PAGE_SIZE;/* could(will) be aligned */
3195f7e80a8Spooka 
3205f7e80a8Spooka         /* How much of it is contiguous
3215f7e80a8Spooka          */
3225f7e80a8Spooka         while (count < sc->sc_count) {
3235f7e80a8Spooka             phys2 = kvtophys(virt + count);
3245f7e80a8Spooka             if (phys2 != (phys + count)) {
3255f7e80a8Spooka 
3265f7e80a8Spooka                 /* No longer contig, ship it
3275f7e80a8Spooka                  */
3285f7e80a8Spooka                 break;
3295f7e80a8Spooka             }
3305f7e80a8Spooka             count += PAGE_SIZE;
3315f7e80a8Spooka         }
3325f7e80a8Spooka 
3335f7e80a8Spooka         /* Trim if we went too far
3345f7e80a8Spooka          */
3355f7e80a8Spooka         if (count > sc->sc_count)
3365f7e80a8Spooka             count = sc->sc_count;
3375f7e80a8Spooka 
3385f7e80a8Spooka         /* Ship it
3395f7e80a8Spooka          */
340c69eb063Stsutsui         DEBUG_PRINT(("icapship %" PRIxPADDR " %d\n",phys,count), DEBUG_XFERS);
3415f7e80a8Spooka         sc->sc_dp->SizeAndFlags = fl | count;
3425f7e80a8Spooka         sc->sc_dp->BufferAddressHi32 = 0; /* BUGBUG 64bit */
3435f7e80a8Spooka         sc->sc_dp->BufferAddressLo32 = phys; /* this pushes the fifo */
3445f7e80a8Spooka 
3455f7e80a8Spooka         /* Adjust pointers and continue
3465f7e80a8Spooka          */
3475f7e80a8Spooka         sc->sc_data  += count;
3485f7e80a8Spooka         sc->sc_count -= count;
3495f7e80a8Spooka 
3505f7e80a8Spooka         if (sc->sc_count <= 0)
3515f7e80a8Spooka             break;
3525f7e80a8Spooka     }
3535f7e80a8Spooka }
3545f7e80a8Spooka 
3555f7e80a8Spooka /*
3565f7e80a8Spooka  * Interrupt handler
3575f7e80a8Spooka  */
3585f7e80a8Spooka static int
icap_ebus_intr(void * cookie,void * f)3595f7e80a8Spooka icap_ebus_intr(void *cookie, void *f)
3605f7e80a8Spooka {
3615f7e80a8Spooka 	struct icap_softc *sc = cookie;
3625f7e80a8Spooka     struct buf *bp = sc->sc_bp;
3635f7e80a8Spooka 	u_int32_t isr, saf = 0, hi, lo;
3645f7e80a8Spooka 
3655f7e80a8Spooka 	isr = sc->sc_dp->Control;
3665f7e80a8Spooka 
3675f7e80a8Spooka 	DEBUG_PRINT(("i %x\n",isr), DEBUG_INTR);
3685f7e80a8Spooka 
3695f7e80a8Spooka     /* Make sure there is an interrupt and that we should take it
3705f7e80a8Spooka      */
3715f7e80a8Spooka 	if ((isr & (ICAPC_INTEN|ICAPC_DONE)) != (ICAPC_INTEN|ICAPC_DONE))
3725f7e80a8Spooka 		return (0);
3735f7e80a8Spooka 
3745f7e80a8Spooka     /* Pull out all completed buffers
3755f7e80a8Spooka      */
3765f7e80a8Spooka     while ((isr & ICAPC_OF_EMPTY) == 0) {
3775f7e80a8Spooka 
3785f7e80a8Spooka         if (isr & ICAPC_ERROR) {
3795f7e80a8Spooka             printf("%s: internal error (%x)\n", device_xname(sc->sc_dev),isr);
3805f7e80a8Spooka             icap_reset(sc);
3815f7e80a8Spooka             if (bp) {
3825f7e80a8Spooka                 bp->b_error = EIO;
3835f7e80a8Spooka                 icapstart(sc);
3845f7e80a8Spooka             }
3855f7e80a8Spooka             return (1);
3865f7e80a8Spooka         }
3875f7e80a8Spooka 
3885f7e80a8Spooka         /* Beware, order matters */
3895f7e80a8Spooka         saf = sc->sc_dp->SizeAndFlags;
3905f7e80a8Spooka         hi  = sc->sc_dp->BufferAddressHi32; /* BUGBUG 64bit */
3915f7e80a8Spooka         lo  = sc->sc_dp->BufferAddressLo32; /* this pops the fifo */
3920101d11cSchristos 	__USE(hi);
3930101d11cSchristos 	__USE(lo);
3945f7e80a8Spooka 
3955f7e80a8Spooka         /* Say its done that much (and sanity)
3965f7e80a8Spooka          */
3975f7e80a8Spooka         if (bp) {
3985f7e80a8Spooka             size_t count = saf & ICAPS_S_MASK;
3995f7e80a8Spooka             /* more sanity */
4005f7e80a8Spooka             if (count > bp->b_resid)
4015f7e80a8Spooka                 count = bp->b_resid;
4025f7e80a8Spooka             bp->b_resid -= count;
4035f7e80a8Spooka         }
4045f7e80a8Spooka 
4055f7e80a8Spooka         /* More? */
4065f7e80a8Spooka         isr = sc->sc_dp->Control;
4075f7e80a8Spooka     }
4085f7e80a8Spooka 
4095f7e80a8Spooka     /* Did we pop at least one */
4105f7e80a8Spooka     if (saf)
4115f7e80a8Spooka         icapstart(sc);
4125f7e80a8Spooka 
4135f7e80a8Spooka     return (1);
4145f7e80a8Spooka }
4155f7e80a8Spooka 
4165f7e80a8Spooka /*
4175f7e80a8Spooka  * HW (re)Initialization
4185f7e80a8Spooka  */
4195f7e80a8Spooka static void
icap_reset(struct icap_softc * sc)4205f7e80a8Spooka icap_reset(struct icap_softc *sc)
4215f7e80a8Spooka {
4225f7e80a8Spooka 	DEBUG_PRINT(("icap_reset %x\n",sc->sc_dp->Control), DEBUG_STATUS);
4235f7e80a8Spooka     sc->sc_dp->Control = ICAPC_RESET;
4245f7e80a8Spooka     DELAY(2);
4255f7e80a8Spooka     sc->sc_dp->Control = ICAPC_INTEN;
4265f7e80a8Spooka }
427