Lines Matching full:bitmap
3 * lib/bitmap.c
4 * Helper functions for bitmap.h.
7 #include <linux/bitmap.h>
26 * DOC: bitmap introduction
30 * given bitmap does _not_ need to be an exact multiple of
34 * of a bitmap are 'don't care'. The implementation makes
37 * The bitmap operations that return Boolean (bitmap_empty,
93 * __bitmap_shift_right - logical right shift of the bits in a bitmap
94 * @dst : destination bitmap
95 * @src : source bitmap
97 * @nbits : bitmap size, in bits
137 * __bitmap_shift_left - logical left shift of the bits in a bitmap
138 * @dst : destination bitmap
139 * @src : source bitmap
141 * @nbits : bitmap size, in bits
174 * bitmap_cut() - remove bit region from bitmap and right shift remaining bits
175 * @dst: destination bitmap, might overlap with src
176 * @src: source bitmap
179 * @nbits: bitmap size, in bits
187 * The @src bitmap is::
349 unsigned int __bitmap_weight(const unsigned long *bitmap, unsigned int bits) in __bitmap_weight() argument
351 return BITMAP_WEIGHT(bitmap[idx], bits); in __bitmap_weight()
407 * @size: The bitmap size in bits
444 * Bitmap printing & parsing functions: first version by Nadia Yvette Chambers,
449 * bitmap_parse_user - convert an ASCII hex string in a user buffer into a bitmap
454 * @maskp: pointer to bitmap array that will contain result.
455 * @nmaskbits: size of bitmap, in bits.
476 * bitmap_print_to_pagebuf - convert bitmap to list or hex format ASCII string
477 * @list: indicates whether the bitmap must be list
479 * @maskp: pointer to bitmap to convert
480 * @nmaskbits: size of bitmap, in bits
502 * bitmap_print_to_buf - convert bitmap to list or hex format ASCII string
503 * @list: indicates whether the bitmap must be list
507 * @maskp: pointer to bitmap to convert
508 * @nmaskbits: size of bitmap, in bits
530 * bitmap_print_bitmask_to_buf - convert bitmap to hex bitmask format ASCII string
532 * @maskp: pointer to bitmap to convert
533 * @nmaskbits: size of bitmap, in bits
560 * The problem is once we have a large bitmap, we have a chance to get a
601 * - If printing part of bitmap as list, the resulting string is not a correct
602 * list representation of bitmap. Particularly, some bits within or out of
605 * - If printing the whole bitmap as list by parts, user must ensure the order
607 * - If printing the whole bitmap as list by parts, user must keep bitmap
621 * bitmap_print_list_to_buf - convert bitmap to decimal list format ASCII string
623 * @maskp: pointer to bitmap to convert
624 * @nmaskbits: size of bitmap, in bits
639 * Region 9-38:4/10 describes the following bitmap structure:
653 static void bitmap_set_region(const struct region *r, unsigned long *bitmap) in bitmap_set_region() argument
658 bitmap_set(bitmap, start, min(r->end - start + 1, r->off)); in bitmap_set_region()
780 * bitmap_parselist - convert list format ASCII string to bitmap
797 * dynamic, so if system changes cause the bitmap width to change, such
838 * string to bitmap
843 * @maskp: pointer to bitmap array that will contain result.
844 * @nmaskbits: size of bitmap, in bits.
891 * bitmap_parse - convert an ASCII hex string into a bitmap.
896 * @maskp: pointer to bitmap array that will contain result.
897 * @nmaskbits: size of bitmap, in bits.
911 u32 *bitmap = (u32 *)maskp; in bitmap_parse() local
924 end = bitmap_get_x32_reverse(start, end, &bitmap[chunk ^ 1]); in bitmap_parse()
926 end = bitmap_get_x32_reverse(start, end, &bitmap[chunk]); in bitmap_parse()
946 * bitmap_pos_to_ord - find ordinal of set bit at given position in bitmap
947 * @buf: pointer to a bitmap
972 * bitmap_remap - Apply map defined by a pair of bitmaps to another bitmap
1065 * bitmap_onto - translate one bitmap relative to another
1066 * @dst: resulting translated bitmap
1067 * @orig: original untranslated bitmap
1068 * @relmap: bitmap relative to which translated
1087 * @orig bitmap over itself so that all its set bits x are in the
1130 * unsigned long *tmp; // a temporary bitmap's bits
1138 * using bitmap_fold() to fold the @orig bitmap modulo ten
1199 * bitmap_fold - fold larger bitmap into smaller, modulo specified size
1200 * @dst: resulting smaller bitmap
1201 * @orig: original larger bitmap
1225 * bitmap: array of unsigned longs corresponding to the bitmap
1228 * reg_op: operation(s) to perform on that region of bitmap
1230 * Can set, verify and/or release a region of bits in a bitmap,
1233 * A region of a bitmap is a sequence of bits in the bitmap, of
1247 static int __reg_op(unsigned long *bitmap, unsigned int pos, int order, int reg_op) in __reg_op() argument
1250 int index; /* index first long of region in bitmap */ in __reg_op()
1251 int offset; /* bit offset region in bitmap[index] */ in __reg_op()
1252 int nlongs_reg; /* num longs spanned by region in bitmap */ in __reg_op()
1255 int i; /* scans bitmap by longs */ in __reg_op()
1279 if (bitmap[index + i] & mask) in __reg_op()
1287 bitmap[index + i] |= mask; in __reg_op()
1292 bitmap[index + i] &= ~mask; in __reg_op()
1301 * @bitmap: array of unsigned longs corresponding to the bitmap
1302 * @bits: number of bits in the bitmap
1305 * Find a region of free (zero) bits in a @bitmap of @bits bits and
1310 * Return the bit offset in bitmap of the allocated region,
1313 int bitmap_find_free_region(unsigned long *bitmap, unsigned int bits, int order) in bitmap_find_free_region() argument
1315 unsigned int pos, end; /* scans bitmap by regions of size order */ in bitmap_find_free_region()
1318 if (!__reg_op(bitmap, pos, order, REG_OP_ISFREE)) in bitmap_find_free_region()
1320 __reg_op(bitmap, pos, order, REG_OP_ALLOC); in bitmap_find_free_region()
1328 * bitmap_release_region - release allocated bitmap region
1329 * @bitmap: array of unsigned longs corresponding to the bitmap
1334 * the found region (by clearing it in the bitmap).
1338 void bitmap_release_region(unsigned long *bitmap, unsigned int pos, int order) in bitmap_release_region() argument
1340 __reg_op(bitmap, pos, order, REG_OP_RELEASE); in bitmap_release_region()
1345 * bitmap_allocate_region - allocate bitmap region
1346 * @bitmap: array of unsigned longs corresponding to the bitmap
1350 * Allocate (set bits in) a specified region of a bitmap.
1355 int bitmap_allocate_region(unsigned long *bitmap, unsigned int pos, int order) in bitmap_allocate_region() argument
1357 if (!__reg_op(bitmap, pos, order, REG_OP_ISFREE)) in bitmap_allocate_region()
1359 return __reg_op(bitmap, pos, order, REG_OP_ALLOC); in bitmap_allocate_region()
1364 * bitmap_copy_le - copy a bitmap, putting the bits into little-endian order.
1366 * @src: bitmap to copy
1367 * @nbits: number of bits in the bitmap
1412 void bitmap_free(const unsigned long *bitmap) in bitmap_free() argument
1414 kfree(bitmap); in bitmap_free()
1420 unsigned long *bitmap = data; in devm_bitmap_free() local
1422 bitmap_free(bitmap); in devm_bitmap_free()
1428 unsigned long *bitmap; in devm_bitmap_alloc() local
1431 bitmap = bitmap_alloc(nbits, flags); in devm_bitmap_alloc()
1432 if (!bitmap) in devm_bitmap_alloc()
1435 ret = devm_add_action_or_reset(dev, devm_bitmap_free, bitmap); in devm_bitmap_alloc()
1439 return bitmap; in devm_bitmap_alloc()
1452 * bitmap_from_arr32 - copy the contents of u32 array of bits to bitmap
1453 * @bitmap: array of unsigned longs, the destination bitmap
1454 * @buf: array of u32 (in host byte order), the source bitmap
1455 * @nbits: number of bits in @bitmap
1457 void bitmap_from_arr32(unsigned long *bitmap, const u32 *buf, unsigned int nbits) in bitmap_from_arr32() argument
1463 bitmap[i/2] = (unsigned long) buf[i]; in bitmap_from_arr32()
1465 bitmap[i/2] |= ((unsigned long) buf[i]) << 32; in bitmap_from_arr32()
1470 bitmap[(halfwords - 1) / 2] &= BITMAP_LAST_WORD_MASK(nbits); in bitmap_from_arr32()
1475 * bitmap_to_arr32 - copy the contents of bitmap to a u32 array of bits
1476 * @buf: array of u32 (in host byte order), the dest bitmap
1477 * @bitmap: array of unsigned longs, the source bitmap
1478 * @nbits: number of bits in @bitmap
1480 void bitmap_to_arr32(u32 *buf, const unsigned long *bitmap, unsigned int nbits) in bitmap_to_arr32() argument
1486 buf[i] = (u32) (bitmap[i/2] & UINT_MAX); in bitmap_to_arr32()
1488 buf[i] = (u32) (bitmap[i/2] >> 32); in bitmap_to_arr32()
1500 * bitmap_from_arr64 - copy the contents of u64 array of bits to bitmap
1501 * @bitmap: array of unsigned longs, the destination bitmap
1502 * @buf: array of u64 (in host byte order), the source bitmap
1503 * @nbits: number of bits in @bitmap
1505 void bitmap_from_arr64(unsigned long *bitmap, const u64 *buf, unsigned int nbits) in bitmap_from_arr64() argument
1512 *bitmap++ = val; in bitmap_from_arr64()
1514 *bitmap++ = val >> 32; in bitmap_from_arr64()
1521 * to the last word of the bitmap, except for nbits == 0, which in bitmap_from_arr64()
1525 bitmap[-1] &= BITMAP_LAST_WORD_MASK(nbits); in bitmap_from_arr64()
1530 * bitmap_to_arr64 - copy the contents of bitmap to a u64 array of bits
1531 * @buf: array of u64 (in host byte order), the dest bitmap
1532 * @bitmap: array of unsigned longs, the source bitmap
1533 * @nbits: number of bits in @bitmap
1535 void bitmap_to_arr64(u64 *buf, const unsigned long *bitmap, unsigned int nbits) in bitmap_to_arr64() argument
1537 const unsigned long *end = bitmap + BITS_TO_LONGS(nbits); in bitmap_to_arr64()
1539 while (bitmap < end) { in bitmap_to_arr64()
1540 *buf = *bitmap++; in bitmap_to_arr64()
1541 if (bitmap < end) in bitmap_to_arr64()
1542 *buf |= (u64)(*bitmap++) << 32; in bitmap_to_arr64()