summaryrefslogtreecommitdiff
path: root/sys/dev/ofw
diff options
context:
space:
mode:
authorthorpej <thorpej@NetBSD.org>2022-01-22 11:49:16 +0000
committerthorpej <thorpej@NetBSD.org>2022-01-22 11:49:16 +0000
commit09eb5c43f131a6790fa9b46f440dd5a2d4ae03ae (patch)
treeffdfd13d89a9bfa56433c400ad83033887f60a5f /sys/dev/ofw
parent1c2752a686271470f2f20bdba60a27d2b6d5b8a8 (diff)
Change the devhandle_from_*() functions to also take a "super handle",
from which the newly created handle will inherit it's implementation. The root implementation for a new handle type is used if an invalid "super handle" is passed.
Diffstat (limited to 'sys/dev/ofw')
-rw-r--r--sys/dev/ofw/ofbus.c12
-rw-r--r--sys/dev/ofw/ofw_pci_subr.c6
-rw-r--r--sys/dev/ofw/ofw_subr.c22
-rw-r--r--sys/dev/ofw/openfirm.h4
4 files changed, 27 insertions, 17 deletions
diff --git a/sys/dev/ofw/ofbus.c b/sys/dev/ofw/ofbus.c
index dfb07dcf003..2abf8f9341c 100644
--- a/sys/dev/ofw/ofbus.c
+++ b/sys/dev/ofw/ofbus.c
@@ -1,4 +1,4 @@
-/* $NetBSD: ofbus.c,v 1.30 2021/08/07 16:19:14 thorpej Exp $ */
+/* $NetBSD: ofbus.c,v 1.31 2022/01/22 11:49:18 thorpej Exp $ */
/*
* Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -32,7 +32,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ofbus.c,v 1.30 2021/08/07 16:19:14 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofbus.c,v 1.31 2022/01/22 11:49:18 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -159,6 +159,8 @@ ofbus_attach(device_t parent, device_t dev, void *aux)
units = 2;
}
+ devhandle_t selfh = device_handle(dev);
+
/* attach displays first */
for (child = OF_child(oba->oba_phandle); child != 0;
child = OF_peer(child)) {
@@ -181,7 +183,8 @@ ofbus_attach(device_t parent, device_t dev, void *aux)
sizeof(oba2.oba_ofname));
}
config_found(dev, &oba2, ofbus_print,
- CFARGS(.devhandle = devhandle_from_of(child)));
+ CFARGS(.devhandle = devhandle_from_of(selfh,
+ child)));
}
}
@@ -211,7 +214,8 @@ ofbus_attach(device_t parent, device_t dev, void *aux)
sizeof(oba2.oba_ofname));
}
config_found(dev, &oba2, ofbus_print,
- CFARGS(.devhandle = devhandle_from_of(child)));
+ CFARGS(.devhandle = devhandle_from_of(selfh,
+ child)));
}
}
}
diff --git a/sys/dev/ofw/ofw_pci_subr.c b/sys/dev/ofw/ofw_pci_subr.c
index 0671befc1e6..f658e79bff8 100644
--- a/sys/dev/ofw/ofw_pci_subr.c
+++ b/sys/dev/ofw/ofw_pci_subr.c
@@ -1,4 +1,4 @@
-/* $NetBSD: ofw_pci_subr.c,v 1.2 2021/09/15 17:33:08 thorpej Exp $ */
+/* $NetBSD: ofw_pci_subr.c,v 1.3 2022/01/22 11:49:18 thorpej Exp $ */
/*-
* Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ofw_pci_subr.c,v 1.2 2021/09/15 17:33:08 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofw_pci_subr.c,v 1.3 2022/01/22 11:49:18 thorpej Exp $");
#include <sys/types.h>
#include <sys/device.h>
@@ -77,7 +77,7 @@ ofw_pci_bus_get_child_devhandle(device_t dev, devhandle_t call_handle, void *v)
}
/* Found it! */
- args->devhandle = devhandle_from_of(phandle);
+ args->devhandle = devhandle_from_of(call_handle, phandle);
return 0;
}
diff --git a/sys/dev/ofw/ofw_subr.c b/sys/dev/ofw/ofw_subr.c
index 01cbed6fd44..e0532a5ad8d 100644
--- a/sys/dev/ofw/ofw_subr.c
+++ b/sys/dev/ofw/ofw_subr.c
@@ -1,4 +1,4 @@
-/* $NetBSD: ofw_subr.c,v 1.59 2021/09/15 17:33:08 thorpej Exp $ */
+/* $NetBSD: ofw_subr.c,v 1.60 2022/01/22 11:49:18 thorpej Exp $ */
/*
* Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ofw_subr.c,v 1.59 2021/09/15 17:33:08 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofw_subr.c,v 1.60 2022/01/22 11:49:18 thorpej Exp $");
#include <sys/param.h>
#include <sys/device.h>
@@ -99,12 +99,18 @@ static const struct devhandle_impl of_devhandle_impl = {
};
devhandle_t
-devhandle_from_of(int phandle)
+devhandle_from_of(devhandle_t super_handle, int phandle)
{
- devhandle_t handle = {
- .impl = &of_devhandle_impl,
- .integer = phandle,
- };
+ devhandle_type_t super_type = devhandle_type(super_handle);
+ devhandle_t handle = { 0 };
+
+ if (super_type == DEVHANDLE_TYPE_OF) {
+ handle.impl = super_handle.impl;
+ } else {
+ KASSERT(super_type == DEVHANDLE_TYPE_INVALID);
+ handle.impl = &of_devhandle_impl;
+ }
+ handle.integer = phandle;
return handle;
}
@@ -125,7 +131,7 @@ of_device_enumerate_children(device_t dev, devhandle_t call_handle, void *v)
int child;
for (child = OF_child(phandle); child != 0; child = OF_peer(child)) {
- if (!args->callback(dev, devhandle_from_of(child),
+ if (!args->callback(dev, devhandle_from_of(call_handle, child),
args->callback_arg)) {
break;
}
diff --git a/sys/dev/ofw/openfirm.h b/sys/dev/ofw/openfirm.h
index 34eee8e53bc..55733c08483 100644
--- a/sys/dev/ofw/openfirm.h
+++ b/sys/dev/ofw/openfirm.h
@@ -1,4 +1,4 @@
-/* $NetBSD: openfirm.h,v 1.47 2021/04/24 23:36:57 thorpej Exp $ */
+/* $NetBSD: openfirm.h,v 1.48 2022/01/22 11:49:18 thorpej Exp $ */
/*
* Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -107,7 +107,7 @@ int openfirmware(void *);
#ifdef _KERNEL
struct device_compatible_entry;
-devhandle_t devhandle_from_of(int);
+devhandle_t devhandle_from_of(devhandle_t, int);
int devhandle_to_of(devhandle_t);
#define OF_DEVICE_CALL_REGISTER(_n_, _c_) \