vmevar.h revision 1.8 1 /* $NetBSD: vmevar.h,v 1.8 2000/06/04 19:15:16 cgd Exp $ */
2
3 /*
4 * Copyright (c) 1999
5 * Matthias Drochner. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
29 */
30
31 #ifndef _vmevar_h_
32 #define _vmevar_h_
33
34 typedef u_int32_t vme_addr_t, vme_size_t;
35 typedef int vme_am_t;
36
37 typedef enum {
38 VME_D8 = 1,
39 VME_D16 = 2,
40 VME_D32 = 4
41 } vme_datasize_t;
42
43 typedef int vme_swap_t; /* hardware swap capabilities,
44 placeholder - contents to be specified */
45
46 #ifdef _KERNEL
47
48 /* generic placeholder for any ressources needed for a mapping,
49 overloaded by bus interface driver */
50 typedef void *vme_mapresc_t;
51
52 /* describes interrupt mapping, overloaded by bus interface driver */
53 typedef void *vme_intr_handle_t;
54
55 /*
56 * tag structure passed to VME bus devices,
57 * contains the bus dependant functions, accessed via macros below
58 */
59 typedef struct vme_chipset_tag {
60 void *cookie;
61
62 int (*vct_map) __P((void *, vme_addr_t, vme_size_t,
63 vme_am_t, vme_datasize_t, vme_swap_t,
64 bus_space_tag_t *, bus_space_handle_t *,
65 vme_mapresc_t *));
66 void (*vct_unmap) __P((void *, vme_mapresc_t));
67
68 int (*vct_probe) __P((void *, vme_addr_t, vme_size_t,
69 vme_am_t, vme_datasize_t,
70 int (*)(void *, bus_space_tag_t, bus_space_handle_t),
71 void *));
72
73 int (*vct_int_map) __P((void *, int, int, vme_intr_handle_t *));
74 const struct evcnt *(*vct_int_evcnt) __P((void *, vme_intr_handle_t));
75 void *(*vct_int_establish) __P((void *, vme_intr_handle_t, int,
76 int (*)(void *), void *));
77 void (*vct_int_disestablish) __P((void *, void *));
78
79 int (*vct_dmamap_create) __P((void *, vme_size_t,
80 vme_am_t, vme_datasize_t, vme_swap_t,
81 int, vme_size_t, vme_addr_t,
82 int, bus_dmamap_t *));
83 void (*vct_dmamap_destroy) __P((void *, bus_dmamap_t));
84
85 /*
86 * This sucks: we have to give all the VME specific arguments
87 * twice - for dmamem_alloc and for dmamem_create. Perhaps
88 * give a "dmamap" argument here, meaning: "allocate memory which
89 * can be accessed through this DMA map".
90 */
91 int (*vct_dmamem_alloc) __P((void *, vme_size_t,
92 vme_am_t, vme_datasize_t, vme_swap_t,
93 bus_dma_segment_t *, int, int *, int));
94 void (*vct_dmamem_free) __P((void *, bus_dma_segment_t *, int));
95
96 struct vmebus_softc *bus;
97 } *vme_chipset_tag_t;
98
99 /*
100 * map / unmap: map VME address ranges into kernel address space
101 * XXX should have mapping to CPU only to allow user mmap() without
102 * wasting kvm
103 */
104 #define vme_space_map(vc, vmeaddr, len, am, datasize, swap, tag, handle, resc) \
105 (*((vc)->vct_map))((vc)->cookie, (vmeaddr), (len), (am), (datasize), \
106 (swap), (tag), (handle), (resc))
107 #define vme_space_unmap(vc, resc) \
108 (*((vc)->vct_unmap))((vc)->cookie, (resc))
109
110 /*
111 * probe: check readability or call callback
112 */
113 #define vme_probe(vc, vmeaddr, len, am, datasize, callback, cbarg) \
114 (*((vc)->vct_probe))((vc)->cookie, (vmeaddr), (len), (am), (datasize), \
115 (callback), (cbarg))
116
117 /*
118 * install / deinstall VME interrupt handler
119 */
120 #define vme_intr_map(vc, level, vector, handlep) \
121 (*((vc)->vct_int_map))((vc)->cookie, (level), (vector), (handlep))
122 #define vme_intr_evcnt(vc, handle) \
123 (*((vc)->vct_int_evcnt))((vc)->cookie, (handle))
124 #define vme_intr_establish(vc, handle, prio, func, arg) \
125 (*((vc)->vct_int_establish))((vc)->cookie, \
126 (handle), (prio), (func), (arg))
127 #define vme_intr_disestablish(vc, cookie) \
128 (*((vc)->vct_int_unmap))((vc)->cookie, (cookie))
129
130 /*
131 * create DMA map (which is later used by bus independant
132 * DMA functions)
133 */
134 #define vme_dmamap_create(vc, size, am, datasize, swap, nsegs, segsz, bound, \
135 flags, map) \
136 (*((vc)->vct_dmamap_create))((vc)->cookie, (size), (am), (datasize), (swap), \
137 (nsegs), (segsz), (bound), (flags), (map))
138 #define vme_dmamap_destroy(vc, map) \
139 (*((vc)->vct_dmamap_destroy))((vc)->cookie, (map))
140
141 /*
142 * allocate memory directly accessible from VME
143 */
144 #define vme_dmamem_alloc(vc, size, am, datasize, swap, \
145 segs, nsegs, rsegs, flags) \
146 (*((vc)->vct_dmamem_alloc))((vc)->cookie, (size), (am), (datasize), (swap), \
147 (segs), (nsegs), (rsegs), (flags))
148 #define vme_dmamem_free(vc, segs, nsegs) \
149 (*((vc)->vct_dmamem_free))((vc)->cookie, (segs), (nsegs))
150
151 /*
152 * autoconfiguration data structures
153 */
154
155 struct vme_attach_args;
156 typedef void (*vme_slaveconf_callback) __P((struct device *,
157 struct vme_attach_args *));
158
159 struct vmebus_attach_args {
160 vme_chipset_tag_t va_vct;
161 bus_dma_tag_t va_bdt;
162
163 vme_slaveconf_callback va_slaveconfig;
164 };
165
166 struct extent;
167
168 struct vmebus_softc {
169 struct device sc_dev;
170
171 vme_chipset_tag_t sc_vct;
172 bus_dma_tag_t sc_bdt;
173
174 vme_slaveconf_callback slaveconfig;
175
176 struct extent *vme32ext, *vme24ext, *vme16ext;
177 };
178
179 #define VME_MAXCFRANGES 3
180
181 struct vme_range {
182 vme_addr_t offset;
183 vme_size_t size;
184 vme_am_t am;
185 };
186
187 struct vme_attach_args {
188 vme_chipset_tag_t va_vct;
189 bus_dma_tag_t va_bdt;
190
191 int ivector, ilevel;
192 int numcfranges;
193 struct vme_range r[VME_MAXCFRANGES];
194 };
195
196 /*
197 * address space accounting
198 */
199 int _vme_space_alloc __P((struct vmebus_softc *, vme_addr_t,
200 vme_size_t, vme_am_t));
201 void _vme_space_free __P((struct vmebus_softc *, vme_addr_t,
202 vme_size_t, vme_am_t));
203 int _vme_space_get __P((struct vmebus_softc *, vme_size_t, vme_am_t,
204 u_long, vme_addr_t*));
205
206 #define vme_space_alloc(tag, addr, size, ams) \
207 _vme_space_alloc(tag->bus, addr, size, ams)
208
209 #define vme_space_free(tag, addr, size, ams) \
210 _vme_space_free(tag->bus, addr, size, ams)
211
212 #define vme_space_get(tag, size, ams, align, addr) \
213 _vme_space_get(tag->bus, size, ams, align, addr)
214
215 #endif /* KERNEL */
216 #endif /* _vmevar_h_ */
217