1 /* 2 * Copyright (c) 2014 Brian Swetland 3 * 4 * Use of this source code is governed by a MIT-style 5 * license that can be found in the LICENSE file or at 6 * https://opensource.org/licenses/MIT 7 */ 8 #pragma once 9 10 #include <sys/types.h> 11 12 typedef struct dt_slice { 13 u8 *data; 14 u32 size; 15 } dt_slice_t; 16 17 struct devicetree_header { 18 u32 magic; 19 u32 size; 20 u32 off_struct; // offset from start to DT 'structure' 21 u32 off_strings; // offset from start to stringdata 22 u32 off_reserve; // offset from start to reserve memory map 23 u32 version; 24 u32 version_compat; // last compatible version 25 u32 boot_cpuid; 26 u32 sz_strings; // size of stringdata 27 u32 sz_struct; // size of DT 'structure' 28 }; 29 30 typedef struct devicetree { 31 dt_slice_t top; 32 dt_slice_t dt; 33 dt_slice_t ds; 34 struct devicetree_header hdr; 35 void (*error)(const char *msg); 36 } devicetree_t; 37 38 typedef int (*dt_node_cb)(int depth, const char *name, void *cookie); 39 typedef int (*dt_prop_cb)(const char *name, u8 *data, u32 size, void *cookie); 40 41 int dt_init(devicetree_t *dt, void *data, u32 len); 42 int dt_walk(devicetree_t *dt, dt_node_cb ncb, dt_prop_cb pcb, void *cookie); 43 44 u32 dt_rd32(u8 *data); 45 void dt_wr32(u32 n, u8 *data); 46 47