ncr.c revision 1.18 1 /* $NetBSD: ncr.c,v 1.18 1999/03/13 15:16:48 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
75 #include "ioconf.h"
76
77 #define MIN_DMA_LEN 128
78
79 #ifdef notyet
80 struct si_dma_handle {
81 int dh_flags;
82 #define SIDH_BUSY 1
83 #define SIDH_OUT 2
84 u_char *dh_addr;
85 };
86 #endif
87
88 struct si_softc {
89 struct ncr5380_softc ncr_sc;
90 caddr_t sca_regs;
91 };
92
93 /* This is copied from julian's bt driver */
94 /* "so we have a default dev struct for our link struct." */
95 static struct scsipi_device si_dev = {
96 NULL, /* Use default error handler. */
97 NULL, /* Use default start handler. */
98 NULL, /* Use default async handler. */
99 NULL, /* Use default "done" routine. */
100 };
101
102 static int si_match(struct device *, struct cfdata *, void *);
103 static void si_attach(struct device *, struct device *, void *);
104 static void si_minphys(struct buf *);
105 static void si_intr(int);
106 void dk_establish(void);
107
108 struct cfattach ncr_ca = {
109 sizeof(struct si_softc), si_match, si_attach
110 };
111
112 void
113 dk_establish(void)
114 {
115 #if 0
116 printf("faking dk_establish()...\n");
117 #endif
118 }
119
120 static int
121 si_match(parent, cf, aux)
122 struct device *parent;
123 struct cfdata *cf;
124 void *aux;
125 {
126 struct vsbus_attach_args *va = aux;
127 volatile char *si_csr = (char *) va->va_addr;
128
129 si_csr[4] = 0xcf;
130 DELAY(100000);
131 va->va_ivec = si_intr;
132 return 1;
133 }
134
135 static void
136 si_attach(parent, self, aux)
137 struct device *parent, *self;
138 void *aux;
139 {
140 struct vsbus_attach_args *va = aux;
141 struct si_softc *sc = (struct si_softc *) self;
142 struct ncr5380_softc *ncr_sc = &sc->ncr_sc;
143
144 printf("\n");
145 sc->sca_regs = (caddr_t)vax_map_physmem(va->va_paddr, 1);
146 /*
147 * MD function pointers used by the MI code.
148 */
149 ncr_sc->sc_pio_out = ncr5380_pio_out;
150 ncr_sc->sc_pio_in = ncr5380_pio_in;
151
152 #ifdef notyet
153 ncr_sc->sc_dma_alloc = si_dma_alloc;
154 ncr_sc->sc_dma_free = si_dma_free;
155 ncr_sc->sc_dma_setup = si_dma_setup;
156 ncr_sc->sc_dma_start = si_dma_start;
157 ncr_sc->sc_dma_poll = si_dma_poll;
158 ncr_sc->sc_dma_eop = si_dma_eop;
159 ncr_sc->sc_dma_stop = si_dma_stop;
160 #endif
161 ncr_sc->sc_intr_on = NULL /*si_intr_on*/;
162 ncr_sc->sc_intr_off = NULL /*si_intr_off*/;
163
164 ncr_sc->sc_dma_alloc = NULL;
165 ncr_sc->sc_min_dma_len = MIN_DMA_LEN;
166
167 /*
168 * Fill in the adapter.
169 */
170 ncr_sc->sc_adapter.scsipi_cmd = ncr5380_scsi_cmd;
171 ncr_sc->sc_adapter.scsipi_minphys = si_minphys;
172
173 /*
174 * Fill in the prototype scsi_link.
175 */
176 ncr_sc->sc_link.scsipi_scsi.channel = SCSI_CHANNEL_ONLY_ONE;
177 ncr_sc->sc_link.adapter_softc = sc;
178 ncr_sc->sc_link.scsipi_scsi.adapter_target = 7;
179 ncr_sc->sc_link.adapter = &ncr_sc->sc_adapter;
180 ncr_sc->sc_link.device = &si_dev;
181 ncr_sc->sc_link.type = BUS_SCSI;
182
183 /*
184 * Initialize fields used by the MI code.
185 */
186 ncr_sc->sci_r0 = sc->sca_regs; /* CUR_DATA/OUT_DATA (rw) */
187 ncr_sc->sci_r1 = sc->sca_regs + 4; /* INI_CMD (rw) */
188 ncr_sc->sci_r2 = sc->sca_regs + 8; /* MODE (rw) */
189 ncr_sc->sci_r3 = sc->sca_regs + 12; /* TAR_CMD (rw) */
190 ncr_sc->sci_r4 = sc->sca_regs + 16; /* CUR_STAT/SEL_ENA (rw) */
191 ncr_sc->sci_r5 = sc->sca_regs + 20; /* STATUS/DMA_SEND (rw) */
192 ncr_sc->sci_r6 = sc->sca_regs + 24; /* IN_DATA/DMA_TRCV (rw) */
193 ncr_sc->sci_r7 = sc->sca_regs + 28; /* RESET/DMA_IRCV (rw) */
194
195 /*
196 * Initialize si board itself.
197 */
198 ncr5380_init(ncr_sc);
199 ncr5380_reset_scsibus(ncr_sc);
200
201 config_found(&(ncr_sc->sc_dev), &(ncr_sc->sc_link), scsiprint);
202 }
203
204 static void
205 si_minphys(struct buf *bp)
206 {
207 #if 0
208 printf("minphys: blkno=%d, bcount=%d, data=0x%x, flags=%x\n",
209 bp->b_blkno, (int) bp->b_bcount,
210 (unsigned) bp->b_data, (unsigned) bp->b_flags);
211 #endif
212 }
213
214 static void
215 si_intr(int arg)
216 {
217 ncr5380_intr(ncr_cd.cd_devs[arg]);
218 }
219
220