ec1677da69c3d14933a6ce0db10d7c04c966838b
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"
59 /** String stored for resource elements that are reserved by the Linux kernel. These
60 * resources will be in use for the lifetime of the system */
61 #define RM_ALLOCATED_TO_LINUX "Linux-Kernel"
63 /** Maximum size of a transmittable RM policy in bytes */
64 #define RM_MAX_POLICY_SIZE_BYTES (64) // Placeholder: This will change
65 // during development
67 /** Pointer to RM instance's transport routing map */
68 typedef void *Rm_TransportRouteMap;
70 /** Pointer to RM instance's transaction queue */
71 typedef void *Rm_TransactionQueue;
73 /** Pointer to the RM instance's allocators */
74 typedef void *Rm_Allocators;
76 /** Pointer to the RM instance's NameServer (Valid only on Server) */
77 typedef void *Rm_NameServer;
79 /**
80 * @brief RM protocol packet resource information
81 */
82 typedef struct {
83 /** Resource name of resource affected by command */
84 char name[RM_RESOURCE_NAME_MAX_CHARS];
85 /** If applicable, start of resource range affected by command. If
86 * RM_RESOURCE_UNSPECIFIED is assigned the higher level RM agent*/
87 int32_t base;
88 /** If applicable, number of specified resource, starting from base, affected by command */
89 uint32_t length;
90 /** If applicable, the alignment of the resource affected by the command */
91 int32_t alignment;
92 /** If applicable, the NameServer name assigned to the specified
93 * resource. Used for commands centering on RM NameServer actions */
94 char nsName[RM_RESOURCE_NAME_MAX_CHARS];
95 } Rm_ResourceInfo;
97 /**
98 * @brief RM transactions are the internalized version of service requests received
99 * from components and RM commands received from other RM instances.
100 * Transactions that cannot immediately be serviced are placed in the RM
101 * instance's transaction queue. The transactions track all service
102 * requests within the RM infrastructure.
103 */
104 typedef struct {
105 /** Transaction service type */
106 Rm_ServiceType type;
107 /** Local ID of the transaction. */
108 uint32_t localId;
109 /** ID of transaction on lower level RM instance that generated the
110 * packet that resulted in the creation of the transaction. The
111 * originating ID will be placed in the transaction's response packet
112 * to the lower level RM instance. The lower level RM instance will
113 * match the response packet with the originating request using the ID */
114 uint32_t remoteOriginatingId;
115 /** Name of the RM instance the RM packet, that spawned the transaction,
116 * originated from */
117 char pktSrcInstName[RM_INSTANCE_NAME_MAX_CHARS];
118 /** Transaction's associated callback function */
119 Rm_ServiceCallback callback;
120 /** Transaction state. The codes are externally visible and tracked
121 * in rmservices.h */
122 int32_t state;
123 /** Name of the RM instance the service originated from */
124 char serviceSrcInstName[RM_INSTANCE_NAME_MAX_CHARS];
125 /** Resource information */
126 Rm_ResourceInfo resourceInfo;
127 /** Link to the next transaction in the queue */
128 void *nextTransaction;
129 } Rm_Transaction;
131 typedef struct {
132 const void *rangeData;
133 int32_t rangeLen;
134 const void *nsAssignData;
135 int32_t nsAssignLen;
136 const void *linuxAliasData;
137 int32_t linuxAliasLen;
138 } Rm_ResourceProperties;
140 typedef enum {
141 Rm_allocatorOp_ALLOCATE = 0,
142 Rm_allocatorOp_FREE = 1,
143 Rm_allocatorOp_PRE_ALLOCATE = 2,
144 } Rm_AllocatorOp;
146 typedef struct {
147 char *serviceSrcInstName;
148 Rm_AllocatorOp operation;
149 /* When pre-allocating, the policy's ranges and alignment for the resource
150 * for the RM instance will be copied to the following three variables. These
151 * variables will be used as the basis for pre-allocating a resource. */
152 uint32_t policyBase;
153 uint32_t policyLength;
154 uint32_t policyAlignment;
155 /* Will contain the actual allocation/free values */
156 Rm_ResourceInfo *resourceInfo;
157 } Rm_AllocatorOpInfo;
159 typedef struct {
160 char resourceName[RM_RESOURCE_NAME_MAX_CHARS];
161 /** Pointer to the first resource entry in the allocator */
162 void *allocatorRootEntry;
163 /** Pointer to next resource allocator */
164 void *nextAllocator;
165 } Rm_Allocator;
167 typedef struct {
168 char name[RM_INSTANCE_NAME_MAX_CHARS];
169 Rm_InstType instType;
170 bool registeredWithDelegateOrServer;
171 Rm_PolicyHandle policyDtb;
172 Rm_Allocators allocators;
173 Rm_NameServer nameServer;
174 /* RM instance transport parameters */
175 Rm_TransportRouteMap routeMap;
176 /* RM Transaction sequence number counter */
177 uint32_t transactionSeqNum;
178 /* RM transaction queue */
179 Rm_TransactionQueue transactionQueue;
180 /* Transport API function pointers - not global in case application wants to
181 * hook up different transports to RM */
182 Rm_TransportCallouts transport;
183 } Rm_Inst;
185 Rm_Transaction *Rm_transactionQueueAdd(Rm_Inst *rmInst);
186 Rm_Transaction *Rm_transactionQueueFind(Rm_Inst *rmInst, uint32_t transactionId);
187 int32_t Rm_transactionQueueDelete(Rm_Inst *rmInst, uint32_t transactionId);
188 uint32_t Rm_transactionGetSequenceNum(Rm_Inst *rmInst);
190 void Rm_transactionResponder (Rm_Inst *rmInst, Rm_Transaction *transaction);
191 void Rm_transactionForwarder (Rm_Inst *rmInst, Rm_Transaction *transaction);
192 void Rm_transactionProcessor (Rm_Inst *rmInst, Rm_Transaction *transaction);
194 /**********************************************************************
195 ******************* Red-Black Tree BBST Defines **********************
196 **********************************************************************/
198 /* Declare the tree structure nodes */
199 typedef struct _Rm_ResourceTreeNode {
200 RB_ENTRY(_Rm_ResourceTreeNode) linkage;
201 uint32_t base;
202 uint32_t length;
203 char allocatedTo[RM_INSTANCE_NAME_MAX_CHARS];
204 } Rm_ResourceTreeNode;
206 /* Declare the tree head structure. A structure of type Rm_ResourceTree will need to be
207 * malloc'd for each tree that is to be created. */
208 typedef RB_HEAD(_Rm_ResourceTree, _Rm_ResourceTreeNode) Rm_ResourceTree;
211 Rm_ResourceTreeNode *Rm_newResourceTreeNode(uint32_t resourceBase, uint32_t resourceLength,
212 char *allocatedTo);
213 void Rm_freeResourceTreeNode(Rm_ResourceTreeNode *treeNode);
214 /* Prototype for tree node comparison function
215 * element1 < element2 --> return < 0
216 * element1 = element2 --> return 0
217 * element1 > element2 --> return > 0 */
218 int Rm_ResourceTreeNodeCompare(Rm_ResourceTreeNode *element1, Rm_ResourceTreeNode *element2);
220 /* Generate the tree prototypes */
221 RB_PROTOTYPE(_Rm_ResourceTree, _Rm_ResourceTreeNode, linkage, Rm_ResourceTreeNodeCompare);
223 #ifdef __cplusplus
224 }
225 #endif
227 #endif /* RMLOC_H_ */