]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/rm-lld.git/blob - src/rm_services.c
Initial testing, basic demo complete
[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 that a callback function has been provided */
65     if (serviceRequest->callback.serviceCallback == NULL)
66     {
67         /* The RM Client and Client Delegate use blocking transports to consult with a 
68          * high-level RM agent prior to providing a response to the component.  It is 
69          * assumed the component's cannot block.  Therefore, all responses must go
70          * through the callback function provided by the component.  Return an error 
71          * if the component does not provide a callback function. */
72         serviceResponse->serviceState = RM_SERVICE_ERROR_CALLBACK_NOT_PROVIDED;
73         return;
74     }
75     
76     /* Create a new transaction */
77     transaction = Rm_transactionQueueAdd(rmInst);
79     if (transaction == NULL)
80     {
81         /* Failed to create a new transaction */
82         serviceResponse->serviceState = RM_SERVICE_ERROR_TRANSACTION_FAILED_TO_ALLOCATE;
83     }
84     else
85     {
86         /* Transfer request information into the transaction */
87         transaction->type = serviceRequest->type;
88         strcpy(transaction->serviceSrcInstName, rmInst->name);
89         transaction->callback.serviceCallback = serviceRequest->callback.serviceCallback;
90         transaction->state = RM_SERVICE_PROCESSING;
91         strcpy(&(transaction->resourceInfo.name)[0], serviceRequest->resourceName);
92         transaction->resourceInfo.base = serviceRequest->resourceBase;
93         transaction->resourceInfo.length = serviceRequest->resourceLength;
94         transaction->resourceInfo.alignment = serviceRequest->resourceAlignment;
95         strcpy(&(transaction->resourceInfo.nsName)[0], serviceRequest->resourceNsName);
97         /* Pass the new transaction to the transaction processor */
98         Rm_transactionProcessor (rmInst, transaction);
100         /* Provide response to the component that requested the service */
101         serviceResponse->serviceState = transaction->state;
102         if (serviceResponse->serviceState == RM_SERVICE_PROCESSING)
103         {
104             /* The service is still being processed.  Provide the transaction ID
105              * back to the component so that it can sort service responses received
106              * via the provided callback function */
107             serviceResponse->serviceId = transaction->localId;
108         }
109         else if (serviceResponse->serviceState == RM_SERVICE_APPROVED_AND_COMPLETED)
110         {
111             /* Service was approved and service was an allocate request the resource
112              * data is passed back to the component */
113             if ((transaction->type == Rm_service_RESOURCE_ALLOCATE) ||
114                 (transaction->type == Rm_service_RESOURCE_GET_BY_NAME))
115             {
116                 strcpy(serviceResponse->resourceName, transaction->resourceInfo.name);
117                 serviceResponse->resourceBase = transaction->resourceInfo.base;
118                 serviceResponse->resourceLength = transaction->resourceInfo.length;
119             }
121             /* Delete the transaction since a response was received immediately */
122             Rm_transactionQueueDelete(rmInst, transaction->localId);
123         }
124         else
125         {
126             /* The serviceState field will contain information regarding why the 
127              * service was denied or what error the service encountered.  Just delete
128              * the transaction since a response was received immediately */
129             Rm_transactionQueueDelete(rmInst, transaction->localId);
130         }
131     }
133     return;
136 /* This function is executed when a RM instance receives a response to one of its requests
137  * and the information in the request must be provided to the original requesting component */
138 void Rm_serviceResponder (Rm_Inst *rmInst, Rm_Transaction *transaction)
140     Rm_ServiceRespInfo serviceResponse;
142     /* The responseTransaction will contain the resultant state details of
143      * the requestTransaction's service request */
144     serviceResponse.serviceState = transaction->state;
145     /* Pass back the ID that was provided to the component when it requested
146      * the service */
147     serviceResponse.serviceId = transaction->localId;
149     /* Service was approved and service was an allocate request.  The resource
150      * data is passed back to the component */
151     if ((serviceResponse.serviceState == RM_SERVICE_APPROVED_AND_COMPLETED) &&
152         ((transaction->type == Rm_service_RESOURCE_ALLOCATE) ||
153          (transaction->type == Rm_service_RESOURCE_GET_BY_NAME)))
154     {
155         strcpy(serviceResponse.resourceName, transaction->resourceInfo.name);
156         serviceResponse.resourceBase = transaction->resourceInfo.base;
157         serviceResponse.resourceLength = transaction->resourceInfo.length;
158     }
160     /* Issue the callback to the requesting component with the response information */
161     transaction->callback.serviceCallback(&serviceResponse);
163     /* Delete the transaction from the transaction queue */
164     Rm_transactionQueueDelete(rmInst, transaction->localId);
165     return;
168 /**********************************************************************
169  ********************** Application visible APIs **********************
170  **********************************************************************/
172 void Rm_preMainAllocService(Rm_PreMainAllocInfo *preMainAllocInfo,
173                             Rm_ServiceRespInfo *serviceResponse)
178 Rm_ServicePort *Rm_getServicePort(Rm_Handle rmHandle)
180     Rm_ServicePort *newServicePort = NULL;
181     
182     /* Create a new service handle for the specified RM instance */
183     
184     /* Get memory for a new service port from local memory */
185     newServicePort = Rm_osalMalloc (sizeof(Rm_ServicePort));
187     /* Return NULL immediately if malloc returned NULL */
188     if (newServicePort == NULL)
189     {
190         return (newServicePort);
191     }
193     newServicePort->rmHandle = rmHandle;
194     newServicePort->rmService = Rm_serviceHandler;
196     return (newServicePort);
199 /**
200 @}
201 */