1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ANDROID_HARDWARE_BINDER_KERNEL_H
18 #define ANDROID_HARDWARE_BINDER_KERNEL_H
19 
20 #include <linux/android/binder.h>
21 
22 /**
23  * This file exists because the uapi kernel headers in bionic are built
24  * from upstream kernel headers only, and the hwbinder kernel changes
25  * haven't made it upstream yet. Therefore, the modifications to the
26  * binder header are added locally in this file.
27  */
28 
29 enum {
30 	BINDER_TYPE_PTR		= B_PACK_CHARS('p', 't', '*', B_TYPE_LARGE),
31 	BINDER_TYPE_FDA		= B_PACK_CHARS('f', 'd', 'a', B_TYPE_LARGE),
32 };
33 
34 /* This header is used in all binder objects that are fixed
35  * up by the kernel driver */
36 struct binder_object_header {
37 	__u32        type;
38 };
39 
40 struct binder_fd_object {
41 	struct binder_object_header	hdr;
42 	/* FD objects used to be represented in flat_binder_object as well,
43 	 * so we're using pads here to remain compatibile to existing userspace
44 	 * clients.
45 	 */
46 	__u32				pad_flags;
47 	union {
48 		binder_uintptr_t	pad_binder;
49 		__u32			fd;
50 	};
51 
52 	binder_uintptr_t		cookie;
53 };
54 
55 /* A binder_buffer object represents an object that the
56  * binder kernel driver copies verbatim to the target
57  * address space. A buffer itself may be pointed to from
58  * within another buffer, meaning that the pointer inside
59  * that other buffer needs to be fixed up as well. This
60  * can be done by specifying the parent buffer, and the
61  * byte offset at which the pointer lives in that buffer.
62  */
63 struct binder_buffer_object {
64 	struct binder_object_header	hdr;
65 	__u32				flags;
66 
67 	union {
68 		struct {
69 			binder_uintptr_t   buffer; /* Pointer to buffer data */
70 			binder_size_t      length; /* Length of the buffer data */
71 		};
72 		struct {
73 			binder_size_t      child;        /* index of child in objects array */
74 			binder_size_t      child_offset; /* byte offset in child buffer */
75 		};
76 	};
77 	binder_size_t			parent; /* index of parent in objects array */
78 	binder_size_t			parent_offset; /* byte offset of pointer in parent buffer */
79 };
80 
81 enum {
82 	BINDER_BUFFER_HAS_PARENT   = 1U << 0,
83 	BINDER_BUFFER_REF          = 1U << 1,
84 };
85 
86 /* A binder_fd_array object represents an array of file
87  * descriptors embedded in a binder_buffer_object. The
88  * kernel driver will fix up all file descriptors in
89  * the parent buffer specified by parent and parent_offset
90  */
91 struct binder_fd_array_object {
92 	struct binder_object_header	hdr;
93 	__u32			_pad; /* hdr is 4 bytes, ensure 8-byte alignment of next fields */
94 	binder_size_t		num_fds;
95 	binder_size_t		parent; /* index of parent in objects array */
96 	binder_size_t		parent_offset; /* offset of pointer in parent */
97 };
98 
99 struct binder_transaction_data_sg {
100     binder_transaction_data    tr; /* regular transaction data */
101     binder_size_t              buffers_size; /* number of bytes of SG buffers */
102 };
103 
104 enum {
105 	BC_TRANSACTION_SG = _IOW('c', 17, struct binder_transaction_data_sg),
106 	BC_REPLY_SG = _IOW('c', 18, struct binder_transaction_data_sg),
107 };
108 
109 enum {
110         FLAT_BINDER_FLAG_SCHEDPOLICY_MASK = 0x600,
111         FLAT_BINDER_FLAG_SCHEDPOLICY_SHIFT = 9,
112 };
113 
114 
115 #endif // ANDROID_HARDWARE_BINDER_KERNEL_H
116