1/*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (c) 1997, 1998 Justin T. Gibbs.
5 * Copyright (c) 2002 by Thomas Moestl <tmm@FreeBSD.org>.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in the
15 *    documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
21 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
26 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 *	from: FreeBSD: src/sys/i386/i386/busdma_machdep.c,v 1.25 2002/01/05
29 *
30 * $FreeBSD$
31 */
32
33#ifndef	_MACHINE_BUS_PRIVATE_H_
34#define	_MACHINE_BUS_PRIVATE_H_
35
36#include <sys/queue.h>
37
38/*
39 * Helpers
40 */
41int sparc64_bus_mem_map(bus_space_tag_t tag, bus_addr_t addr, bus_size_t size,
42    int flags, vm_offset_t vaddr, bus_space_handle_t *hp);
43int sparc64_bus_mem_unmap(bus_space_tag_t tag, bus_space_handle_t handle,
44    bus_size_t size);
45bus_space_tag_t sparc64_alloc_bus_tag(void *cookie, int type);
46bus_space_handle_t sparc64_fake_bustag(int space, bus_addr_t addr,
47    struct bus_space_tag *ptag);
48
49struct bus_dmamap_res {
50	struct resource		*dr_res;
51	bus_size_t		dr_used;
52	SLIST_ENTRY(bus_dmamap_res)	dr_link;
53};
54
55/*
56 * Callers of the bus_dma interfaces must always protect their tags and maps
57 * appropriately against concurrent access. However, when a map is on a LRU
58 * queue, there is a second access path to it; for this case, the locking rules
59 * are given in the parenthesized comments below:
60 *	q - locked by the mutex protecting the queue.
61 *	p - private to the owner of the map, no access through the queue.
62 *	* - comment refers to pointer target.
63 * Only the owner of the map is allowed to insert the map into a queue. Removal
64 * and repositioning (i.e. temporal removal and reinsertion) is allowed to all
65 * if the queue lock is held.
66 */
67struct bus_dmamap {
68	TAILQ_ENTRY(bus_dmamap)	dm_maplruq;		/* (q) */
69	SLIST_HEAD(, bus_dmamap_res)	dm_reslist;	/* (q, *q) */
70	int			dm_onq;			/* (q) */
71	int			dm_flags;		/* (p) */
72};
73
74/* Flag values */
75#define	DMF_LOADED	(1 << 0)	/* Map is loaded. */
76#define	DMF_COHERENT	(1 << 1)	/* Coherent mapping requested. */
77#define	DMF_STREAMED	(1 << 2)	/* Streaming cache used. */
78
79int sparc64_dma_alloc_map(bus_dma_tag_t dmat, bus_dmamap_t *mapp);
80void sparc64_dma_free_map(bus_dma_tag_t dmat, bus_dmamap_t map);
81
82#endif /* !_MACHINE_BUS_PRIVATE_H_ */
83