60e3eb66f68c9f061a1ac39662ca2c5d3fcd51fb
1 /*
2 * file rm_treeloc.h
3 *
4 * Prototypes and data structures for the various RM Trees.
5 *
6 * ============================================================================
7 * (C) Copyright 2012-2015, 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_TREELOC_H_
41 #define RM_TREELOC_H_
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
47 /* Standard includes */
48 #include <stdint.h>
50 /* RM external includes */
51 #include <ti/drv/rm/rm.h>
53 /* Tree algorithm includes */
54 #include <ti/drv/rm/util/tree.h>
56 /**********************************************************************
57 *************** Tree Node Data Structure Definitions *****************
58 **********************************************************************/
60 /* NameServer node configuration structure */
61 typedef struct {
62 /* Name to assign to the resource values */
63 char *objName;
64 /* Resource name assigned to the NameServer name */
65 char *resourceName;
66 /* Resource base value assigned to the NameServer name */
67 uint32_t resourceBase;
68 /* Resource length value (starting from base) assigned to the NameServer
69 * name */
70 uint32_t resourceLength;
71 } Rm_NameServerNodeCfg;
73 /* NameServer node */
74 typedef struct _Rm_NameServerNode {
75 /* Tree algorithm data structure */
76 RB_ENTRY(_Rm_NameServerNode) linkage;
77 /* Name string */
78 char objName[RM_NAME_MAX_CHARS];
79 /* Resource name */
80 char resourceName[RM_NAME_MAX_CHARS];
81 /* Resource base value */
82 uint32_t resourceBase;
83 /* Resource length value */
84 uint32_t resourceLength;
85 } Rm_NameServerNode;
87 /* NameServer tree root entry type definition */
88 typedef RB_HEAD(_Rm_NameServerTree, _Rm_NameServerNode) Rm_NameServerTree;
90 /* Valid instance node */
91 typedef struct _Rm_PolicyValidInstNode {
92 /* Tree algorithm data structure */
93 RB_ENTRY(_Rm_PolicyValidInstNode) linkage;
94 /* Valid instance name string */
95 char name[RM_NAME_MAX_CHARS];
96 /* Number of existing resource allocations the instance is
97 * reference in. Resource frees involving the instance
98 * will decrement this count. A valid instance node cannot
99 * be deleted until this value is zero */
100 uint32_t allocRefCount;
101 /* TRUE: Delete this valid instance node once the allocRefCount
102 * reaches zero
103 * FALSE: Do not delete */
104 int8_t deletePending;
105 } Rm_PolicyValidInstNode;
107 /* Valid instance tree root entry type definition */
108 typedef RB_HEAD(_Rm_PolicyValidInstTree,
109 _Rm_PolicyValidInstNode) Rm_PolicyValidInstTree;
111 /* Resource node owner linked list node */
112 typedef struct Rm_Owner_s {
113 /* Pointer to the valid instance node that currently
114 * owns or partially owns the resource */
115 Rm_PolicyValidInstNode *instNameNode;
116 /* Number of times this owner has allocated the resource it is
117 * linked to. */
118 uint16_t refCnt;
119 /* Link to the next owner of the resoruce if the resource is shared */
120 struct Rm_Owner_s *nextOwner;
121 } Rm_Owner;
123 /* Resource node */
124 typedef struct _Rm_ResourceNode {
125 /* Tree algorithm data structure */
126 RB_ENTRY(_Rm_ResourceNode) linkage;
127 /* Resource base value */
128 uint32_t base;
129 /* Resource length value. With base this node covers a resource's values
130 * from base to base+length-1 */
131 uint32_t length;
132 /* Number of times this resource node has been allocated to a valid
133 * instance. This value will decrement for each free operation */
134 uint16_t allocationCount;
135 /* Linked list of existing owners. Will be NULL if no owners exist
136 * for the resource node */
137 Rm_Owner *ownerList;
138 } Rm_ResourceNode;
140 /* Resource tree root entry type definition */
141 typedef RB_HEAD(_Rm_AllocatorResourceTree, _Rm_ResourceNode) Rm_ResourceTree;
143 /* Allocator node */
144 typedef struct _Rm_AllocatorNode {
145 /* Tree algorithm data structure */
146 RB_ENTRY(_Rm_AllocatorNode) linkage;
147 /* Resource name for which the allocator was created. The resource name
148 * must match a resource node defined in both the GRL and the Policy */
149 char resourceName[RM_NAME_MAX_CHARS];
150 /* Pointer to the root entry of the allocator resource tree */
151 Rm_ResourceTree *resourceRootEntry;
152 } Rm_AllocatorNode;
154 /* Allocator tree root entry type definition */
155 typedef RB_HEAD(_Rm_AllocatorTree, _Rm_AllocatorNode) Rm_AllocatorTree;
157 /**********************************************************************
158 ****************** Tree Node Function Definitions ********************
159 **********************************************************************/
161 void rmNameServerTreeInv(Rm_NameServerTree *treeRoot);
162 void rmNameServerTreeWb(Rm_NameServerTree *treeRoot);
163 Rm_NameServerNode *rmNameServerNodeNew(Rm_NameServerNodeCfg *nodeCfg);
164 void rmNameServerNodeFree(Rm_NameServerNode *node);
165 int rmNameServerNodeCompare(Rm_NameServerNode *node1,
166 Rm_NameServerNode *node2);
167 void rmNameServerNodeInv(Rm_NameServerNode *node);
169 void rmPolicyValidInstTreeInv(Rm_PolicyValidInstTree *treeRoot);
170 void rmPolicyValidInstTreeWb(Rm_PolicyValidInstTree *treeRoot);
171 Rm_PolicyValidInstNode *rmPolicyValidInstNodeNew(char *instName);
172 void rmPolicyValidInstNodeFree(Rm_PolicyValidInstNode *node);
173 int rmPolicyValidInstNodeCompare(Rm_PolicyValidInstNode *node1,
174 Rm_PolicyValidInstNode *node2);
175 void rmPolicyValidInstNodeInv(Rm_PolicyValidInstNode *node);
177 void rmResourceTreeInv(Rm_ResourceTree *treeRoot);
178 void rmResourceTreeWb(Rm_ResourceTree *treeRoot);
179 Rm_ResourceNode *rmResourceNodeNew(uint32_t resourceBase,
180 uint32_t resourceLength);
181 void rmResourceNodeFree(Rm_ResourceNode *node);
182 int rmResourceNodeCompare(Rm_ResourceNode *node1, Rm_ResourceNode *node2);
183 void rmResourceNodeInv(Rm_ResourceNode *node);
185 void rmAllocatorTreeInv(Rm_AllocatorTree *treeRoot);
186 void rmAllocatorTreeWb(Rm_AllocatorTree *treeRoot);
187 Rm_AllocatorNode *rmAllocatorNodeNew(const char *resourceName);
188 void rmAllocatorNodeFree(Rm_AllocatorNode *node);
189 int rmAllocatorNodeCompare(Rm_AllocatorNode *node1, Rm_AllocatorNode *node2);
190 void rmAllocatorNodeInv(Rm_AllocatorNode *node);
192 /**********************************************************************
193 ******************** Tree Prototype Generation ***********************
194 **********************************************************************/
196 RB_PROTOTYPE(_Rm_NameServerTree, _Rm_NameServerNode, linkage,
197 rmNameServerNodeCompare, rmNameServerNodeInv)
198 RB_PROTOTYPE(_Rm_PolicyValidInstTree, _Rm_PolicyValidInstNode, linkage,
199 rmPolicyValidInstNodeCompare, rmPolicyValidInstNodeInv)
200 RB_PROTOTYPE(_Rm_AllocatorResourceTree, _Rm_ResourceNode, linkage,
201 rmResourceNodeCompare, rmResourceNodeInv)
202 RB_PROTOTYPE(_Rm_AllocatorTree, _Rm_AllocatorNode, linkage,
203 rmAllocatorNodeCompare, rmAllocatorNodeInv)
205 #ifdef __cplusplus
206 }
207 #endif
209 #endif /* RM_TREELOC_H_ */