| 1 | /* |
| 2 | Copyright (c) 2012-2014, Broadcom Europe Ltd |
| 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 | * Redistributions of source code must retain the above copyright |
| 8 | notice, this list of conditions and the following disclaimer. |
| 9 | * Redistributions in binary form must reproduce the above copyright |
| 10 | notice, this list of conditions and the following disclaimer in the |
| 11 | documentation and/or other materials provided with the distribution. |
| 12 | * Neither the name of the copyright holder nor the |
| 13 | names of its contributors may be used to endorse or promote products |
| 14 | derived from this software without specific prior written permission. |
| 15 | |
| 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY |
| 20 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 23 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
| 28 | // Contains global defs used by submodules within vchi |
| 29 | |
| 30 | #ifndef VCHI_COMMON_H_ |
| 31 | #define VCHI_COMMON_H_ |
| 32 | |
| 33 | |
| 34 | //flags used when sending messages (must be bitmapped) |
| 35 | typedef enum |
| 36 | { |
| 37 | VCHI_FLAGS_NONE = 0x0, |
| 38 | VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE = 0x1, // waits for message to be received, or sent (NB. not the same as being seen on other side) |
| 39 | VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE = 0x2, // run a callback when message sent |
| 40 | VCHI_FLAGS_BLOCK_UNTIL_QUEUED = 0x4, // return once the transfer is in a queue ready to go |
| 41 | VCHI_FLAGS_ALLOW_PARTIAL = 0x8, |
| 42 | VCHI_FLAGS_BLOCK_UNTIL_DATA_READ = 0x10, |
| 43 | VCHI_FLAGS_CALLBACK_WHEN_DATA_READ = 0x20, |
| 44 | |
| 45 | VCHI_FLAGS_ALIGN_SLOT = 0x000080, // internal use only |
| 46 | VCHI_FLAGS_BULK_AUX_QUEUED = 0x010000, // internal use only |
| 47 | VCHI_FLAGS_BULK_AUX_COMPLETE = 0x020000, // internal use only |
| 48 | VCHI_FLAGS_BULK_DATA_QUEUED = 0x040000, // internal use only |
| 49 | VCHI_FLAGS_BULK_DATA_COMPLETE = 0x080000, // internal use only |
| 50 | VCHI_FLAGS_INTERNAL = 0xFF0000 |
| 51 | } VCHI_FLAGS_T; |
| 52 | |
| 53 | // constants for vchi_crc_control() |
| 54 | typedef enum { |
| 55 | VCHI_CRC_NOTHING = -1, |
| 56 | VCHI_CRC_PER_SERVICE = 0, |
| 57 | VCHI_CRC_EVERYTHING = 1, |
| 58 | } VCHI_CRC_CONTROL_T; |
| 59 | |
| 60 | //callback reasons when an event occurs on a service |
| 61 | typedef enum |
| 62 | { |
| 63 | VCHI_CALLBACK_REASON_MIN, |
| 64 | |
| 65 | //This indicates that there is data available |
| 66 | //handle is the msg id that was transmitted with the data |
| 67 | // When a message is received and there was no FULL message available previously, send callback |
| 68 | // Tasks get kicked by the callback, reset their event and try and read from the fifo until it fails |
| 69 | VCHI_CALLBACK_MSG_AVAILABLE, |
| 70 | VCHI_CALLBACK_MSG_SENT, |
| 71 | VCHI_CALLBACK_MSG_SPACE_AVAILABLE, // XXX not yet implemented |
| 72 | |
| 73 | // This indicates that a transfer from the other side has completed |
| 74 | VCHI_CALLBACK_BULK_RECEIVED, |
| 75 | //This indicates that data queued up to be sent has now gone |
| 76 | //handle is the msg id that was used when sending the data |
| 77 | VCHI_CALLBACK_BULK_SENT, |
| 78 | VCHI_CALLBACK_BULK_RX_SPACE_AVAILABLE, // XXX not yet implemented |
| 79 | VCHI_CALLBACK_BULK_TX_SPACE_AVAILABLE, // XXX not yet implemented |
| 80 | |
| 81 | VCHI_CALLBACK_SERVICE_CLOSED, |
| 82 | |
| 83 | // this side has sent XOFF to peer due to lack of data consumption by service |
| 84 | // (suggests the service may need to take some recovery action if it has |
| 85 | // been deliberately holding off consuming data) |
| 86 | VCHI_CALLBACK_SENT_XOFF, |
| 87 | VCHI_CALLBACK_SENT_XON, |
| 88 | |
| 89 | // indicates that a bulk transfer has finished reading the source buffer |
| 90 | VCHI_CALLBACK_BULK_DATA_READ, |
| 91 | |
| 92 | // power notification events (currently host side only) |
| 93 | VCHI_CALLBACK_PEER_OFF, |
| 94 | VCHI_CALLBACK_PEER_SUSPENDED, |
| 95 | VCHI_CALLBACK_PEER_ON, |
| 96 | VCHI_CALLBACK_PEER_RESUMED, |
| 97 | VCHI_CALLBACK_FORCED_POWER_OFF, |
| 98 | |
| 99 | #ifdef USE_VCHIQ_ARM |
| 100 | // some extra notifications provided by vchiq_arm |
| 101 | VCHI_CALLBACK_SERVICE_OPENED, |
| 102 | VCHI_CALLBACK_BULK_RECEIVE_ABORTED, |
| 103 | VCHI_CALLBACK_BULK_TRANSMIT_ABORTED, |
| 104 | #endif |
| 105 | |
| 106 | VCHI_CALLBACK_REASON_MAX |
| 107 | } VCHI_CALLBACK_REASON_T; |
| 108 | |
| 109 | // service control options |
| 110 | typedef enum |
| 111 | { |
| 112 | VCHI_SERVICE_OPTION_MIN, |
| 113 | |
| 114 | VCHI_SERVICE_OPTION_TRACE, |
| 115 | VCHI_SERVICE_OPTION_SYNCHRONOUS, |
| 116 | |
| 117 | VCHI_SERVICE_OPTION_MAX |
| 118 | } VCHI_SERVICE_OPTION_T; |
| 119 | |
| 120 | //Callback used by all services / bulk transfers |
| 121 | typedef void (*VCHI_CALLBACK_T)( void *callback_param, //my service local param |
| 122 | VCHI_CALLBACK_REASON_T reason, |
| 123 | void *handle ); //for transmitting msg's only |
| 124 | |
| 125 | |
| 126 | |
| 127 | /* |
| 128 | * Define vector struct for scatter-gather (vector) operations |
| 129 | * Vectors can be nested - if a vector element has negative length, then |
| 130 | * the data pointer is treated as pointing to another vector array, with |
| 131 | * '-vec_len' elements. Thus to append a header onto an existing vector, |
| 132 | * you can do this: |
| 133 | * |
| 134 | * void foo(const VCHI_MSG_VECTOR_T *v, int n) |
| 135 | * { |
| 136 | * VCHI_MSG_VECTOR_T nv[2]; |
| 137 | * nv[0].vec_base = my_header; |
| 138 | * nv[0].vec_len = sizeof my_header; |
| 139 | * nv[1].vec_base = v; |
| 140 | * nv[1].vec_len = -n; |
| 141 | * ... |
| 142 | * |
| 143 | */ |
| 144 | typedef struct vchi_msg_vector { |
| 145 | const void *vec_base; |
| 146 | int32_t vec_len; |
| 147 | } VCHI_MSG_VECTOR_T; |
| 148 | |
| 149 | // Opaque type for a connection API |
| 150 | typedef struct opaque_vchi_connection_api_t VCHI_CONNECTION_API_T; |
| 151 | |
| 152 | // Opaque type for a message driver |
| 153 | typedef struct opaque_vchi_message_driver_t VCHI_MESSAGE_DRIVER_T; |
| 154 | |
| 155 | |
| 156 | // Iterator structure for reading ahead through received message queue. Allocated by client, |
| 157 | // initialised by vchi_msg_look_ahead. Fields are for internal VCHI use only. |
| 158 | // Iterates over messages in queue at the instant of the call to vchi_msg_lookahead - |
| 159 | // will not proceed to messages received since. Behaviour is undefined if an iterator |
| 160 | // is used again after messages for that service are removed/dequeued by any |
| 161 | // means other than vchi_msg_iter_... calls on the iterator itself. |
| 162 | typedef struct { |
| 163 | struct opaque_vchi_service_t *service; |
| 164 | void *last; |
| 165 | void *next; |
| 166 | void *remove; |
| 167 | } VCHI_MSG_ITER_T; |
| 168 | |
| 169 | |
| 170 | #endif // VCHI_COMMON_H_ |
| 171 | |