Exemple #1
0
int handle_hotplug_event()
{
	printf("\n\033[34m<<<<handle_hotplug_event, hotplug_fd:%d\033[0m\n", hotplug_fd);
	int ret = 0;
	char buf[PIPE_BUF];
	int nread;

	nread = read(hotplug_fd, buf, PIPE_BUF);

	if (nread == -1)
	{
		D_ERROR("handle_hotplug_event: Error reading from FIFO.\n");
		return -1;
	}
	else if (nread == 0)
	{
		D_WARN("handle_hotplug_event: No more writers?\n");
		return -1;
	}
	
	/* parse the message */
	if (strncmp(buf, MSG_HEADER, strlen(MSG_HEADER)))					/* check the header */
	{
		D_ERROR("handle_hotplug_event: Invalid message header %s\n", buf);
		ret = -1;
	}
	else if (strncmp(buf + strlen(MSG_HEADER), MSG_ADDED, strlen(MSG_ADDED)) == 0)			/* device was added & mounted */
	{
		D_INFO("handle_hotplug_event: USB storage added\n");
		if(read_dev_properties(EXT_STOR, &prop_e_stor) == 0)
			s_status |= ESTORAGE_ADDED;
		else
			D_WARN("Could not read properties of %s. Storage is disabled.", EXT_STOR);
	}
	else if (strncmp(buf + strlen(MSG_HEADER), MSG_REMOVED, strlen(MSG_REMOVED)) == 0)		/* device was removed */
	{
		D_INFO("handle_hotplug_event: USB storage removed\n");
		s_status &= ~ESTORAGE_ADDED;
	}
	else
	{
		D_ERROR("handle_hotplug_event: Invalid message: %s", buf);
		ret = -1;
	}
	printf("\n\033[34m<<<<[TR]handle_hotplug_event, hotplug_fd:%d\033[0m\n", hotplug_fd);
	printf("\n\033[34m<<<<[TR]handle_hotplug_event, hotplug_fd:%d\033[0m\n", hotplug_fd);
	return ret;
}
Exemple #2
0
static int open_fifo()
{
	printf("\n\033[34m<<<<open_fifo\033[0m\n");
	if (mkfifo(FIFO_NAME, S_IRUSR | S_IWUSR) == -1)
	{
		if (errno == EEXIST)
		{
			D_WARN("open_fifo: FIFO already exists.\n");
		}
		else
		{
			D_ERROR("open_fifo: Could not create FIFO.\n");
			return -1;
		}
	}

	hotplug_fd = open(FIFO_NAME, O_RDWR);

	if (hotplug_fd == -1)
	{
		unlink(FIFO_NAME);
		D_ERROR("open_fifo: Could not open fifo.\n");
		return -1;
	}

	return 0;
}
Exemple #3
0
DFBResult
dfb_state_set_source_mask( CardState *state, CoreSurface *source_mask )
{
     D_MAGIC_ASSERT( state, CardState );

     dfb_state_lock( state );

     if (state->source_mask != source_mask) {
          if (source_mask && dfb_surface_ref( source_mask )) {
               D_WARN( "could not ref() source mask" );
               dfb_state_unlock( state );
               return DFB_DEAD;
          }

          if (state->source_mask) {
               D_ASSERT( D_FLAGS_IS_SET( state->flags, CSF_SOURCE_MASK ) );
               dfb_surface_unref( state->source_mask );
          }

          state->source_mask  = source_mask;
          state->modified    |= SMF_SOURCE_MASK;

          if (source_mask) {
               direct_serial_copy( &state->src_mask_serial, &source_mask->serial );

               D_FLAGS_SET( state->flags, CSF_SOURCE_MASK );
          }
          else
               D_FLAGS_CLEAR( state->flags, CSF_SOURCE_MASK );
     }

     dfb_state_unlock( state );

     return DFB_OK;
}
Exemple #4
0
DirectResult
direct_signal_handler_add( int                       num,
                           DirectSignalHandlerFunc   func,
                           void                     *ctx,
                           DirectSignalHandler     **ret_handler )
{
     DirectSignalHandler *handler;

     D_ASSERT( func != NULL );
     D_ASSERT( ret_handler != NULL );

     D_DEBUG_AT( Direct_Signals,
                 "Adding handler %p for signal %d with context %p...\n", func, num, ctx );

     handler = D_CALLOC( 1, sizeof(DirectSignalHandler) );
     if (!handler) {
          D_WARN( "out of memory" );
          return DR_NOLOCALMEMORY;
     }

     handler->num  = num;
     handler->func = func;
     handler->ctx  = ctx;

     D_MAGIC_SET( handler, DirectSignalHandler );

     direct_mutex_lock( &handlers_lock );
     direct_list_append( &handlers, &handler->link );
     direct_mutex_unlock( &handlers_lock );

     *ret_handler = handler;

     return DR_OK;
}
Exemple #5
0
DirectThreadInitHandler *
direct_thread_add_init_handler( DirectThreadInitFunc  func,
                                void                 *arg )
{
     DirectThreadInitHandler *handler;

     handler = D_CALLOC( 1, sizeof(DirectThreadInitHandler) );
     if (!handler) {
          D_WARN( "out of memory" );
          return NULL;
     }

     handler->func = func;
     handler->arg  = arg;

     D_MAGIC_SET( handler, DirectThreadInitHandler );

     pthread_mutex_lock( &handler_lock );

     direct_list_append( &handlers, &handler->link );

     pthread_mutex_unlock( &handler_lock );

     return handler;
}
Exemple #6
0
DFBResult
dfb_state_set_source2( CardState *state, CoreSurface *source2 )
{
     D_MAGIC_ASSERT( state, CardState );

     dfb_state_lock( state );

     if (state->source2 != source2) {
          if (source2 && dfb_surface_ref( source2 )) {
               D_WARN( "could not ref() source2" );
               dfb_state_unlock( state );
               return DFB_DEAD;
          }

          if (state->source2) {
               D_ASSERT( D_FLAGS_IS_SET( state->flags, CSF_SOURCE2 ) );
               dfb_surface_unref( state->source2 );
          }

          state->source2   = source2;
          state->modified |= SMF_SOURCE2;

          if (source2) {
               direct_serial_copy( &state->src2_serial, &source2->serial );

               D_FLAGS_SET( state->flags, CSF_SOURCE2 );
          }
          else
               D_FLAGS_CLEAR( state->flags, CSF_SOURCE2 );
     }

     dfb_state_unlock( state );

     return DFB_OK;
}
Exemple #7
0
DirectResult
fusion_call_execute (FusionCall          *call,
                     FusionCallExecFlags  flags,
                     int                  call_arg,
                     void                *call_ptr,
                     int                 *ret_val)
{
     D_DEBUG_AT( Fusion_Call, "%s( %p, 0x%x, %d, %p )\n", __FUNCTION__, call, flags, call_arg, call_ptr );

     D_ASSERT( call != NULL );

     if (!call->handler)
          return DR_DESTROYED;

     D_DEBUG_AT( Fusion_Call, "  -> %s\n", direct_trace_lookup_symbol_at( call->handler ) );

     if (!(flags & FCEF_NODIRECT) && call->fusion_id == _fusion_id( call->shared )) {
          int                     ret;
          FusionCallHandlerResult result;

          result = call->handler( _fusion_id( call->shared ), call_arg, call_ptr, call->ctx, 0, &ret );

          if (result != FCHR_RETURN)
               D_WARN( "local call handler returned FCHR_RETAIN, need FCEF_NODIRECT" );

          if (ret_val)
               *ret_val = ret;
     }
     else {
          FusionCallExecute execute;

          execute.call_id  = call->call_id;
          execute.call_arg = call_arg;
          execute.call_ptr = call_ptr;
          execute.flags    = flags;

          while (ioctl( _fusion_fd( call->shared ), FUSION_CALL_EXECUTE, &execute )) {
               switch (errno) {
                    case EINTR:
                         continue;
                    case EINVAL:
//                         D_ERROR ("Fusion/Call: invalid call\n");
                         return DR_INVARG;
                    case EIDRM:
                         return DR_DESTROYED;
                    default:
                         break;
               }

               D_PERROR ("FUSION_CALL_EXECUTE");

               return DR_FAILURE;
          }

          if (ret_val)
               *ret_val = execute.ret_val;
     }

     return DR_OK;
}
Exemple #8
0
DirectResult
direct_hash_remove( DirectHash    *hash,
                    unsigned long  key )
{
     int pos;

     D_MAGIC_ASSERT( hash, DirectHash );

     if (!hash->Elements)
          return DR_BUFFEREMPTY;

     pos = locate_key( hash, key );
     if (pos == -1) {
          D_WARN( "key not found" );
          return DR_ITEMNOTFOUND;
     }

     hash->Elements[pos].value = DIRECT_HASH_ELEMENT_REMOVED;

     hash->count--;
     hash->removed++;

     D_DEBUG_AT( Direct_Hash, "Removed key 0x%08lx at %d, new count = %d, removed = %d, size = %d.\n",
                 key, pos, hash->count, hash->removed, hash->size );

//     direct_futex_wake( &hash->count, INT_MAX );  // FIXME: only wake if waiting

     return DR_OK;
}
Exemple #9
0
static int
pool_iv_ent_refresh(d_sg_list_t *dst, d_sg_list_t *src, int ref_rc, void **priv)
{
	struct pool_iv_entry	*dst_iv = dst->sg_iovs[0].iov_buf;
	struct pool_iv_entry	*src_iv = src->sg_iovs[0].iov_buf;
	struct ds_pool		*pool;
	int			rc;

	D_ASSERT(src_iv != NULL);
	D_ASSERT(dst_iv != NULL);
	rc = pool_iv_ent_copy(dst, src);
	if (rc)
		return rc;

	/* Update pool map version or pool map */
	pool = ds_pool_lookup(src_iv->piv_pool_uuid);
	if (pool == NULL) {
		D_WARN("No pool "DF_UUID"\n", DP_UUID(src_iv->piv_pool_uuid));
		return 0;
	}

	rc = ds_pool_tgt_map_update(pool, src_iv->piv_pool_buf.pb_nr > 0 ?
				    &src_iv->piv_pool_buf : NULL,
				    src_iv->piv_pool_map_ver);
	ds_pool_put(pool);

	return rc;
}
Exemple #10
0
DirectResult
direct_map_remove( DirectMap  *map,
                   const void *key )
{
     unsigned int hash;
     int          pos;

     D_DEBUG_AT( Direct_Map, "%s( key %p )\n", __func__, key );

     DIRECT_MAP_ASSERT( map );
     D_ASSERT( key != NULL );

     hash = map->hash( map, key, map->ctx );

     pos = locate_entry( map, hash, key );
     if (pos == -1) {
          D_WARN( "object to remove not found" );
          return DR_ITEMNOTFOUND;
     }

     map->entries[pos].object = REMOVED;

     map->count--;
     map->removed++;

     D_DEBUG_AT( Direct_Map, "  -> new count = %d, removed = %d, size = %d\n", map->count, map->removed, map->size );

     return DR_OK;
}
DFBResult dfb_surfacemanager_deallocate( SurfaceManager *manager,
                                         SurfaceBuffer  *buffer )
{
     int    loops = 0;
     Chunk *chunk = buffer->video.chunk;

     D_ASSERT( buffer->surface );

     D_MAGIC_ASSERT( manager, SurfaceManager );

     if (buffer->video.health == CSH_INVALID)
          return DFB_OK;

     buffer->video.health = CSH_INVALID;
     buffer->video.chunk = NULL;

     dfb_surface_notify_listeners( buffer->surface, CSNF_VIDEO );

     while (buffer->video.locked) {
          if (++loops > 1000)
               break;

          sched_yield();
     }

     if (buffer->video.locked)
          D_WARN( "Freeing chunk with a non-zero lock counter" );

     if (chunk)
          free_chunk( manager, chunk );

     return DFB_OK;
}
bool
Genefx_ABacc_prepare( GenefxState *gfxs, int width )
{
     int size;

     if (!gfxs->need_accumulator)
          return true;

     size = (width + 31) & ~31;

     if (gfxs->ABsize < size) {
          void *ABstart = D_MALLOC( size * sizeof(GenefxAccumulator) * 3 + 31 );

          if (!ABstart) {
               D_WARN( "out of memory" );
               return false;
          }

          if (gfxs->ABstart)
               D_FREE( gfxs->ABstart );

          gfxs->ABstart = ABstart;
          gfxs->ABsize  = size;
          gfxs->Aacc    = (GenefxAccumulator*) (((unsigned long)ABstart+31) & ~31);
          gfxs->Bacc    = gfxs->Aacc + size;
          gfxs->Tacc    = gfxs->Aacc + size + size;
     }

     gfxs->Sacc = gfxs->Dacc = gfxs->Aacc;

     return true;
}
Exemple #13
0
Fichier : tdfx.c Projet : uiv/Lerdu
static inline void tdfx_waitfifo( TDFXDriverData *tdrv,
                                  TDFXDeviceData *tdev,
                                  unsigned int space )
{
    int timeout = 1000000;

    tdev->waitfifo_calls++;
    tdev->waitfifo_sum += space;

    if (tdev->fifo_space < space) {
        while (timeout--) {
            tdev->fifo_waitcycles++;

            tdev->fifo_space = (tdrv->voodoo2D->status & 0x3f);
            if (tdev->fifo_space >= space)
                break;

        }
    } else {
        tdev->fifo_cache_hits++;
    }

    tdev->fifo_space -= space;

    if (!timeout)
        D_WARN( "timeout during waitfifo!" );
}
Exemple #14
0
DirectResult
fusion_shm_deinit( FusionWorld *world )
{
     int              i;
     DirectResult     ret;
     FusionSHM       *shm;
     FusionSHMShared *shared;

     D_MAGIC_ASSERT( world, FusionWorld );

     shm = &world->shm;

     D_MAGIC_ASSERT( shm, FusionSHM );

     shared = shm->shared;

     D_MAGIC_ASSERT( shared, FusionSHMShared );

     ret = fusion_skirmish_prevail( &shared->lock );
     if (ret)
          return ret;

     /* Deinitialize shared data. */
     if (fusion_master( world )) {
          D_ASSUME( shared->num_pools == 0 );

          for (i=0; i<FUSION_SHM_MAX_POOLS; i++) {
               if (shared->pools[i].active) {
                    D_MAGIC_ASSERT( &shared->pools[i], FusionSHMPoolShared );
                    D_MAGIC_ASSERT( &shm->pools[i], FusionSHMPool );

                    D_WARN( "destroying remaining '%s'", shared->pools[i].name );

                    fusion_shm_pool_destroy( world, &shared->pools[i] );
               }
          }

          /* Destroy shared lock. */
          fusion_skirmish_destroy( &shared->lock );

          D_MAGIC_CLEAR( shared );
     }
     else {
          for (i=0; i<FUSION_SHM_MAX_POOLS; i++) {
               if (shared->pools[i].active) {
                    D_MAGIC_ASSERT( &shared->pools[i], FusionSHMPoolShared );
                    D_MAGIC_ASSERT( &shm->pools[i], FusionSHMPool );

                    fusion_shm_pool_detach( shm, &shared->pools[i] );
               }
          }

          fusion_skirmish_dismiss( &shared->lock );
     }

     D_MAGIC_CLEAR( shm );

     return DR_OK;
}
Exemple #15
0
static void
dfb_core_deinit_check( void *ctx )
{
     if (core_dfb && core_dfb->refs) {
          D_WARN( "Application exited without deinitialization of DirectFB!" );
          dfb_core_destroy( core_dfb, true );
     }
}
static inline bool
check_depth( int frame )
{
     if (frame >= STRET_ITERATION_MAX_DEPTH) {
          D_WARN( "refusing to exceed depth limit of %d", STRET_ITERATION_MAX_DEPTH );
          return false;
     }

     return true;
}
static DFBResult
IDirectFBDisplayLayer_GetSurface( IDirectFBDisplayLayer  *thiz,
                                  IDirectFBSurface      **interface )
{
     DFBResult         ret;
     CoreLayerRegion  *region;
     IDirectFBSurface *surface;

     D_DEBUG_AT( Layer, "%s( %p )\n", __FUNCTION__, thiz );

     DIRECT_INTERFACE_GET_DATA(IDirectFBDisplayLayer)

     if (!interface)
          return DFB_INVARG;

     if (data->level == DLSCL_SHARED) {
          D_WARN( "letting unprivileged IDirectFBDisplayLayer::GetSurface() "
                   "call pass until cooperative level handling is finished" );
     }

     ret = CoreLayerContext_GetPrimaryRegion( data->context, true, &region );
     if (ret)
          return ret;

     DIRECT_ALLOCATE_INTERFACE( surface, IDirectFBSurface );

     ret = IDirectFBSurface_Layer_Construct( surface, NULL, NULL, NULL,
                                             region, DSCAPS_NONE, data->core, data->idirectfb );

     // Fix to only perform single buffered clearing using a background when
     // configured to do so AND the display layer region is frozen.  Also
     // added support for this behavior when the cooperative level is
     // DLSCL_ADMINISTRATIVE.
     if (region->config.buffermode == DLBM_FRONTONLY &&
         data->level != DLSCL_SHARED &&
         D_FLAGS_IS_SET( region->state, CLRSF_FROZEN )) {
          // If a window stack is available, give it the opportunity to
          // render the background (optionally based on configuration) and
          // flip the display layer so it is visible.  Otherwise, just
          // directly flip the display layer and make it visible.
          if (data->stack) {
               CoreWindowStack_RepaintAll( data->stack );
          }
          else {
               CoreLayerRegion_FlipUpdate2( region, NULL, NULL, DSFLIP_NONE, -1 );
          }
     }

     *interface = ret ? NULL : surface;

     dfb_layer_region_unref( region );

     return ret;
}
DFBResult
dfb_layer_region_set_surface( CoreLayerRegion *region,
                              CoreSurface     *surface )
{
     DFBResult ret;

     D_ASSERT( region != NULL );
     D_ASSERT( surface != NULL );

     /* Lock the region. */
     if (dfb_layer_region_lock( region ))
          return DFB_FUSION;

     if (region->surface != surface) {
          /* Setup hardware for the new surface if the region is realized. */
          if (D_FLAGS_IS_SET( region->state, CLRSF_REALIZED )) {
               ret = set_region( region, &region->config, CLRCF_SURFACE | CLRCF_PALETTE, surface );
               if (ret) {
                    dfb_layer_region_unlock( region );
                    return ret;
               }
          }

          /* Throw away the old surface. */
          if (region->surface) {
               /* Detach the global listener. */
               dfb_surface_detach_global( region->surface,
                                          &region->surface_reaction );

               /* Unlink surface from structure. */
               dfb_surface_unlink( &region->surface );
          }

          /* Take the new surface. */
          if (surface) {
               /* Link surface into structure. */
               if (dfb_surface_link( &region->surface, surface )) {
                    D_WARN( "region lost it's surface" );
                    dfb_layer_region_unlock( region );
                    return DFB_FUSION;
               }

               /* Attach the global listener. */
               dfb_surface_attach_global( region->surface,
                                          DFB_LAYER_REGION_SURFACE_LISTENER,
                                          region, &region->surface_reaction );
          }
     }

     /* Unlock the region. */
     dfb_layer_region_unlock( region );

     return DFB_OK;
}
Exemple #19
0
void
_fusion_call_process( FusionWorld *world, int call_id, FusionCallMessage *msg )
{
     FusionCallHandler       call_handler;
     FusionCallReturn        call_ret;
     FusionCallHandlerResult result;

     D_DEBUG_AT( Fusion_Call, "%s()\n", __FUNCTION__ );

     D_MAGIC_ASSERT( world, FusionWorld );
     D_ASSERT( msg != NULL );

     call_handler = msg->handler;

     D_ASSERT( call_handler != NULL );

     D_DEBUG_AT( Fusion_Call, "  -> %s\n", direct_trace_lookup_symbol_at( call_handler ) );

     call_ret.val = 0;

     result = call_handler( msg->caller, msg->call_arg, msg->call_ptr, msg->ctx, msg->serial, &call_ret.val );

     switch (result) {
          case FCHR_RETURN:
               if (msg->serial) {
                    call_ret.serial  = msg->serial;
                    call_ret.call_id = call_id;

                    while (ioctl (world->fusion_fd, FUSION_CALL_RETURN, &call_ret)) {
                         switch (errno) {
                              case EINTR:
                                   continue;
                              case EIDRM:
                                   D_WARN( "caller withdrawn (signal?)" );
                                   return;
                              case EINVAL:
                                   D_ERROR( "Fusion/Call: invalid call\n" );
                                   return;
                              default:
                                   D_PERROR( "FUSION_CALL_RETURN" );
                                   return;
                         }
                    }
               }
               break;

          case FCHR_RETAIN:
               break;

          default:
               D_BUG( "unknown result %d from call handler", result );
     }
}
DFBResult dfb_surfacemanager_adjust_heap_offset( SurfaceManager *manager,
                                                 int             offset )
{
     D_ASSERT( offset >= 0 );

     D_MAGIC_ASSERT( manager, SurfaceManager );

     dfb_surfacemanager_lock( manager );

     if (manager->byteoffset_align > 1) {
          offset += manager->byteoffset_align - 1;
          offset -= offset % manager->byteoffset_align;
     }

     if (manager->chunks->buffer == NULL) {
          /* first chunk is free */
          if (offset <= manager->chunks->offset + manager->chunks->length) {
               /* ok, just recalculate offset and length */
               manager->chunks->length = manager->chunks->offset + manager->chunks->length - offset;
               manager->chunks->offset = offset;
          }
          else {
               D_WARN("unable to adjust heap offset");
               /* more space needed than free at the beginning */
               /* TODO: move/destroy instances */
          }
     }
     else {
          D_WARN("unable to adjust heap offset");
          /* very rare case that the first chunk is occupied */
          /* TODO: move/destroy instances */
     }

     manager->heap_offset = offset;

     dfb_surfacemanager_unlock( manager );

     return DFB_OK;
}
Exemple #21
0
DirectResult
voodoo_manager_register_local( VoodooManager    *manager,
                               bool              super,
                               void             *dispatcher,
                               void             *real,
                               VoodooDispatch    dispatch,
                               VoodooInstanceID *ret_instance )
{
     DirectResult      ret;
     VoodooInstance   *instance;
     VoodooInstanceID  instance_id;

     D_MAGIC_ASSERT( manager, VoodooManager );
     D_ASSERT( dispatcher != NULL );
     D_ASSERT( real != NULL );
     D_ASSERT( dispatch != NULL );
     D_ASSERT( ret_instance != NULL );

     instance = D_CALLOC( 1, sizeof(VoodooInstance) );
     if (!instance) {
          D_WARN( "out of memory" );
          return DR_NOLOCALMEMORY;
     }

     instance->super    = super;
     instance->proxy    = dispatcher;
     instance->real     = real;
     instance->dispatch = dispatch;

     pthread_mutex_lock( &manager->instances.lock );

     instance_id = ++manager->instances.last;

     ret = direct_hash_insert( manager->instances.local, instance_id, instance );

     pthread_mutex_unlock( &manager->instances.lock );

     if (ret) {
          D_ERROR( "Voodoo/Manager: Adding a new instance to the dispatcher hash table failed!\n" );
          D_FREE( instance );
          return ret;
     }

     D_DEBUG( "Voodoo/Manager: "
              "Added instance %u, dispatcher %p, real %p.\n", instance_id, dispatcher, real );

     *ret_instance = instance_id;

     return DR_OK;
}
Exemple #22
0
VoodooPacket *
VoodooConnectionLink::GetPacket( size_t length )
{
     D_DEBUG_AT( Voodoo_Connection, "VoodooConnectionLink::%s( %p, length "_ZU" )\n", __func__, this, length );

     D_MAGIC_ASSERT( this, VoodooConnection );
     D_ASSERT( length >= (int) sizeof(VoodooMessageHeader) );
     D_ASSUME( length <= MAX_MSG_SIZE );

     if (length > MAX_MSG_SIZE) {
          D_WARN( _ZU" exceeds maximum message size of %d", length, MAX_MSG_SIZE );
          return NULL;
     }

     size_t aligned = VOODOO_MSG_ALIGN( length );


     Packets *packets = (Packets*) direct_tls_get( output.tls );

     if (!packets) {
          packets = new Packets( this );

          direct_tls_set( output.tls, packets );
     }

     VoodooPacket *packet = packets->active;

     if (packet) {
          if (packet->append( aligned ))
               return packet;

          Flush( packet );
     }

     packet = packets->Get();
     if (packet) {
          if (packet->sending) {
               direct_mutex_lock( &output.lock );

               while (packet->sending)
                    direct_waitqueue_wait( &output.wait, &output.lock );

               direct_mutex_unlock( &output.lock );
          }
          packet->reset( aligned );
     }

     return packet;
}
Exemple #23
0
int init_hotplug()
{
	printf("\n\033[34m<<<<init_hotplug\033[0m\n");
	/* check if the internal, i.e. non-removable storage was mounted */
	if ((check_mnt_point(INT_STOR) == 0) && (read_dev_properties(INT_STOR, &prop_i_stor) == 0))
		s_status |= ISTORAGE_PRESENT;

	/* check if an external, i.e. removable storage was already mounted */
	if ((check_mnt_point(EXT_STOR) == 0) && (read_dev_properties(EXT_STOR, &prop_e_stor) == 0))
		s_status |= ESTORAGE_ADDED;

	if (s_status == STORAGE_NONE)
		D_WARN("init_hotplug: No internal OR external storage mounted.\n");
	
	if (open_fifo() == -1)
	{
		D_WARN("init_hotplug: open_fifo() failed. Hotplug messages will not be received.\n");
		return -1;
	}

	D_INFO("Hotplug handler initialized.\n");

	return 0;
}
Exemple #24
0
static void
InputHub_EventDispatch( void                *ctx,
                        DFBInputDeviceID     device_id,
                        const DFBInputEvent *event )
{
     InputHubDeviceNode *node;

     D_DEBUG_AT( Input_Hub, "%s( ID %u, %s )\n", __FUNCTION__, device_id, dfb_input_event_type_name(event->type) );

     node = direct_hash_lookup( m_nodes, device_id );
     if (node) {
          if (node->device) {
               DFBInputEvent event_copy = *event;

               D_DEBUG_AT( Input_Hub, "  -> found device %p (ID %u)\n", node->device, dfb_input_device_id(node->device) );
          
               dfb_input_dispatch( node->device, &event_copy );
          }
          else
               D_WARN( "inactive device (ID %u)", device_id );
     }
     else
          D_WARN( "unknown device (ID %u)", device_id );
}
Exemple #25
0
long long
direct_clock_get_time( DirectClockType type )
{
     long long       micros;
     struct timespec spec;
     clockid_t       clock_id;

     switch (type) {
          case DIRECT_CLOCK_REALTIME:
               clock_id = CLOCK_REALTIME;
               break;

          case DIRECT_CLOCK_SESSION:
          case DIRECT_CLOCK_MONOTONIC:
               clock_id = CLOCK_MONOTONIC;
               break;

          case DIRECT_CLOCK_PROCESS_CPUTIME_ID:
               clock_id = CLOCK_PROCESS_CPUTIME_ID;
               break;

          case DIRECT_CLOCK_THREAD_CPUTIME_ID:
               clock_id = CLOCK_THREAD_CPUTIME_ID;
               break;

          default:
               D_BUG( "invalid clock type %d", type );
               return DR_INVARG;
     }

     if (clock_gettime( clock_id, &spec ) < 0) {
          if (clock_id != CLOCK_REALTIME) {
               D_WARN( "clock with id %d not supported by system", clock_id );
               return direct_clock_get_time( DIRECT_CLOCK_REALTIME );
          }

          D_PERROR( "Direct/Clock: Could not get even real time clock!\n" );
          return 0;
     }

     micros = spec.tv_sec * 1000000LL + spec.tv_nsec / 1000LL;

     if (type == DIRECT_CLOCK_SESSION)
          micros -= session_clock_offset;

     return micros;
}
Exemple #26
0
DirectResult
fusion_call_return3( FusionCall   *call,
                     unsigned int  serial,
                     void         *ptr,
                     unsigned int  length )
{
     FusionCallReturn3 call_ret;

     D_DEBUG_AT( Fusion_Call, "%s( %p, serial %u, ptr %p, length %u )\n", __FUNCTION__, call, serial, ptr, length );

     D_ASSERT( call != NULL );

     if (direct_log_domain_check( &Fusion_Call )) // avoid call to direct_trace_lookup_symbol_at
          D_DEBUG_AT( Fusion_Call, "  -> %s\n", direct_trace_lookup_symbol_at( call->handler ) );

     D_ASSUME( serial != 0 );
     if (!serial)
          return DR_UNSUPPORTED;

     call_ret.call_id = call->call_id;
     call_ret.serial  = serial;
     call_ret.ptr     = ptr;
     call_ret.length  = length;

     fusion_world_flush_calls( _fusion_world( call->shared ), 1 );

     while (ioctl (_fusion_fd( call->shared ), FUSION_CALL_RETURN3, &call_ret)) {
          switch (errno) {
               case EINTR:
                    continue;
               case EIDRM:
                    D_WARN( "caller withdrawn (signal?)" );
                    return DR_NOCONTEXT;
               case EINVAL:
                    D_ERROR( "Fusion/Call: invalid call\n" );
                    return DR_DESTROYED;
               default:
                    break;
          }

          D_PERROR ("FUSION_CALL_RETURN3");

          return DR_FAILURE;
     }

     return DR_OK;
}
Exemple #27
0
void set_status_estorage_invalid()
{
	printf("\n\033[34m<<<<set_status_estorage_invalid\033[0m\n");
	char *penv;
	
	penv = getenv("PERSISTFS");
	if (penv == NULL)
		D_WARN("set_status_estorage_invalid: PERSISTFS is not set.");
	else if (strcmp(penv, EXT_STOR) == 0)
	{
		unsetenv("PERSISTFS");
		unsetenv("PERSISTFSSIZE");
		unsetenv("PERSISTFSSPEED");
	}
	
	s_status &= ~ESTORAGE_VALID;
}
static DFBResult
preallocStartTransfer( CoreSurfacePoolBridge   *bridge,
                       void                    *bridge_data,
                       void                    *bridge_local,
                       CoreSurfacePoolTransfer *transfer,
                       void                    *transfer_data )
{
     DFBResult               ret   = DFB_BUG;
     preallocPoolBridgeData *data  = bridge_data;
     CoreSurfaceAllocation  *from  = transfer->from;
     CoreSurfaceAllocation  *to    = transfer->to;
     CoreSurface            *surface;
     CoreSlave              *slave;

     D_DEBUG_AT( PreAlloc_Bridge, "%s()\n", __FUNCTION__ );

     D_ASSERT( bridge_data != NULL );
     D_ASSERT( transfer != NULL );

     CORE_SURFACE_BUFFER_ASSERT( transfer->buffer );

     surface = transfer->buffer->surface;
     CORE_SURFACE_ASSERT( surface );

     slave = Core_Resource_GetSlave( surface->object.identity );
     if (!slave) {
          D_WARN( "no slave object for id %lu", surface->object.identity );
          return DFB_NOIMPL;
     }

     if (from->pool == data->prealloc_pool) {
          if (to->pool->desc.access[CSAID_CPU] & CSAF_WRITE)
               ret = prealloc_transfer_locked( surface, transfer, to, CSAF_WRITE, slave );
          else
               ret = prealloc_transfer_readwrite( surface, transfer, to, CSAF_WRITE, slave );
     }
     else if (to->pool == data->prealloc_pool) {
          if (from->pool->desc.access[CSAID_CPU] & CSAF_READ)
               ret = prealloc_transfer_locked( surface, transfer, from, CSAF_READ, slave );
          else
               ret = prealloc_transfer_readwrite( surface, transfer, from, CSAF_READ, slave );
     }

     return ret;
}
Exemple #29
0
DFBResult
dfb_state_set_source_2( CardState   *state,
                        CoreSurface *source,
                        u32          flip_count )
{
     D_MAGIC_ASSERT( state, CardState );

     dfb_state_lock( state );

     if (state->source != source || state->source_flip_count != flip_count || !state->source_flip_count_used) {
          bool ref = true;//!fusion_config->secure_fusion || dfb_core_is_master( core_dfb );

          if (source && ref && dfb_surface_ref( source )) {
               D_WARN( "could not ref() source" );
               dfb_state_unlock( state );
               return DFB_DEAD;
          }

          if (state->source) {
               D_ASSERT( D_FLAGS_IS_SET( state->flags, CSF_SOURCE ) );
               if (ref)
                    dfb_surface_unref( state->source );
          }

          state->source    = source;
          state->modified |= SMF_SOURCE;


          state->source_flip_count      = flip_count;
          state->source_flip_count_used = true;


          if (source) {
               direct_serial_copy( &state->src_serial, &source->serial );

               D_FLAGS_SET( state->flags, CSF_SOURCE );
          }
          else
               D_FLAGS_CLEAR( state->flags, CSF_SOURCE );
     }

     dfb_state_unlock( state );

     return DFB_OK;
}
Exemple #30
0
void
direct_dbg_free( const char *file, int line, const char *func, const char *what, void *mem )
{
     unsigned long *val;
     MemDesc       *desc;

     if (!mem) {
          D_WARN( "%s (NULL) called", __FUNCTION__ );
          return;
     }

     val = (unsigned long*)((char*) mem - DISABLED_OFFSET);

     if (val[0] == ~0) {
          D_DEBUG_AT( Direct_Mem, "  - number of bytes of %s [%s:%d in %s()] -> %p\n", what, file, line, func, mem );

          val[0] = 0;
          direct_free( val );

          return;
     }


     /* Debug only. */
     direct_mutex_lock( &alloc_lock );

     desc = (MemDesc*)((char*) mem - sizeof(MemDesc));
     D_ASSERT( desc->mem == mem );

     if (direct_hash_remove( &alloc_hash, (unsigned long) mem )) {
          D_ERROR( "Direct/Mem: Not freeing unknown %p (%s) from [%s:%d in %s()] - corrupt/incomplete list?\n",
                   mem, what, file, line, func );
     }
     else {
          D_DEBUG_AT( Direct_Mem, "  -"_ZUn(6)" bytes [%s:%d in %s()] -> %p '%s'\n", desc->bytes, file, line, func, mem, what );

          if (desc->trace)
               direct_trace_free_buffer( desc->trace );

          direct_free( desc );
     }

     direct_mutex_unlock( &alloc_lock );
}