Module Name:    src
Committed By:   jruoho
Date:           Tue Apr 27 05:34:15 UTC 2010

Modified Files:
        src/sys/arch/x86/x86: mpacpi.c
        src/sys/dev/acpi: acpi.c acpi_power.c acpireg.h

Log Message:
Clean up <dev/acpi/acpireg.h>. While documenting the control methods is an
admirable goal, it is pretty much mission impossible; the specifications are
nearly thousand pages each and the amount of methods is counted in hundreds.

In addition, use ACPICA's native constants from <actypes.h> when possible.
Also move ACPI_STA_OK from "mpacpi.c" to <dev/acpi/acpireg.h> to simplify
the evaluation of device status.


To generate a diff of this commit:
cvs rdiff -u -r1.86 -r1.87 src/sys/arch/x86/x86/mpacpi.c
cvs rdiff -u -r1.192 -r1.193 src/sys/dev/acpi/acpi.c
cvs rdiff -u -r1.10 -r1.11 src/sys/dev/acpi/acpi_power.c
cvs rdiff -u -r1.7 -r1.8 src/sys/dev/acpi/acpireg.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/x86/mpacpi.c
diff -u src/sys/arch/x86/x86/mpacpi.c:1.86 src/sys/arch/x86/x86/mpacpi.c:1.87
--- src/sys/arch/x86/x86/mpacpi.c:1.86	Wed Apr 14 19:32:35 2010
+++ src/sys/arch/x86/x86/mpacpi.c	Tue Apr 27 05:34:14 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: mpacpi.c,v 1.86 2010/04/14 19:32:35 jruoho Exp $	*/
+/*	$NetBSD: mpacpi.c,v 1.87 2010/04/27 05:34:14 jruoho Exp $	*/
 
 /*
  * Copyright (c) 2003 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mpacpi.c,v 1.86 2010/04/14 19:32:35 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mpacpi.c,v 1.87 2010/04/27 05:34:14 jruoho Exp $");
 
 #include "acpica.h"
 #include "opt_acpi.h"
@@ -84,8 +84,6 @@
 
 #include "locators.h"
 
-#define ACPI_STA_OK (ACPI_STA_DEV_PRESENT|ACPI_STA_DEV_ENABLED|ACPI_STA_DEV_OK)
-
 /* XXX room for PCI-to-PCI bus */
 #define BUS_BUFFER (16)
 

Index: src/sys/dev/acpi/acpi.c
diff -u src/sys/dev/acpi/acpi.c:1.192 src/sys/dev/acpi/acpi.c:1.193
--- src/sys/dev/acpi/acpi.c:1.192	Mon Apr 26 04:31:09 2010
+++ src/sys/dev/acpi/acpi.c	Tue Apr 27 05:34:14 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi.c,v 1.192 2010/04/26 04:31:09 jruoho Exp $	*/
+/*	$NetBSD: acpi.c,v 1.193 2010/04/27 05:34:14 jruoho Exp $	*/
 
 /*-
  * Copyright (c) 2003, 2007 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.192 2010/04/26 04:31:09 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.193 2010/04/27 05:34:14 jruoho Exp $");
 
 #include "opt_acpi.h"
 #include "opt_pcifixup.h"
@@ -725,13 +725,10 @@
 }
 
 #ifdef ACPI_ACTIVATE_DEV
-
-#define ACPI_DEV_VALID	(ACPI_VALID_STA | ACPI_VALID_HID)
-#define ACPI_DEV_STATUS	(ACPI_STA_DEV_PRESENT | ACPI_STA_DEV_ENABLED)
-
 static void
 acpi_activate_device(ACPI_HANDLE handle, ACPI_DEVICE_INFO **di)
 {
+	static const int valid = ACPI_VALID_STA | ACPI_VALID_HID;
 	ACPI_DEVICE_INFO *newdi;
 	ACPI_STATUS rv;
 	uint32_t old;
@@ -740,12 +737,13 @@
 	 * If the device is valid and present,
 	 * but not enabled, try to activate it.
 	 */
-	if (((*di)->Valid & ACPI_DEV_VALID) != ACPI_DEV_VALID)
+	if (((*di)->Valid & valid) != valid)
 		return;
 
 	old = (*di)->CurrentStatus;
 
-	if ((old & ACPI_DEV_STATUS) != ACPI_STA_DEV_PRESENT)
+	if ((old & (ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED)) !=
+	    ACPI_STA_DEVICE_PRESENT)
 		return;
 
 	rv = acpi_allocate_resources(handle);
