Module Name:    src
Committed By:   christos
Date:           Mon Jul 19 00:59:32 UTC 2010

Modified Files:
        src/sys/dev/acpi: acpi_cpu.c acpi_cpu.h acpi_cpu_cstate.c

Log Message:
XXX: If this is not correct, revert or fix.
This makes my laptop boot instead of panic:

panic: kernel diagnostic assertion "native_idle != NULL" failed: file 
"../../../../arch/x86/acpi/acpi_cpu_md.c", line 155
fatal breakpoint trap in supervisor mode
type 1 code 0 rip ffffffff8022e4ad cs 8 rflags 246 cr2  0 cpl 0 rsp 
ffff80004c37db10

trace
breakpoint() at netbsd:breakpoint+0x5
panic() at netbsd:panic+0x2ba
kern_assert() at netbsd:kern_assert+0x2d
acpicpu_md_idle_stop() at netbsd:acpicpu_md_idle_stop+0x62
acpicpu_cstate_callback() at netbsd:acpicpu_cstate_callback+0x34
sysmon_task_queue_thread() at netbsd:sysmon_task_queue_thread+0x41

1. ACPI seems to define cpuids 1..n; we define 0..n-1. Adjust for that
2. My laptop is dual core, but ACPI reports 4 cpu nodes. Instead of
   attaching the unmatched ones, make the match fail. Do we want to
   attach and do nothing instead?
3. Create a flag, and only set it after we are completely initialized,
   so the sysmon thread does not try to access unitialized state.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/acpi/acpi_cpu.c \
    src/sys/dev/acpi/acpi_cpu.h
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/acpi/acpi_cpu_cstate.c

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/acpi/acpi_cpu.c
diff -u src/sys/dev/acpi/acpi_cpu.c:1.2 src/sys/dev/acpi/acpi_cpu.c:1.3
--- src/sys/dev/acpi/acpi_cpu.c:1.2	Sun Jul 18 05:39:45 2010
+++ src/sys/dev/acpi/acpi_cpu.c	Sun Jul 18 20:59:32 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_cpu.c,v 1.2 2010/07/18 09:39:45 jruoho Exp $ */
+/* $NetBSD: acpi_cpu.c,v 1.3 2010/07/19 00:59:32 christos Exp $ */
 
 /*-
  * Copyright (c) 2010 Jukka Ruohonen <jruoho...@iki.fi>
@@ -27,7 +27,7 @@
  * SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_cpu.c,v 1.2 2010/07/18 09:39:45 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_cpu.c,v 1.3 2010/07/19 00:59:32 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/cpu.h>
@@ -77,6 +77,7 @@
 acpicpu_match(device_t parent, cfdata_t match, void *aux)
 {
 	struct acpi_attach_args *aa = aux;
+	struct acpicpu_object ao;
 
 	if (aa->aa_node->ad_type != ACPI_TYPE_PROCESSOR)
 		return 0;
@@ -84,7 +85,10 @@
 	if (acpi_match_hid(aa->aa_node->ad_devinfo, acpicpu_hid) != 0)
 		return 1;
 
-	return acpicpu_object(aa->aa_node->ad_handle, NULL);
+	int rv = acpicpu_object(aa->aa_node->ad_handle, &ao);
+	if (rv == 0 || acpicpu_id(ao.ao_procid) == 0xFFFFFF)
+		return 0;
+	return 1;
 }
 
 static void
@@ -267,10 +271,10 @@
 	CPU_INFO_ITERATOR cii;
 	struct cpu_info *ci;
 
+	KASSERT(id != 0);
 	for (CPU_INFO_FOREACH(cii, ci)) {
-
-		if (id == ci->ci_cpuid)
-			return id;
+		if (id - 1 == ci->ci_cpuid)
+			return id - 1;
 	}
 
 	return 0xFFFFFF;
@@ -434,6 +438,9 @@
 
 	sc = device_private(self);
 
+	if ((sc->sc_flags & ACPICPU_FLAG_INIT) == 0)
+		return;
+
 	switch (evt) {
 
 	case ACPICPU_C_NOTIFY:
Index: src/sys/dev/acpi/acpi_cpu.h
diff -u src/sys/dev/acpi/acpi_cpu.h:1.2 src/sys/dev/acpi/acpi_cpu.h:1.3
--- src/sys/dev/acpi/acpi_cpu.h:1.2	Sun Jul 18 05:39:45 2010
+++ src/sys/dev/acpi/acpi_cpu.h	Sun Jul 18 20:59:32 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_cpu.h,v 1.2 2010/07/18 09:39:45 jruoho Exp $ */
+/* $NetBSD: acpi_cpu.h,v 1.3 2010/07/19 00:59:32 christos Exp $ */
 
 /*-
  * Copyright (c) 2010 Jukka Ruohonen <jruoho...@iki.fi>
@@ -86,6 +86,7 @@
 #define ACPICPU_FLAG_C_NOC3	 __BIT(7)
 #define ACPICPU_FLAG_C_MWAIT	 __BIT(8)
 #define ACPICPU_FLAG_C_C1E	 __BIT(9)
+#define ACPICPU_FLAG_INIT	 __BIT(31)
 
 struct acpicpu_cstate {
 	uint64_t		 cs_stat;

Index: src/sys/dev/acpi/acpi_cpu_cstate.c
diff -u src/sys/dev/acpi/acpi_cpu_cstate.c:1.4 src/sys/dev/acpi/acpi_cpu_cstate.c:1.5
--- src/sys/dev/acpi/acpi_cpu_cstate.c:1.4	Sun Jul 18 16:20:04 2010
+++ src/sys/dev/acpi/acpi_cpu_cstate.c	Sun Jul 18 20:59:32 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_cpu_cstate.c,v 1.4 2010/07/18 20:20:04 jruoho Exp $ */
+/* $NetBSD: acpi_cpu_cstate.c,v 1.5 2010/07/19 00:59:32 christos Exp $ */
 
 /*-
  * Copyright (c) 2010 Jukka Ruohonen <jruoho...@iki.fi>
@@ -27,7 +27,7 @@
  * SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_cpu_cstate.c,v 1.4 2010/07/18 20:20:04 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_cpu_cstate.c,v 1.5 2010/07/19 00:59:32 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/cpu.h>
@@ -204,7 +204,10 @@
 	if (rv != 0)
 		return rv;
 
-	return RUN_ONCE(&once_start, acpicpu_md_idle_start);
+	rv = RUN_ONCE(&once_start, acpicpu_md_idle_start);
+	if (rv == 0)
+		sc->sc_flags |= ACPICPU_FLAG_INIT;
+	return rv;
 }
 
 bool

Reply via email to