mmu_rb.h (1802B)
1/* SPDX-License-Identifier: GPL-2.0 or BSD-3-Clause */ 2/* 3 * Copyright(c) 2020 Cornelis Networks, Inc. 4 * Copyright(c) 2016 Intel Corporation. 5 */ 6 7#ifndef _HFI1_MMU_RB_H 8#define _HFI1_MMU_RB_H 9 10#include "hfi.h" 11 12struct mmu_rb_node { 13 unsigned long addr; 14 unsigned long len; 15 unsigned long __last; 16 struct rb_node node; 17 struct mmu_rb_handler *handler; 18 struct list_head list; 19}; 20 21/* 22 * NOTE: filter, insert, invalidate, and evict must not sleep. Only remove is 23 * allowed to sleep. 24 */ 25struct mmu_rb_ops { 26 bool (*filter)(struct mmu_rb_node *node, unsigned long addr, 27 unsigned long len); 28 int (*insert)(void *ops_arg, struct mmu_rb_node *mnode); 29 void (*remove)(void *ops_arg, struct mmu_rb_node *mnode); 30 int (*invalidate)(void *ops_arg, struct mmu_rb_node *node); 31 int (*evict)(void *ops_arg, struct mmu_rb_node *mnode, 32 void *evict_arg, bool *stop); 33}; 34 35struct mmu_rb_handler { 36 struct mmu_notifier mn; 37 struct rb_root_cached root; 38 void *ops_arg; 39 spinlock_t lock; /* protect the RB tree */ 40 struct mmu_rb_ops *ops; 41 struct list_head lru_list; 42 struct work_struct del_work; 43 struct list_head del_list; 44 struct workqueue_struct *wq; 45}; 46 47int hfi1_mmu_rb_register(void *ops_arg, 48 struct mmu_rb_ops *ops, 49 struct workqueue_struct *wq, 50 struct mmu_rb_handler **handler); 51void hfi1_mmu_rb_unregister(struct mmu_rb_handler *handler); 52int hfi1_mmu_rb_insert(struct mmu_rb_handler *handler, 53 struct mmu_rb_node *mnode); 54void hfi1_mmu_rb_evict(struct mmu_rb_handler *handler, void *evict_arg); 55void hfi1_mmu_rb_remove(struct mmu_rb_handler *handler, 56 struct mmu_rb_node *mnode); 57bool hfi1_mmu_rb_remove_unless_exact(struct mmu_rb_handler *handler, 58 unsigned long addr, unsigned long len, 59 struct mmu_rb_node **rb_node); 60 61#endif /* _HFI1_MMU_RB_H */