1 /**
2 * @file rm_services.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-2013, 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 RM_SERVICES_H_
44 #define RM_SERVICES_H_
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
50 /* RM includes */
51 #include <ti/drv/rm/rm.h>
53 /**
54 @addtogroup RM_SERVICES_API
55 @{
56 */
58 /**
59 * @brief RM service types
60 */
61 typedef enum {
62 /** RM resource allocate for initialization service */
63 Rm_service_RESOURCE_ALLOCATE_INIT = 0,
64 /** RM resource allocate for use service */
65 Rm_service_RESOURCE_ALLOCATE_USE,
66 /** RM resource free service */
67 Rm_service_RESOURCE_FREE,
68 /** RM NameServer map resource to name service */
69 Rm_service_RESOURCE_MAP_TO_NAME,
70 /** RM NameServer get resource by name service */
71 Rm_service_RESOURCE_GET_BY_NAME,
72 /** RM NameServer unmap resource from name service */
73 Rm_service_RESOURCE_UNMAP_NAME,
74 /** DO NOT USE: Last type */
75 Rm_service_LAST
76 } Rm_ServiceType;
78 /**
79 * @brief RM service response information used by RM to provide service
80 * request results back to the application components
81 */
82 typedef struct {
83 /** RM instance handle from which the service request that spawned this
84 * result originated. Used by application to sort responses, received
85 * via callback function, from RM instances located on the same core. */
86 Rm_Handle rmHandle;
87 /** Service request state. The state can be an approval, denial, or error.
88 * The latter codes start at #RM_OK, #RM_SERVICE_DENIED_BASE, and
89 * #RM_ERROR_BASE, respectively. */
90 int32_t serviceState;
91 /** The service ID is returned to the application in order to match service
92 * responses received at a later time via the provided callback function
93 * because RM required a blocking operation in order to satisfy the
94 * resource request. <br> <br> The service ID will never have a value of
95 * zero. */
96 uint32_t serviceId;
97 /** Affected resource name */
98 char resourceName[RM_NAME_MAX_CHARS];
99 /** The resource base value allocated, freed, or mapped to NameServer name. */
100 int32_t resourceBase;
101 /** The resource length starting at base allocated, freed, or mapped to
102 * NameServer name. */
103 uint32_t resourceLength;
104 /** resourceNumOwners is not valid unless >= 0 */
105 #define RM_RESOURCE_NUM_OWNERS_INVALID (-1)
106 /** Current number of owners for the returned resource. A value greater
107 * than one means the resource is being shared. This value is only valid
108 * if the serviceState is RM_SERVICE_APPROVED or RM_SERVICE_APPROVED_STATIC. */
109 int32_t resourceNumOwners;
110 } Rm_ServiceRespInfo;
112 /**
113 * @brief RM service callback function
114 */
115 typedef struct {
116 /** Component callback function. RM calls this function when a blocking
117 * resource service request is complete. The callback function supplied
118 * for this parameter must match the function pointer prototype. */
119 void (*serviceCallback) (Rm_ServiceRespInfo *serviceResponse);
120 } Rm_ServiceCallback;
122 /**
123 * @brief RM service request information
124 */
125 typedef struct {
126 /** The type of service requested */
127 Rm_ServiceType type;
128 /** Pointer to an array containing the resource name affected by
129 * the request. The resource name must match a resource node name
130 * defined in the GRL and global/static policy. The request will be
131 * denied if the resource name does not match any resource node names
132 * in the policy */
133 const char *resourceName;
134 /** Informs RM to find the next available resource block of length
135 * resourceLength and alignment resourceAlignment for allocation. This
136 * parameter is only valid for resource allocate service types. */
137 #define RM_RESOURCE_BASE_UNSPECIFIED (-1)
138 /** The base value of the resource affected by the service request.
139 * #RM_RESOURCE_BASE_UNSPECIFIED can be substituted. */
140 int32_t resourceBase;
141 /** The resource length, starting from #resourceBase affected by the
142 * service request. */
143 uint32_t resourceLength;
144 /** Informs RM to find the next available resource block with length
145 * resourceLength and the alignment specified in
146 * a) The resource node in the policy if it has the "allocation-alignment"
147 * property defined.
148 * b) The default alignment of 1 if no alignment is specified in the policy
149 * for the resource.
150 * This value is only valid if resourceBase is set to #RM_RESOURCE_BASE_UNSPECIFIED */
151 #define RM_RESOURCE_ALIGNMENT_UNSPECIFIED (-1)
152 /** Alignment of the resource affected by the service request. Only valid
153 * if resourceBase is set to #RM_RESOURCE_BASE_UNSPECIFIED.
154 * #RM_RESOURCE_ALIGNMENT_UNSPECIFIED can be substituted. */
155 int32_t resourceAlignment;
156 /** The NameServer name associated, or to be associated, with a resource.
157 * If the service type is #Rm_service_RESOURCE_GET_BY_NAME and the
158 * #resourceBase and #resourceLength fields are not NULL a error will
159 * occur. */
160 const char *resourceNsName;
161 /** Callback function used by RM to provide responses back to application
162 * components after a service request resulted in a blocking operation.
163 * If no callback function is provided the RM instance will block until
164 * the service response is ready. */
165 Rm_ServiceCallback callback;
166 } Rm_ServiceReqInfo;
168 /**
169 * @brief RM service handle provided to application components for requesting
170 * services
171 */
172 typedef struct {
173 /** RM instance handle from which the service handle was allocated from. */
174 void *rmHandle;
175 /**
176 * @b Description
177 * @n
178 * Processes service requests from application components. Responses
179 * are returned immediately if the service request could be satisfied
180 * without blocking. If the service request requires a blocking operation,
181 * such as forwarding the service request to another instance for
182 * validation, the response will be received via the Rm_ServerCallback
183 *
184 * @param[in] rmHandle
185 * RM instance handle specifies the instance that handles the service
186 * request. The request's result, if policy checks are involved, will be
187 * based on the permissions assigned to the rmHandle's instance name within
188 * global/static policy.
189 *
190 * @param[in] serviceRequest
191 * Pointer to the service request structure
192 *
193 * @param[out] serviceResponse
194 * Pointer to a service response structure.
195 */
196 void (*Rm_serviceHandler)(void *rmHandle, const Rm_ServiceReqInfo *serviceRequest,
197 Rm_ServiceRespInfo *serviceResponse);
198 } Rm_ServiceHandle;
200 /**
201 * @b Description
202 * @n
203 * This function returns a RM service handle to the application to
204 * provide services to software components (LLDs, BIOS, etc) that want to use RM
205 * for resource management. Only one service handle can be opened from
206 * each RM instance.
207 *
208 * @param[in] rmHandle
209 * RM instance handle from which the service handle will be opened
210 *
211 * @param[out] result
212 * Pointer to a signed int used to return any errors encountered during
213 * the instance initialization process.
214 *
215 * @retval
216 * Success - Rm_ServiceHandle and result = #RM_OK
217 * @retval
218 * Failure - NULL Rm_ServiceHandle and result = #RM_ERROR_SERVICE_HANDLE_MEM_ALLOC_FAILED
219 * @retval
220 * Failure - NULL Rm_ServiceHandle and result = #RM_ERROR_SERVICE_HANDLE_ALREADY_OPENED
221 */
222 Rm_ServiceHandle *Rm_serviceOpenHandle(Rm_Handle rmHandle, int32_t *result);
224 /**
225 * @b Description
226 * @n
227 * This function closes a RM instance's service handle
228 *
229 * @param[in] rmServiceHandle
230 * RM instance service handle to be closed.
231 *
232 * @retval
233 * Success - #RM_OK
234 * @retval
235 * Failure - #RM_ERROR_SERVICE_HANDLE_ALREADY_CLOSED
236 */
237 int32_t Rm_serviceCloseHandle(Rm_ServiceHandle *rmServiceHandle);
239 /**
240 @}
241 */
243 #ifdef __cplusplus
244 }
245 #endif
247 #endif /* RM_SERVICES_H_ */