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
|
/* SPDX-License-Identifier: GPL-2.0+ */
#ifndef _MAPLE_TREE_H
#define _MAPLE_TREE_H
/*
* Maple Tree - An RCU-safe adaptive tree for storing ranges
* Copyright (c) 2018-2022 Oracle
* Authors: Liam R. Howlett <Liam.Howlett@Oracle.com>
* Matthew Wilcox <willy@infradead.org>
*
* eXtensible Arrays
* Copyright (c) 2017 Microsoft Corporation
* Author: Matthew Wilcox <willy@infradead.org>
*
* See Documentation/core-api/xarray.rst for how to use the XArray.
*/
#include <stdbool.h>
#include <limits.h>
#include <sys/types.h>
/*
* The following are copied and modified from include/linux/maple_tree.h
*/
enum maple_type {
maple_dense,
maple_leaf_64,
maple_range_64,
maple_arange_64,
};
#define MAPLE_NODE_MASK 255UL
#define MT_FLAGS_HEIGHT_OFFSET 0x02
#define MT_FLAGS_HEIGHT_MASK 0x7C
#define MAPLE_NODE_TYPE_MASK 0x0F
#define MAPLE_NODE_TYPE_SHIFT 0x03
#define MAPLE_RESERVED_RANGE 4096
/*
* The following are copied and modified from include/linux/xarray.h
*/
#define XA_ZERO_ENTRY xa_mk_internal(257)
static inline ulong xa_mk_internal(ulong v)
{
return (v << 2) | 2;
}
static inline bool xa_is_internal(ulong entry)
{
return (entry & 3) == 2;
}
static inline bool xa_is_node(ulong entry)
{
return xa_is_internal(entry) && entry > 4096;
}
static inline bool xa_is_value(ulong entry)
{
return entry & 1;
}
static inline bool xa_is_zero(ulong entry)
{
return entry == XA_ZERO_ENTRY;
}
static inline unsigned long xa_to_internal(ulong entry)
{
return entry >> 2;
}
static inline unsigned long xa_to_value(ulong entry)
{
return entry >> 1;
}
#endif /* _MAPLE_TREE_H */
|