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