SyterKit 0.4.0.x
SyterKit is a bare-metal framework
Loading...
Searching...
No Matches
libfdt_env.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) */
2#ifndef LIBFDT_ENV_H
3#define LIBFDT_ENV_H
4/*
5 * libfdt - Flat Device Tree manipulation
6 * Copyright (C) 2006 David Gibson, IBM Corporation.
7 * Copyright 2012 Kim Phillips, Freescale Semiconductor.
8 */
9
10#include <stdbool.h>
11#include <stddef.h>
12#include <stdint.h>
13#include <stdlib.h>
14#include <string.h>
15#include <limits.h>
16
17#ifdef __cplusplus
18extern "C" {
19#endif// __cplusplus
20
21#ifdef __CHECKER__
22#define FDT_FORCE __attribute__((force))
23#define FDT_BITWISE __attribute__((bitwise))
24#else
25#define FDT_FORCE
26#define FDT_BITWISE
27#endif
28
32
33#define EXTRACT_BYTE(x, n) ((unsigned long long) ((uint8_t *) &x)[n])
34#define CPU_TO_FDT16(x) ((EXTRACT_BYTE(x, 0) << 8) | EXTRACT_BYTE(x, 1))
35#define CPU_TO_FDT32(x) ((EXTRACT_BYTE(x, 0) << 24) | (EXTRACT_BYTE(x, 1) << 16) | (EXTRACT_BYTE(x, 2) << 8) | EXTRACT_BYTE(x, 3))
36#define CPU_TO_FDT64(x) \
37 ((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) | \
38 (EXTRACT_BYTE(x, 6) << 8) | EXTRACT_BYTE(x, 7))
39
40static inline uint16_t fdt16_to_cpu(fdt16_t x) {
42}
43static inline fdt16_t cpu_to_fdt16(uint16_t x) {
44 return (FDT_FORCE fdt16_t) CPU_TO_FDT16(x);
45}
46
47static inline uint32_t fdt32_to_cpu(fdt32_t x) {
49}
50static inline fdt32_t cpu_to_fdt32(uint32_t x) {
51 return (FDT_FORCE fdt32_t) CPU_TO_FDT32(x);
52}
53
54static inline uint64_t fdt64_to_cpu(fdt64_t x) {
56}
57static inline fdt64_t cpu_to_fdt64(uint64_t x) {
58 return (FDT_FORCE fdt64_t) CPU_TO_FDT64(x);
59}
60#undef CPU_TO_FDT64
61#undef CPU_TO_FDT32
62#undef CPU_TO_FDT16
63#undef EXTRACT_BYTE
64
65#ifdef __APPLE__
66#include <AvailabilityMacros.h>
67
68/* strnlen() is not available on Mac OS < 10.7 */
69#if !defined(MAC_OS_X_VERSION_10_7) || (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7)
70
71#define strnlen fdt_strnlen
72
73/*
74 * fdt_strnlen: returns the length of a string or max_count - which ever is
75 * smallest.
76 * Input 1 string: the string whose size is to be determined
77 * Input 2 max_count: the maximum value returned by this function
78 * Output: length of the string or max_count (the smallest of the two)
79 */
80static inline size_t fdt_strnlen(const char *string, size_t max_count) {
81 const char *p = memchr(string, 0, max_count);
82 return p ? p - string : max_count;
83}
84
85#endif /* !defined(MAC_OS_X_VERSION_10_7) || (MAC_OS_X_VERSION_MAX_ALLOWED <
86 MAC_OS_X_VERSION_10_7) */
87
88#endif /* __APPLE__ */
89
90#ifdef __cplusplus
91}
92#endif// __cplusplus
93
94#endif /* LIBFDT_ENV_H */
u64_t uint64_t
Definition stdint.h:16
u32_t uint32_t
Definition stdint.h:13
u16_t uint16_t
Definition stdint.h:10
void * memchr(void *ptr, int value, unsigned int num) __attribute__((optimize("O0")))
Locates the first occurrence of the character 'value' (converted to an unsigned char) in the first 'n...
Definition string.c:119
static fdt32_t cpu_to_fdt32(uint32_t x)
Definition libfdt_env.h:50
static fdt16_t cpu_to_fdt16(uint16_t x)
Definition libfdt_env.h:43
#define FDT_BITWISE
Definition libfdt_env.h:26
static fdt64_t cpu_to_fdt64(uint64_t x)
Definition libfdt_env.h:57
static uint64_t fdt64_to_cpu(fdt64_t x)
Definition libfdt_env.h:54
static uint16_t fdt16_to_cpu(fdt16_t x)
Definition libfdt_env.h:40
static uint32_t fdt32_to_cpu(fdt32_t x)
Definition libfdt_env.h:47
#define CPU_TO_FDT64(x)
Definition libfdt_env.h:36
uint32_t FDT_BITWISE fdt32_t
Definition libfdt_env.h:30
uint16_t FDT_BITWISE fdt16_t
Definition libfdt_env.h:29
#define FDT_FORCE
Definition libfdt_env.h:25
uint64_t FDT_BITWISE fdt64_t
Definition libfdt_env.h:31
#define CPU_TO_FDT32(x)
Definition libfdt_env.h:35
#define CPU_TO_FDT16(x)
Definition libfdt_env.h:34