summaryrefslogtreecommitdiffstats
path: root/common.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2022-07-14 18:28:04 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2022-07-16 15:12:07 +0000
commit589986012c4b3ab68e299a2eadca18f90080113b (patch)
treef29a53b04a1950cdddae69344bccb3f0146fa728 /common.h
parentReleasing debian version 1.16-4. (diff)
downloadnvme-cli-589986012c4b3ab68e299a2eadca18f90080113b.tar.xz
nvme-cli-589986012c4b3ab68e299a2eadca18f90080113b.zip
Merging upstream version 2.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'common.h')
-rw-r--r--common.h25
1 files changed, 21 insertions, 4 deletions
diff --git a/common.h b/common.h
index 1c214a4..d69eb1a 100644
--- a/common.h
+++ b/common.h
@@ -1,15 +1,32 @@
#ifndef _COMMON_H
#define _COMMON_H
-#define __round_mask(x, y) ((__typeof__(x))((y)-1))
-#define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
+#include <string.h>
+
+#include "ccan/endian/endian.h"
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
#define min(x, y) ((x) > (y) ? (y) : (x))
#define max(x, y) ((x) > (y) ? (x) : (y))
-#define __stringify_1(x...) #x
-#define __stringify(x...) __stringify_1(x)
+static inline uint32_t mmio_read32(void *addr)
+{
+ leint32_t *p = addr;
+
+ return le32_to_cpu(*p);
+}
+
+/* Access 64-bit registers as 2 32-bit; Some devices fail 64-bit MMIO. */
+static inline uint64_t mmio_read64(void *addr)
+{
+ const volatile uint32_t *p = addr;
+ uint32_t low, high;
+
+ low = le32_to_cpu(*p);
+ high = le32_to_cpu(*(p + 1));
+
+ return ((uint64_t) high << 32) | low;
+}
#endif