]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/rm-lld.git/blob - src/rm_services.c
bbecd4dfc0c556087f2c2ad0f9c92e80131ca9cb
[keystone-rtos/rm-lld.git] / src / rm_services.c
1 /**
2  *   @file  rmservices.c
3  *
4  *   @brief   
5  *      This is the Resource Manager services source.
6  *
7  *  \par
8  *  ============================================================================
9  *  @n   (C) Copyright 2012, Texas Instruments, Inc.
10  * 
11  *  Redistribution and use in source and binary forms, with or without 
12  *  modification, are permitted provided that the following conditions 
13  *  are met:
14  *
15  *    Redistributions of source code must retain the above copyright 
16  *    notice, this list of conditions and the following disclaimer.
17  *
18  *    Redistributions in binary form must reproduce the above copyright
19  *    notice, this list of conditions and the following disclaimer in the 
20  *    documentation and/or other materials provided with the   
21  *    distribution.
22  *
23  *    Neither the name of Texas Instruments Incorporated nor the names of
24  *    its contributors may be used to endorse or promote products derived
25  *    from this software without specific prior written permission.
26  *
27  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
28  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
29  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
31  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
32  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
33  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
36  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
37  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38  *
39  *  \par
40 */
42 /* RM Types */
43 #include <ti/drv/rm/rm_types.h>
45 /* RM external API includes */
46 #include <ti/drv/rm/rm_services.h>
48 /* RM internal API includes */
49 #include <ti/drv/rm/include/rm_loc.h>
51 /* RM OSAL layer */
52 #include <rm_osal.h>
54 /**********************************************************************
55  ********************** Internal Functions ****************************
56  **********************************************************************/
58 void Rm_serviceHandler (void *rmHandle, Rm_ServiceReqInfo *serviceRequest,
59                         Rm_ServiceRespInfo *serviceResponse)
60 {
61     Rm_Inst *rmInst = (Rm_Inst *)rmHandle;
62     Rm_Transaction *transaction;
64     /* Make sure serviceType is valid and that a callback function has been provided */
65     if ((serviceRequest->type < Rm_service_FIRST) || 
66         (serviceRequest->type > Rm_service_LAST))
67     {
68         serviceResponse->serviceState = RM_SERVICE_ERROR_INVALID_SERVICE_TYPE;
69         return;
70     }
71     else if (serviceRequest->callback.serviceCallback == NULL)
72     {
73         /* The RM Client and Client Delegate use blocking transports to consult with a 
74          * high-level RM agent prior to providing a response to the component.  It is 
75          * assumed the component's cannot block.  Therefore, all responses must go
76          * through the callback function provided by the component.  Return an error 
77          * if the component does not provide a callback function. */
78         serviceResponse->serviceState = RM_SERVICE_ERROR_CALLBACK_NOT_PROVIDED;
79         return;
80     }
81     
82     /* Create a new transaction */
83     transaction = Rm_transactionQueueAdd(rmInst);
85     if (transaction == NULL)
86     {
87         /* Failed to create a new transaction */
88         serviceResponse->serviceState = RM_SERVICE_ERROR_TRANSACTION_FAILED_TO_ALLOCATE;
89     }
90     else
91     {
92         /* Transfer request information into the transaction */
93         transaction->type = serviceRequest->type;
94         strcpy(transaction->sourceInstName, rmInst->name);
95         transaction->callback.serviceCallback = serviceRequest->callback.serviceCallback;
96         transaction->state = RM_SERVICE_PROCESSING;
97         strcpy(&(transaction->resourceInfo.name)[0], serviceRequest->resourceName);
98         transaction->resourceInfo.base = serviceRequest->resourceBase;
99         transaction->resourceInfo.length = serviceRequest->resourceLength;
100         transaction->resourceInfo.alignment = serviceRequest->resourceAlignment;
101         strcpy(&(transaction->resourceInfo.nsName)[0], serviceRequest->resourceNsName);
103         /* Pass the new transaction to the transaction processor */
104         Rm_transactionProcessor (rmInst, transaction);
106         /* Provide response to the component that requested the service */
107         serviceResponse->serviceState = transaction->state;
108         if (serviceResponse->serviceState == RM_SERVICE_PROCESSING)
109         {
110             /* The service is still being processed.  Provide the transaction ID
111              * back to the component so that it can sort service responses received
112              * via the provided callback function */
113             serviceResponse->serviceId = transaction->localId;
114         }
115         else if (serviceResponse->serviceState == RM_SERVICE_APPROVED_AND_COMPLETED)
116         {
117             /* Service was approved and service was an allocate request the resource
118              * data is passed back to the component */
119             if ((transaction->type == Rm_service_RESOURCE_ALLOCATE) ||
120                 (transaction->type == Rm_service_RESOURCE_GET_BY_NAME))
121             {
122                 serviceResponse->resourceBase = transaction->resourceInfo.base;
123                 serviceResponse->resourceLength = transaction->resourceInfo.length;
124             }
126             /* Delete the transaction since a response was received immediately */
127             Rm_transactionQueueDelete(rmInst, transaction->localId);
128         }
129         else if ((serviceResponse->serviceState >= RM_SERVICE_DENIED_BEGIN) &&
130                  (serviceResponse->serviceState <= RM_SERVICE_DENIED_END))
131         {
132             /* The serviceState field will contain information regarding why the 
133              * service was denied.  Just delete the transaction since a response was
134              * received immediately */
135             Rm_transactionQueueDelete(rmInst, transaction->localId);
136         }
137     }
139     return;
142 /* This function is executed when a RM instance receives a response to one of its requests
143  * and the information in the request must be provided to the original requesting component */
144 void Rm_serviceResponder (Rm_Inst *rmInst, Rm_Transaction *transaction)
146     Rm_ServiceRespInfo serviceResponse;
148     /* The responseTransaction will contain the resultant state details of
149      * the requestTransaction's service request */
150     serviceResponse.serviceState = transaction->state;
151     /* Pass back the ID that was provided to the component when it requested
152      * the service */
153     serviceResponse.serviceId = transaction->localId;
155     /* Service was approved and service was an allocate request.  The resource
156      * data is passed back to the component */
157     if ((serviceResponse.serviceState == RM_SERVICE_APPROVED_AND_COMPLETED) &&
158         ((transaction->type == Rm_service_RESOURCE_ALLOCATE) ||
159          (transaction->type == Rm_service_RESOURCE_GET_BY_NAME)))
160     {
161         serviceResponse.resourceBase = transaction->resourceInfo.base;
162         serviceResponse.resourceLength = transaction->resourceInfo.length;
163     }
165     /* Issue the callback to the requesting component with the response information */
166     transaction->callback.serviceCallback(&serviceResponse);
168     /* Delete the transaction from the transaction queue */
169     Rm_transactionQueueDelete(rmInst, transaction->localId);
170     return;
173 /**********************************************************************
174  ********************** Application visible APIs **********************
175  **********************************************************************/
177 void Rm_preMainAllocService(Rm_PreMainAllocInfo *preMainAllocInfo,
178                             Rm_ServiceRespInfo *serviceResponse)
183 Rm_ServicePort *Rm_getServicePort(Rm_Handle rmHandle)
185     Rm_ServicePort *newServicePort = NULL;
186     
187     /* Create a new service handle for the specified RM instance */
188     
189     /* Get memory for a new service port from local memory */
190     newServicePort = Rm_osalMalloc (sizeof(Rm_ServicePort));
192     /* Return NULL immediately if malloc returned NULL */
193     if (newServicePort == NULL)
194     {
195         return (newServicePort);
196     }
198     newServicePort->rmHandle = rmHandle;
199     newServicePort->rmService = Rm_serviceHandler;
201     return (newServicePort);
204 /**
205 @}
206 */