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
|
/* $NetBSD: vme.c,v 1.19 2021/08/07 16:19:06 thorpej Exp $ */
/*-
* Copyright (c) 1996 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Gordon W. Ross.
*
* 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.
*
* 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.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: vme.c,v 1.19 2021/08/07 16:19:06 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <uvm/uvm_extern.h>
#define _SUN68K_BUS_DMA_PRIVATE
#include <machine/autoconf.h>
#include <machine/bus.h>
#include <machine/dvma.h>
#include <machine/pmap.h>
#include <sun3/sun3x/vme.h>
/* Does this machine have a VME bus? */
extern int cpu_has_vme;
/*
* Convert vme unit number to bus type,
* but only for supported bus types.
* (See autoconf.h and vme.h)
*/
#define VME_UNITS 6
static const struct {
int bustype;
const char *name;
int pmtype;
vaddr_t base;
vaddr_t mask;
} vme_info[VME_UNITS] = {
{ BUS_VME16D16, "A16/D16", PMAP_VME16, VME16_BASE, VME16_MASK },
{ BUS_VME16D32, "A16/D32", PMAP_VME32, VME16_BASE, VME16_MASK },
{ BUS_VME24D16, "A24/D16", PMAP_VME16, VME24_BASE, VME24_MASK },
{ BUS_VME24D32, "A24/D32", PMAP_VME32, VME24_BASE, VME24_MASK },
{ BUS_VME32D16, "A32/D16", PMAP_VME16, VME32_BASE, VME32_MASK },
{ BUS_VME32D32, "A32/D32", PMAP_VME32, VME32_BASE, VME32_MASK },
};
static int vme_match(device_t, cfdata_t, void *);
static void vme_attach(device_t, device_t, void *);
struct vme_softc {
device_t sc_dev;
bus_space_tag_t sc_bustag;
bus_dma_tag_t sc_dmatag;
int sc_bustype;
};
CFATTACH_DECL_NEW(vme, sizeof(struct vme_softc),
vme_match, vme_attach, NULL, NULL);
static int vme_bus_map(bus_space_tag_t, bus_type_t, bus_addr_t, bus_size_t,
int, vaddr_t, bus_space_handle_t *);
static paddr_t vme_bus_mmap(bus_space_tag_t, bus_type_t, bus_addr_t,
off_t, int, int);
static int vme_dmamap_load(bus_dma_tag_t, bus_dmamap_t, void *, bus_size_t,
struct proc *, int);
static struct sun68k_bus_space_tag vme_space_tag = {
NULL, /* cookie */
NULL, /* parent bus space tag */
vme_bus_map, /* bus_space_map */
NULL, /* bus_space_unmap */
NULL, /* bus_space_subregion */
NULL, /* bus_space_barrier */
vme_bus_mmap, /* bus_space_mmap */
NULL, /* bus_intr_establish */
NULL, /* bus_space_peek_N */
NULL /* bus_space_poke_N */
};
static struct sun68k_bus_dma_tag vme_dma_tag;
static int
vme_match(device_t parent, cfdata_t cf, void *aux)
{
struct confargs *ca = aux;
int unit;
if (cpu_has_vme == 0)
return 0;
unit = cf->cf_unit;
if (unit >= VME_UNITS)
return 0;
if (ca->ca_bustype != vme_info[unit].bustype)
return 0;
return 1;
}
static void
vme_attach(device_t parent, device_t self, void *args)
{
struct confargs *ca = aux;
struct vme_softc *sc = device_private(self);
struct confargs vmea;
int unit;
sc->sc_dev = self;
unit = device_unit(self);
aprint_normal(": (%s)\n", vme_info[unit].name);
sc->sc_bustag = ca->ca_bustag;
sc->sc_dmatag = ca->ca_dmatag;
sc->sc_bustype = unit;
vme_space_tag.cookie = sc;
vme_space_tag.parent = sc->sc_bustag;
vme_dma_tag = *sc->sc_dmatag;
vme_dma_tag._cookie = sc;
vme_dma_tag._dmamap_load = vme_dmamap_load;
vmea = *ca;
vmea.ca_bustag = &vme_space_tag;
vmea.ca_dmatag = &vme_dma_tag;
/* We know ca_bustype == BUS_VMExx */
config_search(self, args,
CFARGS(.search = bus_scan));
}
int
vme_bus_map(bus_space_tag_t t, bus_type_t btype, bus_addr_t paddr,
bus_size_t size, int flags, vaddr_t vaddr, bus_space_handle_t *hp)
{
struct vme_softc *sc = t->cookie;
paddr_t pa;
int bustype, pmtype;
bustype = sc->sc_bustype;
pa = paddr;
pa &= vme_info[bustype].mask;
pa |= vme_info[bustype].base;
pmtype = vme_info[bustype].pmtype;
return bus_space_map2(sc->sc_bustag, pmtype, pa, size,
flags | _SUN68K_BUS_MAP_USE_PROM, vaddr, hp);
}
paddr_t
vme_bus_mmap(bus_space_tag_t t, bus_type_t btype, bus_addr_t paddr, off_t off,
int prot, int flags)
{
struct vme_softc *sc = t->cookie;
paddr_t pa;
int bustype, pmtype;
bustype = sc->sc_bustype;
pa = paddr;
pa &= vme_info[bustype].mask;
pa |= vme_info[bustype].base;
pmtype = vme_info[bustype].pmtype;
return bus_space_mmap2(sc->sc_bustag, pmtype, pa, off, prot, flags);
}
static int
vme_dmamap_load(bus_dma_tag_t t, bus_dmamap_t map, void *buf,
bus_size_t buflen, struct proc *p, int flags)
{
int error;
error = _bus_dmamap_load(t, map, buf, buflen, p, flags);
if (error == 0)
map->dm_segs[0].ds_addr &= DVMA_VME_SLAVE_MASK;
return error;
}
|