Example #1
0
void usb_init(void)
{
	USBCON |= 1 << FRZCLK;		/* freeze the clock */

	/* enable the PLL and wait for it to lock */
#if (F_CPU == 16000000UL)
	PLLCSR = ( (0 << PLLP2 | 0 << PLLP1) | (1 << PLLP0) |
		   1 << PLLE );
#elif (F_CPU == 8000000UL)
	PLLCSR = ( (0 << PLLP2 | 0 << PLLP1) | (0 << PLLP0) |
		   1 << PLLE );
#else
#error unsupported F_CPU value
#endif

	while (!(PLLCSR & (1 << PLOCK)));

	USBCON &= ~(1 << USBE);		/* reset the controller */
	USBCON |= 1 << USBE;

	USBCON &= ~(1 << FRZCLK);	/* thaw the clock */

	UDCON &= ~(1 << DETACH);	/* attach the pull-up */
	UDIEN = 1 << EORSTE;		/* enable device interrupts  */
//	UDCON |= 1 << RSTCPU;		/* reset CPU on bus reset */

	ep_init();
}
Example #2
0
/**
 * main: Get 10 new unique ids. Remove two. Look up removed ids.
 * Passes if lookups don't find anything,
 * otherwise fails.
 *
 * Return value: 0 on success, 1 on failure
 **/
int main(int argc, char **argv)
{
	SaHpiEntityPathT ep, rep;
	guint id[10], i;

	if (oh_uid_initialize())
		return 1;

	ep_init(&ep);

        for (i = 0; i < 10; i++) {
                ep.Entry[0].EntityInstance = i;
                id[i] = oh_uid_from_entity_path(&ep);
        }

        if (oh_uid_remove(id[8]))
                return 1;

        if (oh_uid_remove(id[3]))
                return 1;

        if (!oh_entity_path_lookup(id+8,&rep))
                return 1;

        if (!oh_entity_path_lookup(id+3,&rep))
                return 1;

	return 0;
}
Example #3
0
effect_t gs_create_effect(const char *effect_string, const char *filename,
		char **error_string)
{
	if (!thread_graphics || !effect_string)
		return NULL;

	struct gs_effect *effect = bzalloc(sizeof(struct gs_effect));
	struct effect_parser parser;
	bool success;

	effect->graphics = thread_graphics;

	ep_init(&parser);
	success = ep_parse(&parser, effect, effect_string, filename);
	if (!success) {
		if (error_string)
			*error_string = error_data_buildstring(
					&parser.cfp.error_list);
		effect_destroy(effect);
		effect = NULL;
	}

	ep_free(&parser);
	return effect;
}
Example #4
0
/**
 * main: Get 10 new unique ids. Remove two. Look up removed ids by ep.
 * Passes if lookups don't find anything,
 * otherwise fails.
 *
 * Return value: 0 on success, 1 on failure
 **/
int main(int argc, char **argv)
{
	SaHpiEntityPathT ep;
	guint id[10], i;

	if (oh_uid_initialize())
		return 1;

	ep_init(&ep);

        for (i = 0; i < 10; i++) {
                ep.Entry[0].EntityLocation = i;
                id[i] = oh_uid_from_entity_path(&ep);
        }

        if (oh_uid_remove(id[9]))
                return 1;

        if (oh_uid_remove(id[4]))
                return 1;

        ep.Entry[0].EntityLocation = 9;
        if (oh_uid_lookup(&ep))
                return 1;

        ep.Entry[0].EntityLocation = 4;
        if (oh_uid_lookup(&ep))
                return 1;

	return 0;
}
Example #5
0
/**
 * main: Calls oh_entity_path_lookup using a NULL id.
 * Passes if it returns -1,
 * otherwise fails.
 *
 * Return value: 0 on success, 1 on failure
 **/
int main(int argc, char **argv)
{
        SaHpiEntityPathT ep, rep;

        ep_init(&ep);

	if (oh_uid_initialize())
		return 1;

        if (!oh_uid_from_entity_path(&ep))
                return 1;

        if (!oh_entity_path_lookup(NULL, &rep))
                return 1;

        return 0;
}
Example #6
0
void
main_init()
{
    REVCTL = bmNOAUTOARM | bmSKIPCOMMIT;
    SYNCDELAY;
    SETCPUFREQ(CLK_48M);
    SYNCDELAY;
    
    printf("main_init\r\n");

    ep_init();
    gpif_stuff_init();
    fpga_init();
    
    /* timer2 */
    CKCON &= ~(1<<5);
    T2CON = (1<<2); /* run timer 2 in auto reload mode */
}
Example #7
0
/********************
 * plugin_init
 ********************/
