Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/sys/compat/linuxkpi/common/include/linux/dmapool.h
39604 views
1
/*-
2
* Copyright (c) 2010 Isilon Systems, Inc.
3
* Copyright (c) 2010 iX Systems, Inc.
4
* Copyright (c) 2010 Panasas, Inc.
5
* Copyright (c) 2013, 2014 Mellanox Technologies, Ltd.
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 unmodified, this list of conditions, and the following
13
* disclaimer.
14
* 2. Redistributions in binary form must reproduce the above copyright
15
* notice, this list of conditions and the following disclaimer in the
16
* documentation and/or other materials provided with the distribution.
17
*
18
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
*/
29
#ifndef _LINUXKPI_LINUX_DMAPOOL_H_
30
#define _LINUXKPI_LINUX_DMAPOOL_H_
31
32
#include <linux/types.h>
33
#include <linux/io.h>
34
#include <linux/scatterlist.h>
35
#include <linux/device.h>
36
#include <linux/slab.h>
37
38
struct dma_pool;
39
struct dma_pool *linux_dma_pool_create(char *name, struct device *dev,
40
size_t size, size_t align, size_t boundary);
41
void linux_dma_pool_destroy(struct dma_pool *pool);
42
void lkpi_dmam_pool_destroy(struct device *, void *);
43
void *linux_dma_pool_alloc(struct dma_pool *pool, gfp_t mem_flags,
44
dma_addr_t *handle);
45
void linux_dma_pool_free(struct dma_pool *pool, void *vaddr,
46
dma_addr_t dma_addr);
47
48
static inline struct dma_pool *
49
dma_pool_create(char *name, struct device *dev, size_t size,
50
size_t align, size_t boundary)
51
{
52
53
return (linux_dma_pool_create(name, dev, size, align, boundary));
54
}
55
56
static inline struct dma_pool *
57
dmam_pool_create(/* const */ char *name, struct device *dev, size_t size,
58
size_t align, size_t boundary)
59
{
60
struct dma_pool **pp;
61
62
pp = devres_alloc(lkpi_dmam_pool_destroy, sizeof(*pp), GFP_KERNEL);
63
if (pp == NULL)
64
return (NULL);
65
*pp = linux_dma_pool_create(name, dev, size, align, boundary);
66
if (*pp == NULL) {
67
devres_free(pp);
68
return (NULL);
69
}
70
71
devres_add(dev, pp);
72
return (*pp);
73
}
74
75
static inline void
76
dma_pool_destroy(struct dma_pool *pool)
77
{
78
79
linux_dma_pool_destroy(pool);
80
}
81
82
static inline void *
83
dma_pool_alloc(struct dma_pool *pool, gfp_t mem_flags, dma_addr_t *handle)
84
{
85
86
return (linux_dma_pool_alloc(pool, mem_flags, handle));
87
}
88
89
static inline void *
90
dma_pool_zalloc(struct dma_pool *pool, gfp_t mem_flags, dma_addr_t *handle)
91
{
92
93
return (dma_pool_alloc(pool, mem_flags | __GFP_ZERO, handle));
94
}
95
96
static inline void
97
dma_pool_free(struct dma_pool *pool, void *vaddr, dma_addr_t dma_addr)
98
{
99
100
linux_dma_pool_free(pool, vaddr, dma_addr);
101
}
102
103
#endif /* _LINUXKPI_LINUX_DMAPOOL_H_ */
104
105