@@ -880,10 +878,6 @@
 out:
 	return rv;
 }
-
-#undef ACPI_DEV_VALID
-#undef ACPI_DEV_STATUS
-
 #endif /* ACPI_ACTIVATE_DEV */
 
 /*
@@ -916,6 +910,7 @@
 {
 	struct acpi_attach_args aa;
 	struct acpi_devnode *ad;
+	ACPI_DEVICE_INFO *di;
 
 	SIMPLEQ_FOREACH(ad, &sc->ad_head, ad_list) {
 
@@ -929,21 +924,18 @@
 		if (acpi_is_scope(ad) != false)
 			continue;
 
+		di = ad->ad_devinfo;
+
 		/*
 		 * We only attach devices which are present, enabled, and
 		 * functioning properly. However, if a device is enabled,
 		 * it is decoding resources and we should claim these,
 		 * if possible. This requires changes to bus_space(9).
 		 */
-		if (ad->ad_devinfo->Type == ACPI_TYPE_DEVICE) {
+		if (di->Type == ACPI_TYPE_DEVICE) {
 
-			if ((ad->ad_devinfo->Valid & ACPI_VALID_STA) ==
-			    ACPI_VALID_STA &&
-			    (ad->ad_devinfo->CurrentStatus &
-			     (ACPI_STA_DEV_PRESENT|ACPI_STA_DEV_ENABLED|
-			      ACPI_STA_DEV_OK)) !=
-			    (ACPI_STA_DEV_PRESENT|ACPI_STA_DEV_ENABLED|
-			     ACPI_STA_DEV_OK))
+			if ((di->Valid & ACPI_VALID_STA) != 0 &&
+			    (di->CurrentStatus & ACPI_STA_OK) != ACPI_STA_OK)
 				continue;
 		}
 
@@ -952,20 +944,20 @@
 		 * thermal zones and power resources do not
 		 * have a valid HID, only evaluate devices.
 		 */
-		if (ad->ad_devinfo->Type == ACPI_TYPE_DEVICE &&
-		    (ad->ad_devinfo->Valid & ACPI_VALID_HID) == 0)
+		if (di->Type == ACPI_TYPE_DEVICE &&
+		   (di->Valid & ACPI_VALID_HID) == 0)
 			continue;
 
 		/*
 		 * Handled internally.
 		 */
-		if (ad->ad_devinfo->Type == ACPI_TYPE_PROCESSOR)
+		if (di->Type == ACPI_TYPE_PROCESSOR)
 			continue;
 
 		/*
 		 * Ditto, but bind power resources.
 		 */
-		if (ad->ad_devinfo->Type == ACPI_TYPE_POWER) {
+		if (di->Type == ACPI_TYPE_POWER) {
 			acpi_power_res_add(ad);
 			continue;
 		}
@@ -973,7 +965,7 @@
 		/*
 		 * Skip ignored HIDs.
 		 */
-		if (acpi_match_hid(ad->ad_devinfo, acpi_ignored_ids))
+		if (acpi_match_hid(di, acpi_ignored_ids))
 			continue;
 
 		aa.aa_node = ad;
@@ -988,9 +980,6 @@
 	}
 }
 
-#define ACPI_STA_DEV_VALID      \
-	(ACPI_STA_DEV_PRESENT | ACPI_STA_DEV_ENABLED | ACPI_STA_DEV_OK)
-
 static void
 acpi_rescan_capabilities(struct acpi_softc *sc)
 {
@@ -1007,8 +996,7 @@
 			continue;
 
 		if ((di->Valid & ACPI_VALID_STA) != 0 &&
-		    (di->CurrentStatus & ACPI_STA_DEV_VALID) !=
-		     ACPI_STA_DEV_VALID)
+		    (di->CurrentStatus & ACPI_STA_OK) != ACPI_STA_OK)
 			continue;
 
 		/*
@@ -1036,8 +1024,6 @@
 	}
 }
 
-#undef ACPI_STA_DEV_VALID
-
 static int
 acpi_print(void *aux, const char *pnp)
 {

Index: src/sys/dev/acpi/acpi_power.c
diff -u src/sys/dev/acpi/acpi_power.c:1.10 src/sys/dev/acpi/acpi_power.c:1.11
--- src/sys/dev/acpi/acpi_power.c:1.10	Mon Apr 26 13:38:42 2010
+++ src/sys/dev/acpi/acpi_power.c	Tue Apr 27 05:34:14 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_power.c,v 1.10 2010/04/26 13:38:42 jruoho Exp $ */
+/* $NetBSD: acpi_power.c,v 1.11 2010/04/27 05:34:14 jruoho Exp $ */
 
 /*-
  * Copyright (c) 2009, 2010 The NetBSD Foundation, Inc.
@@ -56,7 +56,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_power.c,v 1.10 2010/04/26 13:38:42 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_power.c,v 1.11 2010/04/27 05:34:14 jruoho Exp $");
 
 #include <sys/param.h>
 #include <sys/kmem.h>
@@ -70,6 +70,9 @@
 #define _COMPONENT			ACPI_BUS_COMPONENT
 ACPI_MODULE_NAME			("acpi_power")
 
+#define	ACPI_STA_POW_OFF		0x00
+#define	ACPI_STA_POW_ON			0x01
+
 /*
  * References.
  */

