]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/rm-lld.git/blob - rm_services.h
2013a662e0898fec77a65a354702334d99214214
[keystone-rtos/rm-lld.git] / rm_services.h
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 /** The policy does not approve of the resources requested by the RM instance in the service
105  *  request */
106 #define RM_SERVICE_DENIED_POLICY_DENIAL (RM_SERVICE_DENIED_BEGIN+14)
107 /** Attempt to add object to NameServer denied: The object name already exists in the NameServer */
108 #define RM_SERVICE_DENIED_NAMESERVER_ERROR_NAME_ALREADY_EXISTS (RM_SERVICE_DENIED_BEGIN+15)
109 /** No valid ranges were specified for the resource within the RM instance's node within the policy.
110  *  By default all resource requests for this resource are denied */
111 #define RM_SERVICE_DENIED_POLICY_DENIAL_NO_RANGES_SPECIFIED (RM_SERVICE_DENIED_BEGIN+16)
112 /** The instance name of the service requesting instance is not in the policy valid instance list */
113 #define RM_SERVICE_DENIED_ORIGINATING_INSTANCE_NAME_NOT_VALID (RM_SERVICE_DENIED_BEGIN+17)
114 /** The policy does not specify any assignment ranges for the resource in the service request */
115 #define RM_SERVICE_DENIED_NO_RANGE_ASSIGNMENTS_FOR_POLICY (RM_SERVICE_DENIED_BEGIN+18)
116 /** The resource couldn't be allocated because the requesting instance was not given the init/use
117  *  permissions in the policy */
118 #define RM_SERVICE_DENIED_INIT_USE_PERMISSION_DENIED (RM_SERVICE_DENIED_BEGIN+19)
119 /** The resource couldn't be allocated because the requesting instance has exclusive privileges in the
120  *  policy but the resource was already allocated */
121 #define RM_SERVICE_DENIED_REQUESTER_HAS_EXCLUSIVE_PRIV_BUT_RESOURCE_ALLOCATED (RM_SERVICE_DENIED_BEGIN+20)
122 /** The resource couldn't be allocated because it was already allocated to an instance with exclusive
123  *  privileges for the resource */
124 #define RM_SERVICE_DENIED_RESOURCE_ALLOCATED_TO_INSTANCE_WITH_EXCLUSIVE_PRIV (RM_SERVICE_DENIED_BEGIN+21)
125 /** End of resource denied reasons */
126 #define RM_SERVICE_DENIED_END (RM_SERVICE_DENIED_BEGIN+21)
128 /** RM Service Request Error Code Base */
129 #define RM_SERVICE_ERROR_BASE (-64)
130 /** RM service request type not recognized */
131 #define RM_SERVICE_ERROR_INVALID_SERVICE_TYPE (RM_SERVICE_ERROR_BASE)
132 /** RM Service request was not provided a component callback
133  *  function.  Service requests may result in blocking operations.  A callback
134  *  function must always be provided with a service request since
135  *  blocked or non-blocked operations cannot be promised.  */
136 #define RM_SERVICE_ERROR_CALLBACK_NOT_PROVIDED (RM_SERVICE_ERROR_BASE-1)
137 /** RM service request needs to be forwarded to another RM agent but no transports
138  *  have been registered */
139 #define RM_SERVICE_ERROR_NO_TRANSPORT_REGISTERED (RM_SERVICE_ERROR_BASE-2)
140 /** RM service request needs to be forwarded but no client delegate or server has 
141  *  been registered with the RM instance */
142 #define RM_SERVICE_ERROR_NOT_REGISTERED_WITH_DEL_OR_SERVER (RM_SERVICE_ERROR_BASE-3)
143 /** RM service request needs to be forwarded but the transport packet alloc API
144  *  has not been provided */
145 #define RM_SERVICE_ERROR_TRANSPORT_PKT_ALLOC_API_NULL (RM_SERVICE_ERROR_BASE-4)
146 /** A failure occurred within a registered transport's packet alloc API */
147 #define RM_SERVICE_ERROR_TRANSPORT_ALLOC_PKT_ERROR (RM_SERVICE_ERROR_BASE-5)
148 /** RM service request needs to be forwarded but the buffer allocated by transport
149  *  is not large enough to fit the RM transport packet */
150 #define RM_SERVICE_ERROR_TRANSPORT_PKT_BUF_TOO_SMALL (RM_SERVICE_ERROR_BASE-6)
151 /** RM service request needs to be forwarded but the transport returned an error
152  *  when trying to send the RM packet to the higher level agent */
153 #define RM_SERVICE_ERROR_TRANPSPORT_SEND_ERROR (RM_SERVICE_ERROR_BASE-7)
154 /** RM service response from higher level agent did not match any requests made
155  *  by the provided RM instance */
156 #define RM_SERVICE_ERROR_TRANSACTION_DOES_NOT_EXIST_FOR_THIS_RM_INSTANCE (RM_SERVICE_ERROR_BASE-8)
157 /** RM failed to allocate memory for new service transaction */
158 #define RM_SERVICE_ERROR_TRANSACTION_FAILED_TO_ALLOCATE (RM_SERVICE_ERROR_BASE-9)
159 /** RM could not find the service transaction in the RM instance's transaction queue */
160 #define RM_SERVICE_ERROR_SERVICE_TRANSACTION_DOES_NOT_EXIST (RM_SERVICE_ERROR_BASE-10)
161 /** A failure occurred within a registered transport's packet free API */
162 #define RM_SERVICE_ERROR_TRANSPORT_FREE_PKT_ERROR (RM_SERVICE_ERROR_BASE-11)
163 /** Invalid NameServer object modification on non-Server instance */
164 #define RM_SERVICE_ERROR_NAMESERVER_OBJECT_MOD_ON_INVALID_INSTANCE (RM_SERVICE_ERROR_BASE-12)
165 /** Request failed because both a NameServer name and a resource range were specified */
166 #define RM_SERVICE_ERROR_NAMESERVER_NAME_AND_RESOURCE_RANGE_BOTH_DEFINED (RM_SERVICE_ERROR_BASE-13)
167 /** Error occurred when trying to add an object to the NameServer */
168 #define RM_SERVICE_ERROR_NAMESERVER_OBJECT_ADD_FAILED (RM_SERVICE_ERROR_BASE-14)
169 /** Could not find the object specified in the service request in the NameServer */
170 #define RM_SERVICE_ERROR_NAMESERVER_ERROR_NAME_DOES_NOT_EXIST (RM_SERVICE_ERROR_BASE-15)
172 /**
173  * @brief Maximum number of characters in the resource names
174  */
175 #define RM_RESOURCE_NAME_MAX_CHARS (36)
177 /** 
178  * @brief RM service types
179  */
180 typedef enum {
181     /** RM resource allocate for initialization service */
182     Rm_service_RESOURCE_ALLOCATE_INIT = 0,
183     /** RM resource allocate for use service */
184     Rm_service_RESOURCE_ALLOCATE_USE,
185     /** RM resource free service */
186     Rm_service_RESOURCE_FREE,
187     /** RM resource mapping to name service */
188     Rm_service_RESOURCE_MAP_TO_NAME,
189     /** RM resource get by name service */
190     Rm_service_RESOURCE_GET_BY_NAME,
191     /** RM resource name unmapping service */
192     Rm_service_RESOURCE_UNMAP_NAME
193 } Rm_ServiceType;
195 /** 
196  * @brief RM pre-main allocation request information provided by the pre-main 
197  *        startup function requesting the resource */
198 typedef struct {
199     /** Pointer to the requested pre-main allocation resource name.  The 
200      *  name provided by the component must match the resource names
201      *  provided in the global resource table and allocation policies */
202     char *resourceName;
203     /** The pre-main allocation request resource base value.  For example, 
204      *  queue number or semaphore number */
205     uint32_t resourceBase;
206     /** Range of resource starting at resourceBase */
207     uint32_t resourceRange;
208 } Rm_PreMainAllocInfo;
210 /** 
211  * @brief RM service response information provided by RM back to the 
212  *        requesting component
213  */
214 typedef struct {
215     /** State of the service request.
216      *  Non-negative result: RM has taken an action based on the request
217      *  Negative result: RM has encountered an error handling the request */
218     int32_t serviceState;
219     /** A service ID will be returned to the component if the requested service cannot
220      *  be completed immediately.  The service ID can be used by the component to identify
221      *  service responses received via the component callback function.  A service ID will not
222      *  be returned if the service request is satisfied immediately */
223     uint32_t serviceId;
224     /** The name of the resource affected by the service request */
225     char resourceName[RM_RESOURCE_NAME_MAX_CHARS];
226     /** The base value of the returned resource.  In the case of a block resource allocation 
227      *  response this field will contain the base value of the block. */
228     int32_t resourceBase;
229     /** The number of resources starting from resourceBase allocated in block requests */
230     uint32_t resourceLength;
231 } Rm_ServiceRespInfo;
233 /** 
234  * @brief RM service callback function structure
235  */
236 typedef struct {
237     /** Component callback function.  RM will call this function when the 
238      *  resource service request is completed. The callback function supplied
239      *  for this parameter must match this function pointer prototype. */
240     void (*serviceCallback) (Rm_ServiceRespInfo *serviceResponse);
241 } Rm_ServiceCallback;
243 /** 
244  * @brief RM service request information provided by the requesting component
245  */
246 typedef struct {
247     /** The type of RM service requested */
248     Rm_ServiceType type;
249     /** Pointer to the name of the resource requested.  The 
250      *  name provided by the component must match the resource node names
251      *  provided in the global resource table and allocation policies */
252     char *resourceName;
253 /** An allocate service can be requested with an unspecified resource base. 
254  *  If this occurs the RM Client Delegate or Server will assign the next available
255  *  resource or set of resources based on the allocation type. */
256 #define RM_RESOURCE_BASE_UNSPECIFIED (-1)  
257     /** The resource base value. */
258     int32_t resourceBase;
259     /** The number of the specified resource to be allocated starting from 
260      *  resourceBase.  Will be greater than one only for block allocate
261      *  and free service requests. */
262     uint32_t resourceLength;
263 /** An allocate service can be requested with an unspecified resource alignment.
264  *  WARNING: Only applicapable if resourceBase is unspecified
265  *
266  *  If the alignment is unspecified the RM Client Delegate or Server will allocate
267  *  the resources from a default alignment as specified in the global policy. */
268 #define RM_RESOURCE_ALIGNMENT_UNSPECIFIED (-1)      
269     /** Resource alignment in block allocation requests */
270     int32_t resourceAlignment;
271     /** The name server name associated with the resource.  Used only for 
272      *  allocate and free by name service requests */
273     char *resourceNsName;
274     /** Component specified callback function used by RM to inform components
275      *  of service requst results */
276     Rm_ServiceCallback callback;
277 } Rm_ServiceReqInfo;
279 /** 
280  * @brief RM Service Port provided to software components and applications that 
281  *        request RM services for the resources they wish to use
282  */
283 typedef struct {
284     /** RM instance handle for which the service handle was registered */
285     void *rmHandle;
286     /**
287      *  @b Description
288      *  @n  
289      *      Callout function used by components to request a resource service 
290      *      from a RM instance
291      *
292      *   @param[in] rmHandle
293      *      RM instance handle specifying the RM instance that should handle the
294      *      service request
295      *  
296      *  @param[in]  serviceRequest
297      *      Service request structure that provides details of the service requested from
298      *      the RM instance tied to this component
299      *
300      *  @param[in]  serviceResponse
301      *      Service response structure that provides details of RM's response to the
302      *      service request
303      */
304     void (*rmService)(void *rmHandle, Rm_ServiceReqInfo *serviceRequest,
305                       Rm_ServiceRespInfo *serviceResponse);
306 } Rm_ServicePort;
308 /**
309  *  @b Description
310  *  @n  
311  *      Non-blocking function used by RTSC pre-main startup functions to
312  *      allocate RM resources for usage.  Pre-main allocated resources will be 
313  *      validated by RM against a memory-mapped startup resource policy.
314  *      Pre-main allocation of unauthorized resources will result in a system
315  *      exception.
316  *
317  *      Note: Resource pre-main allocations can only occur on a core that is 
318  *            running a RM Server or Client Delegate that has a startup policy
319  *            allowing the allocation of pre-main resources
320  *
321  *  @param[in]  preMainAllocInfo
322  *      Resource pre-main allocation structure that provides details of the 
323  *      resource requested from RM for preallocation
324  *
325  *  @param[out] serviceResponse
326  *      Contains the result information regarding the pre-main allocation request
327  *
328  *  @retval
329  *      Success - 0 - Resource pre-main allocation request okay.
330  *  @retval
331  *      Failure - non-zero - Resource pre-main allocation request error.
332  */
333 void Rm_preMainAllocService (Rm_PreMainAllocInfo *preMainAllocInfo,
334                              Rm_ServiceRespInfo *serviceResponse);
336 /**
337  *  @b Description
338  *  @n  
339  *      This function returns a RM service port to the application to 
340  *      provide to software components (LLDs, BIOS, etc) that want to use RM
341  *      for resource management.
342  *
343  *  @param[in]  rmHandle
344  *      RM instance handle.  Used to return a Rm_ServicePort from an RM
345  *      instance.
346  *
347  *  @retval
348  *      Success - RM Service Port.  Used by an application or component to
349  *                request a service from RM.
350  *  @retval
351  *      Failure - NULL
352  */
353 Rm_ServicePort *Rm_getServicePort(Rm_Handle rmHandle);
355 /** 
356 @} 
357 */
359 #ifdef __cplusplus
361 #endif
363 #endif /* RMSERVICES_H_ */