From owner-acpi-jp@jp.freebsd.org  Mon Aug  7 22:30:45 2000
Received: (from daemon@localhost)
	by castle.jp.freebsd.org (8.9.3+3.2W/8.7.3) id WAA62815;
	Mon, 7 Aug 2000 22:30:45 +0900 (JST)
	(envelope-from owner-acpi-jp@jp.FreeBSD.org)
Received: from tasogare.imasy.or.jp (daemon@tasogare.imasy.or.jp [202.227.24.5])
	by castle.jp.freebsd.org (8.9.3+3.2W/8.7.3) with ESMTP id WAA62810
	for <acpi-jp@jp.freebsd.org>; Mon, 7 Aug 2000 22:30:42 +0900 (JST)
	(envelope-from iwasaki@jp.FreeBSD.org)
Received: from localhost (iwasaki.imasy.or.jp [202.227.24.92])
	by tasogare.imasy.or.jp (8.10.2+3.3W/3.7W-tasogare/smtpfeed 1.07) with ESMTP id e77DUcZ68220
	for <acpi-jp@jp.freebsd.org>; Mon, 7 Aug 2000 22:30:38 +0900 (JST)
	(envelope-from iwasaki@jp.FreeBSD.org)
To: acpi-jp@jp.freebsd.org
X-Mailer: Mew version 1.94.1 on Emacs 19.34 / Mule 2.3 (SUETSUMUHANA)
Mime-Version: 1.0
Content-Type: Text/Plain; charset=iso-2022-jp
Content-Transfer-Encoding: 7bit
Message-Id: <20000807223034H.iwasaki@jp.FreeBSD.org>
Date: Mon, 07 Aug 2000 22:30:34 +0900
From: Mitsuru IWASAKI <iwasaki@jp.freebsd.org>
X-Dispatcher: imput version 20000228(IM140)
Lines: 498
Reply-To: acpi-jp@jp.freebsd.org
Precedence: list
X-Distribute: distribute version 2.1 (Alpha) patchlevel 24e+000315
X-Sequence: acpi-jp 537
Subject: [acpi-jp 537] ACPI debug print cleanup
Errors-To: owner-acpi-jp@jp.freebsd.org
Sender: owner-acpi-jp@jp.freebsd.org
X-Originator: iwasaki@jp.freebsd.org

