root/arch/arm/mach-pxa/include/mach/bitfield.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


   1 /* SPDX-License-Identifier: GPL-2.0 */
   2 /*
   3  *      FILE            bitfield.h
   4  *
   5  *      Version         1.1
   6  *      Author          Copyright (c) Marc A. Viredaz, 1998
   7  *                      DEC Western Research Laboratory, Palo Alto, CA
   8  *      Date            April 1998 (April 1997)
   9  *      System          Advanced RISC Machine (ARM)
  10  *      Language        C or ARM Assembly
  11  *      Purpose         Definition of macros to operate on bit fields.
  12  */
  13 
  14 
  15 
  16 #ifndef __BITFIELD_H
  17 #define __BITFIELD_H
  18 
  19 #ifndef __ASSEMBLY__
  20 #define UData(Data)     ((unsigned long) (Data))
  21 #else
  22 #define UData(Data)     (Data)
  23 #endif
  24 
  25 
  26 /*
  27  * MACRO: Fld
  28  *
  29  * Purpose
  30  *    The macro "Fld" encodes a bit field, given its size and its shift value
  31  *    with respect to bit 0.
  32  *
  33  * Note
  34  *    A more intuitive way to encode bit fields would have been to use their
  35  *    mask. However, extracting size and shift value information from a bit
  36  *    field's mask is cumbersome and might break the assembler (255-character
  37  *    line-size limit).
  38  *
  39  * Input
  40  *    Size              Size of the bit field, in number of bits.
  41  *    Shft              Shift value of the bit field with respect to bit 0.
  42  *
  43  * Output
  44  *    Fld               Encoded bit field.
  45  */
  46 
  47 #define Fld(Size, Shft) (((Size) << 16) + (Shft))
  48 
  49 
  50 /*
  51  * MACROS: FSize, FShft, FMsk, FAlnMsk, F1stBit
  52  *
  53  * Purpose
  54  *    The macros "FSize", "FShft", "FMsk", "FAlnMsk", and "F1stBit" return
  55  *    the size, shift value, mask, aligned mask, and first bit of a
  56  *    bit field.
  57  *
  58  * Input
  59  *    Field             Encoded bit field (using the macro "Fld").
  60  *
  61  * Output
  62  *    FSize             Size of the bit field, in number of bits.
  63  *    FShft             Shift value of the bit field with respect to bit 0.
  64  *    FMsk              Mask for the bit field.
  65  *    FAlnMsk           Mask for the bit field, aligned on bit 0.
  66  *    F1stBit           First bit of the bit field.
  67  */
  68 
  69 #define FSize(Field)    ((Field) >> 16)
  70 #define FShft(Field)    ((Field) & 0x0000FFFF)
  71 #define FMsk(Field)     (((UData (1) << FSize (Field)) - 1) << FShft (Field))
  72 #define FAlnMsk(Field)  ((UData (1) << FSize (Field)) - 1)
  73 #define F1stBit(Field)  (UData (1) << FShft (Field))
  74 
  75 
  76 /*
  77  * MACRO: FInsrt
  78  *
  79  * Purpose
  80  *    The macro "FInsrt" inserts a value into a bit field by shifting the
  81  *    former appropriately.
  82  *
  83  * Input
  84  *    Value             Bit-field value.
  85  *    Field             Encoded bit field (using the macro "Fld").
  86  *
  87  * Output
  88  *    FInsrt            Bit-field value positioned appropriately.
  89  */
  90 
  91 #define FInsrt(Value, Field) \
  92                         (UData (Value) << FShft (Field))
  93 
  94 
  95 /*
  96  * MACRO: FExtr
  97  *
  98  * Purpose
  99  *    The macro "FExtr" extracts the value of a bit field by masking and
 100  *    shifting it appropriately.
 101  *
 102  * Input
 103  *    Data              Data containing the bit-field to be extracted.
 104  *    Field             Encoded bit field (using the macro "Fld").
 105  *
 106  * Output
 107  *    FExtr             Bit-field value.
 108  */
 109 
 110 #define FExtr(Data, Field) \
 111                         ((UData (Data) >> FShft (Field)) & FAlnMsk (Field))
 112 
 113 
 114 #endif /* __BITFIELD_H */

/* [<][>][^][v][top][bottom][index][help] */