Home | History | Annotate | Line # | Download | only in tc
tc_dma_3000_500.c revision 1.7
      1 /* $NetBSD: tc_dma_3000_500.c,v 1.7 1998/05/13 21:21:17 thorpej Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
      9  * NASA Ames Research Center.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions and the following disclaimer.
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  * 3. All advertising materials mentioning features or use of this software
     20  *    must display the following acknowledgement:
     21  *	This product includes software developed by the NetBSD
     22  *	Foundation, Inc. and its contributors.
     23  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24  *    contributors may be used to endorse or promote products derived
     25  *    from this software without specific prior written permission.
     26  *
     27  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37  * POSSIBILITY OF SUCH DAMAGE.
     38  */
     39 
     40 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     41 
     42 __KERNEL_RCSID(0, "$NetBSD: tc_dma_3000_500.c,v 1.7 1998/05/13 21:21:17 thorpej Exp $");
     43 
     44 #include <sys/param.h>
     45 #include <sys/systm.h>
     46 #include <sys/kernel.h>
     47 #include <sys/malloc.h>
     48 #include <vm/vm.h>
     49 
     50 #define _ALPHA_BUS_DMA_PRIVATE
     51 #include <machine/bus.h>
     52 
     53 #include <dev/tc/tcvar.h>
     54 #include <alpha/tc/tc_sgmap.h>
     55 #include <alpha/tc/tc_dma_3000_500.h>
     56 
     57 struct alpha_bus_dma_tag tc_dmat_sgmap = {
     58 	NULL,				/* _cookie */
     59 	0,				/* _wbase */
     60 	0,				/* _wsize */
     61 	NULL,				/* _next_window */
     62 	NULL,				/* _sgmap */
     63 	NULL,				/* _get_tag */
     64 	tc_bus_dmamap_create_sgmap,
     65 	tc_bus_dmamap_destroy_sgmap,
     66 	tc_bus_dmamap_load_sgmap,
     67 	tc_bus_dmamap_load_mbuf_sgmap,
     68 	tc_bus_dmamap_load_uio_sgmap,
     69 	tc_bus_dmamap_load_raw_sgmap,
     70 	tc_bus_dmamap_unload_sgmap,
     71 	_bus_dmamap_sync,
     72 	_bus_dmamem_alloc,
     73 	_bus_dmamem_free,
     74 	_bus_dmamem_map,
     75 	_bus_dmamem_unmap,
     76 	_bus_dmamem_mmap,
     77 };
     78 
     79 struct tc_dma_slot_info {
     80 	struct alpha_sgmap tdsi_sgmap;		/* sgmap for slot */
     81 	struct alpha_bus_dma_tag tdsi_dmat;	/* dma tag for slot */
     82 };
     83 struct tc_dma_slot_info *tc_dma_slot_info;
     84 
     85 void
     86 tc_dma_init_3000_500(nslots)
     87 	int nslots;
     88 {
     89 	extern struct alpha_bus_dma_tag tc_dmat_direct;
     90 	size_t sisize;
     91 	int i;
     92 
     93 	/* Allocate per-slot DMA info. */
     94 	sisize = nslots * sizeof(struct tc_dma_slot_info);
     95 	tc_dma_slot_info = malloc(sisize, M_DEVBUF, M_NOWAIT);
     96 	if (tc_dma_slot_info == NULL)
     97 		panic("tc_dma_init: can't allocate per-slot DMA info");
     98 	bzero(tc_dma_slot_info, sisize);
     99 
    100 	/* Default all slots to direct-mapped. */
    101 	for (i = 0; i < nslots; i++)
    102 		bcopy(&tc_dmat_direct, &tc_dma_slot_info[i].tdsi_dmat,
    103 		    sizeof(tc_dma_slot_info[i].tdsi_dmat));
    104 }
    105 
    106 /*
    107  * Return the DMA tag for the given slot.
    108  */
    109 bus_dma_tag_t
    110 tc_dma_get_tag_3000_500(slot)
    111 	int slot;
    112 {
    113 
    114 	return (&tc_dma_slot_info[slot].tdsi_dmat);
    115 }
    116 
    117 /*
    118  * Create a TurboChannel SGMAP-mapped DMA map.
    119  */
    120 int
    121 tc_bus_dmamap_create_sgmap(t, size, nsegments, maxsegsz, boundary,
    122     flags, dmamp)
    123 	bus_dma_tag_t t;
    124 	bus_size_t size;
    125 	int nsegments;
    126 	bus_size_t maxsegsz;
    127 	bus_size_t boundary;
    128 	int flags;
    129 	bus_dmamap_t *dmamp;
    130 {
    131 	struct tc_dma_slot_info *tdsi = t->_cookie;
    132 	bus_dmamap_t map;
    133 	int error;
    134 
    135 	error = _bus_dmamap_create(t, size, nsegments, maxsegsz,
    136 	    boundary, flags, dmamp);
    137 	if (error)
    138 		return (error);
    139 
    140 	map = *dmamp;
    141 
    142 	if (flags & BUS_DMA_ALLOCNOW) {
    143 		error = alpha_sgmap_alloc(map, round_page(size),
    144 		    &tdsi->tdsi_sgmap, flags);
    145 		if (error)
    146 			tc_bus_dmamap_destroy_sgmap(t, map);
    147 	}
    148 
    149 	return (error);
    150 }
    151 
    152 /*
    153  * Destroy a TurboChannel SGMAP-mapped DMA map.
    154  */
    155 void
    156 tc_bus_dmamap_destroy_sgmap(t, map)
    157 	bus_dma_tag_t t;
    158 	bus_dmamap_t map;
    159 {
    160 	struct tc_dma_slot_info *tdsi = t->_cookie;
    161 
    162 	if (map->_dm_flags & DMAMAP_HAS_SGMAP)
    163 		alpha_sgmap_free(map, &tdsi->tdsi_sgmap);
    164 
    165 	_bus_dmamap_destroy(t, map);
    166 }
    167 
    168 /*
    169  * Load a TurboChannel SGMAP-mapped DMA map with a linear buffer.
    170  */
    171 int
    172 tc_bus_dmamap_load_sgmap(t, map, buf, buflen, p, flags)
    173 	bus_dma_tag_t t;
    174 	bus_dmamap_t map;
    175 	void *buf;
    176 	bus_size_t buflen;
    177 	struct proc *p;
    178 	int flags;
    179 {
    180 	struct tc_dma_slot_info *tdsi = t->_cookie;
    181 
    182 	return (tc_sgmap_load(t, map, buf, buflen, p, flags,
    183 	    &tdsi->tdsi_sgmap));
    184 }
    185 
    186 /*
    187  * Load a TurboChannel SGMAP-mapped DMA map with an mbuf chain.
    188  */
    189 int
    190 tc_bus_dmamap_load_mbuf_sgmap(t, map, m, flags)
    191 	bus_dma_tag_t t;
    192 	bus_dmamap_t map;
    193 	struct mbuf *m;
    194 	int flags;
    195 {
    196 	struct tc_dma_slot_info *tdsi = t->_cookie;
    197 
    198 	return (tc_sgmap_load_mbuf(t, map, m, flags, &tdsi->tdsi_sgmap));
    199 }
    200 
    201 /*
    202  * Load a TurboChannel SGMAP-mapped DMA map with a uio.
    203  */
    204 int
    205 tc_bus_dmamap_load_uio_sgmap(t, map, uio, flags)
    206 	bus_dma_tag_t t;
    207 	bus_dmamap_t map;
    208 	struct uio *uio;
    209 	int flags;
    210 {
    211 	struct tc_dma_slot_info *tdsi = t->_cookie;
    212 
    213 	return (tc_sgmap_load_uio(t, map, uio, flags, &tdsi->tdsi_sgmap));
    214 }
    215 
    216 /*
    217  * Load a TurboChannel SGMAP-mapped DMA map with raw memory.
    218  */
    219 int
    220 tc_bus_dmamap_load_raw_sgmap(t, map, segs, nsegs, size, flags)
    221 	bus_dma_tag_t t;
    222 	bus_dmamap_t map;
    223 	bus_dma_segment_t *segs;
    224 	int nsegs;
    225 	bus_size_t size;
    226 	int flags;
    227 {
    228 	struct tc_dma_slot_info *tdsi = t->_cookie;
    229 
    230 	return (tc_sgmap_load_raw(t, map, segs, nsegs, size, flags,
    231 	    &tdsi->tdsi_sgmap));
    232 }
    233 
    234 /*
    235  * Unload a TurboChannel SGMAP-mapped DMA map.
    236  */
    237 void
    238 tc_bus_dmamap_unload_sgmap(t, map)
    239 	bus_dma_tag_t t;
    240 	bus_dmamap_t map;
    241 {
    242 	struct tc_dma_slot_info *tdsi = t->_cookie;
    243 
    244 	/*
    245 	 * Invalidate any SGMAP page table entries used by this
    246 	 * mapping.
    247 	 */
    248 	tc_sgmap_unload(t, map, &tdsi->tdsi_sgmap);
    249 
    250 	/*
    251 	 * Do the generic bits of the unload.
    252 	 */
    253 	_bus_dmamap_unload(t, map);
    254 }
    255