Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 OR MIT */
0002 /*
0003  * Copyright 2020 Advanced Micro Devices, Inc.
0004  *
0005  * Permission is hereby granted, free of charge, to any person obtaining a
0006  * copy of this software and associated documentation files (the "Software"),
0007  * to deal in the Software without restriction, including without limitation
0008  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
0009  * and/or sell copies of the Software, and to permit persons to whom the
0010  * Software is furnished to do so, subject to the following conditions:
0011  *
0012  * The above copyright notice and this permission notice shall be included in
0013  * all copies or substantial portions of the Software.
0014  *
0015  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0016  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0017  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
0018  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
0019  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
0020  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
0021  * OTHER DEALINGS IN THE SOFTWARE.
0022  *
0023  * Authors: Christian König
0024  */
0025 
0026 #ifndef _TTM_PAGE_POOL_H_
0027 #define _TTM_PAGE_POOL_H_
0028 
0029 #include <linux/mmzone.h>
0030 #include <linux/llist.h>
0031 #include <linux/spinlock.h>
0032 #include <drm/ttm/ttm_caching.h>
0033 
0034 struct device;
0035 struct ttm_tt;
0036 struct ttm_pool;
0037 struct ttm_operation_ctx;
0038 
0039 /**
0040  * struct ttm_pool_type - Pool for a certain memory type
0041  *
0042  * @pool: the pool we belong to, might be NULL for the global ones
0043  * @order: the allocation order our pages have
0044  * @caching: the caching type our pages have
0045  * @shrinker_list: our place on the global shrinker list
0046  * @lock: protection of the page list
0047  * @pages: the list of pages in the pool
0048  */
0049 struct ttm_pool_type {
0050     struct ttm_pool *pool;
0051     unsigned int order;
0052     enum ttm_caching caching;
0053 
0054     struct list_head shrinker_list;
0055 
0056     spinlock_t lock;
0057     struct list_head pages;
0058 };
0059 
0060 /**
0061  * struct ttm_pool - Pool for all caching and orders
0062  *
0063  * @dev: the device we allocate pages for
0064  * @use_dma_alloc: if coherent DMA allocations should be used
0065  * @use_dma32: if GFP_DMA32 should be used
0066  * @caching: pools for each caching/order
0067  */
0068 struct ttm_pool {
0069     struct device *dev;
0070 
0071     bool use_dma_alloc;
0072     bool use_dma32;
0073 
0074     struct {
0075         struct ttm_pool_type orders[MAX_ORDER];
0076     } caching[TTM_NUM_CACHING_TYPES];
0077 };
0078 
0079 int ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
0080            struct ttm_operation_ctx *ctx);
0081 void ttm_pool_free(struct ttm_pool *pool, struct ttm_tt *tt);
0082 
0083 void ttm_pool_init(struct ttm_pool *pool, struct device *dev,
0084            bool use_dma_alloc, bool use_dma32);
0085 void ttm_pool_fini(struct ttm_pool *pool);
0086 
0087 int ttm_pool_debugfs(struct ttm_pool *pool, struct seq_file *m);
0088 
0089 int ttm_pool_mgr_init(unsigned long num_pages);
0090 void ttm_pool_mgr_fini(void);
0091 
0092 #endif