diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 19:41:32 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 19:41:32 +0000 |
commit | f26f66d866ba1a9f3204e6fdfe2b07e67b5492ad (patch) | |
tree | c953c007cbe4f60a147ab62f97937d58abb2e9ca /common.h | |
parent | Initial commit. (diff) | |
download | nvme-cli-upstream/2.8.tar.xz nvme-cli-upstream/2.8.zip |
Adding upstream version 2.8.upstream/2.8
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | common.h | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/common.h b/common.h new file mode 100644 index 0000000..b5594e9 --- /dev/null +++ b/common.h @@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#ifndef _COMMON_H +#define _COMMON_H + +#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)) + +#ifdef __packed +#else /* __packed */ +#define __packed __attribute__((__packed__)) +#endif /* __packed */ + +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 |