Esempio n. 1
0
/**
 * acquire_phb
 *
 */
static int acquire_phb(char *drc_name, struct dr_node **phb)
{
    struct dr_connector drc;
    struct of_node *of_nodes;
    char path[DR_PATH_MAX];
    int rc;

    rc = get_drc_by_name(drc_name, &drc, path, OFDT_BASE);
    if (rc) {
        say(ERROR, "Could not find drc index for %s, unable to add the"
            "PHB.\n", drc_name);
        return rc;
    }

    rc = acquire_drc(drc.index);
    if (rc)
        return rc;

    of_nodes = configure_connector(drc.index);
    if (of_nodes == NULL) {
        release_drc(drc.index, PHB_DEV);
        return -1;
    }

    rc = add_device_tree_nodes(path, of_nodes);
    free_of_node(of_nodes);
    if (rc) {
        say(ERROR, "add_device_tree_nodes failed at %s\n", path);
        release_drc(drc.index, PHB_DEV);
        return -1;
    }

    /* Now that the node has been added to the device-tree, retrieve it.
     * This also acts as a sanity check that everything up to this
     * point has succeeded.
     */
    *phb = get_node_by_name(drc_name, PHB_NODES);
    if (*phb == NULL) {
        say(ERROR, "Could not get find \"%s\"\n", drc_name);
        /* or should we call release_drc? but need device type */
        release_drc(drc.index, PHB_DEV);
        return -1;
    }

    return 0;
}
Esempio n. 2
0
/**
 * get_drc_by_name
 * @brief Retrieve a dr_connector with the specified drc_name
 *
 * This routine searches the drc lists for a dr_connector with the
 * specified name starting at the specified directory.  If a dr_connector
 * is found the root_dir that the dr_connector was found in is also
 * filled out.
 *
 * @param drc_name name of the dr_connector to search for
 * @param drc pointer to a drc to point to the found dr_connector
 * @param root_dir pointer to buf to fill in with root directory
 * @param start_dir, directory to start searching
 * @returns 0 on success (drc and root_dir filled in), !0 on failure
 */
int
get_drc_by_name(char *drc_name, struct dr_connector *drc, char *root_dir,
		char *start_dir)
{
        struct dr_connector *drc_list = NULL;
        struct dr_connector *drc_entry;
	struct dirent *de;
	DIR *d;
        int rc = -1;

	memset(drc, 0, sizeof(*drc));

	/* Try to get the drc in this directory */
        drc_list = get_drc_info(start_dir);
        if (drc_list == NULL)
		return -1;

	drc_entry = search_drc_list(drc_list, NULL, DRC_NAME, drc_name);
	if (drc_entry != NULL) {
		memcpy(drc, drc_entry, sizeof(*drc));
		sprintf(root_dir, "%s", start_dir);
                return 0;
        }

	/* If we didn't find it here, check the subdirs */
	d = opendir(start_dir);
	if (d == NULL)
		return -1;

	while ((de = readdir(d)) != NULL) {
		char dir_path[DR_PATH_MAX];

		if ((de->d_type != DT_DIR) || is_dot_dir(de->d_name))
			continue;

		sprintf(dir_path, "%s/%s", start_dir, de->d_name);
		rc = get_drc_by_name(drc_name, drc, root_dir, dir_path);
		if (rc == 0)
			break;
	}
	closedir(d);

	return rc;
}