Testing needed: legacy CPU device
Nate Lawson
nate at root.org
Thu May 6 01:13:12 PDT 2004
The attached patch backs out the previous attempt at adding a newbus
attachment for CPUs and adds it instead as the i386 legacy device. I need
someone with SMP or UP to compile and boot this _without_ ACPI enabled.
Then send me the output of "devinfo".
For the curious, I plan to rename acpi_cpu to cpu and thus drivers can
probe/attach to a CPU via a dependency on "cpu". We'll enumerate
processors via ACPI if enabled, or this legacy attachment if disabled.
This will handle i386 (both with and without acpi), ia64, and amd64.
Thanks,
-Nate
Index: sys/i386/i386/legacy.c
===================================================================
RCS file: /home/ncvs/src/sys/i386/i386/legacy.c,v
retrieving revision 1.52
diff -u -r1.52 legacy.c
--- sys/i386/i386/legacy.c 25 Aug 2003 09:48:47 -0000 1.52
+++ sys/i386/i386/legacy.c 6 May 2004 06:33:56 -0000
@@ -41,7 +41,9 @@
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <machine/bus.h>
+#include <sys/pcpu.h>
#include <sys/rman.h>
+#include <sys/smp.h>
#include "opt_mca.h"
#ifdef DEV_MCA
@@ -143,7 +145,9 @@
static int
legacy_attach(device_t dev)
{
- device_t child;
+ device_t child;
+ int i;
+ struct pcpu *pc;
/*
* First, let our child driver's identify any child devices that
@@ -178,6 +182,20 @@
device_probe_and_attach(child);
}
+ if (!devclass_get_device(devclass_find("cpu"), 0)) {
+ for (i = 0; i <= mp_maxid; i++)
+ if (!CPU_ABSENT(i)) {
+ pc = pcpu_find(i);
+ KASSERT(pc != NULL, ("pcpu_find failed"));
+ child = BUS_ADD_CHILD(dev, 0, "cpu", i);
+ if (child == NULL)
+ panic("legacy_attach cpu");
+ device_probe_and_attach(child);
+ pc->pc_device = child;
+ device_set_ivars(child, pc);
+ }
+ }
+
return 0;
}
@@ -323,4 +341,61 @@
struct resource_list *rl = &atdev->lg_resources;
resource_list_delete(rl, type, rid);
+}
+
+/*
+ * Legacy CPU attachment when ACPI is not available. Drivers like
+ * cpufreq(4) hang off this.
+ */
+static int cpu_read_ivar(device_t dev, device_t child, int index,
+ uintptr_t *result);
+
+static device_method_t cpu_methods[] = {
+ /* Device interface */
+ DEVMETHOD(device_probe, bus_generic_probe),
+ DEVMETHOD(device_attach, bus_generic_attach),
+ DEVMETHOD(device_detach, bus_generic_detach),
+ DEVMETHOD(device_shutdown, bus_generic_shutdown),
+ DEVMETHOD(device_suspend, bus_generic_suspend),
+ DEVMETHOD(device_resume, bus_generic_resume),
+
+ /* Bus interface */
+ DEVMETHOD(bus_read_ivar, cpu_read_ivar),
+ DEVMETHOD(bus_print_child, bus_generic_print_child),
+ DEVMETHOD(bus_alloc_resource, bus_generic_alloc_resource),
+ DEVMETHOD(bus_release_resource, bus_generic_release_resource),
+ DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
+ DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
+ DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
+ DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
+#ifdef notyet
+ DEVMETHOD(bus_add_child, cpu_add_child),
+ DEVMETHOD(bus_set_resource, bus_generic_set_resource),
+ DEVMETHOD(bus_get_resource, bus_generic_get_resource),
+ DEVMETHOD(bus_delete_resource, bus_generic_delete_resource),
+#endif
+
+ { 0, 0 }
+};
+
+static driver_t cpu_driver = {
+ "cpu",
+ cpu_methods,
+ 1, /* no softc */
+};
+static devclass_t cpu_devclass;
+DRIVER_MODULE(cpu, legacy, cpu_driver, cpu_devclass, 0, 0);
+
+static int
+cpu_read_ivar(device_t dev, device_t child, int index, uintptr_t *result)
+{
+ struct pcpu *pc;
+
+ if (index != 0)
+ return (ENOENT);
+ pc = device_get_ivars(child);
+ if (pc == NULL)
+ return (ENOENT);
+ *result = (uintptr_t)pc;
+ return (0);
}
Index: sys/kern/subr_smp.c
===================================================================
RCS file: /home/ncvs/src/sys/kern/subr_smp.c,v
retrieving revision 1.186
diff -u -r1.186 subr_smp.c
--- sys/kern/subr_smp.c 27 Mar 2004 18:21:24 -0000 1.186
+++ sys/kern/subr_smp.c 23 Apr 2004 16:38:52 -0000
@@ -83,48 +83,6 @@
SYSCTL_INT(_kern_smp, OID_AUTO, cpus, CTLFLAG_RD, &smp_cpus, 0,
"Number of CPUs online");
-#if !__sparc64__ && !__powerpc__
-static void cpu_identify(driver_t *driver, device_t parent);
-static device_t cpu_add_child(device_t bus, int order, const char *name,
- int unit);
-
-static device_method_t cpu_methods[] = {
- /* Device interface */
- DEVMETHOD(device_identify, cpu_identify),
- DEVMETHOD(device_probe, bus_generic_probe),
- DEVMETHOD(device_attach, bus_generic_attach),
- DEVMETHOD(device_detach, bus_generic_detach),
- DEVMETHOD(device_shutdown, bus_generic_shutdown),
- DEVMETHOD(device_suspend, bus_generic_suspend),
- DEVMETHOD(device_resume, bus_generic_resume),
-
- /* Bus interface */
- DEVMETHOD(bus_print_child, bus_generic_print_child),
- DEVMETHOD(bus_add_child, cpu_add_child),
- DEVMETHOD(bus_alloc_resource, bus_generic_alloc_resource),
- DEVMETHOD(bus_release_resource, bus_generic_release_resource),
- DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
- DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
- DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
- DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
-#ifdef notyet
- DEVMETHOD(bus_set_resource, bus_generic_set_resource),
- DEVMETHOD(bus_get_resource, bus_generic_get_resource),
- DEVMETHOD(bus_delete_resource, bus_generic_delete_resource),
-#endif
-
- { 0, 0 }
-};
-
-static driver_t cpu_driver = {
- "cpu",
- cpu_methods,
- 1, /* no softc */
-};
-static devclass_t cpu_devclass;
-DRIVER_MODULE(cpu, nexus, cpu_driver, cpu_devclass, 0, 0);
-#endif
-
#ifdef SMP
/* Enable forwarding of a signal to a process running on a different CPU */
static int forward_signal_enabled = 1;
@@ -416,31 +374,3 @@
teardown_func(arg);
}
#endif /* SMP */
-
-#if !__sparc64__ && !__powerpc__
-static void
-cpu_identify(driver_t *driver, device_t parent)
-{
- struct pcpu *pc;
- int i;
-
- /* Protect against multiple scans of the bus. */
- if (!cold || device_find_child(parent, "cpu", 0) != NULL)
- return;
-
- for (i = 0; i <= mp_maxid; i++)
- if (!CPU_ABSENT(i)) {
- pc = pcpu_find(i);
- KASSERT(pc != NULL, ("pcpu_find failed"));
- pc->pc_device = BUS_ADD_CHILD(parent, 0, "cpu", i);
- if (pc->pc_device == NULL)
- panic("failed adding cpu child");
- }
-}
-
-static device_t
-cpu_add_child(device_t bus, int order, const char *name, int unit)
-{
- return (device_add_child_ordered(bus, order, name, unit));
-}
-#endif
More information about the freebsd-arch
mailing list