vmevar.h revision 1.7 1 /* $NetBSD: vmevar.h,v 1.7 2000/02/25 10:33:12 drochner 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 void *(*vct_int_establish) __P((void *, vme_intr_handle_t, int,
75 int (*)(void *), void *));
76 void (*vct_int_disestablish) __P((void *, void *));
77
78 int (*vct_dmamap_create) __P((void *, vme_size_t,
79 vme_am_t, vme_datasize_t, vme_swap_t,
80 int, vme_size_t, vme_addr_t,
81 int, bus_dmamap_t *));
82 void (*vct_dmamap_destroy) __P((void *, bus_dmamap_t));
83
84 /*
85 * This sucks: we have to give all the VME specific arguments
86 * twice - for dmamem_alloc and for dmamem_create. Perhaps
87 * give a "dmamap" argument here, meaning: "allocate memory which
88 * can be accessed through this DMA map".
89 */
90 int (*vct_dmamem_alloc) __P((void *, vme_size_t,
91 vme_am_t, vme_datasize_t, vme_swap_t,
92 bus_dma_segment_t *, int, int *, int));
93 void (*vct_dmamem_free) __P((void *, bus_dma_segment_t *, int));
94
95 struct vmebus_softc *bus;
96 } *vme_chipset_tag_t;
97
98 /*
99 * map / unmap: map VME address ranges into kernel address space
100 * XXX should have mapping to CPU only to allow user mmap() without
101 * wasting kvm
102 */
103 #define vme_space_map(vc, vmeaddr, len, am, datasize, swap, tag, handle, resc) \
104 (*((vc)->vct_map))((vc)->cookie, (vmeaddr), (len), (am), (datasize), \
105 (swap), (tag), (handle), (resc))
106 #define vme_space_unmap(vc, resc) \
107 (*((vc)->vct_unmap))((vc)->cookie, (resc))
108
109 /*
110 * probe: check readability or call callback
111 */
112 #define vme_probe(vc, vmeaddr, len, am, datasize, callback, cbarg) \
113 (*((vc)->vct_probe))((vc)->cookie, (vmeaddr), (len), (am), (datasize), \
114 (callback), (cbarg))
115
116 /*
117 * install / deinstall VME interrupt handler
118 */
119 #define vme_intr_map(vc, level, vector, handlep) \
120 (*((vc)->vct_int_map))((vc)->cookie, (level), (vector), (handlep))
121 #define vme_intr_establish(vc, handle, prio, func, arg) \
122 (*((vc)->vct_int_establish))((vc)->cookie, \
123 (handle), (prio), (func), (arg))
124 #define vme_intr_disestablish(vc, cookie) \
125 (*((vc)->vct_int_unmap))((vc)->cookie, (cookie))
126
127 /*
128 * create DMA map (which is later used by bus independant
129 * DMA functions)
130 */
131 #define vme_dmamap_create(vc, size, am, datasize, swap, nsegs, segsz, bound, \
132 flags, map) \
133 (*((vc)->vct_dmamap_create))((vc)->cookie, (size), (am), (datasize), (swap), \
134 (nsegs), (segsz), (bound), (flags), (map))
135 #define vme_dmamap_destroy(vc, map) \
136 (*((vc)->vct_dmamap_destroy))((vc)->cookie, (map))
137
138 /*
139 * allocate memory directly accessible from VME
140 */
141 #define vme_dmamem_alloc(vc, size, am, datasize, swap, \
142 segs, nsegs, rsegs, flags) \
143 (*((vc)->vct_dmamem_alloc))((vc)->cookie, (size), (am), (datasize), (swap), \
144 (segs), (nsegs), (rsegs), (flags))
145 #define vme_dmamem_free(vc, segs, nsegs) \
146 (*((vc)->vct_dmamem_free))((vc)->cookie, (segs), (nsegs))
147
148 /*
149 * autoconfiguration data structures
150 */
151
152 struct vme_attach_args;
153 typedef void (*vme_slaveconf_callback) __P((struct device *,
154 struct vme_attach_args *));
155
156 struct vmebus_attach_args {
157 vme_chipset_tag_t va_vct;
158 bus_dma_tag_t va_bdt;
159
160 vme_slaveconf_callback va_slaveconfig;
161 };
162
163 struct extent;
164
165 struct vmebus_softc {
166 struct device sc_dev;
167
168 vme_chipset_tag_t sc_vct;
169 bus_dma_tag_t sc_bdt;
170
171 vme_slaveconf_callback slaveconfig;
172
173 struct extent *vme32ext, *vme24ext, *vme16ext;
174 };
175
176 #define VME_MAXCFRANGES 3
177
178 struct vme_range {
179 vme_addr_t offset;
180 vme_size_t size;
181 vme_am_t am;
182 };
183
184 struct vme_attach_args {
185 vme_chipset_tag_t va_vct;
186 bus_dma_tag_t va_bdt;
187
188 int ivector, ilevel;
189 int numcfranges;
190 struct vme_range r[VME_MAXCFRANGES];
191 };
192
193 /*
194 * address space accounting
195 */
196 int _vme_space_alloc __P((struct vmebus_softc *, vme_addr_t,
197 vme_size_t, vme_am_t));
198 void _vme_space_free __P((struct vmebus_softc *, vme_addr_t,
199 vme_size_t, vme_am_t));
200 int _vme_space_get __P((struct vmebus_softc *, vme_size_t, vme_am_t,
201 u_long, vme_addr_t*));
202
203 #define vme_space_alloc(tag, addr, size, ams) \
204 _vme_space_alloc(tag->bus, addr, size, ams)
205
206 #define vme_space_free(tag, addr, size, ams) \
207 _vme_space_free(tag->bus, addr, size, ams)
208
209 #define vme_space_get(tag, size, ams, align, addr) \
210 _vme_space_get(tag->bus, size, ams, align, addr)
211
212 #endif /* KERNEL */
213 #endif /* _vmevar_h_ */
214