1 /* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
2 /* Copyright (c) 2018 Mellanox Technologies. All rights reserved */
3 
4 #ifndef _OBJAGG_H
5 #define _OBJAGG_H
6 
7 struct objagg_ops {
8 	size_t obj_size;
9 	bool (*delta_check)(void *priv, const void *parent_obj,
10 			    const void *obj);
11 	int (*hints_obj_cmp)(const void *obj1, const void *obj2);
12 	void * (*delta_create)(void *priv, void *parent_obj, void *obj);
13 	void (*delta_destroy)(void *priv, void *delta_priv);
14 	void * (*root_create)(void *priv, void *obj, unsigned int root_id);
15 #define OBJAGG_OBJ_ROOT_ID_INVALID UINT_MAX
16 	void (*root_destroy)(void *priv, void *root_priv);
17 };
18 
19 struct objagg;
20 struct objagg_obj;
21 struct objagg_hints;
22 
23 const void *objagg_obj_root_priv(const struct objagg_obj *objagg_obj);
24 const void *objagg_obj_delta_priv(const struct objagg_obj *objagg_obj);
25 const void *objagg_obj_raw(const struct objagg_obj *objagg_obj);
26 
27 struct objagg_obj *objagg_obj_get(struct objagg *objagg, void *obj);
28 void objagg_obj_put(struct objagg *objagg, struct objagg_obj *objagg_obj);
29 struct objagg *objagg_create(const struct objagg_ops *ops,
30 			     struct objagg_hints *hints, void *priv);
31 void objagg_destroy(struct objagg *objagg);
32 
33 struct objagg_obj_stats {
34 	unsigned int user_count;
35 	unsigned int delta_user_count; /* includes delta object users */
36 };
37 
38 struct objagg_obj_stats_info {
39 	struct objagg_obj_stats stats;
40 	struct objagg_obj *objagg_obj; /* associated object */
41 	bool is_root;
42 };
43 
44 struct objagg_stats {
45 	unsigned int root_count;
46 	unsigned int stats_info_count;
47 	struct objagg_obj_stats_info stats_info[];
48 };
49 
50 const struct objagg_stats *objagg_stats_get(struct objagg *objagg);
51 void objagg_stats_put(const struct objagg_stats *objagg_stats);
52 
53 enum objagg_opt_algo_type {
54 	OBJAGG_OPT_ALGO_SIMPLE_GREEDY,
55 };
56 
57 struct objagg_hints *objagg_hints_get(struct objagg *objagg,
58 				      enum objagg_opt_algo_type opt_algo_type);
59 void objagg_hints_put(struct objagg_hints *objagg_hints);
60 const struct objagg_stats *
61 objagg_hints_stats_get(struct objagg_hints *objagg_hints);
62 
63 #endif
64