mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-15 15:04:27 +08:00
12869ecd5e
Pull in SPDX tag conversion from upstream dtc. This will replace the conversion done in the kernel tree copy in v5.2-rc2. This adds the following commits from upstream: 702c1b6c0e73 README.license: Update to reflect SPDX tag usage 4097bbffcf1d dtc: Add GPLv2 SPDX tags to files missing license text 94f87cd5b7c5 libfdt: Add dual GPL/BSD SPDX tags to files missing license text c4ffc05574b1 tests: Replace license boilerplate with SPDX tags a5ac29baacd2 pylibfdt: Replace dual GPLv2/BSD license boilerplate with SPDX tags 7fb0f4db2eb7 libfdt: Replace GPL/BSD boilerplate/reference with SPDX tags acfe84f2c47e dtc: Replace GPLv2 boilerplate/reference with SPDX tags Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Rob Herring <robh@kernel.org>
97 lines
2.7 KiB
C
97 lines
2.7 KiB
C
/* SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) */
|
|
#ifndef LIBFDT_ENV_H
|
|
#define LIBFDT_ENV_H
|
|
/*
|
|
* libfdt - Flat Device Tree manipulation
|
|
* Copyright (C) 2006 David Gibson, IBM Corporation.
|
|
* Copyright 2012 Kim Phillips, Freescale Semiconductor.
|
|
*/
|
|
|
|
#include <stdbool.h>
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <limits.h>
|
|
|
|
#ifdef __CHECKER__
|
|
#define FDT_FORCE __attribute__((force))
|
|
#define FDT_BITWISE __attribute__((bitwise))
|
|
#else
|
|
#define FDT_FORCE
|
|
#define FDT_BITWISE
|
|
#endif
|
|
|
|
typedef uint16_t FDT_BITWISE fdt16_t;
|
|
typedef uint32_t FDT_BITWISE fdt32_t;
|
|
typedef uint64_t FDT_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 (FDT_FORCE uint16_t)CPU_TO_FDT16(x);
|
|
}
|
|
static inline fdt16_t cpu_to_fdt16(uint16_t x)
|
|
{
|
|
return (FDT_FORCE fdt16_t)CPU_TO_FDT16(x);
|
|
}
|
|
|
|
static inline uint32_t fdt32_to_cpu(fdt32_t x)
|
|
{
|
|
return (FDT_FORCE uint32_t)CPU_TO_FDT32(x);
|
|
}
|
|
static inline fdt32_t cpu_to_fdt32(uint32_t x)
|
|
{
|
|
return (FDT_FORCE fdt32_t)CPU_TO_FDT32(x);
|
|
}
|
|
|
|
static inline uint64_t fdt64_to_cpu(fdt64_t x)
|
|
{
|
|
return (FDT_FORCE uint64_t)CPU_TO_FDT64(x);
|
|
}
|
|
static inline fdt64_t cpu_to_fdt64(uint64_t x)
|
|
{
|
|
return (FDT_FORCE fdt64_t)CPU_TO_FDT64(x);
|
|
}
|
|
#undef CPU_TO_FDT64
|
|
#undef CPU_TO_FDT32
|
|
#undef CPU_TO_FDT16
|
|
#undef EXTRACT_BYTE
|
|
|
|
#ifdef __APPLE__
|
|
#include <AvailabilityMacros.h>
|
|
|
|
/* strnlen() is not available on Mac OS < 10.7 */
|
|
# if !defined(MAC_OS_X_VERSION_10_7) || (MAC_OS_X_VERSION_MAX_ALLOWED < \
|
|
MAC_OS_X_VERSION_10_7)
|
|
|
|
#define strnlen fdt_strnlen
|
|
|
|
/*
|
|
* fdt_strnlen: returns the length of a string or max_count - which ever is
|
|
* smallest.
|
|
* Input 1 string: the string whose size is to be determined
|
|
* Input 2 max_count: the maximum value returned by this function
|
|
* Output: length of the string or max_count (the smallest of the two)
|
|
*/
|
|
static inline size_t fdt_strnlen(const char *string, size_t max_count)
|
|
{
|
|
const char *p = memchr(string, 0, max_count);
|
|
return p ? p - string : max_count;
|
|
}
|
|
|
|
#endif /* !defined(MAC_OS_X_VERSION_10_7) || (MAC_OS_X_VERSION_MAX_ALLOWED <
|
|
MAC_OS_X_VERSION_10_7) */
|
|
|
|
#endif /* __APPLE__ */
|
|
|
|
#endif /* LIBFDT_ENV_H */
|