RTEMS  5.1
rtems-fdt.h
Go to the documentation of this file.
1 /*
2  * COPYRIGHT (c) 2013-2017 Chris Johns <chrisj@rtems.org>
3  *
4  * The license and distribution terms for this file may be
5  * found in the file LICENSE in this distribution or at
6  * http://www.rtems.org/license/LICENSE.
7  *
8  * Interface based on the libdft:
9  * libfdt - Flat Device Tree manipulation
10  * Copyright (C) 2006 David Gibson, IBM Corporation.
11  */
22 #if !defined (_RTEMS_FDT_H_)
23 #define _RTEMS_FDT_H_
24 
25 #include <rtems.h>
26 #include <rtems/chain.h>
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif /* __cplusplus */
31 
35 struct rtems_fdt_blob;
36 typedef struct rtems_fdt_blob rtems_fdt_blob;
37 
43 typedef struct
44 {
47 
48 /*
49  * The following are mappings to the standard FDT calls.
50  */
51 
55 #define RTEMS_FDT_ERR_NOTFOUND 1
56 
59 #define RTEMS_FDT_ERR_EXISTS 2
60 
65 #define RTEMS_FDT_ERR_NOSPACE 3
66 
67 /* Error codes: codes for bad parameters */
73 #define RTEMS_FDT_ERR_BADOFFSET 4
74 
78 #define RTEMS_FDT_ERR_BADPATH 5
79 
83 #define RTEMS_FDT_ERR_BADPHANDLE 6
84 
89 #define RTEMS_FDT_ERR_BADSTATE 7
90 
91 /* Error codes: codes for bad device tree blobs */
92 
97 #define RTEMS_FDT_ERR_TRUNCATED 8
98 
102 #define RTEMS_FDT_ERR_BADMAGIC 9
103 
108 #define RTEMS_FDT_ERR_BADVERSION 10
109 
114 #define RTEMS_FDT_ERR_BADSTRUCTURE 11
115 
121 #define RTEMS_FDT_ERR_BADLAYOUT 12
122 
125 #define RTEMS_FDT_ERR_INTERNAL 13
126 
127 /* RTEMS error codes. */
128 
132 #define RTEMS_FDT_ERR_INVALID_HANDLE 100
133 
136 #define RTEMS_FDT_ERR_NO_MEMORY 101
137 
140 #define RTEMS_FDT_ERR_NOT_FOUND 102
141 
144 #define RTEMS_FDT_ERR_READ_FAIL 103
145 
148 #define RTEMS_FDT_ERR_REFERENCED 104
149 
150 #define RTEMS_FDT_ERR_RTEMS_MIN 100
151 #define RTEMS_FDT_ERR_MAX 104
152 
159 
167 
174 
182 bool rtems_fdt_valid_handle (const rtems_fdt_handle* handle);
183 
198 int rtems_fdt_find_path_offset (rtems_fdt_handle* handle, const char* path);
199 
208 int rtems_fdt_load (const char* const filename, rtems_fdt_handle* handle);
209 
217 int rtems_fdt_register (const void* blob, rtems_fdt_handle* handle);
218 
226 int rtems_fdt_unload (rtems_fdt_handle* handle);
227 
237 
250  int n,
251  uint64_t* address,
252  uint64_t* size);
253 
268  int parentoffset,
269  const char* const name,
270  int namelen);
271 
287  int parentoffset,
288  const char* const name);
289 
300 int rtems_fdt_path_offset (rtems_fdt_handle* handle, const char* path);
301 
314 const char* rtems_fdt_get_name (rtems_fdt_handle* handle,
315  int nodeoffset,
316  int* length);
317 
332 const void *rtems_fdt_getprop_namelen (rtems_fdt_handle* handle,
333  int nodeoffset,
334  const char* const name,
335  int namelen,
336  int* length);
337 
353 const void *rtems_fdt_getprop (rtems_fdt_handle* handle,
354  int nodeoffset,
355  const char* const name,
356  int* length);
357 
367 uint32_t rtems_fdt_get_phandle (rtems_fdt_handle* handle, int nodeoffset);
368 
378 const char *rtems_fdt_get_alias_namelen (rtems_fdt_handle* handle,
379  const char* const name,
380  int namelen);
381 
392 const char* rtems_fdt_get_alias (rtems_fdt_handle* handle, const char* name);
393 
408  int nodeoffset,
409  char* buf,
410  int buflen);
411 
429  int nodeoffset,
430  int supernodedepth,
431  int* nodedepth);
432 
444 int rtems_fdt_node_depth (rtems_fdt_handle* handle, int nodeoffset);
445 
458 int rtems_fdt_parent_offset (rtems_fdt_handle* handle, int nodeoffset);
459 
490  int startoffset,
491  const char* const propname,
492  const void* propval,
493  int proplen);
494 
505  uint32_t phandle);
506 
520  int nodeoffset,
521  const char* const compatible);
522 
548  int startoffset,
549  const char* compatible);
550 
559 int rtems_fdt_next_node (rtems_fdt_handle* handle, int offset, int* depth);
560 
567 const char* rtems_fdt_strerror (int errval);
568 
572 int rtems_fdt_prop_value(const char* const path,
573  const char* const propname,
574  void* value,
575  size_t* size);
576 
581 int rtems_fdt_prop_map (const char* const path,
582  const char* const propname,
583  const char* const names[],
584  uint32_t* values,
585  size_t count);
586 
587 /*
588  * Get a value given a path and a property.
589  */
590 int rtems_fdt_get_value (const char* const path,
591  const char* const property,
592  size_t size,
593  uint32_t* value);
594 
599 
604 const char *rtems_fdt_entry_name(rtems_fdt_handle* handle, int id);
605 
610 int rtems_fdt_entry_offset(rtems_fdt_handle* handle, int id);
611 
612 /*
613  * Helper function to convert the void* property result to a 32bit unsigned int.
614  */
615 uint32_t rtems_fdt_get_uint32 (const void* prop);
616 
617 #ifdef __cplusplus
618 }
619 #endif /* __cplusplus */
620 
621 #endif
const char * rtems_fdt_entry_name(rtems_fdt_handle *handle, int id)
Definition: rtems-fdt.c:1088
const void * blob
Definition: rtems-fdt.c:47
int rtems_fdt_prop_value(const char *const path, const char *const propname, void *value, size_t *size)
Definition: rtems-fdt.c:934
int rtems_fdt_load(const char *const filename, rtems_fdt_handle *handle)
Definition: rtems-fdt.c:453
int rtems_fdt_path_offset(rtems_fdt_handle *handle, const char *path)
Definition: rtems-fdt.c:745
Definition: rtems-fdt.c:44
int rtems_fdt_unload(rtems_fdt_handle *handle)
Definition: rtems-fdt.c:663
const void * rtems_fdt_getprop(rtems_fdt_handle *handle, int nodeoffset, const char *const name, int *length)
Definition: rtems-fdt.c:782
int rtems_fdt_register(const void *blob, rtems_fdt_handle *handle)
Definition: rtems-fdt.c:620
int rtems_fdt_find_path_offset(rtems_fdt_handle *handle, const char *path)
Definition: rtems-fdt.c:416
const char * rtems_fdt_get_alias_namelen(rtems_fdt_handle *handle, const char *const name, int namelen)
Definition: rtems-fdt.c:804
int rtems_fdt_subnode_offset_namelen(rtems_fdt_handle *handle, int parentoffset, const char *const name, int namelen)
Definition: rtems-fdt.c:714
int rtems_fdt_parent_offset(rtems_fdt_handle *handle, int nodeoffset)
Definition: rtems-fdt.c:855
uint32_t rtems_fdt_get_phandle(rtems_fdt_handle *handle, int nodeoffset)
Definition: rtems-fdt.c:796
int rtems_fdt_node_offset_by_compatible(rtems_fdt_handle *handle, int startoffset, const char *compatible)
Definition: rtems-fdt.c:897
int rtems_fdt_entry_offset(rtems_fdt_handle *handle, int id)
Definition: rtems-fdt.c:1098
const char * rtems_fdt_get_alias(rtems_fdt_handle *handle, const char *name)
Definition: rtems-fdt.c:814
const char * rtems_fdt_strerror(int errval)
Definition: rtems-fdt.c:917
int rtems_fdt_get_mem_rsv(rtems_fdt_handle *handle, int n, uint64_t *address, uint64_t *size)
Definition: rtems-fdt.c:703
bool rtems_fdt_valid_handle(const rtems_fdt_handle *handle)
Definition: rtems-fdt.c:387
int rtems_fdt_node_depth(rtems_fdt_handle *handle, int nodeoffset)
Definition: rtems-fdt.c:847
int rtems_fdt_num_entries(rtems_fdt_handle *handle)
Definition: rtems-fdt.c:1078
int rtems_fdt_prop_map(const char *const path, const char *const propname, const char *const names[], uint32_t *values, size_t count)
Definition: rtems-fdt.c:971
int rtems_fdt_get_path(rtems_fdt_handle *handle, int nodeoffset, char *buf, int buflen)
Definition: rtems-fdt.c:822
Chain API.
const char * rtems_fdt_get_name(rtems_fdt_handle *handle, int nodeoffset, int *length)
Definition: rtems-fdt.c:751
int rtems_fdt_node_check_compatible(rtems_fdt_handle *handle, int nodeoffset, const char *const compatible)
Definition: rtems-fdt.c:887
void rtems_fdt_dup_handle(rtems_fdt_handle *from, rtems_fdt_handle *to)
Definition: rtems-fdt.c:343
const void * rtems_fdt_getprop_namelen(rtems_fdt_handle *handle, int nodeoffset, const char *const name, int namelen, int *length)
Definition: rtems-fdt.c:766
void rtems_fdt_init_handle(rtems_fdt_handle *handle)
Definition: rtems-fdt.c:336
int rtems_fdt_node_offset_by_phandle(rtems_fdt_handle *handle, uint32_t phandle)
Definition: rtems-fdt.c:879
int rtems_fdt_node_offset_by_prop_value(rtems_fdt_handle *handle, int startoffset, const char *const propname, const void *propval, int proplen)
Definition: rtems-fdt.c:863
int rtems_fdt_next_node(rtems_fdt_handle *handle, int offset, int *depth)
Definition: rtems-fdt.c:909
void rtems_fdt_release_handle(rtems_fdt_handle *handle)
Definition: rtems-fdt.c:357
unsigned size
Definition: tte.h:74
int rtems_fdt_supernode_atdepth_offset(rtems_fdt_handle *handle, int nodeoffset, int supernodedepth, int *nodedepth)
Definition: rtems-fdt.c:833
int rtems_fdt_num_mem_rsv(rtems_fdt_handle *handle)
Definition: rtems-fdt.c:695
Definition: rtems-fdt.h:43
int rtems_fdt_subnode_offset(rtems_fdt_handle *handle, int parentoffset, const char *const name)
Definition: rtems-fdt.c:728
rtems_fdt_blob * blob
Definition: rtems-fdt.h:45