• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  * Description: osal ioctl header file.
15  *
16  * Create: 2016-11-11
17  */
18 
19 #ifndef _OSAL_IOCTL_H
20 #define _OSAL_IOCTL_H
21 
22 #ifndef _IOC_NRBITS
23 #define _IOC_NRBITS    8
24 #endif
25 
26 #ifndef _IOC_TYPEBITS
27 #define _IOC_TYPEBITS  8
28 #endif
29 
30 #ifndef _IOC_SIZEBITS
31 #define _IOC_SIZEBITS  14
32 #endif
33 
34 #ifndef _IOC_DIRBITS
35 #define _IOC_DIRBITS   2
36 #endif
37 
38 #ifndef _IOC_NRMASK
39 #define _IOC_NRMASK    ((1 << _IOC_NRBITS) - 1)
40 #endif
41 
42 #ifndef _IOC_TYPEMASK
43 #define _IOC_TYPEMASK  ((1 << _IOC_TYPEBITS) - 1)
44 #endif
45 
46 #ifndef _IOC_SIZEMASK
47 #define _IOC_SIZEMASK  ((1 << _IOC_SIZEBITS) - 1)
48 #endif
49 
50 #ifndef _IOC_DIRMASK
51 #define _IOC_DIRMASK   ((1 << _IOC_DIRBITS) - 1)
52 #endif
53 
54 #ifndef _IOC_NRSHIFT
55 #define _IOC_NRSHIFT    0
56 #endif
57 
58 #ifndef _IOC_TYPESHIFT
59 #define _IOC_TYPESHIFT   (_IOC_NRSHIFT + _IOC_NRBITS)
60 #endif
61 
62 #ifndef _IOC_SIZESHIFT
63 #define _IOC_SIZESHIFT   (_IOC_TYPESHIFT + _IOC_TYPEBITS)
64 #endif
65 
66 #ifndef _IOC_DIRSHIFT
67 #define _IOC_DIRSHIFT    (_IOC_SIZESHIFT + _IOC_SIZEBITS)
68 #endif
69 
70 #ifndef _IOC_NONE
71 #define _IOC_NONE      0U
72 #endif
73 
74 #ifndef _IOC_WRITE
75 #define _IOC_WRITE     1U
76 #endif
77 
78 #ifndef _IOC_READ
79 #define _IOC_READ      2U
80 #endif
81 
82 #ifndef _IOC
83 #define _IOC(dir, type, nr, size) \
84     (((dir) << _IOC_DIRSHIFT) |   \
85     ((type) << _IOC_TYPESHIFT) |  \
86     ((nr) << _IOC_NRSHIFT) |      \
87     ((size) << _IOC_SIZESHIFT))
88 #endif
89 
90 #ifdef __CHECKER__
91 #define _IOC_TYPECHECK(t) (sizeof(t))
92 #else
93 /* provoke compile error for invalid uses of size argument */
94 extern unsigned int __invalid_size_argument_for_IOC;
95 
96 #ifndef _IOC_TYPECHECK
97 #define _IOC_TYPECHECK(t)               \
98     ((sizeof(t) == sizeof(t[1]) &&      \
99     sizeof(t) < (1 << _IOC_SIZEBITS)) ? \
100     sizeof(t) :                         \
101     __invalid_size_argument_for_IOC)
102 #endif // #ifndef _IOC_TYPECHECK
103 
104 #endif // #ifdef __CHECKER__
105 
106 /* used to create numbers */
107 #ifndef _IO
108 #define _IO(type, nr)             _IOC(_IOC_NONE, (type), (nr), 0)
109 #endif
110 
111 #ifndef _IOR
112 #define _IOR(type, nr, size)      _IOC(_IOC_READ, (type), (nr), (_IOC_TYPECHECK(size)))
113 #endif
114 
115 #ifndef _IOW
116 #define _IOW(type, nr, size)      _IOC(_IOC_WRITE, (type), (nr), (_IOC_TYPECHECK(size)))
117 #endif
118 
119 #ifndef _IOWR
120 #define _IOWR(type, nr, size)     _IOC(_IOC_READ | _IOC_WRITE, (type), (nr), (_IOC_TYPECHECK(size)))
121 #endif
122 
123 #ifndef _IOR_BAD
124 #define _IOR_BAD(type, nr, size)  _IOC(_IOC_READ, (type), (nr), sizeof(size))
125 #endif
126 
127 #ifndef _IOW_BAD
128 #define _IOW_BAD(type, nr, size)  _IOC(_IOC_WRITE, (type), (nr), sizeof(size))
129 #endif
130 
131 #ifndef _IOWR_BAD
132 #define _IOWR_BAD(type, nr, size) _IOC(_IOC_READ | _IOC_WRITE, (type), (nr), sizeof(size))
133 #endif
134 
135 /* used to decode ioctl numbers.. */
136 #ifndef _IOC_DIR
137 #define _IOC_DIR(nr)    (((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK)
138 #endif
139 
140 #ifndef _IOC_TYPE
141 #define _IOC_TYPE(nr)   (((nr) >> _IOC_TYPESHIFT) & _IOC_TYPEMASK)
142 #endif
143 
144 #ifndef _IOC_NR
145 #define _IOC_NR(nr)     (((nr) >> _IOC_NRSHIFT) & _IOC_NRMASK)
146 #endif
147 
148 #ifndef _IOC_SIZE
149 #define _IOC_SIZE(nr)   (((nr) >> _IOC_SIZESHIFT) & _IOC_SIZEMASK)
150 #endif
151 
152 #ifndef IOC_IN
153 #define IOC_IN        (_IOC_WRITE << _IOC_DIRSHIFT)
154 #endif
155 #ifndef IOC_OUT
156 #define IOC_OUT       (_IOC_READ << _IOC_DIRSHIFT)
157 #endif
158 
159 #ifndef IOC_INOUT
160 #define IOC_INOUT     ((_IOC_WRITE | _IOC_READ) << _IOC_DIRSHIFT)
161 #endif
162 
163 #ifndef IOCSIZE_MASK
164 #define IOCSIZE_MASK  (_IOC_SIZEMASK << _IOC_SIZESHIFT)
165 #endif
166 
167 #ifndef IOCSIZE_SHIFT
168 #define IOCSIZE_SHIFT (_IOC_SIZESHIFT)
169 #endif
170 
171 #endif /* _OSAL_IOCTL_H */
172