kdbus: the driver, original and non-working
[platform/kernel/linux-exynos.git] / ipc / kdbus / node.h
1 /*
2  * Copyright (C) 2013-2015 Kay Sievers
3  * Copyright (C) 2013-2015 Greg Kroah-Hartman <gregkh@linuxfoundation.org>
4  * Copyright (C) 2013-2015 Daniel Mack <daniel@zonque.org>
5  * Copyright (C) 2013-2015 David Herrmann <dh.herrmann@gmail.com>
6  * Copyright (C) 2013-2015 Linux Foundation
7  *
8  * kdbus is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU Lesser General Public License as published by the
10  * Free Software Foundation; either version 2.1 of the License, or (at
11  * your option) any later version.
12  */
13
14 #ifndef __KDBUS_NODE_H
15 #define __KDBUS_NODE_H
16
17 #include <linux/atomic.h>
18 #include <linux/kernel.h>
19 #include <linux/mutex.h>
20 #include <linux/wait.h>
21
22 struct kdbus_node;
23
24 enum kdbus_node_type {
25         KDBUS_NODE_DOMAIN,
26         KDBUS_NODE_CONTROL,
27         KDBUS_NODE_BUS,
28         KDBUS_NODE_ENDPOINT,
29 };
30
31 typedef void (*kdbus_node_free_t) (struct kdbus_node *node);
32 typedef void (*kdbus_node_release_t) (struct kdbus_node *node, bool was_active);
33
34 struct kdbus_node {
35         atomic_t refcnt;
36         atomic_t active;
37         wait_queue_head_t waitq;
38
39         /* static members */
40         unsigned int type;
41         kdbus_node_free_t free_cb;
42         kdbus_node_release_t release_cb;
43         umode_t mode;
44         kuid_t uid;
45         kgid_t gid;
46
47         /* valid once linked */
48         char *name;
49         unsigned int hash;
50         unsigned int id;
51         struct kdbus_node *parent; /* may be NULL */
52
53         /* valid iff active */
54         struct mutex lock;
55         struct rb_node rb;
56         struct rb_root children;
57 };
58
59 #define kdbus_node_from_rb(_node) rb_entry((_node), struct kdbus_node, rb)
60
61 extern struct ida kdbus_node_ida;
62
63 void kdbus_node_init(struct kdbus_node *node, unsigned int type);
64
65 int kdbus_node_link(struct kdbus_node *node, struct kdbus_node *parent,
66                     const char *name);
67
68 struct kdbus_node *kdbus_node_ref(struct kdbus_node *node);
69 struct kdbus_node *kdbus_node_unref(struct kdbus_node *node);
70
71 bool kdbus_node_is_active(struct kdbus_node *node);
72 bool kdbus_node_is_deactivated(struct kdbus_node *node);
73 bool kdbus_node_activate(struct kdbus_node *node);
74 void kdbus_node_deactivate(struct kdbus_node *node);
75
76 bool kdbus_node_acquire(struct kdbus_node *node);
77 void kdbus_node_release(struct kdbus_node *node);
78
79 struct kdbus_node *kdbus_node_find_child(struct kdbus_node *node,
80                                          const char *name);
81 struct kdbus_node *kdbus_node_find_closest(struct kdbus_node *node,
82                                            unsigned int hash);
83 struct kdbus_node *kdbus_node_next_child(struct kdbus_node *node,
84                                          struct kdbus_node *prev);
85
86 #endif