1 /*
2  * Copyright (C) 2017 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 #ifndef __CMD_H__
17 #define __CMD_H__
18 
19 #define _IOC_NRBITS     8
20 #define _IOC_TYPEBITS   8
21 
22 /*
23  * Let any architecture override either of the following before
24  * including this file.
25  */
26 
27 #ifndef _IOC_SIZEBITS
28 # define _IOC_SIZEBITS  14
29 #endif
30 
31 #ifndef _IOC_DIRBITS
32 # define _IOC_DIRBITS   2
33 #endif
34 
35 #define _IOC_NRMASK     ((1 << _IOC_NRBITS)-1)
36 #define _IOC_TYPEMASK   ((1 << _IOC_TYPEBITS)-1)
37 #define _IOC_SIZEMASK   ((1 << _IOC_SIZEBITS)-1)
38 #define _IOC_DIRMASK    ((1 << _IOC_DIRBITS)-1)
39 
40 #define _IOC_NRSHIFT    0
41 #define _IOC_TYPESHIFT  (_IOC_NRSHIFT+_IOC_NRBITS)
42 #define _IOC_SIZESHIFT  (_IOC_TYPESHIFT+_IOC_TYPEBITS)
43 #define _IOC_DIRSHIFT   (_IOC_SIZESHIFT+_IOC_SIZEBITS)
44 
45 /*
46  * Direction bits, which any architecture can choose to override
47  * before including this file.
48  */
49 
50 #ifndef _IOC_NONE
51 # define _IOC_NONE      0U
52 #endif
53 
54 #ifndef _IOC_WRITE
55 # define _IOC_WRITE     1U
56 #endif
57 
58 #ifndef _IOC_READ
59 # define _IOC_READ      2U
60 #endif
61 
62 
63 
64 #define _IOC_TYPECHECK(t) (sizeof(t))
65 #define _IOC(dir,type,nr,size) \
66         (((dir)  << _IOC_DIRSHIFT) | \
67          ((type) << _IOC_TYPESHIFT) | \
68          ((nr)   << _IOC_NRSHIFT) | \
69          ((size) << _IOC_SIZESHIFT))
70 
71 
72 
73 /* used to create numbers */
74 #define _IO(type,nr)            _IOC(_IOC_NONE,(type),(nr),0)
75 #define _IOR(type,nr,size)      _IOC(_IOC_READ,(type),(nr),(_IOC_TYPECHECK(size)))
76 #define _IOW(type,nr,size)      _IOC(_IOC_WRITE,(type),(nr),(_IOC_TYPECHECK(size)))
77 #define _IOWR(type,nr,size)     _IOC(_IOC_READ|_IOC_WRITE,(type),(nr),(_IOC_TYPECHECK(size)))
78 
79 #endif
80 
81