Index: src/sys/dev/acpi/acpireg.h
diff -u src/sys/dev/acpi/acpireg.h:1.7 src/sys/dev/acpi/acpireg.h:1.8
--- src/sys/dev/acpi/acpireg.h:1.7	Fri Mar  5 08:30:48 2010
+++ src/sys/dev/acpi/acpireg.h	Tue Apr 27 05:34:14 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpireg.h,v 1.7 2010/03/05 08:30:48 jruoho Exp $	*/
+/*	$NetBSD: acpireg.h,v 1.8 2010/04/27 05:34:14 jruoho Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -39,14 +39,11 @@
 #define _SYS_DEV_ACPI_ACPIREG_H
 
 /*
- * This file defines various ACPI event messages, etc.
- */
-
-/*
- * 5.6.3: Device Object Notifications
+ * XXX: Use the native types from <actypes.h>.
+ *
+ *	Move the device-specific constants to
+ *	the device-specific files.
  */
-
-/* Device Object Notification Types */
 #define	ACPI_NOTIFY_BusCheck		0x00
 #define	ACPI_NOTIFY_DeviceCheck		0x01
 #define	ACPI_NOTIFY_DeviceWake		0x02
@@ -83,238 +80,22 @@
 #define	ACPI_NOTIFY_CStatesChanged		0x81
 
 /*
- * 6: Configuration
- *
- * 6.1: Device Identification Objects
- *
- *	_ADR	Object that evaluates to a device's address on
- *		its parent bus.
- *
- *	_CID	Object that evaluates to a device's Plug and Play
- *		compatible ID list.
- *
- *	_DDN	Object that associates a logical software name
- *		(for example, COM1) with a device.
- *
- *	_HID	Object that evaluates to a device's Plug and Play
- *		hardware ID.
- *
- *	_SUN	Objcet that evaluates to the slot-unique ID number
- *		for a slot.
- *
- *	_STR	Object that contains a Unicode identifier for a device.
- *
- *	_UID	Object that specifies a device's unique persistent ID,
- *		or a control method that generates it.
+ * A common device status mask.
  */
+#define ACPI_STA_OK		(ACPI_STA_DEVICE_PRESENT	|	\
+				 ACPI_STA_DEVICE_ENABLED	|	\
+				 ACPI_STA_DEVICE_FUNCTIONING)
 
 /*
- * 6.1.1: _ADR (Address)
- *
- *	EISA		EISA slot numnber 0-f
- *
- *	Floppy Bus	Drive select values used for programming
- *			the floppy controller to access the
- *			specified INT13 unit number.  The _ADR
- *			objects should be sorted based on drive
- *			select encoding from 0-3.
- *
- *	IDE controller	0 - primary channel, 1 - secondary channel
- *
- *	IDE channel	0 - master drive, 1 - slave drive
- *
- *	PCI		High word - Device #, Low word - Function #
- *			0xffff == all functions on a device
- *
- *	PCMCIA		Socket #; 0 == first socket
- *
- *	PC Card		Socket #; 0 == first socket
- *
- *	SMBus		Lowest slave address
- *
- *	USB Root Hub	Only one child of the host controller, must
- *			have an _ADR of 0.
- *
- *	USB ports	port number
+ * PCI functions.
  */
 #define	ACPI_ADR_PCI_DEV(x)	(((x) >> 16) & 0xffff)
 #define	ACPI_ADR_PCI_FUNC(x)	((x) & 0xffff)
 #define	ACPI_ADR_PCI_ALLFUNCS	0xffff
 
 /*
- * 6.1.2: _CID (Compatible ID)
- */
-
-/*
- * 6.1.3: _DDN (Device Name)
- */
-
-/*
- * 6.1.4: _HID (Hardware ID)
- */
-
-/*
- * 6.1.5: _STR (String)
- */
-
-/*
- * 6.1.6: _SUN (Slot User Number)
- */
-
-/*
- * 6.1.7: _UID (Unique ID)
- */
-
-/*
- * 6.2: Device Configuration Objects
- *
- *	_CRS	Object that specifies a device's *current* resource
- *		settings, or a control method that generates such
- *		an object.
- *
- *	_DIS	Control method that disables a device.
- *
- *	_DMA	Object that specifies a device's *current* resources
- *		for DMA transactions.
- *
- *	_FIX	Object used to provide correlation between the
- *		fixed-hardware register blocks defined in the FADT
- *		and the devices that implement these fixed-hardware
- *		registers.
- *
- *	_HPP	Object that specifies the cache-line size, latency
- *		timer, SERR enable, and PERR enable values to be
- *		used when configuring a PCI device inserted into
- *		a hot-plug slot or initial configuration of a PCI
- *		device at system boot.
- *
- *	_MAT	Object that evaluates to a buffer of MADT APIC
- *		structure entries.
- *
- *	_PRS	An object that specifies a device's *possible*
- *		resource settings, or a control method that
- *		generates such an object.
- *
- *	_PRT	Object that specifies the PCI interrupt routing
- *		table.
- *
- *	_PXM	Object that specifies a proximity domain for a device.
- *
- *	_SRS	Control method that sets a device's settings.
- */
-
-/*
- * 6.2.1: _CRS (Current Resource Settings)
- */
-
-/*
- * 6.2.2: _DIS (Disable)
- */
-
-/*
- * 6.2.3: _DMA (Direct Memory AccesS)
+ * ACPI driver components.
  */
