RTEMS 6.1-rc5
Loading...
Searching...
No Matches
rtems-fdt.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/*
4 * COPYRIGHT (c) 2013-2017 Chris Johns <chrisj@rtems.org>
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
26 *
27 * Interface based on the libdft:
28 * libfdt - Flat Device Tree manipulation
29 * Copyright (C) 2006 David Gibson, IBM Corporation.
30 */
41#if !defined (_RTEMS_FDT_H_)
42#define _RTEMS_FDT_H_
43
44#include <rtems.h>
45#include <rtems/chain.h>
46
47#ifdef __cplusplus
48extern "C" {
49#endif /* __cplusplus */
50
54struct rtems_fdt_blob;
55typedef struct rtems_fdt_blob rtems_fdt_blob;
56
62typedef struct
63{
66
73typedef struct
74{
75 int node;
76 uint64_t address;
77 uint64_t size;
78 int address_cells;
79 int size_cells;
81
82/*
83 * The following are mappings to the standard FDT calls.
84 */
85
89#define RTEMS_FDT_ERR_NOTFOUND 1
93#define RTEMS_FDT_ERR_EXISTS 2
99#define RTEMS_FDT_ERR_NOSPACE 3
100
101/* Error codes: codes for bad parameters */
107#define RTEMS_FDT_ERR_BADOFFSET 4
112#define RTEMS_FDT_ERR_BADPATH 5
117#define RTEMS_FDT_ERR_BADPHANDLE 6
123#define RTEMS_FDT_ERR_BADSTATE 7
124
125/* Error codes: codes for bad device tree blobs */
126
131#define RTEMS_FDT_ERR_TRUNCATED 8
136#define RTEMS_FDT_ERR_BADMAGIC 9
142#define RTEMS_FDT_ERR_BADVERSION 10
148#define RTEMS_FDT_ERR_BADSTRUCTURE 11
155#define RTEMS_FDT_ERR_BADLAYOUT 12
159#define RTEMS_FDT_ERR_INTERNAL 13
160
161/* RTEMS error codes. */
162
166#define RTEMS_FDT_ERR_INVALID_HANDLE 100
170#define RTEMS_FDT_ERR_NO_MEMORY 101
174#define RTEMS_FDT_ERR_NOT_FOUND 102
178#define RTEMS_FDT_ERR_READ_FAIL 103
182#define RTEMS_FDT_ERR_REFERENCED 104
186#define RTEMS_FDT_ERR_BADLENGTH 105
187
188#define RTEMS_FDT_ERR_RTEMS_MIN 100
189#define RTEMS_FDT_ERR_MAX 105
190
197
205
212
220bool rtems_fdt_valid_handle (const rtems_fdt_handle* handle);
221
236int rtems_fdt_find_path_offset (rtems_fdt_handle* handle, const char* path);
237
246int rtems_fdt_load (const char* const filename, rtems_fdt_handle* handle);
247
255int rtems_fdt_register (const void* blob, rtems_fdt_handle* handle);
256
265
275
288 int n,
289 uint64_t* address,
290 uint64_t* size);
291
306 int parentoffset,
307 const char* const name,
308 int namelen);
309
325 int parentoffset,
326 const char* const name);
327
338int rtems_fdt_path_offset (rtems_fdt_handle* handle, const char* path);
339
354const char* rtems_fdt_get_name (rtems_fdt_handle* handle,
355 int nodeoffset,
356 int* length);
357
365int rtems_fdt_first_prop_offset(rtems_fdt_handle* handle, int nodeoffset);
366
374int rtems_fdt_next_prop_offset(rtems_fdt_handle* handle, int propoffset);
375
389 int propoffset,
390 const char** name,
391 int* length);
392
409 int nodeoffset,
410 const char* const name,
411 int namelen,
412 int* length);
413
430const void *rtems_fdt_getprop (rtems_fdt_handle* handle,
431 int nodeoffset,
432 const char* const name,
433 int* length);
434
444uint32_t rtems_fdt_get_phandle (rtems_fdt_handle* handle, int nodeoffset);
445
456 const char* const name,
457 int namelen);
458
469const char* rtems_fdt_get_alias (rtems_fdt_handle* handle, const char* name);
470
485 int nodeoffset,
486 char* buf,
487 int buflen);
488
506 int nodeoffset,
507 int supernodedepth,
508 int* nodedepth);
509
521int rtems_fdt_node_depth (rtems_fdt_handle* handle, int nodeoffset);
522
535int rtems_fdt_parent_offset (rtems_fdt_handle* handle, int nodeoffset);
536
567 int startoffset,
568 const char* const propname,
569 const void* propval,
570 int proplen);
571
582 uint32_t phandle);
583
597 int nodeoffset,
598 const char* const compatible);
599
625 int startoffset,
626 const char* compatible);
627
636int rtems_fdt_next_node (rtems_fdt_handle* handle, int offset, int* depth);
637
644const char* rtems_fdt_strerror (int errval);
645
651 int nodeoffset,
652 const char* name,
653 uint32_t* value);
657int rtems_fdt_prop_value(const char* const path,
658 const char* const propname,
659 void* value,
660 size_t* size);
661
666int rtems_fdt_prop_map (const char* const path,
667 const char* const propname,
668 const char* const names[],
669 uintptr_t* values,
670 size_t count);
671
672/*
673 * Get a value given a path and a property.
674 */
675int rtems_fdt_get_value (const char* const path,
676 const char* const property,
677 size_t size,
678 uintptr_t* value);
679
684
689const char *rtems_fdt_entry_name(rtems_fdt_handle* handle, int id);
690
695int rtems_fdt_entry_offset(rtems_fdt_handle* handle, int id);
696
697/*
698 * Helper function to convert the void* property result of unknown
699 * length to an unsigned int pointer value.
700 */
701uintptr_t rtems_fdt_get_offset_len_uintptr(const void* prop, int offset, int len);
702
703/*
704 * Helper function to convert the void* property result to a 32bit unsigned int.
705 */
706uint32_t rtems_fdt_get_uint32(const void* prop);
707uint32_t rtems_fdt_get_offset_uint32(const void* prop, int offset);
708
709/*
710 * Helper function to convert the void* property result to a 64bit unsigned int.
711 */
712uint64_t rtems_fdt_get_uint64(const void* prop);
713uint64_t rtems_fdt_get_offset_uint64(const void* prop, int offset);
714
715/*
716 * Helper function to convert the void* property result to a uintptr_t
717 */
718uintptr_t rtems_fdt_get_uintptr(const void* prop);
719uintptr_t rtems_fdt_get_offset_uintptr(const void* prop, int offset);
720
721/*
722 * Find the address cells property in parent nodes.
723 */
724int rtems_fdt_getprop_address_cells(rtems_fdt_handle* handle, int nodeoffset);
725
726/*
727 * Find the size cells property in parent nodes.
728 */
729int rtems_fdt_getprop_size_cells(rtems_fdt_handle* handle, int nodeoffset);
730
731/*
732 * Get an address space property.
733 */
734int rtems_fdt_getprop_address_map(rtems_fdt_handle* handle,
735 const char* path,
736 const char* name,
737 rtems_fdt_address_map* addr_map);
738
739#ifdef __cplusplus
740}
741#endif /* __cplusplus */
742
743#endif
This header file provides the Chains API.
int rtems_fdt_node_offset_by_phandle(rtems_fdt_handle *handle, uint32_t phandle)
Definition: rtems-fdt.c:953
int rtems_fdt_supernode_atdepth_offset(rtems_fdt_handle *handle, int nodeoffset, int supernodedepth, int *nodedepth)
Definition: rtems-fdt.c:907
int rtems_fdt_next_node(rtems_fdt_handle *handle, int offset, int *depth)
Definition: rtems-fdt.c:983
int rtems_fdt_next_prop_offset(rtems_fdt_handle *handle, int propoffset)
Definition: rtems-fdt.c:825
const void * rtems_fdt_getprop_by_offset(rtems_fdt_handle *handle, int propoffset, const char **name, int *length)
Definition: rtems-fdt.c:831
void rtems_fdt_init_handle(rtems_fdt_handle *handle)
Definition: rtems-fdt.c:386
uint32_t rtems_fdt_get_phandle(rtems_fdt_handle *handle, int nodeoffset)
Definition: rtems-fdt.c:870
const char * rtems_fdt_get_alias(rtems_fdt_handle *handle, const char *name)
Definition: rtems-fdt.c:888
int rtems_fdt_num_entries(rtems_fdt_handle *handle)
Definition: rtems-fdt.c:1215
const char * rtems_fdt_strerror(int errval)
Definition: rtems-fdt.c:991
int rtems_fdt_subnode_offset_namelen(rtems_fdt_handle *handle, int parentoffset, const char *const name, int namelen)
Definition: rtems-fdt.c:767
int rtems_fdt_prop_map(const char *const path, const char *const propname, const char *const names[], uintptr_t *values, size_t count)
Definition: rtems-fdt.c:1064
const char * rtems_fdt_get_name(rtems_fdt_handle *handle, int nodeoffset, int *length)
Definition: rtems-fdt.c:804
int rtems_fdt_path_offset(rtems_fdt_handle *handle, const char *path)
Definition: rtems-fdt.c:798
int rtems_fdt_entry_offset(rtems_fdt_handle *handle, int id)
Definition: rtems-fdt.c:1235
bool rtems_fdt_get_parent_prop_value(rtems_fdt_handle *handle, int nodeoffset, const char *name, uint32_t *value)
Definition: rtems-fdt.c:1046
int rtems_fdt_node_check_compatible(rtems_fdt_handle *handle, int nodeoffset, const char *const compatible)
Definition: rtems-fdt.c:961
void rtems_fdt_dup_handle(rtems_fdt_handle *from, rtems_fdt_handle *to)
Definition: rtems-fdt.c:393
const char * rtems_fdt_get_alias_namelen(rtems_fdt_handle *handle, const char *const name, int namelen)
Definition: rtems-fdt.c:878
int rtems_fdt_first_prop_offset(rtems_fdt_handle *handle, int nodeoffset)
Definition: rtems-fdt.c:819
int rtems_fdt_find_path_offset(rtems_fdt_handle *handle, const char *path)
Definition: rtems-fdt.c:466
int rtems_fdt_subnode_offset(rtems_fdt_handle *handle, int parentoffset, const char *const name)
Definition: rtems-fdt.c:781
int rtems_fdt_parent_offset(rtems_fdt_handle *handle, int nodeoffset)
Definition: rtems-fdt.c:929
int rtems_fdt_node_depth(rtems_fdt_handle *handle, int nodeoffset)
Definition: rtems-fdt.c:921
bool rtems_fdt_valid_handle(const rtems_fdt_handle *handle)
Definition: rtems-fdt.c:437
const void * rtems_fdt_getprop_namelen(rtems_fdt_handle *handle, int nodeoffset, const char *const name, int namelen, int *length)
Definition: rtems-fdt.c:840
int rtems_fdt_prop_value(const char *const path, const char *const propname, void *value, size_t *size)
Definition: rtems-fdt.c:1009
int rtems_fdt_node_offset_by_compatible(rtems_fdt_handle *handle, int startoffset, const char *compatible)
Definition: rtems-fdt.c:971
const void * rtems_fdt_getprop(rtems_fdt_handle *handle, int nodeoffset, const char *const name, int *length)
Definition: rtems-fdt.c:856
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:937
int rtems_fdt_register(const void *blob, rtems_fdt_handle *handle)
Definition: rtems-fdt.c:671
int rtems_fdt_load(const char *const filename, rtems_fdt_handle *handle)
Definition: rtems-fdt.c:503
const char * rtems_fdt_entry_name(rtems_fdt_handle *handle, int id)
Definition: rtems-fdt.c:1225
void rtems_fdt_release_handle(rtems_fdt_handle *handle)
Definition: rtems-fdt.c:407
int rtems_fdt_get_mem_rsv(rtems_fdt_handle *handle, int n, uint64_t *address, uint64_t *size)
Definition: rtems-fdt.c:756
int rtems_fdt_unload(rtems_fdt_handle *handle)
Definition: rtems-fdt.c:716
int rtems_fdt_get_path(rtems_fdt_handle *handle, int nodeoffset, char *buf, int buflen)
Definition: rtems-fdt.c:896
int rtems_fdt_num_mem_rsv(rtems_fdt_handle *handle)
Definition: rtems-fdt.c:748
This header file defines the RTEMS Classic API.
Definition: rtems-fdt.h:74
Definition: rtems-fdt.c:63
rtems_chain_node node
Definition: rtems-fdt.c:64
const void * blob
Definition: rtems-fdt.c:65
const char * name
Definition: rtems-fdt.c:66
Definition: rtems-fdt.h:63
rtems_fdt_blob * blob
Definition: rtems-fdt.h:64