Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F161798594
D4316.id10594.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D4316.id10594.diff
View Options
Index: sys/dev/ofw/ofw_bus_subr.h
===================================================================
--- sys/dev/ofw/ofw_bus_subr.h
+++ sys/dev/ofw/ofw_bus_subr.h
@@ -110,4 +110,11 @@
/* Helper routine to find a device_t child matchig a given phandle_t */
device_t ofw_bus_find_child_device_by_phandle(device_t bus, phandle_t node);
+/* Helper routines for parsing lists */
+int ofw_bus_parse_xref_list_alloc(phandle_t , char *, char *, int ,
+ phandle_t *, int *, pcell_t **);
+int ofw_bus_find_string_index(phandle_t , char *, char *, int *);
+int ofw_bus_string_list_to_array(phandle_t node, char *list_name,
+ char ***array);
+
#endif /* !_DEV_OFW_OFW_BUS_SUBR_H_ */
Index: sys/dev/ofw/ofw_bus_subr.c
===================================================================
--- sys/dev/ofw/ofw_bus_subr.c
+++ sys/dev/ofw/ofw_bus_subr.c
@@ -593,3 +593,131 @@
return (retval);
}
+
+/*
+ * 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"
+ * Output arguments:
+ * producer - hande of producer
+ * ncells - number of cells in result
+ * cells - array of decoded cells
+ */
+int
+ofw_bus_parse_xref_list_alloc(phandle_t node, char *list_name, char *cells_name,
+ int idx, phandle_t *producer, int *ncells, pcell_t **cells)
+{
+ phandle_t pnode;
+ phandle_t *elems;
+ uint32_t pcells;
+ int rv, i, j, nelems, cnt;
+
+ elems = NULL;
+ nelems = OF_getencprop_alloc(node, list_name, sizeof(*elems),
+ (void **)&elems);
+ if (nelems <= 0)
+ return (ENOENT);
+ rv = ENOENT;
+ for (i = 0, cnt = 0; i < nelems; i += pcells, cnt++) {
+ pnode = elems[i++];
+ if (OF_searchencprop(OF_node_from_xref(pnode),
+ cells_name, &pcells, sizeof(pcells)) == -1) {
+ printf("Missing %s property\n", cells_name);
+ rv = ENOENT;
+ break;
+ }
+
+ if ((i + pcells) > nelems) {
+ printf("Invalid %s property value <%d>\n", cells_name,
+ pcells);
+ rv = ERANGE;
+ break;
+ }
+ if (cnt == idx) {
+ *cells= malloc(pcells * sizeof(**cells), M_OFWPROP,
+ M_WAITOK);
+ *producer = pnode;
+ *ncells = pcells;
+ for (j = 0; j < pcells; j++)
+ (*cells)[j] = elems[i + j];
+ rv = 0;
+ break;
+ }
+ }
+ if (elems != NULL)
+ free(elems, M_OFWPROP);
+ return (rv);
+}
+
+/*
+ * Find index of string in string list property (case sensitive).
+ */
+int
+ofw_bus_find_string_index(phandle_t node, char *list_name, char *name, int *idx)
+{
+ char *elems;
+ int rv, i, cnt, nelems;
+
+ elems = NULL;
+ nelems = OF_getprop_alloc(node, list_name, 1, (void **)&elems);
+ if (nelems <= 0)
+ return (ENOENT);
+
+ rv = ENOENT;
+ for (i = 0, cnt = 0; i < nelems; cnt++) {
+ if (strcmp(elems + i, name) == 0) {
+ *idx = cnt;
+ rv = 0;
+ break;
+ }
+ i += strlen(elems + i) + 1;
+ }
+
+ if (elems != NULL)
+ free(elems, M_OFWPROP);
+ return (rv);
+}
+
+/*
+ * Create zero terminated array of strings from string list property.
+ */
+int
+ofw_bus_string_list_to_array(phandle_t node, char *list_name, char ***array)
+{
+ char *elems, *tptr;
+ int i, cnt, nelems, len;
+
+ elems = NULL;
+ nelems = OF_getprop_alloc(node, list_name, 1, (void **)&elems);
+ if (nelems <= 0)
+ return (nelems);
+
+ /* Count number of strings. */
+ for (i = 0, cnt = 0; i < nelems; cnt++)
+ i += strlen(elems + i) + 1;
+
+ /* Allocate space for arrays and all strings. */
+ *array = malloc((cnt + 1) * sizeof(char *) + nelems, M_OFWPROP,
+ M_WAITOK);
+
+ /* Get address of first string. */
+ tptr = (char *)(*array + cnt);
+
+ /* Copy strings. */
+ memcpy(tptr, elems, nelems);
+ free(elems, M_OFWPROP);
+
+ /* Fill string pointers. */
+ for (i = 0, cnt = 0; i < nelems; cnt++) {
+ len = strlen(tptr + i) + 1;
+ *array[cnt] = tptr;
+ i += len;
+ tptr += len;
+ }
+ *array[cnt] = 0;
+
+ return (cnt);
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Jul 7, 11:17 PM (5 h, 25 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
34817356
Default Alt Text
D4316.id10594.diff (3 KB)
Attached To
Mode
D4316: OFW: Add helper functions for parsing xref based lists.
Attached
Detach File
Event Timeline
Log In to Comment