labcomm2006_ioctl.h 3.97 KB
Newer Older
1
/*
Sven Gestegård Robertz's avatar
Sven Gestegård Robertz committed
2
  labcomm2006_ioctl.h -- labcomm ioctl declarations
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

  Copyright 2013 Anders Blomdell <anders.blomdell@control.lth.se>

  This file is part of LabComm.

  LabComm is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  LabComm is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

22 23
#ifndef __LABCOMM2006_IOCTL_H__
#define __LABCOMM2006_IOCTL_H__
24

Sven Gestegård Robertz's avatar
Sven Gestegård Robertz committed
25
#include "labcomm2006.h"
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101

/*
 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 * | |   |                         |               |               |  
 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 *  | |   |                         |               |
 *  | |   |                         |               +- number    (8)
 *  | |   |                         +----------------- type      (8)
 *  | |   +------------------------------------------- size      (13)
 *  | +----------------------------------------------- direction (2)
 *  +------------------------------------------------- signature (1)
 *  
 * type 0-31     are reserved for labcomm library use
 */


#define LABCOMM_IOC_NRBITS      8
#define LABCOMM_IOC_TYPEBITS    8
#define LABCOMM_IOC_SIZEBITS   13
#define LABCOMM_IOC_DIRBITS     2
#define LABCOMM_IOC_SIGBITS     1
#define LABCOMM_IOC_NRMASK     ((1 << LABCOMM_IOC_NRBITS)-1)
#define LABCOMM_IOC_TYPEMASK   ((1 << LABCOMM_IOC_TYPEBITS)-1)
#define LABCOMM_IOC_SIZEMASK   ((1 << LABCOMM_IOC_SIZEBITS)-1)
#define LABCOMM_IOC_DIRMASK    ((1 << LABCOMM_IOC_DIRBITS)-1)
#define LABCOMM_IOC_SIGMASK    ((1 << LABCOMM_IOC_SIGBITS)-1)
#define LABCOMM_IOC_NRSHIFT    0
#define LABCOMM_IOC_TYPESHIFT  (LABCOMM_IOC_NRSHIFT+LABCOMM_IOC_NRBITS)
#define LABCOMM_IOC_SIZESHIFT  (LABCOMM_IOC_TYPESHIFT+LABCOMM_IOC_TYPEBITS)
#define LABCOMM_IOC_DIRSHIFT   (LABCOMM_IOC_SIZESHIFT+LABCOMM_IOC_SIZEBITS)
#define LABCOMM_IOC_SIGSHIFT   (LABCOMM_IOC_DIRSHIFT+LABCOMM_IOC_DIRBITS)

#define LABCOMM_IOC_NOSIG       0U
#define LABCOMM_IOC_USESIG      1U

#define LABCOMM_IOC_NONE        0U
#define LABCOMM_IOC_WRITE       1U
#define LABCOMM_IOC_READ        2U

#define LABCOMM_IOC(signature,dir,type,nr,size)	  \
  (((signature) << LABCOMM_IOC_SIGSHIFT) |	  \
   ((dir)       << LABCOMM_IOC_DIRSHIFT) |	  \
   ((size)      << LABCOMM_IOC_SIZESHIFT) |	  \
   ((type)      << LABCOMM_IOC_TYPESHIFT) |	  \
   ((nr)        << LABCOMM_IOC_NRSHIFT))	  

#define LABCOMM_IOC_SIG(nr) \
  (((nr) >> LABCOMM_IOC_SIGSHIFT) & LABCOMM_IOC_SIGMASK)
#define LABCOMM_IOC_DIR(nr) \
  (((nr) >> LABCOMM_IOC_DIRSHIFT) & LABCOMM_IOC_DIRMASK)
#define LABCOMM_IOC_SIZE(nr) \
  (((nr) >> LABCOMM_IOC_SIZESHIFT) & LABCOMM_IOC_SIZEMASK)
#define LABCOMM_IOC_TYPE(nr) \
  (((nr) >> LABCOMM_IOC_TYPESHIFT) & LABCOMM_IOC_TYPEMASK)
#define LABCOMM_IOC_NR(nr) \
  (((nr) >> LABCOMM_IOC_NRSHIFT) & LABCOMM_IOC_NRMASK)

#define LABCOMM_IO(type,nr)						\
  LABCOMM_IOC(LABCOMM_IOC_NOSIG,LABCOMM_IOC_NONE,type,nr,0)
#define LABCOMM_IOR(type,nr,size)					\
  LABCOMM_IOC(LABCOMM_IOC_NOSIG,LABCOMM_IOC_READ,type,nr,sizeof(size))
#define LABCOMM_IOW(type,nr,size)					\
  LABCOMM_IOC(LABCOMM_IOC_NOSIG,LABCOMM_IOC_WRITE,type,nr,sizeof(size))
#define LABCOMM_IOS(type,nr)					\
  LABCOMM_IOC(LABCOMM_IOC_USESIG,LABCOMM_IOC_READ,type,nr,0)
#define LABCOMM_IOSR(type,nr,size)					\
  LABCOMM_IOC(LABCOMM_IOC_USESIG,LABCOMM_IOC_READ,type,nr,sizeof(size))
#define LABCOMM_IOSW(type,nr,size)					\
  LABCOMM_IOC(LABCOMM_IOC_USESIG,LABCOMM_IOC_WRITE,type,nr,sizeof(size))

#define LABCOMM_IOCTL_WRITER_GET_BYTES_WRITTEN \
  LABCOMM_IOR(0,1,int)
#define LABCOMM_IOCTL_WRITER_GET_BYTE_POINTER \
  LABCOMM_IOR(0,2,void*)

#endif