commit 3a7e77497d2dcf84b5d6525cdfb6e59dfea7ffbb Author: Haren Myneni Date: Fri Jun 21 15:40:56 2024 -0700 drmgr: Retrieve dr_connector with the specified DRC index search_drc_list() provides the search based on the key type such as DRC_NAME, DRC_TYPE, DRC_INDEX or DRC_POWERDOMAIN. But the current code has get_drc_by_index() which looks in to the DRC list passed to this function instead of all DRC lists and is not used right now. This patch modifies get_drc_by_index() and the corresponding changes such that it retrieves dr_connector with the specified DRC index as does in the case of get_drc_by_name(). Signed-off-by: Haren Myneni Signed-off-by: Tyrel Datwyler diff --git a/src/drmgr/common_ofdt.c b/src/drmgr/common_ofdt.c index 1d9b7e7..655c9d2 100644 --- a/src/drmgr/common_ofdt.c +++ b/src/drmgr/common_ofdt.c @@ -650,23 +650,24 @@ drc_index_to_name(uint32_t index, struct dr_connector *drc_list) } /** - * get_drc_by_name - * @brief Retrieve a dr_connector with the specified drc_name + * search_drc_by_key + * @brief Retrieve a dr_connector based on DRC name or DRC index * * 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. + * specified name or index 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 key to serach for the dr_connector * @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 + * @param key_type whether the key is DRC name or DRC index * @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) +search_drc_by_key(void *key, struct dr_connector *drc, char *root_dir, + char *start_dir, int key_type) { struct dr_connector *drc_list = NULL; struct dr_connector *drc_entry; @@ -681,7 +682,7 @@ get_drc_by_name(char *drc_name, struct dr_connector *drc, char *root_dir, if (drc_list == NULL) return -1; - drc_entry = search_drc_list(drc_list, NULL, DRC_NAME, drc_name); + drc_entry = search_drc_list(drc_list, NULL, key_type, key); if (drc_entry != NULL) { memcpy(drc, drc_entry, sizeof(*drc)); sprintf(root_dir, "%s", start_dir); @@ -700,7 +701,8 @@ get_drc_by_name(char *drc_name, struct dr_connector *drc, char *root_dir, continue; sprintf(dir_path, "%s/%s", start_dir, de->d_name); - rc = get_drc_by_name(drc_name, drc, root_dir, dir_path); + rc = search_drc_by_key(key, drc, root_dir, dir_path, + key_type); if (rc == 0) break; } @@ -709,17 +711,57 @@ get_drc_by_name(char *drc_name, struct dr_connector *drc, char *root_dir, return rc; } -struct dr_connector * -get_drc_by_index(uint32_t drc_index, struct dr_connector *drc_list) +/** + * 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; + int rc; - for (drc = drc_list; drc; drc = drc->next) { - if (drc->index == drc_index) - return drc; - } + rc = search_drc_by_key(drc_name, drc, root_dir, start_dir, DRC_NAME); - return NULL; + return rc; +} + +/** + * get_drc_by_index + * @brief Retrieve a dr_connector with the specified index + * + * This routine searches the drc lists for a dr_connector with the + * specified index 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 index 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_index(uint32_t index, struct dr_connector *drc, char *root_dir, + char *start_dir) +{ + int rc; + + rc = search_drc_by_key((void *)&index, drc, root_dir, start_dir, + DRC_INDEX); + + return rc; } /* diff --git a/src/drmgr/ofdt.h b/src/drmgr/ofdt.h index bd90810..6c1b961 100644 --- a/src/drmgr/ofdt.h +++ b/src/drmgr/ofdt.h @@ -177,6 +177,7 @@ int get_my_drc_index(char *, uint32_t *); int drc_name_to_index(const char *, struct dr_connector *); char * drc_index_to_name(uint32_t, struct dr_connector *); int get_drc_by_name(char *, struct dr_connector *, char *, char *); +int get_drc_by_index(uint32_t, struct dr_connector *, char *, char *); int get_min_common_depth(void); int get_assoc_arrays(const char *dir, struct assoc_arrays *aa,