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