• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: MIT or GPL-2.0-only
2 #ifndef UBLK_TGT_ENDIAN_H
3 #define UBLK_TGT_ENDIAN_H
4 
5 #include <byteswap.h>
6 
7 /* ublksrv target code private header, not for libublksrv user */
8 
9 #define HOST_CONVERT(endian, size, type)\
10 static inline type endian ## size ## _to_cpu(type v)\
11 {\
12 	return endian ## size ## toh(v); \
13 }\
14 \
15 static inline type cpu_to_ ## endian ## size(type v)\
16 {\
17 	return hto ## endian ## size(v); \
18 }\
19 
20 HOST_CONVERT(be, 16, uint16_t)
21 HOST_CONVERT(be, 32, uint32_t)
22 HOST_CONVERT(be, 64, uint64_t)
23 
24 HOST_CONVERT(le, 16, uint16_t)
25 HOST_CONVERT(le, 32, uint32_t)
26 HOST_CONVERT(le, 64, uint64_t)
27 
28 #endif
29