193070Stmm/*-
293070Stmm * Copyright (c) 1997, 1998 Justin T. Gibbs.
393070Stmm * Copyright (c) 2002 by Thomas Moestl <tmm@FreeBSD.org>.
493070Stmm * All rights reserved.
593070Stmm *
693070Stmm * Redistribution and use in source and binary forms, with or without
793070Stmm * modification, are permitted provided that the following conditions
893070Stmm * are met:
993070Stmm * 1. Redistributions of source code must retain the above copyright
1093070Stmm *    notice, this list of conditions and the following disclaimer.
1193070Stmm * 2. Redistributions in binary form must reproduce the above copyright
1293070Stmm *    notice, this list of conditions and the following disclaimer in the
1393070Stmm *    documentation and/or other materials provided with the distribution.
1493070Stmm *
1593070Stmm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1693070Stmm * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1793070Stmm * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1893070Stmm * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
1993070Stmm * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
2093070Stmm * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
2193070Stmm * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
2293070Stmm * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
2393070Stmm * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
2493070Stmm * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2593070Stmm *
2693070Stmm *	from: FreeBSD: src/sys/i386/i386/busdma_machdep.c,v 1.25 2002/01/05
2793070Stmm *
2893070Stmm * $FreeBSD: releng/10.3/sys/sparc64/include/bus_private.h 225931 2011-10-02 23:22:38Z marius $
2993070Stmm */
3093070Stmm
3193070Stmm#ifndef	_MACHINE_BUS_PRIVATE_H_
3293070Stmm#define	_MACHINE_BUS_PRIVATE_H_
3393070Stmm
3493070Stmm#include <sys/queue.h>
3593070Stmm
36109651Stmm/*
37116541Stmm * Helpers
38116541Stmm */
39225931Smariusint sparc64_bus_mem_map(bus_space_tag_t tag, bus_addr_t addr, bus_size_t size,
40225931Smarius    int flags, vm_offset_t vaddr, bus_space_handle_t *hp);
41225931Smariusint sparc64_bus_mem_unmap(bus_space_tag_t tag, bus_space_handle_t handle,
42225931Smarius    bus_size_t size);
43225931Smariusbus_space_tag_t sparc64_alloc_bus_tag(void *cookie,
44225931Smarius    struct bus_space_tag *ptag, int type, void *barrier);
45225931Smariusbus_space_handle_t sparc64_fake_bustag(int space, bus_addr_t addr,
46225931Smarius    struct bus_space_tag *ptag);
47116541Stmm
48108830Stmmstruct bus_dmamap_res {
49108830Stmm	struct resource		*dr_res;
50108830Stmm	bus_size_t		dr_used;
51108830Stmm	SLIST_ENTRY(bus_dmamap_res)	dr_link;
52108830Stmm};
53108830Stmm
54117390Stmm/*
55117390Stmm * Callers of the bus_dma interfaces must always protect their tags and maps
56117390Stmm * appropriately against concurrent access. However, when a map is on a LRU
57117390Stmm * queue, there is a second access path to it; for this case, the locking rules
58117390Stmm * are given in the parenthesized comments below:
59117390Stmm *	q - locked by the mutex protecting the queue.
60117390Stmm *	p - private to the owner of the map, no access through the queue.
61117390Stmm *	* - comment refers to pointer target.
62117390Stmm * Only the owner of the map is allowed to insert the map into a queue. Removal
63117390Stmm * and repositioning (i.e. temporal removal and reinsertion) is allowed to all
64117390Stmm * if the queue lock is held.
65117390Stmm */
6693070Stmmstruct bus_dmamap {
67117390Stmm	TAILQ_ENTRY(bus_dmamap)	dm_maplruq;		/* (q) */
68117390Stmm	SLIST_HEAD(, bus_dmamap_res)	dm_reslist;	/* (q, *q) */
69117390Stmm	int			dm_onq;			/* (q) */
70117390Stmm	int			dm_flags;		/* (p) */
7193070Stmm};
7293070Stmm
73188456Smarius/* Flag values */
74188456Smarius#define	DMF_LOADED	(1 << 0)	/* Map is loaded. */
75188456Smarius#define	DMF_COHERENT	(1 << 1)	/* Coherent mapping requested. */
76188456Smarius#define	DMF_STREAMED	(1 << 2)	/* Streaming cache used. */
77117390Stmm
78116541Stmmint sparc64_dma_alloc_map(bus_dma_tag_t dmat, bus_dmamap_t *mapp);
79116541Stmmvoid sparc64_dma_free_map(bus_dma_tag_t dmat, bus_dmamap_t map);
80108830Stmm
8193070Stmm#endif /* !_MACHINE_BUS_PRIVATE_H_ */
82