061a9ba95d3af848ff4bbe549be8f46f2224eef7
1 /*
2 * file rm_loc.h
3 *
4 * General private data structures of Resource Manager.
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 RMLOC_H_
41 #define RMLOC_H_
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
47 /* RM external includes */
48 #include <ti/drv/rm/rm_services.h>
49 #include <ti/drv/rm/rm_policy.h>
50 #include <ti/drv/rm/rm_transport.h>
52 /* AVL BBST includes */
53 #include <ti/drv/rm/include/tree.h>
55 /** String stored for resource elements that are not currently allocated to anyone. If the
56 * resource is allocated the allocatedTo field will be populated with the RM instance
57 * name it was allocated to. */
58 #define RM_NOT_ALLOCATED_STRING "\0"
60 /** Maximum size of a transmittable RM policy in bytes */
61 #define RM_MAX_POLICY_SIZE_BYTES (64) // Placeholder: This will change
62 // during development
64 /** Pointer to RM instance's transport routing map */
65 typedef void *Rm_TransportRouteMap;
67 /** Pointer to RM instance's transaction queue */
68 typedef void *Rm_TransactionQueue;
70 /** Pointer to the RM instance's allocators */
71 typedef void *Rm_Allocators;
73 /**
74 * @brief RM transaction details values. Details values provide more fine-grained
75 * information regarding a transaction request or response
76 */
77 typedef enum {
78 /** Transaction is being processed */
79 Rm_transactionState_PROCESSING = 0,
80 /** Transaction has been approved */
81 Rm_transactionState_TRANSACTION_APPROVED = 1,
82 /** Transaction has been denied */
83 Rm_transactionState_TRANSACTION_DENIED = 2
84 } Rm_TransactionState;
86 /**
87 * @brief RM protocol packet resource information
88 */
89 typedef struct {
90 /** Resource name of resource affected by command */
91 char name[RM_RESOURCE_NAME_MAX_CHARS];
92 /** If applicable, start of resource range affected by command. If
93 * RM_RESOURCE_UNSPECIFIED is assigned the higher level RM agent*/
94 int32_t base;
95 /** If applicable, number of specified resource, starting from base, affected by command */
96 uint32_t length;
97 /** If applicable, the alignment of the resource affected by the command */
98 int32_t alignment;
99 /** If applicable, the NameServer name assigned to the specified
100 * resource. Used for commands centering on RM NameServer actions */
101 char nsName[RM_RESOURCE_NAME_MAX_CHARS];
102 } Rm_ResourceInfo;
104 /**
105 * @brief RM transactions are the internalized version of service requests received
106 * from components and RM commands received from other RM instances.
107 * Transactions that cannot immediately be serviced are placed in the RM
108 * instance's transaction queue. The transactions track all service
109 * requests within the RM infrastructure.
110 */
111 typedef struct {
112 /** Transaction service type */
113 Rm_ServiceType type;
114 /** Local ID of the transaction. */
115 uint32_t localId;
116 /** ID of transaction on lower level RM instance that generated the
117 * packet that resulted in the creation of the transaction. The
118 * originating ID will be placed in the transaction's response packet
119 * to the lower level RM instance. The lower level RM instance will
120 * match the response packet with the originating request using the ID */
121 uint32_t remoteOriginatingId;
122 /** Name of the RM instance the transaction originated from */
123 char sourceInstName[RM_INSTANCE_NAME_MAX_CHARS];
124 /** Transaction's associated callback function */
125 Rm_ServiceCallback callback;
126 /** Transaction state. The codes are externally visible and tracked
127 * in rmservices.h */
128 int32_t state;
129 /** Resource information */
130 Rm_ResourceInfo resourceInfo;
131 /** Link to the next transaction in the queue */
132 void *nextTransaction;
133 } Rm_Transaction;
135 typedef struct {
136 const void *allocatorData;
137 int32_t allocatorLen;
138 const void *rangeData;
139 int32_t rangeLen;
140 const void *nsAssignData;
141 int32_t nsAssignLen;
142 } Rm_ResourceProperties;
144 typedef enum {
145 Rm_allocatorType_INTEGER = 0,
146 Rm_allocatorType_TREE = 1,
147 } Rm_AllocatorType;
149 typedef enum {
150 Rm_allocatorOp_ALLOCATE = 0,
151 Rm_allocatorOp_FREE = 1,
152 Rm_allocatorOp_PRE_ALLOCATE = 2,
153 } Rm_AllocatorOp;
155 typedef struct {
156 char *srcInstName;
157 Rm_AllocatorOp operation;
158 Rm_ResourceInfo *resourceInfo;
159 } Rm_AllocatorOpInfo;
161 typedef struct {
162 uint32_t value;
163 char allocatedTo[RM_INSTANCE_NAME_MAX_CHARS];
164 } Rm_IntegerEntry;
166 typedef struct {
167 uint32_t numResourceElements;
168 Rm_IntegerEntry *resourceArrayBase;
169 } Rm_IntegerAllocatorRootEntry;
171 typedef struct {
172 char resourceName[RM_RESOURCE_NAME_MAX_CHARS];
173 Rm_AllocatorType type;
174 /** Pointer to the first resource entry in the allocator */
175 void *allocatorRootEntry;
176 /** Pointer to next resource allocator */
177 void *nextAllocator;
178 } Rm_Allocator;
180 typedef struct {
181 char name[RM_INSTANCE_NAME_MAX_CHARS];
182 Rm_InstType instType;
183 bool registeredWithDelegateOrServer;
184 Rm_PolicyHandle policyDtb;
185 Rm_Allocators allocators;
186 /* RM instance transport parameters */
187 Rm_TransportRouteMap routeMap;
188 /* RM Transaction sequence number counter */
189 uint32_t transactionSeqNum;
190 /* RM transaction queue */
191 Rm_TransactionQueue transactionQueue;
192 /* Transport API function pointers - not global in case application wants to
193 * hook up different transports to RM */
194 Rm_TransportCallouts transport;
195 } Rm_Inst;
197 Rm_Transaction *Rm_transactionQueueAdd(Rm_Inst *rmInst);
198 Rm_Transaction *Rm_transactionQueueFind(Rm_Inst *rmInst, uint32_t transactionId);
199 int32_t Rm_transactionQueueDelete(Rm_Inst *rmInst, uint32_t transactionId);
200 uint32_t Rm_transactionGetSequenceNum(Rm_Inst *rmInst);
202 void Rm_transactionProcessor (Rm_Inst *rmInst, Rm_Transaction *transaction);
204 /**********************************************************************
205 ******************* Red-Black Tree BBST Defines **********************
206 **********************************************************************/
208 /* Declare the tree structure nodes */
209 typedef struct _Rm_ResourceTreeNode {
210 RB_ENTRY(_Rm_ResourceTreeNode) linkage;
211 uint32_t base;
212 uint32_t length;
213 char allocatedTo[RM_INSTANCE_NAME_MAX_CHARS];
214 } Rm_ResourceTreeNode;
216 /* Will need to malloc a tree of type Rm_ResourceTree for each tree i want to create */
217 /* Declare the tree head structure */
218 typedef RB_HEAD(_Rm_ResourceTree, _Rm_ResourceTreeNode) Rm_ResourceTree;
220 /* Prototype for function that allocates new tree nodes */
221 Rm_ResourceTreeNode *Rm_newResourceTreeNode(uint32_t resourceBase, uint32_t resourceLength,
222 char *allocatedTo);
223 /* Prototype for function that frees new tree nodes */
224 void Rm_freeResourceTreeNode(Rm_ResourceTreeNode *treeNode);
225 /* Prototype for tree node comparison function
226 * element1 < element2 --> return < 0
227 * element1 = element2 --> return 0
228 * element1 > element2 --> return > 0 */
229 int Rm_ResourceTreeNodeCompare(Rm_ResourceTreeNode *element1, Rm_ResourceTreeNode *element2);
231 /* Generate the tree prototypes */
232 RB_PROTOTYPE(_Rm_ResourceTree, _Rm_ResourceTreeNode, linkage, Rm_ResourceTreeNodeCompare);
234 #ifdef __cplusplus
235 }
236 #endif
238 #endif /* RMLOC_H_ */