1 /* $NetBSD: vmevar.h,v 1.14 2012/10/27 17:18:38 chs 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 /*
49  * Generic placeholder for any resources needed for a mapping,
50  * overloaded by bus interface driver
51  */
52 typedef void *vme_mapresc_t;
53 
54 /* Describes interrupt mapping, opaque to MI drivers */
55 typedef void *vme_intr_handle_t;
56 
57 /*
58  * Tag structure passed to VME bus devices;
59  * contains the bus dependent functions, accessed via macros below.
60  */
61 typedef struct vme_chipset_tag {
62 	void *cookie;
63 
64 	int (*vct_map)(void *, vme_addr_t, vme_size_t,
65 			vme_am_t, vme_datasize_t, vme_swap_t,
66 			bus_space_tag_t *, bus_space_handle_t *,
67 			vme_mapresc_t *);
68 	void (*vct_unmap)(void *, vme_mapresc_t);
69 
70 	int (*vct_probe)(void *, vme_addr_t, vme_size_t,
71 			 vme_am_t, vme_datasize_t,
72 			 int (*)(void *, bus_space_tag_t, bus_space_handle_t),
73 			      void *);
74 
75 	int (*vct_int_map)(void *, int, int, vme_intr_handle_t *);
76 	const struct evcnt *(*vct_int_evcnt)(void *, vme_intr_handle_t);
77 	void *(*vct_int_establish)(void *, vme_intr_handle_t, int,
78 					int (*)(void *), void *);
79 	void (*vct_int_disestablish)(void *, void *);
80 
81 	int (*vct_dmamap_create)(void *, vme_size_t,
82 				 vme_am_t, vme_datasize_t, vme_swap_t,
83 				 int, vme_size_t, vme_addr_t,
84 				 int, bus_dmamap_t *);
85 	void (*vct_dmamap_destroy)(void *, bus_dmamap_t);
86 
87 	/*
88 	 * This sucks: we have to give all the VME specific arguments
89 	 * twice - for dmamem_alloc and for dmamem_create. Perhaps
90 	 * give a "dmamap" argument here, meaning: "allocate memory which
91 	 * can be accessed through this DMA map".
92 	 */
93 	int (*vct_dmamem_alloc)(void *, vme_size_t,
94 				vme_am_t, vme_datasize_t, vme_swap_t,
95 				bus_dma_segment_t *, int, int *, int);
96 	void (*vct_dmamem_free)(void *, bus_dma_segment_t *, int);
97 
98 	struct vmebus_softc *bus;
99 } *vme_chipset_tag_t;
100 
101 /*
102  * map / unmap: map VME address ranges into kernel address space
103  * XXX should have mapping to CPU only to allow user mmap() without
104  *     wasting kvm
105  */
106 #define vme_space_map(vc, vmeaddr, len, am, datasize, swap, tag, handle, resc) \
107 	(*((vc)->vct_map))((vc)->cookie, (vmeaddr), (len), (am), (datasize), \
108 			   (swap), (tag), (handle), (resc))
109 #define vme_space_unmap(vc, resc) \
110 	(*((vc)->vct_unmap))((vc)->cookie, (resc))
111 
112 /*
113  * probe: check readability or call callback.
114  */
115 #define vme_probe(vc, vmeaddr, len, am, datasize, callback, cbarg) \
116 	(*((vc)->vct_probe))((vc)->cookie, (vmeaddr), (len), (am), \
117 			     (datasize), (callback), (cbarg))
118 
119 /*
120  * install / deinstall VME interrupt handler.
121  */
122 #define vme_intr_map(vc, level, vector, handlep) \
123 	(*((vc)->vct_int_map))((vc)->cookie, (level), (vector), (handlep))
124 #define vme_intr_evcnt(vc, handle) \
125 	(*((vc)->vct_int_evcnt))((vc)->cookie, (handle))
126 #define vme_intr_establish(vc, handle, prio, func, arg) \
127 	(*((vc)->vct_int_establish))((vc)->cookie, \
128 		(handle), (prio), (func), (arg))
129 #define vme_intr_disestablish(vc, cookie) \
130 	(*((vc)->vct_int_unmap))((vc)->cookie, (cookie))
131 
132 /*
133  * Create DMA map (which is later used by bus independent DMA functions).
134  */
135 #define vme_dmamap_create(vc, size, am, datasize, swap, nsegs, segsz, bound, \
136 			  flags, map) \
137 	(*((vc)->vct_dmamap_create))((vc)->cookie, (size), (am), (datasize), \
138 		(swap), (nsegs), (segsz), (bound), (flags), (map))
139 #define vme_dmamap_destroy(vc, map) \
140 	(*((vc)->vct_dmamap_destroy))((vc)->cookie, (map))
141 
142 /*
143  * Allocate memory directly accessible from VME.
144  */
145 #define vme_dmamem_alloc(vc, size, am, datasize, swap, \
146   segs, nsegs, rsegs, flags) \
147   (*((vc)->vct_dmamem_alloc))((vc)->cookie, (size), (am), (datasize), (swap), \
148   (segs), (nsegs), (rsegs), (flags))
149 #define vme_dmamem_free(vc, segs, nsegs) \
150   (*((vc)->vct_dmamem_free))((vc)->cookie, (segs), (nsegs))
151 
152 /*
153  * Autoconfiguration data structures.
154  */
155 
156 struct vme_attach_args;
157 typedef void (*vme_slaveconf_callback)(device_t,
158 				       struct vme_attach_args *);
159 
160 struct vmebus_attach_args {
161 	vme_chipset_tag_t va_vct;
162 	bus_dma_tag_t va_bdt;
163 
164 	vme_slaveconf_callback va_slaveconfig;
165 };
166 
167 struct extent;
168 
169 struct vmebus_softc {
170 	vme_chipset_tag_t sc_vct;
171 	bus_dma_tag_t sc_bdt;
172 
173 	vme_slaveconf_callback slaveconfig;
174 
175 	struct extent *vme32ext, *vme24ext, *vme16ext;
176 };
177 
178 #define VME_MAXCFRANGES 3
179 
180 struct vme_range {
181 	vme_addr_t offset;
182 	vme_size_t size;
183 	vme_am_t am;
184 };
185 
186 struct vme_attach_args {
187 	vme_chipset_tag_t va_vct;
188 	bus_dma_tag_t va_bdt;
189 
190 	int ivector, ilevel;
191 	int numcfranges;
192 	struct vme_range r[VME_MAXCFRANGES];
193 };
194 
195 /*
196  * Address space accounting.
197  */
198 int _vme_space_alloc(struct vmebus_softc *, vme_addr_t, vme_size_t, vme_am_t);
199 void _vme_space_free(struct vmebus_softc *, vme_addr_t, vme_size_t, vme_am_t);
200 int _vme_space_get(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