1 /* $NetBSD: ttm_page_alloc.h,v 1.4 2021/12/18 23:45:46 riastradh Exp $ */
2
3 /*
4 * Copyright (c) Red Hat Inc.
5
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sub license,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
15 * of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
24 *
25 * Authors: Dave Airlie <airlied@redhat.com>
26 * Jerome Glisse <jglisse@redhat.com>
27 */
28 #ifndef TTM_PAGE_ALLOC
29 #define TTM_PAGE_ALLOC
30
31 #include <drm/ttm/ttm_bo_driver.h>
32 #include <drm/ttm/ttm_memory.h>
33
34 struct device;
35
36 /**
37 * Initialize pool allocator.
38 */
39 int ttm_page_alloc_init(struct ttm_mem_global *glob, unsigned max_pages);
40 /**
41 * Free pool allocator.
42 */
43 void ttm_page_alloc_fini(void);
44
45 /**
46 * ttm_pool_populate:
47 *
48 * @ttm: The struct ttm_tt to contain the backing pages.
49 *
50 * Add backing pages to all of @ttm
51 */
52 int ttm_pool_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx);
53
54 /**
55 * ttm_pool_unpopulate:
56 *
57 * @ttm: The struct ttm_tt which to free backing pages.
58 *
59 * Free all pages of @ttm
60 */
61 void ttm_pool_unpopulate(struct ttm_tt *ttm);
62
63 /**
64 * Populates and DMA maps pages to fullfil a ttm_dma_populate() request
65 */
66 int ttm_populate_and_map_pages(struct device *dev, struct ttm_dma_tt *tt,
67 struct ttm_operation_ctx *ctx);
68
69 /**
70 * Unpopulates and DMA unmaps pages as part of a
71 * ttm_dma_unpopulate() request */
72 void ttm_unmap_and_unpopulate_pages(struct device *dev, struct ttm_dma_tt *tt);
73
74 #ifdef CONFIG_DEBUG_FS
75 /**
76 * Output the state of pools to debugfs file
77 */
78 int ttm_page_alloc_debugfs(struct seq_file *m, void *data);
79 #endif
80
81 #if defined(CONFIG_DRM_TTM_DMA_PAGE_POOL)
82 /**
83 * Initialize pool allocator.
84 */
85 int ttm_dma_page_alloc_init(struct ttm_mem_global *glob, unsigned max_pages);
86
87 /**
88 * Free pool allocator.
89 */
90 void ttm_dma_page_alloc_fini(void);
91
92 #ifdef CONFIG_DEBUG_FS
93 /**
94 * Output the state of pools to debugfs file
95 */
96 int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
97 #endif CONFIG_DEBUG_FS
98
99 int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev,
100 struct ttm_operation_ctx *ctx);
101 void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
102
103 #else
ttm_dma_page_alloc_init(struct ttm_mem_global * glob,unsigned max_pages)104 static inline int ttm_dma_page_alloc_init(struct ttm_mem_global *glob,
105 unsigned max_pages)
106 {
107 return -ENODEV;
108 }
109
ttm_dma_page_alloc_fini(void)110 static inline void ttm_dma_page_alloc_fini(void) { return; }
111
112 #ifdef CONFIG_DEBUG_FS
ttm_dma_page_alloc_debugfs(struct seq_file * m,void * data)113 static inline int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data)
114 {
115 return 0;
116 }
117 #endif
ttm_dma_populate(struct ttm_dma_tt * ttm_dma,struct device * dev,struct ttm_operation_ctx * ctx)118 static inline int ttm_dma_populate(struct ttm_dma_tt *ttm_dma,
119 struct device *dev,
120 struct ttm_operation_ctx *ctx)
121 {
122 return -ENOMEM;
123 }
ttm_dma_unpopulate(struct ttm_dma_tt * ttm_dma,struct device * dev)124 static inline void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma,
125 struct device *dev)
126 {
127 }
128 #endif
129
130 #endif
131