e06bd20f2d7ae482c088f1eed20bf006a82cbcbf
1 /**
2 * @file rm_services.c
3 *
4 * @brief
5 * This is the Resource Manager services source.
6 *
7 * \par
8 * ============================================================================
9 * @n (C) Copyright 2012-2013, 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 /* Standard includes */
43 #include <string.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 ********************** Application visible APIs **********************
56 **********************************************************************/
58 /* FUNCTION PURPOSE: Handles application component service requests
59 ***********************************************************************
60 * DESCRIPTION: Receives service requests from application components
61 * and routes them to the transaction processor. If
62 * the service can be handled immediately the response
63 * will be provided in the service response. If the
64 * service requires a blocking operation the handler
65 * will provide a service ID back to the application.
66 * The response will be sent at a later time via the
67 * application supplied callback function.
68 */
69 void Rm_serviceHandler (void *rmHandle, Rm_ServiceReqInfo *serviceRequest,
70 Rm_ServiceRespInfo *serviceResponse)
71 {
72 Rm_Inst *rmInst = (Rm_Inst *)rmHandle;
73 Rm_Transaction *transaction;
75 if (rmInst->isLocked) {
76 serviceResponse->serviceState = RM_SERVICE_DENIED_RM_INSTANCE_LOCKED;
77 return;
78 }
80 if (serviceRequest->callback.serviceCallback == NULL) {
81 serviceResponse->serviceState = RM_ERROR_CALLBACK_NOT_PROVIDED;
82 return;
83 }
85 if (serviceRequest->type >= Rm_service_LAST) {
86 serviceResponse->serviceState = RM_ERROR_INVALID_SERVICE_TYPE;
87 return;
88 }
90 transaction = rmTransactionQueueAdd(rmInst);
91 if (transaction) {
92 transaction->type = serviceRequest->type;
93 strncpy(transaction->serviceSrcInstName, rmInst->instName, RM_NAME_MAX_CHARS);
94 transaction->callback.serviceCallback = serviceRequest->callback.serviceCallback;
95 transaction->state = RM_SERVICE_PROCESSING;
96 if (serviceRequest->resourceName) {
97 strncpy(transaction->resourceInfo.name, serviceRequest->resourceName, RM_NAME_MAX_CHARS);
98 }
99 transaction->resourceInfo.base = serviceRequest->resourceBase;
100 transaction->resourceInfo.length = serviceRequest->resourceLength;
101 transaction->resourceInfo.alignment = serviceRequest->resourceAlignment;
102 if (serviceRequest->resourceNsName) {
103 strncpy(transaction->resourceInfo.nameServerName, serviceRequest->resourceNsName, RM_NAME_MAX_CHARS);
104 }
106 rmTransactionProcessor (rmInst, transaction);
107 memset((void *)serviceResponse, 0, sizeof(Rm_ServiceRespInfo));
108 serviceResponse->serviceState = transaction->state;
109 if ((serviceResponse->serviceState == RM_SERVICE_PROCESSING) ||
110 (serviceResponse->serviceState == RM_SERVICE_APPROVED_STATIC)) {
111 /* Service still being processed. Static requests will have their validation responses sent once
112 * all transports have been established. Provide transaction ID back to component so it can sort
113 * service responses received via callback function */
114 serviceResponse->serviceId = transaction->localId;
115 }
117 if ((serviceResponse->serviceState == RM_SERVICE_APPROVED) ||
118 (serviceResponse->serviceState == RM_SERVICE_APPROVED_STATIC)) {
119 strncpy(serviceResponse->resourceName, transaction->resourceInfo.name, RM_NAME_MAX_CHARS);
120 serviceResponse->resourceBase = transaction->resourceInfo.base;
121 serviceResponse->resourceLength = transaction->resourceInfo.length;
122 }
124 /* Transactions still processing not deleted from queue. Includes static transactions which will be
125 * verified once all transports are up */
126 if ((serviceResponse->serviceState != RM_SERVICE_PROCESSING) &&
127 (serviceResponse->serviceState != RM_SERVICE_APPROVED_STATIC)) {
128 rmTransactionQueueDelete(rmInst, transaction->localId);
129 }
130 }
131 else {
132 serviceResponse->serviceState = RM_ERROR_SERVICE_TRANS_NOT_CREATED;
133 }
134 return;
135 }
137 /* FUNCTION PURPOSE: Opens the RM instance service handle
138 ***********************************************************************
139 * DESCRIPTION: Returns the service handle for an RM instance. Only
140 * one service handle can be opened per instance.
141 */
142 Rm_ServiceHandle *Rm_serviceOpenHandle(Rm_Handle rmHandle, int32_t *result)
143 {
144 Rm_Inst *rmInst = (Rm_Inst *)rmHandle;
145 Rm_ServiceHandle *newServiceHandle = NULL;
147 *result = RM_OK;
149 if (rmInst->serviceHandle == NULL) {
150 newServiceHandle = Rm_osalMalloc (sizeof(Rm_ServiceHandle));
151 if (newServiceHandle) {
152 newServiceHandle->rmHandle = rmHandle;
153 newServiceHandle->Rm_serviceHandler = Rm_serviceHandler;
154 rmInst->serviceHandle = newServiceHandle;
155 }
156 else {
157 *result = RM_ERROR_SERVICE_HANDLE_MEM_ALLOC_FAILED;
158 }
159 }
160 else {
161 *result = RM_ERROR_SERVICE_HANDLE_ALREADY_OPENED;
162 }
163 return (newServiceHandle);
164 }
166 /* FUNCTION PURPOSE: Closes the RM instance service handle
167 ***********************************************************************
168 * DESCRIPTION: Closes the service handle for an RM instance.
169 */
170 int32_t Rm_serviceCloseHandle(Rm_ServiceHandle *rmServiceHandle)
171 {
172 Rm_Inst *rmInst = (Rm_Inst *)rmServiceHandle->rmHandle;
173 int32_t retVal = RM_OK;
175 if (rmInst->serviceHandle) {
176 Rm_osalFree((void *)rmServiceHandle, sizeof(Rm_ServiceHandle));
177 rmInst->serviceHandle = NULL;
178 }
179 else {
180 retVal = RM_ERROR_SERVICE_HANDLE_ALREADY_CLOSED;
181 }
182 return(retVal);
183 }