bus_private.h revision 1.3
1/*	$NetBSD: bus_private.h,v 1.3 2005/08/22 11:09:39 bouyer Exp $	*/
2/*	NetBSD: bus.h,v 1.8 2005/03/09 19:04:46 matt Exp	*/
3
4/*-
5 * Copyright (c) 1996, 1997, 1998, 2001 The NetBSD Foundation, Inc.
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
10 * NASA Ames Research Center.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 *    notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 *    notice, this list of conditions and the following disclaimer in the
19 *    documentation and/or other materials provided with the distribution.
20 * 3. All advertising materials mentioning features or use of this software
21 *    must display the following acknowledgement:
22 *	This product includes software developed by the NetBSD
23 *	Foundation, Inc. and its contributors.
24 * 4. Neither the name of The NetBSD Foundation nor the names of its
25 *    contributors may be used to endorse or promote products derived
26 *    from this software without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
29 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
32 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 * POSSIBILITY OF SUCH DAMAGE.
39 */
40
41/*
42 * Copyright (c) 1996 Charles M. Hannum.  All rights reserved.
43 * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
44 *
45 * Redistribution and use in source and binary forms, with or without
46 * modification, are permitted provided that the following conditions
47 * are met:
48 * 1. Redistributions of source code must retain the above copyright
49 *    notice, this list of conditions and the following disclaimer.
50 * 2. Redistributions in binary form must reproduce the above copyright
51 *    notice, this list of conditions and the following disclaimer in the
52 *    documentation and/or other materials provided with the distribution.
53 * 3. All advertising materials mentioning features or use of this software
54 *    must display the following acknowledgement:
55 *      This product includes software developed by Christopher G. Demetriou
56 *	for the NetBSD Project.
57 * 4. The name of the author may not be used to endorse or promote products
58 *    derived from this software without specific prior written permission
59 *
60 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
61 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
62 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
63 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
64 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
65 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
66 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
67 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
68 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
69 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
70 */
71
72#if !defined(_X86_BUS_PRIVATE_H_)
73#define	_X86_BUS_PRIVATE_H_
74
75int	_bus_dmamap_create(bus_dma_tag_t, bus_size_t, int, bus_size_t,
76	    bus_size_t, int, bus_dmamap_t *);
77void	_bus_dmamap_destroy(bus_dma_tag_t, bus_dmamap_t);
78int	_bus_dmamap_load(bus_dma_tag_t, bus_dmamap_t, void *,
79	    bus_size_t, struct proc *, int);
80int	_bus_dmamap_load_mbuf(bus_dma_tag_t, bus_dmamap_t,
81	    struct mbuf *, int);
82int	_bus_dmamap_load_uio(bus_dma_tag_t, bus_dmamap_t,
83	    struct uio *, int);
84int	_bus_dmamap_load_raw(bus_dma_tag_t, bus_dmamap_t,
85	    bus_dma_segment_t *, int, bus_size_t, int);
86void	_bus_dmamap_unload(bus_dma_tag_t, bus_dmamap_t);
87void	_bus_dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_addr_t,
88	    bus_size_t, int);
89
90int	_bus_dmamem_alloc(bus_dma_tag_t tag, bus_size_t size,
91	    bus_size_t alignment, bus_size_t boundary,
92	    bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags);
93void	_bus_dmamem_free(bus_dma_tag_t tag, bus_dma_segment_t *segs,
94	    int nsegs);
95int	_bus_dmamem_map(bus_dma_tag_t tag, bus_dma_segment_t *segs,
96	    int nsegs, size_t size, caddr_t *kvap, int flags);
97void	_bus_dmamem_unmap(bus_dma_tag_t tag, caddr_t kva, size_t size);
98paddr_t	_bus_dmamem_mmap(bus_dma_tag_t tag, bus_dma_segment_t *segs,
99	    int nsegs, off_t off, int prot, int flags);
100
101#ifndef _BUS_DMAMEM_ALLOC_RANGE
102int	_bus_dmamem_alloc_range(bus_dma_tag_t tag, bus_size_t size,
103	    bus_size_t alignment, bus_size_t boundary,
104	    bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags,
105	    bus_addr_t low, bus_addr_t high);
106#endif
107
108/*
109 * Cookie used for bounce buffers. A pointer to one of these it stashed in
110 * the DMA map.
111 */
112struct x86_bus_dma_cookie {
113	int	id_flags;		/* flags; see below */
114
115	/*
116	 * Information about the original buffer used during
117	 * DMA map syncs.  Note that origibuflen is only used
118	 * for ID_BUFTYPE_LINEAR.
119	 */
120	void	*id_origbuf;		/* pointer to orig buffer if
121					   bouncing */
122	bus_size_t id_origbuflen;	/* ...and size */
123	int	id_buftype;		/* type of buffer */
124
125	void	*id_bouncebuf;		/* pointer to the bounce buffer */
126	bus_size_t id_bouncebuflen;	/* ...and size */
127	int	id_nbouncesegs;		/* number of valid bounce segs */
128	bus_dma_segment_t id_bouncesegs[0]; /* array of bounce buffer
129					       physical memory segments */
130};
131
132/* id_flags */
133#define	X86_DMA_MIGHT_NEED_BOUNCE	0x01	/* may need bounce buffers */
134#define	X86_DMA_HAS_BOUNCE		0x02	/* has bounce buffers */
135#define	X86_DMA_IS_BOUNCING		0x04	/* is bouncing current xfer */
136
137/* id_buftype */
138#define	X86_DMA_BUFTYPE_INVALID		0
139#define	X86_DMA_BUFTYPE_LINEAR		1
140#define	X86_DMA_BUFTYPE_MBUF		2
141#define	X86_DMA_BUFTYPE_UIO		3
142#define	X86_DMA_BUFTYPE_RAW		4
143
144/*
145 * default address translation macros, which are appropriate where
146 * paddr_t == bus_addr_t.
147 */
148
149#if !defined(_BUS_PHYS_TO_BUS)
150#define _BUS_PHYS_TO_BUS(pa)	((bus_addr_t)(pa))
151#endif /* !defined(_BUS_PHYS_TO_BUS) */
152
153#if !defined(_BUS_VM_PAGE_TO_BUS)
154#define	_BUS_VM_PAGE_TO_BUS(pg)	_BUS_PHYS_TO_BUS(VM_PAGE_TO_PHYS(pg))
155#endif /* !defined(_BUS_VM_PAGE_TO_BUS) */
156
157#if !defined(_BUS_VIRT_TO_BUS)
158#include <uvm/uvm_extern.h>
159
160static __inline bus_addr_t _bus_virt_to_bus(struct pmap *, vaddr_t);
161#define	_BUS_VIRT_TO_BUS(pm, va) _bus_virt_to_bus((pm), (va))
162
163static __inline bus_addr_t
164_bus_virt_to_bus(struct pmap *pm, vaddr_t va)
165{
166	paddr_t pa;
167
168	if (!pmap_extract(pm, va, &pa)) {
169		panic("_bus_virt_to_bus");
170	}
171
172	return _BUS_PHYS_TO_BUS(pa);
173}
174#endif /* !defined(_BUS_VIRT_TO_BUS) */
175
176/*
177 * by default, the end address of RAM visible on bus is the same as the
178 * largest physical address.
179 */
180#ifndef _BUS_AVAIL_END
181#define _BUS_AVAIL_END (avail_end)
182#endif
183
184
185#endif /* !defined(_X86_BUS_PRIVATE_H_) */
186