예제 #1
0
/* ----------------------------------------------------------------------
 * check to see if there are any pending messages
 *
 * if there are no messages, return 0
 *
 * otherwise, fetch and process the first queued message (which will
 * be either a command or response from host)
 * -------------------------------------------------------------------- */
static int
vc_ilcs_process_message( int block )
{
   int32_t success;
   void *ptr;
   unsigned char *msg;
   uint32_t i, msg_len, cmd, xid;
 
   success = vchi_msg_peek( vc_ilcsg.vchi_handle, &ptr, &msg_len, block ? VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE : VCHI_FLAGS_NONE);
   vc_assert(!block || !success);
   if ( success != 0 ) return 0; // no more messages

   msg = ptr;
   cmd = vchi_readbuf_uint32( msg );
   xid = vchi_readbuf_uint32( msg + 4 );

   if ( cmd == IL_RESPONSE )
   {
      vc_ilcs_response( xid, msg + 8, msg_len - 8 );
      vchi_msg_remove( vc_ilcsg.vchi_handle );
   }
   else
   {
      // we can only handle commands if we have space to copy the message first
      if(vc_ilcsg.msg_inuse == VC_ILCS_MSG_INUSE_MASK)
      {
         // this shouldn't happen, since we have more msg slots than the
         // remote side is allowed concurrent clients.  We don't cope
         // with this assumption not being true.
         vc_assert(0);
         return 0;
      }

      i = 0;
      while(vc_ilcsg.msg_inuse & (1<<i))
         i++;
      
      vc_ilcsg.msg_inuse |= (1<<i);
      
      memcpy( vc_ilcsg.msg[i], msg + 8, msg_len - 8 );
      vchi_msg_remove( vc_ilcsg.vchi_handle );
      vc_ilcs_command( cmd, xid, vc_ilcsg.msg[i], msg_len - 8);
      
      // mark the message copy as free
      vc_ilcsg.msg_inuse &= ~(1<<i);
   }

   return 1;
}
예제 #2
0
/* ----------------------------------------------------------------------
 * check to see if there are any pending messages
 *
 * if there are no messages, return 0
 *
 * otherwise, fetch and process the first queued message (which will
 * be either a command or response from host)
 * -------------------------------------------------------------------- */
static int
vc_ilcs_process_message( void )
{
   int32_t success;
   void *ptr;
   unsigned char *msg;
   VCHI_HELD_MSG_T msg_handle;
   uint32_t msg_len;

   success = vchi_msg_hold( vc_ilcsg.vchi_handle, &ptr, &msg_len, VCHI_FLAGS_NONE, &msg_handle );
   if ( success != 0 ) return 0; // no more messages

   msg = ptr;
   uint32_t cmd = vchi_readbuf_uint32( msg );
   uint32_t xid = vchi_readbuf_uint32( msg + 4 );
   log_add(cmd, msg + 8, msg_len - 8, "<-");

   if ( cmd == IL_RESPONSE )
       vc_ilcs_response( xid, msg + 8, msg_len - 8 );
   else
      //vc_ilcs_command( cmd, xid, msg + 8, msg_len - 8 );
   {
       msg += 8;
       msg_len -= 8;
       if(component_in_kernel(msg)) 
	   {
	      vc_ilcs_command( cmd, xid, msg, msg_len);
	   }
       else
	   {
	      vc_ilcs_command_usr( cmd, xid, msg, msg_len);
       }
    }

   success = vchi_held_msg_release( &msg_handle );
   vc_assert(success == 0);

   return 1;
}
예제 #3
0
/***********************************************************
 * Name: control_callback
 *
 * Arguments: void *callback_param
 *            const VCHI_CALLBACK_REASON_T reason
 *            const void *handle
 *
 * Description: Handles callbacks for received messages
 *
 * Returns: -
 *
 ***********************************************************/
