1 /*
2 * file rmloc.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 #if 0
53 /* RM permissions structure for CPPI DMA channels and flows */
54 typedef struct
55 {
56 /** Array of pointers to each DMAs channel or flow permissions
57 * From CPPI LLD - DMA 0 = SRIO
58 * DMA 1 = AIF
59 * DMA 2 = FFTC A
60 * DMA 3 = FFTC B
61 * DMA 4 = PASS
62 * DMA 5 = QMSS
63 * DMA 6 = FFTC C
64 * DMA 7 = BCP
65 *
66 * Note: Some DMAs may not be supported based on the device */
67 Rm_Perms *dmaPermPtrs[RM_CPPI_MAX_DMAS];
68 } Rm_CppiChAndFlowPerms;
70 /* RM Cache Line Alignment Defines and Macros */
72 #define RM_MAX_CACHE_ALIGN 128 /* Maximum alignment for cache line size */
74 /* This macro generates compiler error if postulate is false, so
75 * allows 0 overhead compile time size check. This "works" when
76 * the expression contains sizeof() which otherwise doesn't work
77 * with preprocessor */
78 #define RM_COMPILE_TIME_SIZE_CHECK(postulate) \
79 do { \
80 typedef struct { \
81 uint8_t NegativeSizeIfPostulateFalse[((int)(postulate))*2 - 1];\
82 } PostulateCheck_t; \
83 } \
84 while (0)
86 /* Macro to pad out internal permission structures to multiple of RM_MAX_CACHE_ALIGN bytes
87 * The macro prevent something else from being placed on same cache line as the permission.
88 * arrays. Note that pad[0] is illegal, so must add full RM_MAX_CACHE_ALIGN if structure
89 * is already padded by chance. */
90 #define RM_ALIGN_PERMISSIONS_ARRAY(numElements, permStructType) ( \
91 (((sizeof(permStructType) * (numElements)) % RM_MAX_CACHE_ALIGN) == 0) ? (numElements) : \
92 ((numElements) + \
93 (RM_MAX_CACHE_ALIGN - \
94 ((sizeof(permStructType) * (numElements)) % RM_MAX_CACHE_ALIGN))/sizeof(permStructType)))
96 /* RM Global Sync Object (unpadded) */
97 typedef struct
98 {
99 /** Rm_init/Rm_start synchronization object. */
100 uint8_t globalSyncObj;
101 } Rm_Sync_Obj_Unpadded;
103 /* RM Global Sync Object (padded) */
104 typedef struct
105 {
106 /** Data structure without padding, so sizeof() can compute padding */
107 Rm_Sync_Obj_Unpadded obj;
108 /** Pad out to end of RM_MAX_CACHE_ALIGN bytes to prevent something else
109 * from being placed on same cache line as Rm_Synci_Obj. Note that
110 * pad[0] is illegal, so must add full RM_MAX_CACHE_ALIGN if structure
111 * is already padded by chance. */
112 uint8_t pad[RM_MAX_CACHE_ALIGN -
113 (sizeof(Rm_Sync_Obj_Unpadded) % RM_MAX_CACHE_ALIGN)];
114 } Rm_Sync_Obj;
115 #endif
117 /** Maximum size of a transmittable RM policy in bytes */
118 #define RM_MAX_POLICY_SIZE_BYTES (64) // Placeholder: This will change
119 // during development
122 #define var(n) ((uint32_t)((uint8_t *)&x)[n])
123 static inline uint32_t dtb32_to_cpu(uint32_t x)
124 {
125 return (var(0) << 24) | (var(1) << 16) | (var(2) << 8) | var(3);
126 }
127 #define cpu_to_dtb32(x) fdt32_to_cpu(x)
130 /** Pointer to RM instance's transport routing map */
131 typedef void *Rm_TransportRouteMap;
133 /** Pointer to RM instance's transaction queue */
134 typedef void *Rm_TransactionQueue;
136 /**
137 * @brief RM transaction details values. Details values provide more fine-grained
138 * information regarding a transaction request or response
139 */
140 typedef enum {
141 /** Transaction is being processed */
142 Rm_transactionState_PROCESSING = 0,
143 /** Transaction has been approved */
144 Rm_transactionState_TRANSACTION_APPROVED = 1,
145 /** Transaction has been denied */
146 Rm_transactionState_TRANSACTION_DENIED = 2
147 } Rm_TransactionState;
149 /**
150 * @brief RM protocol packet resource information
151 */
152 typedef struct {
153 /** Resource name of resource affected by command */
154 char name[RM_RESOURCE_NAME_MAX_CHARS];
155 /** If applicable, start of resource range affected by command. If
156 * RM_RESOURCE_UNSPECIFIED is assigned the higher level RM agent*/
157 int32_t base;
158 /** If applicable, range of specified resource, starting from base, affected by command */
159 uint32_t range;
160 /** If applicable, the alignment of the resource affected by the command */
161 int32_t alignment;
162 /** If applicable, the NameServer name assigned to the specified
163 * resource. Used for commands centering on RM NameServer actions */
164 char nsName[RM_RESOURCE_NAME_MAX_CHARS];
165 } Rm_ResourceInfo;
167 /**
168 * @brief RM transactions are the internalized version of service requests received
169 * from components and RM commands received from other RM instances.
170 * Transactions that cannot immediately be serviced are placed in the RM
171 * instance's transaction queue. The transactions track all service
172 * requests within the RM infrastructure.
173 */
174 typedef struct {
175 /** Transaction service type */
176 Rm_ServiceType type;
177 /** Local ID of the transaction. */
178 uint32_t localId;
179 /** ID of transaction on lower level RM instance that generated the
180 * packet that resulted in the creation of the transaction. The
181 * originating ID will be placed in the transaction's response packet
182 * to the lower level RM instance. The lower level RM instance will
183 * match the response packet with the originating request using the ID */
184 uint32_t remoteOriginatingId;
185 /** Name of the RM instance the transaction originated from */
186 char sourceInstName[RM_INSTANCE_NAME_MAX_CHARS];
187 /** Transaction's associated callback function */
188 Rm_ServiceCallback callback;
189 /** Transaction state. The codes are externally visible and tracked
190 * in rmservices.h */
191 int32_t state;
192 /** Resource information */
193 Rm_ResourceInfo resourceInfo;
194 /** Link to the next transaction in the queue */
195 void *nextTransaction;
196 } Rm_Transaction;
198 typedef struct {
199 char name[RM_INSTANCE_NAME_MAX_CHARS];
200 Rm_InstType instType;
201 bool registeredWithDelegateOrServer;
202 Rm_PolicyHandle instPolicy;
203 /* RM instance transport parameters */
204 Rm_TransportRouteMap routeMap;
205 /* RM Transaction sequence number counter */
206 uint32_t transactionSeqNum;
207 /* RM transaction queue */
208 Rm_TransactionQueue transactionQueue;
209 /* Transport API function pointers - not global in case application wants to
210 * hook up different transports to RM */
211 Rm_TransportCallouts transport;
212 } Rm_Inst;
214 Rm_Transaction *Rm_transactionQueueAdd(Rm_Inst *rmInst);
215 Rm_Transaction *Rm_transactionQueueFind(Rm_Inst *rmInst, uint32_t transactionId);
216 int32_t Rm_transactionQueueDelete(Rm_Inst *rmInst, uint32_t transactionId);
217 uint32_t Rm_transactionGetSequenceNum(Rm_Inst *rmInst);
219 void Rm_transactionProcessor (Rm_Inst *rmInst, Rm_Transaction *transaction);
221 #ifdef __cplusplus
222 }
223 #endif
225 #endif /* RMLOC_H_ */