Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/sys sparc{,64} promlib -> devhandle_t glue



details:   https://anonhg.NetBSD.org/src/rev/a676b9dcb8a9
branches:  trunk
changeset: 983221:a676b9dcb8a9
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Mon May 10 13:59:30 2021 +0000

description:
sparc{,64} promlib -> devhandle_t glue

diffstat:

 sys/arch/sparc/include/promlib.h |   15 ++++-
 sys/arch/sparc/sparc/promlib.c   |  126 ++++++++++++++++++++++++++++++++++++++-
 sys/sys/device.h                 |    5 +-
 3 files changed, 141 insertions(+), 5 deletions(-)

diffs (249 lines):

diff -r 350e250ed12f -r a676b9dcb8a9 sys/arch/sparc/include/promlib.h
--- a/sys/arch/sparc/include/promlib.h  Sun May 09 15:40:27 2021 +0000
+++ b/sys/arch/sparc/include/promlib.h  Mon May 10 13:59:30 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: promlib.h,v 1.25 2017/09/11 19:25:07 palle Exp $ */
+/*     $NetBSD: promlib.h,v 1.26 2021/05/10 13:59:30 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -41,6 +41,8 @@
 #include "opt_multiprocessor.h"
 #endif
 
+#include <sys/device.h>                        /* for devhandle_t */
+
 #include <machine/idprom.h>
 #include <machine/bsd_openprom.h>
 #include <machine/openfirm.h>
@@ -110,6 +112,9 @@
 
        int     (*po_finddevice)(const char *);
 
+       /* devhandle_t interface */
+       devhandle_t (*po_node_to_devhandle)(int);
+       int     (*po_devhandle_to_node)(devhandle_t);
 };
 
 extern struct promops  promops;
@@ -211,6 +216,9 @@
 #define nextsibling(node)      prom_nextsibling(node)
 #define prom_getproplen(node,name)     prom_proplen(node, name)
 
+/* devhandle_t interface */
+#define        prom_node_to_devhandle(n)  ((*promops.po_node_to_devhandle)(n))
+#define        prom_devhandle_to_node(dh) ((*promops.po_devhandle_to_node)(dh))
 
 /* MP stuff - not currently used */
 #define prom_cpustart(m,a,c,pc)        ((*promops.po_cpustart)(m,a,c,pc))
@@ -220,4 +228,9 @@
 
 extern void    *romp;          /* PROM-supplied argument (see locore) */
 
+#ifdef _KERNEL
+#define        OBP_DEVICE_CALL_REGISTER(_n_, _c_)                              \
+       DEVICE_CALL_REGISTER(obp_device_calls, _n_, _c_)
+#endif /* _KERNEL */
+
 #endif /* _SPARC_PROMLIB_H_ */
diff -r 350e250ed12f -r a676b9dcb8a9 sys/arch/sparc/sparc/promlib.c
--- a/sys/arch/sparc/sparc/promlib.c    Sun May 09 15:40:27 2021 +0000
+++ b/sys/arch/sparc/sparc/promlib.c    Mon May 10 13:59:30 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: promlib.c,v 1.47 2021/01/24 07:36:54 mrg Exp $ */
+/*     $NetBSD: promlib.c,v 1.48 2021/05/10 13:59:30 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: promlib.c,v 1.47 2021/01/24 07:36:54 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: promlib.c,v 1.48 2021/05/10 13:59:30 thorpej Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_sparc_arch.h"
@@ -43,6 +43,7 @@
 
 #include <sys/param.h>
 #include <sys/kernel.h>
+#include <sys/device.h>
 
 #ifdef _STANDALONE
 #include <lib/libsa/stand.h>
@@ -93,6 +94,23 @@
 static char    *opf_nextprop(int, const char *);
 static void    opf_interpret_simple(const char *);
 
+#ifndef _STANDALONE
+static devhandle_t
+null_prom_to_devhandle(int node __unused)
+{
+       devhandle_t devhandle;
+
+       devhandle_invalidate(&devhandle);
+
+       return devhandle;
+}
+
+static int
+null_devhandle_to_prom(devhandle_t devhandle __unused)
+{
+       return 0;
+}
+#endif /* ! _STANDALONE */
 
 /*
  * PROM entry points.
@@ -142,7 +160,20 @@
        (void *)notimplemented,         /* getprop */
        (void *)notimplemented,         /* setprop */
        (void *)notimplemented,         /* nextprop */
-       (void *)notimplemented          /* finddevice */
+       (void *)notimplemented,         /* finddevice */
+
+       /*
+        * These should never be called in the STANDALONE environment,
+        * but when we're in the kernel environment, it's not really
+        * invalid to do so.
+        */
+#ifdef STANDALONE
+       (void *)notimplemented,         /* node_to_devhandle */
+       (void *)notimplemented,         /* devhandle_to_node */
+#else
+       (void *)null_prom_to_devhandle, /* node_to_devhandle */
+       (void *)null_devhandle_to_prom, /* devhandle_to_node */
+#endif /* STANDALONE */
 };
 
 static void
