xref: /openbmc/linux/include/drm/ttm/ttm_pool.h (revision c1e01cdbe0312d95b8c1542abd67fe786b534f57)
1d099fc8fSChristian König /* SPDX-License-Identifier: GPL-2.0 OR MIT */
2d099fc8fSChristian König /*
3d099fc8fSChristian König  * Copyright 2020 Advanced Micro Devices, Inc.
4d099fc8fSChristian König  *
5d099fc8fSChristian König  * Permission is hereby granted, free of charge, to any person obtaining a
6d099fc8fSChristian König  * copy of this software and associated documentation files (the "Software"),
7d099fc8fSChristian König  * to deal in the Software without restriction, including without limitation
8d099fc8fSChristian König  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9d099fc8fSChristian König  * and/or sell copies of the Software, and to permit persons to whom the
10d099fc8fSChristian König  * Software is furnished to do so, subject to the following conditions:
11d099fc8fSChristian König  *
12d099fc8fSChristian König  * The above copyright notice and this permission notice shall be included in
13d099fc8fSChristian König  * all copies or substantial portions of the Software.
14d099fc8fSChristian König  *
15d099fc8fSChristian König  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16d099fc8fSChristian König  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17d099fc8fSChristian König  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18d099fc8fSChristian König  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
19d099fc8fSChristian König  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20d099fc8fSChristian König  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21d099fc8fSChristian König  * OTHER DEALINGS IN THE SOFTWARE.
22d099fc8fSChristian König  *
23d099fc8fSChristian König  * Authors: Christian König
24d099fc8fSChristian König  */
25d099fc8fSChristian König 
26d099fc8fSChristian König #ifndef _TTM_PAGE_POOL_H_
27d099fc8fSChristian König #define _TTM_PAGE_POOL_H_
28d099fc8fSChristian König 
29d099fc8fSChristian König #include <linux/mmzone.h>
30d099fc8fSChristian König #include <linux/llist.h>
31d099fc8fSChristian König #include <linux/spinlock.h>
32d099fc8fSChristian König #include <drm/ttm/ttm_caching.h>
33d099fc8fSChristian König 
34d099fc8fSChristian König struct device;
35d099fc8fSChristian König struct ttm_tt;
36d099fc8fSChristian König struct ttm_pool;
37d099fc8fSChristian König struct ttm_operation_ctx;
38d099fc8fSChristian König 
39d099fc8fSChristian König /**
40361da7c3SChristian König  * struct ttm_pool_type - Pool for a certain memory type
41d099fc8fSChristian König  *
42d099fc8fSChristian König  * @pool: the pool we belong to, might be NULL for the global ones
43d099fc8fSChristian König  * @order: the allocation order our pages have
44d099fc8fSChristian König  * @caching: the caching type our pages have
45d099fc8fSChristian König  * @shrinker_list: our place on the global shrinker list
46d099fc8fSChristian König  * @lock: protection of the page list
47d099fc8fSChristian König  * @pages: the list of pages in the pool
48d099fc8fSChristian König  */
49d099fc8fSChristian König struct ttm_pool_type {
50d099fc8fSChristian König 	struct ttm_pool *pool;
51d099fc8fSChristian König 	unsigned int order;
52d099fc8fSChristian König 	enum ttm_caching caching;
53d099fc8fSChristian König 
54d099fc8fSChristian König 	struct list_head shrinker_list;
55d099fc8fSChristian König 
56d099fc8fSChristian König 	spinlock_t lock;
57d099fc8fSChristian König 	struct list_head pages;
58d099fc8fSChristian König };
59d099fc8fSChristian König 
60d099fc8fSChristian König /**
61361da7c3SChristian König  * struct ttm_pool - Pool for all caching and orders
62d099fc8fSChristian König  *
63361da7c3SChristian König  * @dev: the device we allocate pages for
644482d3c9SRajneesh Bhardwaj  * @nid: which numa node to use
65d099fc8fSChristian König  * @use_dma_alloc: if coherent DMA allocations should be used
66d099fc8fSChristian König  * @use_dma32: if GFP_DMA32 should be used
67d099fc8fSChristian König  * @caching: pools for each caching/order
68d099fc8fSChristian König  */
69d099fc8fSChristian König struct ttm_pool {
70d099fc8fSChristian König 	struct device *dev;
714482d3c9SRajneesh Bhardwaj 	int nid;
72d099fc8fSChristian König 
73d099fc8fSChristian König 	bool use_dma_alloc;
74d099fc8fSChristian König 	bool use_dma32;
75d099fc8fSChristian König 
76d099fc8fSChristian König 	struct {
77*ded1ffeaSKirill A. Shutemov 		struct ttm_pool_type orders[NR_PAGE_ORDERS];
78d099fc8fSChristian König 	} caching[TTM_NUM_CACHING_TYPES];
79d099fc8fSChristian König };
80d099fc8fSChristian König 
81d099fc8fSChristian König int ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
82d099fc8fSChristian König 		   struct ttm_operation_ctx *ctx);
83d099fc8fSChristian König void ttm_pool_free(struct ttm_pool *pool, struct ttm_tt *tt);
84d099fc8fSChristian König 
85d099fc8fSChristian König void ttm_pool_init(struct ttm_pool *pool, struct device *dev,
864482d3c9SRajneesh Bhardwaj 		   int nid, bool use_dma_alloc, bool use_dma32);
87d099fc8fSChristian König void ttm_pool_fini(struct ttm_pool *pool);
88d099fc8fSChristian König 
89d099fc8fSChristian König int ttm_pool_debugfs(struct ttm_pool *pool, struct seq_file *m);
90d099fc8fSChristian König 
91d099fc8fSChristian König int ttm_pool_mgr_init(unsigned long num_pages);
92d099fc8fSChristian König void ttm_pool_mgr_fini(void);
93d099fc8fSChristian König 
94d099fc8fSChristian König #endif
95