static void
plugin_init(OhmPlugin *plugin)
{
    if (!OHM_DEBUG_INIT(vibra))
        OHM_WARNING("vibra: failed to register for debugging");
    
    if (signaling_register == NULL || signaling_unregister == NULL) {
        OHM_ERROR("vibra: signaling interface not available");
        exit(1);
    }

    select_driver(&context, plugin);
    
    ep_init(&context, signaling_register);
    context.driver->init(&context, plugin);
    
    OHM_INFO("vibra: plugin ready...");
}
Example #8
0
/**
 * main: Get a new unique id. Get another one with the same entity path.
 * Passes if returned id is equal to previous one,
 * otherwise fails.
 *
 * Return value: 0 on success, 1 on failure
 **/
int main(int argc, char **argv)
{
    SaHpiEntityPathT ep;
    guint id, rid;

    if (oh_uid_initialize())
        return 1;

    ep_init(&ep);

    id = oh_uid_from_entity_path(&ep);
    rid = oh_uid_from_entity_path(&ep);

    if (id != rid)
        return 1;

    return 0;
}
Example #9
0
/**
 * main: Calls oh_entity_path_lookup using a NULL entity path.
 * Passes if it returns -1,
 * otherwise fails.
 *
 * Return value: 0 on success, 1 on failure
 **/
int main(int argc, char **argv)
{
        SaHpiEntityPathT ep;
        guint id;

        ep_init(&ep);

	if (oh_uid_initialize())
		return 1;

        id = oh_uid_from_entity_path(&ep);
        if (!id)
                return 1;

        if (!oh_entity_path_lookup(&id, NULL))
                return 1;

        return 0;
}
Example #10
0
/**
 * oh_uid_lookup
 * @ep: pointer to entity path used to identify resourceID/uid
 *
 * Fetches resourceID/uid based on entity path in @ep.
 *  
 * Returns: success returns resourceID/uid, failure is 0.
 **/
guint oh_uid_lookup(SaHpiEntityPathT *ep)
{
        EP_XREF *ep_xref;
	SaHpiEntityPathT entitypath;
        gpointer key;

        if (!ep) return 0;
        
	ep_init(&entitypath);
	ep_concat(&entitypath, ep);
	key = &entitypath;
        
        /* check hash table for entry in ep_hash_table */ 
        ep_xref = (EP_XREF *)g_hash_table_lookup (ep_hash_table, key);
        if(!ep_xref) {
                dbg("error looking up EP to get uid");
                return 0;
        }

        return(ep_xref->resource_id);
}
Example #11
0
/* Disables endpoint, is called by gadget driver */
static int udc_ep_disable(struct usb_ep *usbep)
{
	struct udc_ep	*ep = NULL;
	unsigned long	iflags;

	if (!usbep)
		return -EINVAL;

	ep = container_of(usbep, struct udc_ep, ep);
	if (usbep->name == ep0_string || !ep->ep.desc)
		return -EINVAL;

	DBG(ep->dev, "Disable ep-%d\n", ep->num);

	spin_lock_irqsave(&ep->dev->lock, iflags);
	udc_free_request(&ep->ep, &ep->bna_dummy_req->req);
	empty_req_queue(ep);
	ep_init(ep->dev->regs, ep);
	spin_unlock_irqrestore(&ep->dev->lock, iflags);

	return 0;
}
/********************
 * plugin_init
 ********************/
static void
plugin_init(OhmPlugin *plugin)
{
    if (!OHM_DEBUG_INIT(backlight))
        OHM_WARNING("backlight: failed to register for debugging");
    
    if (signaling_register == NULL || signaling_unregister == NULL) {
        OHM_ERROR("backlight: signaling interface not available");
        exit(1);
    }

    context.resolve      = resolve;
    context.process_info = process_info;
    
    BACKLIGHT_SAVE_STATE(&context, "off");

    ep_init(&context, signaling_register);

    select_driver(&context, plugin);
    context.driver->init(&context, plugin);
    
    OHM_INFO("backlight: plugin ready...");
}
Example #13
0
/**
 * string2entitypath
 * @epathstr: IN. Pointer to canonical entity path string
 * @epathptr: OUT. Pointer to HPI's entity path structure
 *
 * Converts an entity path canonical string into a
 * SaHpiEntityPathT structure.
 * 
 * Returns: 0 Successful return, -1 Error return
 */
