Home | History | Annotate | Line # | Download | only in tc
      1  1.24   thorpej /* $NetBSD: tc_dma_3000_500.c,v 1.24 2021/07/18 05:12:27 thorpej Exp $ */
      2   1.2   thorpej 
      3   1.2   thorpej /*-
      4   1.4   thorpej  * Copyright (c) 1997, 1998 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  *
     20   1.2   thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     21   1.2   thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     22   1.2   thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     23   1.2   thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     24   1.2   thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     25   1.2   thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     26   1.2   thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     27   1.2   thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     28   1.2   thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     29   1.2   thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     30   1.2   thorpej  * POSSIBILITY OF SUCH DAMAGE.
     31   1.2   thorpej  */
     32   1.2   thorpej 
     33   1.2   thorpej #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     34   1.2   thorpej 
     35  1.24   thorpej __KERNEL_RCSID(0, "$NetBSD: tc_dma_3000_500.c,v 1.24 2021/07/18 05:12:27 thorpej Exp $");
     36   1.2   thorpej 
     37   1.2   thorpej #include <sys/param.h>
     38   1.2   thorpej #include <sys/systm.h>
     39   1.9     enami #include <sys/device.h>
     40   1.2   thorpej #include <sys/kernel.h>
     41  1.23   thorpej #include <sys/kmem.h>
     42  1.10       mrg 
     43   1.2   thorpej #define _ALPHA_BUS_DMA_PRIVATE
     44  1.17    dyoung #include <sys/bus.h>
     45   1.2   thorpej 
     46   1.2   thorpej #include <dev/tc/tcvar.h>
     47   1.2   thorpej #include <alpha/tc/tc_sgmap.h>
     48   1.2   thorpej #include <alpha/tc/tc_dma_3000_500.h>
     49   1.2   thorpej 
     50   1.2   thorpej struct alpha_bus_dma_tag tc_dmat_sgmap = {
     51   1.2   thorpej 	NULL,				/* _cookie */
     52   1.6   thorpej 	0,				/* _wbase */
     53   1.7   thorpej 	0,				/* _wsize */
     54   1.7   thorpej 	NULL,				/* _next_window */
     55   1.8   thorpej 	0,				/* _boundary */
     56   1.7   thorpej 	NULL,				/* _sgmap */
     57  1.24   thorpej 	PAGE_SIZE,			/* _sgmap_minalign */
     58  1.13   thorpej 	0,				/* _pfthresh */
     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.5   thorpej 	_bus_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.15       dsl tc_dma_init_3000_500(int nslots)
     83   1.2   thorpej {
     84   1.2   thorpej 	extern struct alpha_bus_dma_tag tc_dmat_direct;
     85   1.2   thorpej 	size_t sisize;
     86   1.2   thorpej 	int i;
     87   1.2   thorpej 
     88   1.2   thorpej 	/* Allocate per-slot DMA info. */
     89   1.2   thorpej 	sisize = nslots * sizeof(struct tc_dma_slot_info);
     90  1.23   thorpej 	tc_dma_slot_info = kmem_zalloc(sisize, KM_SLEEP);
     91   1.2   thorpej 
     92   1.2   thorpej 	/* Default all slots to direct-mapped. */
     93   1.2   thorpej 	for (i = 0; i < nslots; i++)
     94  1.12   thorpej 		memcpy(&tc_dma_slot_info[i].tdsi_dmat, &tc_dmat_direct,
     95   1.2   thorpej 		    sizeof(tc_dma_slot_info[i].tdsi_dmat));
     96   1.2   thorpej }
     97   1.2   thorpej 
     98   1.2   thorpej /*
     99   1.2   thorpej  * Return the DMA tag for the given slot.
    100   1.2   thorpej  */
    101   1.2   thorpej bus_dma_tag_t
    102  1.15       dsl tc_dma_get_tag_3000_500(int slot)
    103   1.2   thorpej {
    104   1.2   thorpej 
    105   1.2   thorpej 	return (&tc_dma_slot_info[slot].tdsi_dmat);
    106   1.2   thorpej }
    107   1.2   thorpej 
    108   1.2   thorpej /*
    109  1.20      flxd  * Create a TURBOchannel SGMAP-mapped DMA map.
    110   1.2   thorpej  */
    111   1.2   thorpej int
    112  1.18      matt tc_bus_dmamap_create_sgmap(
    113  1.18      matt 	bus_dma_tag_t t,
    114  1.18      matt 	bus_size_t size,
    115  1.18      matt 	int nsegments,
    116  1.18      matt 	bus_size_t maxsegsz,
    117  1.18      matt 	bus_size_t boundary,
    118  1.18      matt 	int flags,
    119  1.18      matt 	bus_dmamap_t *dmamp)
    120   1.2   thorpej {
    121   1.2   thorpej 	int error;
    122   1.2   thorpej 
    123   1.2   thorpej 	error = _bus_dmamap_create(t, size, nsegments, maxsegsz,
    124   1.2   thorpej 	    boundary, flags, dmamp);
    125   1.2   thorpej 	if (error)
    126   1.2   thorpej 		return (error);
    127   1.2   thorpej 
    128  1.19  christos 	(void)*dmamp;
    129   1.2   thorpej 
    130  1.13   thorpej 	/* XXX BUS_DMA_ALLOCNOW */
    131   1.2   thorpej 
    132   1.2   thorpej 	return (error);
    133   1.2   thorpej }
    134   1.2   thorpej 
    135   1.2   thorpej /*
    136  1.20      flxd  * Destroy a TURBOchannel SGMAP-mapped DMA map.
    137   1.2   thorpej  */
    138   1.2   thorpej void
    139  1.15       dsl tc_bus_dmamap_destroy_sgmap(bus_dma_tag_t t, bus_dmamap_t map)
    140   1.2   thorpej {
    141   1.2   thorpej 
    142  1.13   thorpej 	KASSERT(map->dm_mapsize == 0);
    143   1.2   thorpej 
    144   1.2   thorpej 	_bus_dmamap_destroy(t, map);
    145   1.2   thorpej }
    146   1.2   thorpej 
    147   1.2   thorpej /*
    148  1.20      flxd  * Load a TURBOchannel SGMAP-mapped DMA map with a linear buffer.
    149   1.2   thorpej  */
    150   1.2   thorpej int
    151  1.15       dsl tc_bus_dmamap_load_sgmap(bus_dma_tag_t t, bus_dmamap_t map, void *buf, bus_size_t buflen, struct proc *p, int flags)
    152   1.2   thorpej {
    153   1.2   thorpej 	struct tc_dma_slot_info *tdsi = t->_cookie;
    154   1.2   thorpej 
    155   1.2   thorpej 	return (tc_sgmap_load(t, map, buf, buflen, p, flags,
    156   1.2   thorpej 	    &tdsi->tdsi_sgmap));
    157   1.2   thorpej }
    158   1.2   thorpej 
    159   1.2   thorpej /*
    160  1.20      flxd  * Load a TURBOchannel SGMAP-mapped DMA map with an mbuf chain.
    161   1.2   thorpej  */
    162   1.2   thorpej int
    163  1.15       dsl tc_bus_dmamap_load_mbuf_sgmap(bus_dma_tag_t t, bus_dmamap_t map, struct mbuf *m, int flags)
    164   1.2   thorpej {
    165   1.2   thorpej 	struct tc_dma_slot_info *tdsi = t->_cookie;
    166   1.2   thorpej 
    167   1.2   thorpej 	return (tc_sgmap_load_mbuf(t, map, m, flags, &tdsi->tdsi_sgmap));
    168   1.2   thorpej }
    169   1.2   thorpej 
    170   1.2   thorpej /*
    171  1.20      flxd  * Load a TURBOchannel SGMAP-mapped DMA map with a uio.
    172   1.2   thorpej  */
    173   1.2   thorpej int
    174  1.15       dsl tc_bus_dmamap_load_uio_sgmap(bus_dma_tag_t t, bus_dmamap_t map, struct uio *uio, int flags)
    175   1.2   thorpej {
    176   1.2   thorpej 	struct tc_dma_slot_info *tdsi = t->_cookie;
    177   1.2   thorpej 
    178   1.2   thorpej 	return (tc_sgmap_load_uio(t, map, uio, flags, &tdsi->tdsi_sgmap));
    179   1.2   thorpej }
    180   1.2   thorpej 
    181   1.2   thorpej /*
    182  1.20      flxd  * Load a TURBOchannel SGMAP-mapped DMA map with raw memory.
    183   1.2   thorpej  */
    184   1.2   thorpej int
    185  1.15       dsl tc_bus_dmamap_load_raw_sgmap(bus_dma_tag_t t, bus_dmamap_t map, bus_dma_segment_t *segs, int nsegs, bus_size_t size, int flags)
    186   1.2   thorpej {
    187   1.2   thorpej 	struct tc_dma_slot_info *tdsi = t->_cookie;
    188   1.2   thorpej 
    189   1.2   thorpej 	return (tc_sgmap_load_raw(t, map, segs, nsegs, size, flags,
    190   1.2   thorpej 	    &tdsi->tdsi_sgmap));
    191   1.2   thorpej }
    192   1.2   thorpej 
    193   1.2   thorpej /*
    194  1.20      flxd  * Unload a TURBOchannel SGMAP-mapped DMA map.
    195   1.2   thorpej  */
    196   1.2   thorpej void
    197  1.15       dsl tc_bus_dmamap_unload_sgmap(bus_dma_tag_t t, bus_dmamap_t map)
    198   1.2   thorpej {
    199   1.2   thorpej 	struct tc_dma_slot_info *tdsi = t->_cookie;
    200   1.2   thorpej 
    201   1.2   thorpej 	/*
    202   1.2   thorpej 	 * Invalidate any SGMAP page table entries used by this
    203   1.2   thorpej 	 * mapping.
    204   1.2   thorpej 	 */
    205   1.2   thorpej 	tc_sgmap_unload(t, map, &tdsi->tdsi_sgmap);
    206   1.2   thorpej 
    207   1.2   thorpej 	/*
    208   1.2   thorpej 	 * Do the generic bits of the unload.
    209   1.2   thorpej 	 */
    210  1.22   thorpej 	_bus_dmamap_unload_common(t, map);
    211   1.2   thorpej }
    212