5b1d4637e4967819d1a33e063ec04e6a2af65604
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 typedef struct {
72 uint32_t value;
73 void *nextValue;
74 } Rm_ResourceValue;
76 /**********************************************************************
77 ***********Resource List DTB Parsing Defines and Functions************
78 **********************************************************************/
80 /**
81 * @brief Linux DTB alias offset not set
82 */
83 #define RM_DTB_LINUX_ALIAS_OFFSET_NOT_SET 0xFFFF
85 typedef enum {
86 /** Resource DTB unknown property type */
87 Rm_resourcePropType_UNKNOWN = 0,
88 /** Resource DTB device name property type */
89 Rm_resourcePropType_DEVICE_NAME = 1,
90 /** Resource DTB resource range property type */
91 Rm_resourcePropType_RESOURCE_RANGE = 2,
92 /** Resource DTB resource alias path in Linux DTB */
93 Rm_resourcePropType_RESOURCE_LINUX_ALIAS = 3,
94 /** Resource DTB NameServer assignment property type */
95 Rm_resourcePropType_NSASSIGNMENT = 4,
96 } Rm_ResourcePropType;
98 typedef struct {
99 char *path;
100 uint32_t baseOffset;
101 uint32_t lengthOffset;
102 void *nextLinuxAlias;
103 } Rm_LinuxAlias;
105 typedef struct {
106 char *nsName;
107 uint32_t resourceBase;
108 uint32_t resourceLength;
109 void *nextNsAssignment;
110 } Rm_NsAssignment;
112 Rm_ResourcePropType Rm_resourceGetPropertyType(const char *propertyName);
113 char *Rm_resourceExtractDeviceName(const void *dtbDataPtr, int32_t dtbDataLen);
114 void Rm_resourceFreeDeviceName(char *deviceName);
115 Rm_ResourceRange *Rm_resourceExtractRange(const void *dtbDataPtr, int32_t dtbDataLen);
116 void Rm_resourceFreeRange(Rm_ResourceRange *rangeList);
117 Rm_LinuxAlias *Rm_resourceExtractLinuxAlias(const void *dtbDataPtr, int32_t dtbDataLen);
118 void Rm_resourceFreeLinuxAlias(Rm_LinuxAlias *aliasList);
119 Rm_NsAssignment *Rm_resourceExtractNsAssignment(const void *dtbDataPtr, int32_t dtbDataLen);
120 void Rm_resourceFreeNsAssignmentList(Rm_NsAssignment *nsAssignmentList);
122 /**********************************************************************
123 ***************Policy DTB Parsing Defines and Functions***************
124 **********************************************************************/
126 /**
127 * @brief Depth of the RM instance nodes in the policy DTB
128 */
129 #define RM_POLICY_DTB_INSTANCE_DEPTH 1
131 typedef enum {
132 /** Policy DTB unknown property type */
133 Rm_policyPropType_UNKNOWN = 0,
134 /** Policy DTB resource assignments property type */
135 Rm_policyPropType_ASSIGNMENTS = 1,
136 /** Policy DTB resource allocation sizes property type */
137 Rm_policyPropType_ALLOCATION_SIZES = 2,
138 /** Policy DTB allocation alignments property type */
139 Rm_policyPropType_ALLOCATION_ALIGNMENTS = 3,
140 /** Policy DTB valid RM instances property type */
141 Rm_policyPropType_VALID_INSTANCES = 4,
142 } Rm_PolicyPropType;
144 typedef struct Rm_PolicyAssignment_s {
145 uint32_t resourceBase;
146 uint32_t resourceLength;
147 char *permissionsList;
148 struct Rm_PolicyAssignment_s *nextAssignment;
149 } Rm_PolicyAssignment;
151 typedef struct Rm_PolicyValidInst_s {
152 char *instName;
153 struct Rm_PolicyValidInst_s *nextValidInst;
154 } Rm_PolicyValidInst;
156 Rm_PolicyPropType Rm_policyGetPropertyType(const char *propertyName);
157 Rm_PolicyAssignment *Rm_policyExtractAssignments(const void *dtbDataPtr, int32_t dtbDataLen);
158 void Rm_policyFreeAssignments(Rm_PolicyAssignment *assignmentList);
159 Rm_ResourceValue *Rm_policyExtractAllocationSizes(const void *dtbDataPtr, int32_t dtbDataLen);
160 void Rm_policyFreeAllocationSizes(Rm_ResourceValue *allocationSizeList);
161 Rm_ResourceValue *Rm_policyExtractResourceAlignments(const void *dtbDataPtr, int32_t dtbDataLen);
162 void Rm_policyFreeResourceAlignments (Rm_ResourceValue *alignmentList);
163 Rm_PolicyValidInst *Rm_policyExtractValidInstances(const void *dtbDataPtr, int32_t dtbDataLen);
164 void Rm_policyFreeValidInstances (Rm_PolicyValidInst *validInstList);
166 /**********************************************************************
167 ****************Linux DTB Parsing Defines and Functions***************
168 **********************************************************************/
170 typedef struct {
171 uint32_t value;
172 void *nextValue;
173 } Rm_LinuxValueRange;
175 Rm_LinuxValueRange *Rm_linuxExtractValues(const void *dtbDataPtr, int32_t dtbDataLen);
176 void Rm_linuxFreeValues(Rm_LinuxValueRange *valueList);
178 #ifdef __cplusplus
179 }
180 #endif
182 #endif /* RM_DTB_UTILLOC_H_ */