summaryrefslogtreecommitdiffstats
path: root/common.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-05 11:08:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-05 11:09:05 +0000
commit81e5ef4ae340ae4041f8029e7c14a3bc8baab46d (patch)
tree3b0b740dd83d6a1244e81e4270497ad8db31a9b7 /common.h
parentReleasing debian version 2.8-2. (diff)
downloadnvme-cli-81e5ef4ae340ae4041f8029e7c14a3bc8baab46d.tar.xz
nvme-cli-81e5ef4ae340ae4041f8029e7c14a3bc8baab46d.zip
Merging upstream version 2.9.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--common.h23
1 files changed, 22 insertions, 1 deletions
diff --git a/common.h b/common.h
index b5594e9..a4f4f99 100644
--- a/common.h
+++ b/common.h
@@ -3,6 +3,7 @@
#define _COMMON_H
#include <string.h>
+#include <stdbool.h>
#include "ccan/endian/endian.h"
@@ -32,7 +33,27 @@ static inline uint64_t mmio_read64(void *addr)
low = le32_to_cpu(*p);
high = le32_to_cpu(*(p + 1));
- return ((uint64_t) high << 32) | low;
+ return ((uint64_t)high << 32) | low;
}
+static inline void mmio_write32(void *addr, uint32_t value)
+{
+ leint32_t *p = addr;
+
+ *p = cpu_to_le32(value);
+}
+
+/* Access 64-bit registers as 2 32-bit if write32 flag set; Some devices fail 64-bit MMIO. */
+static inline void mmio_write64(void *addr, uint64_t value, bool write32)
+{
+ uint64_t *p = addr;
+
+ if (write32) {
+ mmio_write32(addr, value);
+ mmio_write32((uint32_t *)addr + 1, value >> 32);
+ return;
+ }
+
+ *p = cpu_to_le64(value);
+}
#endif