1278277Sgonzo/** 2278277Sgonzo * Copyright (c) 2010-2012 Broadcom. All rights reserved. 3278277Sgonzo * 4278277Sgonzo * Redistribution and use in source and binary forms, with or without 5278277Sgonzo * modification, are permitted provided that the following conditions 6278277Sgonzo * are met: 7278277Sgonzo * 1. Redistributions of source code must retain the above copyright 8278277Sgonzo * notice, this list of conditions, and the following disclaimer, 9278277Sgonzo * without modification. 10278277Sgonzo * 2. Redistributions in binary form must reproduce the above copyright 11278277Sgonzo * notice, this list of conditions and the following disclaimer in the 12278277Sgonzo * documentation and/or other materials provided with the distribution. 13278277Sgonzo * 3. The names of the above-listed copyright holders may not be used 14278277Sgonzo * to endorse or promote products derived from this software without 15278277Sgonzo * specific prior written permission. 16278277Sgonzo * 17278277Sgonzo * ALTERNATIVELY, this software may be distributed under the terms of the 18278277Sgonzo * GNU General Public License ("GPL") version 2, as published by the Free 19278277Sgonzo * Software Foundation. 20278277Sgonzo * 21278277Sgonzo * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 22278277Sgonzo * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 23278277Sgonzo * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 24278277Sgonzo * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 25278277Sgonzo * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26278277Sgonzo * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27278277Sgonzo * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 28278277Sgonzo * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 29278277Sgonzo * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30278277Sgonzo * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31278277Sgonzo * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32278277Sgonzo */ 33278277Sgonzo 34278277Sgonzo#ifndef VCHI_COMMON_H_ 35278277Sgonzo#define VCHI_COMMON_H_ 36278277Sgonzo 37278277Sgonzo 38278277Sgonzo//flags used when sending messages (must be bitmapped) 39278277Sgonzotypedef enum 40278277Sgonzo{ 41278277Sgonzo VCHI_FLAGS_NONE = 0x0, 42278277Sgonzo 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) 43278277Sgonzo VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE = 0x2, // run a callback when message sent 44278277Sgonzo VCHI_FLAGS_BLOCK_UNTIL_QUEUED = 0x4, // return once the transfer is in a queue ready to go 45278277Sgonzo VCHI_FLAGS_ALLOW_PARTIAL = 0x8, 46278277Sgonzo VCHI_FLAGS_BLOCK_UNTIL_DATA_READ = 0x10, 47278277Sgonzo VCHI_FLAGS_CALLBACK_WHEN_DATA_READ = 0x20, 48278277Sgonzo 49278277Sgonzo VCHI_FLAGS_ALIGN_SLOT = 0x000080, // internal use only 50278277Sgonzo VCHI_FLAGS_BULK_AUX_QUEUED = 0x010000, // internal use only 51278277Sgonzo VCHI_FLAGS_BULK_AUX_COMPLETE = 0x020000, // internal use only 52278277Sgonzo VCHI_FLAGS_BULK_DATA_QUEUED = 0x040000, // internal use only 53278277Sgonzo VCHI_FLAGS_BULK_DATA_COMPLETE = 0x080000, // internal use only 54278277Sgonzo VCHI_FLAGS_INTERNAL = 0xFF0000 55278277Sgonzo} VCHI_FLAGS_T; 56278277Sgonzo 57278277Sgonzo// constants for vchi_crc_control() 58278277Sgonzotypedef enum { 59278277Sgonzo VCHI_CRC_NOTHING = -1, 60278277Sgonzo VCHI_CRC_PER_SERVICE = 0, 61278277Sgonzo VCHI_CRC_EVERYTHING = 1, 62278277Sgonzo} VCHI_CRC_CONTROL_T; 63278277Sgonzo 64278277Sgonzo//callback reasons when an event occurs on a service 65278277Sgonzotypedef enum 66278277Sgonzo{ 67278277Sgonzo VCHI_CALLBACK_REASON_MIN, 68278277Sgonzo 69278277Sgonzo //This indicates that there is data available 70278277Sgonzo //handle is the msg id that was transmitted with the data 71278277Sgonzo // When a message is received and there was no FULL message available previously, send callback 72278277Sgonzo // Tasks get kicked by the callback, reset their event and try and read from the fifo until it fails 73278277Sgonzo VCHI_CALLBACK_MSG_AVAILABLE, 74278277Sgonzo VCHI_CALLBACK_MSG_SENT, 75278277Sgonzo VCHI_CALLBACK_MSG_SPACE_AVAILABLE, // XXX not yet implemented 76278277Sgonzo 77278277Sgonzo // This indicates that a transfer from the other side has completed 78278277Sgonzo VCHI_CALLBACK_BULK_RECEIVED, 79278277Sgonzo //This indicates that data queued up to be sent has now gone 80278277Sgonzo //handle is the msg id that was used when sending the data 81278277Sgonzo VCHI_CALLBACK_BULK_SENT, 82278277Sgonzo VCHI_CALLBACK_BULK_RX_SPACE_AVAILABLE, // XXX not yet implemented 83278277Sgonzo VCHI_CALLBACK_BULK_TX_SPACE_AVAILABLE, // XXX not yet implemented 84278277Sgonzo 85278277Sgonzo VCHI_CALLBACK_SERVICE_CLOSED, 86278277Sgonzo 87278277Sgonzo // this side has sent XOFF to peer due to lack of data consumption by service 88278277Sgonzo // (suggests the service may need to take some recovery action if it has 89278277Sgonzo // been deliberately holding off consuming data) 90278277Sgonzo VCHI_CALLBACK_SENT_XOFF, 91278277Sgonzo VCHI_CALLBACK_SENT_XON, 92278277Sgonzo 93278277Sgonzo // indicates that a bulk transfer has finished reading the source buffer 94278277Sgonzo VCHI_CALLBACK_BULK_DATA_READ, 95278277Sgonzo 96278277Sgonzo // power notification events (currently host side only) 97278277Sgonzo VCHI_CALLBACK_PEER_OFF, 98278277Sgonzo VCHI_CALLBACK_PEER_SUSPENDED, 99278277Sgonzo VCHI_CALLBACK_PEER_ON, 100278277Sgonzo VCHI_CALLBACK_PEER_RESUMED, 101278277Sgonzo VCHI_CALLBACK_FORCED_POWER_OFF, 102278277Sgonzo 103278277Sgonzo#ifdef USE_VCHIQ_ARM 104278277Sgonzo // some extra notifications provided by vchiq_arm 105278277Sgonzo VCHI_CALLBACK_SERVICE_OPENED, 106278277Sgonzo VCHI_CALLBACK_BULK_RECEIVE_ABORTED, 107278277Sgonzo VCHI_CALLBACK_BULK_TRANSMIT_ABORTED, 108278277Sgonzo#endif 109278277Sgonzo 110278277Sgonzo VCHI_CALLBACK_REASON_MAX 111278277Sgonzo} VCHI_CALLBACK_REASON_T; 112278277Sgonzo 113290245Sgonzo// service control options 114290245Sgonzotypedef enum 115290245Sgonzo{ 116290245Sgonzo VCHI_SERVICE_OPTION_MIN, 117290245Sgonzo 118290245Sgonzo VCHI_SERVICE_OPTION_TRACE, 119290245Sgonzo VCHI_SERVICE_OPTION_SYNCHRONOUS, 120290245Sgonzo 121290245Sgonzo VCHI_SERVICE_OPTION_MAX 122290245Sgonzo} VCHI_SERVICE_OPTION_T; 123290245Sgonzo 124290245Sgonzo 125290245Sgonzo//Callback used by all services / bulk transfers 126278277Sgonzotypedef void (*VCHI_CALLBACK_T)( void *callback_param, //my service local param 127278277Sgonzo VCHI_CALLBACK_REASON_T reason, 128278277Sgonzo void *handle ); //for transmitting msg's only 129278277Sgonzo 130278277Sgonzo 131278277Sgonzo 132278277Sgonzo/* 133278277Sgonzo * Define vector struct for scatter-gather (vector) operations 134278277Sgonzo * Vectors can be nested - if a vector element has negative length, then 135278277Sgonzo * the data pointer is treated as pointing to another vector array, with 136278277Sgonzo * '-vec_len' elements. Thus to append a header onto an existing vector, 137278277Sgonzo * you can do this: 138278277Sgonzo * 139278277Sgonzo * void foo(const VCHI_MSG_VECTOR_T *v, int n) 140278277Sgonzo * { 141278277Sgonzo * VCHI_MSG_VECTOR_T nv[2]; 142278277Sgonzo * nv[0].vec_base = my_header; 143278277Sgonzo * nv[0].vec_len = sizeof my_header; 144278277Sgonzo * nv[1].vec_base = v; 145278277Sgonzo * nv[1].vec_len = -n; 146278277Sgonzo * ... 147278277Sgonzo * 148278277Sgonzo */ 149278277Sgonzotypedef struct vchi_msg_vector { 150278277Sgonzo const void *vec_base; 151278277Sgonzo int32_t vec_len; 152278277Sgonzo} VCHI_MSG_VECTOR_T; 153278277Sgonzo 154278277Sgonzo// Opaque type for a connection API 155278277Sgonzotypedef struct opaque_vchi_connection_api_t VCHI_CONNECTION_API_T; 156278277Sgonzo 157278277Sgonzo// Opaque type for a message driver 158278277Sgonzotypedef struct opaque_vchi_message_driver_t VCHI_MESSAGE_DRIVER_T; 159278277Sgonzo 160278277Sgonzo 161278277Sgonzo// Iterator structure for reading ahead through received message queue. Allocated by client, 162278277Sgonzo// initialised by vchi_msg_look_ahead. Fields are for internal VCHI use only. 163278277Sgonzo// Iterates over messages in queue at the instant of the call to vchi_msg_lookahead - 164278277Sgonzo// will not proceed to messages received since. Behaviour is undefined if an iterator 165278277Sgonzo// is used again after messages for that service are removed/dequeued by any 166278277Sgonzo// means other than vchi_msg_iter_... calls on the iterator itself. 167278277Sgonzotypedef struct { 168278277Sgonzo struct opaque_vchi_service_t *service; 169278277Sgonzo void *last; 170278277Sgonzo void *next; 171278277Sgonzo void *remove; 172278277Sgonzo} VCHI_MSG_ITER_T; 173278277Sgonzo 174278277Sgonzo 175278277Sgonzo#endif // VCHI_COMMON_H_ 176