-
-/*
- * 6.2.4: _FIX (Fixed Register Resource Provider)
- */
-
-/*
- * 6.2.5: _HPP (Hot Plug Parameters)
- */
-
-/*
- * 6.2.6: _MAT (Multiple APIC Table Entry)
- */
-
-/*
- * 6.2.7: _PRS (Possible Resource Settings)
- */
-
-/*
- * 6.2.8: _PRT (PCI Routing Table)
- */
-
-/*
- * 6.2.9: _PXM (Proximity)
- */
-
-/*
- * 6.2.10: _SRS (Set Resource Settings)
- */
-
-/*
- * 6.3: Device Insertion and Removal Objects
- *
- *	_EDL	Object that evaluates to a package of namespace
- *		references of device objects that depend on
- *		the device containing _EDL.  Whenever the named
- *		devices is ejected, OSPM ejects all dependent
- *		devices.
- *
- *	_EJD	Object that evaluates to the name of a device object
- *		on which a device depends.  Whenever the named
- *		device is ejected, the dependent device must receive
- *		an ejection notification.
- *
- *	_EJx	Control method that ejects a device.
- *
- *	_LCK	Control method that locks or unlocks a device.
- *
- *	_RMV	Object that indicates that the given device is
- *		removable.
- *
- *	_STA	Control method that returns a device's status.
- */
-
-/*
- * 6.3.1: _EDL (Eject Device List)
- */
-
-/*
- * 6.3.2: _EJD (Ejection Dependent Device)
- */
-
-/*
- * 6.3.3: _EJx (Eject)
- *
- *	x	Indicates sleeping state at which device
- *		can be ejected.
- */
-
-/*
- * 6.3.4: _LCK (Lock)
- */
-
-/*
- * 6.3.5: _RMV (Remove)
- */
-
-/*
- * 6.3.6: _STA (Status) for device insertion/removal
- */
-#define	ACPI_STA_DEV_PRESENT	0x00000001	/* device present */
-#define	ACPI_STA_DEV_ENABLED	0x00000002	/* enabled (decoding res.) */
-#define	ACPI_STA_DEV_SHOW	0x00000004	/* show device in UI */
-#define	ACPI_STA_DEV_OK		0x00000008	/* functioning properly */
-#define	ACPI_STA_DEV_BATT	0x00000010	/* battery present */
-
-/*
- * 6.4: Resource Data Types for ACPI
- *
- *	Used by the _CRS, _PRS, and _SRS methods.
- */
-
-/*
- * 7.1.4: _STA (Status) for power resource current state
- */
-#define	ACPI_STA_POW_OFF	0		/* power resource off */
-#define	ACPI_STA_POW_ON		1		/* power resource on */
-
-/*
- * ACPI driver components
- */
-
 #define	ACPI_BUS_COMPONENT	0x00010000
 #define	ACPI_ACAD_COMPONENT	0x00020000
 #define	ACPI_BAT_COMPONENT	0x00040000

Reply via email to