mirror of
https://github.com/rd-stuffs/msm-4.14.git
synced 2025-02-20 11:45:48 +08:00
Many source files in the tree are missing licensing information, which makes it harder for compliance tools to determine the correct license. By default all files without license information are under the default license of the kernel, which is GPL version 2. Update the files which contain no license information with the 'GPL-2.0' SPDX license identifier. The SPDX identifier is a legally binding shorthand, which can be used instead of the full boiler plate text. This patch is based on work done by Thomas Gleixner and Kate Stewart and Philippe Ombredanne. How this work was done: Patches were generated and checked against linux-4.14-rc6 for a subset of the use cases: - file had no licensing information it it. - file was a */uapi/* one with no licensing information in it, - file was a */uapi/* one with existing licensing information, Further patches will be generated in subsequent months to fix up cases where non-standard license headers were used, and references to license had to be inferred by heuristics based on keywords. The analysis to determine which SPDX License Identifier to be applied to a file was done in a spreadsheet of side by side results from of the output of two independent scanners (ScanCode & Windriver) producing SPDX tag:value files created by Philippe Ombredanne. Philippe prepared the base worksheet, and did an initial spot review of a few 1000 files. The 4.13 kernel was the starting point of the analysis with 60,537 files assessed. Kate Stewart did a file by file comparison of the scanner results in the spreadsheet to determine which SPDX license identifier(s) to be applied to the file. She confirmed any determination that was not immediately clear with lawyers working with the Linux Foundation. Criteria used to select files for SPDX license identifier tagging was: - Files considered eligible had to be source code files. - Make and config files were included as candidates if they contained >5 lines of source - File already had some variant of a license header in it (even if <5 lines). All documentation files were explicitly excluded. The following heuristics were used to determine which SPDX license identifiers to apply. - when both scanners couldn't find any license traces, file was considered to have no license information in it, and the top level COPYING file license applied. For non */uapi/* files that summary was: SPDX license identifier # files ---------------------------------------------------|------- GPL-2.0 11139 and resulted in the first patch in this series. If that file was a */uapi/* path one, it was "GPL-2.0 WITH Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was: SPDX license identifier # files ---------------------------------------------------|------- GPL-2.0 WITH Linux-syscall-note 930 and resulted in the second patch in this series. - if a file had some form of licensing information in it, and was one of the */uapi/* ones, it was denoted with the Linux-syscall-note if any GPL family license was found in the file or had no licensing in it (per prior point). Results summary: SPDX license identifier # files ---------------------------------------------------|------ GPL-2.0 WITH Linux-syscall-note 270 GPL-2.0+ WITH Linux-syscall-note 169 ((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21 ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17 LGPL-2.1+ WITH Linux-syscall-note 15 GPL-1.0+ WITH Linux-syscall-note 14 ((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5 LGPL-2.0+ WITH Linux-syscall-note 4 LGPL-2.1 WITH Linux-syscall-note 3 ((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3 ((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1 and that resulted in the third patch in this series. - when the two scanners agreed on the detected license(s), that became the concluded license(s). - when there was disagreement between the two scanners (one detected a license but the other didn't, or they both detected different licenses) a manual inspection of the file occurred. - In most cases a manual inspection of the information in the file resulted in a clear resolution of the license that should apply (and which scanner probably needed to revisit its heuristics). - When it was not immediately clear, the license identifier was confirmed with lawyers working with the Linux Foundation. - If there was any question as to the appropriate license identifier, the file was flagged for further research and to be revisited later in time. In total, over 70 hours of logged manual review was done on the spreadsheet to determine the SPDX license identifiers to apply to the source files by Kate, Philippe, Thomas and, in some cases, confirmation by lawyers working with the Linux Foundation. Kate also obtained a third independent scan of the 4.13 code base from FOSSology, and compared selected files where the other two scanners disagreed against that SPDX file, to see if there was new insights. The Windriver scanner is based on an older version of FOSSology in part, so they are related. Thomas did random spot checks in about 500 files from the spreadsheets for the uapi headers and agreed with SPDX license identifier in the files he inspected. For the non-uapi files Thomas did random spot checks in about 15000 files. In initial set of patches against 4.14-rc6, 3 files were found to have copy/paste license identifier errors, and have been fixed to reflect the correct identifier. Additionally Philippe spent 10 hours this week doing a detailed manual inspection and review of the 12,461 patched files from the initial patch version early this week with: - a full scancode scan run, collecting the matched texts, detected license ids and scores - reviewing anything where there was a license detected (about 500+ files) to ensure that the applied SPDX license was correct - reviewing anything where there was no detection but the patch license was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied SPDX license was correct This produced a worksheet with 20 files needing minor correction. This worksheet was then exported into 3 different .csv files for the different types of files to be modified. These .csv files were then reviewed by Greg. Thomas wrote a script to parse the csv files and add the proper SPDX tag to the file, in the format that the file expected. This script was further refined by Greg based on the output to detect more types of files automatically and to distinguish between header and source .c files (which need different comment types.) Finally Greg ran the script using the .csv files to generate the patches. Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org> Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com> Reviewed-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
417 lines
15 KiB
C
417 lines
15 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef __LINUX_BITMAP_H
|
|
#define __LINUX_BITMAP_H
|
|
|
|
#ifndef __ASSEMBLY__
|
|
|
|
#include <linux/types.h>
|
|
#include <linux/bitops.h>
|
|
#include <linux/string.h>
|
|
#include <linux/kernel.h>
|
|
|
|
/*
|
|
* bitmaps provide bit arrays that consume one or more unsigned
|
|
* longs. The bitmap interface and available operations are listed
|
|
* here, in bitmap.h
|
|
*
|
|
* Function implementations generic to all architectures are in
|
|
* lib/bitmap.c. Functions implementations that are architecture
|
|
* specific are in various include/asm-<arch>/bitops.h headers
|
|
* and other arch/<arch> specific files.
|
|
*
|
|
* See lib/bitmap.c for more details.
|
|
*/
|
|
|
|
/*
|
|
* The available bitmap operations and their rough meaning in the
|
|
* case that the bitmap is a single unsigned long are thus:
|
|
*
|
|
* Note that nbits should be always a compile time evaluable constant.
|
|
* Otherwise many inlines will generate horrible code.
|
|
*
|
|
* bitmap_zero(dst, nbits) *dst = 0UL
|
|
* bitmap_fill(dst, nbits) *dst = ~0UL
|
|
* bitmap_copy(dst, src, nbits) *dst = *src
|
|
* bitmap_and(dst, src1, src2, nbits) *dst = *src1 & *src2
|
|
* bitmap_or(dst, src1, src2, nbits) *dst = *src1 | *src2
|
|
* bitmap_xor(dst, src1, src2, nbits) *dst = *src1 ^ *src2
|
|
* bitmap_andnot(dst, src1, src2, nbits) *dst = *src1 & ~(*src2)
|
|
* bitmap_complement(dst, src, nbits) *dst = ~(*src)
|
|
* bitmap_equal(src1, src2, nbits) Are *src1 and *src2 equal?
|
|
* bitmap_intersects(src1, src2, nbits) Do *src1 and *src2 overlap?
|
|
* bitmap_subset(src1, src2, nbits) Is *src1 a subset of *src2?
|
|
* bitmap_empty(src, nbits) Are all bits zero in *src?
|
|
* bitmap_full(src, nbits) Are all bits set in *src?
|
|
* bitmap_weight(src, nbits) Hamming Weight: number set bits
|
|
* bitmap_set(dst, pos, nbits) Set specified bit area
|
|
* bitmap_clear(dst, pos, nbits) Clear specified bit area
|
|
* bitmap_find_next_zero_area(buf, len, pos, n, mask) Find bit free area
|
|
* bitmap_find_next_zero_area_off(buf, len, pos, n, mask) as above
|
|
* bitmap_shift_right(dst, src, n, nbits) *dst = *src >> n
|
|
* bitmap_shift_left(dst, src, n, nbits) *dst = *src << n
|
|
* bitmap_remap(dst, src, old, new, nbits) *dst = map(old, new)(src)
|
|
* bitmap_bitremap(oldbit, old, new, nbits) newbit = map(old, new)(oldbit)
|
|
* bitmap_onto(dst, orig, relmap, nbits) *dst = orig relative to relmap
|
|
* bitmap_fold(dst, orig, sz, nbits) dst bits = orig bits mod sz
|
|
* bitmap_parse(buf, buflen, dst, nbits) Parse bitmap dst from kernel buf
|
|
* bitmap_parse_user(ubuf, ulen, dst, nbits) Parse bitmap dst from user buf
|
|
* bitmap_parselist(buf, dst, nbits) Parse bitmap dst from kernel buf
|
|
* bitmap_parselist_user(buf, dst, nbits) Parse bitmap dst from user buf
|
|
* bitmap_find_free_region(bitmap, bits, order) Find and allocate bit region
|
|
* bitmap_release_region(bitmap, pos, order) Free specified bit region
|
|
* bitmap_allocate_region(bitmap, pos, order) Allocate specified bit region
|
|
* bitmap_from_u32array(dst, nbits, buf, nwords) *dst = *buf (nwords 32b words)
|
|
* bitmap_to_u32array(buf, nwords, src, nbits) *buf = *dst (nwords 32b words)
|
|
*/
|
|
|
|
/*
|
|
* Also the following operations in asm/bitops.h apply to bitmaps.
|
|
*
|
|
* set_bit(bit, addr) *addr |= bit
|
|
* clear_bit(bit, addr) *addr &= ~bit
|
|
* change_bit(bit, addr) *addr ^= bit
|
|
* test_bit(bit, addr) Is bit set in *addr?
|
|
* test_and_set_bit(bit, addr) Set bit and return old value
|
|
* test_and_clear_bit(bit, addr) Clear bit and return old value
|
|
* test_and_change_bit(bit, addr) Change bit and return old value
|
|
* find_first_zero_bit(addr, nbits) Position first zero bit in *addr
|
|
* find_first_bit(addr, nbits) Position first set bit in *addr
|
|
* find_next_zero_bit(addr, nbits, bit) Position next zero bit in *addr >= bit
|
|
* find_next_bit(addr, nbits, bit) Position next set bit in *addr >= bit
|
|
*/
|
|
|
|
/*
|
|
* The DECLARE_BITMAP(name,bits) macro, in linux/types.h, can be used
|
|
* to declare an array named 'name' of just enough unsigned longs to
|
|
* contain all bit positions from 0 to 'bits' - 1.
|
|
*/
|
|
|
|
/*
|
|
* lib/bitmap.c provides these functions:
|
|
*/
|
|
|
|
extern int __bitmap_empty(const unsigned long *bitmap, unsigned int nbits);
|
|
extern int __bitmap_full(const unsigned long *bitmap, unsigned int nbits);
|
|
extern int __bitmap_equal(const unsigned long *bitmap1,
|
|
const unsigned long *bitmap2, unsigned int nbits);
|
|
extern void __bitmap_complement(unsigned long *dst, const unsigned long *src,
|
|
unsigned int nbits);
|
|
extern void __bitmap_shift_right(unsigned long *dst, const unsigned long *src,
|
|
unsigned int shift, unsigned int nbits);
|
|
extern void __bitmap_shift_left(unsigned long *dst, const unsigned long *src,
|
|
unsigned int shift, unsigned int nbits);
|
|
extern int __bitmap_and(unsigned long *dst, const unsigned long *bitmap1,
|
|
const unsigned long *bitmap2, unsigned int nbits);
|
|
extern void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1,
|
|
const unsigned long *bitmap2, unsigned int nbits);
|
|
extern void __bitmap_xor(unsigned long *dst, const unsigned long *bitmap1,
|
|
const unsigned long *bitmap2, unsigned int nbits);
|
|
extern int __bitmap_andnot(unsigned long *dst, const unsigned long *bitmap1,
|
|
const unsigned long *bitmap2, unsigned int nbits);
|
|
extern int __bitmap_intersects(const unsigned long *bitmap1,
|
|
const unsigned long *bitmap2, unsigned int nbits);
|
|
extern int __bitmap_subset(const unsigned long *bitmap1,
|
|
const unsigned long *bitmap2, unsigned int nbits);
|
|
extern int __bitmap_weight(const unsigned long *bitmap, unsigned int nbits);
|
|
extern void __bitmap_set(unsigned long *map, unsigned int start, int len);
|
|
extern void __bitmap_clear(unsigned long *map, unsigned int start, int len);
|
|
|
|
extern unsigned long bitmap_find_next_zero_area_off(unsigned long *map,
|
|
unsigned long size,
|
|
unsigned long start,
|
|
unsigned int nr,
|
|
unsigned long align_mask,
|
|
unsigned long align_offset);
|
|
|
|
/**
|
|
* bitmap_find_next_zero_area - find a contiguous aligned zero area
|
|
* @map: The address to base the search on
|
|
* @size: The bitmap size in bits
|
|
* @start: The bitnumber to start searching at
|
|
* @nr: The number of zeroed bits we're looking for
|
|
* @align_mask: Alignment mask for zero area
|
|
*
|
|
* The @align_mask should be one less than a power of 2; the effect is that
|
|
* the bit offset of all zero areas this function finds is multiples of that
|
|
* power of 2. A @align_mask of 0 means no alignment is required.
|
|
*/
|
|
static inline unsigned long
|
|
bitmap_find_next_zero_area(unsigned long *map,
|
|
unsigned long size,
|
|
unsigned long start,
|
|
unsigned int nr,
|
|
unsigned long align_mask)
|
|
{
|
|
return bitmap_find_next_zero_area_off(map, size, start, nr,
|
|
align_mask, 0);
|
|
}
|
|
|
|
extern int __bitmap_parse(const char *buf, unsigned int buflen, int is_user,
|
|
unsigned long *dst, int nbits);
|
|
extern int bitmap_parse_user(const char __user *ubuf, unsigned int ulen,
|
|
unsigned long *dst, int nbits);
|
|
extern int bitmap_parselist(const char *buf, unsigned long *maskp,
|
|
int nmaskbits);
|
|
extern int bitmap_parselist_user(const char __user *ubuf, unsigned int ulen,
|
|
unsigned long *dst, int nbits);
|
|
extern void bitmap_remap(unsigned long *dst, const unsigned long *src,
|
|
const unsigned long *old, const unsigned long *new, unsigned int nbits);
|
|
extern int bitmap_bitremap(int oldbit,
|
|
const unsigned long *old, const unsigned long *new, int bits);
|
|
extern void bitmap_onto(unsigned long *dst, const unsigned long *orig,
|
|
const unsigned long *relmap, unsigned int bits);
|
|
extern void bitmap_fold(unsigned long *dst, const unsigned long *orig,
|
|
unsigned int sz, unsigned int nbits);
|
|
extern int bitmap_find_free_region(unsigned long *bitmap, unsigned int bits, int order);
|
|
extern void bitmap_release_region(unsigned long *bitmap, unsigned int pos, int order);
|
|
extern int bitmap_allocate_region(unsigned long *bitmap, unsigned int pos, int order);
|
|
extern unsigned int bitmap_from_u32array(unsigned long *bitmap,
|
|
unsigned int nbits,
|
|
const u32 *buf,
|
|
unsigned int nwords);
|
|
extern unsigned int bitmap_to_u32array(u32 *buf,
|
|
unsigned int nwords,
|
|
const unsigned long *bitmap,
|
|
unsigned int nbits);
|
|
#ifdef __BIG_ENDIAN
|
|
extern void bitmap_copy_le(unsigned long *dst, const unsigned long *src, unsigned int nbits);
|
|
#else
|
|
#define bitmap_copy_le bitmap_copy
|
|
#endif
|
|
extern unsigned int bitmap_ord_to_pos(const unsigned long *bitmap, unsigned int ord, unsigned int nbits);
|
|
extern int bitmap_print_to_pagebuf(bool list, char *buf,
|
|
const unsigned long *maskp, int nmaskbits);
|
|
|
|
#define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) & (BITS_PER_LONG - 1)))
|
|
#define BITMAP_LAST_WORD_MASK(nbits) (~0UL >> (-(nbits) & (BITS_PER_LONG - 1)))
|
|
|
|
#define small_const_nbits(nbits) \
|
|
(__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG)
|
|
|
|
static inline void bitmap_zero(unsigned long *dst, unsigned int nbits)
|
|
{
|
|
if (small_const_nbits(nbits))
|
|
*dst = 0UL;
|
|
else {
|
|
unsigned int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long);
|
|
memset(dst, 0, len);
|
|
}
|
|
}
|
|
|
|
static inline void bitmap_fill(unsigned long *dst, unsigned int nbits)
|
|
{
|
|
unsigned int nlongs = BITS_TO_LONGS(nbits);
|
|
if (!small_const_nbits(nbits)) {
|
|
unsigned int len = (nlongs - 1) * sizeof(unsigned long);
|
|
memset(dst, 0xff, len);
|
|
}
|
|
dst[nlongs - 1] = BITMAP_LAST_WORD_MASK(nbits);
|
|
}
|
|
|
|
static inline void bitmap_copy(unsigned long *dst, const unsigned long *src,
|
|
unsigned int nbits)
|
|
{
|
|
if (small_const_nbits(nbits))
|
|
*dst = *src;
|
|
else {
|
|
unsigned int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long);
|
|
memcpy(dst, src, len);
|
|
}
|
|
}
|
|
|
|
static inline int bitmap_and(unsigned long *dst, const unsigned long *src1,
|
|
const unsigned long *src2, unsigned int nbits)
|
|
{
|
|
if (small_const_nbits(nbits))
|
|
return (*dst = *src1 & *src2 & BITMAP_LAST_WORD_MASK(nbits)) != 0;
|
|
return __bitmap_and(dst, src1, src2, nbits);
|
|
}
|
|
|
|
static inline void bitmap_or(unsigned long *dst, const unsigned long *src1,
|
|
const unsigned long *src2, unsigned int nbits)
|
|
{
|
|
if (small_const_nbits(nbits))
|
|
*dst = *src1 | *src2;
|
|
else
|
|
__bitmap_or(dst, src1, src2, nbits);
|
|
}
|
|
|
|
static inline void bitmap_xor(unsigned long *dst, const unsigned long *src1,
|
|
const unsigned long *src2, unsigned int nbits)
|
|
{
|
|
if (small_const_nbits(nbits))
|
|
*dst = *src1 ^ *src2;
|
|
else
|
|
__bitmap_xor(dst, src1, src2, nbits);
|
|
}
|
|
|
|
static inline int bitmap_andnot(unsigned long *dst, const unsigned long *src1,
|
|
const unsigned long *src2, unsigned int nbits)
|
|
{
|
|
if (small_const_nbits(nbits))
|
|
return (*dst = *src1 & ~(*src2) & BITMAP_LAST_WORD_MASK(nbits)) != 0;
|
|
return __bitmap_andnot(dst, src1, src2, nbits);
|
|
}
|
|
|
|
static inline void bitmap_complement(unsigned long *dst, const unsigned long *src,
|
|
unsigned int nbits)
|
|
{
|
|
if (small_const_nbits(nbits))
|
|
*dst = ~(*src);
|
|
else
|
|
__bitmap_complement(dst, src, nbits);
|
|
}
|
|
|
|
static inline int bitmap_equal(const unsigned long *src1,
|
|
const unsigned long *src2, unsigned int nbits)
|
|
{
|
|
if (small_const_nbits(nbits))
|
|
return !((*src1 ^ *src2) & BITMAP_LAST_WORD_MASK(nbits));
|
|
if (__builtin_constant_p(nbits & 7) && IS_ALIGNED(nbits, 8))
|
|
return !memcmp(src1, src2, nbits / 8);
|
|
return __bitmap_equal(src1, src2, nbits);
|
|
}
|
|
|
|
static inline int bitmap_intersects(const unsigned long *src1,
|
|
const unsigned long *src2, unsigned int nbits)
|
|
{
|
|
if (small_const_nbits(nbits))
|
|
return ((*src1 & *src2) & BITMAP_LAST_WORD_MASK(nbits)) != 0;
|
|
else
|
|
return __bitmap_intersects(src1, src2, nbits);
|
|
}
|
|
|
|
static inline int bitmap_subset(const unsigned long *src1,
|
|
const unsigned long *src2, unsigned int nbits)
|
|
{
|
|
if (small_const_nbits(nbits))
|
|
return ! ((*src1 & ~(*src2)) & BITMAP_LAST_WORD_MASK(nbits));
|
|
else
|
|
return __bitmap_subset(src1, src2, nbits);
|
|
}
|
|
|
|
static inline int bitmap_empty(const unsigned long *src, unsigned nbits)
|
|
{
|
|
if (small_const_nbits(nbits))
|
|
return ! (*src & BITMAP_LAST_WORD_MASK(nbits));
|
|
|
|
return find_first_bit(src, nbits) == nbits;
|
|
}
|
|
|
|
static inline int bitmap_full(const unsigned long *src, unsigned int nbits)
|
|
{
|
|
if (small_const_nbits(nbits))
|
|
return ! (~(*src) & BITMAP_LAST_WORD_MASK(nbits));
|
|
|
|
return find_first_zero_bit(src, nbits) == nbits;
|
|
}
|
|
|
|
static __always_inline int bitmap_weight(const unsigned long *src, unsigned int nbits)
|
|
{
|
|
if (small_const_nbits(nbits))
|
|
return hweight_long(*src & BITMAP_LAST_WORD_MASK(nbits));
|
|
return __bitmap_weight(src, nbits);
|
|
}
|
|
|
|
static __always_inline void bitmap_set(unsigned long *map, unsigned int start,
|
|
unsigned int nbits)
|
|
{
|
|
if (__builtin_constant_p(nbits) && nbits == 1)
|
|
__set_bit(start, map);
|
|
else if (__builtin_constant_p(start & 7) && IS_ALIGNED(start, 8) &&
|
|
__builtin_constant_p(nbits & 7) && IS_ALIGNED(nbits, 8))
|
|
memset((char *)map + start / 8, 0xff, nbits / 8);
|
|
else
|
|
__bitmap_set(map, start, nbits);
|
|
}
|
|
|
|
static __always_inline void bitmap_clear(unsigned long *map, unsigned int start,
|
|
unsigned int nbits)
|
|
{
|
|
if (__builtin_constant_p(nbits) && nbits == 1)
|
|
__clear_bit(start, map);
|
|
else if (__builtin_constant_p(start & 7) && IS_ALIGNED(start, 8) &&
|
|
__builtin_constant_p(nbits & 7) && IS_ALIGNED(nbits, 8))
|
|
memset((char *)map + start / 8, 0, nbits / 8);
|
|
else
|
|
__bitmap_clear(map, start, nbits);
|
|
}
|
|
|
|
static inline void bitmap_shift_right(unsigned long *dst, const unsigned long *src,
|
|
unsigned int shift, int nbits)
|
|
{
|
|
if (small_const_nbits(nbits))
|
|
*dst = (*src & BITMAP_LAST_WORD_MASK(nbits)) >> shift;
|
|
else
|
|
__bitmap_shift_right(dst, src, shift, nbits);
|
|
}
|
|
|
|
static inline void bitmap_shift_left(unsigned long *dst, const unsigned long *src,
|
|
unsigned int shift, unsigned int nbits)
|
|
{
|
|
if (small_const_nbits(nbits))
|
|
*dst = (*src << shift) & BITMAP_LAST_WORD_MASK(nbits);
|
|
else
|
|
__bitmap_shift_left(dst, src, shift, nbits);
|
|
}
|
|
|
|
static inline int bitmap_parse(const char *buf, unsigned int buflen,
|
|
unsigned long *maskp, int nmaskbits)
|
|
{
|
|
return __bitmap_parse(buf, buflen, 0, maskp, nmaskbits);
|
|
}
|
|
|
|
/*
|
|
* BITMAP_FROM_U64() - Represent u64 value in the format suitable for bitmap.
|
|
*
|
|
* Linux bitmaps are internally arrays of unsigned longs, i.e. 32-bit
|
|
* integers in 32-bit environment, and 64-bit integers in 64-bit one.
|
|
*
|
|
* There are four combinations of endianness and length of the word in linux
|
|
* ABIs: LE64, BE64, LE32 and BE32.
|
|
*
|
|
* On 64-bit kernels 64-bit LE and BE numbers are naturally ordered in
|
|
* bitmaps and therefore don't require any special handling.
|
|
*
|
|
* On 32-bit kernels 32-bit LE ABI orders lo word of 64-bit number in memory
|
|
* prior to hi, and 32-bit BE orders hi word prior to lo. The bitmap on the
|
|
* other hand is represented as an array of 32-bit words and the position of
|
|
* bit N may therefore be calculated as: word #(N/32) and bit #(N%32) in that
|
|
* word. For example, bit #42 is located at 10th position of 2nd word.
|
|
* It matches 32-bit LE ABI, and we can simply let the compiler store 64-bit
|
|
* values in memory as it usually does. But for BE we need to swap hi and lo
|
|
* words manually.
|
|
*
|
|
* With all that, the macro BITMAP_FROM_U64() does explicit reordering of hi and
|
|
* lo parts of u64. For LE32 it does nothing, and for BE environment it swaps
|
|
* hi and lo words, as is expected by bitmap.
|
|
*/
|
|
#if __BITS_PER_LONG == 64
|
|
#define BITMAP_FROM_U64(n) (n)
|
|
#else
|
|
#define BITMAP_FROM_U64(n) ((unsigned long) ((u64)(n) & ULONG_MAX)), \
|
|
((unsigned long) ((u64)(n) >> 32))
|
|
#endif
|
|
|
|
/*
|
|
* bitmap_from_u64 - Check and swap words within u64.
|
|
* @mask: source bitmap
|
|
* @dst: destination bitmap
|
|
*
|
|
* In 32-bit Big Endian kernel, when using (u32 *)(&val)[*]
|
|
* to read u64 mask, we will get the wrong word.
|
|
* That is "(u32 *)(&val)[0]" gets the upper 32 bits,
|
|
* but we expect the lower 32-bits of u64.
|
|
*/
|
|
static inline void bitmap_from_u64(unsigned long *dst, u64 mask)
|
|
{
|
|
dst[0] = mask & ULONG_MAX;
|
|
|
|
if (sizeof(mask) > sizeof(unsigned long))
|
|
dst[1] = mask >> 32;
|
|
}
|
|
|
|
#endif /* __ASSEMBLY__ */
|
|
|
|
#endif /* __LINUX_BITMAP_H */
|