Index: trunk/kernel/libk/bits.h
===================================================================
--- trunk/kernel/libk/bits.h	(revision 635)
+++ trunk/kernel/libk/bits.h	(revision 657)
@@ -1,7 +1,7 @@
 /*
- * bits.h - bits manipulation helper functions
+ * bits.h - bitmap API definition
  *
  * Author   Ghassan Almaless (2008,2009,2010,2011,2012)
- *          Alain Greiner    (2016,2017,2018,2019)
+ *          Alain Greiner    (2016,2017,2018,2019,2020)
  *
  * Copyright (c) UPMC Sorbonne Universites
@@ -28,15 +28,21 @@
 #include <kernel_config.h>
 #include <hal_kernel_types.h>
-
-/*********************************************************************************************
- * These macros are NOT used by the bitmap, but can be useful in other contexts... [AG]
- *********************************************************************************************/
-
-#define ARROUND_UP(val, size) (((val) & ((size) -1)) ? ((val) & ~((size)-1)) + (size) : (val))
-#define ARROUND_DOWN(val, size)  ((val) & ~((size) - 1))
-
-#define ABS(x) (((x) < 0) ? -(x) : (x))
-#define MIN(x,y) (((x) < (y)) ? (x) : (y))
-#define MAX(x,y) (((x) < (y)) ? (y) : (x))
+#include <hal_remote.h>
+
+/**********************************************************************************************
+ * This file defines the API to access a generic bitmap, that can be local or remote.
+ * It is implemented as an array of uint32_t words.
+ * The number of entries in this array is statically defined at compile time
+ * and defines the max number of items that can be registered in the bitmap.
+ * The remote accesses are used in the VFS by the inum allocator.
+ *********************************************************************************************/
+
+typedef uint32_t    bitmap_t;
+
+/**********************************************************************************************
+ * This macro returns the number of 32 bits words required to register <size> entries.
+ *********************************************************************************************/
+
+#define BITMAP_SIZE(size) ( ((size) & 31) ? (((size)>>5) + 1) : ((size)>>5) )
 
 /**********************************************************************************************
@@ -44,4 +50,5 @@
  * It returns 0xFFFFFFFF if data is larger than 0x80000000.
  *********************************************************************************************/
+
 #define POW2_ROUNDUP(data) ( (data <= 0x00000001) ? 0x00000001  : \
                              (data <= 0x00000002) ? 0x00000002  : \
@@ -77,23 +84,29 @@
                              (data <= 0x80000000) ? 0x80000000  : 0xFFFFFFFF )
 
-/**********************************************************************************************
- * This macro returns the number of 32 bits words required to register <size> entries.
- *********************************************************************************************/
-
-#define BITMAP_SIZE(size) ( ((size) & 31) ? (((size)>>5) + 1) : ((size)>>5) )
-
-typedef uint32_t    bitmap_t;
-
-/*********************************************************************************************
- * This function reset all bits in a bitmap. (array ot 32 bits words).
+/*********************************************************************************************
+ * These macros are NOT used by the bitmap, but are useful in other contexts... [AG]
+ *********************************************************************************************/
+
+#define ARROUND_UP(val, size) (((val) & ((size) -1)) ? ((val) & ~((size)-1)) + (size) : (val))
+#define ARROUND_DOWN(val, size)  ((val) & ~((size) - 1))
+
+#define ABS(x) (((x) < 0) ? -(x) : (x))
+#define MIN(x,y) (((x) < (y)) ? (x) : (y))
+#define MAX(x,y) (((x) < (y)) ? (y) : (x))
+
+/*********************************************************************************************
+ * This function reset all bits in a local or remote bitmap. 
  *********************************************************************************************
  * @ bitmap  : pointer on first word in the bitmap.
- * @ len     : number of bits to reset. 
- ********************************************************************************************/
-void bitmap_init( bitmap_t * bitmap,
-                  uint32_t   len );
-
-/*********************************************************************************************
- * This function set a specific bit in a bitmap.
+ * @ size    : number of bits in bitmap. 
+ ********************************************************************************************/
+extern void bitmap_init( bitmap_t * bitmap,
+                         uint32_t   size );
+
+extern void bitmap_remote_init( xptr_t   bitmap_xp,
+                                uint32_t size );
+
+/*********************************************************************************************
+ * These functions set a specific bit in a local or remote bitmap.
  *********************************************************************************************
  * @ bitmap  : pointer on the bitmap
@@ -103,6 +116,9 @@
                                uint32_t   index );
 
-/*********************************************************************************************
- * This function clear a specific bit in a bitmap.
+extern inline void bitmap_remote_set( xptr_t    bitmap_xp,
+                                      uint32_t  index );
+
+/*********************************************************************************************
+ * These functions clear a specific bit in a local or remote bitmap.
  *********************************************************************************************
  * @ bitmap  : pointer on the bitmap
@@ -112,6 +128,24 @@
                                  uint32_t   index );
 
-/*********************************************************************************************
- * This function returns a specific bit in a bitmap.
+extern inline void bitmap_remote_clear( xptr_t     bitmap_xp, 
+                                        uint32_t   index );
+
+/*********************************************************************************************
+ * These functions search the first bit non-set in a local or remote bitmap, in the
+ * range [0 , size-1], set this bit, and return the index of the found bit.
+ * The lock protecting the bitmap must be taken by the caller.
+ *********************************************************************************************
+ * @ bitmap  : pointer on the bitmap.
+ * @ size    : number of bits to scan.
+ * @ returns index of found bit / returns 0xFFFFFFFF if not found.
+ ********************************************************************************************/
+extern uint32_t bitmap_alloc( bitmap_t * bitmap, 
+                              uint32_t   size );
+
+extern uint32_t bitmap_remote_alloc( xptr_t    bitmap_xp,
+                                     uint32_t  size );
+
+/*********************************************************************************************
+ * This function returns the index of aa specific bit in a bitmap.
  *********************************************************************************************
  * @ bitmap  : pointer on the bitmap
@@ -179,5 +213,6 @@
 
 /*********************************************************************************************
- * This function returns the index of first bit cleared in a bitmap, starting from bit 0.
+ * These functions return the index of first bit cleared in a local or remote bitmap,
+ * starting from bit 0.
  *********************************************************************************************
  * @ bitmap  : pointer on the bitmap
@@ -187,4 +222,7 @@
 extern uint32_t bitmap_ffc( bitmap_t * bitmap, 
                             uint32_t   size );
+
+extern uint32_t bitmap_remote_ffc( xptr_t   bitmap_xp, 
+                                   uint32_t size );
 
 /*********************************************************************************************
