2 * Copyright(c) 2020 Cornelis Networks, Inc.
3 * Copyright(c) 2016 Intel Corporation.
5 * This file is provided under a dual BSD/GPLv2 license. When using or
6 * redistributing this file, you may do so under either license.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
21 * Redistribution and use in source and binary forms, with or without
22 * modification, are permitted provided that the following conditions
25 * - Redistributions of source code must retain the above copyright
26 * notice, this list of conditions and the following disclaimer.
27 * - Redistributions in binary form must reproduce the above copyright
28 * notice, this list of conditions and the following disclaimer in
29 * the documentation and/or other materials provided with the
31 * - Neither the name of Intel Corporation nor the names of its
32 * contributors may be used to endorse or promote products derived
33 * from this software without specific prior written permission.
35 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
36 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
37 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
38 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
39 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
42 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
43 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
44 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
45 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48 #ifndef _HFI1_MMU_RB_H
49 #define _HFI1_MMU_RB_H
58 struct mmu_rb_handler *handler;
59 struct list_head list;
63 * NOTE: filter, insert, invalidate, and evict must not sleep. Only remove is
67 bool (*filter)(struct mmu_rb_node *node, unsigned long addr,
69 int (*insert)(void *ops_arg, struct mmu_rb_node *mnode);
70 void (*remove)(void *ops_arg, struct mmu_rb_node *mnode);
71 int (*invalidate)(void *ops_arg, struct mmu_rb_node *node);
72 int (*evict)(void *ops_arg, struct mmu_rb_node *mnode,
73 void *evict_arg, bool *stop);
76 struct mmu_rb_handler {
77 struct mmu_notifier mn;
78 struct rb_root_cached root;
80 spinlock_t lock; /* protect the RB tree */
81 struct mmu_rb_ops *ops;
82 struct list_head lru_list;
83 struct work_struct del_work;
84 struct list_head del_list;
85 struct workqueue_struct *wq;
88 int hfi1_mmu_rb_register(void *ops_arg,
89 struct mmu_rb_ops *ops,
90 struct workqueue_struct *wq,
91 struct mmu_rb_handler **handler);
92 void hfi1_mmu_rb_unregister(struct mmu_rb_handler *handler);
93 int hfi1_mmu_rb_insert(struct mmu_rb_handler *handler,
94 struct mmu_rb_node *mnode);
95 void hfi1_mmu_rb_evict(struct mmu_rb_handler *handler, void *evict_arg);
96 void hfi1_mmu_rb_remove(struct mmu_rb_handler *handler,
97 struct mmu_rb_node *mnode);
98 bool hfi1_mmu_rb_remove_unless_exact(struct mmu_rb_handler *handler,
99 unsigned long addr, unsigned long len,
100 struct mmu_rb_node **rb_node);
102 #endif /* _HFI1_MMU_RB_H */