1 /* $Id$
2  *
3  * This file is subject to the terms and conditions of the GNU General Public
4  * License.  See the file "COPYING" in the main directory of this archive
5  * for more details.
6  *
7  * Copyright (C) 1992-1997, 2000-2003 Silicon Graphics, Inc.  All Rights Reserved.
8  */
9 #ifndef _ASM_SN_XTALK_XTALK_H
10 #define _ASM_SN_XTALK_XTALK_H
11 #include <linux/config.h>
12 
13 #ifdef __KERNEL__
14 #include "asm/sn/sgi.h"
15 #endif
16 
17 
18 /*
19  * xtalk.h -- platform-independent crosstalk interface
20  */
21 /*
22  * User-level device driver visible types
23  */
24 typedef char            xwidgetnum_t;	/* xtalk widget number  (0..15) */
25 
26 #define XWIDGET_NONE		(-1)
27 
28 typedef int xwidget_part_num_t;	/* xtalk widget part number */
29 
30 #define XWIDGET_PART_NUM_NONE	(-1)
31 
32 typedef int             xwidget_rev_num_t;	/* xtalk widget revision number */
33 
34 #define XWIDGET_REV_NUM_NONE	(-1)
35 
36 typedef int xwidget_mfg_num_t;	/* xtalk widget manufacturing ID */
37 
38 #define XWIDGET_MFG_NUM_NONE	(-1)
39 
40 typedef struct xtalk_piomap_s *xtalk_piomap_t;
41 
42 /* It is often convenient to fold the XIO target port
43  * number into the XIO address.
44  */
45 #define	XIO_NOWHERE	(0xFFFFFFFFFFFFFFFFull)
46 #define	XIO_ADDR_BITS	(0x0000FFFFFFFFFFFFull)
47 #define	XIO_PORT_BITS	(0xF000000000000000ull)
48 #define	XIO_PORT_SHIFT	(60)
49 
50 #define	XIO_PACKED(x)	(((x)&XIO_PORT_BITS) != 0)
51 #define	XIO_ADDR(x)	((x)&XIO_ADDR_BITS)
52 #define	XIO_PORT(x)	((xwidgetnum_t)(((x)&XIO_PORT_BITS) >> XIO_PORT_SHIFT))
53 #define	XIO_PACK(p,o)	((((uint64_t)(p))<<XIO_PORT_SHIFT) | ((o)&XIO_ADDR_BITS))
54 
55 
56 /*
57  * Kernel/driver only definitions
58  */
59 #if __KERNEL__
60 
61 #include <asm/types.h>
62 #include <asm/sn/types.h>
63 #include <asm/sn/alenlist.h>
64 #include <asm/sn/ioerror.h>
65 #include <asm/sn/driver.h>
66 #include <asm/sn/dmamap.h>
67 
68 struct xwidget_hwid_s;
69 
70 /*
71  *    Acceptable flag bits for xtalk service calls
72  *
73  * XTALK_FIXED: require that mappings be established
74  *	using fixed sharable resources; address
75  *	translation results will be permanently
76  *	available. (PIOMAP_FIXED and DMAMAP_FIXED are
77  *	the same numeric value and are acceptable).
78  * XTALK_NOSLEEP: if any part of the operation would
79  *	sleep waiting for resoruces, return an error
80  *	instead. (PIOMAP_NOSLEEP and DMAMAP_NOSLEEP are
81  *	the same numeric value and are acceptable).
82  * XTALK_INPLACE: when operating on alenlist structures,
83  *	reuse the source alenlist rather than creating a
84  *	new one. (PIOMAP_INPLACE and DMAMAP_INPLACE are
85  *	the same numeric value and are acceptable).
86  */
87 #define	XTALK_FIXED		DMAMAP_FIXED
88 #define	XTALK_NOSLEEP		DMAMAP_NOSLEEP
89 #define	XTALK_INPLACE		DMAMAP_INPLACE
90 
91 /* PIO MANAGEMENT */
92 typedef xtalk_piomap_t
93 xtalk_piomap_alloc_f    (vertex_hdl_t dev,	/* set up mapping for this device */
94 			 device_desc_t dev_desc,	/* device descriptor */
95 			 iopaddr_t xtalk_addr,	/* map for this xtalk_addr range */
96 			 size_t byte_count,
97 			 size_t byte_count_max,		/* maximum size of a mapping */
98 			 unsigned flags);	/* defined in sys/pio.h */
99 typedef void
100 xtalk_piomap_free_f     (xtalk_piomap_t xtalk_piomap);
101 
102 typedef caddr_t
103 xtalk_piomap_addr_f     (xtalk_piomap_t xtalk_piomap,	/* mapping resources */
104 			 iopaddr_t xtalk_addr,	/* map for this xtalk address */
105 			 size_t byte_count);	/* map this many bytes */
106 
107 typedef void
108 xtalk_piomap_done_f     (xtalk_piomap_t xtalk_piomap);
109 
110 typedef caddr_t
111 xtalk_piotrans_addr_f   (vertex_hdl_t dev,	/* translate for this device */
112 			 device_desc_t dev_desc,	/* device descriptor */
113 			 iopaddr_t xtalk_addr,	/* Crosstalk address */
114 			 size_t byte_count,	/* map this many bytes */
115 			 unsigned flags);	/* (currently unused) */
116 
117 extern caddr_t
118 xtalk_pio_addr		(vertex_hdl_t dev,	/* translate for this device */
119 			 device_desc_t dev_desc,	/* device descriptor */
120 			 iopaddr_t xtalk_addr,	/* Crosstalk address */
121 			 size_t byte_count,	/* map this many bytes */
122 			 xtalk_piomap_t *xtalk_piomapp,	/* RETURNS mapping resources */
123 			 unsigned flags);	/* (currently unused) */
124 
125 /* DMA MANAGEMENT */
126 
127 typedef struct xtalk_dmamap_s *xtalk_dmamap_t;
128 
129 typedef xtalk_dmamap_t
130 xtalk_dmamap_alloc_f    (vertex_hdl_t dev,	/* set up mappings for this device */
131 			 device_desc_t dev_desc,	/* device descriptor */
132 			 size_t byte_count_max,		/* max size of a mapping */
133 			 unsigned flags);	/* defined in dma.h */
134 
135 typedef void
136 xtalk_dmamap_free_f     (xtalk_dmamap_t dmamap);
137 
138 typedef iopaddr_t
139 xtalk_dmamap_addr_f     (xtalk_dmamap_t dmamap,		/* use these mapping resources */
140 			 paddr_t paddr,		/* map for this address */
141 			 size_t byte_count);	/* map this many bytes */
142 
143 typedef alenlist_t
144 xtalk_dmamap_list_f     (xtalk_dmamap_t dmamap,		/* use these mapping resources */
145 			 alenlist_t alenlist,	/* map this address/length list */
146 			 unsigned flags);
147 
148 typedef void
149 xtalk_dmamap_done_f     (xtalk_dmamap_t dmamap);
150 
151 typedef iopaddr_t
152 xtalk_dmatrans_addr_f   (vertex_hdl_t dev,	/* translate for this device */
153 			 device_desc_t dev_desc,	/* device descriptor */
154 			 paddr_t paddr,		/* system physical address */
155 			 size_t byte_count,	/* length */
156 			 unsigned flags);
157 
158 typedef alenlist_t
159 xtalk_dmatrans_list_f   (vertex_hdl_t dev,	/* translate for this device */
160 			 device_desc_t dev_desc,	/* device descriptor */
161 			 alenlist_t palenlist,	/* system address/length list */
162 			 unsigned flags);
163 
164 typedef void
165 xtalk_dmamap_drain_f	(xtalk_dmamap_t map);	/* drain this map's channel */
166 
167 typedef void
168 xtalk_dmaaddr_drain_f	(vertex_hdl_t vhdl,	/* drain channel from this device */
169 			 paddr_t addr,		/* to this physical address */
170 			 size_t bytes);		/* for this many bytes */
171 
172 typedef void
173 xtalk_dmalist_drain_f	(vertex_hdl_t vhdl,	/* drain channel from this device */
174 			 alenlist_t list);	/* for this set of physical blocks */
175 
176 
177 /* INTERRUPT MANAGEMENT */
178 
179 /*
180  * A xtalk interrupt resource handle.  When resources are allocated
181  * in order to satisfy a xtalk_intr_alloc request, a xtalk_intr handle
182  * is returned.  xtalk_intr_connect associates a software handler with
183 
184  * these system resources.
185  */
186 typedef struct xtalk_intr_s *xtalk_intr_t;
187 
188 
189 /*
190  * When a crosstalk device connects an interrupt, it passes in a function
191  * that knows how to set its xtalk interrupt register appropriately.  The
192  * low-level interrupt code may invoke this function later in order to
193  * migrate an interrupt transparently to the device driver(s) that use this
194  * interrupt.
195  *
196  * The argument passed to this function contains enough information for a
197  * crosstalk device to (re-)target an interrupt.  A function of this type
198  * must be supplied by every crosstalk driver.
199  */
200 typedef int
201 xtalk_intr_setfunc_f    (xtalk_intr_t intr_hdl);	/* interrupt handle */
202 
203 typedef xtalk_intr_t
204 xtalk_intr_alloc_f      (vertex_hdl_t dev,	/* which crosstalk device */
205 			 device_desc_t dev_desc,	/* device descriptor */
206 			 vertex_hdl_t owner_dev);	/* owner of this intr */
207 
208 typedef void
209 xtalk_intr_free_f       (xtalk_intr_t intr_hdl);
210 
211 typedef int
212 xtalk_intr_connect_f    (xtalk_intr_t intr_hdl,		/* xtalk intr resource handle */
213 			intr_func_t intr_func,         /* xtalk intr handler */
214 			void *intr_arg,	/* arg to intr handler */
215 			xtalk_intr_setfunc_f *setfunc,		/* func to set intr hw */
216 			void *setfunc_arg);	/* arg to setfunc */
217 
218 typedef void
219 xtalk_intr_disconnect_f (xtalk_intr_t intr_hdl);
220 
221 typedef vertex_hdl_t
222 xtalk_intr_cpu_get_f    (xtalk_intr_t intr_hdl);	/* xtalk intr resource handle */
223 
224 /* CONFIGURATION MANAGEMENT */
225 
226 typedef void
227 xtalk_provider_startup_f (vertex_hdl_t xtalk_provider);
228 
229 typedef void
230 xtalk_provider_shutdown_f (vertex_hdl_t xtalk_provider);
231 
232 typedef void
233 xtalk_widgetdev_enable_f (vertex_hdl_t, int);
234 
235 typedef void
236 xtalk_widgetdev_shutdown_f (vertex_hdl_t, int);
237 
238 typedef int
239 xtalk_dma_enabled_f (vertex_hdl_t);
240 
241 /* Error Management */
242 
243 typedef int
244 xtalk_error_devenable_f (vertex_hdl_t xconn_vhdl,
245 			 int devnum,
246 			 int error_code);
247 
248 /* Early Action Support */
249 typedef caddr_t
250 xtalk_early_piotrans_addr_f (xwidget_part_num_t part_num,
251 			     xwidget_mfg_num_t mfg_num,
252 			     int which,
253 			     iopaddr_t xtalk_addr,
254 			     size_t byte_count,
255 			     unsigned flags);
256 
257 /*
258  * Adapters that provide a crosstalk interface adhere to this software interface.
259  */
260 typedef struct xtalk_provider_s {
261     /* PIO MANAGEMENT */
262     xtalk_piomap_alloc_f   *piomap_alloc;
263     xtalk_piomap_free_f    *piomap_free;
264     xtalk_piomap_addr_f    *piomap_addr;
265     xtalk_piomap_done_f    *piomap_done;
266     xtalk_piotrans_addr_f  *piotrans_addr;
267 
268     /* DMA MANAGEMENT */
269     xtalk_dmamap_alloc_f   *dmamap_alloc;
270     xtalk_dmamap_free_f    *dmamap_free;
271     xtalk_dmamap_addr_f    *dmamap_addr;
272     xtalk_dmamap_list_f    *dmamap_list;
273     xtalk_dmamap_done_f    *dmamap_done;
274     xtalk_dmatrans_addr_f  *dmatrans_addr;
275     xtalk_dmatrans_list_f  *dmatrans_list;
276     xtalk_dmamap_drain_f   *dmamap_drain;
277     xtalk_dmaaddr_drain_f  *dmaaddr_drain;
278     xtalk_dmalist_drain_f  *dmalist_drain;
279 
280     /* INTERRUPT MANAGEMENT */
281     xtalk_intr_alloc_f     *intr_alloc;
282     xtalk_intr_alloc_f     *intr_alloc_nothd;
283     xtalk_intr_free_f      *intr_free;
284     xtalk_intr_connect_f   *intr_connect;
285     xtalk_intr_disconnect_f *intr_disconnect;
286 
287     /* CONFIGURATION MANAGEMENT */
288     xtalk_provider_startup_f *provider_startup;
289     xtalk_provider_shutdown_f *provider_shutdown;
290 
291     /* Error Management     */
292     xtalk_error_devenable_f *error_devenable;
293 } xtalk_provider_t;
294 
295 /* Crosstalk devices use these standard Crosstalk provider interfaces */
296 extern xtalk_piomap_alloc_f xtalk_piomap_alloc;
297 extern xtalk_piomap_free_f xtalk_piomap_free;
298 extern xtalk_piomap_addr_f xtalk_piomap_addr;
299 extern xtalk_piomap_done_f xtalk_piomap_done;
300 extern xtalk_piotrans_addr_f xtalk_piotrans_addr;
301 extern xtalk_dmamap_alloc_f xtalk_dmamap_alloc;
302 extern xtalk_dmamap_free_f xtalk_dmamap_free;
303 extern xtalk_dmamap_addr_f xtalk_dmamap_addr;
304 extern xtalk_dmamap_list_f xtalk_dmamap_list;
305 extern xtalk_dmamap_done_f xtalk_dmamap_done;
306 extern xtalk_dmatrans_addr_f xtalk_dmatrans_addr;
307 extern xtalk_dmatrans_list_f xtalk_dmatrans_list;
308 extern xtalk_dmamap_drain_f xtalk_dmamap_drain;
309 extern xtalk_dmaaddr_drain_f xtalk_dmaaddr_drain;
310 extern xtalk_dmalist_drain_f xtalk_dmalist_drain;
311 extern xtalk_intr_alloc_f xtalk_intr_alloc;
312 extern xtalk_intr_alloc_f xtalk_intr_alloc_nothd;
313 extern xtalk_intr_free_f xtalk_intr_free;
314 extern xtalk_intr_connect_f xtalk_intr_connect;
315 extern xtalk_intr_disconnect_f xtalk_intr_disconnect;
316 extern xtalk_intr_cpu_get_f xtalk_intr_cpu_get;
317 extern xtalk_provider_startup_f xtalk_provider_startup;
318 extern xtalk_provider_shutdown_f xtalk_provider_shutdown;
319 extern xtalk_widgetdev_enable_f xtalk_widgetdev_enable;
320 extern xtalk_widgetdev_shutdown_f xtalk_widgetdev_shutdown;
321 extern xtalk_dma_enabled_f xtalk_dma_enabled;
322 extern xtalk_error_devenable_f xtalk_error_devenable;
323 extern xtalk_early_piotrans_addr_f xtalk_early_piotrans_addr;
324 
325 /* error management */
326 
327 extern int              xtalk_error_handler(vertex_hdl_t,
328 					    int,
329 					    ioerror_mode_t,
330 					    ioerror_t *);
331 
332 /*
333  * Generic crosstalk interface, for use with all crosstalk providers
334  * and all crosstalk devices.
335  */
336 typedef unchar xtalk_intr_vector_t;	/* crosstalk interrupt vector (0..255) */
337 
338 #define XTALK_INTR_VECTOR_NONE	(xtalk_intr_vector_t)0
339 
340 /* Generic crosstalk interrupt interfaces */
341 extern vertex_hdl_t     xtalk_intr_dev_get(xtalk_intr_t xtalk_intr);
342 extern xwidgetnum_t     xtalk_intr_target_get(xtalk_intr_t xtalk_intr);
343 extern xtalk_intr_vector_t xtalk_intr_vector_get(xtalk_intr_t xtalk_intr);
344 extern iopaddr_t        xtalk_intr_addr_get(xtalk_intr_t xtalk_intr);
345 extern vertex_hdl_t     xtalk_intr_cpu_get(xtalk_intr_t xtalk_intr);
346 extern void            *xtalk_intr_sfarg_get(xtalk_intr_t xtalk_intr);
347 
348 /* Generic crosstalk pio interfaces */
349 extern vertex_hdl_t     xtalk_pio_dev_get(xtalk_piomap_t xtalk_piomap);
350 extern xwidgetnum_t     xtalk_pio_target_get(xtalk_piomap_t xtalk_piomap);
351 extern iopaddr_t        xtalk_pio_xtalk_addr_get(xtalk_piomap_t xtalk_piomap);
352 extern size_t           xtalk_pio_mapsz_get(xtalk_piomap_t xtalk_piomap);
353 extern caddr_t          xtalk_pio_kvaddr_get(xtalk_piomap_t xtalk_piomap);
354 
355 /* Generic crosstalk dma interfaces */
356 extern vertex_hdl_t     xtalk_dma_dev_get(xtalk_dmamap_t xtalk_dmamap);
357 extern xwidgetnum_t     xtalk_dma_target_get(xtalk_dmamap_t xtalk_dmamap);
358 
359 /* Register/unregister Crosstalk providers and get implementation handle */
360 extern void             xtalk_set_early_piotrans_addr(xtalk_early_piotrans_addr_f *);
361 extern void             xtalk_provider_register(vertex_hdl_t provider, xtalk_provider_t *xtalk_fns);
362 extern void             xtalk_provider_unregister(vertex_hdl_t provider);
363 extern xtalk_provider_t *xtalk_provider_fns_get(vertex_hdl_t provider);
364 
365 /* Crosstalk Switch generic layer, for use by initialization code */
366 extern void             xswitch_census(vertex_hdl_t xswitchv);
367 extern void             xswitch_init_widgets(vertex_hdl_t xswitchv);
368 
369 /* early init interrupt management */
370 
371 typedef void
372 xwidget_intr_preset_f   (void *which_widget,
373 			 int which_widget_intr,
374 			 xwidgetnum_t targ,
375 			 iopaddr_t addr,
376 			 xtalk_intr_vector_t vect);
377 
378 typedef void
379 xtalk_intr_prealloc_f   (void *which_xtalk,
380 			 xtalk_intr_vector_t xtalk_vector,
381 			 xwidget_intr_preset_f *preset_func,
382 			 void *which_widget,
383 			 int which_widget_intr);
384 
385 typedef void
386 xtalk_intr_preconn_f    (void *which_xtalk,
387 			 xtalk_intr_vector_t xtalk_vector,
388 			 intr_func_t intr_func,
389 			 intr_arg_t intr_arg);
390 
391 
392 #define XTALK_ADDR_TO_UPPER(xtalk_addr) (((iopaddr_t)(xtalk_addr) >> 32) & 0xffff)
393 #define XTALK_ADDR_TO_LOWER(xtalk_addr) ((iopaddr_t)(xtalk_addr) & 0xffffffff)
394 
395 typedef xtalk_intr_setfunc_f *xtalk_intr_setfunc_t;
396 
397 typedef void		xtalk_iter_f(vertex_hdl_t vhdl);
398 
399 extern void		xtalk_iterate(char *prefix, xtalk_iter_f *func);
400 
401 #endif				/* __KERNEL__ */
402 #endif				/* _ASM_SN_XTALK_XTALK_H */
403