Ignore:
Timestamp:
Mar 18, 2020, 11:16:59 PM (4 years ago)
Author:
alain
Message:

Introduce remote_buf.c/.h & socket.c/.h files.
Update dev_nic.c/.h files.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/libk/bits.h

    r635 r657  
    11/*
    2  * bits.h - bits manipulation helper functions
     2 * bits.h - bitmap API definition
    33 *
    44 * Author   Ghassan Almaless (2008,2009,2010,2011,2012)
    5  *          Alain Greiner    (2016,2017,2018,2019)
     5 *          Alain Greiner    (2016,2017,2018,2019,2020)
    66 *
    77 * Copyright (c) UPMC Sorbonne Universites
     
    2828#include <kernel_config.h>
    2929#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
     40typedef 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) )
    4147
    4248/**********************************************************************************************
     
    4450 * It returns 0xFFFFFFFF if data is larger than 0x80000000.
    4551 *********************************************************************************************/
     52
    4653#define POW2_ROUNDUP(data) ( (data <= 0x00000001) ? 0x00000001  : \
    4754                             (data <= 0x00000002) ? 0x00000002  : \
     
    7784                             (data <= 0x80000000) ? 0x80000000  : 0xFFFFFFFF )
    7885
    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.
    8999 *********************************************************************************************
    90100 * @ 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 ********************************************************************************************/
     103extern void bitmap_init( bitmap_t * bitmap,
     104                         uint32_t   size );
     105
     106extern 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.
    98111 *********************************************************************************************
    99112 * @ bitmap  : pointer on the bitmap
     
    103116                               uint32_t   index );
    104117
    105 /*********************************************************************************************
    106  * This function clear a specific bit in a bitmap.
     118extern 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.
    107123 *********************************************************************************************
    108124 * @ bitmap  : pointer on the bitmap
     
    112128                                 uint32_t   index );
    113129
    114 /*********************************************************************************************
    115  * This function returns a specific bit in a bitmap.
     130extern 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 ********************************************************************************************/
     142extern uint32_t bitmap_alloc( bitmap_t * bitmap,
     143                              uint32_t   size );
     144
     145extern 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.
    116150 *********************************************************************************************
    117151 * @ bitmap  : pointer on the bitmap
     
    179213
    180214/*********************************************************************************************
    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.
    182217 *********************************************************************************************
    183218 * @ bitmap  : pointer on the bitmap
     
    187222extern uint32_t bitmap_ffc( bitmap_t * bitmap,
    188223                            uint32_t   size );
     224
     225extern uint32_t bitmap_remote_ffc( xptr_t   bitmap_xp,
     226                                   uint32_t size );
    189227
    190228/*********************************************************************************************
Note: See TracChangeset for help on using the changeset viewer.