sys/acpi.h $B$N(B cleanup $B$H%G%P%C%0>pJs=PNO@)8f$r$A$g$C$H=$@5$7$^$7$?!#(B
loader $B$G(B set debug.acpi_debug=0 $B$H$+;XDj$G$-$k$h$&$K$J$j!"(Bacpi_debug=0
$B$N>l9g$O%G%P%C%0>pJs$O>JN,$5$l!"(Bprobe/attach $B$K$F(B
acpi0: <RIOS> on motherboard
acpi0: at 0x1d0 irq 13
$B$NFs9T$N$_=PNO$5$l$^$9!#(B

$B=>Mh$N%^%/%m(B ACPIPRINTF $B$rGQ;_$7!"(BACPI_DEVPRINTF $B$H(B ACPI_DEBUGPRINT $B$K(B
$B$7$F$$$^$9$,!"H?BP$,$J$1$l$P(B aml $B$NJ}$b(B AML_PRINT -> AML_DEBUGPRINT $B$H(B
$BJQ99$7$^$9!#(B

$B0J2<$K(B patch $B$rE:IU$7$^$9!#L@F|Lk(B commit $B$7$A$c$$$^$9!#(B
$B$=$&$=$&!":rF|N.$7$?$d$D$N0lIt$O:#HU(B commit $B$7$^$9!#(B

Index: sys/acpi.h
===================================================================
RCS file: /home/cvs/ACPI/sys/sys/acpi.h,v
retrieving revision 1.8
diff -u -r1.8 acpi.h
--- sys/acpi.h	2000/08/03 16:04:36	1.8
+++ sys/acpi.h	2000/08/07 12:41:59
@@ -27,8 +27,8 @@
  * $FreeBSD$
  */
 
-#ifndef	_MACHINE_PC_ACPI_H_
-#define	_MACHINE_PC_ACPI_H_
+#ifndef	_SYS_ACPI_H_
+#define	_SYS_ACPI_H_
 
 #include <sys/ioccom.h>
 
@@ -128,6 +128,40 @@
 	char            reserved[40];
 } __attribute__((packed));
 
+/*
+ * Bits for ACPI registers
+ */
+
+/* Power Management 1 Event Regisers (4.7.3.1 Table 4-9, 4-10) */
+/* these bits are for status and enable regiser */
+#define	ACPI_PM1_TMR_EN			0x0001
+#define	ACPI_PM1_GBL_EN			0x0020
+#define	ACPI_PM1_PWRBTN_EN		0x0100
+#define	ACPI_PM1_SLPBTN_EN		0x0200
+#define	ACPI_PM1_RTC_EN			0x0400
+#define	ACPI_PM1_ALL_ENABLE_BITS	0x0721
+/* these bits are for status regiser only */
+#define	ACPI_PM1_BM_STS			0x0010
+#define	ACPI_PM1_WAK_STS		0x8000
+
+/* Power Management 1 Control Regisers (4.7.3.2 Table 4-11) */
+#define	ACPI_CNT_SCI_EN			0x0001
+#define	ACPI_CNT_BM_RLD			0x0002
+#define	ACPI_CNT_GBL_RLS		0x0004
+#define	ACPI_CNT_SLP_TYPX		0x1c00
+#define	ACPI_CNT_SLP_EN			0x2000
+
+#define	ACPI_CNT_SET_SLP_TYP(x)		(x << 10)
+
+/* Power Management Timer (4.7.3.3 Table 4-12) */
+/* Not yet */
+
+/* Power Management 2 Control (4.7.3.4 Table 4-13) */
+/* Not yet */
+
+/* Processor Register Block (4.7.3.5 Table 4-14, 4-15, 4-16) */
+/* Not yet */
+
 #ifdef _KERNEL
 extern struct ACPIrsdp *acpi_rsdp;	/* ACPI Root System Description Table */
 
@@ -238,4 +272,4 @@
 
 #endif	/* !_KERNEL */
 
-#endif	/* _MACHINE_PC_ACPI_H_ */
+#endif	/* _SYS_ACPI_H_ */
Index: dev/acpi/acpi.c
===================================================================
RCS file: /home/cvs/ACPI/sys/dev/acpi/acpi.c,v
retrieving revision 1.22
diff -u -r1.22 acpi.c
--- dev/acpi/acpi.c	2000/08/05 18:47:48	1.22
+++ dev/acpi/acpi.c	2000/08/07 12:32:13
@@ -167,7 +167,12 @@
 #endif	/* ACPI_DEBUG */
 SYSCTL_INT(_debug, OID_AUTO, acpi_debug, CTLFLAG_RW, &acpi_debug, 1, "");
 
-#define ACPIPRINTF(args...)	printf("acpi0: " args)
+#define ACPI_DEVPRINTF(args...)	printf("acpi0: " args)
+#define ACPI_DEBUGPRINT(args...) do {					\
+	if (acpi_debug) {						\
+		ACPI_DEVPRINTF(args);					\
+	}								\
+} while(0)
 
 void
 acpi_init_addr_range()
@@ -217,8 +222,8 @@
 		va = (vm_offset_t) pmap_mapdev(acpi_addr.t[i].pa_base,
 					       acpi_addr.t[i].size);
 		acpi_addr.t[i].va_base = va;
-		ACPIPRINTF("ADDR RANGE %x %x (mapped 0x%x)\n",
-			   acpi_addr.t[i].pa_base, acpi_addr.t[i].size, va);
+		ACPI_DEBUGPRINT("ADDR RANGE %x %x (mapped 0x%x)\n",
+		    acpi_addr.t[i].pa_base, acpi_addr.t[i].size, va);
 	}
 }
 
@@ -348,10 +353,8 @@
 		}
 		ssp.mode[i].slp_typ_a = spkg->package.objects[0]->num.number;
 		ssp.mode[i].slp_typ_b = spkg->package.objects[1]->num.number;
