| /******************************************************************* |
| * (c) Copyright 2011-2012 Discretix Technologies Ltd. * |
| * This software is protected by copyright, international * |
| * treaties and patents, and distributed under multiple licenses. * |
| * Any use of this Software as part of the Discretix CryptoCell or * |
| * Packet Engine products requires a commercial license. * |
| * Copies of this Software that are distributed with the Discretix * |
| * CryptoCell or Packet Engine product drivers, may be used in * |
| * accordance with a commercial license, or at the user's option, * |
| * used and redistributed under the terms and conditions of the GNU * |
| * General Public License ("GPL") version 2, as published by the * |
| * Free Software Foundation. * |
| * This program is distributed in the hope that it will be useful, * |
| * but WITHOUT ANY LIABILITY AND WARRANTY; without even the implied * |
| * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * |
| * See the GNU General Public License version 2 for more details. * |
| * You should have received a copy of the GNU General Public * |
| * License version 2 along with this Software; if not, please write * |
| * to the Free Software Foundation, Inc., 59 Temple Place - Suite * |
| * 330, Boston, MA 02111-1307, USA. * |
| * Any copy or reproduction of this Software, as permitted under * |
| * the GNU General Public License version 2, must include this * |
| * Copyright Notice as well as any other notices provided under * |
| * the said license. * |
| ********************************************************************/ |
| |
| /*! |
| * \file dx_bitops.h |
| * Bit fields operations macros. |
| */ |
| #ifndef _DX_BITOPS_H_ |
| #define _DX_BITOPS_H_ |
| |
| #define BITMASK(mask_size) (((mask_size) < 32) ? \ |
| ((1UL << (mask_size)) - 1) : 0xFFFFFFFFUL) |
| #define BITMASK_AT(mask_size, mask_offset) (BITMASK(mask_size) << (mask_offset)) |
| |
| #define BITFIELD_GET(word, bit_offset, bit_size) \ |
| (((word) >> (bit_offset)) & BITMASK(bit_size)) |
| #define BITFIELD_SET(word, bit_offset, bit_size, new_val) \ |
| (word = ((word) & ~BITMASK_AT(bit_size, bit_offset)) | \ |
| (((new_val) & BITMASK(bit_size)) << (bit_offset))) |
| |
| /* Is val aligned to "align" ("align" must be power of 2) */ |
| #ifndef IS_ALIGNED |
| #define IS_ALIGNED(val, align) (((u32)(val) & ((align) - 1)) == 0) |
| #endif |
| |
| #define SWAP_ENDIAN(word) \ |
| (((word) >> 24) | (((word) & 0x00FF0000) >> 8) | \ |
| (((word) & 0x0000FF00) << 8) | (((word) & 0x000000FF) << 24)) |
| |
| /* Is val a multiple of "mult" ("mult" must be power of 2) */ |
| #define IS_MULT(val, mult) (((val) & ((mult) - 1)) == 0) |
| |
| #define IS_NULL_ADDR(adr) (!(adr)) |
| |
| #endif /*_DX_BITOPS_H_*/ |