1 /**
2 * @file rmservices.h
3 *
4 * @brief
5 * This is the RM include file for services provided to components that
6 * register a RM instance
7 *
8 * \par
9 * ============================================================================
10 * @n (C) Copyright 2012, Texas Instruments, Inc.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 *
16 * Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 *
19 * Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the
22 * distribution.
23 *
24 * Neither the name of Texas Instruments Incorporated nor the names of
25 * its contributors may be used to endorse or promote products derived
26 * from this software without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *
40 * \par
41 */
43 #ifndef RMSERVICES_H_
44 #define RMSERVICES_H_
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
50 /* RM includes */
51 #include <ti/drv/rm/rm.h>
53 /**
54 @addtogroup RMSERVICES_API
55 @{
56 */
58 /** RM Service Request State Codes and Errors */
59 /** RM Service Request State Code Base */
60 #define RM_SERVICE_STATE_BASE (0)
61 /** RM internal state okay - This value is for internal use by RM. It should never be
62 * seen as a return value during normal operation */
63 #define RM_SERVICE_STATE_OKAY (RM_SERVICE_STATE_BASE)
64 /** RM service is being processed. Typically this means the service is
65 * being sent to a higher level RM agent for processing */
66 #define RM_SERVICE_PROCESSING (RM_SERVICE_STATE_BASE+1)
67 /** RM service was approved. The resource data in the response is valid if
68 * the service has been approved. */
69 #define RM_SERVICE_APPROVED_AND_COMPLETED (RM_SERVICE_STATE_BASE+2)
70 /** Beginning of resource denied reasons */
71 #define RM_SERVICE_DENIED_BEGIN (RM_SERVICE_STATE_BASE+3)
72 /** RM could not find an allocator for the resource specified with the provided name */
73 #define RM_SERVICE_DENIED_RESOURCE_DOES_NOT_EXIST (RM_SERVICE_DENIED_BEGIN)
74 /** A resource value within the specifed base+range could not be found within the resource's
75 * allocator. No action was taken on the resources. */
76 #define RM_SERVICE_DENIED_RESOURCE_VALUE_RANGE_DOES_NOT_EXIST (RM_SERVICE_DENIED_BEGIN+1)
77 /** A resource value within the specifed base+range was not allocated to the RM instance
78 * that is the source of the request. No action was taken on the resources. */
79 #define RM_SERVICE_DENIED_RESOURCE_NOT_ALLOCATED_TO_INSTANCE_REQUESTING_THE_SERVICE (RM_SERVICE_DENIED_BEGIN+2)
80 /** A resource value within the specifed base+range is already free */
81 #define RM_SERVICE_DENIED_RESOURCE_ALREADY_FREE (RM_SERVICE_DENIED_BEGIN+3)
82 /** A resource value within the specifed base+range is already allocated to another
83 * RM instance. */
84 #define RM_SERVICE_DENIED_RESOURCE_ALREADY_ALLOCATED (RM_SERVICE_DENIED_BEGIN+4)
85 /** The resource range specified for freeing included free and allocated resoruces. */
86 #define RM_SERVICE_DENIED_INVALID_RESOURCE_RANGE (RM_SERVICE_DENIED_BEGIN+5)
87 /** No free resource ranges could be found that satisfy the resource base, length, and
88 * alignment requirements */
89 #define RM_SERVICE_DENIED_RESOURCE_ALLOCATION_REQUIREMENTS_COULD_NOT_BE_SATISFIED (RM_SERVICE_DENIED_BEGIN+6)
90 /** The RM instance requesting the service is not defined in the policy */
91 #define RM_SERVICE_DENIED_RM_INST_NOT_DEFINED_IN_POLICY (RM_SERVICE_DENIED_BEGIN+7)
92 /** The resource in the service request is not defined in the policy */
93 #define RM_SERVICE_DENIED_RESOURCE_NOT_DEFINED_IN_POLICY (RM_SERVICE_DENIED_BEGIN+8)
94 /** The resource has multiple assigned range definitions */
95 #define RM_SERVICE_DENIED_ASSIGNED_RANGE_SPECIFICATION_ERROR (RM_SERVICE_DENIED_BEGIN+9)
96 /** The resource has multiple allocation size definitions */
97 #define RM_SERVICE_DENIED_ALLOCATION_SIZE_SPECIFICATION_ERROR (RM_SERVICE_DENIED_BEGIN+10)
98 /** The resource has multiple assigned name definitions */
99 #define RM_SERVICE_DENIED_ASSIGNED_NAME_SPECIFICATION_ERROR (RM_SERVICE_DENIED_BEGIN+11)
100 /** The resource has multiple allocation alignment definitions */
101 #define RM_SERVICE_DENIED_ALLOCATION_ALIGNMENT_SPECIFICATION_ERROR (RM_SERVICE_DENIED_BEGIN+12)
102 /** The resource node in the policy has an unknown property type */
103 #define RM_SERVICE_DENIED_UNKNOWN_POLICY_PROPERTY (RM_SERVICE_DENIED_BEGIN+13)
104 /** End of resource denied reasons */
105 #define RM_SERVICE_DENIED_END (RM_SERVICE_DENIED_BEGIN+13)
107 /** RM Service Request Error Code Base */
108 #define RM_SERVICE_ERROR_BASE (-64)
109 /** RM service request type not recognized */
110 #define RM_SERVICE_ERROR_INVALID_SERVICE_TYPE (RM_SERVICE_ERROR_BASE)
111 /** RM Service request was not provided a component callback
112 * function. Service requests may result in blocking operations. A callback
113 * function must always be provided with a service request since
114 * blocked or non-blocked operations cannot be promised. */
115 #define RM_SERVICE_ERROR_CALLBACK_NOT_PROVIDED (RM_SERVICE_ERROR_BASE-1)
116 /** RM service request needs to be forwarded to another RM agent but no transports
117 * have been registered */
118 #define RM_SERVICE_ERROR_NO_TRANSPORT_REGISTERED (RM_SERVICE_ERROR_BASE-2)
119 /** RM service request needs to be forwarded but no client delegate or server has
120 * been registered with the RM instance */
121 #define RM_SERVICE_ERROR_NOT_REGISTERED_WITH_DEL_OR_SERVER (RM_SERVICE_ERROR_BASE-3)
122 /** RM service request needs to be forwarded but the transport packet alloc API
123 * has not been provided */
124 #define RM_SERVICE_ERROR_TRANSPORT_PKT_ALLOC_API_NULL (RM_SERVICE_ERROR_BASE-4)
125 /** A failure occurred within a registered transport's packet alloc API */
126 #define RM_SERVICE_ERROR_TRANSPORT_ALLOC_PKT_ERROR (RM_SERVICE_ERROR_BASE-5)
127 /** RM service request needs to be forwarded but the buffer allocated by transport
128 * is not large enough to fit the RM transport packet */
129 #define RM_SERVICE_ERROR_TRANSPORT_PKT_BUF_TOO_SMALL (RM_SERVICE_ERROR_BASE-6)
130 /** RM service request needs to be forwarded but the transport returned an error
131 * when trying to send the RM packet to the higher level agent */
132 #define RM_SERVICE_ERROR_TRANPSPORT_SEND_ERROR (RM_SERVICE_ERROR_BASE-7)
133 /** RM service response from higher level agent did not match any requests made
134 * by the provided RM instance */
135 #define RM_SERVICE_ERROR_TRANSACTION_DOES_NOT_EXST_FOR_THIS_RM_INSTANCE (RM_SERVICE_ERROR_BASE-8)
136 /** RM failed to allocate memory for new service transaction */
137 #define RM_SERVICE_ERROR_TRANSACTION_FAILED_TO_ALLOCATE (RM_SERVICE_ERROR_BASE-9)
138 /** RM could not find the service transaction in the RM instance's transaction queue */
139 #define RM_SERVICE_ERROR_SERVICE_TRANSACTION_DOES_NOT_EXIST (RM_SERVICE_ERROR_BASE-10)
140 /** A failure occurred within a registered transport's packet free API */
141 #define RM_SERVICE_ERROR_TRANSPORT_FREE_PKT_ERROR (RM_SERVICE_ERROR_BASE-11)
142 /** Invalid NameServer object modification on non-Server instance */
143 #define RM_SERVICE_ERROR_NAMESERVER_OBJECT_MOD_ON_INVALID_INSTANCE (RM_SERVICE_ERROR_BASE-12)
144 /** Request failed because both a NameServer name and a resource range were specified */
145 #define RM_SERVICE_ERROR_NAMESERVER_NAME_AND_RESOURCE_RANGE_BOTH_DEFINED (RM_SERVICE_ERROR_BASE-13)
147 /**
148 * @brief Maximum number of characters in the resource names
149 */
150 #define RM_RESOURCE_NAME_MAX_CHARS (36)
152 /**
153 * @brief RM service types
154 */
155 typedef enum {
156 /** RM resource allocate service */
157 Rm_service_RESOURCE_ALLOCATE = 0,
158 /** RM resource free service */
159 Rm_service_RESOURCE_FREE = 1,
160 /** RM resource mapping to name service */
161 Rm_service_RESOURCE_MAP_TO_NAME = 2,
162 /** RM resource get by name service */
163 Rm_service_RESOURCE_GET_BY_NAME = 3,
164 /** RM resource name unmapping service */
165 Rm_service_RESOURCE_UNMAP_NAME = 4
166 } Rm_ServiceType;
168 /**
169 * @brief RM pre-main allocation request information provided by the pre-main
170 * startup function requesting the resource */
171 typedef struct {
172 /** Pointer to the requested pre-main allocation resource name. The
173 * name provided by the component must match the resource names
174 * provided in the global resource table and allocation policies */
175 char *resourceName;
176 /** The pre-main allocation request resource base value. For example,
177 * queue number or semaphore number */
178 uint32_t resourceBase;
179 /** Range of resource starting at resourceBase */
180 uint32_t resourceRange;
181 } Rm_PreMainAllocInfo;
183 /**
184 * @brief RM service response information provided by RM back to the
185 * requesting component
186 */
187 typedef struct {
188 /** State of the service request.
189 * Non-negative result: RM has taken an action based on the request
190 * Negative result: RM has encountered an error handling the request */
191 int32_t serviceState;
192 /** A service ID will be returned to the component if the requested service cannot
193 * be completed immediately. The service ID can be used by the component to identify
194 * service responses received via the component callback function. A service ID will not
195 * be returned if the service request is satisfied immediately */
196 uint32_t serviceId;
197 /** The name of the resource affected by the service request */
198 char resourceName[RM_RESOURCE_NAME_MAX_CHARS];
199 /** The base value of the returned resource. In the case of a block resource allocation
200 * response this field will contain the base value of the block. */
201 int32_t resourceBase;
202 /** The number of resources starting from resourceBase allocated in block requests */
203 uint32_t resourceLength;
204 } Rm_ServiceRespInfo;
206 /**
207 * @brief RM service callback function structure
208 */
209 typedef struct {
210 /** Component callback function. RM will call this function when the
211 * resource service request is completed. The callback function supplied
212 * for this parameter must match this function pointer prototype. */
213 void (*serviceCallback) (Rm_ServiceRespInfo *serviceResponse);
214 } Rm_ServiceCallback;
216 /**
217 * @brief RM service request information provided by the requesting component
218 */
219 typedef struct {
220 /** The type of RM service requested */
221 Rm_ServiceType type;
222 /** Pointer to the name of the resource requested. The
223 * name provided by the component must match the resource node names
224 * provided in the global resource table and allocation policies */
225 char *resourceName;
226 /** An allocate service can be requested with an unspecified resource base.
227 * If this occurs the RM Client Delegate or Server will assign the next available
228 * resource or set of resources based on the allocation type. */
229 #define RM_RESOURCE_BASE_UNSPECIFIED (-1)
230 /** The resource base value. */
231 int32_t resourceBase;
232 /** The number of the specified resource to be allocated starting from
233 * resourceBase. Will be greater than one only for block allocate
234 * and free service requests. */
235 uint32_t resourceLength;
236 /** An allocate service can be requested with an unspecified resource alignment.
237 * WARNING: Only applicapable if resourceBase is unspecified
238 *
239 * If the alignment is unspecified the RM Client Delegate or Server will allocate
240 * the resources from a default alignment as specified in the global policy. */
241 #define RM_RESOURCE_ALIGNMENT_UNSPECIFIED (-1)
242 /** Resource alignment in block allocation requests */
243 int32_t resourceAlignment;
244 /** The name server name associated with the resource. Used only for
245 * allocate and free by name service requests */
246 char *resourceNsName;
247 /** Component specified callback function used by RM to inform components
248 * of service requst results */
249 Rm_ServiceCallback callback;
250 } Rm_ServiceReqInfo;
252 /**
253 * @brief RM Service Port provided to software components and applications that
254 * request RM services for the resources they wish to use
255 */
256 typedef struct {
257 /** RM instance handle for which the service handle was registered */
258 void *rmHandle;
259 /**
260 * @b Description
261 * @n
262 * Callout function used by components to request a resource service
263 * from a RM instance
264 *
265 * @param[in] rmHandle
266 * RM instance handle specifying the RM instance that should handle the
267 * service request
268 *
269 * @param[in] serviceRequest
270 * Service request structure that provides details of the service requested from
271 * the RM instance tied to this component
272 *
273 * @param[in] serviceResponse
274 * Service response structure that provides details of RM's response to the
275 * service request
276 */
277 void (*rmService)(void *rmHandle, Rm_ServiceReqInfo *serviceRequest,
278 Rm_ServiceRespInfo *serviceResponse);
279 } Rm_ServicePort;
281 /**
282 * @b Description
283 * @n
284 * Non-blocking function used by RTSC pre-main startup functions to
285 * allocate RM resources for usage. Pre-main allocated resources will be
286 * validated by RM against a memory-mapped startup resource policy.
287 * Pre-main allocation of unauthorized resources will result in a system
288 * exception.
289 *
290 * Note: Resource pre-main allocations can only occur on a core that is
291 * running a RM Server or Client Delegate that has a startup policy
292 * allowing the allocation of pre-main resources
293 *
294 * @param[in] preMainAllocInfo
295 * Resource pre-main allocation structure that provides details of the
296 * resource requested from RM for preallocation
297 *
298 * @param[out] serviceResponse
299 * Contains the result information regarding the pre-main allocation request
300 *
301 * @retval
302 * Success - 0 - Resource pre-main allocation request okay.
303 * @retval
304 * Failure - non-zero - Resource pre-main allocation request error.
305 */
306 void Rm_preMainAllocService (Rm_PreMainAllocInfo *preMainAllocInfo,
307 Rm_ServiceRespInfo *serviceResponse);
309 /**
310 * @b Description
311 * @n
312 * This function returns a RM service port to the application to
313 * provide to software components (LLDs, BIOS, etc) that want to use RM
314 * for resource management.
315 *
316 * @param[in] rmHandle
317 * RM instance handle. Used to return a Rm_ServicePort from an RM
318 * instance.
319 *
320 * @retval
321 * Success - RM Service Port. Used by an application or component to
322 * request a service from RM.
323 * @retval
324 * Failure - NULL
325 */
326 Rm_ServicePort *Rm_getServicePort(Rm_Handle rmHandle);
328 /**
329 @}
330 */
332 #ifdef __cplusplus
333 }
334 #endif
336 #endif /* RMSERVICES_H_ */