Jianjun Wang has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/59738 )
Change subject: helpers: Add fls support ......................................................................
helpers: Add fls support
Introduce the C-language equivalent function of fls: find last (most-significant) bit set.
Since x86 has its specific function, only used in non-x86 platform, and remove the duplicate definitions in commonlib/storage/sdhci.c.
This code is copied from Linux kernel in: include/asm-generic/bitops/fls.h
Signed-off-by: Jianjun Wang jianjun.wang@mediatek.com Change-Id: Ib458abfec7e03b2979569a8440a6e69b0285ac32 --- M src/commonlib/bsd/include/commonlib/bsd/helpers.h M src/commonlib/storage/sdhci.c 2 files changed, 38 insertions(+), 30 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/38/59738/1
diff --git a/src/commonlib/bsd/include/commonlib/bsd/helpers.h b/src/commonlib/bsd/include/commonlib/bsd/helpers.h index 733b05a..80a1790 100644 --- a/src/commonlib/bsd/include/commonlib/bsd/helpers.h +++ b/src/commonlib/bsd/include/commonlib/bsd/helpers.h @@ -126,4 +126,42 @@ #define retry(attempts, condition, ...) \ _retry_impl(attempts, condition, __VA_ARGS__)
+#ifndef ARCH_X86 +/** + * fls - find last (most-significant) bit set + * @x: the word to search + * + * This is defined the same way as ffs. + * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32. + */ +static __always_inline int fls(unsigned int x) +{ + int r = 32; + + if (!x) + return 0; + if (!(x & 0xffff0000u)) { + x <<= 16; + r -= 16; + } + if (!(x & 0xff000000u)) { + x <<= 8; + r -= 8; + } + if (!(x & 0xf0000000u)) { + x <<= 4; + r -= 4; + } + if (!(x & 0xc0000000u)) { + x <<= 2; + r -= 2; + } + if (!(x & 0x80000000u)) { + x <<= 1; + r -= 1; + } + return r; +} +#endif + #endif /* COMMONLIB_BSD_HELPERS_H */ diff --git a/src/commonlib/storage/sdhci.c b/src/commonlib/storage/sdhci.c index 6d39a45..0dcc66e 100644 --- a/src/commonlib/storage/sdhci.c +++ b/src/commonlib/storage/sdhci.c @@ -411,36 +411,6 @@ return 0; }
-/* Find leftmost set bit in a 32 bit integer */ -static int fls(u32 x) -{ - int r = 32; - - if (!x) - return 0; - if (!(x & 0xffff0000u)) { - x <<= 16; - r -= 16; - } - if (!(x & 0xff000000u)) { - x <<= 8; - r -= 8; - } - if (!(x & 0xf0000000u)) { - x <<= 4; - r -= 4; - } - if (!(x & 0xc0000000u)) { - x <<= 2; - r -= 2; - } - if (!(x & 0x80000000u)) { - x <<= 1; - r -= 1; - } - return r; -} - static void sdhci_set_power(struct sdhci_ctrlr *sdhci_ctrlr, unsigned short power) {