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