arm_adi_v5: describe Class 0x9 Device Architecture register
[openocd.git] / src / helper / bits.h
1 /*
2 * Copyright (C) 2018, STMicroelectronics - All Rights Reserved
3 * Author(s): Antonio Borneo <borneo.antonio@gmail.com> for STMicroelectronics
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 /*
20 * The content of this file is mainly copied/inspired from Linux kernel
21 * code in include/linux/types.h include/linux/bitmap.h include/linux/bitops.h
22 */
23
24 #ifndef OPENOCD_HELPER_BITS_H
25 #define OPENOCD_HELPER_BITS_H
26
27 #include <helper/replacements.h>
28 #include <helper/types.h>
29
30 #define BIT(nr) (1UL << (nr))
31 #define BIT_ULL(nr) (1ULL << (nr))
32 #define BITS_PER_BYTE 8
33 #define BITS_PER_LONG (BITS_PER_BYTE * sizeof(long))
34 #define BITS_PER_LONG_LONG (BITS_PER_BYTE * sizeof(long long))
35 #define GENMASK(h, l) (((~0UL) - (1UL << (l)) + 1) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
36 #define GENMASK_ULL(h, l) (((~0ULL) - (1ULL << (l)) + 1) & (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h))))
37 #define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
38 #define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
39 #define BIT_WORD(nr) ((nr) / BITS_PER_LONG)
40 #define DECLARE_BITMAP(name, bits) unsigned long name[BITS_TO_LONGS(bits)]
41
42 /**
43 * bitmap_zero - Clears all the bits in memory
44 * @param dst the address of the bitmap
45 * @param nbits the number of bits to clear
46 */
47 static inline void bitmap_zero(unsigned long *dst, unsigned int nbits)
48 {
49 unsigned int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long);
50 memset(dst, 0, len);
51 }
52
53 /**
54 * clear_bit - Clear a bit in memory
55 * @param nr the bit to set
56 * @param addr the address to start counting from
57 */
58 static inline void clear_bit(unsigned int nr, volatile unsigned long *addr)
59 {
60 unsigned long mask = BIT_MASK(nr);
61 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
62
63 *p &= ~mask;
64 }
65
66 /**
67 * set_bit - Set a bit in memory
68 * @param nr the bit to set
69 * @param addr the address to start counting from
70 */
71 static inline void set_bit(unsigned int nr, volatile unsigned long *addr)
72 {
73 unsigned long mask = BIT_MASK(nr);
74 unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
75
76 *p |= mask;
77 }
78
79 /**
80 * test_bit - Determine whether a bit is set
81 * @param nr bit number to test
82 * @param addr Address to start counting from
83 */
84 static inline int test_bit(unsigned int nr, const volatile unsigned long *addr)
85 {
86 return 1UL & (addr[BIT_WORD(nr)] >> (nr % BITS_PER_LONG));
87 }
88
89 #endif /* OPENOCD_HELPER_BITS_H */

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)