xref: /openbmc/linux/drivers/infiniband/hw/hfi1/mmu_rb.h (revision 1034599805009394cc42e6c538575d12d8dc57fa)
1f48ad614SDennis Dalessandro /*
2f48ad614SDennis Dalessandro  * Copyright(c) 2016 Intel Corporation.
3f48ad614SDennis Dalessandro  *
4f48ad614SDennis Dalessandro  * This file is provided under a dual BSD/GPLv2 license.  When using or
5f48ad614SDennis Dalessandro  * redistributing this file, you may do so under either license.
6f48ad614SDennis Dalessandro  *
7f48ad614SDennis Dalessandro  * GPL LICENSE SUMMARY
8f48ad614SDennis Dalessandro  *
9f48ad614SDennis Dalessandro  * This program is free software; you can redistribute it and/or modify
10f48ad614SDennis Dalessandro  * it under the terms of version 2 of the GNU General Public License as
11f48ad614SDennis Dalessandro  * published by the Free Software Foundation.
12f48ad614SDennis Dalessandro  *
13f48ad614SDennis Dalessandro  * This program is distributed in the hope that it will be useful, but
14f48ad614SDennis Dalessandro  * WITHOUT ANY WARRANTY; without even the implied warranty of
15f48ad614SDennis Dalessandro  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16f48ad614SDennis Dalessandro  * General Public License for more details.
17f48ad614SDennis Dalessandro  *
18f48ad614SDennis Dalessandro  * BSD LICENSE
19f48ad614SDennis Dalessandro  *
20f48ad614SDennis Dalessandro  * Redistribution and use in source and binary forms, with or without
21f48ad614SDennis Dalessandro  * modification, are permitted provided that the following conditions
22f48ad614SDennis Dalessandro  * are met:
23f48ad614SDennis Dalessandro  *
24f48ad614SDennis Dalessandro  *  - Redistributions of source code must retain the above copyright
25f48ad614SDennis Dalessandro  *    notice, this list of conditions and the following disclaimer.
26f48ad614SDennis Dalessandro  *  - Redistributions in binary form must reproduce the above copyright
27f48ad614SDennis Dalessandro  *    notice, this list of conditions and the following disclaimer in
28f48ad614SDennis Dalessandro  *    the documentation and/or other materials provided with the
29f48ad614SDennis Dalessandro  *    distribution.
30f48ad614SDennis Dalessandro  *  - Neither the name of Intel Corporation nor the names of its
31f48ad614SDennis Dalessandro  *    contributors may be used to endorse or promote products derived
32f48ad614SDennis Dalessandro  *    from this software without specific prior written permission.
33f48ad614SDennis Dalessandro  *
34f48ad614SDennis Dalessandro  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
35f48ad614SDennis Dalessandro  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
36f48ad614SDennis Dalessandro  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
37f48ad614SDennis Dalessandro  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
38f48ad614SDennis Dalessandro  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
39f48ad614SDennis Dalessandro  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
40f48ad614SDennis Dalessandro  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
41f48ad614SDennis Dalessandro  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
42f48ad614SDennis Dalessandro  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
43f48ad614SDennis Dalessandro  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
44f48ad614SDennis Dalessandro  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45f48ad614SDennis Dalessandro  *
46f48ad614SDennis Dalessandro  */
47f48ad614SDennis Dalessandro #ifndef _HFI1_MMU_RB_H
48f48ad614SDennis Dalessandro #define _HFI1_MMU_RB_H
49f48ad614SDennis Dalessandro 
50f48ad614SDennis Dalessandro #include "hfi.h"
51f48ad614SDennis Dalessandro 
52f48ad614SDennis Dalessandro struct mmu_rb_node {
53f48ad614SDennis Dalessandro 	unsigned long addr;
54f48ad614SDennis Dalessandro 	unsigned long len;
55f48ad614SDennis Dalessandro 	unsigned long __last;
56f48ad614SDennis Dalessandro 	struct rb_node node;
57*10345998SDean Luick 	struct list_head list;
58f48ad614SDennis Dalessandro };
59f48ad614SDennis Dalessandro 
60f48ad614SDennis Dalessandro struct mmu_rb_ops {
61862548daSIra Weiny 	bool (*filter)(struct mmu_rb_node *node, unsigned long addr,
62862548daSIra Weiny 		       unsigned long len);
63e0b09ac5SDean Luick 	int (*insert)(void *ops_arg, struct mmu_rb_node *mnode);
64e0b09ac5SDean Luick 	void (*remove)(void *ops_arg, struct mmu_rb_node *mnode,
65862548daSIra Weiny 		       struct mm_struct *mm);
66e0b09ac5SDean Luick 	int (*invalidate)(void *ops_arg, struct mmu_rb_node *node);
67*10345998SDean Luick 	int (*evict)(void *ops_arg, struct mmu_rb_node *mnode,
68*10345998SDean Luick 		     void *evict_arg, bool *stop);
69f48ad614SDennis Dalessandro };
70f48ad614SDennis Dalessandro 
71e0b09ac5SDean Luick int hfi1_mmu_rb_register(void *ops_arg, struct mm_struct *mm,
72e0b09ac5SDean Luick 			 struct mmu_rb_ops *ops,
73e0b09ac5SDean Luick 			 struct mmu_rb_handler **handler);
74e0b09ac5SDean Luick void hfi1_mmu_rb_unregister(struct mmu_rb_handler *handler);
75e0b09ac5SDean Luick int hfi1_mmu_rb_insert(struct mmu_rb_handler *handler,
76e0b09ac5SDean Luick 		       struct mmu_rb_node *mnode);
77*10345998SDean Luick void hfi1_mmu_rb_evict(struct mmu_rb_handler *handler, void *evict_arg);
78e0b09ac5SDean Luick void hfi1_mmu_rb_remove(struct mmu_rb_handler *handler,
79e0b09ac5SDean Luick 			struct mmu_rb_node *mnode);
80e0b09ac5SDean Luick struct mmu_rb_node *hfi1_mmu_rb_extract(struct mmu_rb_handler *handler,
81e0b09ac5SDean Luick 					unsigned long addr, unsigned long len);
82f48ad614SDennis Dalessandro 
83f48ad614SDennis Dalessandro #endif /* _HFI1_MMU_RB_H */
84