aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/ofw
diff options
context:
space:
mode:
Diffstat (limited to 'sys/dev/ofw')
-rw-r--r--sys/dev/ofw/ofw_bus_subr.c6
-rw-r--r--sys/dev/ofw/ofw_cpu.c91
-rw-r--r--sys/dev/ofw/ofw_cpu.h2
-rw-r--r--sys/dev/ofw/ofw_fdt.c3
-rw-r--r--sys/dev/ofw/ofw_firmware.c3
-rw-r--r--sys/dev/ofw/ofw_pcib.c25
-rw-r--r--sys/dev/ofw/ofw_standard.c3
-rw-r--r--sys/dev/ofw/ofwbus.c5
-rw-r--r--sys/dev/ofw/openfirm.c32
-rw-r--r--sys/dev/ofw/openfirm.h5
10 files changed, 101 insertions, 74 deletions
diff --git a/sys/dev/ofw/ofw_bus_subr.c b/sys/dev/ofw/ofw_bus_subr.c
index d63e89e2d677..4d0479dfb957 100644
--- a/sys/dev/ofw/ofw_bus_subr.c
+++ b/sys/dev/ofw/ofw_bus_subr.c
@@ -210,7 +210,7 @@ ofw_bus_node_status_okay(phandle_t node)
OF_getprop(node, "status", status, OFW_STATUS_LEN);
if ((len == 5 && (bcmp(status, "okay", len) == 0)) ||
- (len == 3 && (bcmp(status, "ok", len))))
+ (len == 3 && (bcmp(status, "ok", len) == 0)))
return (1);
return (0);
@@ -641,7 +641,7 @@ ofw_bus_intr_to_rl(device_t dev, phandle_t node,
phandle_t iparent;
uint32_t icells, *intr;
int err, i, irqnum, nintr, rid;
- boolean_t extended;
+ bool extended;
nintr = OF_getencprop_alloc_multi(node, "interrupts", sizeof(*intr),
(void **)&intr);
@@ -707,7 +707,7 @@ ofw_bus_intr_by_rid(device_t dev, phandle_t node, int wanted_rid,
phandle_t iparent;
uint32_t icells, *intr;
int err, i, nintr, rid;
- boolean_t extended;
+ bool extended;
nintr = OF_getencprop_alloc_multi(node, "interrupts", sizeof(*intr),
(void **)&intr);
diff --git a/sys/dev/ofw/ofw_cpu.c b/sys/dev/ofw/ofw_cpu.c
index e18004ae19d2..888af0440746 100644
--- a/sys/dev/ofw/ofw_cpu.c
+++ b/sys/dev/ofw/ofw_cpu.c
@@ -42,8 +42,9 @@
#include <dev/ofw/ofw_bus_subr.h>
#include <dev/ofw/ofw_cpu.h>
-#if defined(__arm__) || defined(__arm64__) || defined(__riscv__)
+#if defined(__arm__) || defined(__arm64__) || defined(__riscv)
#include <dev/clk/clk.h>
+#define HAS_CLK
#endif
static int ofw_cpulist_probe(device_t);
@@ -123,7 +124,7 @@ ofw_cpulist_attach(device_t dev)
free(dinfo, M_OFWCPU);
continue;
}
- cdev = device_add_child(dev, NULL, -1);
+ cdev = device_add_child(dev, NULL, DEVICE_UNIT_ANY);
if (cdev == NULL) {
device_printf(dev, "<%s>: device_add_child failed\n",
dinfo->obd_name);
@@ -134,7 +135,8 @@ ofw_cpulist_attach(device_t dev)
device_set_ivars(cdev, dinfo);
}
- return (bus_generic_attach(dev));
+ bus_attach_children(dev);
+ return (0);
}
static const struct ofw_bus_devinfo *
@@ -151,7 +153,7 @@ static int ofw_cpu_read_ivar(device_t dev, device_t child, int index,
struct ofw_cpu_softc {
struct pcpu *sc_cpu_pcpu;
uint32_t sc_nominal_mhz;
- boolean_t sc_reg_valid;
+ bool sc_reg_valid;
pcell_t sc_reg[2];
};
@@ -180,6 +182,24 @@ static driver_t ofw_cpu_driver = {
DRIVER_MODULE(ofw_cpu, cpulist, ofw_cpu_driver, 0, 0);
+static bool
+ofw_cpu_is_runnable(phandle_t node)
+{
+ /*
+ * Per the DeviceTree Specification, a cpu node (under /cpus) that
+ * has 'status = disabled' indicates that "the CPU is in a quiescent
+ * state."
+ *
+ * A quiescent CPU that specifies an "enable-method", such as
+ * "spin-table", can still be used by the kernel.
+ *
+ * Lacking this, any CPU marked "disabled" or other non-okay status
+ * should be excluded from the kernel's view.
+ */
+ return (ofw_bus_node_status_okay(node) ||
+ OF_hasprop(node, "enable-method"));
+}
+
static int
ofw_cpu_probe(device_t dev)
{
@@ -188,6 +208,9 @@ ofw_cpu_probe(device_t dev)
if (type == NULL || strcmp(type, "cpu") != 0)
return (ENXIO);
+ if (!ofw_cpu_is_runnable(ofw_bus_get_node(dev)))
+ return (ENXIO);
+
device_set_desc(dev, "Open Firmware CPU");
if (!bootverbose && device_get_unit(dev) != 0) {
device_quiet(dev);
@@ -198,6 +221,30 @@ ofw_cpu_probe(device_t dev)
}
static int
+get_freq_from_clk(device_t dev, struct ofw_cpu_softc *sc)
+{
+#ifdef HAS_CLK
+ clk_t cpuclk;
+ uint64_t freq;
+ int rv;
+
+ rv = clk_get_by_ofw_index(dev, 0, 0, &cpuclk);
+ if (rv == 0) {
+ rv = clk_get_freq(cpuclk, &freq);
+ if (rv != 0 && bootverbose)
+ device_printf(dev,
+ "Cannot get freq of property clocks\n");
+ else
+ sc->sc_nominal_mhz = freq / 1000000;
+ }
+
+ return (rv);
+#else
+ return (ENODEV);
+#endif
+}
+
+static int
ofw_cpu_attach(device_t dev)
{
struct ofw_cpulist_softc *psc;
@@ -205,10 +252,6 @@ ofw_cpu_attach(device_t dev)
phandle_t node;
pcell_t cell;
int rv;
-#if defined(__arm__) || defined(__arm64__) || defined(__riscv__)
- clk_t cpuclk;
- uint64_t freq;
-#endif
sc = device_get_softc(dev);
psc = device_get_softc(device_get_parent(dev));
@@ -275,18 +318,7 @@ ofw_cpu_attach(device_t dev)
sc->sc_cpu_pcpu = pcpu_find(device_get_unit(dev));
if (OF_getencprop(node, "clock-frequency", &cell, sizeof(cell)) < 0) {
-#if defined(__arm__) || defined(__arm64__) || defined(__riscv__)
- rv = clk_get_by_ofw_index(dev, 0, 0, &cpuclk);
- if (rv == 0) {
- rv = clk_get_freq(cpuclk, &freq);
- if (rv != 0 && bootverbose)
- device_printf(dev,
- "Cannot get freq of property clocks\n");
- else
- sc->sc_nominal_mhz = freq / 1000000;
- } else
-#endif
- {
+ if (get_freq_from_clk(dev, sc) != 0) {
if (bootverbose)
device_printf(dev,
"missing 'clock-frequency' property\n");
@@ -297,8 +329,10 @@ ofw_cpu_attach(device_t dev)
if (sc->sc_nominal_mhz != 0 && bootverbose)
device_printf(dev, "Nominal frequency %dMhz\n",
sc->sc_nominal_mhz);
- bus_generic_probe(dev);
- return (bus_generic_attach(dev));
+
+ bus_identify_children(dev);
+ bus_attach_children(dev);
+ return (0);
}
static int
@@ -335,11 +369,10 @@ ofw_cpu_read_ivar(device_t dev, device_t child, int index, uintptr_t *result)
}
int
-ofw_cpu_early_foreach(ofw_cpu_foreach_cb callback, boolean_t only_runnable)
+ofw_cpu_early_foreach(ofw_cpu_foreach_cb callback, bool only_runnable)
{
phandle_t node, child;
pcell_t addr_cells, reg[2];
- char status[16];
char device_type[16];
u_int id, next_id;
int count, rv;
@@ -376,14 +409,8 @@ ofw_cpu_early_foreach(ofw_cpu_foreach_cb callback, boolean_t only_runnable)
* those that have been enabled, or do provide a method
* to enable them.
*/
- if (only_runnable) {
- status[0] = '\0';
- OF_getprop(child, "status", status, sizeof(status));
- if (status[0] != '\0' && strcmp(status, "okay") != 0 &&
- strcmp(status, "ok") != 0 &&
- !OF_hasprop(child, "enable-method"))
- continue;
- }
+ if (only_runnable && !ofw_cpu_is_runnable(child))
+ continue;
/*
* Check we have a register to identify the cpu
diff --git a/sys/dev/ofw/ofw_cpu.h b/sys/dev/ofw/ofw_cpu.h
index cb30dfb6e262..9f4e9e65aa61 100644
--- a/sys/dev/ofw/ofw_cpu.h
+++ b/sys/dev/ofw/ofw_cpu.h
@@ -30,6 +30,6 @@
#define _DEV_OFW_OFW_CPU_H_
typedef bool (*ofw_cpu_foreach_cb)(u_int, phandle_t, u_int, pcell_t *);
-int ofw_cpu_early_foreach(ofw_cpu_foreach_cb, boolean_t);
+int ofw_cpu_early_foreach(ofw_cpu_foreach_cb, bool);
#endif /* _DEV_OFW_OFW_CPU_H_ */
diff --git a/sys/dev/ofw/ofw_fdt.c b/sys/dev/ofw/ofw_fdt.c
index 4b0451824df5..fd9a9f80af39 100644
--- a/sys/dev/ofw/ofw_fdt.c
+++ b/sys/dev/ofw/ofw_fdt.c
@@ -32,12 +32,11 @@
#include <sys/ctype.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
+#include <sys/stdarg.h>
#include <sys/systm.h>
#include <contrib/libfdt/libfdt.h>
-#include <machine/stdarg.h>
-
#include <dev/fdt/fdt_common.h>
#include <dev/ofw/ofwvar.h>
#include <dev/ofw/openfirm.h>
diff --git a/sys/dev/ofw/ofw_firmware.c b/sys/dev/ofw/ofw_firmware.c
index 8723965f74be..360f7ee56e8a 100644
--- a/sys/dev/ofw/ofw_firmware.c
+++ b/sys/dev/ofw/ofw_firmware.c
@@ -150,7 +150,8 @@ ofw_firmware_attach(device_t dev)
device_probe_and_attach(cdev);
}
- return (bus_generic_attach(dev));
+ bus_attach_children(dev);
+ return (0);
}
static device_method_t ofw_firmware_methods[] = {
diff --git a/sys/dev/ofw/ofw_pcib.c b/sys/dev/ofw/ofw_pcib.c
index ebc09fccd93e..0cfddd155e52 100644
--- a/sys/dev/ofw/ofw_pcib.c
+++ b/sys/dev/ofw/ofw_pcib.c
@@ -302,8 +302,9 @@ ofw_pcib_attach(device_t dev)
return (error);
}
- device_add_child(dev, "pci", -1);
- return (bus_generic_attach(dev));
+ device_add_child(dev, "pci", DEVICE_UNIT_ANY);
+ bus_attach_children(dev);
+ return (0);
}
static int
@@ -421,17 +422,13 @@ static struct resource *
ofw_pcib_alloc_resource(device_t bus, device_t child, int type, int *rid,
rman_res_t start, rman_res_t end, rman_res_t count, u_int flags)
{
-#if defined(NEW_PCIB) && defined(PCI_RES_BUS)
struct ofw_pci_softc *sc;
sc = device_get_softc(bus);
-#endif
switch (type) {
-#if defined(NEW_PCIB) && defined(PCI_RES_BUS)
case PCI_RES_BUS:
return (pci_domain_alloc_bus(sc->sc_pci_domain, child, rid,
start, end, count, flags));
-#endif
case SYS_RES_MEMORY:
case SYS_RES_IOPORT:
return (bus_generic_rman_alloc_resource(bus, child, type, rid,
@@ -445,16 +442,12 @@ ofw_pcib_alloc_resource(device_t bus, device_t child, int type, int *rid,
static int
ofw_pcib_release_resource(device_t bus, device_t child, struct resource *res)
{
-#if defined(NEW_PCIB) && defined(PCI_RES_BUS)
struct ofw_pci_softc *sc;
sc = device_get_softc(bus);
-#endif
switch (rman_get_type(res)) {
-#if defined(NEW_PCIB) && defined(PCI_RES_BUS)
case PCI_RES_BUS:
return (pci_domain_release_bus(sc->sc_pci_domain, child, res));
-#endif
case SYS_RES_MEMORY:
case SYS_RES_IOPORT:
return (bus_generic_rman_release_resource(bus, child, res));
@@ -505,16 +498,12 @@ ofw_pcib_translate_resource(device_t bus, int type, rman_res_t start,
static int
ofw_pcib_activate_resource(device_t bus, device_t child, struct resource *res)
{
-#if defined(NEW_PCIB) && defined(PCI_RES_BUS)
struct ofw_pci_softc *sc;
sc = device_get_softc(bus);
-#endif
switch (rman_get_type(res)) {
-#if defined(NEW_PCIB) && defined(PCI_RES_BUS)
case PCI_RES_BUS:
return (pci_domain_activate_bus(sc->sc_pci_domain, child, res));
-#endif
case SYS_RES_MEMORY:
case SYS_RES_IOPORT:
return (bus_generic_rman_activate_resource(bus, child, res));
@@ -621,17 +610,13 @@ ofw_pcib_bus_get_bus_tag(device_t bus, device_t child)
static int
ofw_pcib_deactivate_resource(device_t bus, device_t child, struct resource *res)
{
-#if defined(NEW_PCIB) && defined(PCI_RES_BUS)
struct ofw_pci_softc *sc;
sc = device_get_softc(bus);
-#endif
switch (rman_get_type(res)) {
-#if defined(NEW_PCIB) && defined(PCI_RES_BUS)
case PCI_RES_BUS:
return (pci_domain_deactivate_bus(sc->sc_pci_domain, child,
res));
-#endif
case SYS_RES_MEMORY:
case SYS_RES_IOPORT:
return (bus_generic_rman_deactivate_resource(bus, child, res));
@@ -644,17 +629,13 @@ static int
ofw_pcib_adjust_resource(device_t bus, device_t child,
struct resource *res, rman_res_t start, rman_res_t end)
{
-#if defined(NEW_PCIB) && defined(PCI_RES_BUS)
struct ofw_pci_softc *sc;
sc = device_get_softc(bus);
-#endif
switch (rman_get_type(res)) {
-#if defined(NEW_PCIB) && defined(PCI_RES_BUS)
case PCI_RES_BUS:
return (pci_domain_adjust_bus(sc->sc_pci_domain, child, res,
start, end));
-#endif
case SYS_RES_MEMORY:
case SYS_RES_IOPORT:
return (bus_generic_rman_adjust_resource(bus, child, res,
diff --git a/sys/dev/ofw/ofw_standard.c b/sys/dev/ofw/ofw_standard.c
index 47a2cabf44a6..8df768dffbcd 100644
--- a/sys/dev/ofw/ofw_standard.c
+++ b/sys/dev/ofw/ofw_standard.c
@@ -60,10 +60,9 @@
#include <sys/param.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
+#include <sys/stdarg.h>
#include <sys/systm.h>
-#include <machine/stdarg.h>
-
#include <dev/ofw/ofwvar.h>
#include <dev/ofw/openfirm.h>
diff --git a/sys/dev/ofw/ofwbus.c b/sys/dev/ofw/ofwbus.c
index 51e6072ad4ba..d66befcb7314 100644
--- a/sys/dev/ofw/ofwbus.c
+++ b/sys/dev/ofw/ofwbus.c
@@ -117,7 +117,7 @@ ofwbus_attach(device_t dev)
/*
* Allow devices to identify.
*/
- bus_generic_probe(dev);
+ bus_identify_children(dev);
/*
* Now walk the OFW tree and attach top-level devices.
@@ -125,7 +125,8 @@ ofwbus_attach(device_t dev)
for (node = OF_child(node); node > 0; node = OF_peer(node))
simplebus_add_device(dev, node, 0, NULL, -1, NULL);
- return (bus_generic_attach(dev));
+ bus_attach_children(dev);
+ return (0);
}
static struct resource *
diff --git a/sys/dev/ofw/openfirm.c b/sys/dev/ofw/openfirm.c
index 881a2cccb072..b5f58b86a9c3 100644
--- a/sys/dev/ofw/openfirm.c
+++ b/sys/dev/ofw/openfirm.c
@@ -68,8 +68,7 @@
#include <sys/queue.h>
#include <sys/systm.h>
#include <sys/endian.h>
-
-#include <machine/stdarg.h>
+#include <sys/stdarg.h>
#include <dev/ofw/ofwvar.h>
#include <dev/ofw/openfirm.h>
@@ -96,7 +95,7 @@ struct xrefinfo {
static SLIST_HEAD(, xrefinfo) xreflist = SLIST_HEAD_INITIALIZER(xreflist);
static struct mtx xreflist_lock;
-static boolean_t xref_init_done;
+static bool xref_init_done;
#define FIND_BY_XREF 0
#define FIND_BY_NODE 1
@@ -187,13 +186,22 @@ xrefinfo_add(phandle_t node, phandle_t xref, device_t dev)
return (xi);
}
+static void
+xrefinfo_remove(struct xrefinfo *xi)
+{
+
+ mtx_lock(&xreflist_lock);
+ SLIST_REMOVE(&xreflist, xi, xrefinfo, next_entry);
+ mtx_unlock(&xreflist_lock);
+}
+
/*
* OFW install routines. Highest priority wins, equal priority also
* overrides allowing last-set to win.
*/
SET_DECLARE(ofw_set, ofw_def_t);
-boolean_t
+bool
OF_install(char *name, int prio)
{
ofw_def_t *ofwp, **ofwpp;
@@ -202,7 +210,7 @@ OF_install(char *name, int prio)
/* Allow OF layer to be uninstalled */
if (name == NULL) {
ofw_def_impl = NULL;
- return (FALSE);
+ return (false);
}
/*
@@ -216,11 +224,11 @@ OF_install(char *name, int prio)
prio >= curr_prio) {
curr_prio = prio;
ofw_def_impl = ofwp;
- return (TRUE);
+ return (true);
}
}
- return (FALSE);
+ return (false);
}
/* Initializer */
@@ -704,6 +712,16 @@ OF_device_register_xref(phandle_t xref, device_t dev)
panic("Attempt to register device before xreflist_init");
}
+void
+OF_device_unregister_xref(phandle_t xref, device_t dev)
+{
+ struct xrefinfo *xi;
+
+ if ((xi = xrefinfo_find(xref, FIND_BY_XREF)) == NULL)
+ return;
+ xrefinfo_remove(xi);
+}
+
/* Call the method in the scope of a given instance. */
int
OF_call_method(const char *method, ihandle_t instance, int nargs, int nreturns,
diff --git a/sys/dev/ofw/openfirm.h b/sys/dev/ofw/openfirm.h
index 149f2a951745..4e2b035827cb 100644
--- a/sys/dev/ofw/openfirm.h
+++ b/sys/dev/ofw/openfirm.h
@@ -83,8 +83,8 @@ MALLOC_DECLARE(M_OFWPROP);
* interface as the Open Firmware access mechanism, OF_init initializes it.
*/
-boolean_t OF_install(char *name, int prio);
-int OF_init(void *cookie);
+bool OF_install(char *name, int prio);
+int OF_init(void *cookie);
/*
* Known Open Firmware interface names
@@ -149,6 +149,7 @@ phandle_t OF_xref_from_node(phandle_t node);
device_t OF_device_from_xref(phandle_t xref);
phandle_t OF_xref_from_device(device_t dev);
int OF_device_register_xref(phandle_t xref, device_t dev);
+void OF_device_unregister_xref(phandle_t xref, device_t dev);
/* Device I/O functions */
ihandle_t OF_open(const char *path);