summaryrefslogtreecommitdiff
path: root/board/cr50/tpm2/endian.h
diff options
context:
space:
mode:
Diffstat (limited to 'board/cr50/tpm2/endian.h')
-rw-r--r--board/cr50/tpm2/endian.h48
1 files changed, 48 insertions, 0 deletions
diff --git a/board/cr50/tpm2/endian.h b/board/cr50/tpm2/endian.h
new file mode 100644
index 0000000000..893a794c16
--- /dev/null
+++ b/board/cr50/tpm2/endian.h
@@ -0,0 +1,48 @@
+/* Copyright 2015 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef __EC_BOARD_CR50_TPM2_ENDIAN_H
+#define __EC_BOARD_CR50_TPM2_ENDIAN_H
+
+#include <stddef.h>
+#include <stdint.h>
+
+static inline void swap_n(void *in, void *out, size_t size)
+{
+ int i;
+
+ for (i = 0; i < size; i++)
+ ((uint8_t *)out)[size - i - 1] = ((uint8_t *)in)[i];
+}
+
+static inline uint16_t be16toh(uint16_t in)
+{
+ uint16_t out;
+
+ swap_n(&in, &out, sizeof(out));
+ return out;
+}
+
+static inline uint32_t be32toh(uint32_t in)
+{
+ uint32_t out;
+
+ swap_n(&in, &out, sizeof(out));
+ return out;
+}
+
+static inline uint64_t be64toh(uint64_t in)
+{
+ uint64_t out;
+
+ swap_n(&in, &out, sizeof(out));
+ return out;
+}
+
+#define htobe16 be16toh
+#define htobe32 be32toh
+#define htobe64 be64toh
+
+#endif /* __EC_BOARD_CR50_TPM2_ENDIAN_H */