Ultibo API
C/C++ API for Ultibo Core
Loading...
Searching...
No Matches
devicetree.h
Go to the documentation of this file.
1/*
2 * This file is part of the Ultibo project, https://ultibo.org/
3 *
4 * The MIT License (MIT)
5 *
6 * Copyright (c) 2026 Garry Wood <garry@softoz.com.au>
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 * THE SOFTWARE.
25 */
26#ifndef _ULTIBO_DEVICETREE_H
27#define _ULTIBO_DEVICETREE_H
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33#include "ultibo/globaltypes.h"
34#include "ultibo/globalconst.h"
35#include "ultibo/platform.h"
36
39#define DTB_MAGIC 0xD00DFEED
40
42#define DTB_VERSION_17 17
43#define DTB_VERSION_16 16
44
45#define DTB_VERSION_CURRENT DTB_VERSION_17
46#define DTB_VERSION_COMPATIBLE DTB_VERSION_16
47
49#define DTB_BEGIN_NODE 0x00000001
50#define DTB_END_NODE 0x00000002
51#define DTB_PROP 0x00000003
52#define DTB_NOP 0x00000004
53#define DTB_END 0x00000009
54
56#define DTB_NODE_OFFSET 4
57#define DTB_PROPERTY_OFFSET 12
58
60#define DTB_STRUCTURE_ALIGNMENT 4
61#define DTB_RESERVATION_ALIGNMENT 8
62
65#define DTB_NODE_ROOT "/"
66#define DTB_NODE_CPUS "cpus"
67#define DTB_NODE_MEMORY "memory"
68#define DTB_NODE_CHOSEN "chosen"
69#define DTB_NODE_ALIASES "aliases"
71#define DTB_NODE_SYMBOLS "__symbols__"
72#define DTB_NODE_OVERRIDES "__overrides__"
73
75#define DTB_PATH_SEPARATOR "/"
76
78#define DTB_TYPE_UNKNOWN 0
79#define DTB_TYPE_EMPTY 1
80#define DTB_TYPE_U32 2
81#define DTB_TYPE_U64 3
82#define DTB_TYPE_STRING 4
83#define DTB_TYPE_ENCODED_ARRAY 5
84#define DTB_TYPE_PHANDLE 6
85#define DTB_TYPE_STRINGLIST 7
86
89#define DTB_PROPERTY_COMPATIBLE "compatible"
90#define DTB_PROPERTY_MODEL "model"
91#define DTB_PROPERTY_PHANDLE "phandle"
92#define DTB_PROPERTY_STATUS "status"
93#define DTB_PROPERTY_ADDRESS_CELLS "#address-cells"
94#define DTB_PROPERTY_SIZE_CELLS "#size-cells"
95#define DTB_PROPERTY_REG "reg"
96#define DTB_PROPERTY_VIRTUAL_REG "virtual-reg"
97#define DTB_PROPERTY_RANGES "ranges"
98#define DTB_PROPERTY_DMA_RANGES "dma-ranges"
99#define DTB_PROPERTY_NAME "name"
100#define DTB_PROPERTY_DEVICE_TYPE "device_type"
101
103#define DTB_PROPERTY_INTERRUPTS "interrupts"
104#define DTB_PROPERTY_INTERRUPT_PARENT "interrupt-parent"
105#define DTB_PROPERTY_INTERRUPTS_EXTENDED "interrupts-extended"
106
108#define DTB_PROPERTY_INTERRUPT_CELLS "#interrupt-cells"
109#define DTB_PROPERTY_INTERRUPT_CONTROLLER "interrupt-controller"
110
112#define DTB_PROPERTY_INTERRUPT_MAP "interrupt-map"
113#define DTB_PROPERTY_INTERRUPT_MAP_MASK "interrupt-map-mask"
114
116#define DTB_PROPERTY_INITIAL_MAPPED_AREA "initial-mapped-area"
117
119#define DTB_PROPERTY_BOOTARGS "bootargs"
120#define DTB_PROPERTY_STDOUT_PATH "stdout-path"
121#define DTB_PROPERTY_STDIN_PATH "stdin-path"
122#define DTB_PROPERTY_INITRD_START "initrd-start"
123#define DTB_PROPERTY_INITRD_END "initrd-end"
124
126#define DTB_PROPERTY_CLOCK_FREQUENCY "clock-frequency"
127#define DTB_PROPERTY_TIMEBASE_FREQUENCY "timebase-frequency"
128#define DTB_PROPERTY_ENABLE_METHOD "enable-method"
129#define DTB_PROPERTY_CPU_RELEASE_ADDR "cpu-release-addr"
130
131#define DTB_PROPERTY_POWER_ISA_VERSION "power-isa-version"
132#define DTB_PROPERTY_CACHE_OP_BLOCK_SIZE "cache-op-block-size"
133#define DTB_PROPERTY_RESERVATION_GRANULE_SIZE "reservation-granule-size"
134#define DTB_PROPERTY_MMU_TYPE "mmu-type"
135
136#define DTB_PROPERTY_TLB_SPLIT "tlb-split"
137#define DTB_PROPERTY_TLB_SIZE "tlb-size"
138#define DTB_PROPERTY_TLB_SETS "tlb-sets"
139#define DTB_PROPERTY_D_TLB_SIZE "d-tlb-size"
140#define DTB_PROPERTY_D_TLB_SETS "d-tlb-sets"
141#define DTB_PROPERTY_I_TLB_SIZE "i-tlb-size"
142#define DTB_PROPERTY_I_TLB_SETS "i-tlb-sets"
143
144#define DTB_PROPERTY_CACHE_UNIFIED "cache-unified"
145#define DTB_PROPERTY_CACHE_SIZE "cache-size"
146#define DTB_PROPERTY_CACHE_SETS "cache-sets"
147#define DTB_PROPERTY_CACHE_BLOCK_SIZE "cache-block-size"
148#define DTB_PROPERTY_CACHE_LINE_SIZE "cache-line-size"
149#define DTB_PROPERTY_I_CACHE_SIZE "i-cache-size"
150#define DTB_PROPERTY_I_CACHE_SETS "i-cache-sets"
151#define DTB_PROPERTY_I_CACHE_BLOCK_SIZE "i-cache-block-size"
152#define DTB_PROPERTY_I_CACHE_LINE_SIZE "i-cache-line-size"
153#define DTB_PROPERTY_D_CACHE_SIZE "d-cache-size"
154#define DTB_PROPERTY_D_CACHE_SETS "d-cache-sets"
155#define DTB_PROPERTY_D_CACHE_BLOCK_SIZE "d-cache-block-size"
156#define DTB_PROPERTY_D_CACHE_LINE_SIZE "d-cache-line-size"
157#define DTB_PROPERTY_NEXT_LEVEL_CACHE "next-level-cache"
158
159#define DTB_PROPERTY_CACHE_LEVEL "cache-level"
160
162#define DTB_PROPERTY_SERIAL_NUMBER "serial-number"
163#define DTB_PROPERTY_ALLOC_RANGES "alloc-ranges"
164#define DTB_PROPERTY_RESETS "resets"
165#define DTB_PROPERTY_CLOCK_CELLS "#clock-cells"
166#define DTB_PROPERTY_LINUX_INITRD_START "linux,initrd-start"
167#define DTB_PROPERTY_LINUX_INITRD_END "linux,initrd-end"
168
170#define DTB_MAX_PROPERTY_TYPE 60
171
174typedef struct _DTB_HEADER DTB_HEADER;
176{
177 uint32_t magic;
178 uint32_t totalsize;
180 uint32_t stringsoffset;
182 uint32_t version;
184 uint32_t bootcpuid;
185 uint32_t stringssize;
186 uint32_t structuresize;
188
192{
193 uint64_t address;
194 uint64_t size;
195} PACKED;
196
198typedef struct _DTB_NODE DTB_NODE;
200{
201 uint32_t token;
202 char name[1];
203} PACKED;
204
208{
209 uint32_t token;
210 uint32_t valuelength;
211 uint32_t nameoffset;
212 uint8_t value[1];
213} PACKED;
214
215
219{
220 uint32_t token;
221 uint32_t valuelength;
222 uint32_t nameoffset;
223 char value[1];
224} PACKED;
225
226
230{
231 uint32_t token;
232 uint32_t valuelength;
233 uint32_t nameoffset;
234 uint32_t value[1];
235} PACKED;
236
237
241{
242 uint32_t token;
243 uint32_t valuelength;
244 uint32_t nameoffset;
245 uint64_t value[1];
246} PACKED;
247
249typedef void STDCALL (*dtb_log_output_cb)(const char *text, void *data);
250typedef char * STDCALL (*dtb_decode_value_cb)(HANDLE node, HANDLE handle, void *value, uint32_t size, void *data);
251
253
261BOOL STDCALL device_tree_validate(size_t address, uint32_t *size);
262
270
278
285HANDLE STDCALL device_tree_get_node(const char *path, HANDLE parent);
286
294
300uint32_t STDCALL device_tree_get_node_name(HANDLE handle, char *name, uint32_t len);
301
308uint32_t STDCALL device_tree_split_node_name(HANDLE handle, char *nodename, uint32_t namelen, char *unitaddress, uint32_t addresslen);
309
316
328BOOL STDCALL device_tree_get_node_reg_cells(HANDLE handle, uint32_t *address, uint32_t *size);
329
342BOOL STDCALL device_tree_get_node_range_cells(HANDLE handle, uint32_t *parentaddress, uint32_t *nodeaddress, uint32_t *nodesize);
343
349uint32_t STDCALL device_tree_get_property_name(HANDLE handle, char *name, uint32_t len);
350
357uint32_t STDCALL device_tree_split_property_name(HANDLE handle, char *uniqueprefix, uint32_t prefixlen, char *propertyname, uint32_t namelen);
358
366
373
379uint32_t STDCALL device_tree_get_property_string(HANDLE handle, char *string, uint32_t len);
380
387
394
396
403
412BOOL STDCALL device_tree_get_ramdisk(size_t *address, uint64_t *size);
413
424#if defined (__i386__) || defined (__arm__)
425BOOL STDCALL device_tree_get_memory(uint32_t index, uint32_t *range, size_t *address, uint64_t *size);
426#else
427BOOL STDCALL device_tree_get_memory(uint32_t index, size_t *address, uint64_t *size);
428#endif
429
437BOOL STDCALL device_tree_get_reservation(uint32_t index, size_t *address, uint64_t *size);
438
444
454
455#ifdef __cplusplus
456}
457#endif
458
459#endif // _ULTIBO_DEVICETREE_H
uint32_t STDCALL device_tree_get_property_name(HANDLE handle, char *name, uint32_t len)
Get the name of the specified property.
struct _DTB_PROPERTY_LONGWORD DTB_PROPERTY_LONGWORD
Definition devicetree.h:228
uint32_t STDCALL device_tree_log_tree(void)
Print information about all nodes and properties in the device tree.
uint32_t STDCALL device_tree_get_property_length(HANDLE handle)
Get the length of the raw value of the specified property.
BOOL STDCALL device_tree_get_memory(uint32_t index, size_t *address, uint64_t *size)
Return the address and size of a memory block specified in the device tree blob.
uint32_t STDCALL device_tree_get_property_longword(HANDLE handle)
Get the value of the specified property as a longword.
uint32_t STDCALL device_tree_get_property_string(HANDLE handle, char *string, uint32_t len)
Get the value of the specified property as a string.
HANDLE STDCALL device_tree_next_node(HANDLE parent, HANDLE previous)
Find the next DTB node within the Device Tree.
void *STDCALL device_tree_get_property_value(HANDLE handle)
Get a pointer to the raw value of the specified property.
BOOL STDCALL device_tree_get_ramdisk(size_t *address, uint64_t *size)
Return the address and size of the initial ram disk specified in the device tree blob.
BOOL STDCALL device_tree_get_node_range_cells(HANDLE handle, uint32_t *parentaddress, uint32_t *nodeaddress, uint32_t *nodesize)
Get the address-cells and size-cells values that apply to range properties of the specified node.
HANDLE STDCALL device_tree_get_property(HANDLE node, const char *name)
Get the handle of the property matching the specified name.
HANDLE STDCALL device_tree_get_node(const char *path, HANDLE parent)
Get the handle of the node matching the specified path, optionally within a specified parent.
HANDLE STDCALL device_tree_next_property(HANDLE node, HANDLE previous)
Find the next DTB property within the specified node of the Device Tree.
uint32_t STDCALL device_tree_split_node_name(HANDLE handle, char *nodename, uint32_t namelen, char *unitaddress, uint32_t addresslen)
Split the name of a node into node name and unit address.
struct _DTB_NODE DTB_NODE
Definition devicetree.h:198
struct _DTB_PROPERTY DTB_PROPERTY
Definition devicetree.h:206
HANDLE STDCALL device_tree_get_node_parent(HANDLE handle)
Get the parent node of the specified node.
char *STDCALL(* dtb_decode_value_cb)(HANDLE node, HANDLE handle, void *value, uint32_t size, void *data)
Definition devicetree.h:250
struct _DTB_PROPERTY_CHAR DTB_PROPERTY_CHAR
Definition devicetree.h:217
void STDCALL(* dtb_log_output_cb)(const char *text, void *data)
Definition devicetree.h:249
BOOL STDCALL device_tree_get_node_reg_cells(HANDLE handle, uint32_t *address, uint32_t *size)
Get the address-cells and size-cells values that apply to reg properties of the specified node.
struct _DTB_PROPERTY_QUADWORD DTB_PROPERTY_QUADWORD
Definition devicetree.h:239
struct _DTB_RESERVATION DTB_RESERVATION
Definition devicetree.h:190
struct _DTB_HEADER DTB_HEADER
Definition devicetree.h:174
uint32_t STDCALL device_tree_split_property_name(HANDLE handle, char *uniqueprefix, uint32_t prefixlen, char *propertyname, uint32_t namelen)
Split the name of a property into property name and unique prefix.
uint32_t STDCALL device_tree_get_node_name(HANDLE handle, char *name, uint32_t len)
Get the name of the specified node.
BOOL STDCALL device_tree_get_reservation(uint32_t index, size_t *address, uint64_t *size)
Return the address and size of a memory reservation specified in the device tree blob.
BOOL STDCALL device_tree_validate(size_t address, uint32_t *size)
Check the data at the supplied address to determine if it is a valid Device Tree Blob.
char *STDCALL device_tree_get_boot_args(void)
Return a character pointer to the location of the command line in the device tree blob.
uint32_t STDCALL device_tree_log_tree_ex(HANDLE node, dtb_log_output_cb output, dtb_decode_value_cb decode, void *data)
Print information about one or all nodes and properties in the device tree with custom value decode c...
uint64_t STDCALL device_tree_get_property_quadword(HANDLE handle)
Get the value of the specified property as a quadword.
size_t HANDLE
Definition globaltypes.h:51
#define STDCALL
Definition globaltypes.h:45
#define PACKED
Definition globaltypes.h:48
_Bool BOOL
Built in Boolean type (1 byte) (Redeclared here for flexibility).
Definition globaltypes.h:55
Definition devicetree.h:176
uint32_t stringsoffset
The offset in bytes of the strings block from the beginning of the header (big-endian).
Definition devicetree.h:180
uint32_t reservationoffset
The offset in bytes of the memory reservation block from the beginning of the header (big-endian).
Definition devicetree.h:181
uint32_t magic
The value 0xd00dfeed (big-endian).
Definition devicetree.h:177
uint32_t stringssize
The length in bytes of the strings block section of the devicetree blob (big-endian).
Definition devicetree.h:185
uint32_t totalsize
The total size in bytes of the devicetree data structure (big-endian).
Definition devicetree.h:178
uint32_t structuresize
The length in bytes of the structure block section of the devicetree blob (big-endian).
Definition devicetree.h:186
uint32_t compatibleversion
The lowest version of the devicetree data structure with which the version used is backwards compatib...
Definition devicetree.h:183
uint32_t structureoffset
The offset in bytes of the structure block from the beginning of the header (big-endian).
Definition devicetree.h:179
uint32_t bootcpuid
The physical ID of the system’s boot CPU (big-endian).
Definition devicetree.h:184
uint32_t version
The version of the devicetree data structure (big-endian).
Definition devicetree.h:182
Definition devicetree.h:200
char name[1]
The name stored as a null-terminated string, shall include the unit address if any.
Definition devicetree.h:202
uint32_t token
Token (big-endian).
Definition devicetree.h:201
Definition devicetree.h:219
uint32_t nameoffset
The offset into the strings block of the property name stored as a null-terminated string.
Definition devicetree.h:222
uint32_t valuelength
The length of the property value in bytes.
Definition devicetree.h:221
char value[1]
The property value as a string of value length.
Definition devicetree.h:223
uint32_t token
Token (big-endian).
Definition devicetree.h:220
Definition devicetree.h:230
uint32_t nameoffset
The offset into the strings block of the property name stored as a null-terminated string.
Definition devicetree.h:233
uint32_t valuelength
The length of the property value in bytes.
Definition devicetree.h:232
uint32_t value[1]
The property value as an array of longwords of value length (big-endian).
Definition devicetree.h:234
uint32_t token
Token (big-endian).
Definition devicetree.h:231
Definition devicetree.h:241
uint64_t value[1]
The property value as an array of quadwords of value length (big-endian).
Definition devicetree.h:245
uint32_t nameoffset
The offset into the strings block of the property name stored as a null-terminated string.
Definition devicetree.h:244
uint32_t valuelength
The length of the property value in bytes.
Definition devicetree.h:243
uint32_t token
Token (big-endian).
Definition devicetree.h:242
Definition devicetree.h:208
uint8_t value[1]
The property value as an array of bytes of value length.
Definition devicetree.h:212
uint32_t nameoffset
The offset into the strings block of the property name stored as a null-terminated string.
Definition devicetree.h:211
uint32_t valuelength
The length of the property value in bytes.
Definition devicetree.h:210
uint32_t token
Token (big-endian).
Definition devicetree.h:209
Definition devicetree.h:192
uint64_t address
Physical address of a reserved memory region.
Definition devicetree.h:193
uint64_t size
Size in bytes of a reserved memory region.
Definition devicetree.h:194