fwdma.h revision 1.1 1 1.1 kiyohara /* $NetBSD: fwdma.h,v 1.1 2005/07/11 15:29:05 kiyohara Exp $ */
2 1.1 kiyohara /*-
3 1.1 kiyohara * Copyright (C) 2003
4 1.1 kiyohara * Hidetoshi Shimokawa. All rights reserved.
5 1.1 kiyohara *
6 1.1 kiyohara * Redistribution and use in source and binary forms, with or without
7 1.1 kiyohara * modification, are permitted provided that the following conditions
8 1.1 kiyohara * are met:
9 1.1 kiyohara * 1. Redistributions of source code must retain the above copyright
10 1.1 kiyohara * notice, this list of conditions and the following disclaimer.
11 1.1 kiyohara * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 kiyohara * notice, this list of conditions and the following disclaimer in the
13 1.1 kiyohara * documentation and/or other materials provided with the distribution.
14 1.1 kiyohara * 3. All advertising materials mentioning features or use of this software
15 1.1 kiyohara * must display the following acknowledgement:
16 1.1 kiyohara *
17 1.1 kiyohara * This product includes software developed by Hidetoshi Shimokawa.
18 1.1 kiyohara *
19 1.1 kiyohara * 4. Neither the name of the author nor the names of its contributors
20 1.1 kiyohara * may be used to endorse or promote products derived from this software
21 1.1 kiyohara * without specific prior written permission.
22 1.1 kiyohara *
23 1.1 kiyohara * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 1.1 kiyohara * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 1.1 kiyohara * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 1.1 kiyohara * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 1.1 kiyohara * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 1.1 kiyohara * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 1.1 kiyohara * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 1.1 kiyohara * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 1.1 kiyohara * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 1.1 kiyohara * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 1.1 kiyohara * SUCH DAMAGE.
34 1.1 kiyohara *
35 1.1 kiyohara * $FreeBSD: /repoman/r/ncvs/src/sys/dev/firewire/fwdma.h,v 1.3 2005/01/06 01:42:41 imp Exp $
36 1.1 kiyohara */
37 1.1 kiyohara
38 1.1 kiyohara struct fwdma_alloc {
39 1.1 kiyohara fw_bus_dma_tag_t fw_dma_tag;
40 1.1 kiyohara bus_dmamap_t dma_map;
41 1.1 kiyohara void * v_addr;
42 1.1 kiyohara bus_addr_t bus_addr;
43 1.1 kiyohara };
44 1.1 kiyohara
45 1.1 kiyohara struct fwdma_seg {
46 1.1 kiyohara bus_dmamap_t dma_map;
47 1.1 kiyohara void * v_addr;
48 1.1 kiyohara bus_addr_t bus_addr;
49 1.1 kiyohara };
50 1.1 kiyohara
51 1.1 kiyohara struct fwdma_alloc_multi {
52 1.1 kiyohara bus_size_t ssize;
53 1.1 kiyohara bus_size_t esize;
54 1.1 kiyohara int nseg;
55 1.1 kiyohara fw_bus_dma_tag_t fw_dma_tag;
56 1.1 kiyohara struct fwdma_seg seg[0];
57 1.1 kiyohara };
58 1.1 kiyohara
59 1.1 kiyohara static __inline void *
60 1.1 kiyohara fwdma_v_addr(struct fwdma_alloc_multi *am, int index)
61 1.1 kiyohara {
62 1.1 kiyohara bus_size_t ssize = am->ssize;
63 1.1 kiyohara int offset = am->esize * index;
64 1.1 kiyohara
65 1.1 kiyohara return ((caddr_t)am->seg[offset / ssize].v_addr + (offset % ssize));
66 1.1 kiyohara }
67 1.1 kiyohara
68 1.1 kiyohara static __inline bus_addr_t
69 1.1 kiyohara fwdma_bus_addr(struct fwdma_alloc_multi *am, int index)
70 1.1 kiyohara {
71 1.1 kiyohara bus_size_t ssize = am->ssize;
72 1.1 kiyohara int offset = am->esize * index;
73 1.1 kiyohara
74 1.1 kiyohara return (am->seg[offset / ssize].bus_addr + (offset % ssize));
75 1.1 kiyohara }
76 1.1 kiyohara
77 1.1 kiyohara static __inline void
78 1.1 kiyohara fwdma_sync(struct fwdma_alloc *dma, bus_dmasync_op_t op)
79 1.1 kiyohara {
80 1.1 kiyohara fw_bus_dmamap_sync(dma->fw_dma_tag, dma->dma_map, op);
81 1.1 kiyohara }
82 1.1 kiyohara
83 1.1 kiyohara static __inline void
84 1.1 kiyohara fwdma_sync_multiseg(struct fwdma_alloc_multi *am,
85 1.1 kiyohara int start, int end, bus_dmasync_op_t op)
86 1.1 kiyohara {
87 1.1 kiyohara struct fwdma_seg *seg, *eseg;
88 1.1 kiyohara
89 1.1 kiyohara seg = &am->seg[am->esize * start / am->ssize];
90 1.1 kiyohara eseg = &am->seg[am->esize * end / am->ssize];
91 1.1 kiyohara for (; seg <= eseg; seg ++)
92 1.1 kiyohara fw_bus_dmamap_sync(am->fw_dma_tag, seg->dma_map, op);
93 1.1 kiyohara }
94 1.1 kiyohara
95 1.1 kiyohara static __inline void
96 1.1 kiyohara fwdma_sync_multiseg_all(struct fwdma_alloc_multi *am, bus_dmasync_op_t op)
97 1.1 kiyohara {
98 1.1 kiyohara struct fwdma_seg *seg;
99 1.1 kiyohara int i;
100 1.1 kiyohara
101 1.1 kiyohara seg = &am->seg[0];
102 1.1 kiyohara for (i = 0; i < am->nseg; i++, seg++)
103 1.1 kiyohara fw_bus_dmamap_sync(am->fw_dma_tag, seg->dma_map, op);
104 1.1 kiyohara }
105 1.1 kiyohara
106 1.1 kiyohara void *fwdma_malloc(struct firewire_comm *, int, bus_size_t, struct fwdma_alloc *, int);
107 1.1 kiyohara void fwdma_free(struct firewire_comm *, struct fwdma_alloc *);
108 1.1 kiyohara void *fwdma_malloc_size(
109 1.1 kiyohara fw_bus_dma_tag_t, bus_dmamap_t *, bus_size_t, bus_addr_t *, int);
110 1.1 kiyohara void fwdma_free_size(fw_bus_dma_tag_t, bus_dmamap_t, void *, bus_size_t);
111 1.1 kiyohara struct fwdma_alloc_multi *fwdma_malloc_multiseg(struct firewire_comm *,
112 1.1 kiyohara int, int, int, int);
113 1.1 kiyohara void fwdma_free_multiseg(struct fwdma_alloc_multi *);
114 1.1 kiyohara
115