ncr.c revision 1.21 1 /* $NetBSD: ncr.c,v 1.21 1999/08/27 17:49:42 ragge Exp $ */
2
3 /*-
4 * Copyright (c) 1996 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Adam Glass, David Jones, Gordon W. Ross, and Jens A. Nilsson.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 /*
40 * This file contains the machine-dependent parts of the NCR-5380
41 * controller. The machine-independent parts are in ncr5380sbc.c.
42 *
43 * Note: Only PIO transfers for now which implicates very bad
44 * performance. DMA support will come soon.
45 *
46 * Jens A. Nilsson.
47 *
48 * Credits:
49 *
50 * This code is based on arch/sun3/dev/si*
51 * Written by David Jones, Gordon Ross, and Adam Glass.
52 */
53
54 #include <sys/param.h>
55 #include <sys/systm.h>
56 #include <sys/errno.h>
57 #include <sys/kernel.h>
58 #include <sys/malloc.h>
59 #include <sys/device.h>
60 #include <sys/buf.h>
61 #include <sys/proc.h>
62 #include <sys/user.h>
63
64 #include <dev/scsipi/scsi_all.h>
65 #include <dev/scsipi/scsipi_all.h>
66 #include <dev/scsipi/scsipi_debug.h>
67 #include <dev/scsipi/scsiconf.h>
68
69 #include <dev/ic/ncr5380reg.h>
70 #include <dev/ic/ncr5380var.h>
71
72 #include <machine/vsbus.h>
73 #include <machine/bus.h>
74 #include <machine/sid.h>
75
76 #include "ioconf.h"
77
78 #define MIN_DMA_LEN 128
79
80 #ifdef notyet
81 struct si_dma_handle {
82 int dh_flags;
83 #define SIDH_BUSY 1
84 #define SIDH_OUT 2
85 u_char *dh_addr;
86 };
87 #endif
88
89 struct si_softc {
90 struct ncr5380_softc ncr_sc;
91 caddr_t sca_regs;
92 };
93
94 /* This is copied from julian's bt driver */
95 /* "so we have a default dev struct for our link struct." */
96 static struct scsipi_device si_dev = {
97 NULL, /* Use default error handler. */
98 NULL, /* Use default start handler. */
99 NULL, /* Use default async handler. */
100 NULL, /* Use default "done" routine. */
101 };
102
103 static int si_match(struct device *, struct cfdata *, void *);
104 static void si_attach(struct device *, struct device *, void *);
105 static void si_minphys(struct buf *);
106 static void si_intr(int);
107 void dk_establish(void);
108
109 struct cfattach ncr_ca = {
110 sizeof(struct si_softc), si_match, si_attach
111 };
112
113 void
114 dk_establish(void)
115 {
116 #if 0
117 printf("faking dk_establish()...\n");
118 #endif
119 }
120
121 static int
122 si_match(parent, cf, aux)
123 struct device *parent;
124 struct cfdata *cf;
125 void *aux;
126 {
127 struct vsbus_attach_args *va = aux;
128 volatile char *si_csr = (char *) va->va_addr;
129
130 if (vax_boardtype == VAX_BTYP_49)
131 return 0;
132 /* This is the way Linux autoprobes the interrupt MK-990321 */
133 si_csr[12] = 0;
134 si_csr[16] = 0x80;
135 si_csr[0] = 0x80;
136 si_csr[4] = 5; /* 0xcf */
137 DELAY(100000);
138 va->va_ivec = si_intr;
139 return 1;
140 }
141
142 static void
143 si_attach(parent, self, aux)
144 struct device *parent, *self;
145 void *aux;
146 {
147 struct vsbus_attach_args *va = aux;
148 struct si_softc *sc = (struct si_softc *) self;
149 struct ncr5380_softc *ncr_sc = &sc->ncr_sc;
150
151 printf("\n");
152 sc->sca_regs = (caddr_t)vax_map_physmem(va->va_paddr, 1);
153 /*
154 * MD function pointers used by the MI code.
155 */
156 ncr_sc->sc_pio_out = ncr5380_pio_out;
157 ncr_sc->sc_pio_in = ncr5380_pio_in;
158
159 #ifdef notyet
160 ncr_sc->sc_dma_alloc = si_dma_alloc;
161 ncr_sc->sc_dma_free = si_dma_free;
162 ncr_sc->sc_dma_setup = si_dma_setup;
163 ncr_sc->sc_dma_start = si_dma_start;
164 ncr_sc->sc_dma_poll = si_dma_poll;
165 ncr_sc->sc_dma_eop = si_dma_eop;
166 ncr_sc->sc_dma_stop = si_dma_stop;
167 #endif
168 ncr_sc->sc_intr_on = NULL /*si_intr_on*/;
169 ncr_sc->sc_intr_off = NULL /*si_intr_off*/;
170
171 ncr_sc->sc_dma_alloc = NULL;
172 ncr_sc->sc_min_dma_len = MIN_DMA_LEN;
173
174 /*
175 * Fill in the adapter.
176 */
177 ncr_sc->sc_adapter.scsipi_cmd = ncr5380_scsi_cmd;
178 ncr_sc->sc_adapter.scsipi_minphys = si_minphys;
179
180 /*
181 * Fill in the prototype scsi_link.
182 */
183 ncr_sc->sc_link.scsipi_scsi.channel = SCSI_CHANNEL_ONLY_ONE;
184 ncr_sc->sc_link.adapter_softc = sc;
185 ncr_sc->sc_link.scsipi_scsi.adapter_target = 7;
186 ncr_sc->sc_link.adapter = &ncr_sc->sc_adapter;
187 ncr_sc->sc_link.device = &si_dev;
188 ncr_sc->sc_link.type = BUS_SCSI;
189
190 /*
191 * Initialize fields used by the MI code.
192 */
193 ncr_sc->sci_r0 = sc->sca_regs; /* CUR_DATA/OUT_DATA (rw) */
194 ncr_sc->sci_r1 = sc->sca_regs + 4; /* INI_CMD (rw) */
195 ncr_sc->sci_r2 = sc->sca_regs + 8; /* MODE (rw) */
196 ncr_sc->sci_r3 = sc->sca_regs + 12; /* TAR_CMD (rw) */
197 ncr_sc->sci_r4 = sc->sca_regs + 16; /* CUR_STAT/SEL_ENA (rw) */
198 ncr_sc->sci_r5 = sc->sca_regs + 20; /* STATUS/DMA_SEND (rw) */
199 ncr_sc->sci_r6 = sc->sca_regs + 24; /* IN_DATA/DMA_TRCV (rw) */
200 ncr_sc->sci_r7 = sc->sca_regs + 28; /* RESET/DMA_IRCV (rw) */
201
202 ncr_sc->sc_no_disconnect = 0xff;
203 /*
204 * Initialize si board itself.
205 */
206 ncr5380_init(ncr_sc);
207 ncr5380_reset_scsibus(ncr_sc);
208
209 config_found(&(ncr_sc->sc_dev), &(ncr_sc->sc_link), scsiprint);
210 }
211
212 static void
213 si_minphys(struct buf *bp)
214 {
215 #if 0
216 printf("minphys: blkno=%d, bcount=%d, data=0x%x, flags=%x\n",
217 bp->b_blkno, (int) bp->b_bcount,
218 (unsigned) bp->b_data, (unsigned) bp->b_flags);
219 #endif
220 }
221
222 static void
223 si_intr(int arg)
224 {
225 ncr5380_intr(ncr_cd.cd_devs[arg]);
226 }
227
228