int string2entitypath(const gchar *epathstr, SaHpiEntityPathT *epathptr)
{

	gchar  **epathdefs = NULL, **epathvalues = NULL;
	gchar  *gstr = NULL, *etype = NULL, *einstance = NULL, *endptr = NULL;
        gint rtncode = 0;
	guint   i, j, match, instance, num_valid_entities = 0;
        GSList *epath_list = NULL, *lst = NULL;
	SaHpiEntityT  *entityptr = NULL;
        gint num = 0;
        int is_numeric = 0;
        
	if (epathstr == NULL || epathstr[0] == '\0') {
		dbg("Input entity path string is NULL"); 
		return -1;
	}

        /* Split out {xxx,yyy} definition pairs */
       	gstr = g_strstrip(g_strdup(epathstr));
	if (gstr == NULL || gstr[0] == '\0') {
		dbg("Stripped entity path string is NULL"); 
		rtncode = -1;
		goto CLEANUP;
	}
	epathdefs = g_strsplit(gstr, EPATHSTRING_END_DELIMITER, -1);
	if (epathdefs == NULL) {
		dbg("Could not split entity path string.");
		rtncode = -1;
		goto CLEANUP;
        }

	/* Split out HPI entity type and instance strings */
	for (i=0; epathdefs[i] != NULL && epathdefs[i][0] != '\0'; i++) {

		epathdefs[i] = g_strstrip(epathdefs[i]);
		/* Check format - for starting delimiter and a comma */
		if ((epathdefs[i][0] != EPATHSTRING_START_DELIMITER_CHAR) || 
		    (strpbrk(epathdefs[i], EPATHSTRING_VALUE_DELIMITER) == NULL)) {
			dbg("Invalid entity path format.");
			rtncode = -1;
			goto CLEANUP;
		}

		epathvalues = g_strsplit(epathdefs[i],
                                         EPATHSTRING_VALUE_DELIMITER,
                                         ELEMENTS_IN_SaHpiEntityT);
		epathvalues[0] = g_strdelimit(epathvalues[0], EPATHSTRING_START_DELIMITER, ' ');

		etype = g_strstrip(epathvalues[0]);
		einstance = g_strstrip(epathvalues[1]);

		instance = strtol(einstance, &endptr, 10);
		if (endptr[0] != '\0') { 
			dbg("Invalid instance character"); 
			rtncode = -1; 
			goto CLEANUP;
                }

		for (match=0, j=0; j < ESHORTNAMES_ARRAY_SIZE + 1; j++) {
			if (!strcmp(eshort_names[j], etype)) {
				match = 1;
				break;
			}
		}
                
                is_numeric = 0;

		if (!match) { 
                        // check for numeric type
                        num = strtol(etype,&endptr, 0);

                        if (num <= 0 || endptr[0] != '\0') {
                                dbg("Invalid entity type string"); 
                                rtncode = -1; 
                                goto CLEANUP;
                        }
                        
                        is_numeric = 1;
		}

		/* Save entity path definitions; reverse order */
		if (num_valid_entities < SAHPI_MAX_ENTITY_PATH) {
			entityptr = (SaHpiEntityT *)g_malloc0(sizeof(*entityptr));
			if (entityptr == NULL) { 
				dbg("Out of memory"); 
				rtncode = -1; 
				goto CLEANUP;
			}

                        if (is_numeric)
                                entityptr->EntityType = num;
                        else
                                entityptr->EntityType = index2entitytype(j);

			entityptr->EntityInstance = instance;
			epath_list = g_slist_prepend(epath_list, (gpointer)entityptr);
		}

		num_valid_entities++; 
	}  
  
	/* Initialize and write HPI entity path structure */
	ep_init(epathptr);

	for (i = 0; epath_list != NULL; i++) {
                lst = epath_list;
                if (i < SAHPI_MAX_ENTITY_PATH) {
                        epathptr->Entry[i].EntityType = 
                                ((SaHpiEntityT *)(lst->data))->EntityType;
                        epathptr->Entry[i].EntityInstance = 
                                ((SaHpiEntityT *)(lst->data))->EntityInstance;
                }
                epath_list = g_slist_remove_link(epath_list,lst);
                g_free(lst->data);
		g_slist_free(lst);
	}

	if (num_valid_entities > SAHPI_MAX_ENTITY_PATH) {
		dbg("Too many entity defs");
		rtncode = -1;
	}

 CLEANUP:
	g_free(gstr);
	g_strfreev(epathdefs);
	g_strfreev(epathvalues);
	g_slist_free(epath_list);

	return(rtncode);
} /* End string2entitypath */
Example #14
0
/* End of Reset interrupt handler. Gets triggered at the end of a bus reset */
void intp_eor()
{
	EOR_INT_CLR();
	ep_init();
}
Example #15
0
/**
 * oh_uid_from_entity_path
 * @ep: value to be removed from used
 *
 * This function returns an unique value to be used as
 * an uid/resourceID base upon a unique entity path specified
 * by @ep.  If the entity path already exists, the already assigned 
 * resource id is returned.  Before returning, this call updates the
 * uid map file saved on disk.  
 * 
 * Returns: positive unsigned int, failure is 0.
 **/
