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/types.h>
24 #include <linux/ioctl.h>
26 #define B_PACK_CHARS(c1, c2, c3, c4) \
27 ((((c1)<<24)) | (((c2)<<16)) | (((c3)<<8)) | (c4))
28 #define B_TYPE_LARGE 0x85
31 BINDER_TYPE_BINDER = B_PACK_CHARS('s', 'b', '*', B_TYPE_LARGE),
32 BINDER_TYPE_WEAK_BINDER = B_PACK_CHARS('w', 'b', '*', B_TYPE_LARGE),
33 BINDER_TYPE_HANDLE = B_PACK_CHARS('s', 'h', '*', B_TYPE_LARGE),
34 BINDER_TYPE_WEAK_HANDLE = B_PACK_CHARS('w', 'h', '*', B_TYPE_LARGE),
35 BINDER_TYPE_FD = B_PACK_CHARS('f', 'd', '*', B_TYPE_LARGE),
39 FLAT_BINDER_FLAG_PRIORITY_MASK = 0xff,
40 FLAT_BINDER_FLAG_ACCEPTS_FDS = 0x100,
43 #ifdef BINDER_IPC_32BIT
44 typedef __u32 binder_size_t;
45 typedef __u32 binder_uintptr_t;
47 typedef __u64 binder_size_t;
48 typedef __u64 binder_uintptr_t;
52 * This is the flattened representation of a Binder object for transfer
53 * between processes. The 'offsets' supplied as part of a binder transaction
54 * contains offsets into the data where these structures occur. The Binder
55 * driver takes care of re-writing the structure type and data as it moves
58 struct flat_binder_object {
59 /* 8 bytes for large_flat_header. */
63 /* 8 bytes of data. */
65 binder_uintptr_t binder; /* local object */
66 __u32 handle; /* remote object */
69 /* extra data associated with local object */
70 binder_uintptr_t cookie;
74 * On 64-bit platforms where user code may run in 32-bits the driver must
75 * translate the buffer (and local binder) addresses appropriately.
78 struct binder_write_read {
79 binder_size_t write_size; /* bytes to write */
80 binder_size_t write_consumed; /* bytes consumed by driver */
81 binder_uintptr_t write_buffer;
82 binder_size_t read_size; /* bytes to read */
83 binder_size_t read_consumed; /* bytes consumed by driver */
84 binder_uintptr_t read_buffer;
87 /* Use with BINDER_VERSION, driver fills in fields. */
88 struct binder_version {
89 /* driver protocol version -- increment with incompatible change */
90 __s32 protocol_version;
93 /* This is the current protocol version. */
94 #ifdef BINDER_IPC_32BIT
95 #define BINDER_CURRENT_PROTOCOL_VERSION 7
97 #define BINDER_CURRENT_PROTOCOL_VERSION 8
100 #define BINDER_WRITE_READ _IOWR('b', 1, struct binder_write_read)
101 #define BINDER_SET_IDLE_TIMEOUT _IOW('b', 3, __s64)
102 #define BINDER_SET_MAX_THREADS _IOW('b', 5, __u32)
103 #define BINDER_SET_IDLE_PRIORITY _IOW('b', 6, __s32)
104 #define BINDER_SET_CONTEXT_MGR _IOW('b', 7, __s32)
105 #define BINDER_THREAD_EXIT _IOW('b', 8, __s32)
106 #define BINDER_VERSION _IOWR('b', 9, struct binder_version)
109 * NOTE: Two special error codes you should check for when calling
110 * in to the driver are:
112 * EINTR -- The operation has been interupted. This should be
113 * handled by retrying the ioctl() until a different error code
116 * ECONNREFUSED -- The driver is no longer accepting operations
117 * from your process. That is, the process is being destroyed.
118 * You should handle this by exiting from your process. Note
119 * that once this error code is returned, all further calls to
120 * the driver from any thread will return this same code.
123 enum transaction_flags {
124 TF_ONE_WAY = 0x01, /* this is a one-way call: async, no return */
125 TF_ROOT_OBJECT = 0x04, /* contents are the component's root object */
126 TF_STATUS_CODE = 0x08, /* contents are a 32-bit status code */
127 TF_ACCEPT_FDS = 0x10, /* allow replies with file descriptors */
130 struct binder_transaction_data {
131 /* The first two are only used for bcTRANSACTION and brTRANSACTION,
132 * identifying the target and contents of the transaction.
135 /* target descriptor of command transaction */
137 /* target descriptor of return transaction */
138 binder_uintptr_t ptr;
140 binder_uintptr_t cookie; /* target object cookie */
141 __u32 code; /* transaction command */
143 /* General information about the transaction. */
147 binder_size_t data_size; /* number of bytes of data */
148 binder_size_t offsets_size; /* number of bytes of offsets */
150 /* If this transaction is inline, the data immediately
151 * follows here; otherwise, it ends with a pointer to
156 /* transaction data */
157 binder_uintptr_t buffer;
158 /* offsets from buffer to flat_binder_object structs */
159 binder_uintptr_t offsets;
165 struct binder_ptr_cookie {
166 binder_uintptr_t ptr;
167 binder_uintptr_t cookie;
170 struct binder_handle_cookie {
172 binder_uintptr_t cookie;
175 struct binder_pri_desc {
180 struct binder_pri_ptr_cookie {
182 binder_uintptr_t ptr;
183 binder_uintptr_t cookie;
186 enum binder_driver_return_protocol {
187 BR_ERROR = _IOR('r', 0, __s32),
195 BR_TRANSACTION = _IOR('r', 2, struct binder_transaction_data),
196 BR_REPLY = _IOR('r', 3, struct binder_transaction_data),
198 * binder_transaction_data: the received command.
201 BR_ACQUIRE_RESULT = _IOR('r', 4, __s32),
203 * not currently supported
204 * int: 0 if the last bcATTEMPT_ACQUIRE was not successful.
205 * Else the remote object has acquired a primary reference.
208 BR_DEAD_REPLY = _IO('r', 5),
210 * The target of the last transaction (either a bcTRANSACTION or
211 * a bcATTEMPT_ACQUIRE) is no longer with us. No parameters.
214 BR_TRANSACTION_COMPLETE = _IO('r', 6),
216 * No parameters... always refers to the last transaction requested
217 * (including replies). Note that this will be sent even for
218 * asynchronous transactions.
221 BR_INCREFS = _IOR('r', 7, struct binder_ptr_cookie),
222 BR_ACQUIRE = _IOR('r', 8, struct binder_ptr_cookie),
223 BR_RELEASE = _IOR('r', 9, struct binder_ptr_cookie),
224 BR_DECREFS = _IOR('r', 10, struct binder_ptr_cookie),
226 * void *: ptr to binder
227 * void *: cookie for binder
230 BR_ATTEMPT_ACQUIRE = _IOR('r', 11, struct binder_pri_ptr_cookie),
232 * not currently supported
234 * void *: ptr to binder
235 * void *: cookie for binder
238 BR_NOOP = _IO('r', 12),
240 * No parameters. Do nothing and examine the next command. It exists
241 * primarily so that we can replace it with a BR_SPAWN_LOOPER command.
244 BR_SPAWN_LOOPER = _IO('r', 13),
246 * No parameters. The driver has determined that a process has no
247 * threads waiting to service incoming transactions. When a process
248 * receives this command, it must spawn a new service thread and
249 * register it via bcENTER_LOOPER.
252 BR_FINISHED = _IO('r', 14),
254 * not currently supported
255 * stop threadpool thread
258 BR_DEAD_BINDER = _IOR('r', 15, binder_uintptr_t),
262 BR_CLEAR_DEATH_NOTIFICATION_DONE = _IOR('r', 16, binder_uintptr_t),
267 BR_FAILED_REPLY = _IO('r', 17),
269 * The the last transaction (either a bcTRANSACTION or
270 * a bcATTEMPT_ACQUIRE) failed (e.g. out of memory). No parameters.
274 enum binder_driver_command_protocol {
275 BC_TRANSACTION = _IOW('c', 0, struct binder_transaction_data),
276 BC_REPLY = _IOW('c', 1, struct binder_transaction_data),
278 * binder_transaction_data: the sent command.
281 BC_ACQUIRE_RESULT = _IOW('c', 2, __s32),
283 * not currently supported
284 * int: 0 if the last BR_ATTEMPT_ACQUIRE was not successful.
285 * Else you have acquired a primary reference on the object.
288 BC_FREE_BUFFER = _IOW('c', 3, binder_uintptr_t),
290 * void *: ptr to transaction data received on a read
293 BC_INCREFS = _IOW('c', 4, __u32),
294 BC_ACQUIRE = _IOW('c', 5, __u32),
295 BC_RELEASE = _IOW('c', 6, __u32),
296 BC_DECREFS = _IOW('c', 7, __u32),
301 BC_INCREFS_DONE = _IOW('c', 8, struct binder_ptr_cookie),
302 BC_ACQUIRE_DONE = _IOW('c', 9, struct binder_ptr_cookie),
304 * void *: ptr to binder
305 * void *: cookie for binder
308 BC_ATTEMPT_ACQUIRE = _IOW('c', 10, struct binder_pri_desc),
310 * not currently supported
315 BC_REGISTER_LOOPER = _IO('c', 11),
318 * Register a spawned looper thread with the device.
321 BC_ENTER_LOOPER = _IO('c', 12),
322 BC_EXIT_LOOPER = _IO('c', 13),
325 * These two commands are sent as an application-level thread
326 * enters and exits the binder loop, respectively. They are
327 * used so the binder can have an accurate count of the number
328 * of looping threads it has available.
331 BC_REQUEST_DEATH_NOTIFICATION = _IOW('c', 14,
332 struct binder_handle_cookie),
338 BC_CLEAR_DEATH_NOTIFICATION = _IOW('c', 15,
339 struct binder_handle_cookie),
345 BC_DEAD_BINDER_DONE = _IOW('c', 16, binder_uintptr_t),
351 #endif /* _UAPI_LINUX_BINDER_H */