Skip to content

Commit b1078c3

Browse files
Michal Simekgregkh
authored andcommitted
of: base: Introduce of_alias_get_alias_list() to check alias IDs
The function travels the lookup table to record alias ids for the given device match structures and alias stem. This function will be used by serial drivers to check if requested alias is allocated or free to use. Signed-off-by: Michal Simek <michal.simek@xilinx.com> Reviewed-by: Rob Herring <robh@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 13b4353 commit b1078c3

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

drivers/of/base.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#define pr_fmt(fmt) "OF: " fmt
1818

19+
#include <linux/bitmap.h>
1920
#include <linux/console.h>
2021
#include <linux/ctype.h>
2122
#include <linux/cpu.h>
@@ -1942,6 +1943,57 @@ int of_alias_get_id(struct device_node *np, const char *stem)
19421943
}
19431944
EXPORT_SYMBOL_GPL(of_alias_get_id);
19441945

1946+
/**
1947+
* of_alias_get_alias_list - Get alias list for the given device driver
1948+
* @matches: Array of OF device match structures to search in
1949+
* @stem: Alias stem of the given device_node
1950+
* @bitmap: Bitmap field pointer
1951+
* @nbits: Maximum number of alias ID which can be recorded it bitmap
1952+
*
1953+
* The function travels the lookup table to record alias ids for the given
1954+
* device match structures and alias stem.
1955+
*
1956+
* Return: 0 or -ENOSYS when !CONFIG_OF
1957+
*/
1958+
int of_alias_get_alias_list(const struct of_device_id *matches,
1959+
const char *stem, unsigned long *bitmap,
1960+
unsigned int nbits)
1961+
{
1962+
struct alias_prop *app;
1963+
1964+
/* Zero bitmap field to make sure that all the time it is clean */
1965+
bitmap_zero(bitmap, nbits);
1966+
1967+
mutex_lock(&of_mutex);
1968+
pr_debug("%s: Looking for stem: %s\n", __func__, stem);
1969+
list_for_each_entry(app, &aliases_lookup, link) {
1970+
pr_debug("%s: stem: %s, id: %d\n",
1971+
__func__, app->stem, app->id);
1972+
1973+
if (strcmp(app->stem, stem) != 0) {
1974+
pr_debug("%s: stem comparison doesn't passed %s\n",
1975+
__func__, app->stem);
1976+
continue;
1977+
}
1978+
1979+
if (app->id >= nbits) {
1980+
pr_debug("%s: ID %d greater then bitmap field %d\n",
1981+
__func__, app->id, nbits);
1982+
continue;
1983+
}
1984+
1985+
if (of_match_node(matches, app->np)) {
1986+
pr_debug("%s: Allocated ID %d\n", __func__, app->id);
1987+
set_bit(app->id, bitmap);
1988+
}
1989+
/* Alias exist but it not compatible with matches */
1990+
}
1991+
mutex_unlock(&of_mutex);
1992+
1993+
return 0;
1994+
}
1995+
EXPORT_SYMBOL_GPL(of_alias_get_alias_list);
1996+
19451997
/**
19461998
* of_alias_get_highest_id - Get highest alias id for the given stem
19471999
* @stem: Alias stem to be examined

include/linux/of.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,9 @@ extern int of_phandle_iterator_args(struct of_phandle_iterator *it,
392392
extern void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align));
393393
extern int of_alias_get_id(struct device_node *np, const char *stem);
394394
extern int of_alias_get_highest_id(const char *stem);
395+
extern int of_alias_get_alias_list(const struct of_device_id *matches,
396+
const char *stem, unsigned long *bitmap,
397+
unsigned int nbits);
395398

396399
extern int of_machine_is_compatible(const char *compat);
397400

@@ -893,6 +896,13 @@ static inline int of_alias_get_highest_id(const char *stem)
893896
return -ENOSYS;
894897
}
895898

899+
static inline int of_alias_get_alias_list(const struct of_device_id *matches,
900+
const char *stem, unsigned long *bitmap,
901+
unsigned int nbits)
902+
{
903+
return -ENOSYS;
904+
}
905+
896906
static inline int of_machine_is_compatible(const char *compat)
897907
{
898908
return 0;

0 commit comments

Comments
 (0)