Home | History | Annotate | Line # | Download | only in pci
ttwoga_dma.c revision 1.1
      1  1.1  thorpej /* $NetBSD: ttwoga_dma.c,v 1.1 2000/12/21 20:51:55 thorpej Exp $ */
      2  1.1  thorpej 
      3  1.1  thorpej /*-
      4  1.1  thorpej  * Copyright (c) 1999 The NetBSD Foundation, Inc.
      5  1.1  thorpej  * All rights reserved.
      6  1.1  thorpej  *
      7  1.1  thorpej  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1  thorpej  * by Jason R. Thorpe.
      9  1.1  thorpej  *
     10  1.1  thorpej  * Redistribution and use in source and binary forms, with or without
     11  1.1  thorpej  * modification, are permitted provided that the following conditions
     12  1.1  thorpej  * are met:
     13  1.1  thorpej  * 1. Redistributions of source code must retain the above copyright
     14  1.1  thorpej  *    notice, this list of conditions and the following disclaimer.
     15  1.1  thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1  thorpej  *    notice, this list of conditions and the following disclaimer in the
     17  1.1  thorpej  *    documentation and/or other materials provided with the distribution.
     18  1.1  thorpej  * 3. All advertising materials mentioning features or use of this software
     19  1.1  thorpej  *    must display the following acknowledgement:
     20  1.1  thorpej  *	This product includes software developed by the NetBSD
     21  1.1  thorpej  *	Foundation, Inc. and its contributors.
     22  1.1  thorpej  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.1  thorpej  *    contributors may be used to endorse or promote products derived
     24  1.1  thorpej  *    from this software without specific prior written permission.
     25  1.1  thorpej  *
     26  1.1  thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.1  thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.1  thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.1  thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.1  thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.1  thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.1  thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.1  thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.1  thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.1  thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.1  thorpej  * POSSIBILITY OF SUCH DAMAGE.
     37  1.1  thorpej  */
     38  1.1  thorpej 
     39  1.1  thorpej #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     40  1.1  thorpej 
     41  1.1  thorpej __KERNEL_RCSID(0, "$NetBSD: ttwoga_dma.c,v 1.1 2000/12/21 20:51:55 thorpej Exp $");
     42  1.1  thorpej 
     43  1.1  thorpej #include <sys/param.h>
     44  1.1  thorpej #include <sys/systm.h>
     45  1.1  thorpej #include <sys/kernel.h>
     46  1.1  thorpej #include <sys/device.h>
     47  1.1  thorpej 
     48  1.1  thorpej #include <uvm/uvm_extern.h>
     49  1.1  thorpej 
     50  1.1  thorpej #define	_ALPHA_BUS_DMA_PRIVATE
     51  1.1  thorpej #include <machine/bus.h>
     52  1.1  thorpej 
     53  1.1  thorpej #include <dev/pci/pcireg.h>
     54  1.1  thorpej #include <dev/pci/pcivar.h>
     55  1.1  thorpej 
     56  1.1  thorpej #include <alpha/pci/ttwogareg.h>
     57  1.1  thorpej #include <alpha/pci/ttwogavar.h>
     58  1.1  thorpej 
     59  1.1  thorpej bus_dma_tag_t ttwoga_dma_get_tag(bus_dma_tag_t, alpha_bus_t);
     60  1.1  thorpej 
     61  1.1  thorpej int	ttwoga_bus_dmamap_create_sgmap(bus_dma_tag_t, bus_size_t, int,
     62  1.1  thorpej 	    bus_size_t, bus_size_t, int, bus_dmamap_t *);
     63  1.1  thorpej 
     64  1.1  thorpej void	ttwoga_bus_dmamap_destroy_sgmap(bus_dma_tag_t, bus_dmamap_t);
     65  1.1  thorpej 
     66  1.1  thorpej int	ttwoga_bus_dmamap_load_sgmap(bus_dma_tag_t, bus_dmamap_t, void *,
     67  1.1  thorpej 	    bus_size_t, struct proc *, int);
     68  1.1  thorpej 
     69  1.1  thorpej int	ttwoga_bus_dmamap_load_mbuf_sgmap(bus_dma_tag_t, bus_dmamap_t,
     70  1.1  thorpej 	    struct mbuf *, int);
     71  1.1  thorpej 
     72  1.1  thorpej int	ttwoga_bus_dmamap_load_uio_sgmap(bus_dma_tag_t, bus_dmamap_t,
     73  1.1  thorpej 	    struct uio *, int);
     74  1.1  thorpej 
     75  1.1  thorpej int	ttwoga_bus_dmamap_load_raw_sgmap(bus_dma_tag_t, bus_dmamap_t,
     76  1.1  thorpej 	    bus_dma_segment_t *, int, bus_size_t, int);
     77  1.1  thorpej 
     78  1.1  thorpej void	ttwoga_bus_dmamap_unload_sgmap(bus_dma_tag_t, bus_dmamap_t);
     79  1.1  thorpej 
     80  1.1  thorpej /*
     81  1.1  thorpej  * Direct-mapped window: 1G at 1G
     82  1.1  thorpej  */
     83  1.1  thorpej #define	TTWOGA_DIRECT_MAPPED_BASE	(1UL*1024UL*1024UL*1024UL)
     84  1.1  thorpej #define	TTWOGA_DIRECT_MAPPED_SIZE	(1UL*1024UL*1024UL*1024UL)
     85  1.1  thorpej 
     86  1.1  thorpej /*
     87  1.1  thorpej  * SGMAP window: 8M at 8M
     88  1.1  thorpej  */
     89  1.1  thorpej #define	TTWOGA_SGMAP_MAPPED_BASE	(8UL*1024UL*1024UL)
     90  1.1  thorpej #define	TTWOGA_SGMAP_MAPPED_SIZE	(8UL*1024UL*1024UL)
     91  1.1  thorpej 
     92  1.1  thorpej /*
     93  1.1  thorpej  * Macro to flush the T2 Gate Array scatter/gather TLB.
     94  1.1  thorpej  */
     95  1.1  thorpej #define	TTWOGA_TLB_INVALIDATE(tcp)					\
     96  1.1  thorpej do {									\
     97  1.1  thorpej 	u_int64_t temp;							\
     98  1.1  thorpej 									\
     99  1.1  thorpej 	alpha_mb();							\
    100  1.1  thorpej 	temp = T2GA((tcp), T2_IOCSR);					\
    101  1.1  thorpej 	T2GA((tcp), T2_IOCSR) = temp | IOCSR_FTLB;			\
    102  1.1  thorpej 	alpha_mb();							\
    103  1.1  thorpej 	alpha_mb();	/* MAGIC */					\
    104  1.1  thorpej 	T2GA((tcp), T2_IOCSR) = temp;					\
    105  1.1  thorpej 	alpha_mb();							\
    106  1.1  thorpej 	alpha_mb();	/* MAGIC */					\
    107  1.1  thorpej } while (0)
    108  1.1  thorpej 
    109  1.1  thorpej void
    110  1.1  thorpej ttwoga_dma_init(struct ttwoga_config *tcp)
    111  1.1  thorpej {
    112  1.1  thorpej 	bus_dma_tag_t t;
    113  1.1  thorpej 
    114  1.1  thorpej 	/*
    115  1.1  thorpej 	 * Initialize the DMA tag used for direct-mapped DMA.
    116  1.1  thorpej 	 */
    117  1.1  thorpej 	t = &tcp->tc_dmat_direct;
    118  1.1  thorpej 	t->_cookie = tcp;
    119  1.1  thorpej 	t->_wbase = TTWOGA_DIRECT_MAPPED_BASE;
    120  1.1  thorpej 	t->_wsize = TTWOGA_DIRECT_MAPPED_SIZE;
    121  1.1  thorpej 	t->_next_window = NULL;
    122  1.1  thorpej 	t->_boundary = 0;
    123  1.1  thorpej 	t->_sgmap = NULL;
    124  1.1  thorpej 	t->_get_tag = ttwoga_dma_get_tag;
    125  1.1  thorpej 	t->_dmamap_create = _bus_dmamap_create;
    126  1.1  thorpej 	t->_dmamap_destroy = _bus_dmamap_destroy;
    127  1.1  thorpej 	t->_dmamap_load = _bus_dmamap_load_direct;
    128  1.1  thorpej 	t->_dmamap_load_mbuf = _bus_dmamap_load_mbuf_direct;
    129  1.1  thorpej 	t->_dmamap_load_uio = _bus_dmamap_load_uio_direct;
    130  1.1  thorpej 	t->_dmamap_load_raw = _bus_dmamap_load_raw_direct;
    131  1.1  thorpej 	t->_dmamap_unload = _bus_dmamap_unload;
    132  1.1  thorpej 	t->_dmamap_sync = _bus_dmamap_sync;
    133  1.1  thorpej 
    134  1.1  thorpej 	t->_dmamem_alloc = _bus_dmamem_alloc;
    135  1.1  thorpej 	t->_dmamem_free = _bus_dmamem_free;
    136  1.1  thorpej 	t->_dmamem_map = _bus_dmamem_map;
    137  1.1  thorpej 	t->_dmamem_unmap = _bus_dmamem_unmap;
    138  1.1  thorpej 	t->_dmamem_mmap = _bus_dmamem_mmap;
    139  1.1  thorpej 
    140  1.1  thorpej 	/*
    141  1.1  thorpej 	 * Initialize the DMA tag used for sgmap-mapped DMA.
    142  1.1  thorpej 	 */
    143  1.1  thorpej 	t = &tcp->tc_dmat_sgmap;
    144  1.1  thorpej 	t->_cookie = tcp;
    145  1.1  thorpej 	t->_wbase = TTWOGA_SGMAP_MAPPED_BASE;
    146  1.1  thorpej 	t->_wsize = TTWOGA_SGMAP_MAPPED_SIZE;
    147  1.1  thorpej 	t->_next_window = NULL;
    148  1.1  thorpej 	t->_boundary = 0;
    149  1.1  thorpej 	t->_sgmap = &tcp->tc_sgmap;
    150  1.1  thorpej 	t->_get_tag = ttwoga_dma_get_tag;
    151  1.1  thorpej 	t->_dmamap_create = ttwoga_bus_dmamap_create_sgmap;
    152  1.1  thorpej 	t->_dmamap_destroy = ttwoga_bus_dmamap_destroy_sgmap;
    153  1.1  thorpej 	t->_dmamap_load = ttwoga_bus_dmamap_load_sgmap;
    154  1.1  thorpej 	t->_dmamap_load_mbuf = ttwoga_bus_dmamap_load_mbuf_sgmap;
    155  1.1  thorpej 	t->_dmamap_load_uio = ttwoga_bus_dmamap_load_uio_sgmap;
    156  1.1  thorpej 	t->_dmamap_load_raw = ttwoga_bus_dmamap_load_raw_sgmap;
    157  1.1  thorpej 	t->_dmamap_unload = ttwoga_bus_dmamap_unload_sgmap;
    158  1.1  thorpej 	t->_dmamap_sync = _bus_dmamap_sync;
    159  1.1  thorpej 
    160  1.1  thorpej 	t->_dmamem_alloc = _bus_dmamem_alloc;
    161  1.1  thorpej 	t->_dmamem_free = _bus_dmamem_free;
    162  1.1  thorpej 	t->_dmamem_map = _bus_dmamem_map;
    163  1.1  thorpej 	t->_dmamem_unmap = _bus_dmamem_unmap;
    164  1.1  thorpej 	t->_dmamem_mmap = _bus_dmamem_mmap;
    165  1.1  thorpej 
    166  1.1  thorpej 	/*
    167  1.1  thorpej 	 * Disable the SGMAP TLB, and flush it.  We reenable it if
    168  1.1  thorpej 	 * we have a Sable or a Gamma with T3 or T4; Gamma with T2
    169  1.1  thorpej 	 * has a TLB bug apparently severe enough to require disabling
    170  1.1  thorpej 	 * it.
    171  1.1  thorpej 	 */
    172  1.1  thorpej 	alpha_mb();
    173  1.1  thorpej 	T2GA(tcp, T2_IOCSR) &= ~IOCSR_ETLB;
    174  1.1  thorpej 	alpha_mb();
    175  1.1  thorpej 	alpha_mb();	/* MAGIC */
    176  1.1  thorpej 
    177  1.1  thorpej 	TTWOGA_TLB_INVALIDATE(tcp);
    178  1.1  thorpej 
    179  1.1  thorpej 	/*
    180  1.1  thorpej 	 * XXX We might want to make sure our DMA windows don't
    181  1.1  thorpej 	 * XXX overlap with PCI memory space!
    182  1.1  thorpej 	 */
    183  1.1  thorpej 
    184  1.1  thorpej 	/*
    185  1.1  thorpej 	 * Set up window 1 as a 1G direct-mapped window
    186  1.1  thorpej 	 * starting at 1G.
    187  1.1  thorpej 	 */
    188  1.1  thorpej 	T2GA(tcp, T2_WBASE1) = 0;
    189  1.1  thorpej 	alpha_mb();
    190  1.1  thorpej 
    191  1.1  thorpej 	T2GA(tcp, T2_WMASK1) = (TTWOGA_DIRECT_MAPPED_SIZE - 1) & WMASKx_PWM;
    192  1.1  thorpej 	alpha_mb();
    193  1.1  thorpej 
    194  1.1  thorpej 	T2GA(tcp, T2_TBASE1) = 0;
    195  1.1  thorpej 	alpha_mb();
    196  1.1  thorpej 
    197  1.1  thorpej 	T2GA(tcp, T2_WBASE1) = TTWOGA_DIRECT_MAPPED_BASE |
    198  1.1  thorpej 	    ((TTWOGA_DIRECT_MAPPED_BASE + (TTWOGA_DIRECT_MAPPED_SIZE - 1)) >>
    199  1.1  thorpej 	     WBASEx_PWxA_SHIFT) | WBASEx_PWE;
    200  1.1  thorpej 	alpha_mb();
    201  1.1  thorpej 
    202  1.1  thorpej 	/*
    203  1.1  thorpej 	 * Initialize the SGMAP.
    204  1.1  thorpej 	 */
    205  1.1  thorpej 	alpha_sgmap_init(t, &tcp->tc_sgmap, "ttwoga_sgmap",
    206  1.1  thorpej 	    TTWOGA_SGMAP_MAPPED_BASE, 0, TTWOGA_SGMAP_MAPPED_SIZE,
    207  1.1  thorpej 	    sizeof(u_int64_t), NULL, 0);
    208  1.1  thorpej 
    209  1.1  thorpej 	/*
    210  1.1  thorpej 	 * Set up window 2 as an 8MB SGMAP-mapped window
    211  1.1  thorpej 	 * starting at 8MB.
    212  1.1  thorpej 	 */
    213  1.1  thorpej #ifdef DIAGNOSTIC
    214  1.1  thorpej 	if ((TTWOGA_SGMAP_MAPPED_BASE & WBASEx_PWSA) !=
    215  1.1  thorpej 	    TTWOGA_SGMAP_MAPPED_BASE)
    216  1.1  thorpej 		panic("ttwoga_dma_init: SGMAP base inconsistency");
    217  1.1  thorpej #endif
    218  1.1  thorpej 	T2GA(tcp, T2_WBASE2) = 0;
    219  1.1  thorpej 	alpha_mb();
    220  1.1  thorpej 
    221  1.1  thorpej 	T2GA(tcp, T2_WMASK2) = (TTWOGA_SGMAP_MAPPED_SIZE - 1) & WMASKx_PWM;
    222  1.1  thorpej 	alpha_mb();
    223  1.1  thorpej 
    224  1.1  thorpej 	T2GA(tcp, T2_TBASE2) = tcp->tc_sgmap.aps_ptpa >> 1;
    225  1.1  thorpej 	alpha_mb();
    226  1.1  thorpej 
    227  1.1  thorpej 	T2GA(tcp, T2_WBASE2) = TTWOGA_SGMAP_MAPPED_BASE |
    228  1.1  thorpej 	    ((TTWOGA_SGMAP_MAPPED_BASE + (TTWOGA_SGMAP_MAPPED_SIZE - 1)) >>
    229  1.1  thorpej 	     WBASEx_PWxA_SHIFT) | WBASEx_SGE | WBASEx_PWE;
    230  1.1  thorpej 	alpha_mb();
    231  1.1  thorpej 
    232  1.1  thorpej 	/*
    233  1.1  thorpej 	 * Enable SGMAP TLB on Sable or Gamma with T3 or T4; see above.
    234  1.1  thorpej 	 */
    235  1.1  thorpej 	if (alpha_implver() == ALPHA_IMPLVER_EV4 ||
    236  1.1  thorpej 	    tcp->tc_rev >= TRN_T3) {
    237  1.1  thorpej 		alpha_mb();
    238  1.1  thorpej 		T2GA(tcp, T2_IOCSR) |= IOCSR_ETLB;
    239  1.1  thorpej 		alpha_mb();
    240  1.1  thorpej 		alpha_mb();	/* MAGIC */
    241  1.1  thorpej 		tcp->tc_use_tlb = 1;
    242  1.1  thorpej 	}
    243  1.1  thorpej 
    244  1.1  thorpej 	/* XXX XXX BEGIN XXX XXX */
    245  1.1  thorpej 	{							/* XXX */
    246  1.1  thorpej 		extern paddr_t alpha_XXX_dmamap_or;		/* XXX */
    247  1.1  thorpej 		alpha_XXX_dmamap_or = TTWOGA_DIRECT_MAPPED_BASE;/* XXX */
    248  1.1  thorpej 	}							/* XXX */
    249  1.1  thorpej 	/* XXX XXX END XXX XXX */
    250  1.1  thorpej }
    251  1.1  thorpej 
    252  1.1  thorpej /*
    253  1.1  thorpej  * Return the bus dma tag to be used for the specified bus type.
    254  1.1  thorpej  * INTERNAL USE ONLY!
    255  1.1  thorpej  */
    256  1.1  thorpej bus_dma_tag_t
    257  1.1  thorpej ttwoga_dma_get_tag(bus_dma_tag_t t, alpha_bus_t bustype)
    258  1.1  thorpej {
    259  1.1  thorpej 	struct ttwoga_config *tcp = t->_cookie;
    260  1.1  thorpej 
    261  1.1  thorpej 	switch (bustype) {
    262  1.1  thorpej 	case ALPHA_BUS_PCI:
    263  1.1  thorpej 	case ALPHA_BUS_EISA:
    264  1.1  thorpej 		/*
    265  1.1  thorpej 		 * Systems with a T2 Gate Array can have 2G
    266  1.1  thorpej 		 * of memory, but we only get a direct-mapped
    267  1.1  thorpej 		 * window of 1G!
    268  1.1  thorpej 		 *
    269  1.1  thorpej 		 * XXX FIX THIS SOMEDAY!
    270  1.1  thorpej 		 */
    271  1.1  thorpej 		return (&tcp->tc_dmat_direct);
    272  1.1  thorpej 
    273  1.1  thorpej 	case ALPHA_BUS_ISA:
    274  1.1  thorpej 		/*
    275  1.1  thorpej 		 * ISA doesn't have enough address bits to use
    276  1.1  thorpej 		 * the direct-mapped DMA window, so we must use
    277  1.1  thorpej 		 * SGMAPs.
    278  1.1  thorpej 		 */
    279  1.1  thorpej 		return (&tcp->tc_dmat_sgmap);
    280  1.1  thorpej 
    281  1.1  thorpej 	default:
    282  1.1  thorpej 		panic("ttwoga_dma_get_tag: shouldn't be here, really...");
    283  1.1  thorpej 	}
    284  1.1  thorpej }
    285  1.1  thorpej 
    286  1.1  thorpej /*
    287  1.1  thorpej  * Create a T2 SGMAP-mapped DMA map.
    288  1.1  thorpej  */
    289  1.1  thorpej int
    290  1.1  thorpej ttwoga_bus_dmamap_create_sgmap(bus_dma_tag_t t, bus_size_t size, int nsegments,
    291  1.1  thorpej     bus_size_t maxsegsz, bus_size_t boundary, int flags, bus_dmamap_t *dmamp)
    292  1.1  thorpej {
    293  1.1  thorpej 	bus_dmamap_t map;
    294  1.1  thorpej 	int error;
    295  1.1  thorpej 
    296  1.1  thorpej 	error = _bus_dmamap_create(t, size, nsegments, maxsegsz,
    297  1.1  thorpej 	    boundary, flags, dmamp);
    298  1.1  thorpej 	if (error)
    299  1.1  thorpej 		return (error);
    300  1.1  thorpej 
    301  1.1  thorpej 	map = *dmamp;
    302  1.1  thorpej 
    303  1.1  thorpej 	if (flags & BUS_DMA_ALLOCNOW) {
    304  1.1  thorpej 		error = alpha_sgmap_alloc(map, round_page(size),
    305  1.1  thorpej 		    t->_sgmap, flags);
    306  1.1  thorpej 		if (error)
    307  1.1  thorpej 			ttwoga_bus_dmamap_destroy_sgmap(t, map);
    308  1.1  thorpej 	}
    309  1.1  thorpej 
    310  1.1  thorpej 	return (error);
    311  1.1  thorpej }
    312  1.1  thorpej 
    313  1.1  thorpej /*
    314  1.1  thorpej  * Destroy a T2 SGMAP-mapped DMA map.
    315  1.1  thorpej  */
    316  1.1  thorpej void
    317  1.1  thorpej ttwoga_bus_dmamap_destroy_sgmap(bus_dma_tag_t t, bus_dmamap_t map)
    318  1.1  thorpej {
    319  1.1  thorpej 
    320  1.1  thorpej 	if (map->_dm_flags & DMAMAP_HAS_SGMAP)
    321  1.1  thorpej 		alpha_sgmap_free(map, t->_sgmap);
    322  1.1  thorpej 
    323  1.1  thorpej 	_bus_dmamap_destroy(t, map);
    324  1.1  thorpej }
    325  1.1  thorpej 
    326  1.1  thorpej /*
    327  1.1  thorpej  * Load a T2 SGMAP-mapped DMA map with a liner buffer.
    328  1.1  thorpej  */
    329  1.1  thorpej int
    330  1.1  thorpej ttwoga_bus_dmamap_load_sgmap(bus_dma_tag_t t, bus_dmamap_t map, void *buf,
    331  1.1  thorpej     bus_size_t buflen, struct proc *p, int flags)
    332  1.1  thorpej {
    333  1.1  thorpej 	struct ttwoga_config *tcp = t->_cookie;
    334  1.1  thorpej 	int error;
    335  1.1  thorpej 
    336  1.1  thorpej 	error = pci_sgmap_pte64_load(t, map, buf, buflen, p, flags,
    337  1.1  thorpej 	    t->_sgmap);
    338  1.1  thorpej 	if (error == 0 && tcp->tc_use_tlb)
    339  1.1  thorpej 		TTWOGA_TLB_INVALIDATE(tcp);
    340  1.1  thorpej 
    341  1.1  thorpej 	return (error);
    342  1.1  thorpej }
    343  1.1  thorpej 
    344  1.1  thorpej /*
    345  1.1  thorpej  * Load a T2 SGMAP-mapped DMA map with an mbuf chain.
    346  1.1  thorpej  */
    347  1.1  thorpej int
    348  1.1  thorpej ttwoga_bus_dmamap_load_mbuf_sgmap(bus_dma_tag_t t, bus_dmamap_t map,
    349  1.1  thorpej     struct mbuf *m, int flags)
    350  1.1  thorpej {
    351  1.1  thorpej 	struct ttwoga_config *tcp = t->_cookie;
    352  1.1  thorpej 	int error;
    353  1.1  thorpej 
    354  1.1  thorpej 	error = pci_sgmap_pte64_load_mbuf(t, map, m, flags, t->_sgmap);
    355  1.1  thorpej 	if (error == 0 && tcp->tc_use_tlb)
    356  1.1  thorpej 		TTWOGA_TLB_INVALIDATE(tcp);
    357  1.1  thorpej 
    358  1.1  thorpej 	return (error);
    359  1.1  thorpej }
    360  1.1  thorpej 
    361  1.1  thorpej /*
    362  1.1  thorpej  * Load a T2 SGMAP-mapped DMA map with a uio.
    363  1.1  thorpej  */
    364  1.1  thorpej int
    365  1.1  thorpej ttwoga_bus_dmamap_load_uio_sgmap(bus_dma_tag_t t, bus_dmamap_t map,
    366  1.1  thorpej     struct uio *uio, int flags)
    367  1.1  thorpej {
    368  1.1  thorpej 	struct ttwoga_config *tcp = t->_cookie;
    369  1.1  thorpej 	int error;
    370  1.1  thorpej 
    371  1.1  thorpej 	error = pci_sgmap_pte64_load_uio(t, map, uio, flags, t->_sgmap);
    372  1.1  thorpej 	if (error == 0 && tcp->tc_use_tlb)
    373  1.1  thorpej 		TTWOGA_TLB_INVALIDATE(tcp);
    374  1.1  thorpej 
    375  1.1  thorpej 	return (error);
    376  1.1  thorpej }
    377  1.1  thorpej 
    378  1.1  thorpej /*
    379  1.1  thorpej  * Load a T2 SGMAP-mapped DMA map with raw memory.
    380  1.1  thorpej  */
    381  1.1  thorpej int
    382  1.1  thorpej ttwoga_bus_dmamap_load_raw_sgmap(bus_dma_tag_t t, bus_dmamap_t map,
    383  1.1  thorpej     bus_dma_segment_t *segs, int nsegs, bus_size_t size, int flags)
    384  1.1  thorpej {
    385  1.1  thorpej 	struct ttwoga_config *tcp = t->_cookie;
    386  1.1  thorpej 	int error;
    387  1.1  thorpej 
    388  1.1  thorpej 	error = pci_sgmap_pte64_load_raw(t, map, segs, nsegs, size, flags,
    389  1.1  thorpej 	    t->_sgmap);
    390  1.1  thorpej 	if (error == 0 && tcp->tc_use_tlb)
    391  1.1  thorpej 		TTWOGA_TLB_INVALIDATE(tcp);
    392  1.1  thorpej 
    393  1.1  thorpej 	return (error);
    394  1.1  thorpej }
    395  1.1  thorpej 
    396  1.1  thorpej /*
    397  1.1  thorpej  * Unload an T2 DMA map.
    398  1.1  thorpej  */
    399  1.1  thorpej void
    400  1.1  thorpej ttwoga_bus_dmamap_unload_sgmap(bus_dma_tag_t t, bus_dmamap_t map)
    401  1.1  thorpej {
    402  1.1  thorpej 	struct ttwoga_config *tcp = t->_cookie;
    403  1.1  thorpej 
    404  1.1  thorpej 	/*
    405  1.1  thorpej 	 * Invalidate any SGMAP page table entries used by this
    406  1.1  thorpej 	 * mapping.
    407  1.1  thorpej 	 */
    408  1.1  thorpej 	pci_sgmap_pte64_unload(t, map, t->_sgmap);
    409  1.1  thorpej 	if (tcp->tc_use_tlb)
    410  1.1  thorpej 		TTWOGA_TLB_INVALIDATE(tcp);
    411  1.1  thorpej 
    412  1.1  thorpej 	/*
    413  1.1  thorpej 	 * Do the generic bits of the unload.
    414  1.1  thorpej 	 */
    415  1.1  thorpej 	_bus_dmamap_unload(t, map);
    416  1.1  thorpej }
    417