Changeset 657 for trunk/kernel/libk/bits.h
- Timestamp:
- Mar 18, 2020, 11:16:59 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/libk/bits.h
r635 r657 1 1 /* 2 * bits.h - bit s manipulation helper functions2 * bits.h - bitmap API definition 3 3 * 4 4 * Author Ghassan Almaless (2008,2009,2010,2011,2012) 5 * Alain Greiner (2016,2017,2018,2019 )5 * Alain Greiner (2016,2017,2018,2019,2020) 6 6 * 7 7 * Copyright (c) UPMC Sorbonne Universites … … 28 28 #include <kernel_config.h> 29 29 #include <hal_kernel_types.h> 30 31 /********************************************************************************************* 32 * These macros are NOT used by the bitmap, but can be useful in other contexts... [AG] 33 *********************************************************************************************/ 34 35 #define ARROUND_UP(val, size) (((val) & ((size) -1)) ? ((val) & ~((size)-1)) + (size) : (val)) 36 #define ARROUND_DOWN(val, size) ((val) & ~((size) - 1)) 37 38 #define ABS(x) (((x) < 0) ? -(x) : (x)) 39 #define MIN(x,y) (((x) < (y)) ? (x) : (y)) 40 #define MAX(x,y) (((x) < (y)) ? (y) : (x)) 30 #include <hal_remote.h> 31 32 /********************************************************************************************** 33 * This file defines the API to access a generic bitmap, that can be local or remote. 34 * It is implemented as an array of uint32_t words. 35 * The number of entries in this array is statically defined at compile time 36 * and defines the max number of items that can be registered in the bitmap. 37 * The remote accesses are used in the VFS by the inum allocator. 38 *********************************************************************************************/ 39 40 typedef uint32_t bitmap_t; 41 42 /********************************************************************************************** 43 * This macro returns the number of 32 bits words required to register <size> entries. 44 *********************************************************************************************/ 45 46 #define BITMAP_SIZE(size) ( ((size) & 31) ? (((size)>>5) + 1) : ((size)>>5) ) 41 47 42 48 /********************************************************************************************** … … 44 50 * It returns 0xFFFFFFFF if data is larger than 0x80000000. 45 51 *********************************************************************************************/ 52 46 53 #define POW2_ROUNDUP(data) ( (data <= 0x00000001) ? 0x00000001 : \ 47 54 (data <= 0x00000002) ? 0x00000002 : \ … … 77 84 (data <= 0x80000000) ? 0x80000000 : 0xFFFFFFFF ) 78 85 79 /********************************************************************************************** 80 * This macro returns the number of 32 bits words required to register <size> entries. 81 *********************************************************************************************/ 82 83 #define BITMAP_SIZE(size) ( ((size) & 31) ? (((size)>>5) + 1) : ((size)>>5) ) 84 85 typedef uint32_t bitmap_t; 86 87 /********************************************************************************************* 88 * This function reset all bits in a bitmap. (array ot 32 bits words). 86 /********************************************************************************************* 87 * These macros are NOT used by the bitmap, but are useful in other contexts... [AG] 88 *********************************************************************************************/ 89 90 #define ARROUND_UP(val, size) (((val) & ((size) -1)) ? ((val) & ~((size)-1)) + (size) : (val)) 91 #define ARROUND_DOWN(val, size) ((val) & ~((size) - 1)) 92 93 #define ABS(x) (((x) < 0) ? -(x) : (x)) 94 #define MIN(x,y) (((x) < (y)) ? (x) : (y)) 95 #define MAX(x,y) (((x) < (y)) ? (y) : (x)) 96 97 /********************************************************************************************* 98 * This function reset all bits in a local or remote bitmap. 89 99 ********************************************************************************************* 90 100 * @ bitmap : pointer on first word in the bitmap. 91 * @ len : number of bits to reset. 92 ********************************************************************************************/ 93 void bitmap_init( bitmap_t * bitmap, 94 uint32_t len ); 95 96 /********************************************************************************************* 97 * This function set a specific bit in a bitmap. 101 * @ size : number of bits in bitmap. 102 ********************************************************************************************/ 103 extern void bitmap_init( bitmap_t * bitmap, 104 uint32_t size ); 105 106 extern void bitmap_remote_init( xptr_t bitmap_xp, 107 uint32_t size ); 108 109 /********************************************************************************************* 110 * These functions set a specific bit in a local or remote bitmap. 98 111 ********************************************************************************************* 99 112 * @ bitmap : pointer on the bitmap … … 103 116 uint32_t index ); 104 117 105 /********************************************************************************************* 106 * This function clear a specific bit in a bitmap. 118 extern inline void bitmap_remote_set( xptr_t bitmap_xp, 119 uint32_t index ); 120 121 /********************************************************************************************* 122 * These functions clear a specific bit in a local or remote bitmap. 107 123 ********************************************************************************************* 108 124 * @ bitmap : pointer on the bitmap … … 112 128 uint32_t index ); 113 129 114 /********************************************************************************************* 115 * This function returns a specific bit in a bitmap. 130 extern inline void bitmap_remote_clear( xptr_t bitmap_xp, 131 uint32_t index ); 132 133 /********************************************************************************************* 134 * These functions search the first bit non-set in a local or remote bitmap, in the 135 * range [0 , size-1], set this bit, and return the index of the found bit. 136 * The lock protecting the bitmap must be taken by the caller. 137 ********************************************************************************************* 138 * @ bitmap : pointer on the bitmap. 139 * @ size : number of bits to scan. 140 * @ returns index of found bit / returns 0xFFFFFFFF if not found. 141 ********************************************************************************************/ 142 extern uint32_t bitmap_alloc( bitmap_t * bitmap, 143 uint32_t size ); 144 145 extern uint32_t bitmap_remote_alloc( xptr_t bitmap_xp, 146 uint32_t size ); 147 148 /********************************************************************************************* 149 * This function returns the index of aa specific bit in a bitmap. 116 150 ********************************************************************************************* 117 151 * @ bitmap : pointer on the bitmap … … 179 213 180 214 /********************************************************************************************* 181 * This function returns the index of first bit cleared in a bitmap, starting from bit 0. 215 * These functions return the index of first bit cleared in a local or remote bitmap, 216 * starting from bit 0. 182 217 ********************************************************************************************* 183 218 * @ bitmap : pointer on the bitmap … … 187 222 extern uint32_t bitmap_ffc( bitmap_t * bitmap, 188 223 uint32_t size ); 224 225 extern uint32_t bitmap_remote_ffc( xptr_t bitmap_xp, 226 uint32_t size ); 189 227 190 228 /*********************************************************************************************
Note: See TracChangeset
for help on using the changeset viewer.