-		if (acpi_debug) {
-			ACPIPRINTF("%s : [%d, %d]\n", namestr,
-			    ssp.mode[i].slp_typ_a, ssp.mode[i].slp_typ_b);
-		}
+		ACPI_DEBUGPRINT("%s : [%d, %d]\n", namestr,
+		    ssp.mode[i].slp_typ_a, ssp.mode[i].slp_typ_b);
 	}
 	sc->system_state_package = ssp;
 
@@ -370,7 +373,7 @@
 	struct FACPbody *body = (struct FACPbody *) facp->body;
 	struct FACS    *facs;
 
-	ACPIPRINTF("	FACP found\n");
+	ACPI_DEBUGPRINT("	FACP found\n");
 	sc->facp_body = body;
 	dsdt = (struct ACPIsdt *) acpi_pmap_ptv(body->dsdt_ptr);
 	sc->dsdt = NULL;
@@ -381,7 +384,7 @@
 
 	if (strncmp(dsdt->signature, "DSDT", 4) == 0 &&
 	    acpi_sdt_checksum(dsdt) == 0) {
-		ACPIPRINTF("	DSDT found Size=%d bytes\n", dsdt->len);
+		ACPI_DEBUGPRINT("	DSDT found Size=%d bytes\n", dsdt->len);
 		sc->dsdt = dsdt;
 		acpi_handle_dsdt(sc);
 	}
@@ -397,40 +400,10 @@
 	 */
 	if (strncmp(facs->signature, "FACS", 4) == 0) {
 		sc->facs = facs;
-		ACPIPRINTF("	FACS Found Size=%d bytes\n", facs->len);
+		ACPI_DEBUGPRINT("	FACS found Size=%d bytes\n", facs->len);
 	}
 }
 
-/* XXX should be moved to acpi.h */
-#define	ACPI_PM1_ALL_ENABLE_BITS	0x0721	/* 0000 0111 0010 0001 */
-#define	ACPI_PM1_TMR_EN			0x0001
-#define	ACPI_PM1_GBL_EN			0x0020
-#define	ACPI_PM1_PWRBTN_EN		0x0100
-#define	ACPI_PM1_SLPBTN_EN		0x0200
-#define	ACPI_PM1_RTC_EN			0x0400
-/* these bits are for status only */
-#define	ACPI_PM1_BM_STS			0x0010
-#define	ACPI_PM1_WAK_STS		0x8000
-
-#define	ACPI_CNT_SCI_EN			0x0001
-#define	ACPI_CNT_BM_RLD			0x0002
-#define	ACPI_CNT_GBL_RLS		0x0004
-#define	ACPI_CNT_SLP_TYPX		0x1c00
-#define	ACPI_CNT_SLP_EN			0x2000
-
-#define	ACPI_CNT_SET_SLP_TYP(x)		(x << 10)
-
-/* Fixed ACPI Description Table Fixed Feature Flags (5.2.5 Table 5-6) */
-#define ACPI_FACP_FLAGS_WBINVD		0x00000001
-#define ACPI_FACP_FLAGS_WBINVD_FLUSH	0x00000002
-#define ACPI_FACP_FLAGS_PROC_C1		0x00000004
-#define ACPI_FACP_FLAGS_P_LVL2L_UP	0x00000008
-#define ACPI_FACP_FLAGS_PWR_BUTTON	0x00000010
-#define ACPI_FACP_FLAGS_SLP_BUTTON	0x00000020
-#define ACPI_FACP_FLAGS_FIX_RTC		0x00000040
-#define ACPI_FACP_FLAGS_RTC_S4		0x00000080
-#define ACPI_FACP_FLAGS_TMR_VAL_EXT	0x00000100
-#define ACPI_FACP_FLAGS_DCK_CAP		0x00000200
 /*
  * System sleeping state stuff.
  */
