mirror of
https://github.com/dgibson/dtc.git
synced 2025-10-14 00:37:41 -04:00
Projects such as linux and u-boot run sparse on libfdt. libfdt contains the notion of endianness via usage of endian conversion functions such as fdt32_to_cpu. As such, in order to pass endian checks, libfdt has to annotate its fdt variables such that sparse can warn when mixing bitwise and regular integers. This patch adds these new fdtXX_t types and, ifdef __CHECKER__ (a symbol sparse defines), includes the bitwise annotation. Signed-off-by: Kim Phillips <kim.phillips@freescale.com> Acked-by: David Gibson <david@gibson.dropbear.id.au>
60 lines
1.5 KiB
C
60 lines
1.5 KiB
C
#ifndef _LIBFDT_ENV_H
|
|
#define _LIBFDT_ENV_H
|
|
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
#include <string.h>
|
|
|
|
#ifdef __CHECKER__
|
|
#define __force __attribute__((force))
|
|
#define __bitwise __attribute__((bitwise))
|
|
#else
|
|
#define __force
|
|
#define __bitwise
|
|
#endif
|
|
|
|
typedef uint16_t __bitwise fdt16_t;
|
|
typedef uint32_t __bitwise fdt32_t;
|
|
typedef uint64_t __bitwise fdt64_t;
|
|
|
|
#define EXTRACT_BYTE(x, n) ((unsigned long long)((uint8_t *)&x)[n])
|
|
#define CPU_TO_FDT16(x) ((EXTRACT_BYTE(x, 0) << 8) | EXTRACT_BYTE(x, 1))
|
|
#define CPU_TO_FDT32(x) ((EXTRACT_BYTE(x, 0) << 24) | (EXTRACT_BYTE(x, 1) << 16) | \
|
|
(EXTRACT_BYTE(x, 2) << 8) | EXTRACT_BYTE(x, 3))
|
|
#define CPU_TO_FDT64(x) ((EXTRACT_BYTE(x, 0) << 56) | (EXTRACT_BYTE(x, 1) << 48) | \
|
|
(EXTRACT_BYTE(x, 2) << 40) | (EXTRACT_BYTE(x, 3) << 32) | \
|
|
(EXTRACT_BYTE(x, 4) << 24) | (EXTRACT_BYTE(x, 5) << 16) | \
|
|
(EXTRACT_BYTE(x, 6) << 8) | EXTRACT_BYTE(x, 7))
|
|
|
|
static inline uint16_t fdt16_to_cpu(fdt16_t x)
|
|
{
|
|
return (__force uint16_t)CPU_TO_FDT16(x);
|
|
}
|
|
static inline fdt16_t cpu_to_fdt16(uint16_t x)
|
|
{
|
|
return (__force fdt16_t)CPU_TO_FDT16(x);
|
|
}
|
|
|
|
static inline uint32_t fdt32_to_cpu(fdt32_t x)
|
|
{
|
|
return (__force uint32_t)CPU_TO_FDT32(x);
|
|
}
|
|
static inline fdt32_t cpu_to_fdt32(uint32_t x)
|
|
{
|
|
return (__force fdt32_t)CPU_TO_FDT32(x);
|
|
}
|
|
|
|
static inline uint64_t fdt64_to_cpu(fdt64_t x)
|
|
{
|
|
return (__force uint64_t)CPU_TO_FDT64(x);
|
|
}
|
|
static inline fdt64_t cpu_to_fdt64(uint64_t x)
|
|
{
|
|
return (__force fdt64_t)CPU_TO_FDT64(x);
|
|
}
|
|
#undef CPU_TO_FDT64
|
|
#undef CPU_TO_FDT32
|
|
#undef CPU_TO_FDT16
|
|
#undef EXTRACT_BYTE
|
|
|
|
#endif /* _LIBFDT_ENV_H */
|