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