scatterlist.h revision 1.6 1 /* $NetBSD: scatterlist.h,v 1.6 2021/12/19 11:38:04 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 <linux/mm.h>
38 #include <linux/mm_types.h>
39 #include <linux/gfp.h>
40 #include <linux/types.h>
41
42 /* namespace */
43 #define __sg_alloc_table_from_pages linux___sg_alloc_table_from_pages
44 #define dma_map_sg linux_dma_map_sg
45 #define dma_map_sg_attrs linux_dma_map_sg_attrs
46 #define dma_unmap_sg linux_dma_unmap_sg
47 #define dma_unmap_sg_attrs linux_dma_unmap_sg_attrs
48 #define sg_alloc_table linux_sg_alloc_table
49 #define sg_alloc_table_from_bus_dmamem linux_sg_alloc_table_from_bus_dmamem
50 #define sg_alloc_table_from_pages linux_sg_alloc_table_from_pages
51 #define sg_dma_address linux_sg_dma_address
52 #define sg_dma_len linux_sg_dma_len
53 #define sg_free_table linux_sg_free_table
54
55 struct page;
56
57 struct sg_table {
58 struct scatterlist {
59 struct page **sg_pgs;
60 unsigned sg_npgs;
61 bus_dmamap_t sg_dmamap;
62 } sgl[1];
63 unsigned nents;
64 };
65
66 int sg_alloc_table(struct sg_table *, unsigned, gfp_t);
67 int __sg_alloc_table_from_pages(struct sg_table *, struct page **, unsigned,
68 bus_size_t, bus_size_t, unsigned, gfp_t);
69 int sg_alloc_table_from_pages(struct sg_table *, struct page **, unsigned,
70 bus_size_t, bus_size_t, gfp_t);
71 int sg_alloc_table_from_bus_dmamem(struct sg_table *, bus_dma_tag_t,
72 const bus_dma_segment_t *, int, gfp_t);
73 void sg_free_table(struct sg_table *);
74
75 bus_addr_t sg_dma_address(const struct scatterlist *);
76 bus_size_t sg_dma_len(const struct scatterlist *);
77
78 int dma_map_sg(bus_dma_tag_t, struct scatterlist *, int, int);
79 int dma_map_sg_attrs(bus_dma_tag_t, struct scatterlist *, int, int, int);
80 void dma_unmap_sg(bus_dma_tag_t, struct scatterlist *, int, int);
81 void dma_unmap_sg_attrs(bus_dma_tag_t, struct scatterlist *, int, int, int);
82
83 #endif /* _LINUX_SCATTERLIST_H_ */
84