Home | History | Annotate | Line # | Download | only in tc
tc_dma_3000_500.c revision 1.13
      1 /* $NetBSD: tc_dma_3000_500.c,v 1.13 2001/07/19 06:40:03 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.13 2001/07/19 06:40:03 thorpej Exp $");
     43 
     44 #include <sys/param.h>
     45 #include <sys/systm.h>
     46 #include <sys/device.h>
     47 #include <sys/kernel.h>
     48 #include <sys/malloc.h>
     49 
     50 #include <uvm/uvm_extern.h>
     51 
     52 #define _ALPHA_BUS_DMA_PRIVATE
     53 #include <machine/bus.h>
     54 
     55 #include <dev/tc/tcvar.h>
     56 #include <alpha/tc/tc_sgmap.h>
     57 #include <alpha/tc/tc_dma_3000_500.h>
     58 
     59 struct alpha_bus_dma_tag tc_dmat_sgmap = {
     60 	NULL,				/* _cookie */
     61 	0,				/* _wbase */
     62 	0,				/* _wsize */
     63 	NULL,				/* _next_window */
     64 	0,				/* _boundary */
     65 	NULL,				/* _sgmap */
     66 	0,				/* _pfthresh */
     67 	NULL,				/* _get_tag */
     68 	tc_bus_dmamap_create_sgmap,
     69 	tc_bus_dmamap_destroy_sgmap,
     70 	tc_bus_dmamap_load_sgmap,
     71 	tc_bus_dmamap_load_mbuf_sgmap,
     72 	tc_bus_dmamap_load_uio_sgmap,
     73 	tc_bus_dmamap_load_raw_sgmap,
     74 	tc_bus_dmamap_unload_sgmap,
     75 	_bus_dmamap_sync,
     76 	_bus_dmamem_alloc,
     77 	_bus_dmamem_free,
     78 	_bus_dmamem_map,
     79 	_bus_dmamem_unmap,
     80 	_bus_dmamem_mmap,
     81 };
     82 
     83 struct tc_dma_slot_info {
     84 	struct alpha_sgmap tdsi_sgmap;		/* sgmap for slot */
     85 	struct alpha_bus_dma_tag tdsi_dmat;	/* dma tag for slot */
     86 };
     87 struct tc_dma_slot_info *tc_dma_slot_info;
     88 
     89 void
     90 tc_dma_init_3000_500(nslots)
     91 	int nslots;
     92 {
     93 	extern struct alpha_bus_dma_tag tc_dmat_direct;
     94 	size_t sisize;
     95 	int i;
     96 
     97 	/* Allocate per-slot DMA info. */
     98 	sisize = nslots * sizeof(struct tc_dma_slot_info);
     99 	tc_dma_slot_info = malloc(sisize, M_DEVBUF, M_NOWAIT);
    100 	if (tc_dma_slot_info == NULL)
    101 		panic("tc_dma_init: can't allocate per-slot DMA info");
    102 	memset(tc_dma_slot_info, 0, sisize);
    103 
    104 	/* Default all slots to direct-mapped. */
    105 	for (i = 0; i < nslots; i++)
    106 		memcpy(&tc_dma_slot_info[i].tdsi_dmat, &tc_dmat_direct,
    107 		    sizeof(tc_dma_slot_info[i].tdsi_dmat));
    108 }
    109 
    110 /*
    111  * Return the DMA tag for the given slot.
    112  */
    113 bus_dma_tag_t
    114 tc_dma_get_tag_3000_500(slot)
    115 	int slot;
    116 {
    117 
    118 	return (&tc_dma_slot_info[slot].tdsi_dmat);
    119 }
    120 
    121 /*
    122  * Create a TurboChannel SGMAP-mapped DMA map.
    123  */
    124 int
    125 tc_bus_dmamap_create_sgmap(t, size, nsegments, maxsegsz, boundary,
    126     flags, dmamp)
    127 	bus_dma_tag_t t;
    128 	bus_size_t size;
    129 	int nsegments;
    130 	bus_size_t maxsegsz;
    131 	bus_size_t boundary;
    132 	int flags;
    133 	bus_dmamap_t *dmamp;
    134 {
    135 	bus_dmamap_t map;
    136 	int error;
    137 
    138 	error = _bus_dmamap_create(t, size, nsegments, maxsegsz,
    139 	    boundary, flags, dmamp);
    140 	if (error)
    141 		return (error);
    142 
    143 	map = *dmamp;
    144 
    145 	/* XXX BUS_DMA_ALLOCNOW */
    146 
    147 	return (error);
    148 }
    149 
    150 /*
    151  * Destroy a TurboChannel SGMAP-mapped DMA map.
    152  */
    153 void
    154 tc_bus_dmamap_destroy_sgmap(t, map)
    155 	bus_dma_tag_t t;
    156 	bus_dmamap_t map;
    157 {
    158 
    159 	KASSERT(map->dm_mapsize == 0);
    160 
    161 	_bus_dmamap_destroy(t, map);
    162 }
    163 
    164 /*
    165  * Load a TurboChannel SGMAP-mapped DMA map with a linear buffer.
    166  */
    167 int
    168 tc_bus_dmamap_load_sgmap(t, map, buf, buflen, p, flags)
    169 	bus_dma_tag_t t;
    170 	bus_dmamap_t map;
    171 	void *buf;
    172 	bus_size_t buflen;
    173 	struct proc *p;
    174 	int flags;
    175 {
    176 	struct tc_dma_slot_info *tdsi = t->_cookie;
    177 
    178 	return (tc_sgmap_load(t, map, buf, buflen, p, flags,
    179 	    &tdsi->tdsi_sgmap));
    180 }
    181 
    182 /*
    183  * Load a TurboChannel SGMAP-mapped DMA map with an mbuf chain.
    184  */
    185 int
    186 tc_bus_dmamap_load_mbuf_sgmap(t, map, m, flags)
    187 	bus_dma_tag_t t;
    188 	bus_dmamap_t map;
    189 	struct mbuf *m;
    190 	int flags;
    191 {
    192 	struct tc_dma_slot_info *tdsi = t->_cookie;
    193 
    194 	return (tc_sgmap_load_mbuf(t, map, m, flags, &tdsi->tdsi_sgmap));
    195 }
    196 
    197 /*
    198  * Load a TurboChannel SGMAP-mapped DMA map with a uio.
    199  */
    200 int
    201 tc_bus_dmamap_load_uio_sgmap(t, map, uio, flags)
    202 	bus_dma_tag_t t;
    203 	bus_dmamap_t map;
    204 	struct uio *uio;
    205 	int flags;
    206 {
    207 	struct tc_dma_slot_info *tdsi = t->_cookie;
    208 
    209 	return (tc_sgmap_load_uio(t, map, uio, flags, &tdsi->tdsi_sgmap));
    210 }
    211 
    212 /*
    213  * Load a TurboChannel SGMAP-mapped DMA map with raw memory.
    214  */
    215 int
    216 tc_bus_dmamap_load_raw_sgmap(t, map, segs, nsegs, size, flags)
    217 	bus_dma_tag_t t;
    218 	bus_dmamap_t map;
    219 	bus_dma_segment_t *segs;
    220 	int nsegs;
    221 	bus_size_t size;
    222 	int flags;
    223 {
    224 	struct tc_dma_slot_info *tdsi = t->_cookie;
    225 
    226 	return (tc_sgmap_load_raw(t, map, segs, nsegs, size, flags,
    227 	    &tdsi->tdsi_sgmap));
    228 }
    229 
    230 /*
    231  * Unload a TurboChannel SGMAP-mapped DMA map.
    232  */
    233 void
    234 tc_bus_dmamap_unload_sgmap(t, map)
    235 	bus_dma_tag_t t;
    236 	bus_dmamap_t map;
    237 {
    238 	struct tc_dma_slot_info *tdsi = t->_cookie;
    239 
    240 	/*
    241 	 * Invalidate any SGMAP page table entries used by this
    242 	 * mapping.
    243 	 */
    244 	tc_sgmap_unload(t, map, &tdsi->tdsi_sgmap);
    245 
    246 	/*
    247 	 * Do the generic bits of the unload.
    248 	 */
    249 	_bus_dmamap_unload(t, map);
    250 }
    251