1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
|
/* $OpenBSD: hpcdma.c,v 1.1 2012/03/28 20:44:23 miod Exp $ */
/* $NetBSD: hpcdma.c,v 1.21 2011/07/01 18:53:46 dyoung Exp $ */
/*
* Copyright (c) 2001 Wayne Knowles
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Wayne Knowles
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Support for SCSI DMA provided by the HPC.
*
* Note: We use SCSI0 offsets, etc. here. Since the layout of SCSI0
* and SCSI1 are the same, this is no problem.
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <sys/buf.h>
#include <uvm/uvm_extern.h>
#include <machine/bus.h>
#include <sgi/hpc/hpcreg.h>
#include <sgi/hpc/hpcvar.h>
#include <sgi/hpc/hpcdma.h>
/*
* Allocate DMA Chain descriptor list
*/
void
hpcdma_init(struct hpc_attach_args *haa, struct hpc_dma_softc *sc, int ndesc)
{
bus_dma_segment_t seg;
int rseg, allocsz;
sc->sc_bst = haa->ha_st;
sc->sc_dmat = haa->ha_dmat;
sc->sc_ndesc = ndesc;
sc->sc_flags = 0;
if (bus_space_subregion(haa->ha_st, haa->ha_sh, haa->ha_dmaoff,
sc->hpc->scsi0_regs_size, &sc->sc_bsh) != 0) {
printf(": can't map DMA registers\n");
return;
}
/* Alloc 1 additional descriptor - needed for DMA bug fix */
allocsz = sizeof(struct hpc_dma_desc) * (ndesc + 1);
/*
* Allocate a block of memory for dma chaining pointers
*/
if (bus_dmamem_alloc(sc->sc_dmat, allocsz, 0, 0, &seg, 1, &rseg,
BUS_DMA_NOWAIT)) {
printf(": can't allocate sglist\n");
return;
}
/* Map pages into kernel memory */
if (bus_dmamem_map(sc->sc_dmat, &seg, rseg, allocsz,
(caddr_t *)&sc->sc_desc_kva, BUS_DMA_NOWAIT)) {
printf(": can't map sglist\n");
bus_dmamem_free(sc->sc_dmat, &seg, rseg);
return;
}
if (bus_dmamap_create(sc->sc_dmat, allocsz, 1 /*seg*/, allocsz, 0,
BUS_DMA_WAITOK, &sc->sc_dmamap) != 0) {
printf(": failed to create dmamap\n");
return;
}
if (bus_dmamap_load(sc->sc_dmat, sc->sc_dmamap,
sc->sc_desc_kva, allocsz, NULL, BUS_DMA_NOWAIT)) {
printf(": can't load sglist\n");
return;
}
sc->sc_desc_pa = sc->sc_dmamap->dm_segs[0].ds_addr;
}
void
hpcdma_sglist_create(struct hpc_dma_softc *sc, bus_dmamap_t dmamap)
{
struct hpc_dma_desc *hva;
bus_addr_t hpa;
bus_dma_segment_t *segp;
int i;
KASSERT(dmamap->dm_nsegs <= sc->sc_ndesc);
hva = sc->sc_desc_kva;
hpa = sc->sc_desc_pa;
segp = dmamap->dm_segs;
#ifdef DMA_DEBUG
printf("DMA_SGLIST<");
#endif
for (i = dmamap->dm_nsegs; i; i--) {
#ifdef DMA_DEBUG
printf("%p:%ld, ", (void *)segp->ds_addr, segp->ds_len);
#endif
hpa += sizeof(struct hpc_dma_desc); /* next chain desc */
if (sc->hpc->revision == 3) {
hva->hpc3_hdd_bufptr = segp->ds_addr;
hva->hpc3_hdd_ctl = segp->ds_len;
hva->hdd_descptr = hpa;
} else /* HPC 1/1.5 */ {
/*
* there doesn't seem to be any good way of doing this
* via an abstraction layer
*/
hva->hpc1_hdd_bufptr = segp->ds_addr;
hva->hpc1_hdd_ctl = segp->ds_len;
hva->hdd_descptr = hpa;
}
++hva;
++segp;
}
/* Work around HPC3 DMA bug */
if (sc->hpc->revision == 3) {
hva->hpc3_hdd_bufptr = 0;
hva->hpc3_hdd_ctl = HPC3_HDD_CTL_EOCHAIN;
hva->hdd_descptr = 0;
} else {
hva--;
hva->hpc1_hdd_bufptr |= HPC1_HDD_CTL_EOCHAIN;
hva->hdd_descptr = 0;
}
#ifdef DMA_DEBUG
printf(">\n");
#endif
bus_dmamap_sync(sc->sc_dmat, sc->sc_dmamap,
0, sizeof(struct hpc_dma_desc) * (dmamap->dm_nsegs + 1),
BUS_DMASYNC_PREWRITE);
/* Load DMA Descriptor list */
bus_space_write_4(sc->sc_bst, sc->sc_bsh, sc->hpc->scsi0_ndbp,
sc->sc_desc_pa);
}
void
hpcdma_cntl(struct hpc_dma_softc *sc, uint32_t mode)
{
bus_space_write_4(sc->sc_bst, sc->sc_bsh, sc->hpc->scsi0_ctl, mode);
}
void
hpcdma_reset(struct hpc_dma_softc *sc)
{
bus_space_write_4(sc->sc_bst, sc->sc_bsh, sc->hpc->scsi0_ctl,
sc->hpc->scsi_dmactl_reset);
delay(100);
bus_space_write_4(sc->sc_bst, sc->sc_bsh, sc->hpc->scsi0_ctl, 0);
delay(1000);
}
void
hpcdma_flush(struct hpc_dma_softc *sc)
{
uint32_t mode;
mode = bus_space_read_4(sc->sc_bst, sc->sc_bsh, sc->hpc->scsi0_ctl);
bus_space_write_4(sc->sc_bst, sc->sc_bsh,
sc->hpc->scsi0_ctl, mode | sc->hpc->scsi_dmactl_flush);
/* Wait for Active bit to drop */
while (bus_space_read_4(sc->sc_bst, sc->sc_bsh, sc->hpc->scsi0_ctl) &
sc->hpc->scsi_dmactl_active) {
bus_space_barrier(sc->sc_bst, sc->sc_bsh, sc->hpc->scsi0_ctl, 4,
BUS_SPACE_BARRIER_READ);
}
}
|