aboutsummaryrefslogtreecommitdiffstats
path: root/src/vppinfra/devicetree.h
blob: 21c2e0f7006c2d4d25455c6e887c24f5ee8b861f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* SPDX-License-Identifier: Apache-2.0
 * Copyright (c) 2024 Cisco Systems, Inc.
 */

#ifndef CLIB_DEVICETREE_H_
#define CLIB_DEVICETREE_H_

#include <vppinfra/clib.h>
#include <vlib/vlib.h>

#ifdef __linux
#define CLIB_DT_LINUX_PREFIX "/sys/firmware/devicetree/base"
#endif

typedef struct
{
  char name[32];
  u32 size;
  u8 data[];
} clib_dt_property_t;

typedef struct clib_dt_main clib_dt_main_t;

typedef struct clib_dt_node
{
  u8 *path;
  struct clib_dt_node *parent;
  struct clib_dt_node *prev;
  struct clib_dt_node *next;
  struct clib_dt_node **child_nodes;
  u8 depth;
  clib_dt_property_t *name;
  clib_dt_property_t **properties;
  clib_dt_main_t *dt_main;
} clib_dt_node_t;

typedef struct clib_dt_main
{
  clib_dt_node_t **nodes;
  clib_dt_node_t *root;
  uword *node_by_path;
  uword *node_by_phandle;
} clib_dt_main_t;

clib_dt_node_t *clib_dt_get_node_with_path (clib_dt_main_t *dm, char *fmt,
					    ...);
clib_dt_property_t *clib_dt_get_node_property_by_name (clib_dt_node_t *,
						       char *);
int clib_dt_node_is_compatible (clib_dt_node_t *, char *);
clib_dt_node_t *clib_dt_dereference_node (clib_dt_node_t *, char *);
#ifdef __linux
clib_error_t *clib_dt_read_from_sysfs (clib_dt_main_t *dm);
#endif

format_function_t format_clib_dt_desc;
format_function_t format_clib_dt_property_data;

static_always_inline int
clib_dt_proprerty_is_u32 (clib_dt_property_t *p)
{
  if (p == 0 || p->size != 4)
    return 0;
  return 1;
}

static_always_inline u32
clib_dt_proprerty_get_u32 (clib_dt_property_t *p)
{
  return clib_net_to_host_u32 (*(u32u *) p->data);
}

#endif /* CLIB_DEVICETREE_H_ */