@@ -454,7 +427,7 @@
 		if ((val_a | val_b) & ACPI_PM1_WAK_STS) {
 			sc->broken_wakeuplogic = 0;
 		} else {
-			ACPIPRINTF("wake-up logic seems broken, "
+			ACPI_DEVPRINTF("wake-up logic seems broken, "
 			    "this may cause troubles on wakeup\n");
 			sc->broken_wakeuplogic = 1;
 		}
@@ -594,7 +567,7 @@
 	if ((status_a & enable_a) != 0 || (status_b & enable_b) != 0) {
 		acpi_debug = debug;	/* OK, you can speak */
 
-		ACPIPRINTF("pm1_status intr CALLED\n");
+		ACPI_DEVPRINTF("pm1_status intr CALLED\n");
 
 		/* Disable all intrrupt generation */
 		val_a = enable_a & (~ACPI_PM1_ALL_ENABLE_BITS);
@@ -623,7 +596,7 @@
 	if ((status_0 & enable_0) != 0) {
 		acpi_debug = debug;	/* OK, you can speak */
 
-		ACPIPRINTF("gpe0_status intr CALLED\n");
+		ACPI_DEVPRINTF("gpe0_status intr CALLED\n");
 
 		/* Disable all intrrupt generation */
 		val_a = enable_0 & ~status_0;
@@ -652,7 +625,7 @@
 	if ((status_1 & enable_1) != 0) {
 		acpi_debug = debug;	/* OK, you can speak */
 
-		ACPIPRINTF("gpe1_status intr CALLED\n");
+		ACPI_DEVPRINTF("gpe1_status intr CALLED\n");
 
 		/* Disable all intrrupt generation */
 		val_a = enable_1 & ~status_1;
@@ -693,15 +666,25 @@
 acpi_probe(device_t dev)
 {
 	static char     oemstring[7];
+	int             debug;
 
 	if (acpi_rsdp == NULL) {
 		return (ENXIO);
 	}
+
+	/* get debug variables specified in loader. */
+	if (getenv_int("debug.acpi_debug", &debug)) {
+		acpi_debug = debug;
+	}
+	if (getenv_int("debug.aml_debug", &debug)) {
+		aml_debug = debug;
+	}
+
 	bzero(oemstring, sizeof(oemstring));
 	strncpy(oemstring, acpi_rsdp->oem, sizeof(acpi_rsdp->oem));
 
-	printf("ACPI: Found ACPI BIOS data at %p (<%s>, RSDT@%x)\n",
-	       acpi_rsdp, oemstring, acpi_rsdp->addr);
+	ACPI_DEBUGPRINT("Found ACPI BIOS data at %p (<%s>, RSDT@%x)\n",
+	    acpi_rsdp, oemstring, acpi_rsdp->addr);
 
 	device_set_desc(dev, oemstring);
 	return (0);
@@ -728,25 +711,25 @@
 
 	rsdt = (struct ACPIsdt *) acpi_pmap_ptv(acpi_rsdp->addr);
 	if (rsdt == 0) {
-		ACPIPRINTF("cannot map physical memory\n");
+		ACPI_DEVPRINTF("cannot map physical memory\n");
 		return (ENXIO);
 	}
 	if ((strncmp(rsdt->signature, "RSDT", 4) != 0) ||
 	    (acpi_sdt_checksum(rsdt) != 0)) {
-		ACPIPRINTF("RSDT is broken\n");
+		ACPI_DEVPRINTF("RSDT is broken\n");
 		acpi_pmap_release();
 		return (ENXIO);
 	}
 	sc->rsdt = rsdt;
 	entries = (rsdt->len - SIZEOF_SDT_HDR) / sizeof(u_int32_t);
-	ACPIPRINTF("RSDT have %d entries\n", entries);
+	ACPI_DEBUGPRINT("RSDT have %d entries\n", entries);
 	ptrs = (u_int32_t *) & rsdt->body;
 
 	for (i = 0; i < entries; i++) {
 		sdt = (struct ACPIsdt *) acpi_pmap_ptv((vm_offset_t) ptrs[i]);
 		bzero(sigstring, sizeof(sigstring));
 		strncpy(sigstring, sdt->signature, sizeof(sdt->signature));
-		ACPIPRINTF("RSDT entry%d %s\n", i, sigstring);
+		ACPI_DEBUGPRINT("RSDT entry%d %s\n", i, sigstring);
 
 		if (strncmp(sdt->signature, "FACP", 4) == 0 &&
 		    acpi_sdt_checksum(sdt) == 0) {
@@ -761,7 +744,7 @@
 	res_port = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, port, port, 1, RF_ACTIVE);
 
 	if (res_port == NULL) {
-		ACPIPRINTF("could not allocate port\n");
+		ACPI_DEVPRINTF("could not allocate port\n");
 		acpi_pmap_release();
 		return (ENOMEM);
 	}
@@ -778,7 +761,7 @@
 	err = bus_setup_intr(dev, res_irq, INTR_TYPE_MISC,
 			     (driver_intr_t *) acpi_intr, sc, &ih);
 	if (err) {
-		ACPIPRINTF("could not setup irq, %d\n", err);
+		ACPI_DEVPRINTF("could not setup irq, %d\n", err);
 		acpi_pmap_release();
 		return (err);
 	}
@@ -787,7 +770,7 @@
 	acpi_enable_disable(sc, 1);
 #endif
 
-	ACPIPRINTF("at 0x%x irq %d\n", port, irq);
+	ACPI_DEVPRINTF("at 0x%x irq %d\n", port, irq);
 
 	/*
 	 * Setup PM1 Enable Registers Fixed Feature Enable Bits (4.7.3.1.2)
@@ -795,11 +778,11 @@
 	 */
 	acpi_io_pm1_enable(sc, ACPI_REGISTERS_INPUT, &status_a, &status_b);
 	flags = sc->facp_body->flags;
-	if ((flags & ACPI_FACP_FLAGS_PWR_BUTTON) == 0) {
+	if ((flags & ACPI_FACP_FLAG_PWR_BUTTON) == 0) {
 		status_a |= ACPI_PM1_PWRBTN_EN;
 		status_b |= ACPI_PM1_PWRBTN_EN;
 	}
-	if ((flags & ACPI_FACP_FLAGS_SLP_BUTTON) == 0) {
+	if ((flags & ACPI_FACP_FLAG_SLP_BUTTON) == 0) {
 		status_a |= ACPI_PM1_SLPBTN_EN;
 		status_b |= ACPI_PM1_SLPBTN_EN;
 	}
@@ -878,7 +861,7 @@
 		val = OsdIn32(ioaddr);
 		break;
 	default:
-		ACPIPRINTF("acpi_registers_input(): invalid size\n");
+		ACPI_DEVPRINTF("acpi_registers_input(): invalid size\n");
 		val = 0;
 		break;
 	}
@@ -909,7 +892,7 @@
 		OsdOut32(ioaddr, val);
 		break;
 	default:
-		ACPIPRINTF("acpi_registers_output(): invalid size\n");
+		ACPI_DEVPRINTF("acpi_registers_output(): invalid size\n");
 		break;
 	}
 }
@@ -929,9 +912,7 @@
 
 	OsdOut8(ioaddr, val);
 
-	if (acpi_debug) {
-		ACPIPRINTF("acpi_enable_disable(%d) = (%x)\n", enable, val);
-	}
+	ACPI_DEBUGPRINT("acpi_enable_disable(%d) = (%x)\n", enable, val);
 }
 
 static void
@@ -955,10 +936,8 @@
 		}
 	}
 
-	if (acpi_debug) {
-		ACPIPRINTF("acpi_io_pm1_status(%d) = (%x, %x)\n",
-			   io, *status_a, *status_b);
-	}
+	ACPI_DEBUGPRINT("acpi_io_pm1_status(%d) = (%x, %x)\n",
+	    io, *status_a, *status_b);
 
 	return;
 }
@@ -984,10 +963,8 @@
 		}
 	}
 
