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
7struct 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
19struct objagg;
20struct objagg_obj;
21struct objagg_hints;
22
23const void *objagg_obj_root_priv(const struct objagg_obj *objagg_obj);
24const void *objagg_obj_delta_priv(const struct objagg_obj *objagg_obj);
25const void *objagg_obj_raw(const struct objagg_obj *objagg_obj);
26
27struct objagg_obj *objagg_obj_get(struct objagg *objagg, void *obj);
28void objagg_obj_put(struct objagg *objagg, struct objagg_obj *objagg_obj);
29struct objagg *objagg_create(const struct objagg_ops *ops,
30 struct objagg_hints *hints, void *priv);
31void objagg_destroy(struct objagg *objagg);
32
33struct objagg_obj_stats {
34 unsigned int user_count;
35 unsigned int delta_user_count; /* includes delta object users */
36};
37
38struct objagg_obj_stats_info {
39 struct objagg_obj_stats stats;
40 struct objagg_obj *objagg_obj; /* associated object */
41 bool is_root;
42};
43
44struct objagg_stats {
45 unsigned int root_count;
46 unsigned int stats_info_count;
47 struct objagg_obj_stats_info stats_info[];
48};
49
50const struct objagg_stats *objagg_stats_get(struct objagg *objagg);
51void objagg_stats_put(const struct objagg_stats *objagg_stats);
52
53enum objagg_opt_algo_type {
54 OBJAGG_OPT_ALGO_SIMPLE_GREEDY,
55};
56
57struct objagg_hints *objagg_hints_get(struct objagg *objagg,
58 enum objagg_opt_algo_type opt_algo_type);
59void objagg_hints_put(struct objagg_hints *objagg_hints);
60const struct objagg_stats *
61objagg_hints_stats_get(struct objagg_hints *objagg_hints);
62
63#endif
64