kdbus: the driver, original and non-working
[platform/kernel/linux-exynos.git] / ipc / kdbus / names.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  * Copyright (C) 2014-2015 Djalal Harouni <tixxdz@opendz.org>
8  *
9  * kdbus is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU Lesser General Public License as published by the
11  * Free Software Foundation; either version 2.1 of the License, or (at
12  * your option) any later version.
13  */
14
15 #ifndef __KDBUS_NAMES_H
16 #define __KDBUS_NAMES_H
17
18 #include <linux/hashtable.h>
19 #include <linux/rwsem.h>
20
21 struct kdbus_name_entry;
22 struct kdbus_name_owner;
23 struct kdbus_name_registry;
24
25 /**
26  * struct kdbus_name_registry - names registered for a bus
27  * @entries_hash:       Map of entries
28  * @lock:               Registry data lock
29  * @name_seq_last:      Last used sequence number to assign to a name entry
30  */
31 struct kdbus_name_registry {
32         DECLARE_HASHTABLE(entries_hash, 8);
33         struct rw_semaphore rwlock;
34         u64 name_seq_last;
35 };
36
37 /**
38  * struct kdbus_name_entry - well-know name entry
39  * @name_id:            sequence number of name entry to be able to uniquely
40  *                      identify a name over its registration lifetime
41  * @activator:          activator of this name, or NULL
42  * @queue:              list of queued owners
43  * @hentry:             entry in registry map
44  * @name:               well-known name
45  */
46 struct kdbus_name_entry {
47         u64 name_id;
48         struct kdbus_name_owner *activator;
49         struct list_head queue;
50         struct hlist_node hentry;
51         char name[];
52 };
53
54 /**
55  * struct kdbus_name_owner - owner of a well-known name
56  * @flags:              KDBUS_NAME_* flags of this owner
57  * @conn:               connection owning the name
58  * @name:               name that is owned
59  * @conn_entry:         link into @conn
60  * @name_entry:         link into @name
61  */
62 struct kdbus_name_owner {
63         u64 flags;
64         struct kdbus_conn *conn;
65         struct kdbus_name_entry *name;
66         struct list_head conn_entry;
67         struct list_head name_entry;
68 };
69
70 bool kdbus_name_is_valid(const char *p, bool allow_wildcard);
71
72 struct kdbus_name_registry *kdbus_name_registry_new(void);
73 void kdbus_name_registry_free(struct kdbus_name_registry *reg);
74
75 struct kdbus_name_entry *
76 kdbus_name_lookup_unlocked(struct kdbus_name_registry *reg, const char *name);
77
78 int kdbus_name_acquire(struct kdbus_name_registry *reg,
79                        struct kdbus_conn *conn, const char *name,
80                        u64 flags, u64 *return_flags);
81 void kdbus_name_release_all(struct kdbus_name_registry *reg,
82                             struct kdbus_conn *conn);
83
84 int kdbus_cmd_name_acquire(struct kdbus_conn *conn, void __user *argp);
85 int kdbus_cmd_name_release(struct kdbus_conn *conn, void __user *argp);
86 int kdbus_cmd_list(struct kdbus_conn *conn, void __user *argp);
87
88 /**
89  * kdbus_name_get_owner() - get current owner of a name
90  * @name:       name to get current owner of
91  *
92  * This returns a pointer to the current owner of a name (or its activator if
93  * there is no owner). The caller must make sure @name is valid and does not
94  * vanish.
95  *
96  * Return: Pointer to current owner or NULL if there is none.
97  */
98 static inline struct kdbus_name_owner *
99 kdbus_name_get_owner(struct kdbus_name_entry *name)
100 {
101         return list_first_entry_or_null(&name->queue, struct kdbus_name_owner,
102                                         name_entry) ? : name->activator;
103 }
104
105 #endif