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 * struct binder_object_header - header shared by all binder metadata objects.
53 * @type: type of the object
55 struct binder_object_header
{
60 * This is the flattened representation of a Binder object for transfer
61 * between processes. The 'offsets' supplied as part of a binder transaction
62 * contains offsets into the data where these structures occur. The Binder
63 * driver takes care of re-writing the structure type and data as it moves
66 struct flat_binder_object
{
67 struct binder_object_header hdr
;
70 /* 8 bytes of data. */
72 binder_uintptr_t binder
; /* local object */
73 __u32 handle
; /* remote object */
76 /* extra data associated with local object */
77 binder_uintptr_t cookie
;
81 * struct binder_fd_object - describes a filedescriptor to be fixed up.
82 * @hdr: common header structure
83 * @pad_flags: padding to remain compatible with old userspace code
84 * @pad_binder: padding to remain compatible with old userspace code
85 * @fd: file descriptor
86 * @cookie: opaque data, used by user-space
88 struct binder_fd_object
{
89 struct binder_object_header hdr
;
92 binder_uintptr_t pad_binder
;
96 binder_uintptr_t cookie
;
99 * On 64-bit platforms where user code may run in 32-bits the driver must
100 * translate the buffer (and local binder) addresses appropriately.
103 struct binder_write_read
{
104 binder_size_t write_size
; /* bytes to write */
105 binder_size_t write_consumed
; /* bytes consumed by driver */
106 binder_uintptr_t write_buffer
;
107 binder_size_t read_size
; /* bytes to read */
108 binder_size_t read_consumed
; /* bytes consumed by driver */
109 binder_uintptr_t read_buffer
;
112 /* Use with BINDER_VERSION, driver fills in fields. */
113 struct binder_version
{
114 /* driver protocol version -- increment with incompatible change */
115 __s32 protocol_version
;
118 /* This is the current protocol version. */
119 #ifdef BINDER_IPC_32BIT
120 #define BINDER_CURRENT_PROTOCOL_VERSION 7
122 #define BINDER_CURRENT_PROTOCOL_VERSION 8
125 #define BINDER_WRITE_READ _IOWR('b', 1, struct binder_write_read)
126 #define BINDER_SET_IDLE_TIMEOUT _IOW('b', 3, __s64)
127 #define BINDER_SET_MAX_THREADS _IOW('b', 5, __u32)
128 #define BINDER_SET_IDLE_PRIORITY _IOW('b', 6, __s32)
129 #define BINDER_SET_CONTEXT_MGR _IOW('b', 7, __s32)
130 #define BINDER_THREAD_EXIT _IOW('b', 8, __s32)
131 #define BINDER_VERSION _IOWR('b', 9, struct binder_version)
134 * NOTE: Two special error codes you should check for when calling
135 * in to the driver are:
137 * EINTR -- The operation has been interupted. This should be
138 * handled by retrying the ioctl() until a different error code
141 * ECONNREFUSED -- The driver is no longer accepting operations
142 * from your process. That is, the process is being destroyed.
143 * You should handle this by exiting from your process. Note
144 * that once this error code is returned, all further calls to
145 * the driver from any thread will return this same code.
148 enum transaction_flags
{
149 TF_ONE_WAY
= 0x01, /* this is a one-way call: async, no return */
150 TF_ROOT_OBJECT
= 0x04, /* contents are the component's root object */
151 TF_STATUS_CODE
= 0x08, /* contents are a 32-bit status code */
152 TF_ACCEPT_FDS
= 0x10, /* allow replies with file descriptors */
155 struct binder_transaction_data
{
156 /* The first two are only used for bcTRANSACTION and brTRANSACTION,
157 * identifying the target and contents of the transaction.
160 /* target descriptor of command transaction */
162 /* target descriptor of return transaction */
163 binder_uintptr_t ptr
;
165 binder_uintptr_t cookie
; /* target object cookie */
166 __u32 code
; /* transaction command */
168 /* General information about the transaction. */
172 binder_size_t data_size
; /* number of bytes of data */
173 binder_size_t offsets_size
; /* number of bytes of offsets */
175 /* If this transaction is inline, the data immediately
176 * follows here; otherwise, it ends with a pointer to
181 /* transaction data */
182 binder_uintptr_t buffer
;
183 /* offsets from buffer to flat_binder_object structs */
184 binder_uintptr_t offsets
;
190 struct binder_ptr_cookie
{
191 binder_uintptr_t ptr
;
192 binder_uintptr_t cookie
;
195 struct binder_handle_cookie
{
197 binder_uintptr_t cookie
;
200 struct binder_pri_desc
{
205 struct binder_pri_ptr_cookie
{
207 binder_uintptr_t ptr
;
208 binder_uintptr_t cookie
;
211 enum binder_driver_return_protocol
{
212 BR_ERROR
= _IOR('r', 0, __s32
),
220 BR_TRANSACTION
= _IOR('r', 2, struct binder_transaction_data
),
221 BR_REPLY
= _IOR('r', 3, struct binder_transaction_data
),
223 * binder_transaction_data: the received command.
226 BR_ACQUIRE_RESULT
= _IOR('r', 4, __s32
),
228 * not currently supported
229 * int: 0 if the last bcATTEMPT_ACQUIRE was not successful.
230 * Else the remote object has acquired a primary reference.
233 BR_DEAD_REPLY
= _IO('r', 5),
235 * The target of the last transaction (either a bcTRANSACTION or
236 * a bcATTEMPT_ACQUIRE) is no longer with us. No parameters.
239 BR_TRANSACTION_COMPLETE
= _IO('r', 6),
241 * No parameters... always refers to the last transaction requested
242 * (including replies). Note that this will be sent even for
243 * asynchronous transactions.
246 BR_INCREFS
= _IOR('r', 7, struct binder_ptr_cookie
),
247 BR_ACQUIRE
= _IOR('r', 8, struct binder_ptr_cookie
),
248 BR_RELEASE
= _IOR('r', 9, struct binder_ptr_cookie
),
249 BR_DECREFS
= _IOR('r', 10, struct binder_ptr_cookie
),
251 * void *: ptr to binder
252 * void *: cookie for binder
255 BR_ATTEMPT_ACQUIRE
= _IOR('r', 11, struct binder_pri_ptr_cookie
),
257 * not currently supported
259 * void *: ptr to binder
260 * void *: cookie for binder
263 BR_NOOP
= _IO('r', 12),
265 * No parameters. Do nothing and examine the next command. It exists
266 * primarily so that we can replace it with a BR_SPAWN_LOOPER command.
269 BR_SPAWN_LOOPER
= _IO('r', 13),
271 * No parameters. The driver has determined that a process has no
272 * threads waiting to service incoming transactions. When a process
273 * receives this command, it must spawn a new service thread and
274 * register it via bcENTER_LOOPER.
277 BR_FINISHED
= _IO('r', 14),
279 * not currently supported
280 * stop threadpool thread
283 BR_DEAD_BINDER
= _IOR('r', 15, binder_uintptr_t
),
287 BR_CLEAR_DEATH_NOTIFICATION_DONE
= _IOR('r', 16, binder_uintptr_t
),
292 BR_FAILED_REPLY
= _IO('r', 17),
294 * The the last transaction (either a bcTRANSACTION or
295 * a bcATTEMPT_ACQUIRE) failed (e.g. out of memory). No parameters.
299 enum binder_driver_command_protocol
{
300 BC_TRANSACTION
= _IOW('c', 0, struct binder_transaction_data
),
301 BC_REPLY
= _IOW('c', 1, struct binder_transaction_data
),
303 * binder_transaction_data: the sent command.
306 BC_ACQUIRE_RESULT
= _IOW('c', 2, __s32
),
308 * not currently supported
309 * int: 0 if the last BR_ATTEMPT_ACQUIRE was not successful.
310 * Else you have acquired a primary reference on the object.
313 BC_FREE_BUFFER
= _IOW('c', 3, binder_uintptr_t
),
315 * void *: ptr to transaction data received on a read
318 BC_INCREFS
= _IOW('c', 4, __u32
),
319 BC_ACQUIRE
= _IOW('c', 5, __u32
),
320 BC_RELEASE
= _IOW('c', 6, __u32
),
321 BC_DECREFS
= _IOW('c', 7, __u32
),
326 BC_INCREFS_DONE
= _IOW('c', 8, struct binder_ptr_cookie
),
327 BC_ACQUIRE_DONE
= _IOW('c', 9, struct binder_ptr_cookie
),
329 * void *: ptr to binder
330 * void *: cookie for binder
333 BC_ATTEMPT_ACQUIRE
= _IOW('c', 10, struct binder_pri_desc
),
335 * not currently supported
340 BC_REGISTER_LOOPER
= _IO('c', 11),
343 * Register a spawned looper thread with the device.
346 BC_ENTER_LOOPER
= _IO('c', 12),
347 BC_EXIT_LOOPER
= _IO('c', 13),
350 * These two commands are sent as an application-level thread
351 * enters and exits the binder loop, respectively. They are
352 * used so the binder can have an accurate count of the number
353 * of looping threads it has available.
356 BC_REQUEST_DEATH_NOTIFICATION
= _IOW('c', 14,
357 struct binder_handle_cookie
),
363 BC_CLEAR_DEATH_NOTIFICATION
= _IOW('c', 15,
364 struct binder_handle_cookie
),
370 BC_DEAD_BINDER_DONE
= _IOW('c', 16, binder_uintptr_t
),
376 #endif /* _UAPI_LINUX_BINDER_H */