summaryrefslogtreecommitdiffstats
path: root/bitops.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 18:30:56 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 18:30:56 +0000
commitd3114e0edc60508fc1e44e6cd2733fb2a97cdaca (patch)
tree82d66db664dea6ee75010455b98b04f47fcc4a90 /bitops.h
parentInitial commit. (diff)
downloadpciutils-d3114e0edc60508fc1e44e6cd2733fb2a97cdaca.tar.xz
pciutils-d3114e0edc60508fc1e44e6cd2733fb2a97cdaca.zip
Adding upstream version 1:3.11.1.upstream/1%3.11.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'bitops.h')
-rw-r--r--bitops.h39
1 files changed, 39 insertions, 0 deletions
diff --git a/bitops.h b/bitops.h
new file mode 100644
index 0000000..029741e
--- /dev/null
+++ b/bitops.h
@@ -0,0 +1,39 @@
+/*
+ * The PCI Utilities -- Decode bits and bit fields
+ *
+ * Copyright (c) 2023 Martin Mares <mj@ucw.cz>
+ * Copyright (c) 2023 KNS Group LLC (YADRO)
+ *
+ * Can be freely distributed and used under the terms of the GNU GPL v2+.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef _BITOPS_H
+#define _BITOPS_H
+
+#ifndef _PCI_LIB_H
+#error Import only from pci.h
+#endif
+
+/* Useful macros for decoding of bits and bit fields */
+
+#define FLAG(x, y) ((x & y) ? '+' : '-')
+
+// Generate mask
+
+#define BIT(at) ((u64)1 << (at))
+// Boundaries inclusive
+#define MASK(h, l) ((((u64)1 << ((h) + 1)) - 1) & ~(((u64)1 << (l)) - 1))
+
+// Get/set from register
+
+#define BITS(x, at, width) (((x) >> (at)) & ((1 << (width)) - 1))
+#define GET_REG_MASK(reg, mask) (((reg) & (mask)) / ((mask) & ~((mask) << 1)))
+#define SET_REG_MASK(reg, mask, val) \
+ (((reg) & ~(mask)) | (((val) * ((mask) & ~((mask) << 1))) & (mask)))
+
+#define TABLE(tab, x, buf) \
+ ((x) < sizeof(tab) / sizeof((tab)[0]) ? (tab)[x] : (sprintf((buf), "??%d", (x)), (buf)))
+
+#endif