cfi_endian.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Copyright © 2001-2010 David Woodhouse <[email protected]>
  4. */
  5. #include <asm/byteorder.h>
  6. #define CFI_HOST_ENDIAN 1
  7. #define CFI_LITTLE_ENDIAN 2
  8. #define CFI_BIG_ENDIAN 3
  9. #if !defined(CONFIG_MTD_CFI_ADV_OPTIONS) || defined(CONFIG_MTD_CFI_NOSWAP)
  10. #define CFI_DEFAULT_ENDIAN CFI_HOST_ENDIAN
  11. #elif defined(CONFIG_MTD_CFI_LE_BYTE_SWAP)
  12. #define CFI_DEFAULT_ENDIAN CFI_LITTLE_ENDIAN
  13. #elif defined(CONFIG_MTD_CFI_BE_BYTE_SWAP)
  14. #define CFI_DEFAULT_ENDIAN CFI_BIG_ENDIAN
  15. #else
  16. #error No CFI endianness defined
  17. #endif
  18. #define cfi_default(s) ((s)?:CFI_DEFAULT_ENDIAN)
  19. #define cfi_be(s) (cfi_default(s) == CFI_BIG_ENDIAN)
  20. #define cfi_le(s) (cfi_default(s) == CFI_LITTLE_ENDIAN)
  21. #define cfi_host(s) (cfi_default(s) == CFI_HOST_ENDIAN)
  22. #define cpu_to_cfi8(map, x) (x)
  23. #define cfi8_to_cpu(map, x) (x)
  24. #define cpu_to_cfi16(map, x) _cpu_to_cfi(16, (map)->swap, (x))
  25. #define cpu_to_cfi32(map, x) _cpu_to_cfi(32, (map)->swap, (x))
  26. #define cpu_to_cfi64(map, x) _cpu_to_cfi(64, (map)->swap, (x))
  27. #define cfi16_to_cpu(map, x) _cfi_to_cpu(16, (map)->swap, (x))
  28. #define cfi32_to_cpu(map, x) _cfi_to_cpu(32, (map)->swap, (x))
  29. #define cfi64_to_cpu(map, x) _cfi_to_cpu(64, (map)->swap, (x))
  30. #define _cpu_to_cfi(w, s, x) (cfi_host(s)?(x):_swap_to_cfi(w, s, x))
  31. #define _cfi_to_cpu(w, s, x) (cfi_host(s)?(x):_swap_to_cpu(w, s, x))
  32. #define _swap_to_cfi(w, s, x) (cfi_be(s)?cpu_to_be##w(x):cpu_to_le##w(x))
  33. #define _swap_to_cpu(w, s, x) (cfi_be(s)?be##w##_to_cpu(x):le##w##_to_cpu(x))