1*40f7eaafSjdolecek /* $NetBSD: bztzsc.c,v 1.38 2019/01/08 19:41:09 jdolecek Exp $ */
2af2691cdSis
3af2691cdSis /*
466e9e901Smhitch * Copyright (c) 1997 Michael L. Hitch
5af2691cdSis * Copyright (c) 1996 Ignatios Souvatzis
6af2691cdSis * Copyright (c) 1982, 1990 The Regents of the University of California.
7af2691cdSis * All rights reserved.
8af2691cdSis *
9af2691cdSis * Redistribution and use in source and binary forms, with or without
10af2691cdSis * modification, are permitted provided that the following conditions
11af2691cdSis * are met:
12af2691cdSis * 1. Redistributions of source code must retain the above copyright
13af2691cdSis * notice, this list of conditions and the following disclaimer.
14af2691cdSis * 2. Redistributions in binary form must reproduce the above copyright
15af2691cdSis * notice, this list of conditions and the following disclaimer in the
16af2691cdSis * documentation and/or other materials provided with the distribution.
17ac9f09c8Ssnj * 3. Neither the name of the University nor the names of its contributors
18af2691cdSis * may be used to endorse or promote products derived from this software
19af2691cdSis * without specific prior written permission.
20af2691cdSis *
21af2691cdSis * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22af2691cdSis * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23af2691cdSis * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24af2691cdSis * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25af2691cdSis * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26af2691cdSis * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27af2691cdSis * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28af2691cdSis * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29af2691cdSis * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30af2691cdSis * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31af2691cdSis * SUCH DAMAGE.
32af2691cdSis *
33af2691cdSis */
34af2691cdSis
3566e9e901Smhitch /*
3666e9e901Smhitch * Initial amiga Blizzard 2060 driver by Ingatios Souvatzis. Conversion to
3766e9e901Smhitch * 53c9x MI driver by Michael L. Hitch (mhitch@montana.edu).
3866e9e901Smhitch */
3966e9e901Smhitch
4023b820a8Sphx #ifdef __m68k__
41bd01b4a3Smrg #include "opt_m68k_arch.h"
4223b820a8Sphx #endif
43bd01b4a3Smrg
441ea4df81Saymeric #include <sys/cdefs.h>
45*40f7eaafSjdolecek __KERNEL_RCSID(0, "$NetBSD: bztzsc.c,v 1.38 2019/01/08 19:41:09 jdolecek Exp $");
461ea4df81Saymeric
4766e9e901Smhitch #include <sys/types.h>
48af2691cdSis #include <sys/param.h>
49af2691cdSis #include <sys/systm.h>
50af2691cdSis #include <sys/kernel.h>
5166e9e901Smhitch #include <sys/errno.h>
5266e9e901Smhitch #include <sys/ioctl.h>
53af2691cdSis #include <sys/device.h>
5466e9e901Smhitch #include <sys/buf.h>
5566e9e901Smhitch #include <sys/proc.h>
5666e9e901Smhitch #include <sys/queue.h>
5766e9e901Smhitch
586f3bab1fSbouyer #include <dev/scsipi/scsi_all.h>
596f3bab1fSbouyer #include <dev/scsipi/scsipi_all.h>
606f3bab1fSbouyer #include <dev/scsipi/scsiconf.h>
6166e9e901Smhitch #include <dev/scsipi/scsi_message.h>
6266e9e901Smhitch
6366e9e901Smhitch #include <machine/cpu.h>
6466e9e901Smhitch
6566e9e901Smhitch #include <dev/ic/ncr53c9xreg.h>
6666e9e901Smhitch #include <dev/ic/ncr53c9xvar.h>
6766e9e901Smhitch
68af2691cdSis #include <amiga/amiga/isr.h>
69af2691cdSis #include <amiga/dev/bztzscvar.h>
7066e9e901Smhitch #include <amiga/dev/zbusvar.h>
71af2691cdSis
721ee8b50fSis #ifdef __powerpc__
731ee8b50fSis #define badaddr(a) badaddr_read(a, 2, NULL)
741ee8b50fSis #endif
751ee8b50fSis
7678a1d236Stsutsui int bztzscmatch(device_t, cfdata_t, void *);
7778a1d236Stsutsui void bztzscattach(device_t, device_t, void *);
78af2691cdSis
7966e9e901Smhitch /* Linkup to the rest of the kernel */
8078a1d236Stsutsui CFATTACH_DECL_NEW(bztzsc, sizeof(struct bztzsc_softc),
81c5e91d44Sthorpej bztzscmatch, bztzscattach, NULL, NULL);
82af2691cdSis
83af2691cdSis /*
8466e9e901Smhitch * Functions and the switch for the MI code.
8566e9e901Smhitch */
8678a1d236Stsutsui uint8_t bztzsc_read_reg(struct ncr53c9x_softc *, int);
8778a1d236Stsutsui void bztzsc_write_reg(struct ncr53c9x_softc *, int, uint8_t);
889382c873Saymeric int bztzsc_dma_isintr(struct ncr53c9x_softc *);
899382c873Saymeric void bztzsc_dma_reset(struct ncr53c9x_softc *);
909382c873Saymeric int bztzsc_dma_intr(struct ncr53c9x_softc *);
9178a1d236Stsutsui int bztzsc_dma_setup(struct ncr53c9x_softc *, uint8_t **,
929382c873Saymeric size_t *, int, size_t *);
939382c873Saymeric void bztzsc_dma_go(struct ncr53c9x_softc *);
949382c873Saymeric void bztzsc_dma_stop(struct ncr53c9x_softc *);
959382c873Saymeric int bztzsc_dma_isactive(struct ncr53c9x_softc *);
9666e9e901Smhitch
9766e9e901Smhitch struct ncr53c9x_glue bztzsc_glue = {
9866e9e901Smhitch bztzsc_read_reg,
9966e9e901Smhitch bztzsc_write_reg,
10066e9e901Smhitch bztzsc_dma_isintr,
10166e9e901Smhitch bztzsc_dma_reset,
10266e9e901Smhitch bztzsc_dma_intr,
10366e9e901Smhitch bztzsc_dma_setup,
10466e9e901Smhitch bztzsc_dma_go,
10566e9e901Smhitch bztzsc_dma_stop,
10666e9e901Smhitch bztzsc_dma_isactive,
10778a1d236Stsutsui NULL,
10866e9e901Smhitch };
10966e9e901Smhitch
11066e9e901Smhitch /* Maximum DMA transfer length to reduce impact on high-speed serial input */
11166e9e901Smhitch u_long bztzsc_max_dma = 1024;
11266e9e901Smhitch extern int ser_open_speed;
11366e9e901Smhitch
11466e9e901Smhitch u_long bztzsc_cnt_pio = 0; /* number of PIO transfers */
11566e9e901Smhitch u_long bztzsc_cnt_dma = 0; /* number of DMA transfers */
11666e9e901Smhitch u_long bztzsc_cnt_dma2 = 0; /* number of DMA transfers broken up */
11766e9e901Smhitch u_long bztzsc_cnt_dma3 = 0; /* number of pages combined */
11866e9e901Smhitch
11966e9e901Smhitch #ifdef DEBUG
12066e9e901Smhitch struct {
12178a1d236Stsutsui uint8_t hardbits;
12278a1d236Stsutsui uint8_t status;
12378a1d236Stsutsui uint8_t xx;
12478a1d236Stsutsui uint8_t yy;
12566e9e901Smhitch } bztzsc_trace[128];
12666e9e901Smhitch int bztzsc_trace_ptr = 0;
12766e9e901Smhitch int bztzsc_trace_enable = 1;
1289382c873Saymeric void bztzsc_dump(void);
12966e9e901Smhitch #endif
13066e9e901Smhitch
13166e9e901Smhitch /*
13266e9e901Smhitch * if we are a Phase5 Blizzard 2060 SCSI
133af2691cdSis */
134af2691cdSis int
bztzscmatch(device_t parent,cfdata_t cf,void * aux)13578a1d236Stsutsui bztzscmatch(device_t parent, cfdata_t cf, void *aux)
136af2691cdSis {
137af2691cdSis struct zbus_args *zap;
13878a1d236Stsutsui volatile uint8_t *regs;
139af2691cdSis
14066e9e901Smhitch zap = aux;
1419bec32eeSmhitch if (zap->manid != 0x2140 || zap->prodid != 24)
14278a1d236Stsutsui return 0;
14378a1d236Stsutsui regs = &((volatile uint8_t *)zap->va)[0x1ff00];
14453524e44Schristos if (badaddr((void *)__UNVOLATILE(regs)))
14578a1d236Stsutsui return 0;
14666e9e901Smhitch regs[NCR_CFG1 * 4] = 0;
14766e9e901Smhitch regs[NCR_CFG1 * 4] = NCRCFG1_PARENB | 7;
14866e9e901Smhitch delay(5);
14966e9e901Smhitch if (regs[NCR_CFG1 * 4] != (NCRCFG1_PARENB | 7))
15078a1d236Stsutsui return 0;
15178a1d236Stsutsui return 1;
15266e9e901Smhitch }
153af2691cdSis
15466e9e901Smhitch /*
15566e9e901Smhitch * Attach this instance, and then all the sub-devices
15666e9e901Smhitch */
15766e9e901Smhitch void
bztzscattach(device_t parent,device_t self,void * aux)15878a1d236Stsutsui bztzscattach(device_t parent, device_t self, void *aux)
15966e9e901Smhitch {
16078a1d236Stsutsui struct bztzsc_softc *bsc = device_private(self);
16166e9e901Smhitch struct ncr53c9x_softc *sc = &bsc->sc_ncr53c9x;
16266e9e901Smhitch struct zbus_args *zap;
16366e9e901Smhitch extern u_long scsi_nosync;
16466e9e901Smhitch extern int shift_nosync;
16566e9e901Smhitch extern int ncr53c9x_debug;
166af2691cdSis
16766e9e901Smhitch /*
16866e9e901Smhitch * Set up the glue for MI code early; we use some of it here.
16966e9e901Smhitch */
17078a1d236Stsutsui sc->sc_dev = self;
17166e9e901Smhitch sc->sc_glue = &bztzsc_glue;
17266e9e901Smhitch
17366e9e901Smhitch /*
17466e9e901Smhitch * Save the regs
17566e9e901Smhitch */
17666e9e901Smhitch zap = aux;
17778a1d236Stsutsui bsc->sc_reg = &((volatile uint8_t *)zap->va)[0x1ff00];
17866e9e901Smhitch bsc->sc_dmabase = &bsc->sc_reg[0xf0];
17966e9e901Smhitch
180a1f606d3Slukem sc->sc_freq = 40; /* Clocked at 40 MHz */
18166e9e901Smhitch
18278a1d236Stsutsui aprint_normal(": address %p", bsc->sc_reg);
18366e9e901Smhitch
18466e9e901Smhitch sc->sc_id = 7;
18566e9e901Smhitch
18666e9e901Smhitch /*
18766e9e901Smhitch * It is necessary to try to load the 2nd config register here,
18866e9e901Smhitch * to find out what rev the FAS chip is, else the ncr53c9x_reset
18966e9e901Smhitch * will not set up the defaults correctly.
19066e9e901Smhitch */
19166e9e901Smhitch sc->sc_cfg1 = sc->sc_id | NCRCFG1_PARENB;
19266e9e901Smhitch sc->sc_cfg2 = NCRCFG2_SCSI2 | NCRCFG2_FE;
19366e9e901Smhitch sc->sc_cfg3 = 0x08 /*FCLK*/ | NCRESPCFG3_FSCSI | NCRESPCFG3_CDB;
19466e9e901Smhitch sc->sc_rev = NCR_VARIANT_FAS216;
19566e9e901Smhitch
19666e9e901Smhitch /*
19766e9e901Smhitch * This is the value used to start sync negotiations
19866e9e901Smhitch * Note that the NCR register "SYNCTP" is programmed
19966e9e901Smhitch * in "clocks per byte", and has a minimum value of 4.
20066e9e901Smhitch * The SCSI period used in negotiation is one-fourth
20166e9e901Smhitch * of the time (in nanoseconds) needed to transfer one byte.
20266e9e901Smhitch * Since the chip's clock is given in MHz, we have the following
20366e9e901Smhitch * formula: 4 * period = (1000 / freq) * 4
20466e9e901Smhitch */
20566e9e901Smhitch sc->sc_minsync = 1000 / sc->sc_freq;
20666e9e901Smhitch
20766e9e901Smhitch /*
20866e9e901Smhitch * get flags from -I argument and set cf_flags.
20966e9e901Smhitch * NOTE: low 8 bits are to disable disconnect, and the next
21066e9e901Smhitch * 8 bits are to disable sync.
21166e9e901Smhitch */
21278a1d236Stsutsui device_cfdata(self)->cf_flags |= (scsi_nosync >> shift_nosync)
21366e9e901Smhitch & 0xffff;
21466e9e901Smhitch shift_nosync += 16;
21566e9e901Smhitch
21666e9e901Smhitch /* Use next 16 bits of -I argument to set ncr53c9x_debug flags */
21766e9e901Smhitch ncr53c9x_debug |= (scsi_nosync >> shift_nosync) & 0xffff;
21866e9e901Smhitch shift_nosync += 16;
21966e9e901Smhitch
22066e9e901Smhitch #if 1
22166e9e901Smhitch if (((scsi_nosync >> shift_nosync) & 0xff00) == 0xff00)
22266e9e901Smhitch sc->sc_minsync = 0;
22366e9e901Smhitch #endif
22466e9e901Smhitch
22566e9e901Smhitch /* Really no limit, but since we want to fit into the TCR... */
22666e9e901Smhitch sc->sc_maxxfer = 64 * 1024;
22766e9e901Smhitch
22866e9e901Smhitch bsc->sc_reg[0xe0] = BZTZSC_PB_LED; /* Turn LED off */
22966e9e901Smhitch
23066e9e901Smhitch /*
23166e9e901Smhitch * Configure interrupts.
23266e9e901Smhitch */
2338c4d1bf1Stsutsui bsc->sc_isr.isr_intr = ncr53c9x_intr;
23466e9e901Smhitch bsc->sc_isr.isr_arg = sc;
23566e9e901Smhitch bsc->sc_isr.isr_ipl = 2;
23666e9e901Smhitch add_isr(&bsc->sc_isr);
23766e9e901Smhitch
23866e9e901Smhitch /*
23966e9e901Smhitch * Now try to attach all the sub-devices
24066e9e901Smhitch */
241937a7a3eSbouyer sc->sc_adapter.adapt_request = ncr53c9x_scsipi_request;
242937a7a3eSbouyer sc->sc_adapter.adapt_minphys = minphys;
243937a7a3eSbouyer ncr53c9x_attach(sc);
24466e9e901Smhitch }
24566e9e901Smhitch
24666e9e901Smhitch /*
24766e9e901Smhitch * Glue functions.
24866e9e901Smhitch */
24966e9e901Smhitch
25078a1d236Stsutsui uint8_t
bztzsc_read_reg(struct ncr53c9x_softc * sc,int reg)2519382c873Saymeric bztzsc_read_reg(struct ncr53c9x_softc *sc, int reg)
25266e9e901Smhitch {
25366e9e901Smhitch struct bztzsc_softc *bsc = (struct bztzsc_softc *)sc;
25466e9e901Smhitch
25566e9e901Smhitch return bsc->sc_reg[reg * 4];
25666e9e901Smhitch }
25766e9e901Smhitch
25866e9e901Smhitch void
bztzsc_write_reg(struct ncr53c9x_softc * sc,int reg,uint8_t val)25978a1d236Stsutsui bztzsc_write_reg(struct ncr53c9x_softc *sc, int reg, uint8_t val)
26066e9e901Smhitch {
26166e9e901Smhitch struct bztzsc_softc *bsc = (struct bztzsc_softc *)sc;
26278a1d236Stsutsui uint8_t v = val;
26366e9e901Smhitch
26466e9e901Smhitch bsc->sc_reg[reg * 4] = v;
26566e9e901Smhitch #ifdef DEBUG
266e6c88a76Sthorpej if (bztzsc_trace_enable/* && sc->sc_nexus && sc->sc_nexus->xs->xs_control & XS_CTL_POLL*/ &&
26766e9e901Smhitch reg == NCR_CMD/* && bsc->sc_active*/) {
26866e9e901Smhitch bztzsc_trace[(bztzsc_trace_ptr - 1) & 127].yy = v;
26966e9e901Smhitch /* printf(" cmd %x", v);*/
27066e9e901Smhitch }
27166e9e901Smhitch #endif
27266e9e901Smhitch }
27366e9e901Smhitch
27466e9e901Smhitch int
bztzsc_dma_isintr(struct ncr53c9x_softc * sc)2759382c873Saymeric bztzsc_dma_isintr(struct ncr53c9x_softc *sc)
27666e9e901Smhitch {
27766e9e901Smhitch struct bztzsc_softc *bsc = (struct bztzsc_softc *)sc;
27866e9e901Smhitch
27966e9e901Smhitch if ((bsc->sc_reg[NCR_STAT * 4] & NCRSTAT_INT) == 0)
280af2691cdSis return 0;
281af2691cdSis
28266e9e901Smhitch if (sc->sc_state == NCR_CONNECTED)
28366e9e901Smhitch bsc->sc_reg[0xe0] = 0; /* Turn LED on */
28466e9e901Smhitch else
28566e9e901Smhitch bsc->sc_reg[0xe0] = BZTZSC_PB_LED; /* Turn LED off */
286af2691cdSis
28766e9e901Smhitch #ifdef DEBUG
288e6c88a76Sthorpej if (/*sc->sc_nexus && sc->sc_nexus->xs->xs_control & XS_CTL_POLL &&*/ bztzsc_trace_enable) {
28966e9e901Smhitch bztzsc_trace[bztzsc_trace_ptr].status = bsc->sc_reg[NCR_STAT * 4];
29066e9e901Smhitch bztzsc_trace[bztzsc_trace_ptr].xx = bsc->sc_reg[NCR_CMD * 4];
29166e9e901Smhitch bztzsc_trace[bztzsc_trace_ptr].yy = bsc->sc_active;
29266e9e901Smhitch bztzsc_trace_ptr = (bztzsc_trace_ptr + 1) & 127;
293af2691cdSis }
294af2691cdSis #endif
29566e9e901Smhitch return 1;
296af2691cdSis }
297af2691cdSis
298af2691cdSis void
bztzsc_dma_reset(struct ncr53c9x_softc * sc)2999382c873Saymeric bztzsc_dma_reset(struct ncr53c9x_softc *sc)
300af2691cdSis {
30166e9e901Smhitch struct bztzsc_softc *bsc = (struct bztzsc_softc *)sc;
302af2691cdSis
30366e9e901Smhitch bsc->sc_active = 0;
304af2691cdSis }
30566e9e901Smhitch
30666e9e901Smhitch int
bztzsc_dma_intr(struct ncr53c9x_softc * sc)3079382c873Saymeric bztzsc_dma_intr(struct ncr53c9x_softc *sc)
30866e9e901Smhitch {
30966e9e901Smhitch register struct bztzsc_softc *bsc = (struct bztzsc_softc *)sc;
31066e9e901Smhitch register int cnt;
31166e9e901Smhitch
31266e9e901Smhitch NCR_DMA(("bztzsc_dma_intr: cnt %d int %x stat %x fifo %d ",
31366e9e901Smhitch bsc->sc_dmasize, sc->sc_espintr, sc->sc_espstat,
31466e9e901Smhitch bsc->sc_reg[NCR_FFLAG * 4] & NCRFIFO_FF));
31566e9e901Smhitch if (bsc->sc_active == 0) {
31666e9e901Smhitch printf("bztzsc_intr--inactive DMA\n");
31766e9e901Smhitch return -1;
31866e9e901Smhitch }
31966e9e901Smhitch
32066e9e901Smhitch /* update sc_dmaaddr and sc_pdmalen */
32166e9e901Smhitch cnt = bsc->sc_reg[NCR_TCL * 4];
32266e9e901Smhitch cnt += bsc->sc_reg[NCR_TCM * 4] << 8;
32366e9e901Smhitch cnt += bsc->sc_reg[NCR_TCH * 4] << 16;
32466e9e901Smhitch if (!bsc->sc_datain) {
32566e9e901Smhitch cnt += bsc->sc_reg[NCR_FFLAG * 4] & NCRFIFO_FF;
32666e9e901Smhitch bsc->sc_reg[NCR_CMD * 4] = NCRCMD_FLUSH;
32766e9e901Smhitch }
32866e9e901Smhitch cnt = bsc->sc_dmasize - cnt; /* number of bytes transferred */
32966e9e901Smhitch NCR_DMA(("DMA xferred %d\n", cnt));
33066e9e901Smhitch if (bsc->sc_xfr_align) {
33178a1d236Stsutsui memcpy(*bsc->sc_dmaaddr, bsc->sc_alignbuf, cnt);
33266e9e901Smhitch bsc->sc_xfr_align = 0;
33366e9e901Smhitch }
33466e9e901Smhitch *bsc->sc_dmaaddr += cnt;
33566e9e901Smhitch *bsc->sc_pdmalen -= cnt;
33666e9e901Smhitch bsc->sc_active = 0;
33766e9e901Smhitch return 0;
33866e9e901Smhitch }
33966e9e901Smhitch
34066e9e901Smhitch int
bztzsc_dma_setup(struct ncr53c9x_softc * sc,uint8_t ** addr,size_t * len,int datain,size_t * dmasize)34178a1d236Stsutsui bztzsc_dma_setup(struct ncr53c9x_softc *sc, uint8_t **addr, size_t *len,
3429382c873Saymeric int datain, size_t *dmasize)
34366e9e901Smhitch {
34466e9e901Smhitch struct bztzsc_softc *bsc = (struct bztzsc_softc *)sc;
345744246faSis paddr_t pa;
34678a1d236Stsutsui uint8_t *ptr;
34766e9e901Smhitch size_t xfer;
34866e9e901Smhitch
34978a1d236Stsutsui bsc->sc_dmaaddr = addr;
35066e9e901Smhitch bsc->sc_pdmalen = len;
35166e9e901Smhitch bsc->sc_datain = datain;
35266e9e901Smhitch bsc->sc_dmasize = *dmasize;
35366e9e901Smhitch /*
35466e9e901Smhitch * DMA can be nasty for high-speed serial input, so limit the
35566e9e901Smhitch * size of this DMA operation if the serial port is running at
35666e9e901Smhitch * a high speed (higher than 19200 for now - should be adjusted
357d20841bbSwiz * based on CPU type and speed?).
35866e9e901Smhitch * XXX - add serial speed check XXX
35966e9e901Smhitch */
36066e9e901Smhitch if (ser_open_speed > 19200 && bztzsc_max_dma != 0 &&
36166e9e901Smhitch bsc->sc_dmasize > bztzsc_max_dma)
36266e9e901Smhitch bsc->sc_dmasize = bztzsc_max_dma;
36366e9e901Smhitch ptr = *addr; /* Kernel virtual address */
36466e9e901Smhitch pa = kvtop(ptr); /* Physical address of DMA */
365d1579b2dSriastradh xfer = uimin(bsc->sc_dmasize, PAGE_SIZE - (pa & (PAGE_SIZE - 1)));
36666e9e901Smhitch bsc->sc_xfr_align = 0;
36766e9e901Smhitch /*
36866e9e901Smhitch * If output and unaligned, stuff odd byte into FIFO
36966e9e901Smhitch */
37066e9e901Smhitch if (datain == 0 && (int)ptr & 1) {
37166e9e901Smhitch NCR_DMA(("bztzsc_dma_setup: align byte written to fifo\n"));
37266e9e901Smhitch pa++;
37366e9e901Smhitch xfer--; /* XXXX CHECK THIS !!!! XXXX */
37466e9e901Smhitch bsc->sc_reg[NCR_FIFO * 4] = *ptr++;
37566e9e901Smhitch }
37666e9e901Smhitch /*
37766e9e901Smhitch * If unaligned address, read unaligned bytes into alignment buffer
37866e9e901Smhitch */
37966e9e901Smhitch else if ((int)ptr & 1) {
38053524e44Schristos pa = kvtop((void *)&bsc->sc_alignbuf);
381d1579b2dSriastradh xfer = bsc->sc_dmasize = uimin(xfer, sizeof(bsc->sc_alignbuf));
38266e9e901Smhitch NCR_DMA(("bztzsc_dma_setup: align read by %d bytes\n", xfer));
38366e9e901Smhitch bsc->sc_xfr_align = 1;
38466e9e901Smhitch }
38566e9e901Smhitch ++bztzsc_cnt_dma; /* number of DMA operations */
38666e9e901Smhitch
38766e9e901Smhitch while (xfer < bsc->sc_dmasize) {
38878a1d236Stsutsui if ((pa + xfer) != kvtop(*addr + xfer))
38966e9e901Smhitch break;
3908818afa4Sthorpej if ((bsc->sc_dmasize - xfer) < PAGE_SIZE)
39166e9e901Smhitch xfer = bsc->sc_dmasize;
39266e9e901Smhitch else
3938818afa4Sthorpej xfer += PAGE_SIZE;
39466e9e901Smhitch ++bztzsc_cnt_dma3;
39566e9e901Smhitch }
39666e9e901Smhitch if (xfer != *len)
39766e9e901Smhitch ++bztzsc_cnt_dma2;
39866e9e901Smhitch
39966e9e901Smhitch bsc->sc_dmasize = xfer;
40066e9e901Smhitch *dmasize = bsc->sc_dmasize;
40166e9e901Smhitch bsc->sc_pa = pa;
40266e9e901Smhitch #if defined(M68040) || defined(M68060)
40366e9e901Smhitch if (mmutype == MMU_68040) {
40466e9e901Smhitch if (bsc->sc_xfr_align) {
40566e9e901Smhitch dma_cachectl(bsc->sc_alignbuf,
40666e9e901Smhitch sizeof(bsc->sc_alignbuf));
40766e9e901Smhitch }
40866e9e901Smhitch else
40966e9e901Smhitch dma_cachectl(*bsc->sc_dmaaddr, bsc->sc_dmasize);
41066e9e901Smhitch }
41166e9e901Smhitch #endif
41266e9e901Smhitch
41366e9e901Smhitch pa >>= 1;
41466e9e901Smhitch if (!bsc->sc_datain)
41566e9e901Smhitch pa |= 0x80000000;
41678a1d236Stsutsui bsc->sc_dmabase[12] = (uint8_t)(pa);
41778a1d236Stsutsui bsc->sc_dmabase[8] = (uint8_t)(pa >> 8);
41878a1d236Stsutsui bsc->sc_dmabase[4] = (uint8_t)(pa >> 16);
41978a1d236Stsutsui bsc->sc_dmabase[0] = (uint8_t)(pa >> 24);
42066e9e901Smhitch bsc->sc_active = 1;
42166e9e901Smhitch return 0;
42266e9e901Smhitch }
42366e9e901Smhitch
42466e9e901Smhitch void
bztzsc_dma_go(struct ncr53c9x_softc * sc)4259382c873Saymeric bztzsc_dma_go(struct ncr53c9x_softc *sc)
42666e9e901Smhitch {
42766e9e901Smhitch }
42866e9e901Smhitch
42966e9e901Smhitch void
bztzsc_dma_stop(struct ncr53c9x_softc * sc)4309382c873Saymeric bztzsc_dma_stop(struct ncr53c9x_softc *sc)
43166e9e901Smhitch {
43266e9e901Smhitch }
43366e9e901Smhitch
43466e9e901Smhitch int
bztzsc_dma_isactive(struct ncr53c9x_softc * sc)4359382c873Saymeric bztzsc_dma_isactive(struct ncr53c9x_softc *sc)
43666e9e901Smhitch {
43766e9e901Smhitch struct bztzsc_softc *bsc = (struct bztzsc_softc *)sc;
43866e9e901Smhitch
43966e9e901Smhitch return bsc->sc_active;
44066e9e901Smhitch }
44166e9e901Smhitch
44266e9e901Smhitch #ifdef DEBUG
44366e9e901Smhitch void
bztzsc_dump(void)4449382c873Saymeric bztzsc_dump(void)
44566e9e901Smhitch {
44666e9e901Smhitch int i;
44766e9e901Smhitch
44866e9e901Smhitch i = bztzsc_trace_ptr;
44966e9e901Smhitch printf("bztzsc_trace dump: ptr %x\n", bztzsc_trace_ptr);
45066e9e901Smhitch do {
45166e9e901Smhitch if (bztzsc_trace[i].hardbits == 0) {
45266e9e901Smhitch i = (i + 1) & 127;
45366e9e901Smhitch continue;
45466e9e901Smhitch }
45566e9e901Smhitch printf("%02x%02x%02x%02x(", bztzsc_trace[i].hardbits,
45666e9e901Smhitch bztzsc_trace[i].status, bztzsc_trace[i].xx, bztzsc_trace[i].yy);
45766e9e901Smhitch if (bztzsc_trace[i].status & NCRSTAT_INT)
45866e9e901Smhitch printf("NCRINT/");
45966e9e901Smhitch if (bztzsc_trace[i].status & NCRSTAT_TC)
46066e9e901Smhitch printf("NCRTC/");
46166e9e901Smhitch switch(bztzsc_trace[i].status & NCRSTAT_PHASE) {
46266e9e901Smhitch case 0:
46366e9e901Smhitch printf("dataout"); break;
46466e9e901Smhitch case 1:
46566e9e901Smhitch printf("datain"); break;
46666e9e901Smhitch case 2:
46766e9e901Smhitch printf("cmdout"); break;
46866e9e901Smhitch case 3:
46966e9e901Smhitch printf("status"); break;
47066e9e901Smhitch case 6:
47166e9e901Smhitch printf("msgout"); break;
47266e9e901Smhitch case 7:
47366e9e901Smhitch printf("msgin"); break;
47466e9e901Smhitch default:
47566e9e901Smhitch printf("phase%d?", bztzsc_trace[i].status & NCRSTAT_PHASE);
47666e9e901Smhitch }
47766e9e901Smhitch printf(") ");
47866e9e901Smhitch i = (i + 1) & 127;
47966e9e901Smhitch } while (i != bztzsc_trace_ptr);
48066e9e901Smhitch printf("\n");
48166e9e901Smhitch }
48266e9e901Smhitch #endif
483