-	if (acpi_debug) {
-		ACPIPRINTF("acpi_io_pm1_enable(%d) = (%x, %x)\n",
-			   io, *status_a, *status_b);
-	}
+	ACPI_DEBUGPRINT("acpi_io_pm1_enable(%d) = (%x, %x)\n",
+	    io, *status_a, *status_b);
 
 	return;
 }
@@ -1013,10 +990,8 @@
 		}
 	}
 
-	if (acpi_debug) {
-		ACPIPRINTF("acpi_io_pm1_control(%d) = (%x, %x)\n",
-			   io, *value_a, *value_b);
-	}
+	ACPI_DEBUGPRINT("acpi_io_pm1_control(%d) = (%x, %x)\n",
+	    io, *value_a, *value_b);
 
 	return;
 }
@@ -1037,10 +1012,8 @@
 		acpi_registers_output(facp->pm2_cnt_blk, val, size);
 	}
 
-	if (acpi_debug) {
-		ACPIPRINTF("acpi_io_pm2_control(%d) = (%x)\n",
-			   io, *val);
-	}
+	ACPI_DEBUGPRINT("acpi_io_pm2_control(%d) = (%x)\n",
+	    io, *val);
 
 	return;
 }
@@ -1057,10 +1030,8 @@
 		return;	/* XXX read-only */
 	}
 
