Add support "interrupts-extended". trunk
authorhkenken <hkenken@NetBSD.org>
Fri, 14 Jun 2019 11:08:18 +0000
branchtrunk
changeset 452002 73a5e7e68b89
parent 452001 959aad8a3b7b
child 452003 2d6d70d4519f
Add support "interrupts-extended". * fdtbus_get_phandle_with_data(). Add utility subroutine to get phandle with data.
sys/dev/fdt/fdt_intr.c
sys/dev/fdt/fdt_subr.c
sys/dev/fdt/fdtvar.h
--- a/sys/dev/fdt/fdt_intr.c	Fri Jun 14 09:23:42 2019 +0000
+++ b/sys/dev/fdt/fdt_intr.c	Fri Jun 14 11:08:18 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fdt_intr.c,v 1.21 2019/02/27 17:01:57 jakllsch Exp $ */
+/* $NetBSD: fdt_intr.c,v 1.22 2019/06/14 11:08:18 hkenken Exp $ */
 
 /*-
  * Copyright (c) 2015-2018 Jared McNeill <jmcneill@invisible.ca>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fdt_intr.c,v 1.21 2019/02/27 17:01:57 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdt_intr.c,v 1.22 2019/06/14 11:08:18 hkenken Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -322,12 +322,31 @@
 	return result;
 }
 
+
+static const u_int *
+get_specifier_from_extended(int phandle, int pindex, int *piphandle)
+{
+	const u_int *result = NULL;
+	struct fdt_phandle_data data;
+
+	if (fdtbus_get_phandle_with_data(phandle, "interrupts-extended",
+		"#interrupt-cells", pindex, &data) == 0) {
+		*piphandle = data.phandle;
+		result = data.values;
+	}
+
+	return result;
+}
+
 static const u_int *
 get_specifier_by_index(int phandle, int pindex, int *piphandle)
 {
 	const u_int *node_specifier;
 	int interrupt_parent, interrupt_cells, len;
 
+	if (of_hasprop(phandle, "interrupts-extended"))
+		return get_specifier_from_extended(phandle, pindex, piphandle);
+
 	interrupt_parent = fdtbus_get_interrupt_parent(phandle);
 	if (interrupt_parent <= 0)
 		return NULL;
--- a/sys/dev/fdt/fdt_subr.c	Fri Jun 14 09:23:42 2019 +0000
+++ b/sys/dev/fdt/fdt_subr.c	Fri Jun 14 11:08:18 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fdt_subr.c,v 1.29 2019/02/27 16:56:00 jakllsch Exp $ */
+/* $NetBSD: fdt_subr.c,v 1.30 2019/06/14 11:08:18 hkenken Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill <jmcneill@invisible.ca>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fdt_subr.c,v 1.29 2019/02/27 16:56:00 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdt_subr.c,v 1.30 2019/06/14 11:08:18 hkenken Exp $");
 
 #include "opt_fdt.h"
 
@@ -130,6 +130,42 @@
 }
 
 int
+fdtbus_get_phandle_with_data(int phandle, const char *prop, const char *cells,
+    int index, struct fdt_phandle_data *data)
+{
+	int len;
+	const int offset = 1;
+
+	const u_int *p = fdtbus_get_prop(phandle, prop, &len);
+	if (p == NULL || len <= 0)
+		return EINVAL;
+
+	for (int i = 0; len > 0; i++) {
+		u_int phandle_ref = be32toh(*p);
+		const u_int iparent = fdtbus_get_phandle_from_native(phandle_ref);
+		uint32_t cells_num;
+		of_getprop_uint32(iparent, cells, &cells_num);
+
+		if (index == i) {
+			if (data != NULL) {
+				data->phandle = iparent;
+				data->count = cells_num;
+				data->values = p + offset;
+			}
+			goto done;
+		}
+
+		const u_int reclen = offset + cells_num;
+		len -= reclen * sizeof(u_int);
+		p += reclen;
+	}
+	return EINVAL;
+
+done:
+	return 0;
+}
+
+int
 fdtbus_get_phandle_from_native(int phandle)
 {
 	const int off = fdt_node_offset_by_phandle(fdt_data, phandle);
--- a/sys/dev/fdt/fdtvar.h	Fri Jun 14 09:23:42 2019 +0000
+++ b/sys/dev/fdt/fdtvar.h	Fri Jun 14 11:08:18 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fdtvar.h,v 1.51 2019/05/08 13:40:18 isaki Exp $ */
+/* $NetBSD: fdtvar.h,v 1.52 2019/06/14 11:08:18 hkenken Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill <jmcneill@invisible.ca>
@@ -232,6 +232,12 @@
 	const struct fdt_console *ops;
 };
 
+struct fdt_phandle_data {
+	int phandle;
+	int count;
+	const u_int *values;
+};
+
 #define	_FDT_CONSOLE_REGISTER(name)	\
 	__link_set_add_rodata(fdt_consoles, __CONCAT(name,_consinfo));
 
@@ -278,6 +284,8 @@
 		    bus_size_t *);
 int		fdtbus_get_reg64(int, u_int, uint64_t *, uint64_t *);
 int		fdtbus_get_phandle(int, const char *);
+int		fdtbus_get_phandle_with_data(int, const char *, const char *,
+		    int, struct fdt_phandle_data *);
 int		fdtbus_get_phandle_from_native(int);
 i2c_tag_t	fdtbus_get_i2c_tag(int);
 i2c_tag_t	fdtbus_i2c_acquire(int, const char *);