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-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 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 if (rmInst->isLocked) {
65 serviceResponse->serviceState = RM_SERVICE_DENIED_RM_INSTANCE_LOCKED;
66 return;
67 }
69 if (serviceRequest->callback.serviceCallback == NULL) {
70 serviceResponse->serviceState = RM_ERROR_CALLBACK_NOT_PROVIDED;
71 return;
72 }
74 if (serviceRequest->type >= Rm_service_LAST) {
75 serviceResponse->serviceState = RM_ERROR_INVALID_SERVICE_TYPE;
76 return;
77 }
79 transaction = rmTransactionQueueAdd(rmInst);
80 if (transaction) {
81 transaction->type = serviceRequest->type;
82 strncpy(transaction->serviceSrcInstName, rmInst->instName, RM_NAME_MAX_CHARS);
83 transaction->callback.serviceCallback = serviceRequest->callback.serviceCallback;
84 transaction->state = RM_SERVICE_PROCESSING;
85 if (serviceRequest->resourceName) {
86 strncpy(transaction->resourceInfo.name, serviceRequest->resourceName, RM_NAME_MAX_CHARS);
87 }
88 transaction->resourceInfo.base = serviceRequest->resourceBase;
89 transaction->resourceInfo.length = serviceRequest->resourceLength;
90 transaction->resourceInfo.alignment = serviceRequest->resourceAlignment;
91 if (serviceRequest->resourceNsName) {
92 strncpy(transaction->resourceInfo.nameServerName, serviceRequest->resourceNsName, RM_NAME_MAX_CHARS);
93 }
95 rmTransactionProcessor (rmInst, transaction);
96 memset((void *)serviceResponse, 0, sizeof(Rm_ServiceRespInfo));
97 serviceResponse->serviceState = transaction->state;
98 if ((serviceResponse->serviceState == RM_SERVICE_PROCESSING) ||
99 (serviceResponse->serviceState == RM_SERVICE_APPROVED_STATIC)) {
100 /* Service still being processed. Static requests will have their validation responses sent once
101 * all transports have been established. Provide transaction ID back to component so it can sort
102 * service responses received via callback function */
103 serviceResponse->serviceId = transaction->localId;
104 }
106 if ((serviceResponse->serviceState == RM_SERVICE_APPROVED) ||
107 (serviceResponse->serviceState == RM_SERVICE_APPROVED_STATIC)) {
108 strncpy(serviceResponse->resourceName, transaction->resourceInfo.name, RM_NAME_MAX_CHARS);
109 serviceResponse->resourceBase = transaction->resourceInfo.base;
110 serviceResponse->resourceLength = transaction->resourceInfo.length;
111 }
113 /* Transactions still processing not deleted from queue. Includes static transactions which will be
114 * verified once all transports are up */
115 if ((serviceResponse->serviceState != RM_SERVICE_PROCESSING) &&
116 (serviceResponse->serviceState != RM_SERVICE_APPROVED_STATIC)) {
117 rmTransactionQueueDelete(rmInst, transaction->localId);
118 }
119 }
120 else {
121 serviceResponse->serviceState = RM_ERROR_SERVICE_TRANS_NOT_CREATED;
122 }
123 return;
124 }
126 Rm_ServiceHandle *Rm_serviceOpenHandle(Rm_Handle rmHandle, int32_t *result)
127 {
128 Rm_Inst *rmInst = (Rm_Inst *)rmHandle;
129 Rm_ServiceHandle *newServiceHandle = NULL;
131 *result = RM_OK;
133 if (rmInst->serviceHandle == NULL) {
134 newServiceHandle = Rm_osalMalloc (sizeof(Rm_ServiceHandle));
135 if (newServiceHandle) {
136 newServiceHandle->rmHandle = rmHandle;
137 newServiceHandle->Rm_serviceHandler = Rm_serviceHandler;
138 rmInst->serviceHandle = newServiceHandle;
139 }
140 else {
141 *result = RM_ERROR_SERVICE_HANDLE_MEM_ALLOC_FAILED;
142 }
143 }
144 else {
145 *result = RM_ERROR_SERVICE_HANDLE_ALREADY_OPENED;
146 }
147 return (newServiceHandle);
148 }
150 int32_t Rm_serviceCloseHandle(Rm_ServiceHandle *rmServiceHandle)
151 {
152 Rm_Inst *rmInst = (Rm_Inst *)rmServiceHandle->rmHandle;
153 int32_t retVal = RM_OK;
155 if (rmInst->serviceHandle) {
156 Rm_osalFree((void *)rmServiceHandle, sizeof(Rm_ServiceHandle));
157 rmInst->serviceHandle = NULL;
158 }
159 else {
160 retVal = RM_ERROR_SERVICE_HANDLE_ALREADY_CLOSED;
161 }
162 return(retVal);
163 }