7405b782458914d56b3f2cfeeede2495ff097b91
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 allocator property type */
88 Rm_resourcePropType_RESOURCE_ALLOCATOR = 3,
89 /** Resource DTB resource alias path in Linux DTB */
90 Rm_resourcePropType_RESOURCE_LINUX_ALIAS = 4,
91 /** Resource DTB NameServer assignment property type */
92 Rm_resourcePropType_NSASSIGNMENT = 5,
93 } Rm_ResourcePropType;
95 typedef struct {
96 const char *pathList;
97 uint32_t pathListLenBytes;
98 uint32_t baseOffset;
99 uint32_t lengthOffset;
100 void *nextLinuxAlias;
101 } Rm_LinuxAlias;
103 typedef struct {
104 char *nsName;
105 uint32_t resourceValue;
106 void *nextNsAssignment;
107 } Rm_NsAssignment;
109 Rm_ResourcePropType Rm_resourceGetPropertyType(const char *propertyName);
110 char *Rm_resourceExtractDeviceName(const void *dtbDataPtr, int32_t dtbDataLen);
111 void Rm_resourceFreeDeviceName(char *deviceName);
112 Rm_ResourceRange *Rm_resourceExtractRange(const void *dtbDataPtr, int32_t dtbDataLen);
113 void Rm_resourceFreeRange(Rm_ResourceRange *rangeList);
114 char *Rm_resourceExtractAllocator(const void *dtbDataPtr, int32_t dtbDataLen);
115 void Rm_resourceFreeAllocator(char *resourceAllocatorType);
116 Rm_LinuxAlias *Rm_resourceExtractLinuxAlias(const void *dtbDataPtr, int32_t dtbDataLen);
117 void Rm_resourceFreeLinuxAlias(Rm_LinuxAlias *aliasList);
118 Rm_NsAssignment *Rm_resourceExtractNsAssignment(const void *dtbDataPtr, int32_t dtbDataLen);
119 void Rm_resourceFreeNsAssignmentList(Rm_NsAssignment *nsAssignmentList);
121 /**********************************************************************
122 ***************Policy DTB Parsing Defines and Functions***************
123 **********************************************************************/
125 typedef enum {
126 /** Policy DTB unknown property type */
127 Rm_policyPropType_UNKNOWN = 0,
128 /** Policy DTB policy type property type */
129 Rm_policyPropType_POLICY_TYPE = 1,
130 /** Policy DTB resource assigned ranges property type */
131 Rm_policyPropType_RESOURCE_ASSIGNED_RANGES = 2,
132 /** Policy DTB resource allocation sizes property type */
133 Rm_policyPropType_RESOURCE_ALLOCATION_SIZES = 3,
134 /** Policy DTB assigned NameServer names property type */
135 Rm_policyPropType_ASSIGNED_NS_NAMES = 4,
136 } Rm_PolicyPropType;
138 typedef struct {
139 uint32_t allocationSize;
140 void *nextAllocationSize;
141 } Rm_AllocationSize;
143 typedef struct {
144 char *assignedName;
145 void *nextAssignedName;
146 } Rm_AssignedNsNames;
148 Rm_PolicyPropType Rm_policyGetPropertyType(const char *propertyName);
149 char *Rm_policyExtractPolicyType(const void *dtbDataPtr, int32_t dtbDataLen);
150 void Rm_policyFreePolicyType(char *policyType);
151 Rm_ResourceRange *Rm_policyExtractAssignedRanges(const void *dtbDataPtr, int32_t dtbDataLen);
152 void Rm_policyFreeAssignedRanges(Rm_ResourceRange *rangeList);
153 Rm_AllocationSize *Rm_policyExtractAllocationSizes(const void *dtbDataPtr, int32_t dtbDataLen);
154 void Rm_policyFreeAllocationSizesPropList(Rm_AllocationSize *allocationSizeList);
155 Rm_AssignedNsNames *Rm_policyExtractAssignedNsNames(const void *dtbDataPtr, int32_t dtbDataLen);
156 void Rm_policyFreeAssignmentNsNamesList(Rm_AssignedNsNames *assignedNsNamesList);
158 /**********************************************************************
159 ****************Linux DTB Parsing Defines and Functions***************
160 **********************************************************************/
162 typedef struct {
163 uint32_t value;
164 void *nextValue;
165 } Rm_LinuxValueRange;
167 Rm_LinuxValueRange *Rm_linuxExtractValues(const void *dtbDataPtr, int32_t dtbDataLen);
168 void Rm_linuxFreeValues(Rm_LinuxValueRange *valueList);
170 #ifdef __cplusplus
171 }
172 #endif
174 #endif /* RM_DTB_UTILLOC_H_ */