guint oh_uid_from_entity_path(SaHpiEntityPathT *ep) 
{
        gpointer key;
	gpointer value;

        EP_XREF *ep_xref;

        char *uid_map_file;
        int file;
	
	SaHpiEntityPathT entitypath;

        if (!ep) return 0;
	
	ep_init(&entitypath);
	ep_concat(&entitypath,ep);
	key = &entitypath;

        /* check for presence of EP and */
        /* previously assigned uid      */
        ep_xref = (EP_XREF *)g_hash_table_lookup (ep_hash_table, key);
        if (ep_xref) {
                /*dbg("Entity Path already assigned uid. Use oh_uid_lookup().");*/
                return ep_xref->resource_id;
        }

        /* allocate storage for EP cross reference data structure*/
        ep_xref = (EP_XREF *)g_malloc0(sizeof(EP_XREF));
        if(!ep_xref) { 
                dbg("malloc failed");
                return 0;
        }

        memset(ep_xref, 0, sizeof(EP_XREF));
        memcpy(&ep_xref->entity_path, &entitypath, sizeof(SaHpiEntityPathT));

        ep_xref->resource_id = resource_id;
        resource_id++;

        value = (gpointer)ep_xref;

        /* entity path based key */   
        key = (gpointer)&ep_xref->entity_path; 
        g_hash_table_insert(ep_hash_table, key, value);

        /* resource id based key */
        key = (gpointer)&ep_xref->resource_id;
        g_hash_table_insert(resource_id_hash_table, key, value);

        /* save newly created ep xref (iud/resource_id) to map file */
        uid_map_file = (char *)getenv("OPENHPI_UID_MAP");
        if (uid_map_file == NULL) {
                uid_map_file = OH_DEFAULT_UID_MAP;
        }
        file = open(uid_map_file, O_WRONLY);
        if(file >= 0) {
                lseek(file, 0, SEEK_END);
                write(file,ep_xref, sizeof(EP_XREF));
                lseek(file, 0, SEEK_SET);
                write(file, &resource_id, sizeof(resource_id));
        }

        close(file);

        return ep_xref->resource_id;
}               
Example #16
0
/**
 * snmp_bc_logsrc2rid:
 * @handle: Pointer to handler's data.
 * @src: Log's "Source" field string.
 * @res_info: Location to store HPI mapping data for resource
 * @ovr_flags: Override flags
 *
 * Translates error log's "Source" field into an HPI resource ID
 * and stores HPI mapping info needed by other routines in
 * @res_info. Assume "Source" field text is in the following format:
 *
 *   "BLADE_0x" - map to blade x RID
 *   "SWITCH_x" - map to switch x RID
 *
 * All other "Source" field text strings are mapped to the 
 * Chassis's resource ID.
 *
 * @ovr_flags is used to indicate exception cases. The only one
 * currently is to indicate if the resource is an expansion card.
 *
 * Return values:
 * SA_OK - normal case.
 * SA_ERR_HPI_INVALID_PARAMS - @handle, @src, or @resinfo is NULL.
 **/
