]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/rm-lld.git/blob - include/rm_loc.h
Added pre-main capabilities, cleaned up services and NameServer modules
[keystone-rtos/rm-lld.git] / include / rm_loc.h
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_transport.h>
51 /* RM internal includes */
52 #include <ti/drv/rm/include/rm_servicesloc.h>
53 #include <ti/drv/rm/include/rm_policyloc.h>
54 #include <ti/drv/rm/include/rm_nameserverloc.h>
56 /* AVL BBST includes */
57 #include <ti/drv/rm/include/tree.h>
59 /** Maximum size of a transmittable RM policy in bytes */
60 #define RM_MAX_POLICY_SIZE_BYTES (64)  // Placeholder: This will change 
61                                        // during development
63 /** Pointer to RM instance's transport routing map */
64 typedef void *Rm_TransportRouteMap;
66 /** Pointer to RM instance's transaction queue */
67 typedef void *Rm_TransactionQueue;
69 /**
70  * @brief RM protocol packet resource information
71  */
72 typedef struct {
73     /** Resource name of resource affected by command */
74     char     name[RM_RESOURCE_NAME_MAX_CHARS];
75     /** If applicable, start of resource range affected by command.  If
76      *  RM_RESOURCE_UNSPECIFIED is assigned the higher level RM agent*/
77     int32_t  base;
78     /** If applicable, number of specified resource, starting from base, affected by command */
79     uint32_t length;
80     /** If applicable, the alignment of the resource affected by the command */
81     int32_t  alignment;
82     /** If applicable, the NameServer name assigned to the specified
83      *  resource.  Used for commands centering on RM NameServer actions */
84     char     nameServerName[RM_RESOURCE_NAME_MAX_CHARS];
85 } Rm_ResourceInfo;
87 /**
88  * @brief RM transactions are the internalized version of service requests received 
89  *        from components and RM commands received from other RM instances.
90  *        Transactions that cannot immediately be serviced are placed in the RM
91  *        instance's transaction queue.  The transactions track all service
92  *        requests within the RM infrastructure.
93  */
94 typedef struct {
95     /** Transaction service type */
96     Rm_ServiceType type;
97     /** Local ID of the transaction. */
98     uint32_t localId;
99     /** ID of transaction in RM instance that generated the
100      *  packet that resulted in the creation of the transaction.  The
101      *  originating ID will be placed in the transaction's response packet
102      *  to the lower level RM instance.  The lower level RM instance will 
103      *  match the response packet with the originating request using the ID */
104     uint32_t remoteOriginatingId;
105     /** Name of the RM instance the RM packet, that spawned the transaction,
106      *  originated from */
107     char pktSrcInstName[RM_INSTANCE_NAME_MAX_CHARS];
108     /** Transaction's associated callback function */
109     Rm_ServiceCallback callback;
110     /** Transaction state.  The codes are externally visible and tracked
111      *  in rmservices.h */
112     int32_t state;
113     /** Name of the RM instance the service originated from */
114     char serviceSrcInstName[RM_INSTANCE_NAME_MAX_CHARS];    
115     /** Resource information */
116     Rm_ResourceInfo resourceInfo;
117     /** Link to the next transaction in the queue */
118     void *nextTransaction;    
119 } Rm_Transaction;
121 typedef struct {
122     const void *rangeData;
123     int32_t     rangeLen;
124     const void *nsAssignData;
125     int32_t     nsAssignLen;
126     const void *linuxAliasData;
127     int32_t     linuxAliasLen;
128 } Rm_ResourceProperties;
130 typedef enum {
131     Rm_allocatorOp_ALLOCATE = 0,
132     Rm_allocatorOp_FREE,
133     Rm_allocatorOp_PRE_ALLOCATE
134 } Rm_AllocatorOp;
136 typedef struct {
137     Rm_PolicyValidInstNode *serviceSrcInstNode;
138     Rm_AllocatorOp   operation;
139     uint32_t         allocType;
140     Rm_ResourceInfo *resourceInfo;
141 } Rm_AllocatorOpInfo;
143 typedef struct Rm_Allocator_s {
144     char resourceName[RM_RESOURCE_NAME_MAX_CHARS];
145     /** Pointer to the first resource entry in the allocator */
146     void *allocatorRootEntry;
147     /** Pointer to next resource allocator */
148     struct Rm_Allocator_s *nextAllocator;
149 } Rm_Allocator;
152 typedef struct {
153     char                    instName[RM_INSTANCE_NAME_MAX_CHARS];
154     void                   *startupDtb;
155     Rm_PolicyValidInstTree *validInstTree;
156     uint32_t                requestCount;
157     Rm_ServicePreMainReq   *preMainReqList;
158 } Rm_PreMainInst;
160 typedef struct {
161     char                    instName[RM_INSTANCE_NAME_MAX_CHARS];
162     Rm_InstType             instType;
163     bool                    registeredWithDelegateOrServer;
164     void                   *policy;
165     Rm_PolicyValidInstTree *validInstances;    
166     Rm_Allocator           *allocators;
167     Rm_NameServerTree      *nameServer;
168     /* RM instance transport parameters */
169     Rm_TransportRouteMap    routeMap;
170     /* RM Transaction sequence number counter */
171     uint32_t                transactionSeqNum;
172     /* RM transaction queue */
173     Rm_TransactionQueue     transactionQueue;
174     /* Transport API function pointers - not global in case application wants to
175       * hook up different transports to RM */
176     Rm_TransportCallouts    transport;
177 } Rm_Inst;
179 Rm_Transaction *Rm_transactionQueueAdd(Rm_Inst *rmInst);
180 Rm_Transaction *Rm_transactionQueueFind(Rm_Inst *rmInst, uint32_t transactionId);
181 int32_t Rm_transactionQueueDelete(Rm_Inst *rmInst, uint32_t transactionId);
182 uint32_t Rm_transactionGetSequenceNum(Rm_Inst *rmInst);
184 Rm_Allocator *Rm_allocatorFind(Rm_Allocator *allocatorList, char *resourceName);
186 void Rm_transactionResponder (Rm_Inst *rmInst, Rm_Transaction *transaction);
187 void Rm_transactionForwarder (Rm_Inst *rmInst, Rm_Transaction *transaction);
188 void Rm_transactionProcessor (Rm_Inst *rmInst, Rm_Transaction *transaction);
190 /**********************************************************************
191  ******************* Red-Black Tree BBST Defines **********************
192  **********************************************************************/
194 /* Declare the tree structure nodes */
195 typedef struct Rm_AllocatedTo_s {
196     Rm_PolicyValidInstNode  *instNameNode;
197     struct Rm_AllocatedTo_s *nextAllocatedTo;
198 } Rm_AllocatedTo;
200 typedef struct _Rm_ResourceNode {
201     RB_ENTRY(_Rm_ResourceNode)  linkage;
202     uint32_t                    base;
203     uint32_t                    length;
204     uint16_t                    allocationCount;
205     Rm_AllocatedTo             *allocatedTo;
206 } Rm_ResourceNode;
208 /* Declare the tree head structure.  A structure of type Rm_ResourceTree will need to be
209  * malloc'd for each tree that is to be created. */
210 typedef RB_HEAD(_Rm_ResourceTree, _Rm_ResourceNode) Rm_ResourceTree;
212 Rm_ResourceNode *Rm_newResourceNode(uint32_t resourceBase, uint32_t resourceLength);
213 void Rm_freeResourceNode(Rm_ResourceNode *node);
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_ResourceNodeCompare(Rm_ResourceNode *element1, Rm_ResourceNode *element2); 
220 /* Generate the tree prototypes */
221 RB_PROTOTYPE(_Rm_ResourceTree, _Rm_ResourceNode, linkage, Rm_ResourceNodeCompare);
223 #ifdef __cplusplus
225 #endif
227 #endif /* RMLOC_H_ */