kdbus: the driver, original and non-working
[platform/kernel/linux-exynos.git] / ipc / kdbus / message.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_MESSAGE_H
15 #define __KDBUS_MESSAGE_H
16
17 #include <linux/fs.h>
18 #include <linux/kref.h>
19 #include <uapi/linux/kdbus.h>
20
21 struct kdbus_bus;
22 struct kdbus_conn;
23 struct kdbus_meta_conn;
24 struct kdbus_meta_proc;
25 struct kdbus_pool_slice;
26
27 /**
28  * struct kdbus_gaps - gaps in message to be filled later
29  * @kref:               Reference counter
30  * @n_memfd_offs:       Number of memfds
31  * @memfd_offs:         Offsets of kdbus_memfd items in target slice
32  * @n_fds:              Number of fds
33  * @fds:                Array of sent fds
34  * @fds_offset:         Offset of fd-array in target slice
35  *
36  * The 'gaps' object is used to track data that is needed to fill gaps in a
37  * message at RECV time. Usually, we try to compile the whole message at SEND
38  * time. This has the advantage, that we don't have to cache any information and
39  * can keep the memory consumption small. Furthermore, all copy operations can
40  * be combined into a single function call, which speeds up transactions
41  * considerably.
42  * However, things like file-descriptors can only be fully installed at RECV
43  * time. The gaps object tracks this data and pins it until a message is
44  * received. The gaps object is shared between all receivers of the same
45  * message.
46  */
47 struct kdbus_gaps {
48         struct kref kref;
49
50         /* state tracking for KDBUS_ITEM_PAYLOAD_MEMFD entries */
51         size_t n_memfds;
52         u64 *memfd_offsets;
53         struct file **memfd_files;
54
55         /* state tracking for KDBUS_ITEM_FDS */
56         size_t n_fds;
57         struct file **fd_files;
58         u64 fd_offset;
59 };
60
61 struct kdbus_gaps *kdbus_gaps_ref(struct kdbus_gaps *gaps);
62 struct kdbus_gaps *kdbus_gaps_unref(struct kdbus_gaps *gaps);
63 int kdbus_gaps_install(struct kdbus_gaps *gaps, struct kdbus_pool_slice *slice,
64                        bool *out_incomplete);
65
66 /**
67  * struct kdbus_staging - staging area to import messages
68  * @msg:                User-supplied message
69  * @gaps:               Gaps-object created during import (or NULL if empty)
70  * @msg_seqnum:         Message sequence number
71  * @notify_entry:       Entry into list of kernel-generated notifications
72  * @i_payload:          Current relative index of start of payload
73  * @n_payload:          Total number of bytes needed for payload
74  * @n_parts:            Number of parts
75  * @parts:              Array of iovecs that make up the whole message
76  * @meta_proc:          Process metadata of the sender (or NULL if empty)
77  * @meta_conn:          Connection metadata of the sender (or NULL if empty)
78  * @bloom_filter:       Pointer to the bloom-item in @msg, or NULL
79  * @dst_name:           Pointer to the dst-name-item in @msg, or NULL
80  * @notify:             Pointer to the notification item in @msg, or NULL
81  *
82  * The kdbus_staging object is a temporary staging area to import user-supplied
83  * messages into the kernel. It is only used during SEND and dropped once the
84  * message is queued. Any data that cannot be collected during SEND, is
85  * collected in a kdbus_gaps object and attached to the message queue.
86  */
87 struct kdbus_staging {
88         struct kdbus_msg *msg;
89         struct kdbus_gaps *gaps;
90         u64 msg_seqnum;
91         struct list_head notify_entry;
92
93         /* crafted iovecs to copy the message */
94         size_t i_payload;
95         size_t n_payload;
96         size_t n_parts;
97         struct iovec *parts;
98
99         /* metadata state */
100         struct kdbus_meta_proc *meta_proc;
101         struct kdbus_meta_conn *meta_conn;
102
103         /* cached pointers into @msg */
104         const struct kdbus_bloom_filter *bloom_filter;
105         const char *dst_name;
106         struct kdbus_item *notify;
107 };
108
109 struct kdbus_staging *kdbus_staging_new_kernel(struct kdbus_bus *bus,
110                                                u64 dst, u64 cookie_timeout,
111                                                size_t it_size, size_t it_type);
112 struct kdbus_staging *kdbus_staging_new_user(struct kdbus_bus *bus,
113                                              struct kdbus_cmd_send *cmd,
114                                              struct kdbus_msg *msg);
115 struct kdbus_staging *kdbus_staging_free(struct kdbus_staging *staging);
116 struct kdbus_pool_slice *kdbus_staging_emit(struct kdbus_staging *staging,
117                                             struct kdbus_conn *src,
118                                             struct kdbus_conn *dst);
119
120 #endif