ncr.c revision 1.19 1 /* $NetBSD: ncr.c,v 1.19 1999/03/26 22:04:07 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 /* This is the way Linux autoprobes the interrupt MK-990321 */
130 si_csr[12] = 0;
131 si_csr[16] = 0x80;
132 si_csr[0] = 0x80;
133 si_csr[4] = 5; /* 0xcf */
134 DELAY(100000);
135 va->va_ivec = si_intr;
136 return 1;
137 }
138
139 static void
140 si_attach(parent, self, aux)
141 struct device *parent, *self;
142 void *aux;
143 {
144 struct vsbus_attach_args *va = aux;
145 struct si_softc *sc = (struct si_softc *) self;
146 struct ncr5380_softc *ncr_sc = &sc->ncr_sc;
147
148 printf("\n");
149 sc->sca_regs = (caddr_t)vax_map_physmem(va->va_paddr, 1);
150 /*
151 * MD function pointers used by the MI code.
152 */
153 ncr_sc->sc_pio_out = ncr5380_pio_out;
154 ncr_sc->sc_pio_in = ncr5380_pio_in;
155
156 #ifdef notyet
157 ncr_sc->sc_dma_alloc = si_dma_alloc;
158 ncr_sc->sc_dma_free = si_dma_free;
159 ncr_sc->sc_dma_setup = si_dma_setup;
160 ncr_sc->sc_dma_start = si_dma_start;
161 ncr_sc->sc_dma_poll = si_dma_poll;
162 ncr_sc->sc_dma_eop = si_dma_eop;
163 ncr_sc->sc_dma_stop = si_dma_stop;
164 #endif
165 ncr_sc->sc_intr_on = NULL /*si_intr_on*/;
166 ncr_sc->sc_intr_off = NULL /*si_intr_off*/;
167
168 ncr_sc->sc_dma_alloc = NULL;
169 ncr_sc->sc_min_dma_len = MIN_DMA_LEN;
170
171 /*
172 * Fill in the adapter.
173 */
174 ncr_sc->sc_adapter.scsipi_cmd = ncr5380_scsi_cmd;
175 ncr_sc->sc_adapter.scsipi_minphys = si_minphys;
176
177 /*
178 * Fill in the prototype scsi_link.
179 */
180 ncr_sc->sc_link.scsipi_scsi.channel = SCSI_CHANNEL_ONLY_ONE;
181 ncr_sc->sc_link.adapter_softc = sc;
182 ncr_sc->sc_link.scsipi_scsi.adapter_target = 7;
183 ncr_sc->sc_link.adapter = &ncr_sc->sc_adapter;
184 ncr_sc->sc_link.device = &si_dev;
185 ncr_sc->sc_link.type = BUS_SCSI;
186
187 /*
188 * Initialize fields used by the MI code.
189 */
190 ncr_sc->sci_r0 = sc->sca_regs; /* CUR_DATA/OUT_DATA (rw) */
191 ncr_sc->sci_r1 = sc->sca_regs + 4; /* INI_CMD (rw) */
192 ncr_sc->sci_r2 = sc->sca_regs + 8; /* MODE (rw) */
193 ncr_sc->sci_r3 = sc->sca_regs + 12; /* TAR_CMD (rw) */
194 ncr_sc->sci_r4 = sc->sca_regs + 16; /* CUR_STAT/SEL_ENA (rw) */
195 ncr_sc->sci_r5 = sc->sca_regs + 20; /* STATUS/DMA_SEND (rw) */
196 ncr_sc->sci_r6 = sc->sca_regs + 24; /* IN_DATA/DMA_TRCV (rw) */
197 ncr_sc->sci_r7 = sc->sca_regs + 28; /* RESET/DMA_IRCV (rw) */
198
199 /*
200 * Initialize si board itself.
201 */
202 ncr5380_init(ncr_sc);
203 ncr5380_reset_scsibus(ncr_sc);
204
205 config_found(&(ncr_sc->sc_dev), &(ncr_sc->sc_link), scsiprint);
206 }
207
208 static void
209 si_minphys(struct buf *bp)
210 {
211 #if 0
212 printf("minphys: blkno=%d, bcount=%d, data=0x%x, flags=%x\n",
213 bp->b_blkno, (int) bp->b_bcount,
214 (unsigned) bp->b_data, (unsigned) bp->b_flags);
215 #endif
216 }
217
218 static void
219 si_intr(int arg)
220 {
221 ncr5380_intr(ncr_cd.cd_devs[arg]);
222 }
223
224