OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2010 NVIDIA Corporation. |
| 3 * All rights reserved. |
| 4 * |
| 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are met: |
| 7 * |
| 8 * Redistributions of source code must retain the above copyright notice, |
| 9 * this list of conditions and the following disclaimer. |
| 10 * |
| 11 * Redistributions in binary form must reproduce the above copyright notice, |
| 12 * this list of conditions and the following disclaimer in the documentation |
| 13 * and/or other materials provided with the distribution. |
| 14 * |
| 15 * Neither the name of the NVIDIA Corporation nor the names of its contributors |
| 16 * may be used to endorse or promote products derived from this software |
| 17 * without specific prior written permission. |
| 18 * |
| 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 29 * POSSIBILITY OF SUCH DAMAGE. |
| 30 * |
| 31 */ |
| 32 |
| 33 #ifndef INCLUDED_nvrm_transport_H |
| 34 #define INCLUDED_nvrm_transport_H |
| 35 |
| 36 |
| 37 #if defined(__cplusplus) |
| 38 extern "C" |
| 39 { |
| 40 #endif |
| 41 |
| 42 #include "nvrm_module.h" |
| 43 #include "nvrm_init.h" |
| 44 |
| 45 /** @file |
| 46 * @brief <b>NVIDIA Driver Development Kit: |
| 47 * Resource Manager Transport APIs</b> |
| 48 * |
| 49 * @b Description: This is the Transport API, which defines a simple means to |
| 50 * pass messages across a lower level connection (generally between |
| 51 * processors). |
| 52 * |
| 53 */ |
| 54 |
| 55 /** @defgroup nvrm_transport RM Transport API |
| 56 * |
| 57 * The Transport API defines a simple protocol through which clients and |
| 58 * services may connect and communicate--normally, though not necessarily, |
| 59 * across separate processors. Clients to this interface mostly include |
| 60 * audio-visual applications whose code may reside on either the MPCore or AVP |
| 61 * processors. These applications (and there could be many concurrently) may |
| 62 * utilize this transport API to synchronize their operations. How the |
| 63 * Transport API shepherds messages through these connections is not visible to |
| 64 * the client. |
| 65 * |
| 66 * To setup a new connection, both the client and the service must open a port |
| 67 * (whose name is agreed upon before compile-time). The service waits for a |
| 68 * client to connect; this "handshake" allows a connection to be established. |
| 69 * Once a client has established a connection with the service, they may send |
| 70 * and receive messages. |
| 71 * |
| 72 * @ingroup nvddk_rm |
| 73 * @{ |
| 74 */ |
| 75 |
| 76 #include "nvos.h" |
| 77 |
| 78 /** |
| 79 * A type-safe handle for the transport connection. |
| 80 */ |
| 81 |
| 82 typedef struct NvRmTransportRec *NvRmTransportHandle; |
| 83 |
| 84 /** |
| 85 * Creates one end of a transport connection. Both the service and client |
| 86 * to the service must call this API to create each endpoint of the connection |
| 87 * through a specified port (whose name is agreed upon before compile-time). |
| 88 * A connection is not established between the service and client until a |
| 89 * handshake is completed (via calls to NvRmTransportWaitForConnect() and |
| 90 * NvRmTransportConnect() respectively). |
| 91 * |
| 92 * Assert in debug mode encountered if PortName is too long or does not exist |
| 93 * |
| 94 * @see NvRmTransportWaitForConnect() |
| 95 * @see NvRmTransportConnect() |
| 96 * @see NvRmTransportClose() |
| 97 * |
| 98 * @param hRmDevice Handle to RM device |
| 99 * @param pPortName A character string that identifies the name of the port. |
| 100 * This value must be 16 bytes or less, otherwise the caller receives an error. |
| 101 * You can optionally pass NULL for this parameter, in which case a unique |
| 102 * name will be assigned. And you can call NvRmTransporGetPortName to retrieve |
| 103 * the name. |
| 104 * @param RecvMessageSemaphore The externally created semaphore that the |
| 105 * transport connection will signal upon receipt of a message. |
| 106 * @param phTransport Points to the location where the transport handle shall |
| 107 * be stored |
| 108 * |
| 109 * @retval NvSuccess Transport endpoint successfully allocated |
| 110 * @retval NvError_InsufficientMemory Not enough memory to allocate endpoint |
| 111 * @retval NvError_MutexCreateFailed Creaion of mutex failed. |
| 112 * @retval NvError_SemaphoreCreateFailed Creaion of semaphore failed. |
| 113 * @retval NvError_SharedMemAllocFailed Creaion of shared memory allocation |
| 114 * failed. |
| 115 * @retval NvError_NotInitialized The transport is not able to initialzed the |
| 116 * threads. |
| 117 */ |
| 118 |
| 119 NvError NvRmTransportOpen( |
| 120 NvRmDeviceHandle hRmDevice, |
| 121 char * pPortName, |
| 122 NvOsSemaphoreHandle RecvMessageSemaphore, |
| 123 NvRmTransportHandle * phTransport ); |
| 124 |
| 125 /** |
| 126 * Retrieve the name associated with a port. |
| 127 * |
| 128 * Assert in debug mode encountered if PortName is too long or does not exist |
| 129 * |
| 130 * @see NvRmTransportOpen() |
| 131 * |
| 132 * @param hTransport Handle to the port that you want the name of. |
| 133 * @param PortName A character string that identifies the name of the port. |
| 134 * @param PortNameSize Length of the PortName buffer. |
| 135 * |
| 136 */ |
| 137 |
| 138 void NvRmTransportGetPortName( |
| 139 NvRmTransportHandle hTransport, |
| 140 NvU8 * PortName, |
| 141 NvU32 PortNameSize ); |
| 142 |
| 143 /** |
| 144 * Closes a transport connection. Proper closure of this connection requires |
| 145 * that both the client and service call this API. Therefore, it is expected |
| 146 * that the client and service message one another to coordinate the close. |
| 147 * |
| 148 * @see NvRmTransportOpen() |
| 149 * |
| 150 * @param hTransport Specifies the transport connection to close. If hTransport |
| 151 * is NULL, this API does nothing. |
| 152 */ |
| 153 |
| 154 void NvRmTransportClose( |
| 155 NvRmTransportHandle hTransport ); |
| 156 |
| 157 /** |
| 158 * Initializes the transport. |
| 159 * |
| 160 * @param hRmDevice Handle to RM device |
| 161 * |
| 162 */ |
| 163 |
| 164 NvError NvRmTransportInit( |
| 165 NvRmDeviceHandle hRmDevice ); |
| 166 |
| 167 /** |
| 168 * Deinitializes the transport. |
| 169 * |
| 170 * @param hRmDevice Handle to RM device |
| 171 * |
| 172 */ |
| 173 |
| 174 void NvRmTransportDeInit( |
| 175 NvRmDeviceHandle hRmDevice ); |
| 176 |
| 177 /** |
| 178 * This handshake API is called by the service, which waits for a client to |
| 179 * establish a connection via a call to NvRmTransportConnect(). Messages |
| 180 * cannot be sent and received until this handshake is completed. |
| 181 * |
| 182 * To ensure a client has sufficient opportunity to establish a connection |
| 183 * from the other end, a large timeout value (such as NV_WAIT_INFINITE) is |
| 184 * recommended here. |
| 185 * |
| 186 * @see NvRmTransportConnect() |
| 187 * |
| 188 * @param hTransport Specifies the transport connection |
| 189 * @param TimeoutMS Specifies the amount of time (in milliseconds) to wait for |
| 190 * connection to be established. A value of NV_WAIT_INFINITE means "wait |
| 191 * indefinitely." A value of zero (0) will timeout immediately, which is |
| 192 * not recommended for this function call. |
| 193 * |
| 194 * @retval NvSuccess Service is waiting to receive a "connect" from client |
| 195 * @retval NvError_NotInitialized hTransport is not open |
| 196 * @retval NvError_Timeout Timed out waiting for service to respond |
| 197 */ |
| 198 |
| 199 NvError NvRmTransportWaitForConnect( |
| 200 NvRmTransportHandle hTransport, |
| 201 NvU32 TimeoutMS ); |
| 202 |
| 203 /** |
| 204 * This blocking handshake API is called by the client, which seeks a |
| 205 * service (as specified by a handle) to establish a connection. Messages |
| 206 * cannot be sent and received until this handshake is completed. |
| 207 * |
| 208 * @see NvRmTransportWaitForConnect() |
| 209 * |
| 210 * @param hTransport Specifies the transport connection |
| 211 * @param TimeoutMS Specifies the amount of time (in milliseconds) to wait for |
| 212 * connection to be established. A value of NV_WAIT_INFINITE means "wait |
| 213 * indefinitely." A value of zero (0) will timeout immediately, but |
| 214 * this function will at least take time to check if the port is open and |
| 215 * waiting for a connection--if so, a connection will be established. |
| 216 * |
| 217 * @retval NvSuccess Transport connection successfully established |
| 218 * @retval NvError_NotInitialized hTransport is not open |
| 219 * @retval NvError_Timeout Timed out waiting for service to respond. |
| 220 */ |
| 221 |
| 222 NvError NvRmTransportConnect( |
| 223 NvRmTransportHandle hTransport, |
| 224 NvU32 TimeoutMS ); |
| 225 |
| 226 /** |
| 227 * Set the max size of the message queue (FIFO) deptha nd length which can be |
| 228 * send and receive from this port. The programmer must decide the |
| 229 * queue depth that's appropriate for their design. If this function is not |
| 230 * called, the queue depth is set to one (1) and message size is 256 bytes. |
| 231 * |
| 232 * |
| 233 * @see NvRmTransportSendMsg() |
| 234 * @see NvRmTransportRecvMsg() |
| 235 * |
| 236 * @param hTransport Specifies the transport connection |
| 237 * @param MaxQueueDepth The maximum number of message which can be queued for |
| 238 * this port for receiving and sending. The receive message can queue message |
| 239 * till this count for this port. If receive queue is full for this port and |
| 240 * if other port send the message to this port then receive queue error status |
| 241 * will turn as overrun and ignore the incoming message. |
| 242 * If send message queue is full and client request to send message then he |
| 243 * will wait for time provided by the parameter. |
| 244 * @param MaxMessageSize Specifies the maximum size of the message in bytes |
| 245 * which client can receive and transmit through this port. |
| 246 * |
| 247 * @retval NvSuccess New queue depth is set |
| 248 * @retval NvError_NotInitialized hTransport is not open. |
| 249 * @retval NvError_BadValue The parameter passed is not correct. There is |
| 250 * limitation for maximum message q and message length from the driver and if |
| 251 * this parameter is larger than those value then it returns this error. |
| 252 * |
| 253 */ |
| 254 |
| 255 NvError NvRmTransportSetQueueDepth( |
| 256 NvRmTransportHandle hTransport, |
| 257 NvU32 MaxQueueDepth, |
| 258 NvU32 MaxMessageSize ); |
| 259 |
| 260 /** |
| 261 * Sends a message to the other port which is connected to this port. |
| 262 * This will use the copy method to copy the client buffer message to |
| 263 * transport message buffer. This function queue the message to the transmit |
| 264 * queue. the data will be send later based on the physical transfer channel |
| 265 * availablity. |
| 266 * |
| 267 * @see NvRmTransportOpen() |
| 268 * @see NvRmTransportSetQueueDepth() |
| 269 * @see NvRmTransportRecvMsg() |
| 270 * |
| 271 * @param hTransport Specifies the transport connection |
| 272 * @param pMessageBuffer The pointer to the message buffer where message which |
| 273 * need to be send is available. |
| 274 * @param MessageSize Specifies the size of the message. |
| 275 * @param TimeoutMS Specifies the amount of time (in milliseconds) to wait for |
| 276 * sent message to be queued for the transfer. If the transmit queue if full |
| 277 * then this function will block the client till maximum of timeout to queue |
| 278 * this message. If meesage queue is available before timeout then it will |
| 279 * queue the message and comeout. If message queue is full and timeout happen |
| 280 * the it will return the timeout error. |
| 281 * if zero timeout is selecetd and the message queue is full then it will be |
| 282 * return NvError_TransportMessageBoxFull error. |
| 283 * Avalue of NV_WAIT_INFINITE means "wait indefinitely" for queueing the |
| 284 * message. |
| 285 * |
| 286 * @retval NvSuccess Message is queued successfully. |
| 287 * @retval NvError_NotInitialized hTransport is not open. |
| 288 * @retval NvError_BadValue The parameter passed is not valid. |
| 289 * @retval NvError_InvalidState The port is not connected to the other port and |
| 290 * it is not ready for sending the message. |
| 291 * @retval NvError_Timeout Timed out waiting for message to be queue if send |
| 292 * message queue. |
| 293 * @retval NvError_TransportMessageBoxFull Message box is full and it is not |
| 294 * able to queue the message. |
| 295 */ |
| 296 |
| 297 NvError NvRmTransportSendMsg( |
| 298 NvRmTransportHandle hTransport, |
| 299 void* pMessageBuffer, |
| 300 NvU32 MessageSize, |
| 301 NvU32 TimeoutMS ); |
| 302 |
| 303 /** |
| 304 * Sends a message to the other port which is connected to this port. |
| 305 * This function is to be used ONLY when we're about to enter LP0! |
| 306 * There is no synchronization in this function as only one person |
| 307 * should be talking to the AVP at the time of LP0. The message is sent |
| 308 * on the RPC_AVP_PORT. In the future, there might be instances where |
| 309 * we need to talk on a different port in LP0. |
| 310 * |
| 311 * @retval NvSuccess Message is queued successfully. |
| 312 * @retval NvError_TransportMessageBoxFull Message box is full and it is not |
| 313 * able to queue the message. |
| 314 */ |
| 315 |
| 316 NvError NvRmTransportSendMsgInLP0( |
| 317 NvRmTransportHandle hPort, |
| 318 void* message, |
| 319 NvU32 MessageSize ); |
| 320 |
| 321 /** |
| 322 * Receive the message from the port. This will read the message if it is |
| 323 * available for this port otherwise it will return the |
| 324 * NvError_TransportMessageBoxEmpty error. |
| 325 * |
| 326 * @see NvRmTransportOpen() |
| 327 * @see NvRmTransportSetQueueDepth() |
| 328 * @see NvRmTransportSendMsg() |
| 329 * |
| 330 * @param hTransport Specifies the transport connection |
| 331 * @param pMessageBuffer The pointer to the receive message buffer where the |
| 332 * received message will be copied. |
| 333 * @param MaxSize The maximum size in bytes that may be copied to the buffer |
| 334 * @param pMessageSize Pointer to the variable where the length of the message |
| 335 * will be stored. |
| 336 * |
| 337 * @retval NvSuccess Message received successfully. |
| 338 * @retval NvError_NotInitialized hTransport is not open. |
| 339 * @retval NvError_InvalidState The port is not connection state. |
| 340 * @retval NvError_TransportMessageBoxEmpty The message box empty and not able |
| 341 * to receive the message. |
| 342 * @retval NvError_TransportIncompleteMessage The received message for this |
| 343 * port is longer than the configured message length for this port. It copied |
| 344 * the maximm size of the configured length of the message for this port and |
| 345 * return the incomplete message buffer. |
| 346 * @retval NvError_TransportMessageOverflow The port receives the message more |
| 347 * than the configured queue depth count for this port and hence message |
| 348 * overflow has been ocuured. |
| 349 */ |
| 350 |
| 351 NvError NvRmTransportRecvMsg( |
| 352 NvRmTransportHandle hTransport, |
| 353 void* pMessageBuffer, |
| 354 NvU32 MaxSize, |
| 355 NvU32 * pMessageSize ); |
| 356 |
| 357 #if defined(__cplusplus) |
| 358 } |
| 359 #endif |
| 360 |
| 361 #endif |
OLD | NEW |