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