b9ced927d5637b4863202303ca046d66b3d76eb4
1 /*
2 * file rm_dtb_utilloc.h
3 *
4 * Private Resource List and Policy DTB Parsing Utilities
5 *
6 * ============================================================================
7 * (C) Copyright 2012, Texas Instruments, Inc.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the
19 * distribution.
20 *
21 * Neither the name of Texas Instruments Incorporated nor the names of
22 * its contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 *
37 * \par
38 */
40 #ifndef RM_DTB_UTILLOC_H_
41 #define RM_DTB_UTILLOC_H_
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
47 /**********************************************************************
48 *************Common RM DTB Parsing Defines and Functions**************
49 **********************************************************************/
51 /**
52 * @brief LIBFDT's return codes start at 1. Map a return value of 0 to an okay result
53 * from the LIBFDT APIs
54 */
55 #define RM_DTB_UTIL_RESULT_OKAY 0
56 /**
57 * @brief DTB starting node offset for parsing
58 */
59 #define RM_DTB_UTIL_STARTING_NODE_OFFSET 0
60 /**
61 * @brief DTB starting depth for parsing
62 */
63 #define RM_DTB_UTIL_STARTING_DEPTH 0
65 typedef struct {
66 uint32_t base;
67 uint32_t length;
68 void *nextRange;
69 } Rm_ResourceRange;
71 /**********************************************************************
72 ***********Resource List DTB Parsing Defines and Functions************
73 **********************************************************************/
75 /**
76 * @brief Linux DTB alias offset not set
77 */
78 #define RM_DTB_LINUX_ALIAS_OFFSET_NOT_SET 0xFFFF
80 typedef enum {
81 /** Resource DTB unknown property type */
82 Rm_resourcePropType_UNKNOWN = 0,
83 /** Resource DTB device name property type */
84 Rm_resourcePropType_DEVICE_NAME = 1,
85 /** Resource DTB resource range property type */
86 Rm_resourcePropType_RESOURCE_RANGE = 2,
87 /** Resource DTB resource alias path in Linux DTB */
88 Rm_resourcePropType_RESOURCE_LINUX_ALIAS = 3,
89 /** Resource DTB NameServer assignment property type */
90 Rm_resourcePropType_NSASSIGNMENT = 4,
91 } Rm_ResourcePropType;
93 typedef struct {
94 const char *pathList;
95 uint32_t pathListLenBytes;
96 uint32_t baseOffset;
97 uint32_t lengthOffset;
98 void *nextLinuxAlias;
99 } Rm_LinuxAlias;
101 typedef struct {
102 char *nsName;
103 uint32_t resourceBase;
104 uint32_t resourceLength;
105 void *nextNsAssignment;
106 } Rm_NsAssignment;
108 Rm_ResourcePropType Rm_resourceGetPropertyType(const char *propertyName);
109 char *Rm_resourceExtractDeviceName(const void *dtbDataPtr, int32_t dtbDataLen);
110 void Rm_resourceFreeDeviceName(char *deviceName);
111 Rm_ResourceRange *Rm_resourceExtractRange(const void *dtbDataPtr, int32_t dtbDataLen);
112 void Rm_resourceFreeRange(Rm_ResourceRange *rangeList);
113 Rm_LinuxAlias *Rm_resourceExtractLinuxAlias(const void *dtbDataPtr, int32_t dtbDataLen);
114 void Rm_resourceFreeLinuxAlias(Rm_LinuxAlias *aliasList);
115 Rm_NsAssignment *Rm_resourceExtractNsAssignment(const void *dtbDataPtr, int32_t dtbDataLen);
116 void Rm_resourceFreeNsAssignmentList(Rm_NsAssignment *nsAssignmentList);
118 /**********************************************************************
119 ***************Policy DTB Parsing Defines and Functions***************
120 **********************************************************************/
122 typedef enum {
123 /** Policy DTB unknown property type */
124 Rm_policyPropType_UNKNOWN = 0,
125 /** Policy DTB policy type property type */
126 Rm_policyPropType_POLICY_TYPE = 1,
127 /** Policy DTB resource assigned ranges property type */
128 Rm_policyPropType_RESOURCE_ASSIGNED_RANGES = 2,
129 /** Policy DTB resource allocation sizes property type */
130 Rm_policyPropType_RESOURCE_ALLOCATION_SIZES = 3,
131 /** Policy DTB assigned NameServer names property type */
132 Rm_policyPropType_ASSIGNED_NS_NAMES = 4,
133 } Rm_PolicyPropType;
135 typedef struct {
136 uint32_t allocationSize;
137 void *nextAllocationSize;
138 } Rm_AllocationSize;
140 typedef struct {
141 char *assignedName;
142 void *nextAssignedName;
143 } Rm_AssignedNsNames;
145 Rm_PolicyPropType Rm_policyGetPropertyType(const char *propertyName);
146 char *Rm_policyExtractPolicyType(const void *dtbDataPtr, int32_t dtbDataLen);
147 void Rm_policyFreePolicyType(char *policyType);
148 Rm_ResourceRange *Rm_policyExtractAssignedRanges(const void *dtbDataPtr, int32_t dtbDataLen);
149 void Rm_policyFreeAssignedRanges(Rm_ResourceRange *rangeList);
150 Rm_AllocationSize *Rm_policyExtractAllocationSizes(const void *dtbDataPtr, int32_t dtbDataLen);
151 void Rm_policyFreeAllocationSizesPropList(Rm_AllocationSize *allocationSizeList);
152 Rm_AssignedNsNames *Rm_policyExtractAssignedNsNames(const void *dtbDataPtr, int32_t dtbDataLen);
153 void Rm_policyFreeAssignmentNsNamesList(Rm_AssignedNsNames *assignedNsNamesList);
155 /**********************************************************************
156 ****************Linux DTB Parsing Defines and Functions***************
157 **********************************************************************/
159 typedef struct {
160 uint32_t value;
161 void *nextValue;
162 } Rm_LinuxValueRange;
164 Rm_LinuxValueRange *Rm_linuxExtractValues(const void *dtbDataPtr, int32_t dtbDataLen);
165 void Rm_linuxFreeValues(Rm_LinuxValueRange *valueList);
167 #ifdef __cplusplus
168 }
169 #endif
171 #endif /* RM_DTB_UTILLOC_H_ */