-	if (acpi_debug) {
-		ACPIPRINTF("acpi_io_pm_timer(%d) = (%x)\n",
-			   io, *val);
-	}
+	ACPI_DEBUGPRINT("acpi_io_pm_timer(%d) = (%x)\n",
+	    io, *val);
 
 	return;
 }
@@ -1081,10 +1052,8 @@
 		acpi_registers_output(facp->gpe0_blk, val, size);
 	}
 
-	if (acpi_debug) {
-		ACPIPRINTF("acpi_io_gpe0_status(%d) = (%x)\n",
-			   io, *val);
-	}
+	ACPI_DEBUGPRINT("acpi_io_gpe0_status(%d) = (%x)\n",
+	    io, *val);
 
 	return;
 }
@@ -1105,10 +1074,8 @@
 		acpi_registers_output(facp->gpe0_blk + size, val, size);
 	}
 
-	if (acpi_debug) {
-		ACPIPRINTF("acpi_io_gpe0_enable(%d) = (%x)\n",
-			   io, *val);
-	}
+	ACPI_DEBUGPRINT("acpi_io_gpe0_enable(%d) = (%x)\n",
+	    io, *val);
 
 	return;
 }
@@ -1129,10 +1096,8 @@
 		acpi_registers_output(facp->gpe1_blk, val, size);
 	}
 
-	if (acpi_debug) {
-		ACPIPRINTF("acpi_io_gpe1_status(%d) = (%x)\n",
-			   io, *val);
-	}
+	ACPI_DEBUGPRINT("acpi_io_gpe1_status(%d) = (%x)\n",
+	    io, *val);
 
 	return;
 }
@@ -1153,10 +1118,8 @@
 		acpi_registers_output(facp->gpe1_blk + size, val, size);
 	}
 
-	if (acpi_debug) {
-		ACPIPRINTF("acpi_io_gpe1_enable(%d) = (%x)\n",
-			   io, *val);
-	}
+	ACPI_DEBUGPRINT("acpi_io_gpe1_enable(%d) = (%x)\n",
+	    io, *val);
 
 	return;
 }
@@ -1201,17 +1164,16 @@
 		} else {
 			error = EINVAL;
 		}
-		if (acpi_debug)
-			ACPIPRINTF("ACPIIO_SETSLPSTATE = %d\n", state);
+		ACPI_DEBUGPRINT("ACPIIO_SETSLPSTATE = %d\n", state);
 		break;
 
 	case ACPIIO_GETSLPSTATEPKG:
 		ssp = (struct acpi_system_state_package *)addr;
 		*ssp = sc->system_state_package;
 		if (acpi_debug) {
-			ACPIPRINTF("ACPIIO_GETSLPSTATEPKG\n");
+			ACPI_DEBUGPRINT("ACPIIO_GETSLPSTATEPKG\n");
 			for (i = 0; i < 6; i++) {
-				ACPIPRINTF("	[%d] = (%d,%d)\n", i,
+				ACPI_DEBUGPRINT("	[%d] = (%d,%d)\n", i,
 				    sc->system_state_package.mode[i].slp_typ_a,
 				    sc->system_state_package.mode[i].slp_typ_b);
 			}
@@ -1223,9 +1185,9 @@
 		sc->system_state_package = *ssp;
 		sc->system_state_initialized = 1;
 		if (acpi_debug) {
-			ACPIPRINTF("ACPIIO_SETSLPSTATEPKG\n");
+			ACPI_DEBUGPRINT("ACPIIO_SETSLPSTATEPKG\n");
 			for (i = 0; i < 6; i++) {
-				ACPIPRINTF("	[%d] = (%d,%d)\n", i,
+				ACPI_DEBUGPRINT("	[%d] = (%d,%d)\n", i,
 				    sc->system_state_package.mode[i].slp_typ_a,
 				    sc->system_state_package.mode[i].slp_typ_b);
 			}
