1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Support for Medifield PNW Camera Imaging ISP subsystem. 4 * 5 * Copyright (c) 2010 Intel Corporation. All Rights Reserved. 6 * 7 * Copyright (c) 2010 Silicon Hive www.siliconhive.com. 8 * 9 * This program is free software; you can redistribute it and/or 10 * modify it under the terms of the GNU General Public License version 11 * 2 as published by the Free Software Foundation. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * 19 */ 20 #ifndef __HMM_POOL_H__ 21 #define __HMM_POOL_H__ 22 23 #include <linux/kernel.h> 24 #include <linux/slab.h> 25 #include <linux/list.h> 26 #include <linux/spinlock.h> 27 #include <linux/mutex.h> 28 #include <linux/kref.h> 29 #include "hmm_common.h" 30 #include "hmm/hmm_bo.h" 31 32 #define ALLOC_PAGE_FAIL_NUM 5 33 34 enum hmm_pool_type { 35 HMM_POOL_TYPE_RESERVED, 36 HMM_POOL_TYPE_DYNAMIC, 37 }; 38 39 /** 40 * struct hmm_pool_ops - memory pool callbacks. 41 * 42 * @pool_init: initialize the memory pool. 43 * @pool_exit: uninitialize the memory pool. 44 * @pool_alloc_pages: allocate pages from memory pool. 45 * @pool_free_pages: free pages to memory pool. 46 * @pool_inited: check whether memory pool is initialized. 47 */ 48 struct hmm_pool_ops { 49 int (*pool_init)(void **pool, unsigned int pool_size); 50 void (*pool_exit)(void **pool); 51 unsigned int (*pool_alloc_pages)(void *pool, 52 struct hmm_page_object *page_obj, 53 unsigned int size, bool cached); 54 void (*pool_free_pages)(void *pool, 55 struct hmm_page_object *page_obj); 56 int (*pool_inited)(void *pool); 57 }; 58 59 struct hmm_pool { 60 struct hmm_pool_ops *pops; 61 62 void *pool_info; 63 }; 64 65 /** 66 * struct hmm_reserved_pool_info - represents reserved pool private data. 67 * @pages: a array that store physical pages. 68 * The array is as reserved memory pool. 69 * @index: to indicate the first blank page number 70 * in reserved memory pool(pages array). 71 * @pgnr: the valid page amount in reserved memory 72 * pool. 73 * @list_lock: list lock is used to protect the operation 74 * to reserved memory pool. 75 * @flag: reserved memory pool state flag. 76 */ 77 struct hmm_reserved_pool_info { 78 struct page **pages; 79 80 unsigned int index; 81 unsigned int pgnr; 82 spinlock_t list_lock; 83 bool initialized; 84 }; 85 86 /** 87 * struct hmm_dynamic_pool_info - represents dynamic pool private data. 88 * @pages_list: a list that store physical pages. 89 * The pages list is as dynamic memory pool. 90 * @list_lock: list lock is used to protect the operation 91 * to dynamic memory pool. 92 * @flag: dynamic memory pool state flag. 93 * @pgptr_cache: struct kmem_cache, manages a cache. 94 */ 95 struct hmm_dynamic_pool_info { 96 struct list_head pages_list; 97 98 /* list lock is used to protect the free pages block lists */ 99 spinlock_t list_lock; 100 101 struct kmem_cache *pgptr_cache; 102 bool initialized; 103 104 unsigned int pool_size; 105 unsigned int pgnr; 106 }; 107 108 struct hmm_page { 109 struct page *page; 110 struct list_head list; 111 }; 112 113 extern struct hmm_pool_ops reserved_pops; 114 extern struct hmm_pool_ops dynamic_pops; 115 116 #endif 117