Module Name:    src
Committed By:   hkenken
Date:           Fri Jun 14 11:08:18 UTC 2019

Modified Files:
        src/sys/dev/fdt: fdt_intr.c fdt_subr.c fdtvar.h

Log Message:
Add support "interrupts-extended".

* fdtbus_get_phandle_with_data().
  Add utility subroutine to get phandle with data.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/dev/fdt/fdt_intr.c
cvs rdiff -u -r1.29 -r1.30 src/sys/dev/fdt/fdt_subr.c
cvs rdiff -u -r1.51 -r1.52 src/sys/dev/fdt/fdtvar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/fdt/fdt_intr.c
diff -u src/sys/dev/fdt/fdt_intr.c:1.21 src/sys/dev/fdt/fdt_intr.c:1.22
--- src/sys/dev/fdt/fdt_intr.c:1.21	Wed Feb 27 17:01:57 2019
+++ src/sys/dev/fdt/fdt_intr.c	Fri Jun 14 11:08:18 2019
@@ -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 <jmcne...@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 @@ done:
 	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;

Index: src/sys/dev/fdt/fdt_subr.c
diff -u src/sys/dev/fdt/fdt_subr.c:1.29 src/sys/dev/fdt/fdt_subr.c:1.30
--- src/sys/dev/fdt/fdt_subr.c:1.29	Wed Feb 27 16:56:00 2019
+++ src/sys/dev/fdt/fdt_subr.c	Fri Jun 14 11:08:18 2019
@@ -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 <jmcne...@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 @@ fdtbus_get_phandle(int phandle, const ch
 }
 
 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);

Index: src/sys/dev/fdt/fdtvar.h
diff -u src/sys/dev/fdt/fdtvar.h:1.51 src/sys/dev/fdt/fdtvar.h:1.52
--- src/sys/dev/fdt/fdtvar.h:1.51	Wed May  8 13:40:18 2019
+++ src/sys/dev/fdt/fdtvar.h	Fri Jun 14 11:08:18 2019
@@ -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 <jmcne...@invisible.ca>
@@ -232,6 +232,12 @@ struct fdt_console_info {
 	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 @@ int		fdtbus_get_reg_byname(int, const ch
 		    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 *);

Reply via email to