Changeset View
Changeset View
Standalone View
Standalone View
head/sys/dev/ofw/ofw_bus_subr.c
Show First 20 Lines • Show All 623 Lines • ▼ Show 20 Lines | |||||
/* | /* | ||||
* Parse property that contain list of xrefs and values | * Parse property that contain list of xrefs and values | ||||
* (like standard "clocks" and "resets" properties) | * (like standard "clocks" and "resets" properties) | ||||
* Input arguments: | * Input arguments: | ||||
* node - consumers device node | * node - consumers device node | ||||
* list_name - name of parsed list - "clocks" | * list_name - name of parsed list - "clocks" | ||||
* cells_name - name of size property - "#clock-cells" | * cells_name - name of size property - "#clock-cells" | ||||
* idx - the index of the requested list entry, or, if -1, an indication | |||||
* to return the number of entries in the parsed list. | |||||
* Output arguments: | * Output arguments: | ||||
* producer - handle of producer | * producer - handle of producer | ||||
* ncells - number of cells in result | * ncells - number of cells in result or the number of items in the list when | ||||
* idx == -1. | |||||
* cells - array of decoded cells | * cells - array of decoded cells | ||||
*/ | */ | ||||
int | static int | ||||
ofw_bus_parse_xref_list_alloc(phandle_t node, const char *list_name, | ofw_bus_parse_xref_list_internal(phandle_t node, const char *list_name, | ||||
const char *cells_name, int idx, phandle_t *producer, int *ncells, | const char *cells_name, int idx, phandle_t *producer, int *ncells, | ||||
pcell_t **cells) | pcell_t **cells) | ||||
{ | { | ||||
phandle_t pnode; | phandle_t pnode; | ||||
phandle_t *elems; | phandle_t *elems; | ||||
uint32_t pcells; | uint32_t pcells; | ||||
int rv, i, j, nelems, cnt; | int rv, i, j, nelems, cnt; | ||||
elems = NULL; | elems = NULL; | ||||
nelems = OF_getencprop_alloc(node, list_name, sizeof(*elems), | nelems = OF_getencprop_alloc(node, list_name, sizeof(*elems), | ||||
(void **)&elems); | (void **)&elems); | ||||
if (nelems <= 0) | if (nelems <= 0) | ||||
return (ENOENT); | return (ENOENT); | ||||
rv = ENOENT; | rv = (idx == -1) ? 0 : ENOENT; | ||||
for (i = 0, cnt = 0; i < nelems; i += pcells, cnt++) { | for (i = 0, cnt = 0; i < nelems; i += pcells, cnt++) { | ||||
pnode = elems[i++]; | pnode = elems[i++]; | ||||
if (OF_getencprop(OF_node_from_xref(pnode), | if (OF_getencprop(OF_node_from_xref(pnode), | ||||
cells_name, &pcells, sizeof(pcells)) == -1) { | cells_name, &pcells, sizeof(pcells)) == -1) { | ||||
printf("Missing %s property\n", cells_name); | printf("Missing %s property\n", cells_name); | ||||
rv = ENOENT; | rv = ENOENT; | ||||
break; | break; | ||||
} | } | ||||
Show All 12 Lines | if (cnt == idx) { | ||||
for (j = 0; j < pcells; j++) | for (j = 0; j < pcells; j++) | ||||
(*cells)[j] = elems[i + j]; | (*cells)[j] = elems[i + j]; | ||||
rv = 0; | rv = 0; | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
if (elems != NULL) | if (elems != NULL) | ||||
free(elems, M_OFWPROP); | free(elems, M_OFWPROP); | ||||
if (idx == -1 && rv == 0) | |||||
*ncells = cnt; | |||||
return (rv); | return (rv); | ||||
} | |||||
/* | |||||
* Parse property that contain list of xrefs and values | |||||
* (like standard "clocks" and "resets" properties) | |||||
* Input arguments: | |||||
* node - consumers device node | |||||
* list_name - name of parsed list - "clocks" | |||||
* cells_name - name of size property - "#clock-cells" | |||||
* idx - the index of the requested list entry (>= 0) | |||||
* Output arguments: | |||||
* producer - handle of producer | |||||
* ncells - number of cells in result | |||||
* cells - array of decoded cells | |||||
*/ | |||||
int | |||||
ofw_bus_parse_xref_list_alloc(phandle_t node, const char *list_name, | |||||
const char *cells_name, int idx, phandle_t *producer, int *ncells, | |||||
pcell_t **cells) | |||||
{ | |||||
KASSERT(idx >= 0, | |||||
("ofw_bus_parse_xref_list_alloc: negative index supplied")); | |||||
return (ofw_bus_parse_xref_list_internal(node, list_name, cells_name, | |||||
idx, producer, ncells, cells)); | |||||
} | |||||
/* | |||||
* Parse property that contain list of xrefs and values | |||||
* (like standard "clocks" and "resets" properties) | |||||
* and determine the number of items in the list | |||||
* Input arguments: | |||||
* node - consumers device node | |||||
* list_name - name of parsed list - "clocks" | |||||
* cells_name - name of size property - "#clock-cells" | |||||
* Output arguments: | |||||
* count - number of items in list | |||||
*/ | |||||
int | |||||
ofw_bus_parse_xref_list_get_length(phandle_t node, const char *list_name, | |||||
const char *cells_name, int *count) | |||||
{ | |||||
return (ofw_bus_parse_xref_list_internal(node, list_name, cells_name, | |||||
-1, NULL, count, NULL)); | |||||
} | } | ||||
/* | /* | ||||
* Find index of string in string list property (case sensitive). | * Find index of string in string list property (case sensitive). | ||||
*/ | */ | ||||
int | int | ||||
ofw_bus_find_string_index(phandle_t node, const char *list_name, | ofw_bus_find_string_index(phandle_t node, const char *list_name, | ||||
const char *name, int *idx) | const char *name, int *idx) | ||||
▲ Show 20 Lines • Show All 67 Lines • Show Last 20 Lines |