@@ -181,6 +212,73 @@
        }
 }
 
+#ifndef _STANDALONE
+/*
+ * OBP device handle support.  We subsume v0-v3 into a single implementation
+ * and use promops to handle differences.
+ *
+ * On 32-bit SPARC, the OpenFirmware variant also gets redirected here.
+ * See prom_init_opf().
+ */
+
+static device_call_t
+obp_devhandle_lookup_device_call(devhandle_t handle, const char *name,
+    devhandle_t *call_handlep)
+{
+       __link_set_decl(obp_device_calls, struct device_call_descriptor);
+       struct device_call_descriptor * const *desc;
+
+       __link_set_foreach(desc, obp_device_calls) {
+               if (strcmp((*desc)->name, name) == 0) {
+                       return (*desc)->call;
+               }
+       }
+       return NULL;
+}
+
+static const struct devhandle_impl obp_devhandle_impl = {
+       .type = DEVHANDLE_TYPE_OPENBOOT,
+       .lookup_device_call = obp_devhandle_lookup_device_call,
+};
+
+static devhandle_t
+devhandle_from_obp(int node)
+{
+       devhandle_t handle = {
+               .impl = &obp_devhandle_impl,
+               .integer = node,
+       };
+
+       return handle;
+}
+
+static int
+devhandle_to_obp(devhandle_t const handle)
+{
+       KASSERT(devhandle_type(handle) == DEVHANDLE_TYPE_OPENBOOT);
+
+       return handle.integer;
+}
+
+static int
+obp_device_enumerate_children(device_t dev, devhandle_t call_handle, void *v)
+{
+       struct device_enumerate_children_args *args = v;
+       int node = devhandle_to_obp(call_handle);
+
+       for (node = prom_firstchild(node); node != 0;
+            node = prom_nextsibling(node)) {
+               if (!args->callback(dev, devhandle_from_obp(node),
+                                   args->callback_arg)) {
+                       break;
+               }
+       }
+
+       return 0;
+}
+OBP_DEVICE_CALL_REGISTER("device-enumerate-children",
+                        obp_device_enumerate_children)
+#endif /* ! _STANDALONE */
 
 /*
  * prom_getprop() reads the named property data from a given node.
@@ -1185,6 +1283,11 @@
        promops.po_setprop = no->no_setprop;
        promops.po_nextprop = no->no_nextprop;
 
+#ifndef _STANDALONE
+       promops.po_node_to_devhandle = devhandle_from_obp;
+       promops.po_devhandle_to_node = devhandle_to_obp;
+#endif /* _STANDALONE */
+
        /*
         * Next, deal with prom vector differences between versions.
         */
@@ -1288,6 +1391,23 @@
        promops.po_instance_to_package = opf_instance_to_package;
        promops.po_finddevice = opf_finddevice;
 
+#ifndef _STANDALONE
+#ifdef __sparc64__
+       promops.po_node_to_devhandle = devhandle_from_of;
+       promops.po_devhandle_to_node = devhandle_to_of;
+#else
+       /*
+        * For 32-bit SPARC, pretend this is OpenBoot for now.
+        * The differences will be hidden behind the promops
+        * anyway.  We do this because this platform doesn't
+        * pull in all of the OpenFirmware support code that
+        * 64-bit SPARC does.
+        */
+       promops.po_node_to_devhandle = devhandle_from_obp;
+       promops.po_devhandle_to_node = devhandle_to_obp;
+#endif /* __sparc64__ */
+#endif /* _STANDALONE */
+
        /* Retrieve and cache stdio handles */
        node = findchosen();
        OF_getprop(node, "stdin", &promops.po_stdin, sizeof(int));
diff -r 350e250ed12f -r a676b9dcb8a9 sys/sys/device.h
--- a/sys/sys/device.h  Sun May 09 15:40:27 2021 +0000
+++ b/sys/sys/device.h  Mon May 10 13:59:30 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: device.h,v 1.169 2021/04/27 14:48:28 thorpej Exp $ */
+/* $NetBSD: device.h,v 1.170 2021/05/10 13:59:30 thorpej Exp $ */
 
 /*
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -219,6 +219,9 @@
        /* OpenFirmware, FDT */
        DEVHANDLE_TYPE_OF               =       0x4f504657,     /* 'OPFW' */
 
+       /* Sun OpenBoot */
+       DEVHANDLE_TYPE_OPENBOOT         =       0x4f504254,     /* 'OPBT' */
+
        /* Private (opaque data) */
        DEVHANDLE_TYPE_PRIVATE          =       0x50525654,     /* 'PRVT' */
 



Home | Main Index | Thread Index | Old Index