static SaErrorT snmp_bc_logsrc2rid(struct oh_handler_state *handle,
				   gchar *src,
				   LogSource2ResourceT *resinfo,
				   unsigned short ovr_flags)
{
	int rpt_index;
	guint loc;
	gchar **src_parts = NULL, *endptr = NULL, *root_tuple;
	SaErrorT err;
	SaHpiBoolT isblade, isexpansioncard, ischassis, isswitch;
	SaHpiEntityPathT ep, ep_root;
	SaHpiEntityTypeT entity_type;
	struct snmp_bc_sensor *array_ptr;

	if (!handle || !src || !resinfo) {
		dbg("Invalid parameters.");
		return(SA_ERR_HPI_INVALID_PARAMS);
	}

	/* Find top-level chassis entity path */
        ep_init(&ep);
	ep_init(&ep_root);
	root_tuple = (gchar *)g_hash_table_lookup(handle->config, "entity_root");
        string2entitypath(root_tuple, &ep_root);
        
        /* Assume chassis location/type unless another resource type is discovered */
	loc = ep_root.Entry[0].EntityLocation;
	entity_type = ep_root.Entry[0].EntityType;

	/* Break down "Source" text string to find source's RPT index and location */
	src_parts = g_strsplit(src, "_", -1);
	if (src_parts == NULL) {
		dbg("Cannot split Source text string.");
		g_strfreev(src_parts);
		return(SA_ERR_HPI_INTERNAL_ERROR);
	}

	/* See if resource is something other than the chassis */
	isblade = isexpansioncard = isswitch = ischassis = SAHPI_FALSE;
	if (!strcmp(src_parts[0], "BLADE")) { 
		/* All expansion card events are reported as blade events in Error Log */
		if (ovr_flags & OVR_EXP) { isexpansioncard = SAHPI_TRUE; }
		else { isblade = SAHPI_TRUE; }
	}
	else {
		if (!strcmp(src_parts[0], "SWITCH")) { isswitch = SAHPI_TRUE; }
	}
	/* If not the chassis, find the location value from last part of log's source string */
	if (isexpansioncard == SAHPI_TRUE || isblade == SAHPI_TRUE || isswitch == SAHPI_TRUE) {
		loc = strtoul(src_parts[1], &endptr, 10);
		if (isexpansioncard == SAHPI_TRUE) {
			rpt_index = BC_RPT_ENTRY_BLADE_ADDIN_CARD;
			array_ptr = &snmp_bc_blade_addin_sensors[0];	
		}
		else {
			if (isblade == SAHPI_TRUE) { 
				rpt_index = BC_RPT_ENTRY_BLADE; 
				array_ptr = &snmp_bc_blade_sensors[0];
			}
			else { 
				rpt_index = BC_RPT_ENTRY_SWITCH_MODULE;
				array_ptr = &snmp_bc_switch_sensors[0];
			}
		}
		entity_type = snmp_rpt_array[rpt_index].rpt.ResourceEntity.Entry[0].EntityType;
	}
	else {
		ischassis = SAHPI_TRUE;
		rpt_index = BC_RPT_ENTRY_CHASSIS;
		array_ptr = &snmp_bc_chassis_sensors[0];
	}
	g_strfreev(src_parts);

	/* Find rest of Entity Path and calculate RID */
	err = ep_concat(&ep, &snmp_rpt_array[rpt_index].rpt.ResourceEntity);
	if (err) {
		dbg("Cannot concat Entity Path. Error=%s.", oh_lookup_error(err));
		return(SA_ERR_HPI_INTERNAL_ERROR);
	}
	err = ep_concat(&ep, &ep_root);
	if (err) {
		dbg("Cannot concat Entity Path. Error=%s.", oh_lookup_error(err));
		return(SA_ERR_HPI_INTERNAL_ERROR);
	}
	err = set_ep_instance(&ep, entity_type, loc);
	if (err) {
		dbg("Cannot set location. Type=%s; Location=%d; Error=%s.",
		    oh_lookup_entitytype(entity_type), loc, oh_lookup_error(err));
		return(SA_ERR_HPI_INTERNAL_ERROR);
	}
	
	/* Special case - if Expansion Card set location of parent blade as well */
	if (isexpansioncard == SAHPI_TRUE) {
		err = set_ep_instance(&ep, SAHPI_ENT_SBC_BLADE, loc);
		if (err) {
			dbg("Cannot set location. Type=%s; Location=%d; Error=%s.",
			    oh_lookup_entitytype(SAHPI_ENT_SBC_BLADE), loc, oh_lookup_error(err));  
			return(SA_ERR_HPI_INTERNAL_ERROR);
		}
	}

	/* Fill in RID and RPT table info about "Source" */
	resinfo->rpt = rpt_index;
	resinfo->sensor_array_ptr = array_ptr;
	resinfo->ep = ep;
	resinfo->rid = oh_uid_lookup(&ep);
	if (resinfo->rid == 0) {
		dbg("No RID");
		return(SA_ERR_HPI_INTERNAL_ERROR);
	}
	
	return(SA_OK);
}