scatterlist.h revision 1.8 1 /* $NetBSD: scatterlist.h,v 1.8 2021/12/19 12:13:23 riastradh Exp $ */
2
3 /*-
4 * Copyright (c) 2018 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Taylor R. Campbell.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #ifndef _LINUX_SCATTERLIST_H_
33 #define _LINUX_SCATTERLIST_H_
34
35 #include <sys/bus.h>
36
37 #include <asm/io.h>
38
39 #include <linux/mm.h>
40 #include <linux/mm_types.h>
41 #include <linux/gfp.h>
42 #include <linux/types.h>
43
44 /* namespace */
45 #define __sg_alloc_table_from_pages linux___sg_alloc_table_from_pages
46 #define dma_map_sg linux_dma_map_sg
47 #define dma_map_sg_attrs linux_dma_map_sg_attrs
48 #define dma_unmap_sg linux_dma_unmap_sg
49 #define dma_unmap_sg_attrs linux_dma_unmap_sg_attrs
50 #define sg_alloc_table linux_sg_alloc_table
51 #define sg_alloc_table_from_bus_dmamem linux_sg_alloc_table_from_bus_dmamem
52 #define sg_alloc_table_from_pages linux_sg_alloc_table_from_pages
53 #define sg_dma_address linux_sg_dma_address
54 #define sg_dma_len linux_sg_dma_len
55 #define sg_free_table linux_sg_free_table
56
57 struct page;
58
59 struct sg_table {
60 struct scatterlist {
61 struct page **sg_pgs;
62 unsigned sg_npgs;
63 bus_dma_tag_t sg_dmat;
64 bus_dmamap_t sg_dmamap;
65 } sgl[1];
66 unsigned nents;
67 };
68
69 int sg_alloc_table(struct sg_table *, unsigned, gfp_t);
70 int __sg_alloc_table_from_pages(struct sg_table *, struct page **, unsigned,
71 bus_size_t, bus_size_t, unsigned, gfp_t);
72 int sg_alloc_table_from_pages(struct sg_table *, struct page **, unsigned,
73 bus_size_t, bus_size_t, gfp_t);
74 int sg_alloc_table_from_bus_dmamem(struct sg_table *, bus_dma_tag_t,
75 const bus_dma_segment_t *, int, gfp_t);
76 void sg_free_table(struct sg_table *);
77
78 bus_addr_t sg_dma_address(const struct scatterlist *);
79 bus_size_t sg_dma_len(const struct scatterlist *);
80
81 int dma_map_sg(bus_dma_tag_t, struct scatterlist *, int, int);
82 int dma_map_sg_attrs(bus_dma_tag_t, struct scatterlist *, int, int, int);
83 void dma_unmap_sg(bus_dma_tag_t, struct scatterlist *, int, int);
84 void dma_unmap_sg_attrs(bus_dma_tag_t, struct scatterlist *, int, int, int);
85
86 #endif /* _LINUX_SCATTERLIST_H_ */
87