static void control_callback( void *callback_param, //my service local param
                              const VCHI_CALLBACK_REASON_T reason,
                              void *handle )
{
CONTROL_SERVICE_INFO_T * service_info = (CONTROL_SERVICE_INFO_T *)callback_param;
uint8_t *message;
uint8_t output_message[128];
uint32_t message_length;
int32_t return_value;
fourcc_t service_id;
uint32_t flags;
VCHI_FLAGS_T output_flags = VCHI_FLAGS_NONE;

   switch(reason)
   {
      case VCHI_CALLBACK_MSG_AVAILABLE:
      {
         // handle the message in place
         void *message_handle;
#if defined VCHI_COARSE_LOCKING
         os_semaphore_obtain(&service_info->connection->sem);
#endif
#ifdef VCHI_FEWER_MSG_AVAILABLE_CALLBACKS
         do {
         message_handle = NULL;
#endif
         return_value = service_info->connection->api->service_hold_msg(service_info->open_handle,(void**)&message,&message_length,VCHI_FLAGS_NONE,&message_handle);
         if(return_value == 0)
         {
            if (message_length>0)
            {
               // this is a valid message - read the command
               uint32_t command = vchi_readbuf_uint32(&message[0]);
               int32_t reply_required = VC_FALSE;
               switch(command)
               {
               case CONNECT:
                  os_logging_message("CTRL SERVICE: Connect message");
                  if(service_info->initialised ==  VC_FALSE)
                  {
                     uint32_t protocol_version;
                     uint32_t slot_size;
                     uint32_t num_slots;
                     uint32_t min_bulk_size;

                     return_value = os_semaphore_release( &service_info->connected_semaphore );
                     os_assert( return_value == 0 );
                     // record that we have been initialised
                     service_info->initialised = VC_TRUE;
                     // extract the values we need to pass back to the service - principally slot size for the moment
                     protocol_version = vchi_readbuf_uint32(&message[4]);
                     slot_size        = vchi_readbuf_uint32(&message[8]);
                     num_slots        = vchi_readbuf_uint32(&message[12]);
                     min_bulk_size    = message_length >= 20 ? vchi_readbuf_uint32(&message[16]) : 0;
                     //os_assert(0);
                     service_info->connection->api->connection_info(service_info->connection->state,protocol_version, slot_size, num_slots, min_bulk_size);
                     // we are going to reply with 'CONNECT'
                     return_value = vchi_control_queue_connect( service_info, VC_TRUE );
                     os_assert( return_value == 0);
                  }
                  break;
               case SERVER_AVAILABLE:
               {
                  VCHI_SERVICE_FLAGS_T peer_flags = (VCHI_SERVICE_FLAGS_T)(message_length >= 12 ? vchi_readbuf_uint32(&message[8]) : 0);
                  int32_t our_flags;
                  service_id = vchi_readbuf_fourcc(&message[4]);
                  os_logging_message("CTRL SERVICE: Server available (%c%c%c%c:0x%x)",FOURCC_TO_CHAR(service_id),peer_flags);
                  message_length = 12;
                  // we are replying
                  reply_required = VC_TRUE;
                  // first part of the reply is the command
                  vchi_writebuf_uint32( &output_message[0], SERVER_AVAILABLE_REPLY );
                  // then the requested server ID
                  vchi_writebuf_fourcc( &output_message[4], service_id );
                  // check if this fourcc is in our list of servers on this connection
                  our_flags = service_info->connection->api->server_present(service_info->connection->state, service_id, peer_flags);
                  if(our_flags >= 0)
                     vchi_writebuf_uint32( &output_message[8], AVAILABLE | our_flags );
                  else
                     vchi_writebuf_uint32( &output_message[8], 0 );
                  break;
               }
               case SERVER_AVAILABLE_REPLY:
                  // Connection can take ownership of the message - signalled by returning true.
                  service_id = vchi_readbuf_fourcc(&message[4]);
                  flags = vchi_readbuf_uint32(&message[8]);
                  service_info->connection->api->server_available_reply(service_info->connection->state, service_id, flags);
                  break;
               case BULK_TRANSFER_RX:
               {
                  uint32_t length, channel_params, data_length, data_offset;
                  MESSAGE_TX_CHANNEL_T channel;
                  // extract the service and length and pass it to the low level driver
                  service_id = vchi_readbuf_fourcc(&message[4]);
                  length = vchi_readbuf_uint32(&message[8]);
                  channel = (MESSAGE_TX_CHANNEL_T)(message_length >= 20 ? message[12] : MESSAGE_TX_CHANNEL_BULK);
                  channel_params = message_length >= 20 ? vchi_readbuf_uint32(&message[16]) : 0;
                  data_length = message_length >= 28 ? vchi_readbuf_uint32(&message[20]) : length;
                  data_offset = message_length >= 28 ? vchi_readbuf_uint32(&message[24]) : 0;
                  os_logging_message("CTRL SERVICE: Bulk transfer rx (%c%c%c%c), channel %d, %u Bytes (core=%u, offset=%u)",FOURCC_TO_CHAR(service_id), channel, length, data_length, data_offset);
                  service_info->connection->api->rx_bulk_buffer_added(service_info->connection->state,service_id,length,channel,channel_params,data_length,data_offset);
                  break;
               }
               case XON:
                  service_id = vchi_readbuf_fourcc(&message[4]);
                  os_logging_message("CTRL SERVICE: Xon (%c%c%c%c)",FOURCC_TO_CHAR(service_id));
                  service_info->connection->api->flow_control(service_info->connection->state, service_id, VC_FALSE);
                  break;
               case XOFF:
                  service_id = vchi_readbuf_fourcc(&message[4]);
                  os_logging_message("CTRL SERVICE: Xoff (%c%c%c%c)",FOURCC_TO_CHAR(service_id));
                  service_info->connection->api->flow_control(service_info->connection->state, service_id, VC_TRUE);
                  break;
               case DISCONNECT:
                  flags = message_length >= 8 ? vchi_readbuf_uint32(&message[4]) : 0;
                  service_info->connection->api->disconnect(service_info->connection->state, flags);
                  break;
               case POWER_CONTROL:
               {
                  MESSAGE_TX_CHANNEL_T channel = vchi_readbuf_uint32(&message[4]);
                  bool_t enable = vchi_readbuf_uint32(&message[8]);
                  uint32_t cookie = vchi_readbuf_uint32(&message[12]);
                  os_logging_message("CTRL SERVICE: Power (%d -> %d; %d)", channel, enable, cookie);
                  // connection should synchronously perform the power change, then we reply
                  // don't currently allow for any sort of error (protocol doesn't allow for it)
                  service_info->connection->api->power_control(service_info->connection->state, channel, enable);
                  // we are replying
                  reply_required = VC_TRUE;
                  message_length = 16;
                  // reply is the same as the message, except for the command code
                  vchi_writebuf_uint32( &output_message[0], POWER_CONTROL_REPLY );
                  memcpy(output_message+4, message+4, 12);
                  break;
               }
               default:
                  os_logging_message("CTRL SERVICE: Unknown message (0x%x)", command);
                  os_assert(0);
                  break;
               }
               // transmit the reply (if needed)
               if(reply_required)
               {
                  //attempt to send
                  return_value = service_info->connection->api->service_queue_msg(service_info->open_handle,output_message,message_length,output_flags,NULL);
                  if (return_value != 0) //failed because tx slots are full or whatever
                  {
                     //save the msg and send it later
                     return_value = vchi_control_reply_add_service(service_info,service_id,output_message);
                     os_assert(return_value == 0);
                  }
               }
            }
            return_value = service_info->connection->api->held_msg_release(service_info->open_handle, message_handle);
            os_assert(return_value == 0);
         }
#ifdef VCHI_FEWER_MSG_AVAILABLE_CALLBACKS
         } while (message_handle);
#endif
#if defined VCHI_COARSE_LOCKING
         os_semaphore_release(&service_info->connection->sem);
#endif
         break;
      }
      case VCHI_CALLBACK_MSG_SENT:
         break;
         
      case VCHI_CALLBACK_BULK_RECEIVED:
      case VCHI_CALLBACK_BULK_DATA_READ:
      case VCHI_CALLBACK_BULK_SENT:      // control service doesn't use bulk transfers
      case VCHI_CALLBACK_SENT_XOFF:
      case VCHI_CALLBACK_SENT_XON:       // control service must never be XOFFed
         os_assert(0);
         break;
   }
}