1 /*
2 * file rm_dtb_utilloc.h
3 *
4 * Private Resource List and Policy DTB Parsing Utilities
5 *
6 * ============================================================================
7 * (C) Copyright 2012-2013, 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 /* RM external includes */
48 #include <ti/drv/rm/rm.h>
50 /* DTB starting node offset for parsing */
51 #define RM_DTB_UTIL_STARTING_NODE_OFFSET 0
52 /* DTB starting depth for parsing */
53 #define RM_DTB_UTIL_STARTING_DEPTH 0
54 /* Linux DTB alias offset not set */
55 #define RM_DTB_UTIL_LINUX_ALIAS_OFFSET_NOT_SET 0xFFFF
57 /**********************************************************************
58 ******************* Common DTB Parsing Definitions *******************
59 **********************************************************************/
61 /* Resource range linked list node */
62 typedef struct Rm_ResourceRange_s {
63 /* Resource base */
64 uint32_t base;
65 /* Resource length */
66 uint32_t length;
67 /* Link to next resource range linked list node */
68 struct Rm_ResourceRange_s *nextRange;
69 } Rm_ResourceRange;
71 /* Resource value linked list node */
72 typedef struct Rm_ResourceValue_s {
73 /* Numerical resource value */
74 uint32_t value;
75 /* Link to next resource value linked list node */
76 struct Rm_ResourceValue_s *nextValue;
77 } Rm_ResourceValue;
79 /**********************************************************************
80 ************* Global Resource List Parsing Definitions ***************
81 **********************************************************************/
83 /* GRL resource node property types */
84 typedef enum {
85 /** Resource DTB unknown property type */
86 Rm_resourcePropType_UNKNOWN = 0,
87 /** Resource DTB resource range property type */
88 Rm_resourcePropType_RESOURCE_RANGE,
89 /** Resource DTB resource alias path in Linux DTB */
90 Rm_resourcePropType_RESOURCE_LINUX_ALIAS,
91 /** Resource DTB NameServer assignment property type */
92 Rm_resourcePropType_NSASSIGNMENT
93 } Rm_ResourcePropType;
95 /* Linux alias path linked list node */
96 typedef struct Rm_LinuxAlias_s {
97 /* Pointer to the alias path string */
98 char *path;
99 /* Base value offset into Linux value range located at the end
100 * of the path in the Linux DTB */
101 uint32_t baseOffset;
102 /* Length value offset into the Linux value range located at
103 * the end of the path in the Linux DTB. Will be set to
104 * RM_DTB_UTIL_LINUX_ALIAS_OFFSET_NOT_SET if there is only
105 * a base value to read from the Linux DTB */
106 uint32_t lengthOffset;
107 /* Link to next Linux alias linked list node */
108 struct Rm_LinuxAlias_s *nextLinuxAlias;
109 } Rm_LinuxAlias;
111 /* NameServer assignment linked list node */
112 typedef struct Rm_NsAssignment_s {
113 /* NameServer name to be created */
114 char nsName[RM_NAME_MAX_CHARS];
115 /* Resource base value to tie to the name */
116 uint32_t resourceBase;
117 /* Resource length value to tie to the name */
118 uint32_t resourceLength;
119 /* Link to next NameServer assignment linked list node */
120 struct Rm_NsAssignment_s *nextNsAssignment;
121 } Rm_NsAssignment;
123 /**********************************************************************
124 ********************* Policy Parsing Definitions *********************
125 **********************************************************************/
127 /* Policy resource node property types */
128 typedef enum {
129 /** Policy DTB unknown property type */
130 Rm_policyPropType_UNKNOWN = 0,
131 /** Policy DTB resource assignments property type */
132 Rm_policyPropType_ASSIGNMENTS,
133 /** Policy DTB Client Delegate resource allocation size property type */
134 Rm_policyPropType_CD_ALLOCATION_SIZE,
135 /** Policy DTB allocation alignment property type */
136 Rm_policyPropType_ALLOCATION_ALIGNMENT,
137 /** Policy DTB valid RM instances property type */
138 Rm_policyPropType_VALID_INSTANCES
139 } Rm_PolicyPropType;
141 /* Policy assignment linked list node */
142 typedef struct Rm_PolicyAssignment_s {
143 /* Resource base affected by the permissions */
144 uint32_t resourceBase;
145 /* Resource length (started from base) affected by the permissions */
146 uint32_t resourceLength;
147 /* Permissions string defining which RM instances get
148 * which permissions for the defined resource range starting
149 * at resourceBase and ending at
150 * resourceBase+resourceLength-1 */
151 char *permissionsList;
152 /* Link to next policy assignment linked list node */
153 struct Rm_PolicyAssignment_s *nextAssignment;
154 } Rm_PolicyAssignment;
156 /* Valid instance linked list node */
157 typedef struct Rm_PolicyValidInst_s {
158 /* RM instance name */
159 char instName[RM_NAME_MAX_CHARS];
160 /* Link to next valid instance linked list node */
161 struct Rm_PolicyValidInst_s *nextValidInst;
162 } Rm_PolicyValidInst;
164 /**********************************************************************
165 ******************** Linux DTB Parsing Definitions *******************
166 **********************************************************************/
168 /* Linux value range linked list node */
169 typedef struct Rm_LinuxValueRange_s {
170 /* Numerical value extracted from Linux DTB */
171 uint32_t value;
172 /* Link to next Linux value linked list node */
173 struct Rm_LinuxValueRange_s *nextValue;
174 } Rm_LinuxValueRange;
176 /**********************************************************************
177 *************** Global Resource List Parsing Functions ***************
178 **********************************************************************/
180 Rm_ResourcePropType rmDtbUtilResGetPropertyType(const char *propertyName);
181 Rm_ResourceRange *rmDtbUtilResExtractRange(const void *dtbDataPtr, int32_t dtbDataLen);
182 void rmDtbUtilResFreeRange(Rm_ResourceRange *rangeList);
183 Rm_LinuxAlias *rmDtbUtilResExtractLinuxAlias(const void *dtbDataPtr, int32_t dtbDataLen,
184 int32_t *result);
185 void rmDtbUtilResFreeLinuxAlias(Rm_LinuxAlias *aliasList);
186 Rm_NsAssignment *rmDtbUtilResExtractNsAssignment(const void *dtbDataPtr, int32_t dtbDataLen,
187 int32_t *result);
188 void rmDtbUtilResFreeNsAssignmentList(Rm_NsAssignment *nsAssignmentList);
190 /**********************************************************************
191 ********************** Policy Parsing Functions***********************
192 **********************************************************************/
194 Rm_PolicyPropType rmDtbUtilPolicyGetPropertyType(const char *propertyName);
195 Rm_PolicyAssignment *rmDtbUtilPolicyExtractAssignments(const void *dtbDataPtr, int32_t dtbDataLen);
196 void rmDtbUtilPolicyFreeAssignments(Rm_PolicyAssignment *assignmentList);
197 Rm_ResourceValue *rmDtbUtilPolicyExtractCdAllocationSizes(const void *dtbDataPtr, int32_t dtbDataLen);
198 void rmDtbUtilPolicyFreeCdAllocationSizes(Rm_ResourceValue *allocationSizeList);
199 Rm_ResourceValue *rmDtbUtilPolicyExtractResourceAlignments(const void *dtbDataPtr, int32_t dtbDataLen);
200 void rmDtbUtilPolicyFreeResourceAlignments (Rm_ResourceValue *alignmentList);
201 Rm_PolicyValidInst *rmDtbUtilPolicyExtractValidInstances(const void *dtbDataPtr, int32_t dtbDataLen,
202 int32_t *result);
203 void rmDtbUtilPolicyFreeValidInstances (Rm_PolicyValidInst *validInstList);
205 /**********************************************************************
206 ********************* Linux DTB Parsing Functions ********************
207 **********************************************************************/
209 Rm_LinuxValueRange *rmDtbUtilLinuxExtractValues(const void *dtbDataPtr, int32_t dtbDataLen);
210 void rmDtbUtilLinuxFreeValues(Rm_LinuxValueRange *valueList);
212 #ifdef __cplusplus
213 }
214 #endif
216 #endif /* RM_DTB_UTILLOC_H_ */