MOS Source Code
Loading...
Searching...
No Matches
libfdt++.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-3.0-or-later
2
3#pragma once
4
5#include <mos/types.h>
6#include <utility>
7
8extern unsigned int dt_root_addr_cells;
9extern unsigned int dt_root_size_cells;
10
11class dt_node;
12class dt_root;
13class dt_property;
14class dt_reg;
15
17{
18 public:
19 explicit dt_property(const dt_node &node, const char *name);
20 explicit dt_property(const dt_node &node, int poffset);
21
22 public:
23 u32 get_u32() const;
24 u64 get_u64() const;
25 const char *get_string() const;
26
27 // clang-format off
28 int len() const { return m_len; }
29 void *get_data() const { return (void *) m_propdata; }
30 const char *get_name() const { return m_name; }
31 operator bool() const { return m_propdata != nullptr; }
32 // clang-format on
33
34 private:
36 const char *m_name;
37 const void *m_propdata;
38 int m_len;
39
40 friend dt_reg;
41};
42
47class dt_reg
48{
50 {
51 public:
52 explicit iterator(const dt_reg &reg, char *data) : reg(reg), data(data){};
53 std::pair<ptr_t, size_t> operator*() const;
55
56 // clang-format off
57 bool operator!=(const iterator &other) const { return data != other.data; }
58 // clang-format on
59
60 private:
61 const dt_reg &reg;
62 const char *data;
63 };
64
65 public:
67 bool verify_validity() const;
68
69 // clang-format off
70 iterator begin() const { return iterator(*this, (char *) prop.m_propdata); }
71 iterator end() const { return iterator(*this, (char *) prop.m_propdata + prop.m_len); }
72 // clang-format on
73
74 private:
76};
77
79{
81 {
82 public:
83 explicit iterator(const dt_node &node, int offset) : node(node), iter_offset(offset){};
84
85 public:
87
88 // clang-format off
90 bool operator!=(const iterator &other) const { return iter_offset != other.iter_offset; }
91 // clang-format on
92
93 private:
94 const dt_node &node;
96 };
97
99 {
101 {
102 public:
103 explicit iterator(const dt_node &node, int offset) : node(node), poffset(offset){};
104
105 public:
107
108 // clang-format off
110 bool operator!=(const iterator &other) const { return poffset != other.poffset; }
111 // clang-format on
112
113 private:
114 const dt_node &node;
116 };
117
118 public:
119 explicit node_property_list(const dt_node &node) : node(node){};
120
121 iterator begin() const;
122 iterator end() const;
123
124 private:
125 const dt_node &node;
126 };
127
128 public:
129 explicit dt_node(const dt_root &root, unsigned long offset) : m_root(root), m_offset(offset){};
130 explicit dt_node(const dt_root &root, const char *path);
131
132 public:
133 const char *get_name() const;
134
135 // clang-format off
136 long offset() const { return m_offset; }
137 // clang-format on
138
139 iterator begin() const;
140 iterator end() const;
141
142 bool has_property(const char *name) const;
143
144 // clang-format off
145 const dt_root &root() const { return m_root; }
147 dt_property get_property(const char *name) const { return dt_property(*this, name); }
148 dt_property operator[](const char *name) const { return dt_property(*this, name); }
149 // clang-format on
150
151 private:
153 unsigned long m_offset; // node offset of current node
154};
155
157{
158 public:
159 explicit dt_root(void *fdt) : _fdt(fdt), _root_node(*this, "/"){};
160
161 public:
162 // clang-format off
163 void *fdt() const { return _fdt; }
165 const dt_node &rootnode() const { return _root_node; }
166 dt_node get_node(const char *path) const { return dt_node(*this, path); }
167 // clang-format on
168
169 private:
170 void *_fdt;
172};
bool operator!=(const iterator &other) const
Definition libfdt++.hpp:90
const dt_node & node
Definition libfdt++.hpp:94
iterator & operator++()
Definition libfdt++.cpp:60
iterator(const dt_node &node, int offset)
Definition libfdt++.hpp:83
dt_node operator*() const
Definition libfdt++.hpp:89
bool operator!=(const iterator &other) const
Definition libfdt++.hpp:110
iterator(const dt_node &node, int offset)
Definition libfdt++.hpp:103
node_property_list(const dt_node &node)
Definition libfdt++.hpp:119
iterator begin() const
Definition libfdt++.cpp:76
dt_node(const dt_root &root, unsigned long offset)
Definition libfdt++.hpp:129
const dt_root & root() const
Definition libfdt++.hpp:145
iterator end() const
Definition libfdt++.cpp:71
const char * get_name() const
Definition libfdt++.cpp:55
const dt_root & m_root
Definition libfdt++.hpp:152
long offset() const
Definition libfdt++.hpp:136
dt_property get_property(const char *name) const
Definition libfdt++.hpp:147
dt_property operator[](const char *name) const
Definition libfdt++.hpp:148
unsigned long m_offset
Definition libfdt++.hpp:153
iterator begin() const
Definition libfdt++.cpp:66
node_property_list properties() const
Definition libfdt++.hpp:146
bool has_property(const char *name) const
Definition libfdt++.cpp:92
u64 get_u64() const
Definition libfdt++.cpp:112
void * get_data() const
Definition libfdt++.hpp:29
dt_property(const dt_node &node, const char *name)
Definition libfdt++.cpp:97
const char * get_string() const
Definition libfdt++.cpp:117
int len() const
Definition libfdt++.hpp:28
const char * get_name() const
Definition libfdt++.hpp:30
const void * m_propdata
Definition libfdt++.hpp:37
const char * m_name
Definition libfdt++.hpp:36
u32 get_u32() const
Definition libfdt++.cpp:107
const dt_node & m_node
Definition libfdt++.hpp:35
friend dt_reg
Definition libfdt++.hpp:40
iterator(const dt_reg &reg, char *data)
Definition libfdt++.hpp:52
bool operator!=(const iterator &other) const
Definition libfdt++.hpp:57
std::pair< ptr_t, size_t > operator*() const
Definition libfdt++.cpp:36
iterator & operator++()
Definition libfdt++.cpp:44
const char * data
Definition libfdt++.hpp:62
const dt_reg & reg
Definition libfdt++.hpp:61
Class to iterate over reg property cells.
Definition libfdt++.hpp:48
iterator begin() const
Definition libfdt++.hpp:70
iterator end() const
Definition libfdt++.hpp:71
dt_reg(const dt_property &prop)
Definition libfdt++.hpp:66
const dt_property & prop
Definition libfdt++.hpp:75
bool verify_validity() const
Definition libfdt++.cpp:25
dt_node _root_node
Definition libfdt++.hpp:171
dt_node get_node(const char *path) const
Definition libfdt++.hpp:166
dt_root(void *fdt)
Definition libfdt++.hpp:159
void * _fdt
Definition libfdt++.hpp:170
dt_node & rootnode()
Definition libfdt++.hpp:164
const dt_node & rootnode() const
Definition libfdt++.hpp:165
void * fdt() const
Definition libfdt++.hpp:163
unsigned int dt_root_addr_cells
Definition libfdt++.cpp:7
unsigned int dt_root_size_cells
Definition libfdt++.cpp:8
int bool
Definition pb_syshdr.h:57
const char * name
Definition slab.c:31
unsigned int u32
Definition types.h:21
unsigned long long u64
Definition types.h:23