2 * Copyright (C) 2008 Google, Inc.
4 * Based on, but no longer compatible with, the original
5 * OpenBinder.org binder driver interface, which is:
7 * Copyright (c) 2005 Palmsource, Inc.
9 * This software is licensed under the terms of the GNU General Public
10 * License version 2, as published by the Free Software Foundation, and
11 * may be copied, distributed, and modified under those terms.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
20 #ifndef _UAPI_LINUX_BINDER_H
21 #define _UAPI_LINUX_BINDER_H
23 #include <linux/ioctl.h>
25 #define B_PACK_CHARS(c1, c2, c3, c4) \
26 ((((c1)<<24)) | (((c2)<<16)) | (((c3)<<8)) | (c4))
27 #define B_TYPE_LARGE 0x85
30 BINDER_TYPE_BINDER = B_PACK_CHARS('s', 'b', '*', B_TYPE_LARGE),
31 BINDER_TYPE_WEAK_BINDER = B_PACK_CHARS('w', 'b', '*', B_TYPE_LARGE),
32 BINDER_TYPE_HANDLE = B_PACK_CHARS('s', 'h', '*', B_TYPE_LARGE),
33 BINDER_TYPE_WEAK_HANDLE = B_PACK_CHARS('w', 'h', '*', B_TYPE_LARGE),
34 BINDER_TYPE_FD = B_PACK_CHARS('f', 'd', '*', B_TYPE_LARGE),
38 FLAT_BINDER_FLAG_PRIORITY_MASK = 0xff,
39 FLAT_BINDER_FLAG_ACCEPTS_FDS = 0x100,
42 #ifdef BINDER_IPC_32BIT
43 typedef __u32 binder_size_t;
44 typedef __u32 binder_uintptr_t;
46 typedef __u64 binder_size_t;
47 typedef __u64 binder_uintptr_t;
51 * This is the flattened representation of a Binder object for transfer
52 * between processes. The 'offsets' supplied as part of a binder transaction
53 * contains offsets into the data where these structures occur. The Binder
54 * driver takes care of re-writing the structure type and data as it moves
57 struct flat_binder_object {
58 /* 8 bytes for large_flat_header. */
62 /* 8 bytes of data. */
64 binder_uintptr_t binder; /* local object */
65 __u32 handle; /* remote object */
68 /* extra data associated with local object */
69 binder_uintptr_t cookie;
73 * On 64-bit platforms where user code may run in 32-bits the driver must
74 * translate the buffer (and local binder) addresses appropriately.
77 struct binder_write_read {
78 binder_size_t write_size; /* bytes to write */
79 binder_size_t write_consumed; /* bytes consumed by driver */
80 binder_uintptr_t write_buffer;
81 binder_size_t read_size; /* bytes to read */
82 binder_size_t read_consumed; /* bytes consumed by driver */
83 binder_uintptr_t read_buffer;
86 /* Use with BINDER_VERSION, driver fills in fields. */
87 struct binder_version {
88 /* driver protocol version -- increment with incompatible change */
89 __s32 protocol_version;
92 /* This is the current protocol version. */
93 #ifdef BINDER_IPC_32BIT
94 #define BINDER_CURRENT_PROTOCOL_VERSION 7
96 #define BINDER_CURRENT_PROTOCOL_VERSION 8
99 #define BINDER_WRITE_READ _IOWR('b', 1, struct binder_write_read)
100 #define BINDER_SET_IDLE_TIMEOUT _IOW('b', 3, __s64)
101 #define BINDER_SET_MAX_THREADS _IOW('b', 5, __u32)
102 #define BINDER_SET_IDLE_PRIORITY _IOW('b', 6, __s32)
103 #define BINDER_SET_CONTEXT_MGR _IOW('b', 7, __s32)
104 #define BINDER_THREAD_EXIT _IOW('b', 8, __s32)
105 #define BINDER_VERSION _IOWR('b', 9, struct binder_version)
108 * NOTE: Two special error codes you should check for when calling
109 * in to the driver are:
111 * EINTR -- The operation has been interupted. This should be
112 * handled by retrying the ioctl() until a different error code
115 * ECONNREFUSED -- The driver is no longer accepting operations
116 * from your process. That is, the process is being destroyed.
117 * You should handle this by exiting from your process. Note
118 * that once this error code is returned, all further calls to
119 * the driver from any thread will return this same code.
122 enum transaction_flags {
123 TF_ONE_WAY = 0x01, /* this is a one-way call: async, no return */
124 TF_ROOT_OBJECT = 0x04, /* contents are the component's root object */
125 TF_STATUS_CODE = 0x08, /* contents are a 32-bit status code */
126 TF_ACCEPT_FDS = 0x10, /* allow replies with file descriptors */
129 struct binder_transaction_data {
130 /* The first two are only used for bcTRANSACTION and brTRANSACTION,
131 * identifying the target and contents of the transaction.
134 /* target descriptor of command transaction */
136 /* target descriptor of return transaction */
137 binder_uintptr_t ptr;
139 binder_uintptr_t cookie; /* target object cookie */
140 __u32 code; /* transaction command */
142 /* General information about the transaction. */
146 binder_size_t data_size; /* number of bytes of data */
147 binder_size_t offsets_size; /* number of bytes of offsets */
149 /* If this transaction is inline, the data immediately
150 * follows here; otherwise, it ends with a pointer to
155 /* transaction data */
156 binder_uintptr_t buffer;
157 /* offsets from buffer to flat_binder_object structs */
158 binder_uintptr_t offsets;
164 struct binder_ptr_cookie {
165 binder_uintptr_t ptr;
166 binder_uintptr_t cookie;
169 struct binder_handle_cookie {
171 binder_uintptr_t cookie;
174 struct binder_pri_desc {
179 struct binder_pri_ptr_cookie {
181 binder_uintptr_t ptr;
182 binder_uintptr_t cookie;
185 enum binder_driver_return_protocol {
186 BR_ERROR = _IOR('r', 0, __s32),
194 BR_TRANSACTION = _IOR('r', 2, struct binder_transaction_data),
195 BR_REPLY = _IOR('r', 3, struct binder_transaction_data),
197 * binder_transaction_data: the received command.
200 BR_ACQUIRE_RESULT = _IOR('r', 4, __s32),
202 * not currently supported
203 * int: 0 if the last bcATTEMPT_ACQUIRE was not successful.
204 * Else the remote object has acquired a primary reference.
207 BR_DEAD_REPLY = _IO('r', 5),
209 * The target of the last transaction (either a bcTRANSACTION or
210 * a bcATTEMPT_ACQUIRE) is no longer with us. No parameters.
213 BR_TRANSACTION_COMPLETE = _IO('r', 6),
215 * No parameters... always refers to the last transaction requested
216 * (including replies). Note that this will be sent even for
217 * asynchronous transactions.
220 BR_INCREFS = _IOR('r', 7, struct binder_ptr_cookie),
221 BR_ACQUIRE = _IOR('r', 8, struct binder_ptr_cookie),
222 BR_RELEASE = _IOR('r', 9, struct binder_ptr_cookie),
223 BR_DECREFS = _IOR('r', 10, struct binder_ptr_cookie),
225 * void *: ptr to binder
226 * void *: cookie for binder
229 BR_ATTEMPT_ACQUIRE = _IOR('r', 11, struct binder_pri_ptr_cookie),
231 * not currently supported
233 * void *: ptr to binder
234 * void *: cookie for binder
237 BR_NOOP = _IO('r', 12),
239 * No parameters. Do nothing and examine the next command. It exists
240 * primarily so that we can replace it with a BR_SPAWN_LOOPER command.
243 BR_SPAWN_LOOPER = _IO('r', 13),
245 * No parameters. The driver has determined that a process has no
246 * threads waiting to service incoming transactions. When a process
247 * receives this command, it must spawn a new service thread and
248 * register it via bcENTER_LOOPER.
251 BR_FINISHED = _IO('r', 14),
253 * not currently supported
254 * stop threadpool thread
257 BR_DEAD_BINDER = _IOR('r', 15, binder_uintptr_t),
261 BR_CLEAR_DEATH_NOTIFICATION_DONE = _IOR('r', 16, binder_uintptr_t),
266 BR_FAILED_REPLY = _IO('r', 17),
268 * The the last transaction (either a bcTRANSACTION or
269 * a bcATTEMPT_ACQUIRE) failed (e.g. out of memory). No parameters.
273 enum binder_driver_command_protocol {
274 BC_TRANSACTION = _IOW('c', 0, struct binder_transaction_data),
275 BC_REPLY = _IOW('c', 1, struct binder_transaction_data),
277 * binder_transaction_data: the sent command.
280 BC_ACQUIRE_RESULT = _IOW('c', 2, __s32),
282 * not currently supported
283 * int: 0 if the last BR_ATTEMPT_ACQUIRE was not successful.
284 * Else you have acquired a primary reference on the object.
287 BC_FREE_BUFFER = _IOW('c', 3, binder_uintptr_t),
289 * void *: ptr to transaction data received on a read
292 BC_INCREFS = _IOW('c', 4, __u32),
293 BC_ACQUIRE = _IOW('c', 5, __u32),
294 BC_RELEASE = _IOW('c', 6, __u32),
295 BC_DECREFS = _IOW('c', 7, __u32),
300 BC_INCREFS_DONE = _IOW('c', 8, struct binder_ptr_cookie),
301 BC_ACQUIRE_DONE = _IOW('c', 9, struct binder_ptr_cookie),
303 * void *: ptr to binder
304 * void *: cookie for binder
307 BC_ATTEMPT_ACQUIRE = _IOW('c', 10, struct binder_pri_desc),
309 * not currently supported
314 BC_REGISTER_LOOPER = _IO('c', 11),
317 * Register a spawned looper thread with the device.
320 BC_ENTER_LOOPER = _IO('c', 12),
321 BC_EXIT_LOOPER = _IO('c', 13),
324 * These two commands are sent as an application-level thread
325 * enters and exits the binder loop, respectively. They are
326 * used so the binder can have an accurate count of the number
327 * of looping threads it has available.
330 BC_REQUEST_DEATH_NOTIFICATION = _IOW('c', 14, struct binder_handle_cookie),
336 BC_CLEAR_DEATH_NOTIFICATION = _IOW('c', 15, struct binder_handle_cookie),
342 BC_DEAD_BINDER_DONE = _IOW('c', 16, binder_uintptr_t),
348 #endif /* _UAPI_LINUX_BINDER_H */