e37ea2b556806fc7f01792b313920f4e32055503
1 /*
2 * file rm_treeloc.h
3 *
4 * Prototypes and data structures for the various RM Trees.
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_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 name */
69 uint32_t resourceLength;
70 } Rm_NameServerNodeCfg;
72 /* NameServer node */
73 typedef struct _Rm_NameServerNode {
74 /* Tree algorithm data structure */
75 RB_ENTRY(_Rm_NameServerNode) linkage;
76 /* Name string */
77 char objName[RM_NAME_MAX_CHARS];
78 /* Resource name */
79 char resourceName[RM_NAME_MAX_CHARS];
80 /* Resource base value */
81 uint32_t resourceBase;
82 /* Resource length value */
83 uint32_t resourceLength;
84 } Rm_NameServerNode;
86 /* NameServer tree root entry type definition */
87 typedef RB_HEAD(_Rm_NameServerTree, _Rm_NameServerNode) Rm_NameServerTree;
89 /* Valid instance node */
90 typedef struct _Rm_PolicyValidInstNode {
91 /* Tree algorithm data structure */
92 RB_ENTRY(_Rm_PolicyValidInstNode) linkage;
93 /* Valid instance name string */
94 char name[RM_NAME_MAX_CHARS];
95 /* Number of existing resource allocations the instance is
96 * reference in. Resource frees involving the instance
97 * will decrement this count. A valid instance node cannot
98 * be deleted until this value is zero */
99 uint32_t allocRefCount;
100 /* TRUE: Delete this valid instance node once the allocRefCount
101 * reaches zero
102 * FALSE: Do not delete */
103 int8_t deletePending;
104 } Rm_PolicyValidInstNode;
106 /* Valid instance tree root entry type definition */
107 typedef RB_HEAD(_Rm_PolicyValidInstTree, _Rm_PolicyValidInstNode) Rm_PolicyValidInstTree;
109 /* Resource node owner linked list node */
110 typedef struct Rm_Owner_s {
111 /* Pointer to the valid instance node that currently
112 * owns or partially owns the resource */
113 Rm_PolicyValidInstNode *instNameNode;
114 /* Number of times this owner has allocated the resource it is
115 * linked to. */
116 uint16_t refCnt;
117 /* Link to the next owner of the resoruce if the resource is shared */
118 struct Rm_Owner_s *nextOwner;
119 } Rm_Owner;
121 /* Resource node */
122 typedef struct _Rm_ResourceNode {
123 /* Tree algorithm data structure */
124 RB_ENTRY(_Rm_ResourceNode) linkage;
125 /* Resource base value */
126 uint32_t base;
127 /* Resource length value. With base this node covers a resource's values
128 * from base to base+length-1 */
129 uint32_t length;
130 /* Number of times this resource node has been allocated to a valid
131 * instance. This value will decrement for each free operation */
132 uint16_t allocationCount;
133 /* Linked list of existing owners. Will be NULL if no owners exist
134 * for the resource node */
135 Rm_Owner *ownerList;
136 } Rm_ResourceNode;
138 /* Resource tree root entry type definition */
139 typedef RB_HEAD(_Rm_AllocatorResourceTree, _Rm_ResourceNode) Rm_ResourceTree;
141 /**********************************************************************
142 ****************** Tree Node Function Definitions ********************
143 **********************************************************************/
145 void rmNameServerTreeInv(Rm_NameServerTree *treeRoot);
146 void rmNameServerTreeWb(Rm_NameServerTree *treeRoot);
147 Rm_NameServerNode *rmNameServerNodeNew(Rm_NameServerNodeCfg *nodeCfg);
148 void rmNameServerNodeFree(Rm_NameServerNode *node);
149 int rmNameServerNodeCompare(Rm_NameServerNode *node1, Rm_NameServerNode *node2);
150 void rmNameServerNodeInv(Rm_NameServerNode *node);
152 void rmPolicyValidInstTreeInv(Rm_PolicyValidInstTree *treeRoot);
153 void rmPolicyValidInstTreeWb(Rm_PolicyValidInstTree *treeRoot);
154 Rm_PolicyValidInstNode *rmPolicyValidInstNodeNew(char *instName);
155 void rmPolicyValidInstNodeFree(Rm_PolicyValidInstNode *node);
156 int rmPolicyValidInstNodeCompare(Rm_PolicyValidInstNode *node1, Rm_PolicyValidInstNode *node2);
157 void rmPolicyValidInstNodeInv(Rm_PolicyValidInstNode *node);
159 void rmResourceTreeInv(Rm_ResourceTree *treeRoot);
160 void rmResourceTreeWb(Rm_ResourceTree *treeRoot);
161 Rm_ResourceNode *rmResourceNodeNew(uint32_t resourceBase, uint32_t resourceLength);
162 void rmResourceNodeFree(Rm_ResourceNode *node);
163 int rmResourceNodeCompare(Rm_ResourceNode *node1, Rm_ResourceNode *node2);
164 void rmResourceNodeInv(Rm_ResourceNode *node);
166 /**********************************************************************
167 ******************** Tree Prototype Generation ***********************
168 **********************************************************************/
170 RB_PROTOTYPE(_Rm_NameServerTree, _Rm_NameServerNode, linkage, rmNameServerNodeCompare, rmNameServerNodeInv)
171 RB_PROTOTYPE(_Rm_PolicyValidInstTree, _Rm_PolicyValidInstNode, linkage, rmPolicyValidInstNodeCompare, rmPolicyValidInstNodeInv)
172 RB_PROTOTYPE(_Rm_AllocatorResourceTree, _Rm_ResourceNode, linkage, rmResourceNodeCompare, rmResourceNodeInv)
174 #ifdef __cplusplus
175 }
176 #endif
178 #endif /* RM_TREELOC_H_ */